From d5d38aea1cb423b8bdb952f2683ab93c410ac8a0 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 12 Sep 2019 22:45:29 +0200 Subject: [PATCH] Added a few spell and aura arrays to ItemTemplate, added a new enum, and fixed compile. --- data/item_template.cpp | 175 +++++++++++++++++++++++++++++++---------- data/item_template.h | 42 ++++++++-- data/skill.h | 4 +- spell_enums.cpp | 1 + spell_enums.h | 20 +++++ 5 files changed, 193 insertions(+), 49 deletions(-) diff --git a/data/item_template.cpp b/data/item_template.cpp index fa73915..9534a01 100644 --- a/data/item_template.cpp +++ b/data/item_template.cpp @@ -115,32 +115,112 @@ void ItemTemplate::set_bag_size(const int size) { _bag_size = size; } -Ref ItemTemplate::get_spell() const { - if (_spell) - return (*_spell); +//// TEACHES //// - return Ref(NULL); +int ItemTemplate::get_num_teaches_spells() { + return _teaches_spells.size(); +} +void ItemTemplate::set_num_teaches_spells(int value) { + _teaches_spells.resize(value); } -void ItemTemplate::set_spell(const Ref spell) { - if (_spell) - memdelete(_spell); +Ref ItemTemplate::get_teaches_spell(int index) const { + ERR_FAIL_INDEX_V(index, _teaches_spells.size(), Ref()); - _spell = memnew(Ref(spell)); + return _teaches_spells[index]; +} +void ItemTemplate::set_teaches_spell(int index, Ref spell) { + ERR_FAIL_INDEX(index, _teaches_spells.size()); + + _teaches_spells.set(index, Ref(spell)); } -Ref ItemTemplate::get_aura(const int index) const { - if (_auras[index]) - return (*_auras[index]); +Vector ItemTemplate::get_teaches_spells() { + Vector r; + for (int i = 0; i < _teaches_spells.size(); i++) { + r.push_back(_teaches_spells[i].get_ref_ptr()); + } + return r; +} +void ItemTemplate::set_teaches_spells(const Vector &spells) { + _teaches_spells.clear(); + for (int i = 0; i < spells.size(); i++) { + Ref spell = Ref(spells[i]); - return Ref(NULL); + _teaches_spells.push_back(spell); + } } -void ItemTemplate::set_aura(const int index, const Ref aura) { - if (_auras[index]) - memdelete(_auras[index]); +//// GRANTS SPELLS //// - _auras[index] = memnew(Ref(aura)); +int ItemTemplate::get_num_grants_spells() { + return _grants_spells.size(); +} +void ItemTemplate::set_num_grants_spells(int value) { + _grants_spells.resize(value); +} + +Ref ItemTemplate::get_grants_spell(int index) const { + ERR_FAIL_INDEX_V(index, _grants_spells.size(), Ref()); + + return _grants_spells[index]; +} +void ItemTemplate::set_grants_spell(int index, Ref spell) { + ERR_FAIL_INDEX(index, _grants_spells.size()); + + _grants_spells.set(index, Ref(spell)); +} + +Vector ItemTemplate::get_grants_spells() { + Vector r; + for (int i = 0; i < _grants_spells.size(); i++) { + r.push_back(_grants_spells[i].get_ref_ptr()); + } + return r; +} +void ItemTemplate::set_grants_spells(const Vector &spells) { + _grants_spells.clear(); + for (int i = 0; i < spells.size(); i++) { + Ref spell = Ref(spells[i]); + + _grants_spells.push_back(spell); + } +} + +//// AURAS //// + +int ItemTemplate::get_num_auras() { + return _auras.size(); +} +void ItemTemplate::set_num_auras(int value) { + _auras.resize(value); +} + +Ref ItemTemplate::get_aura(int index) const { + ERR_FAIL_INDEX_V(index, _auras.size(), Ref()); + + return _auras[index]; +} +void ItemTemplate::set_aura(int index, Ref aura) { + ERR_FAIL_INDEX(index, _auras.size()); + + _auras.set(index, Ref(aura)); +} + +Vector ItemTemplate::get_auras() { + Vector r; + for (int i = 0; i < _auras.size(); i++) { + r.push_back(_auras[i].get_ref_ptr()); + } + return r; +} +void ItemTemplate::set_auras(const Vector &auras) { + _auras.clear(); + for (int i = 0; i < auras.size(); i++) { + Ref spell = Ref(auras[i]); + + _auras.push_back(spell); + } } int ItemTemplate::get_item_stat_modifier_count() const { @@ -272,12 +352,6 @@ ItemTemplate::ItemTemplate() { _inventory_size_x = 0; _inventory_size_y = 0; _bag_size = 0; - - _spell = NULL; - - for (int i = 0; i < MAX_AURAS; ++i) { - _auras[i] = NULL; - } for (int i = 0; i < MAX_ITEM_STAT_MOD; ++i) { _modifiers[i] = Ref(memnew(ItemTemplateStatModifier())); @@ -285,14 +359,9 @@ ItemTemplate::ItemTemplate() { } ItemTemplate::~ItemTemplate() { - - if (_spell) - memdelete(_spell); - - for (int i = 0; i < MAX_AURAS; ++i) { - if (_auras[i]) - memdelete(_auras[i]); - } + _teaches_spells.clear(); + _grants_spells.clear(); + _auras.clear(); } void ItemTemplate::_validate_property(PropertyInfo &property) const { @@ -369,22 +438,49 @@ void ItemTemplate::_bind_methods() { ClassDB::bind_method(D_METHOD("get_bag_size"), &ItemTemplate::get_bag_size); ClassDB::bind_method(D_METHOD("set_bag_size", "size"), &ItemTemplate::set_bag_size); ADD_PROPERTY(PropertyInfo(Variant::INT, "bag_size"), "set_bag_size", "get_bag_size"); - - ClassDB::bind_method(D_METHOD("get_spell"), &ItemTemplate::get_spell); - ClassDB::bind_method(D_METHOD("set_spell", "spell"), &ItemTemplate::set_spell); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "spell", PROPERTY_HINT_RESOURCE_TYPE, "Spell"), "set_spell", "get_spell"); + + + //// Teaches //// + ADD_GROUP("Teaches Spells", "teaches_spells"); + ClassDB::bind_method(D_METHOD("get_num_teaches_spells"), &ItemTemplate::get_num_teaches_spells); + ClassDB::bind_method(D_METHOD("set_num_teaches_spells", "value"), &ItemTemplate::set_num_teaches_spells); + + ClassDB::bind_method(D_METHOD("get_teaches_spell", "index"), &ItemTemplate::get_teaches_spell); + ClassDB::bind_method(D_METHOD("set_teaches_spell", "index", "spell"), &ItemTemplate::set_teaches_spell); + + ClassDB::bind_method(D_METHOD("get_teaches_spells"), &ItemTemplate::get_teaches_spells); + ClassDB::bind_method(D_METHOD("set_teaches_spells", "spells"), &ItemTemplate::set_teaches_spells); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "teaches_spells", PROPERTY_HINT_NONE, "17/17:Spell", PROPERTY_USAGE_DEFAULT, "Spell"), "set_teaches_spells", "get_teaches_spells"); + + //// Grants Spells //// + ADD_GROUP("Grants Spells", "grants_spells"); + ClassDB::bind_method(D_METHOD("get_num_grants_spells"), &ItemTemplate::get_num_grants_spells); + ClassDB::bind_method(D_METHOD("set_num_grants_spells", "value"), &ItemTemplate::set_num_grants_spells); + + ClassDB::bind_method(D_METHOD("get_grants_spell", "index"), &ItemTemplate::get_grants_spell); + ClassDB::bind_method(D_METHOD("set_grants_spell", "index", "spell"), &ItemTemplate::set_grants_spell); + + ClassDB::bind_method(D_METHOD("get_grants_spells"), &ItemTemplate::get_grants_spells); + ClassDB::bind_method(D_METHOD("set_grants_spells", "spells"), &ItemTemplate::set_grants_spells); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "grants_spells", PROPERTY_HINT_NONE, "17/17:Spell", PROPERTY_USAGE_DEFAULT, "Spell"), "set_grants_spells", "get_grants_spells"); + + //// Auras //// + ADD_GROUP("Auras", "auras"); + ClassDB::bind_method(D_METHOD("get_num_auras"), &ItemTemplate::get_num_auras); + ClassDB::bind_method(D_METHOD("set_num_auras", "value"), &ItemTemplate::set_num_auras); ClassDB::bind_method(D_METHOD("get_aura", "index"), &ItemTemplate::get_aura); ClassDB::bind_method(D_METHOD("set_aura", "index", "aura"), &ItemTemplate::set_aura); - for (int i = 0; i < MAX_AURAS; ++i) { - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "aura_" + itos(i + 1), PROPERTY_HINT_RESOURCE_TYPE, "Aura"), "set_aura", "get_aura", i); - } + ClassDB::bind_method(D_METHOD("get_auras"), &ItemTemplate::get_auras); + ClassDB::bind_method(D_METHOD("set_auras", "spells"), &ItemTemplate::set_auras); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "auras", PROPERTY_HINT_NONE, "17/17:Aura", PROPERTY_USAGE_DEFAULT, "Aura"), "set_auras", "get_auras"); //StatMods Property binds + ADD_GROUP("Item Stat Modifiers", "item_stat_modifier"); ClassDB::bind_method(D_METHOD("get_item_stat_modifier_count"), &ItemTemplate::get_item_stat_modifier_count); ClassDB::bind_method(D_METHOD("set_item_stat_modifier_count", "count"), &ItemTemplate::set_item_stat_modifier_count); - ADD_PROPERTY(PropertyInfo(Variant::INT, "set_item_stat_modifier_count", PROPERTY_HINT_RANGE, "0," + itos(MAX_ITEM_STAT_MOD), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_item_stat_modifier_count", "get_item_stat_modifier_count"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "item_stat_modifier_count", PROPERTY_HINT_RANGE, "0," + itos(MAX_ITEM_STAT_MOD), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_item_stat_modifier_count", "get_item_stat_modifier_count"); ClassDB::bind_method(D_METHOD("get_item_stat_id", "index"), &ItemTemplate::get_item_stat_id); ClassDB::bind_method(D_METHOD("set_item_stat_id", "index", "value"), &ItemTemplate::set_item_stat_id); @@ -414,15 +510,12 @@ void ItemTemplate::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::INT, "Modifiers_" + itos(i) + "/stat_id", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_item_stat_id", "get_item_stat_id", i); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "Modifiers_" + itos(i) + "/min_base_mod", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_item_min_base_mod", "get_item_min_base_mod", i); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "Modifiers_" + itos(i) + "/max_base_mod", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_item_max_base_mod", "get_item_max_base_mod", i); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "Modifiers_" + itos(i) + "/min_bonus_mod", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_item_min_bonus_mod", "get_item_min_bonus_mod", i); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "Modifiers_" + itos(i) + "/max_bonus_mod", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_item_max_bonus_mod", "get_item_max_bonus_mod", i); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "Modifiers_" + itos(i) + "/min_percent_mod", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_item_min_percent_mod", "get_item_min_percent_mod", i); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "Modifiers_" + itos(i) + "/max_percent_mod", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_item_max_percent_mod", "get_item_max_percent_mod", i); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "Modifiers_" + itos(i) + "/scaling_factor", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_item_scaling_factor", "get_item_scaling_factor", i); diff --git a/data/item_template.h b/data/item_template.h index 464e76d..a89457e 100644 --- a/data/item_template.h +++ b/data/item_template.h @@ -3,6 +3,7 @@ #include "core/resource.h" #include "scene/resources/texture.h" +#include "core/vector.h" #include "item_visual.h" #include "item_template_stat_modifier.h" @@ -64,11 +65,36 @@ public: int get_bag_size() const; void set_bag_size(const int size); - Ref get_spell() const; - void set_spell(const Ref spell); + //Teaches + int get_num_teaches_spells(); + void set_num_teaches_spells(int value); + + Ref get_teaches_spell(int index) const; + void set_teaches_spell(int index, Ref teaches_spell); + + Vector get_teaches_spells(); + void set_teaches_spells(const Vector &teaches_spells); + + //Grants Spells + int get_num_grants_spells(); + void set_num_grants_spells(int value); + + Ref get_grants_spell(int index) const; + void set_grants_spell(int index, Ref grants_spell); + + Vector get_grants_spells(); + void set_grants_spells(const Vector &grants_spells); + + //Auras + int get_num_auras(); + void set_num_auras(int value); Ref get_aura(int index) const; - void set_aura(const int index, const Ref aura); + void set_aura(int index, Ref aura); + + Vector get_auras(); + void set_auras(const Vector &auras); + int get_item_stat_modifier_count() const; void set_item_stat_modifier_count(const int value); @@ -108,7 +134,6 @@ protected: private: enum { MAX_ITEM_STAT_MOD = 6, - MAX_AURAS = 5, }; int _id; @@ -133,8 +158,13 @@ private: int _bag_size; - Ref *_spell; - Ref *_auras[MAX_AURAS]; + //Ref *_spell; + //Ref *_auras; + + Vector > _teaches_spells; + Vector > _grants_spells; + Vector > _auras; + int _modifier_count; Ref _modifiers[MAX_ITEM_STAT_MOD]; diff --git a/data/skill.h b/data/skill.h index be5cc39..939bb7c 100644 --- a/data/skill.h +++ b/data/skill.h @@ -1,5 +1,5 @@ -#ifndef TALENT_H -#define TALENT_H +#ifndef SKILL_H +#define SKILL_H #include "core/resource.h" #include "core/ustring.h" diff --git a/spell_enums.cpp b/spell_enums.cpp index 1576a76..6096f9d 100644 --- a/spell_enums.cpp +++ b/spell_enums.cpp @@ -1,6 +1,7 @@ #include "spell_enums.h" const String SpellEnums::BINDING_STRING_SPELL_TYPES = "Melee,Holy,Shadow,Nature,Fire,Frost,Lightning,Chaos"; +const String SpellEnums::BINDING_STRING_SPELL_CATEGORY = "Normal,Alchemy,Cooking,Engineering,Crafting,Hidden,Development"; const String SpellEnums::BINDING_STRING_DIMINISHING_RETURN_CATEGORIES = "None,Root,Stun"; const String SpellEnums::BINDING_STRING_TRIGGER_EVENTS = "None,S On Before Damage,S On Damage Receive,S On Hit,S On Damage Dealt,S Aura Remove,S Aura Dispell,S On Before Aura Applied,S On After Aura Applied,C On Aura Added,C On Aura Removed,C On Aura Refreshed"; const String SpellEnums::BINDING_STRING_DAMAGE_TYPES = "Melee,Holy,Shadow,Nature,Fire,Frost,Lightning,Chaos"; diff --git a/spell_enums.h b/spell_enums.h index 2ec34dd..cac3986 100644 --- a/spell_enums.h +++ b/spell_enums.h @@ -8,6 +8,7 @@ class SpellEnums : public Object { public: static const String BINDING_STRING_SPELL_TYPES; + static const String BINDING_STRING_SPELL_CATEGORY; static const String BINDING_STRING_DIMINISHING_RETURN_CATEGORIES; static const String BINDING_STRING_TRIGGER_EVENTS; static const String BINDING_STRING_DAMAGE_TYPES; @@ -25,6 +26,16 @@ public: DAMAGE_TYPE_CHAOS = 1 << 7, }; + enum SpellCategory { + SPELL_CATEGORY_NORMAL = 0, + SPELL_CATEGORY_ALCHEMY = 1, + SPELL_CATEGORY_COOKING = 2, + SPELL_CATEGORY_ENGINEERING = 3, + SPELL_CATEGORY_CRAFTING = 4, + SPELL_CATEGORY_HIDDEN = 5, + SPELL_CATEGORY_DEVELOPMENT = 6, + }; + enum SpellType { SPELL_TYPE_NONE = 0, SPELL_TYPE_MELEE = 1 << 0, @@ -83,6 +94,14 @@ protected: BIND_ENUM_CONSTANT(DAMAGE_TYPE_LIGHTNING); BIND_ENUM_CONSTANT(DAMAGE_TYPE_CHAOS); + BIND_ENUM_CONSTANT(SPELL_CATEGORY_NORMAL); + BIND_ENUM_CONSTANT(SPELL_CATEGORY_ALCHEMY); + BIND_ENUM_CONSTANT(SPELL_CATEGORY_COOKING); + BIND_ENUM_CONSTANT(SPELL_CATEGORY_ENGINEERING); + BIND_ENUM_CONSTANT(SPELL_CATEGORY_CRAFTING); + BIND_ENUM_CONSTANT(SPELL_CATEGORY_HIDDEN); + BIND_ENUM_CONSTANT(SPELL_CATEGORY_DEVELOPMENT); + BIND_ENUM_CONSTANT(SPELL_TYPE_NONE); BIND_ENUM_CONSTANT(SPELL_TYPE_MELEE); BIND_ENUM_CONSTANT(SPELL_TYPE_HOLY); @@ -122,6 +141,7 @@ protected: }; VARIANT_ENUM_CAST(SpellEnums::SpellType); +VARIANT_ENUM_CAST(SpellEnums::SpellCategory); VARIANT_ENUM_CAST(SpellEnums::DiminishingReturnCategory); VARIANT_ENUM_CAST(SpellEnums::TriggerEvents); VARIANT_ENUM_CAST(SpellEnums::DamageType);