diff --git a/data/auras/aura.cpp b/data/auras/aura.cpp index b99515b..fdc0924 100644 --- a/data/auras/aura.cpp +++ b/data/auras/aura.cpp @@ -464,12 +464,12 @@ void Aura::set_aura_stat_attribute_count(int count) { _aura_stat_attribute_count = count; } -Stat::StatId Aura::get_aura_stat_attribute_stat(int index) const { - ERR_FAIL_INDEX_V(index, MAX_AURA_STATS, Stat::STAT_ID_NONE); +int Aura::get_aura_stat_attribute_stat(int index) const { + ERR_FAIL_INDEX_V(index, MAX_AURA_STATS, 0); return _aura_stat_attributes[index]->get_stat(); } -void Aura::set_aura_stat_attribute_stat(int index, const Stat::StatId value) { +void Aura::set_aura_stat_attribute_stat(int index, const int value) { ERR_FAIL_INDEX(index, MAX_AURA_STATS); _aura_stat_attributes[index]->set_stat(value); @@ -1145,7 +1145,7 @@ void Aura::_sapply(Ref info) { for (int i = 0; i < _aura_stat_attribute_count; ++i) { Ref stat_attribute = _aura_stat_attributes[i]; - Ref stat = info->get_target()->get_stat_enum(stat_attribute->get_stat()); + Ref stat = info->get_target()->get_stat(stat_attribute->get_stat()); stat->add_modifier(_id, stat_attribute->get_base_mod(), stat_attribute->get_bonus_mod(), stat_attribute->get_percent_mod()); } @@ -1171,7 +1171,7 @@ void Aura::_sdeapply(Ref data) { for (int i = 0; i < _aura_stat_attribute_count; ++i) { Ref stat_attribute = _aura_stat_attributes[i]; - Ref stat = data->get_owner()->get_stat_enum(stat_attribute->get_stat()); + Ref stat = data->get_owner()->get_stat(stat_attribute->get_stat()); stat->remove_modifier(_id); } @@ -1360,6 +1360,9 @@ void Aura::_validate_property(PropertyInfo &property) const { if (frame >= _aura_stat_attribute_count) { property.usage = 0; } + + if (property.name.ends_with("stat")) + property.hint_string = ESS::get_instance()->stat_get_string(); } else if (prop.begins_with("Trigger_")) { int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int(); if (frame >= _trigger_count) { @@ -1848,7 +1851,7 @@ void Aura::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "attribute_count", PROPERTY_HINT_RANGE, "0," + itos(MAX_AURA_STATS), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_aura_stat_attribute_count", "get_aura_stat_attribute_count"); for (int i = 0; i < MAX_AURA_STATS; i++) { - ADD_PROPERTYI(PropertyInfo(Variant::INT, "StatModAttribute_" + itos(i) + "/stat", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_aura_stat_attribute_stat", "get_aura_stat_attribute_stat", i); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "StatModAttribute_" + itos(i) + "/stat", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_aura_stat_attribute_stat", "get_aura_stat_attribute_stat", i); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "StatModAttribute_" + itos(i) + "/base_mod", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_aura_stat_attribute_base_mod", "get_aura_stat_attribute_base_mod", i); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "StatModAttribute_" + itos(i) + "/bonus_mod", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_aura_stat_attribute_bonus_mod", "get_aura_stat_attribute_bonus_mod", i); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "StatModAttribute_" + itos(i) + "/percent_mod", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_aura_stat_attribute_percent_mod", "get_aura_stat_attribute_percent_mod", i); diff --git a/data/auras/aura.h b/data/auras/aura.h index 0fd10ee..08d086c 100644 --- a/data/auras/aura.h +++ b/data/auras/aura.h @@ -223,8 +223,8 @@ public: int get_aura_stat_attribute_count() const; void set_aura_stat_attribute_count(int count); - Stat::StatId get_aura_stat_attribute_stat(int index) const; - void set_aura_stat_attribute_stat(int index, const Stat::StatId value); + int get_aura_stat_attribute_stat(int index) const; + void set_aura_stat_attribute_stat(int index, const int value); float get_aura_stat_attribute_base_mod(int index) const; void set_aura_stat_attribute_base_mod(int index, float value); diff --git a/data/auras/aura_stat_attribute.h b/data/auras/aura_stat_attribute.h index 58fb88a..40ccf97 100644 --- a/data/auras/aura_stat_attribute.h +++ b/data/auras/aura_stat_attribute.h @@ -26,12 +26,14 @@ SOFTWARE. #include "../../entities/stats/stat.h" #include "core/reference.h" +#include "../../singletons/ess.h" + class AuraStatAttribute : public Reference { GDCLASS(AuraStatAttribute, Reference); public: - Stat::StatId get_stat() const { return _stat; } - void set_stat(Stat::StatId value) { _stat = value; } + int get_stat() const { return _stat; } + void set_stat(int value) { _stat = value; } float get_base_mod() const { return _base_mod; } void set_base_mod(float value) { _base_mod = value; } @@ -43,17 +45,23 @@ public: void set_percent_mod(float value) { _percent_mod = value; } AuraStatAttribute() { - _stat = Stat::STAT_ID_NONE; + _stat = 0; _base_mod = 0; _bonus_mod = 0; _percent_mod = 0; } protected: + void validate_property(PropertyInfo &property) const { + if (property.name == "stat") { + property.hint_string = ESS::get_instance()->stat_get_string(); + } + } + static void _bind_methods() { ClassDB::bind_method(D_METHOD("get_stat"), &AuraStatAttribute::get_stat); ClassDB::bind_method(D_METHOD("set_stat", "value"), &AuraStatAttribute::set_stat); - ADD_PROPERTY(PropertyInfo(Variant::INT, "stat", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING), "set_stat", "get_stat"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stat", PROPERTY_HINT_ENUM, ""), "set_stat", "get_stat"); ClassDB::bind_method(D_METHOD("get_base_mod"), &AuraStatAttribute::get_base_mod); ClassDB::bind_method(D_METHOD("set_base_mod", "value"), &AuraStatAttribute::set_base_mod); @@ -69,7 +77,7 @@ protected: } private: - Stat::StatId _stat; + int _stat; float _base_mod; float _bonus_mod; float _percent_mod; diff --git a/data/items/item_stat_modifier.cpp b/data/items/item_stat_modifier.cpp index 074f5d3..a2b8ada 100644 --- a/data/items/item_stat_modifier.cpp +++ b/data/items/item_stat_modifier.cpp @@ -22,11 +22,13 @@ SOFTWARE. #include "item_stat_modifier.h" -Stat::StatId ItemStatModifier::get_stat_id() { +#include "../../singletons/ess.h" + +int ItemStatModifier::get_stat_id() { return _stat_id; } -void ItemStatModifier::set_stat_id(Stat::StatId value) { +void ItemStatModifier::set_stat_id(int value) { _stat_id = value; } @@ -75,23 +77,29 @@ Dictionary ItemStatModifier::_to_dict() { void ItemStatModifier::_from_dict(const Dictionary &dict) { ERR_FAIL_COND(dict.empty()); - _stat_id = static_cast(static_cast(dict.get("stat_id", 0))); + _stat_id = dict.get("stat_id", 0); _base_mod = dict.get("base_mod", 0); _bonus_mod = dict.get("bonus_mod", 0); _percent_mod = dict.get("percent_mod", 0); } ItemStatModifier::ItemStatModifier() { - _stat_id = Stat::STAT_ID_HEALTH; + _stat_id = 0; _base_mod = 0; _bonus_mod = 0; _percent_mod = 0; } +void ItemStatModifier::_validate_property(PropertyInfo &property) const { + if (property.name == "stat_id") { + property.hint_string = ESS::get_instance()->stat_get_string(); + } +} + void ItemStatModifier::_bind_methods() { ClassDB::bind_method(D_METHOD("get_stat_id"), &ItemStatModifier::get_stat_id); ClassDB::bind_method(D_METHOD("set_stat_id", "value"), &ItemStatModifier::set_stat_id); - ADD_PROPERTY(PropertyInfo(Variant::INT, "stat_id", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING), "set_stat_id", "get_stat_id"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stat_id", PROPERTY_HINT_ENUM, ""), "set_stat_id", "get_stat_id"); ClassDB::bind_method(D_METHOD("get_base_mod"), &ItemStatModifier::get_base_mod); ClassDB::bind_method(D_METHOD("set_base_mod", "value"), &ItemStatModifier::set_base_mod); diff --git a/data/items/item_stat_modifier.h b/data/items/item_stat_modifier.h index b2056ae..3cef867 100644 --- a/data/items/item_stat_modifier.h +++ b/data/items/item_stat_modifier.h @@ -36,8 +36,8 @@ class ItemStatModifier : public Reference { GDCLASS(ItemStatModifier, Reference); public: - Stat::StatId get_stat_id(); - void set_stat_id(Stat::StatId value); + int get_stat_id(); + void set_stat_id(int value); float get_base_mod(); void set_base_mod(float value); @@ -57,10 +57,11 @@ public: ItemStatModifier(); protected: + void _validate_property(PropertyInfo &property) const; static void _bind_methods(); private: - Stat::StatId _stat_id; + int _stat_id; float _base_mod; float _bonus_mod; float _percent_mod; diff --git a/data/items/item_template.cpp b/data/items/item_template.cpp index 92af697..6764fe7 100644 --- a/data/items/item_template.cpp +++ b/data/items/item_template.cpp @@ -27,6 +27,8 @@ SOFTWARE. #include "../spells/spell.h" #include "item_instance.h" +#include "../../singletons/ess.h" + #include "core/version.h" int ItemTemplate::get_id() const { @@ -341,11 +343,11 @@ void ItemTemplate::set_item_stat_modifier_count(int value) { _modifier_count = value; } -Stat::StatId ItemTemplate::get_item_stat_id(const int index) const { +int ItemTemplate::get_item_stat_id(const int index) const { return _modifiers[index]->get_stat_id(); } -void ItemTemplate::set_item_stat_id(const int index, const Stat::StatId value) { +void ItemTemplate::set_item_stat_id(const int index, const int value) { _modifiers[index]->set_stat_id(value); } @@ -492,6 +494,9 @@ void ItemTemplate::_validate_property(PropertyInfo &property) const { if (frame >= _modifier_count) { property.usage = 0; } + + if (property.name.ends_with("stat_id")) + property.hint_string = ESS::get_instance()->stat_get_string(); } } @@ -656,7 +661,7 @@ void ItemTemplate::_bind_methods() { ClassDB::bind_method(D_METHOD("set_item_scaling_factor", "index", "value"), &ItemTemplate::set_item_scaling_factor); for (int i = 0; i < MAX_ITEM_STAT_MOD; ++i) { - 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::INT, "Modifiers_" + itos(i) + "/stat_id", PROPERTY_HINT_ENUM, "", 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); diff --git a/data/items/item_template.h b/data/items/item_template.h index a7b456a..fe5cbf4 100644 --- a/data/items/item_template.h +++ b/data/items/item_template.h @@ -145,8 +145,8 @@ public: int get_item_stat_modifier_count() const; void set_item_stat_modifier_count(const int value); - Stat::StatId get_item_stat_id(int index) const; - void set_item_stat_id(int index, Stat::StatId value); + int get_item_stat_id(int index) const; + void set_item_stat_id(int index, int value); float get_item_min_base_mod(const int index) const; void set_item_min_base_mod(const int index, const float value); @@ -182,8 +182,8 @@ public: }; protected: - static void _bind_methods(); void _validate_property(PropertyInfo &property) const; + static void _bind_methods(); private: enum { diff --git a/data/items/item_template_stat_modifier.cpp b/data/items/item_template_stat_modifier.cpp index 26ef297..1aacc10 100644 --- a/data/items/item_template_stat_modifier.cpp +++ b/data/items/item_template_stat_modifier.cpp @@ -22,11 +22,13 @@ SOFTWARE. #include "item_template_stat_modifier.h" -Stat::StatId ItemTemplateStatModifier::get_stat_id() const { +#include "../../singletons/ess.h" + +int ItemTemplateStatModifier::get_stat_id() const { return _stat_id; } -void ItemTemplateStatModifier::set_stat_id(const Stat::StatId value) { +void ItemTemplateStatModifier::set_stat_id(const int value) { _stat_id = value; } @@ -87,7 +89,7 @@ void ItemTemplateStatModifier::set_scaling_factor(const float value) { } ItemTemplateStatModifier::ItemTemplateStatModifier() { - _stat_id = Stat::STAT_ID_HEALTH; + _stat_id = 0; _min_mod_max = 0; _max_mod_max = 0; _min_mod_precent = 0; @@ -95,10 +97,16 @@ ItemTemplateStatModifier::ItemTemplateStatModifier() { _scaling_factor = 1; } +void ItemTemplateStatModifier::_validate_property(PropertyInfo &property) const { + if (property.name == "stat_id") { + property.hint_string = ESS::get_instance()->stat_get_string(); + } +} + void ItemTemplateStatModifier::_bind_methods() { ClassDB::bind_method(D_METHOD("get_stat_id"), &ItemTemplateStatModifier::get_stat_id); ClassDB::bind_method(D_METHOD("set_stat_id", "value"), &ItemTemplateStatModifier::set_stat_id); - ADD_PROPERTY(PropertyInfo(Variant::INT, "stat_id", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING), "set_stat_id", "get_stat_id"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stat_id", PROPERTY_HINT_ENUM, ""), "set_stat_id", "get_stat_id"); ClassDB::bind_method(D_METHOD("get_min_base_mod"), &ItemTemplateStatModifier::get_min_base_mod); ClassDB::bind_method(D_METHOD("set_min_base_mod", "value"), &ItemTemplateStatModifier::set_min_base_mod); diff --git a/data/items/item_template_stat_modifier.h b/data/items/item_template_stat_modifier.h index c42ff46..5a03a0d 100644 --- a/data/items/item_template_stat_modifier.h +++ b/data/items/item_template_stat_modifier.h @@ -36,8 +36,8 @@ class ItemTemplateStatModifier : public Reference { GDCLASS(ItemTemplateStatModifier, Reference); public: - Stat::StatId get_stat_id() const; - void set_stat_id(const Stat::StatId value); + int get_stat_id() const; + void set_stat_id(const int value); float get_min_base_mod() const; void set_min_base_mod(const float value); @@ -63,10 +63,11 @@ public: ItemTemplateStatModifier(); protected: + virtual void _validate_property(PropertyInfo &property) const; static void _bind_methods(); private: - Stat::StatId _stat_id; + int _stat_id; float _min_mod_max; float _max_mod_max; diff --git a/data/spells/spell.cpp b/data/spells/spell.cpp index d12b508..eae482c 100644 --- a/data/spells/spell.cpp +++ b/data/spells/spell.cpp @@ -396,10 +396,10 @@ void Spell::set_damage_max(const int value) { _damage_max = value; } -Stat::StatId Spell::get_damage_scale_stat() const { +int Spell::get_damage_scale_stat() const { return _damage_scale_stat; } -void Spell::set_damage_scale_stat(const Stat::StatId value) { +void Spell::set_damage_scale_stat(const int value) { _damage_scale_stat = value; } @@ -431,10 +431,10 @@ void Spell::set_heal_max(const int value) { _heal_max = value; } -Stat::StatId Spell::get_heal_scale_stat() const { +int Spell::get_heal_scale_stat() const { return _heal_scale_stat; } -void Spell::set_heal_scale_stat(const Stat::StatId value) { +void Spell::set_heal_scale_stat(const int value) { _heal_scale_stat = value; } @@ -773,7 +773,10 @@ void Spell::handle_gcd(Ref info) { ERR_FAIL_COND(!info.is_valid()); if (_global_cooldown_enabled && _cast_time_enabled) { - info->get_caster()->sstart_global_cooldown(info->get_caster()->get_gcd()->gets_current()); + Ref gcd = info->get_caster()->get_stat(ESS::get_instance()->stat_get_id("Global Cooldown")); + + if (gcd.is_valid()) + info->get_caster()->sstart_global_cooldown(gcd->gets_current()); } } void Spell::handle_cooldown(Ref info) { @@ -876,13 +879,13 @@ Spell::Spell() { _damage_type = 0; _damage_min = 0; _damage_max = 0; - _damage_scale_stat = Stat::STAT_ID_NONE; + _damage_scale_stat = 0; _damage_scale_coeff = 0; _heal_enabled = false; _heal_min = 0; _heal_max = 0; - _heal_scale_stat = Stat::STAT_ID_NONE; + _heal_scale_stat = 0; _heal_scale_coeff = 0; _dispell_enabled = false; @@ -1130,6 +1133,12 @@ void Spell::_handle_effect(Ref info) { } } +void Spell::_validate_property(PropertyInfo &property) const { + if (property.name.ends_with("_stat")) { + property.hint_string = ESS::get_instance()->stat_get_string(); + } +} + void Spell::_bind_methods() { //Commands ClassDB::bind_method(D_METHOD("sstart_casting", "info"), &Spell::sstart_casting); @@ -1382,7 +1391,7 @@ void Spell::_bind_methods() { ClassDB::bind_method(D_METHOD("get_damage_scale_stat"), &Spell::get_damage_scale_stat); ClassDB::bind_method(D_METHOD("set_damage_scale_stat", "value"), &Spell::set_damage_scale_stat); - ADD_PROPERTY(PropertyInfo(Variant::INT, "damage_scale_stat", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING), "set_damage_scale_stat", "get_damage_scale_stat"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "damage_scale_stat", PROPERTY_HINT_ENUM, ""), "set_damage_scale_stat", "get_damage_scale_stat"); ClassDB::bind_method(D_METHOD("get_damage_scale_coeff"), &Spell::get_damage_scale_coeff); ClassDB::bind_method(D_METHOD("set_damage_scale_coeff", "value"), &Spell::set_damage_scale_coeff); @@ -1403,7 +1412,7 @@ void Spell::_bind_methods() { ClassDB::bind_method(D_METHOD("get_heal_scale_stat"), &Spell::get_heal_scale_stat); ClassDB::bind_method(D_METHOD("set_heal_scale_stat", "value"), &Spell::set_heal_scale_stat); - ADD_PROPERTY(PropertyInfo(Variant::INT, "heal_scale_stat", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING), "set_heal_scale_stat", "get_heal_scale_stat"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "heal_scale_stat", PROPERTY_HINT_ENUM, ""), "set_heal_scale_stat", "get_heal_scale_stat"); ClassDB::bind_method(D_METHOD("get_heal_scale_coeff"), &Spell::get_heal_scale_coeff); ClassDB::bind_method(D_METHOD("set_heal_scale_coeff", "value"), &Spell::set_heal_scale_coeff); diff --git a/data/spells/spell.h b/data/spells/spell.h index 86d4db9..c4d8b79 100644 --- a/data/spells/spell.h +++ b/data/spells/spell.h @@ -214,8 +214,8 @@ public: int get_damage_max() const; void set_damage_max(const int value); - Stat::StatId get_damage_scale_stat() const; - void set_damage_scale_stat(const Stat::StatId value); + int get_damage_scale_stat() const; + void set_damage_scale_stat(const int value); float get_damage_scale_coeff() const; void set_damage_scale_coeff(const float value); @@ -229,8 +229,8 @@ public: int get_heal_max() const; void set_heal_max(const int value); - Stat::StatId get_heal_scale_stat() const; - void set_heal_scale_stat(const Stat::StatId value); + int get_heal_scale_stat() const; + void set_heal_scale_stat(const int value); float get_heal_scale_coeff() const; void set_heal_scale_coeff(const float value); @@ -356,6 +356,7 @@ protected: virtual void _handle_projectile(Ref info); virtual void _handle_effect(Ref info); + void _validate_property(PropertyInfo &property) const; static void _bind_methods(); private: @@ -408,13 +409,13 @@ private: int _damage_type; int _damage_min; int _damage_max; - Stat::StatId _damage_scale_stat; + int _damage_scale_stat; float _damage_scale_coeff; bool _heal_enabled; int _heal_min; int _heal_max; - Stat::StatId _heal_scale_stat; + int _heal_scale_stat; float _heal_scale_coeff; bool _dispell_enabled; diff --git a/entities/entity.cpp b/entities/entity.cpp index c5beb24..d9af51a 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -567,10 +567,10 @@ void Entity::_setup() { ERR_FAIL_COND(!stat_data.is_valid()); - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { - Ref sde = stat_data->get_stat_data_int(i); + for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) { + Ref sde = stat_data->get_stat_data(i); - _stats[i]->set_stat_data_entry(sde); + _stats.get(i)->set_stat_data_entry(sde); } sets_ai(_s_entity_data->get_ai_instance()); @@ -631,11 +631,11 @@ void Entity::_setup() { ERR_FAIL_COND(!cc.is_valid()); - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { + for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) { cc->get_stat_data()->get_stat_for_stat(_stats[i]); } - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { + for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) { Ref s = _stats[i]; s->apply_modifiers(); @@ -1092,7 +1092,7 @@ Dictionary Entity::_to_dict() { Dictionary sd; - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { + for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) { Ref s = _stats[i]; sd[i] = s->to_dict(); @@ -1272,7 +1272,7 @@ void Entity::_from_dict(const Dictionary &dict) { Dictionary stats = dict.get("stats", Dictionary()); - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { + for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) { Ref s = _stats[i]; s->from_dict(stats.get(String::num(i), Dictionary())); @@ -1809,32 +1809,16 @@ int Entity::getc_craft_recipe_count() { //// Stat System //// -Ref Entity::get_stat_int(int index) { +Ref Entity::get_stat(int index) { + ERR_FAIL_INDEX_V(index, ESS::get_instance()->stat_get_count(), Ref()); + return _stats[index]; } -void Entity::set_stat_int(int index, Ref entry) { - _stats[index] = Ref(entry); -} +void Entity::set_stat(int index, Ref entry) { + ERR_FAIL_INDEX(index, ESS::get_instance()->stat_get_count()); -Ref Entity::get_stat_enum(Stat::StatId stat_id) { - ERR_FAIL_INDEX_V(stat_id, Stat::STAT_ID_TOTAL_STATS, Ref()); - - return _stats[stat_id]; -} - -void Entity::set_stat_enum(Stat::StatId stat_id, Ref entry) { - ERR_FAIL_COND(!entry.is_valid()); - - //ERR_FAIL_COND(stat_id == Stat::STAT_ID_NONE); - - if (stat_id == Stat::STAT_ID_NONE) { - print_error("Add fail cond here, stat has STAT_ID_NONE!"); - _stats[0] = Ref(entry); - return; - } - - _stats[stat_id] = Ref(entry); + _stats.set(index, entry); } void Entity::sdie() { @@ -1867,20 +1851,23 @@ void Entity::onc_stat_changed(Ref stat) { } void Entity::ssend_stat(int id, int ccurrent, int cmax) { - ERR_FAIL_INDEX(id, Stat::STAT_ID_TOTAL_STATS); + ERR_FAIL_INDEX(id, ESS::get_instance()->stat_get_count()); - if (id <= Stat::STAT_ID_MANA) { - VRPC(creceive_stat, id, ccurrent, cmax); - return; - } + //TODO, mark stats that should be sent to all clients like health + //if (id <= ESS::get_instance()->stat_get_main_stat_count()) { + // VRPC(creceive_stat, id, ccurrent, cmax); + // return; + //} - ORPC(creceive_stat, id, ccurrent, cmax); + VRPC(creceive_stat, id, ccurrent, cmax); + + //ORPC(creceive_stat, id, ccurrent, cmax); } void Entity::creceive_stat(int id, int ccurrent, int cmax) { - ERR_FAIL_INDEX(id, Stat::STAT_ID_TOTAL_STATS); + ERR_FAIL_INDEX(id, ESS::get_instance()->stat_get_count()); - _stats[id]->setc_values(ccurrent, cmax); + _stats.get(id)->setc_values(ccurrent, cmax); } //// Equip Slots //// @@ -2099,7 +2086,7 @@ void Entity::_sapply_item(Ref item) { if (!mod.is_valid()) continue; - Ref stat = get_stat_enum(mod->get_stat_id()); + Ref stat = get_stat(mod->get_stat_id()); ERR_CONTINUE(!stat.is_valid()); @@ -2125,7 +2112,7 @@ void Entity::_sdeapply_item(Ref item) { if (!mod.is_valid()) continue; - Ref stat = get_stat_enum(mod->get_stat_id()); + Ref stat = get_stat(mod->get_stat_id()); ERR_CONTINUE(!stat.is_valid()); @@ -2386,13 +2373,16 @@ void Entity::stake_damage(Ref info) { son_damage_receive(info); - int h = get_health()->gets_current() - info->get_damage(); + Ref hp = get_stat(ESS::get_instance()->stat_get_id("Health")); + ERR_FAIL_COND(!hp.is_valid()); + + int h = hp->gets_current() - info->get_damage(); if (h < 0) { h = 0; } - get_health()->sets_current(h); + hp->sets_current(h); son_damage_dealt(info); @@ -2402,7 +2392,7 @@ void Entity::stake_damage(Ref info) { //send an event to client VRPCOBJ(cdamage_dealt_rpc, JSON::print(info->to_dict()), con_damage_dealt, info); - if (get_health()->gets_current() <= 0) { + if (hp->gets_current() <= 0) { sdie(); } } @@ -2426,7 +2416,10 @@ void Entity::sdeal_damage_to(Ref info) { //signal emit_signal("son_damage_received", this, info); - if (get_health()->gets_current() <= 0) { + Ref hp = get_stat(ESS::get_instance()->stat_get_id("Health")); + ERR_FAIL_COND(!hp.is_valid()); + + if (hp->gets_current() <= 0) { sdie(); } } @@ -2455,12 +2448,15 @@ void Entity::stake_heal(Ref info) { son_heal_receive(info); - int h = get_health()->gets_current() + info->get_heal(); + Ref hp = get_stat(ESS::get_instance()->stat_get_id("Health")); + ERR_FAIL_COND(!hp.is_valid()); - if (h > get_health()->gets_max()) { - h = get_health()->gets_max(); + int h = hp->gets_current() + info->get_heal(); + + if (h > hp->gets_max()) { + h = hp->gets_max(); } - get_health()->sets_current(h); + hp->sets_current(h); //send an event to client VRPCOBJ(cheal_dealt_rpc, JSON::print(info->to_dict()), con_heal_dealt, info); @@ -5766,7 +5762,7 @@ void Entity::update(float delta) { } } - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { + for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) { Ref s = _stats[i]; if (s->get_dirty_mods()) @@ -6141,10 +6137,11 @@ Entity::Entity() { //_action_bar_profile.instance(); _actionbar_locked = false; - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { - Ref s = Ref(memnew(Stat(static_cast(i), this))); + _stats.resize(ESS::get_instance()->stat_get_count()); + for (int i = 0; i < _stats.size(); ++i) { + Ref s = Ref(memnew(Stat(i, this))); - _stats[i] = s; + _stats.set(i, s); } _sai_state = EntityEnums::AI_STATE_OFF; @@ -6386,9 +6383,7 @@ Entity::~Entity() { _s_talents.clear(); _c_talents.clear(); - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { - _stats[i].unref(); - } + _stats.clear(); for (int i = 0; i < ItemEnums::EQUIP_SLOT_EQUIP_SLOT_MAX; ++i) { _s_equipment[i].unref(); @@ -6488,7 +6483,7 @@ void Entity::_son_character_level_up(int level) { int statid = i + Stat::MAIN_STAT_ID_START; - Ref stat = get_stat_int(statid); + Ref stat = get_stat(statid); Ref sm = stat->get_modifier(0); sm->set_base_mod(sm->get_base_mod() + st); @@ -6700,7 +6695,7 @@ bool Entity::_set(const StringName &p_name, const Variant &p_value) { if (!stat.is_valid()) { stat.instance(); stat->set_owner(this); - _stats[stat_id] = stat; + _stats.set(stat_id, stat); } if (stat_prop_name == "public") { @@ -7259,7 +7254,7 @@ void Entity::_get_property_list(List *p_list) const { //int property_usange = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL; int property_usange = PROPERTY_USAGE_DEFAULT; - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { + for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) { Ref stat = _stats[i]; if (!stat.is_valid()) @@ -7840,33 +7835,11 @@ void Entity::_bind_methods() { ClassDB::bind_method(D_METHOD("setc_entity_data", "value"), &Entity::setc_entity_data); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "centity_data", PROPERTY_HINT_RESOURCE_TYPE, "EntityData", 0), "setc_entity_data", "getc_entity_data"); - ClassDB::bind_method(D_METHOD("get_health"), &Entity::get_health); - ClassDB::bind_method(D_METHOD("get_mana"), &Entity::get_mana); - ClassDB::bind_method(D_METHOD("get_rage"), &Entity::get_rage); - ClassDB::bind_method(D_METHOD("get_energy"), &Entity::get_energy); - ClassDB::bind_method(D_METHOD("get_speed"), &Entity::get_speed); - ClassDB::bind_method(D_METHOD("get_gcd"), &Entity::get_gcd); - ClassDB::bind_method(D_METHOD("get_melee_crit"), &Entity::get_melee_crit); - ClassDB::bind_method(D_METHOD("get_melee_crit_bonus"), &Entity::get_melee_crit_bonus); - ClassDB::bind_method(D_METHOD("get_spell_crit"), &Entity::get_spell_crit); - ClassDB::bind_method(D_METHOD("get_spell_crit_bonus"), &Entity::get_spell_crit_bonus); - ClassDB::bind_method(D_METHOD("get_block"), &Entity::get_block); - ClassDB::bind_method(D_METHOD("get_parry"), &Entity::get_parry); - ClassDB::bind_method(D_METHOD("get_damage_reduction"), &Entity::get_damage_reduction); - ClassDB::bind_method(D_METHOD("get_melee_damage_reduction"), &Entity::get_melee_damage_reduction); - ClassDB::bind_method(D_METHOD("get_spell_damage_reduction"), &Entity::get_spell_damage_reduction); - ClassDB::bind_method(D_METHOD("get_damage_taken"), &Entity::get_damage_taken); - ClassDB::bind_method(D_METHOD("get_melee_damage"), &Entity::get_melee_damage); - ClassDB::bind_method(D_METHOD("get_spell_damage"), &Entity::get_spell_damage); - - ClassDB::bind_method(D_METHOD("get_stat_int", "index"), &Entity::get_stat_int); - ClassDB::bind_method(D_METHOD("set_stat_int", "index", "entry"), &Entity::set_stat_int); - - ClassDB::bind_method(D_METHOD("get_stat_enum", "index"), &Entity::get_stat_enum); - ClassDB::bind_method(D_METHOD("set_stat_enum", "stat_id", "entry"), &Entity::set_stat_enum); + ClassDB::bind_method(D_METHOD("get_stat", "index"), &Entity::get_stat); + ClassDB::bind_method(D_METHOD("set_stat", "index", "entry"), &Entity::set_stat); //todo - //for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { + //for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) { // ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "stats/" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "Stat"), "set_stat_int", "get_stat_int", i); //} diff --git a/entities/entity.h b/entities/entity.h index b406311..5ae38fd 100644 --- a/entities/entity.h +++ b/entities/entity.h @@ -333,34 +333,8 @@ public: void setc_seed(int value); //// Stats //// - - _FORCE_INLINE_ Ref get_health() { return _stats[Stat::STAT_ID_HEALTH]; } - _FORCE_INLINE_ Ref get_mana() { return _stats[Stat::STAT_ID_MANA]; } - _FORCE_INLINE_ Ref get_energy() { return _stats[Stat::STAT_ID_RAGE]; } - _FORCE_INLINE_ Ref get_rage() { return _stats[Stat::STAT_ID_ENERGY]; } - _FORCE_INLINE_ Ref get_speed() { return _stats[Stat::STAT_ID_SPEED]; } - _FORCE_INLINE_ Ref get_gcd() { return _stats[Stat::STAT_ID_GLOBAL_COOLDOWN]; } - - _FORCE_INLINE_ Ref get_melee_crit() { return _stats[Stat::STAT_ID_MELEE_CRIT]; } - _FORCE_INLINE_ Ref get_melee_crit_bonus() { return _stats[Stat::STAT_ID_MELEE_CRIT_BONUS]; } - _FORCE_INLINE_ Ref get_spell_crit() { return _stats[Stat::STAT_ID_SPELL_CRIT]; } - _FORCE_INLINE_ Ref get_spell_crit_bonus() { return _stats[Stat::STAT_ID_SPELL_CRIT_BONUS]; } - - _FORCE_INLINE_ Ref get_block() { return _stats[Stat::STAT_ID_BLOCK]; } - _FORCE_INLINE_ Ref get_parry() { return _stats[Stat::STAT_ID_PARRY]; } - _FORCE_INLINE_ Ref get_damage_reduction() { return _stats[Stat::STAT_ID_DAMAGE_REDUCTION]; } - _FORCE_INLINE_ Ref get_melee_damage_reduction() { return _stats[Stat::STAT_ID_MELEE_DAMAGE_REDUCTION]; } - _FORCE_INLINE_ Ref get_spell_damage_reduction() { return _stats[Stat::STAT_ID_SPELL_DAMAGE_REDUCTION]; } - _FORCE_INLINE_ Ref get_damage_taken() { return _stats[Stat::STAT_ID_DAMAGE_TAKEN]; } - _FORCE_INLINE_ Ref get_heal_taken() { return _stats[Stat::STAT_ID_HEAL_TAKEN]; } - _FORCE_INLINE_ Ref get_melee_damage() { return _stats[Stat::STAT_ID_MELEE_DAMAGE]; } - _FORCE_INLINE_ Ref get_spell_damage() { return _stats[Stat::STAT_ID_SPELL_DAMAGE]; } - - Ref get_stat_int(int index); - void set_stat_int(int index, Ref entry); - - Ref get_stat_enum(Stat::StatId stat_id); - void set_stat_enum(Stat::StatId stat_id, Ref entry); + Ref get_stat(int index); + void set_stat(int index, Ref entry); void sdie(); void cdie(); @@ -1105,7 +1079,7 @@ private: //// Stats //// - Ref _stats[Stat::STAT_ID_TOTAL_STATS]; + Vector > _stats; //// Equipment //// @@ -1204,7 +1178,7 @@ private: //// Stat Allocations //// //int _unallocated_stats; - //int _stat_allocations[Stat::STAT_ID_TOTAL_STATS]; + //int _stat_allocations[ESS::get_instance()->stat_get_count()]; //// Inventory //// diff --git a/entities/stats/stat.cpp b/entities/stats/stat.cpp index 597af5e..6137741 100644 --- a/entities/stats/stat.cpp +++ b/entities/stats/stat.cpp @@ -22,118 +22,20 @@ SOFTWARE. #include "stat.h" +#include "../../singletons/ess.h" #include "../entity.h" #include "stat_data_entry.h" #include "core/version.h" -const String Stat::STAT_BINDING_STRING = "Health,Speed,Mana,GCD,Haste,Agility,Strength,Stamina,Intellect,Spirit,Haste Rating,Resilience,Armor,Attack Power,Spell Power,Melee Crit,Melee Crit bonus,Spell Crit,Spell Crit Bonus,Block,Parry,Damage Reduction,Melee Damage Reduction,Spell Damage Reduction,Damage Taken,Heal Taken,Melee Damage,Spell Damage,Holy Resist,Shadow Resist,Nature Resist,Fire Resist,Frost Resist,Lightning Resist,Chaos Resist,Silence Resist,Fear Resist,Stun Resist,Energy,Rage,XP Rate,None"; const String Stat::MAIN_STAT_BINDING_STRING = "Agility,Strength,Stamina,Intellect,Spirit"; const String Stat::MODIFIER_APPLY_TYPE_BINDING_STRING = "Standard,Only min modifier,Only Max modifier"; -String Stat::stat_id_name(int stat_id) { - switch (stat_id) { - case STAT_ID_HEALTH: - return "health"; - case STAT_ID_SPEED: - return "speed"; - case STAT_ID_MANA: - return "mana"; - case STAT_ID_GLOBAL_COOLDOWN: - return "gcd"; - case STAT_ID_HASTE: - return "haste"; - - case STAT_ID_AGILITY: - return "agility"; - case STAT_ID_STRENGTH: - return "strength"; - case STAT_ID_STAMINA: - return "stamina"; - case STAT_ID_INTELLECT: - return "intellect"; - case STAT_ID_SPIRIT: - return "spirit"; - - case STAT_ID_HASTE_RATING: - return "haste_rating"; - case STAT_ID_RESLILIENCE: - return "resilience"; - case STAT_ID_ARMOR: - return "armor"; - - case STAT_ID_ATTACK_POWER: - return "attack_power"; - case STAT_ID_SPELL_POWER: - return "spell_power"; - - case STAT_ID_MELEE_CRIT: - return "melee_crit"; - case STAT_ID_MELEE_CRIT_BONUS: - return "melee_crit_bonus"; - case STAT_ID_SPELL_CRIT: - return "spell_crit"; - case STAT_ID_SPELL_CRIT_BONUS: - return "spell_crit_bonus"; - - case STAT_ID_BLOCK: - return "block"; - case STAT_ID_PARRY: - return "parry"; - case STAT_ID_DAMAGE_REDUCTION: - return "damage_reduction"; - case STAT_ID_MELEE_DAMAGE_REDUCTION: - return "melee_damage_reduction"; - case STAT_ID_SPELL_DAMAGE_REDUCTION: - return "spell_damage_reduction"; - case STAT_ID_DAMAGE_TAKEN: - return "damage_taken"; - case STAT_ID_HEAL_TAKEN: - return "heal_taken"; - - case STAT_ID_MELEE_DAMAGE: - return "melee_damage"; - case STAT_ID_SPELL_DAMAGE: - return "spell_damage"; - - case STAT_ID_HOLY_RESIST: - return "holy_resist"; - case STAT_ID_SHADOW_RESIST: - return "shadow_resist"; - case STAT_ID_NATURE_RESIST: - return "nature_resist"; - case STAT_ID_FIRE_RESIST: - return "fire_resist"; - case STAT_ID_FROST_RESIST: - return "frost_resist"; - case STAT_ID_LIGHTNING_RESIST: - return "lightning_resist"; - case STAT_ID_CHAOS_RESIST: - return "chaos_resist"; - case STAT_ID_SILENCE_RESIST: - return "silence_resist"; - case STAT_ID_FEAR_RESIST: - return "fear_resist"; - case STAT_ID_STUN_RESIST: - return "stun_resist"; - - case STAT_ID_ENERGY: - return "energy"; - case STAT_ID_RAGE: - return "rage"; - - case STAT_ID_XP_RATE: - return "xp_rate"; - } - - return ""; -} - -Stat::StatId Stat::get_id() { +int Stat::get_id() { return _id; } -void Stat::set_id(Stat::StatId id) { +void Stat::set_id(int id) { _id = id; } @@ -384,7 +286,7 @@ void Stat::apply_modifiers() { _dirty_mods = false; for (int i = 0; i < _stat_data_entry->get_mod_stat_count(); ++i) { - Ref stat = _owner->get_stat_enum(_stat_data_entry->get_mod_stat_id(i)); + Ref stat = _owner->get_stat(_stat_data_entry->get_mod_stat_id(i)); Ref curve = _stat_data_entry->get_mod_stat_curve(i); float max_value = _stat_data_entry->get_mod_stat_max_value(i); @@ -481,7 +383,7 @@ Dictionary Stat::_to_dict() { void Stat::_from_dict(const Dictionary &dict) { ERR_FAIL_COND(dict.empty()); - _id = (Stat::StatId)((int)dict.get("id", 0)); + _id = dict.get("id", 0); _modifier_apply_type = (StatModifierApplyType)((int)dict.get("modifier_apply_type", 0)); _public = dict.get("public", false); @@ -518,7 +420,7 @@ void Stat::_from_dict(const Dictionary &dict) { } Stat::Stat() { - _id = Stat::STAT_ID_NONE; + _id = 0; _owner = NULL; _modifier_apply_type = MODIFIER_APPLY_TYPE_STANDARD; @@ -540,7 +442,7 @@ Stat::Stat() { _c_max = 0; } -Stat::Stat(Stat::StatId id, Entity *owner) { +Stat::Stat(int id, Entity *owner) { _id = id; _owner = owner; @@ -563,7 +465,7 @@ Stat::Stat(Stat::StatId id, Entity *owner) { _c_max = 0; } -Stat::Stat(Stat::StatId id, StatModifierApplyType modifier_apply_type, Entity *owner) { +Stat::Stat(int id, StatModifierApplyType modifier_apply_type, Entity *owner) { _id = id; _owner = owner; @@ -592,13 +494,19 @@ Stat::~Stat() { _stat_data_entry.unref(); } +void Stat::_validate_property(PropertyInfo &property) const { + if (property.name == "id") { + property.hint_string = ESS::get_instance()->stat_get_string(); + } +} + void Stat::_bind_methods() { ADD_SIGNAL(MethodInfo("s_changed", PropertyInfo(Variant::OBJECT, "stat", PROPERTY_HINT_RESOURCE_TYPE, "Stat"))); ADD_SIGNAL(MethodInfo("c_changed", PropertyInfo(Variant::OBJECT, "stat", PROPERTY_HINT_RESOURCE_TYPE, "Stat"))); ClassDB::bind_method(D_METHOD("get_id"), &Stat::get_id); ClassDB::bind_method(D_METHOD("set_id", "id"), &Stat::set_id); - ADD_PROPERTY(PropertyInfo(Variant::INT, "id", PROPERTY_HINT_ENUM, STAT_BINDING_STRING), "set_id", "get_id"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "id", PROPERTY_HINT_ENUM, ""), "set_id", "get_id"); ClassDB::bind_method(D_METHOD("get_stat_data_entry"), &Stat::get_stat_data_entry); ClassDB::bind_method(D_METHOD("set_stat_data_entry", "value"), &Stat::set_stat_data_entry); @@ -687,51 +595,6 @@ void Stat::_bind_methods() { ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &Stat::_from_dict); ClassDB::bind_method(D_METHOD("_to_dict"), &Stat::_to_dict); - BIND_ENUM_CONSTANT(STAT_ID_HEALTH); - BIND_ENUM_CONSTANT(STAT_ID_SPEED); - BIND_ENUM_CONSTANT(STAT_ID_MANA); - BIND_ENUM_CONSTANT(STAT_ID_GLOBAL_COOLDOWN); - BIND_ENUM_CONSTANT(STAT_ID_HASTE); - - BIND_ENUM_CONSTANT(STAT_ID_AGILITY); - BIND_ENUM_CONSTANT(STAT_ID_STRENGTH); - BIND_ENUM_CONSTANT(STAT_ID_STAMINA); - BIND_ENUM_CONSTANT(STAT_ID_INTELLECT); - BIND_ENUM_CONSTANT(STAT_ID_SPIRIT); - - BIND_ENUM_CONSTANT(STAT_ID_HASTE_RATING); - BIND_ENUM_CONSTANT(STAT_ID_RESLILIENCE); - BIND_ENUM_CONSTANT(STAT_ID_ARMOR); - - BIND_ENUM_CONSTANT(STAT_ID_ATTACK_POWER); - BIND_ENUM_CONSTANT(STAT_ID_SPELL_POWER); - - BIND_ENUM_CONSTANT(STAT_ID_MELEE_CRIT); - BIND_ENUM_CONSTANT(STAT_ID_MELEE_CRIT_BONUS); - BIND_ENUM_CONSTANT(STAT_ID_SPELL_CRIT); - BIND_ENUM_CONSTANT(STAT_ID_SPELL_CRIT_BONUS); - BIND_ENUM_CONSTANT(STAT_ID_BLOCK); - BIND_ENUM_CONSTANT(STAT_ID_PARRY); - BIND_ENUM_CONSTANT(STAT_ID_DAMAGE_REDUCTION); - BIND_ENUM_CONSTANT(STAT_ID_MELEE_DAMAGE_REDUCTION); - BIND_ENUM_CONSTANT(STAT_ID_SPELL_DAMAGE_REDUCTION); - BIND_ENUM_CONSTANT(STAT_ID_DAMAGE_TAKEN); - BIND_ENUM_CONSTANT(STAT_ID_MELEE_DAMAGE); - BIND_ENUM_CONSTANT(STAT_ID_SPELL_DAMAGE); - - BIND_ENUM_CONSTANT(STAT_ID_HOLY_RESIST); - BIND_ENUM_CONSTANT(STAT_ID_SHADOW_RESIST); - BIND_ENUM_CONSTANT(STAT_ID_NATURE_RESIST); - BIND_ENUM_CONSTANT(STAT_ID_FIRE_RESIST); - BIND_ENUM_CONSTANT(STAT_ID_FROST_RESIST); - BIND_ENUM_CONSTANT(STAT_ID_LIGHTNING_RESIST); - BIND_ENUM_CONSTANT(STAT_ID_CHAOS_RESIST); - BIND_ENUM_CONSTANT(STAT_ID_SILENCE_RESIST); - BIND_ENUM_CONSTANT(STAT_ID_FEAR_RESIST); - - BIND_ENUM_CONSTANT(STAT_ID_TOTAL_STATS); - BIND_ENUM_CONSTANT(STAT_ID_NONE); - BIND_ENUM_CONSTANT(MODIFIER_APPLY_TYPE_STANDARD); BIND_ENUM_CONSTANT(MODIFIER_APPLY_TYPE_ONLY_MIN_MODIFIER); BIND_ENUM_CONSTANT(MODIFIER_APPLY_TYPE_ONLY_MAX_MODIFIER); diff --git a/entities/stats/stat.h b/entities/stats/stat.h index 70afb86..cee6f47 100644 --- a/entities/stats/stat.h +++ b/entities/stats/stat.h @@ -37,66 +37,9 @@ class Stat : public Reference { GDCLASS(Stat, Reference); public: - static const String STAT_BINDING_STRING; static const String MAIN_STAT_BINDING_STRING; static const String MODIFIER_APPLY_TYPE_BINDING_STRING; - enum StatId { - STAT_ID_HEALTH = 0, - STAT_ID_SPEED, - STAT_ID_MANA, - STAT_ID_GLOBAL_COOLDOWN, - STAT_ID_HASTE, - - STAT_ID_AGILITY, - STAT_ID_STRENGTH, - STAT_ID_STAMINA, - STAT_ID_INTELLECT, - STAT_ID_SPIRIT, - - STAT_ID_HASTE_RATING, - STAT_ID_RESLILIENCE, - STAT_ID_ARMOR, - - STAT_ID_ATTACK_POWER, - STAT_ID_SPELL_POWER, - - STAT_ID_MELEE_CRIT, - STAT_ID_MELEE_CRIT_BONUS, - STAT_ID_SPELL_CRIT, - STAT_ID_SPELL_CRIT_BONUS, - STAT_ID_BLOCK, - STAT_ID_PARRY, - STAT_ID_DAMAGE_REDUCTION, - STAT_ID_MELEE_DAMAGE_REDUCTION, - STAT_ID_SPELL_DAMAGE_REDUCTION, - STAT_ID_DAMAGE_TAKEN, - STAT_ID_HEAL_TAKEN, - STAT_ID_MELEE_DAMAGE, - STAT_ID_SPELL_DAMAGE, - - STAT_ID_HOLY_RESIST, - STAT_ID_SHADOW_RESIST, - STAT_ID_NATURE_RESIST, - STAT_ID_FIRE_RESIST, - STAT_ID_FROST_RESIST, - STAT_ID_LIGHTNING_RESIST, - STAT_ID_CHAOS_RESIST, - STAT_ID_SILENCE_RESIST, - STAT_ID_FEAR_RESIST, - STAT_ID_STUN_RESIST, - - STAT_ID_ENERGY, - STAT_ID_RAGE, - - STAT_ID_XP_RATE, - - STAT_DISPELL_RESIST, - - STAT_ID_TOTAL_STATS, - STAT_ID_NONE = STAT_ID_TOTAL_STATS, - }; - enum StatModifierApplyType { MODIFIER_APPLY_TYPE_STANDARD, MODIFIER_APPLY_TYPE_ONLY_MIN_MODIFIER, @@ -110,15 +53,15 @@ public: MAIN_STAT_INTELLECT = 3, MAIN_STAT_SPIRIT = 4, - MAIN_STAT_ID_START = STAT_ID_AGILITY, + MAIN_STAT_ID_START = 0, MAIN_STAT_ID_COUNT = 5, }; static String stat_id_name(int stat_id); public: - Stat::StatId get_id(); - void set_id(Stat::StatId id); + int get_id(); + void set_id(int id); Ref get_stat_data_entry(); void set_stat_data_entry(Ref entry); @@ -190,15 +133,16 @@ public: void _from_dict(const Dictionary &dict); Stat(); - Stat(Stat::StatId id, Entity *owner); - Stat(Stat::StatId id, StatModifierApplyType modifier_apply_type, Entity *owner); + Stat(int id, Entity *owner); + Stat(int id, StatModifierApplyType modifier_apply_type, Entity *owner); ~Stat(); protected: + virtual void _validate_property(PropertyInfo &property) const; static void _bind_methods(); private: - Stat::StatId _id; + int _id; StatModifierApplyType _modifier_apply_type; @@ -223,7 +167,6 @@ private: Ref _stat_data_entry; }; -VARIANT_ENUM_CAST(Stat::StatId); VARIANT_ENUM_CAST(Stat::MainStats); VARIANT_ENUM_CAST(Stat::StatModifierApplyType); diff --git a/entities/stats/stat_data.cpp b/entities/stats/stat_data.cpp index 036ce0c..1457f77 100644 --- a/entities/stats/stat_data.cpp +++ b/entities/stats/stat_data.cpp @@ -22,29 +22,20 @@ SOFTWARE. #include "stat_data.h" -Ref StatData::get_stat_data_int(int index) { - ERR_FAIL_INDEX_V(index, Stat::STAT_ID_TOTAL_STATS, Ref(NULL)); +#include "../../singletons/ess.h" - return Ref(_entries[index]); +Ref StatData::get_stat_data(int index) { + ERR_FAIL_INDEX_V(index, _entries.size(), Ref(NULL)); + + return _entries[index]; } -void StatData::set_stat_data_int(int index, Ref entry) { - ERR_FAIL_INDEX(index, Stat::STAT_ID_TOTAL_STATS); +void StatData::set_stat_data(int index, Ref entry) { + ERR_FAIL_INDEX(index, _entries.size()); - _entries[index] = entry; + _entries.set(index, entry); } -Ref StatData::get_stat_data_enum(Stat::StatId stat_id) { - ERR_FAIL_INDEX_V(stat_id, Stat::STAT_ID_TOTAL_STATS, Ref(NULL)); - - return Ref(_entries[stat_id]); -} - -void StatData::set_stat_data_enum(Stat::StatId stat_id, Ref entry) { - ERR_FAIL_INDEX(stat_id, Stat::STAT_ID_TOTAL_STATS); - - _entries[stat_id] = entry; -} Ref StatData::get_level_stat_data() { return _level_stat_data; } @@ -54,22 +45,25 @@ void StatData::set_level_stat_data(Ref value) { } void StatData::get_stat_for_stat(Ref stat) { - Ref sd = get_stat_data_enum(stat->get_id()); + Ref sd = get_stat_data(stat->get_id()); - ERR_FAIL_COND(sd == NULL); + ERR_FAIL_COND(!sd.is_valid()); sd->get_stats_for_stat(stat); } StatData::StatData() { - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { + //TODO remove? let properties handle this? + _entries.resize(ESS::get_instance()->stat_get_count()); + + for (int i = 0; i < _entries.size(); ++i) { Ref entry(memnew(StatDataEntry())); - - entry->set_stat_id(static_cast(i)); - - _entries[i] = Ref(entry); + entry->set_stat_id(i); + _entries.set(i, Ref(entry)); } + /* + TODO Add something equivalent to this into project settings get_stat_data_enum(Stat::STAT_ID_HEALTH)->set_base(100); get_stat_data_enum(Stat::STAT_ID_MANA)->set_base(100); get_stat_data_enum(Stat::STAT_ID_SPEED)->set_base(4.2); @@ -81,22 +75,71 @@ StatData::StatData() { get_stat_data_enum(Stat::STAT_ID_BLOCK)->set_base(10); get_stat_data_enum(Stat::STAT_ID_PARRY)->set_base(15); get_stat_data_enum(Stat::STAT_ID_MELEE_DAMAGE_REDUCTION)->set_base(15); - get_stat_data_enum(Stat::STAT_ID_XP_RATE)->set_base(1); + */ +} + +StatData::~StatData() { + _entries.clear(); + + _level_stat_data.unref(); +} + +bool StatData::_set(const StringName &p_name, const Variant &p_value) { + String name = p_name; + + if (name.get_slicec('/', 0) == "stat") { + int stat_id = name.get_slicec('/', 1).to_int(); + + if (_entries.size() < stat_id) { + _entries.resize(stat_id + 1); + } + + _entries.set(stat_id, p_value); + + return true; + } else { + return false; + } + + return true; +} + +bool StatData::_get(const StringName &p_name, Variant &r_ret) const { + String name = p_name; + + if (name.get_slicec('/', 0) == "stat") { + int stat_id = name.get_slicec('/', 1).to_int(); + + if (_entries.size() < stat_id) { + r_ret = Ref(); + + return true; + } + + r_ret = _entries[stat_id]; + + return true; + } else { + return false; + } + + return true; +} + +void StatData::_get_property_list(List *p_list) const { + //int property_usange = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL; + int property_usange = PROPERTY_USAGE_DEFAULT; + + for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) { + p_list->push_back(PropertyInfo(Variant::INT, "stat/" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "StatDataEntry", property_usange)); + } } void StatData::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_stat_data_int", "index"), &StatData::get_stat_data_int); - ClassDB::bind_method(D_METHOD("set_stat_data_int", "index", "entry"), &StatData::set_stat_data_int); - - ClassDB::bind_method(D_METHOD("get_stat_data_enum", "index"), &StatData::get_stat_data_enum); - ClassDB::bind_method(D_METHOD("set_stat_data_enum", "stat_id", "entry"), &StatData::set_stat_data_enum); - - ADD_GROUP("Base Stats", "base_stat"); - for (int i = 0; i < Stat::STAT_ID_TOTAL_STATS; ++i) { - ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "base_stat_" + Stat::stat_id_name(i), PROPERTY_HINT_RESOURCE_TYPE, "StatDataEntry"), "set_stat_data_enum", "get_stat_data_enum", i); - } + ClassDB::bind_method(D_METHOD("get_stat_data", "index"), &StatData::get_stat_data); + ClassDB::bind_method(D_METHOD("set_stat_data", "index", "entry"), &StatData::set_stat_data); ClassDB::bind_method(D_METHOD("get_level_stat_data"), &StatData::get_level_stat_data); ClassDB::bind_method(D_METHOD("set_level_stat_data", "value"), &StatData::set_level_stat_data); diff --git a/entities/stats/stat_data.h b/entities/stats/stat_data.h index f1ab29d..4849820 100644 --- a/entities/stats/stat_data.h +++ b/entities/stats/stat_data.h @@ -34,11 +34,8 @@ class StatData : public Resource { GDCLASS(StatData, Resource); public: - Ref get_stat_data_int(int index); - void set_stat_data_int(int index, Ref entry); - - Ref get_stat_data_enum(Stat::StatId stat_id); - void set_stat_data_enum(Stat::StatId stat_id, Ref entry); + Ref get_stat_data(int index); + void set_stat_data(int index, Ref entry); Ref get_level_stat_data(); void set_level_stat_data(Ref value); @@ -46,12 +43,16 @@ public: void get_stat_for_stat(Ref stat); StatData(); + ~StatData(); protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; static void _bind_methods(); private: - Ref _entries[Stat::STAT_ID_TOTAL_STATS]; + Vector > _entries; Ref _level_stat_data; }; diff --git a/entities/stats/stat_data_entry.cpp b/entities/stats/stat_data_entry.cpp index 9e1a304..82c0c71 100644 --- a/entities/stats/stat_data_entry.cpp +++ b/entities/stats/stat_data_entry.cpp @@ -24,18 +24,20 @@ SOFTWARE. #include "core/version.h" +#include "../../singletons/ess.h" + #if VERSION_MAJOR >= 4 #define REAL FLOAT #endif -Stat::StatId StatDataEntry::get_stat_id() { +int StatDataEntry::get_stat_id() { return _stat_id; } -void StatDataEntry::set_stat_id(Stat::StatId value) { +void StatDataEntry::set_stat_id(int value) { _stat_id = value; - if (static_cast(value) < Stat::STAT_ID_GLOBAL_COOLDOWN) - _public = true; + //if (value < Stat::STAT_ID_GLOBAL_COOLDOWN) TODO + _public = true; } bool StatDataEntry::get_public() { @@ -84,12 +86,12 @@ void StatDataEntry::set_mod_stat_count(int value) { _mod_stat_count = value; } -Stat::StatId StatDataEntry::get_mod_stat_id(int index) { - ERR_FAIL_INDEX_V(index, MAX_MOD_STATS, Stat::STAT_ID_HEALTH); +int StatDataEntry::get_mod_stat_id(int index) { + ERR_FAIL_INDEX_V(index, MAX_MOD_STATS, 0); return _mod_stats[index].stat_id; } -void StatDataEntry::set_mod_stat_id(int index, Stat::StatId value) { +void StatDataEntry::set_mod_stat_id(int index, int value) { ERR_FAIL_INDEX(index, MAX_MOD_STATS); _mod_stats[index].stat_id = value; @@ -128,7 +130,7 @@ void StatDataEntry::get_stats_for_stat(Ref stat) { } StatDataEntry::StatDataEntry() { - _stat_id = Stat::STAT_ID_NONE; + _stat_id = 0; _public = false; _base = 0; @@ -139,7 +141,7 @@ StatDataEntry::StatDataEntry() { _modifier_apply_type = Stat::MODIFIER_APPLY_TYPE_STANDARD; for (int i = 0; i < MAX_MOD_STATS; ++i) { - _mod_stats[i].stat_id = Stat::STAT_ID_HEALTH; + _mod_stats[i].stat_id = 0; _mod_stats[i].max_value = 1000; } } @@ -150,10 +152,24 @@ StatDataEntry::~StatDataEntry() { } } +void StatDataEntry::_validate_property(PropertyInfo &property) const { + String prop = property.name; + if (prop.begins_with("ModStat_")) { + int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int(); + if (frame >= _mod_stat_count) { + property.usage = 0; + } + } + + if (prop.ends_with("stat_id")) { + property.hint_string = ESS::get_instance()->stat_get_string(); + } +} + void StatDataEntry::_bind_methods() { ClassDB::bind_method(D_METHOD("get_stat_id"), &StatDataEntry::get_stat_id); ClassDB::bind_method(D_METHOD("set_stat_id", "value"), &StatDataEntry::set_stat_id); - ADD_PROPERTY(PropertyInfo(Variant::INT, "stat_id", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING), "set_stat_id", "get_stat_id"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stat_id", PROPERTY_HINT_ENUM, ""), "set_stat_id", "get_stat_id"); ClassDB::bind_method(D_METHOD("get_base"), &StatDataEntry::get_base); ClassDB::bind_method(D_METHOD("set_base", "value"), &StatDataEntry::set_base); @@ -187,20 +203,10 @@ void StatDataEntry::_bind_methods() { ClassDB::bind_method(D_METHOD("set_mod_stat_max_value", "index", "value"), &StatDataEntry::set_mod_stat_max_value); for (int i = 0; i < MAX_MOD_STATS; i++) { - ADD_PROPERTYI(PropertyInfo(Variant::INT, "ModStat_" + itos(i) + "/stat_id", PROPERTY_HINT_ENUM, Stat::STAT_BINDING_STRING, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_id", "get_mod_stat_id", i); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "ModStat_" + itos(i) + "/stat_id", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_id", "get_mod_stat_id", i); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "ModStat_" + itos(i) + "/curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_curve", "get_mod_stat_curve", i); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "ModStat_" + itos(i) + "/max_value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_max_value", "get_mod_stat_max_value", i); } ClassDB::bind_method(D_METHOD("get_stats_for_stat", "stat"), &StatDataEntry::get_stats_for_stat); } - -void StatDataEntry::_validate_property(PropertyInfo &property) const { - String prop = property.name; - if (prop.begins_with("ModStat_")) { - int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int(); - if (frame >= _mod_stat_count) { - property.usage = 0; - } - } -} diff --git a/entities/stats/stat_data_entry.h b/entities/stats/stat_data_entry.h index ed445fb..b831d48 100644 --- a/entities/stats/stat_data_entry.h +++ b/entities/stats/stat_data_entry.h @@ -33,8 +33,8 @@ class StatDataEntry : public Resource { GDCLASS(StatDataEntry, Resource); public: - Stat::StatId get_stat_id(); - void set_stat_id(Stat::StatId value); + int get_stat_id(); + void set_stat_id(int value); bool get_public(); void set_public(bool value); @@ -56,8 +56,8 @@ public: int get_mod_stat_count(); void set_mod_stat_count(int value); - Stat::StatId get_mod_stat_id(int index); - void set_mod_stat_id(int index, Stat::StatId value); + int get_mod_stat_id(int index); + void set_mod_stat_id(int index, int value); Ref get_mod_stat_curve(int index); void set_mod_stat_curve(int index, Ref curve); @@ -71,12 +71,12 @@ public: ~StatDataEntry(); protected: - static void _bind_methods(); void _validate_property(PropertyInfo &property) const; + static void _bind_methods(); public: struct ModStat { - Stat::StatId stat_id; + int stat_id; Ref curve; float max_value; }; @@ -86,7 +86,7 @@ public: }; private: - Stat::StatId _stat_id; + int _stat_id; bool _public; float _base; float _bonus;