diff --git a/SCsub b/SCsub index bf25533..c476899 100644 --- a/SCsub +++ b/SCsub @@ -80,6 +80,7 @@ module_env.add_source_files(env.modules_sources,"pipelines/spell_damage_info.cpp module_env.add_source_files(env.modules_sources,"pipelines/spell_heal_info.cpp") module_env.add_source_files(env.modules_sources,"entities/auras/aura_data.cpp") module_env.add_source_files(env.modules_sources,"entities/entity.cpp") +module_env.add_source_files(env.modules_sources,"entities/resources/entity_resource_data.cpp") module_env.add_source_files(env.modules_sources,"entities/resources/entity_resource.cpp") module_env.add_source_files(env.modules_sources,"ui/unit_frame.cpp") diff --git a/entities/data/entity_class_data.cpp b/entities/data/entity_class_data.cpp index 5011328..67cdce8 100644 --- a/entities/data/entity_class_data.cpp +++ b/entities/data/entity_class_data.cpp @@ -72,6 +72,51 @@ void EntityClassData::set_stat_data(Ref value) { _stat_data = value; } +//// Entity Resources //// + +int EntityClassData::get_num_entity_resources() { + if (_entity_resources.size() == 0 && _inherits.is_valid()) { + return _inherits->get_num_entity_resources(); + } + + return _entity_resources.size(); +} +void EntityClassData::set_num_entity_resources(int value) { + _entity_resources.resize(value); +} + +Ref EntityClassData::get_entity_resource(int index) const { + if (_entity_resources.size() == 0 && _inherits.is_valid()) { + return _inherits->get_entity_resource(index); + } + + ERR_FAIL_INDEX_V(index, _entity_resources.size(), Ref()); + + return _entity_resources[index]; +} +void EntityClassData::set_entity_resource(int index, Ref entity_resource) { + ERR_FAIL_INDEX(index, _entity_resources.size()); + + _entity_resources.set(index, Ref(entity_resource)); +} + +Vector EntityClassData::get_entity_resources() { + Vector r; + for (int i = 0; i < _entity_resources.size(); i++) { + r.push_back(_entity_resources[i].get_ref_ptr()); + } + return r; +} +void EntityClassData::set_entity_resources(const Vector &entity_resources) { + _entity_resources.clear(); + for (int i = 0; i < entity_resources.size(); i++) { + Ref entity_resource = Ref(entity_resources[i]); + + _entity_resources.push_back(entity_resource); + } +} + + //// SPECS //// int EntityClassData::get_num_specs() { @@ -313,10 +358,23 @@ Ref EntityClassData::_get_ai_instance() { //// SETUP //// void EntityClassData::setup_resources(Entity *entity) { + if (_inherits.is_valid()) + _inherits->setup_resources(entity); + if (has_method("_setup_resources")) call("_setup_resources", entity); - else if (_inherits.is_valid()) - _inherits->setup_resources(entity); +} + +void EntityClassData::_setup_resources(Node *entity) { + Entity *ent = Object::cast_to(entity); + + for (int i = 0; i < _entity_resources.size(); ++i) { + Ref res = _entity_resources.get(i); + + if (res.is_valid()) { + ent->adds_resource(res->get_entity_resource_instance()); + } + } } void EntityClassData::start_casting(int spell_id, Entity *caster, float spellScale) { @@ -1016,6 +1074,19 @@ void EntityClassData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_playstyle_type", "value"), &EntityClassData::set_playstyle_type); ADD_PROPERTY(PropertyInfo(Variant::INT, "playstyle_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_PLAYSTYLE_TYPE), "set_playstyle_type", "get_playstyle_type"); + //// Entity Resources //// + ClassDB::bind_method(D_METHOD("get_num_entity_resources"), &EntityClassData::get_num_entity_resources); + ClassDB::bind_method(D_METHOD("set_num_entity_resources", "value"), &EntityClassData::set_num_entity_resources); + + ClassDB::bind_method(D_METHOD("get_entity_resource", "index"), &EntityClassData::get_entity_resource); + ClassDB::bind_method(D_METHOD("set_entity_resource", "index", "entity_resource"), &EntityClassData::set_entity_resource); + + ClassDB::bind_method(D_METHOD("get_entity_resources"), &EntityClassData::get_entity_resources); + ClassDB::bind_method(D_METHOD("set_entity_resources", "entity_resources"), &EntityClassData::set_entity_resources); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_resources", PROPERTY_HINT_NONE, "17/17:EntityResourceData", PROPERTY_USAGE_DEFAULT, "EntityResourceData"), "set_entity_resources", "get_entity_resources"); + + ClassDB::bind_method(D_METHOD("_setup_resources", "entity"), &EntityClassData::_setup_resources); + //// Specs //// ClassDB::bind_method(D_METHOD("get_num_specs"), &EntityClassData::get_num_specs); ClassDB::bind_method(D_METHOD("set_num_specs", "value"), &EntityClassData::set_num_specs); diff --git a/entities/data/entity_class_data.h b/entities/data/entity_class_data.h index b210014..ecde212 100644 --- a/entities/data/entity_class_data.h +++ b/entities/data/entity_class_data.h @@ -17,6 +17,8 @@ #include "../../utility/category_cooldown.h" #include "../../item_enums.h" +#include "../resources/entity_resource_data.h" + class Aura; class Spell; class Entity; @@ -54,6 +56,16 @@ public: EntityEnums::EntityClassPlaystyleType get_playstyle_type(); void set_playstyle_type(EntityEnums::EntityClassPlaystyleType playstyle_type); + //Entity Resources + int get_num_entity_resources(); + void set_num_entity_resources(int value); + + Ref get_entity_resource(int index) const; + void set_entity_resource(int index, Ref entity_resources); + + Vector get_entity_resources(); + void set_entity_resources(const Vector &entity_resourcess); + //Specs int get_num_specs(); void set_num_specs(int value); @@ -109,7 +121,7 @@ public: //Setup void setup_resources(Entity *entity); - //void _setup_resources(Entity *entity); + void _setup_resources(Node *entity); //// Spell System //// @@ -230,9 +242,10 @@ private: Ref _stat_data; + Vector > _entity_resources; + Vector > _specs; Vector > _spells; Vector > _start_spells; - Vector > _specs; Vector > _auras; Vector > _ais; }; diff --git a/entities/data/entity_data.h b/entities/data/entity_data.h index 8843222..5757baf 100644 --- a/entities/data/entity_data.h +++ b/entities/data/entity_data.h @@ -111,7 +111,6 @@ public: //Setup void setup_resources(Entity *entity); - //void _setup_resources(Entity *entity); //// Interactions //// bool cans_interact(Entity *entity); diff --git a/entities/resources/entity_resource_data.cpp b/entities/resources/entity_resource_data.cpp new file mode 100644 index 0000000..4013848 --- /dev/null +++ b/entities/resources/entity_resource_data.cpp @@ -0,0 +1,18 @@ +#include "entity_resource_data.h" + +Ref EntityResourceData::get_entity_resource_instance() { + if (has_method("_get_entity_resource_instance")) { + return call("_get_entity_resource_instance"); + } + + return Ref(); +} + +EntityResourceData::EntityResourceData() { +} + +void EntityResourceData::_bind_methods() { + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "res", PROPERTY_HINT_RESOURCE_TYPE, "EntityResource"), "_get_entity_resource_instance")); + + ClassDB::bind_method(D_METHOD("get_entity_resource_instance"), &EntityResourceData::get_entity_resource_instance); +} diff --git a/entities/resources/entity_resource_data.h b/entities/resources/entity_resource_data.h new file mode 100644 index 0000000..9ac8c5c --- /dev/null +++ b/entities/resources/entity_resource_data.h @@ -0,0 +1,21 @@ +#ifndef ENTITY_RESOURCE_DATA_H +#define ENTITY_RESOURCE_DATA_H + +#include "core/resource.h" +#include "scene/main/node.h" + +#include "entity_resource.h" + +class EntityResourceData : public Resource { + GDCLASS(EntityResourceData, Resource); + +public: + Ref get_entity_resource_instance(); + + EntityResourceData(); + +protected: + static void _bind_methods(); +}; + +#endif diff --git a/entity_enums.cpp b/entity_enums.cpp index b22cf7a..d0041cf 100644 --- a/entity_enums.cpp +++ b/entity_enums.cpp @@ -1,7 +1,5 @@ #include "entity_enums.h" -const String EntityEnums::BINDING_STRING_PLAYER_RESOURCE_TYPES = "None,Rage,Mana,Energy,Time Anomaly"; - const String EntityEnums::BINDING_STRING_ENTITY_TYPES = "None,Creature,Totem,Idol,Humanoid,Mechanical,Beast,Dragonkin,Elemental,Ghost,Energy,Anomaly,Demon,Object"; const String EntityEnums::BINDING_STRING_ENTITY_CONTOLLER = "None,Player,AI"; const String EntityEnums::BINDING_STRING_ENTITY_FLAGS = "Untargetable,Hidden,Interactable,Hostile"; @@ -15,16 +13,11 @@ const String EntityEnums::BINDING_STRING_ENTITY_PLAYSTYLE_TYPE = "Melee,Spell,Hy const String EntityEnums::BINDING_STRING_ENTITY_GENDER = "Male,Female"; const String EntityEnums::BINDING_STRING_ENTITY_WINDOWS = "Loot,Container,Vendor"; -const int EntityEnums::PLAYER_RESOURCE_TYPES_RAGE = 0; -const int EntityEnums::PLAYER_RESOURCE_TYPES_MANA = 1; -const int EntityEnums::PLAYER_RESOURCE_TYPES_ENERGY = 2; -const int EntityEnums::PLAYER_RESOURCE_TYPES_TIME_ANOMALY = 3; - void EntityEnums::_bind_methods() { - BIND_CONSTANT(PLAYER_RESOURCE_TYPES_RAGE); - BIND_CONSTANT(PLAYER_RESOURCE_TYPES_MANA); - BIND_CONSTANT(PLAYER_RESOURCE_TYPES_ENERGY); - BIND_CONSTANT(PLAYER_RESOURCE_TYPES_TIME_ANOMALY); + BIND_CONSTANT(ENTITY_RESOURCE_TYPES_MANA); + BIND_CONSTANT(ENTITY_RESOURCE_TYPES_RAGE); + BIND_CONSTANT(ENTITY_RESOURCE_TYPES_ENERGY); + BIND_CONSTANT(ENTITY_RESOURCE_TYPES_TIME_ANOMALY); BIND_ENUM_CONSTANT(ENITIY_TYPE_NONE); BIND_ENUM_CONSTANT(ENITIY_TYPE_CREATURE); diff --git a/entity_enums.h b/entity_enums.h index 60d706e..06cbd98 100644 --- a/entity_enums.h +++ b/entity_enums.h @@ -8,8 +8,6 @@ class EntityEnums : public Object { GDCLASS(EntityEnums, Object); public: - static const String BINDING_STRING_PLAYER_RESOURCE_TYPES; - static const String BINDING_STRING_ENTITY_TYPES; static const String BINDING_STRING_ENTITY_CONTOLLER; static const String BINDING_STRING_ENTITY_FLAGS; @@ -23,11 +21,6 @@ public: static const String BINDING_STRING_ENTITY_GENDER; static const String BINDING_STRING_ENTITY_WINDOWS; - static const int PLAYER_RESOURCE_TYPES_RAGE; - static const int PLAYER_RESOURCE_TYPES_MANA; - static const int PLAYER_RESOURCE_TYPES_ENERGY; - static const int PLAYER_RESOURCE_TYPES_TIME_ANOMALY; - enum EntityType { ENITIY_TYPE_NONE, ENITIY_TYPE_CREATURE, @@ -51,6 +44,13 @@ public: ENITIY_CONTROLLER_AI }; + enum { + ENTITY_RESOURCE_TYPES_MANA = 0, + ENTITY_RESOURCE_TYPES_RAGE, + ENTITY_RESOURCE_TYPES_ENERGY, + ENTITY_RESOURCE_TYPES_TIME_ANOMALY, + }; + enum EntityFlags { ENITIY_FLAGS_NONE = 0, diff --git a/register_types.cpp b/register_types.cpp index f518a72..696dac1 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -60,6 +60,7 @@ #include "pipelines/spell_damage_info.h" #include "pipelines/spell_heal_info.h" +#include "entities/resources/entity_resource_data.h" #include "entities/resources/entity_resource.h" #include "entities/auras/aura_data.h" #include "entities/entity.h" @@ -185,6 +186,7 @@ void register_entity_spell_system_types() { ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class();