From 0bdf6652a622d420e142de4efd1d0a44a592c957 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 1 Nov 2019 22:07:56 +0100 Subject: [PATCH] Better/Different AuraGroup implementation. --- SCsub | 1 + data/aura.cpp | 17 +++++------------ data/aura.h | 11 ++++++----- data/aura_group.cpp | 8 ++++++++ data/aura_group.h | 16 ++++++++++++++++ entities/entity.cpp | 33 ++++++++++++++++++++++++++++++--- entities/entity.h | 7 ++++++- register_types.cpp | 2 ++ 8 files changed, 74 insertions(+), 21 deletions(-) create mode 100644 data/aura_group.cpp create mode 100644 data/aura_group.h diff --git a/SCsub b/SCsub index 1bb0705..2a576c9 100644 --- a/SCsub +++ b/SCsub @@ -12,6 +12,7 @@ module_env.add_source_files(env.modules_sources,"spell_enums.cpp") module_env.add_source_files(env.modules_sources,"item_enums.cpp") module_env.add_source_files(env.modules_sources,"data/aura.cpp") +module_env.add_source_files(env.modules_sources,"data/aura_group.cpp") module_env.add_source_files(env.modules_sources,"data/talent_rank_data.cpp") module_env.add_source_files(env.modules_sources,"data/xp_data.cpp") module_env.add_source_files(env.modules_sources,"data/item_stat_modifier.cpp") diff --git a/data/aura.cpp b/data/aura.cpp index 0359675..f69f82e 100644 --- a/data/aura.cpp +++ b/data/aura.cpp @@ -28,11 +28,11 @@ void Aura::set_tick(float value) { _tick = value; } -int Aura::get_aura_group() { - return aura_group; +Ref Aura::get_aura_group() { + return _aura_group; } -void Aura::set_aura_group(int value) { - aura_group = value; +void Aura::set_aura_group(Ref value) { + _aura_group = value; } bool Aura::get_is_debuff() { @@ -135,12 +135,6 @@ void Aura::set_teaches_spell(const Ref spell) { _teaches_spell = spell; } -void Aura::set(int id, float time, int auraGroup) { - this->set_id(id); - this->set_time(time); - this->set_aura_group(auraGroup); -} - /* void Aura::SetScalingData(AbilityScalingData *scalingData) { scalingData->getDamageCurve(); @@ -270,7 +264,6 @@ Aura::Aura() { _tick = 0; _aura_type = SpellEnums::AURA_TYPE_NONE; _is_debuff = false; - aura_group = 0; _hide = false; _rank = 0; @@ -1385,7 +1378,7 @@ void Aura::_bind_methods() { ClassDB::bind_method(D_METHOD("get_aura_group"), &Aura::get_aura_group); ClassDB::bind_method(D_METHOD("set_aura_group", "value"), &Aura::set_aura_group); - ADD_PROPERTY(PropertyInfo(Variant::INT, "aura_group"), "set_aura_group", "get_aura_group"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "aura_group", PROPERTY_HINT_RESOURCE_TYPE, "AuraGroup"), "set_aura_group", "get_aura_group"); ClassDB::bind_method(D_METHOD("get_hide"), &Aura::get_hide); ClassDB::bind_method(D_METHOD("set_hide", "value"), &Aura::set_hide); diff --git a/data/aura.h b/data/aura.h index 3e60253..cf608fa 100644 --- a/data/aura.h +++ b/data/aura.h @@ -5,6 +5,8 @@ #include "scene/resources/curve.h" #include "scene/resources/texture.h" +#include "aura_group.h" + #include "../entity_enums.h" #include "../spell_enums.h" @@ -45,8 +47,8 @@ public: float get_time(); void set_time(float value); - int get_aura_group(); - void set_aura_group(int value); + Ref get_aura_group(); + void set_aura_group(Ref value); bool get_is_debuff(); void set_is_debuff(bool value); @@ -84,8 +86,7 @@ public: float get_damage_scale_for_level(int level); float get_heal_scale_for_level(int level); float get_absorb_scale_for_level(int level); - void set(int id, float time, int auraGroup); - + Ref get_teaches_spell() const; void set_teaches_spell(const Ref spell); @@ -405,7 +406,7 @@ private: int id; float time; float _tick; - int aura_group; + Ref _aura_group; Ref _icon; SpellEnums::AuraType _aura_type; bool _is_debuff; diff --git a/data/aura_group.cpp b/data/aura_group.cpp new file mode 100644 index 0000000..cf1ee92 --- /dev/null +++ b/data/aura_group.cpp @@ -0,0 +1,8 @@ +#include "aura_group.h" + +AuraGroup::AuraGroup() { +} + +void AuraGroup::_bind_methods() { + ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_description"), "set_text_description", "get_text_description"); +} diff --git a/data/aura_group.h b/data/aura_group.h new file mode 100644 index 0000000..538ccd7 --- /dev/null +++ b/data/aura_group.h @@ -0,0 +1,16 @@ +#ifndef AURA_GROUP_H +#define AURA_GROUP_H + +#include "core/resource.h" + +class AuraGroup : public Resource { + GDCLASS(AuraGroup, Resource); + +public: + AuraGroup(); + +protected: + static void _bind_methods(); +}; + +#endif diff --git a/entities/entity.cpp b/entities/entity.cpp index 7cf51f3..c0f2af0 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -2458,18 +2458,45 @@ Ref Entity::sget_aura_by(Entity *caster, int aura_id) { } Ref Entity::sget_aura_by_bind(Node *caster, int aura_id) { if (!caster) { - return Ref(NULL); + return Ref(); } Entity *e = cast_to(caster); if (!e) { - return Ref(NULL); + return Ref(); } return sget_aura_by(e, aura_id); } + +Ref Entity::sget_aura_with_group_by(Entity *caster, Ref aura_group) { + for (int i = 0; i < _s_auras.size(); ++i) { + Ref ad = _s_auras.get(i); + + if (ad->get_aura()->get_aura_group() == aura_group && ad->get_caster() == caster) { + return ad; + } + } + + return Ref(NULL); +} +Ref Entity::sget_aura_with_group_by_bind(Node *caster, Ref aura_group) { + if (!caster) { + return Ref(); + } + + Entity *e = cast_to(caster); + + if (!e) { + return Ref(); + } + + return sget_aura_with_group_by(e, aura_group); +} + + int Entity::cget_aura_count() { return _s_auras.size(); } @@ -3568,7 +3595,7 @@ void Entity::setc_spell_cast_info(Ref info) { _c_spell_cast_info = Ref(info); } -void Entity::sremove_auras_with_group(int aura_group) { +void Entity::sremove_auras_with_group(Ref aura_group) { for (int i = 0; i < _s_auras.size(); ++i) { Ref ad = _s_auras.get(i); diff --git a/entities/entity.h b/entities/entity.h index 0d777b0..e04fff8 100644 --- a/entities/entity.h +++ b/entities/entity.h @@ -38,6 +38,8 @@ #include "../ai/ai_fsm_action.h" +#include "../data/aura_group.h" + class EntityData; class AuraData; class Spell; @@ -500,7 +502,7 @@ public: void cremove_aura_dispelled(Ref aura); void caura_refreshed(Ref aura); - void sremove_auras_with_group(int aura_group); + void sremove_auras_with_group(Ref aura_group); //NOTE: No reason for shas_aura_by, just query it, and check for null. int sget_aura_count(); @@ -508,6 +510,9 @@ public: Ref sget_aura_by(Entity *caster, int aura_id); Ref sget_aura_by_bind(Node *caster, int aura_id); + Ref sget_aura_with_group_by(Entity *caster, Ref aura_group); + Ref sget_aura_with_group_by_bind(Node *caster, Ref aura_group); + int cget_aura_count(); Ref cget_aura(int index); diff --git a/register_types.cpp b/register_types.cpp index 4ab11b5..1587c43 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -4,6 +4,7 @@ #include "item_enums.h" #include "data/aura.h" +#include "data/aura_group.h" #include "data/aura_stat_attribute.h" #include "entity_data_manager.h" #include "data/xp_data.h" @@ -134,6 +135,7 @@ void register_entity_spell_system_types() { ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class();