From 18925ee2364183f867b3fdf53d66de95cb5c2ae9 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 16 Sep 2019 21:57:55 +0200 Subject: [PATCH] Implemented Bags, and added a InteractionType enum. --- SCsub | 2 +- data/item_instance.cpp | 62 ++---- data/item_instance.h | 20 +- data/item_template.cpp | 28 +-- data/item_template.h | 10 +- entities/data/entity_data.cpp | 25 +++ entities/data/entity_data.h | 12 +- entities/data/player_character_data.cpp | 10 +- entities/data/player_character_data.h | 11 +- entities/entity.cpp | 114 +++++++++- entities/entity.h | 39 +++- entities/player.cpp | 162 +-------------- entities/player.h | 59 +----- entity_enums.cpp | 7 + entity_enums.h | 10 + inventory/bag.cpp | 265 +++++++++++++++++++----- inventory/bag.h | 16 +- register_types.cpp | 4 +- 18 files changed, 496 insertions(+), 360 deletions(-) diff --git a/SCsub b/SCsub index 53b8408..2a1b239 100644 --- a/SCsub +++ b/SCsub @@ -66,7 +66,7 @@ module_env.add_source_files(env.modules_sources,"data/world_effect_data.cpp") module_env.add_source_files(env.modules_sources,"entities/player_talent.cpp") module_env.add_source_files(env.modules_sources,"inventory/bag.cpp") -module_env.add_source_files(env.modules_sources,"inventory/inventory.cpp") +#module_env.add_source_files(env.modules_sources,"inventory/inventory.cpp") module_env.add_source_files(env.modules_sources,"infos/aura_infos.cpp") module_env.add_source_files(env.modules_sources,"infos/spell_cast_info.cpp") diff --git a/data/item_instance.cpp b/data/item_instance.cpp index e2a6ec3..8af2913 100644 --- a/data/item_instance.cpp +++ b/data/item_instance.cpp @@ -11,35 +11,20 @@ void ItemInstance::set_id(int value) { _id = value; } -int ItemInstance::get_inventory_position_x() const { - return _inventory_position_x; +int ItemInstance::get_inventory_position() const { + return _inventory_position; } -void ItemInstance::set_inventory_position_x(const int value) { - _inventory_position_x = value; +void ItemInstance::set_inventory_position(const int value) { + _inventory_position = value; } -int ItemInstance::get_inventory_position_y() const { - return _inventory_position_y; -} -void ItemInstance::set_inventory_position_y(const int value) { - _inventory_position_y = value; -} Ref ItemInstance::get_bag() const { - if (_bag == NULL) { - return Ref(NULL); - } - - return *_bag; + return _bag; } void ItemInstance::set_bag(const Ref bag) { - if (_bag == NULL) { - _bag = memnew(Ref(NULL)); - } else { - _bag->unref(); - (*_bag) = bag; - } + _bag = bag; } Ref ItemInstance::get_item_template() const { @@ -97,20 +82,18 @@ void ItemInstance::set_percent_mod(int index, float value) { _modifiers[index]->set_percent_mod(value); } -int ItemInstance::get_count() { - return _count; +int ItemInstance::get_stack_size() { + return _stack_size; } -void ItemInstance::set_count(int value) { - _count = value; +void ItemInstance::set_stack_size(int value) { + _stack_size = value; } ItemInstance::ItemInstance() { _id = 0; - _bag = NULL; - - _count = 0; + _stack_size = 1; _modifier_count = 0; @@ -120,11 +103,6 @@ ItemInstance::ItemInstance() { } ItemInstance::~ItemInstance() { - if (_bag != NULL) { - _bag->unref(); - - memdelete(_bag); - } } void ItemInstance::_validate_property(PropertyInfo &property) const { @@ -144,23 +122,19 @@ void ItemInstance::_bind_methods() { ClassDB::bind_method(D_METHOD("set_id", "count"), &ItemInstance::set_id); ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id"); - ClassDB::bind_method(D_METHOD("get_inventory_position_x"), &ItemInstance::get_inventory_position_x); - ClassDB::bind_method(D_METHOD("set_inventory_position_x", "value"), &ItemInstance::set_inventory_position_x); - ADD_PROPERTY(PropertyInfo(Variant::INT, "inventory_position_x"), "set_inventory_position_x", "get_inventory_position_x"); - - ClassDB::bind_method(D_METHOD("get_inventory_position_y"), &ItemInstance::get_inventory_position_y); - ClassDB::bind_method(D_METHOD("set_inventory_position_y", "value"), &ItemInstance::set_inventory_position_y); - ADD_PROPERTY(PropertyInfo(Variant::INT, "inventory_position_y"), "set_inventory_position_y", "get_inventory_position_y"); - + ClassDB::bind_method(D_METHOD("get_inventory_position"), &ItemInstance::get_inventory_position); + ClassDB::bind_method(D_METHOD("set_inventory_position", "value"), &ItemInstance::set_inventory_position); + ADD_PROPERTY(PropertyInfo(Variant::INT, "inventory_position"), "set_inventory_position", "get_inventory_position"); + ClassDB::bind_method(D_METHOD("get_bag"), &ItemInstance::get_bag); ClassDB::bind_method(D_METHOD("set_bag", "bag"), &ItemInstance::set_bag); ClassDB::bind_method(D_METHOD("get_item_template"), &ItemInstance::get_item_template); ClassDB::bind_method(D_METHOD("set_item_template", "value"), &ItemInstance::set_item_template); - ClassDB::bind_method(D_METHOD("get_count"), &ItemInstance::get_count); - ClassDB::bind_method(D_METHOD("set_count", "count"), &ItemInstance::set_count); - ADD_PROPERTY(PropertyInfo(Variant::INT, "ount"), "set_count", "get_count"); + ClassDB::bind_method(D_METHOD("get_stack_size"), &ItemInstance::get_stack_size); + ClassDB::bind_method(D_METHOD("set_stack_size", "count"), &ItemInstance::set_stack_size); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stack_size"), "set_stack_size", "get_stack_size"); ClassDB::bind_method(D_METHOD("get_item_stat_modifier", "index"), &ItemInstance::get_item_stat_modifier); //ClassDB::bind_method(D_METHOD("set_item_stat_modifier", "index", "value"), &ItemInstance::set_item_stat_modifier); diff --git a/data/item_instance.h b/data/item_instance.h index 386486b..04fe0e1 100644 --- a/data/item_instance.h +++ b/data/item_instance.h @@ -18,12 +18,9 @@ public: int get_id(); void set_id(int value); - int get_inventory_position_x() const; - void set_inventory_position_x(const int value); - - int get_inventory_position_y() const; - void set_inventory_position_y(const int value); - + int get_inventory_position() const; + void set_inventory_position(const int value); + Ref get_bag() const; void set_bag(const Ref bag); @@ -48,8 +45,8 @@ public: float get_percent_mod(int index); void set_percent_mod(int index, float value); - int get_count(); - void set_count(int value); + int get_stack_size(); + void set_stack_size(int value); //to_dict(); //from_dict(); @@ -68,15 +65,14 @@ private: int _id; - int _inventory_position_x; - int _inventory_position_y; + int _inventory_position; int _item_tamplate_id; Ref _item_template; - int _count; + int _stack_size; - Ref *_bag; + Ref _bag; int _modifier_count; Ref _modifiers[MAX_ITEM_STAT_MOD]; diff --git a/data/item_template.cpp b/data/item_template.cpp index d893fc9..d270025 100644 --- a/data/item_template.cpp +++ b/data/item_template.cpp @@ -62,20 +62,13 @@ void ItemTemplate::set_price(const int value) { _price = value; } -int ItemTemplate::get_inventory_size_x() const { - return _inventory_size_x; +int ItemTemplate::get_stack_size() const { + return _stack_size; } -void ItemTemplate::set_inventory_size_x(const int value) { - _inventory_size_x = value; +void ItemTemplate::set_stack_size(const int value) { + _stack_size = value; } -int ItemTemplate::get_inventory_size_y() const { - return _inventory_size_y; -} -void ItemTemplate::set_inventory_size_y(const int value) { - _inventory_size_y = value; -} - Ref ItemTemplate::get_icon() const { return _icon; } @@ -349,8 +342,7 @@ ItemTemplate::ItemTemplate() { _scale_z = 0; _modifier_count = 0; - _inventory_size_x = 0; - _inventory_size_y = 0; + _stack_size = 1; _bag_size = 0; for (int i = 0; i < MAX_ITEM_STAT_MOD; ++i) { @@ -411,13 +403,9 @@ void ItemTemplate::_bind_methods() { ClassDB::bind_method(D_METHOD("set_item_visual", "value"), &ItemTemplate::set_item_visual); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "item_visual", PROPERTY_HINT_RESOURCE_TYPE, "ItemVisual"), "set_item_visual", "get_item_visual"); - ClassDB::bind_method(D_METHOD("get_inventory_size_x"), &ItemTemplate::get_inventory_size_x); - ClassDB::bind_method(D_METHOD("set_inventory_size_x", "value"), &ItemTemplate::set_inventory_size_x); - ADD_PROPERTY(PropertyInfo(Variant::INT, "inventory_size_x"), "set_inventory_size_x", "get_inventory_size_x"); - - ClassDB::bind_method(D_METHOD("get_inventory_size_y"), &ItemTemplate::get_inventory_size_y); - ClassDB::bind_method(D_METHOD("set_inventory_size_y", "value"), &ItemTemplate::set_inventory_size_y); - ADD_PROPERTY(PropertyInfo(Variant::INT, "inventory_size_y"), "set_inventory_size_y", "get_inventory_size_y"); + ClassDB::bind_method(D_METHOD("get_stack_size"), &ItemTemplate::get_stack_size); + ClassDB::bind_method(D_METHOD("set_stack_size", "value"), &ItemTemplate::set_stack_size); + ADD_PROPERTY(PropertyInfo(Variant::INT, "stack_size"), "set_stack_size", "get_stack_size"); ClassDB::bind_method(D_METHOD("get_icon"), &ItemTemplate::get_icon); ClassDB::bind_method(D_METHOD("set_icon", "value"), &ItemTemplate::set_icon); diff --git a/data/item_template.h b/data/item_template.h index a89457e..8ed8fd7 100644 --- a/data/item_template.h +++ b/data/item_template.h @@ -44,12 +44,9 @@ public: int get_price() const; void set_price(const int value); - int get_inventory_size_x() const; - void set_inventory_size_x(const int value); + int get_stack_size() const; + void set_stack_size(const int value); - int get_inventory_size_y() const; - void set_inventory_size_y(const int value); - Ref get_icon() const; void set_icon(const Ref value); @@ -147,8 +144,7 @@ private: Ref _item_visual; - int _inventory_size_x; - int _inventory_size_y; + int _stack_size; Ref _icon; diff --git a/entities/data/entity_data.cpp b/entities/data/entity_data.cpp index 845c5a8..cf58dd0 100644 --- a/entities/data/entity_data.cpp +++ b/entities/data/entity_data.cpp @@ -30,6 +30,14 @@ void EntityData::set_entity_type(EntityEnums::EntityType value) { _entity_type = value; } +EntityEnums::EntityInteractionType EntityData::get_entity_interaction_type() { + return _interaction_type; +} + +void EntityData::set_entity_interaction_type(EntityEnums::EntityInteractionType value) { + _interaction_type = value; +} + int EntityData::get_immunity_flags() { return _immunity_flags; } @@ -65,6 +73,13 @@ void EntityData::set_money(int value) { _money = value; } +int EntityData::get_bag_size() { + return _bag_size; +} +void EntityData::set_bag_size(int value) { + _bag_size = value; +} + Ref EntityData::get_icon() { return _icon; } @@ -1191,6 +1206,10 @@ void EntityData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_entity_type", "value"), &EntityData::set_entity_type); ADD_PROPERTY(PropertyInfo(Variant::INT, "entity_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_TYPES), "set_entity_type", "get_entity_type"); + ClassDB::bind_method(D_METHOD("get_entity_interaction_type"), &EntityData::get_entity_interaction_type); + ClassDB::bind_method(D_METHOD("set_entity_interaction_type", "value"), &EntityData::set_entity_interaction_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "entity_interaction_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_INTERACTION_TYPE), "set_entity_interaction_type", "get_entity_interaction_type"); + ClassDB::bind_method(D_METHOD("get_entity_controller"), &EntityData::get_entity_controller); ClassDB::bind_method(D_METHOD("set_entity_controller", "value"), &EntityData::set_entity_controller); ADD_PROPERTY(PropertyInfo(Variant::INT, "entity_controller", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_CONTOLLER), "set_entity_controller", "get_entity_controller"); @@ -1203,6 +1222,10 @@ void EntityData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_money", "value"), &EntityData::set_money); ADD_PROPERTY(PropertyInfo(Variant::INT, "money"), "set_money", "get_money"); + ClassDB::bind_method(D_METHOD("get_bag_size"), &EntityData::get_bag_size); + ClassDB::bind_method(D_METHOD("set_bag_size", "value"), &EntityData::set_bag_size); + ADD_PROPERTY(PropertyInfo(Variant::INT, "bag_size"), "set_bag_size", "get_bag_size"); + ClassDB::bind_method(D_METHOD("get_inherits"), &EntityData::get_inherits); ClassDB::bind_method(D_METHOD("set_inherits", "value"), &EntityData::set_inherits); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "inherits", PROPERTY_HINT_RESOURCE_TYPE, "EntityData"), "set_inherits", "get_inherits"); @@ -1318,8 +1341,10 @@ EntityData::EntityData() { _id = 0; _player_resource_type = 0; _money = 0; + _bag_size = 0; _entity_type = EntityEnums::ENITIY_TYPE_NONE; + _interaction_type = EntityEnums::ENITIY_INTERACTION_TYPE_NORMAL; _immunity_flags = 0; _entity_flags = 0; _entity_controller = EntityEnums::ENITIY_CONTROLLER_NONE; diff --git a/entities/data/entity_data.h b/entities/data/entity_data.h index cf68de1..0928942 100644 --- a/entities/data/entity_data.h +++ b/entities/data/entity_data.h @@ -45,7 +45,10 @@ public: EntityEnums::EntityType get_entity_type(); void set_entity_type(EntityEnums::EntityType value); - + + EntityEnums::EntityInteractionType get_entity_interaction_type(); + void set_entity_interaction_type(EntityEnums::EntityInteractionType value); + int get_immunity_flags(); void set_immunity_flags(int value); @@ -61,6 +64,9 @@ public: int get_money(); void set_money(int value); + int get_bag_size(); + void set_bag_size(int value); + Ref get_inherits(); void set_inherits(Ref value); @@ -266,6 +272,9 @@ private: int _id; EntityEnums::EntityType _entity_type; + + EntityEnums::EntityInteractionType _interaction_type; + int _immunity_flags; int _entity_flags; EntityEnums::EntityController _entity_controller; @@ -278,6 +287,7 @@ private: int _player_resource_type; int _money; + int _bag_size; int _stat_points_per_level; diff --git a/entities/data/player_character_data.cpp b/entities/data/player_character_data.cpp index 4a1777b..78a702e 100644 --- a/entities/data/player_character_data.cpp +++ b/entities/data/player_character_data.cpp @@ -1,5 +1,11 @@ #include "player_character_data.h" +Ref PlayerCharacterData::get_entity_data() { + return _entity_data; +} +void PlayerCharacterData::set_entity_data(Ref data) { + _entity_data = data; +} PlayerCharacterData::PlayerCharacterData() { } @@ -7,5 +13,7 @@ PlayerCharacterData::~PlayerCharacterData() { } void PlayerCharacterData::_bind_methods() { - + ClassDB::bind_method(D_METHOD("get_entity_data"), &PlayerCharacterData::get_entity_data); + ClassDB::bind_method(D_METHOD("set_entity_data", "value"), &PlayerCharacterData::set_entity_data); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "entity_data", PROPERTY_HINT_RESOURCE_TYPE, "EntityData"), "set_entity_data", "get_entity_data"); } diff --git a/entities/data/player_character_data.h b/entities/data/player_character_data.h index 7717559..9f7bca1 100644 --- a/entities/data/player_character_data.h +++ b/entities/data/player_character_data.h @@ -6,11 +6,17 @@ #include "entity_data.h" -class PlayerCharacterData : public EntityData { - GDCLASS(PlayerCharacterData, EntityData); +//Rename this to EntityData, and rename EntityData to EntityClassData +//inheritance in entiotyData? + +class PlayerCharacterData : public Resource { + GDCLASS(PlayerCharacterData, Resource); public: + Ref get_entity_data(); + void set_entity_data(Ref data); + PlayerCharacterData(); ~PlayerCharacterData(); @@ -18,6 +24,7 @@ protected: static void _bind_methods(); private: + Ref _entity_data; }; diff --git a/entities/entity.cpp b/entities/entity.cpp index 56dd72b..c2ecda9 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -4,6 +4,7 @@ #include "../data/spell.h" #include "../entities/auras/aura_data.h" #include "../infos/spell_cast_info.h" +#include "../inventory/bag.h" #include "../pipelines/spell_damage_info.h" #include "../pipelines/spell_heal_info.h" @@ -83,6 +84,23 @@ void Entity::setc_entity_type(EntityEnums::EntityType value) { _c_entity_type = value; } +//EntityInteractionType +EntityEnums::EntityInteractionType Entity::gets_entity_interaction_type() { + return _s_interaction_type; +} +void Entity::sets_entity_interaction_type(EntityEnums::EntityInteractionType value) { + _s_interaction_type = value; + + SEND_RPC(rpc("setc_entity_interaction_type", value), setc_entity_interaction_type(value)); +} + +EntityEnums::EntityInteractionType Entity::getc_entity_interaction_type() { + return _c_interaction_type; +} +void Entity::setc_entity_interaction_type(EntityEnums::EntityInteractionType value) { + _c_interaction_type = value; +} + int Entity::gets_immunity_flags() { return _s_immunity_flags; } @@ -218,8 +236,10 @@ void Entity::sets_entity_data(Ref value) { } void Entity::setup() { + _setup(); + if (has_method("_setup")) { - call("_setup"); + call_multilevel("_setup"); } } @@ -230,6 +250,7 @@ void Entity::_setup() { sets_entity_data_id(_s_entity_data->get_id()); sets_entity_type(_s_entity_data->get_entity_type()); + sets_entity_interaction_type(_s_entity_data->get_entity_interaction_type()); sets_immunity_flags(_s_entity_data->get_immunity_flags()); sets_entity_flags(_s_entity_data->get_entity_flags()); @@ -375,6 +396,9 @@ Dictionary Entity::_to_dict() { dict["skills"] = skills; + if (_s_bag.is_valid()) + dict["bag"] = _s_bag->to_dict(); + return dict; } void Entity::_from_dict(const Dictionary &dict) { @@ -524,6 +548,21 @@ void Entity::_from_dict(const Dictionary &dict) { _s_skills.push_back(r); _c_skills.push_back(r); } + + Dictionary bagd = dict.get("known_spells", Dictionary()); + + if (!bagd.empty()) { + if (!_s_bag.is_valid()) { + Ref bag; + bag.instance(); + + bag->from_dict(bagd); + + sets_bag(_s_bag); + } else { + _s_bag->from_dict(bagd); + } + } } Entity::Entity() { @@ -562,6 +601,9 @@ Entity::Entity() { _s_gcd = 0; _c_gcd = 0; + _s_interaction_type = EntityEnums::ENITIY_INTERACTION_TYPE_NORMAL; + _c_interaction_type = EntityEnums::ENITIY_INTERACTION_TYPE_NORMAL; + for (int i = 0; i < EntityEnums::ENTITY_STATE_TYPE_INDEX_MAX; ++i) { _s_states[i] = 0; } @@ -755,6 +797,7 @@ void Entity::initialize(Ref info) { setc_xp(info->get_xp()); sets_entity_data(info->get_entity_data()); + //setc_entity_data(info->get_entity_data()); /* if (gets_entity_data() != NULL) { @@ -3235,6 +3278,43 @@ void Entity::creceive_rank(int talentID, int rank) { // return NULL; //} +//// Bag //// + +Ref Entity::gets_bag() const { + return _s_bag; +} + +Ref Entity::getc_bag() const { + return _c_bag; +} + +void Entity::sets_bag(const Ref bag) { + _s_bag = bag; + + SEND_RPC(rpc("setc_bag", bag), setc_bag(bag)); +} +void Entity::setc_bag(const Ref bag) { + _c_bag = bag; +} + +Ref Entity::gets_target_bag() const { + return _s_target_bag; +} + +void Entity::sets_target_bag(const Ref bag) { + _s_target_bag = bag; + + SEND_RPC(rpc("setc_target_bag", bag), setc_target_bag(bag)); +} + +Ref Entity::getc_target_bag() const { + return _c_target_bag; +} + +void Entity::setc_target_bag(const Ref bag) { + _c_target_bag = bag; +} + //// DATA //// void Entity::adds_data(Ref data) { _s_data.push_back(data); @@ -3523,10 +3603,10 @@ void Entity::_bind_methods() { ADD_SIGNAL(MethodInfo("cskill_removed", PropertyInfo(Variant::OBJECT, "entity", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), PropertyInfo(Variant::OBJECT, "skill", PROPERTY_HINT_RESOURCE_TYPE, "EntitySkill"))); //setup - BIND_VMETHOD(MethodInfo("_setup", PropertyInfo(Variant::OBJECT, "entity_data", PROPERTY_HINT_RESOURCE_TYPE, "EntityData"))); + BIND_VMETHOD(MethodInfo("_setup")); ClassDB::bind_method(D_METHOD("setup"), &Entity::setup); - ClassDB::bind_method(D_METHOD("_setup"), &Entity::_setup); + //ClassDB::bind_method(D_METHOD("_setup"), &Entity::_setup); //binds ClassDB::bind_method(D_METHOD("sdie"), &Entity::sdie); @@ -3733,6 +3813,15 @@ void Entity::_bind_methods() { ClassDB::bind_method(D_METHOD("setc_entity_type", "value"), &Entity::sets_entity_type); ADD_PROPERTY(PropertyInfo(Variant::INT, "centity_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_TYPES), "setc_entity_type", "getc_entity_type"); + //Interaction type + ClassDB::bind_method(D_METHOD("gets_entity_interaction_type"), &Entity::gets_entity_interaction_type); + ClassDB::bind_method(D_METHOD("sets_entity_interaction_type", "value"), &Entity::sets_entity_interaction_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "sentity_interaction_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_INTERACTION_TYPE), "sets_entity_interaction_type", "gets_entity_interaction_type"); + + ClassDB::bind_method(D_METHOD("getc_entity_interaction_type"), &Entity::getc_entity_interaction_type); + ClassDB::bind_method(D_METHOD("setc_entity_interaction_type", "value"), &Entity::setc_entity_interaction_type); + ADD_PROPERTY(PropertyInfo(Variant::INT, "centity_interaction_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_INTERACTION_TYPE), "setc_entity_interaction_type", "getc_entity_interaction_type"); + ClassDB::bind_method(D_METHOD("gets_immunity_flags"), &Entity::gets_immunity_flags); ClassDB::bind_method(D_METHOD("sets_immunity_flags", "value"), &Entity::sets_immunity_flags); ADD_PROPERTY(PropertyInfo(Variant::INT, "simmunity_flags", PROPERTY_HINT_FLAGS, EntityEnums::BINDING_STRING_ENTITY_IMMUNITY_FLAGS), "sets_immunity_flags", "gets_immunity_flags"); @@ -3974,8 +4063,25 @@ void Entity::_bind_methods() { ClassDB::bind_method(D_METHOD("setc_target", "target"), &Entity::setc_target); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ctarget", PROPERTY_HINT_RESOURCE_TYPE, "Entity"), "setc_target", "getc_target"); - //Serialization + //// Bag System //// + ClassDB::bind_method(D_METHOD("gets_bag"), &Entity::gets_bag); + ClassDB::bind_method(D_METHOD("sets_bag", "bag"), &Entity::sets_bag); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "sbag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), "sets_bag", "gets_bag"); + + ClassDB::bind_method(D_METHOD("getc_bag"), &Entity::getc_bag); + ClassDB::bind_method(D_METHOD("setc_bag", "bag"), &Entity::setc_bag); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "cbag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), "setc_bag", "getc_bag"); + + ClassDB::bind_method(D_METHOD("gets_target_bag"), &Entity::gets_target_bag); + ClassDB::bind_method(D_METHOD("sets_target_bag", "bag"), &Entity::sets_target_bag); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "starget_bag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), "sets_target_bag", "gets_target_bag"); + + ClassDB::bind_method(D_METHOD("getc_target_bag"), &Entity::getc_target_bag); + ClassDB::bind_method(D_METHOD("setc_target_bag", "bag"), &Entity::setc_target_bag); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ctarget_bag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), "setc_target_bag", "getc_target_bag"); + + //Serialization BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict"))); BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict")); diff --git a/entities/entity.h b/entities/entity.h index 446637e..9791484 100644 --- a/entities/entity.h +++ b/entities/entity.h @@ -138,12 +138,20 @@ public: int getc_entity_data_id(); void setc_entity_data_id(int value); + //EntityType EntityEnums::EntityType gets_entity_type(); void sets_entity_type(EntityEnums::EntityType value); EntityEnums::EntityType getc_entity_type(); void setc_entity_type(EntityEnums::EntityType value); + //EntityInteractionType + EntityEnums::EntityInteractionType gets_entity_interaction_type(); + void sets_entity_interaction_type(EntityEnums::EntityInteractionType value); + + EntityEnums::EntityInteractionType getc_entity_interaction_type(); + void setc_entity_interaction_type(EntityEnums::EntityInteractionType value); + int gets_immunity_flags(); void sets_immunity_flags(int value); @@ -496,7 +504,7 @@ public: Ref getc_skill(int index); int getc_skill_count(); - //// TargetComponent //// + //// Target //// void crequest_target_change(NodePath path); void net_sets_target(NodePath path); @@ -508,7 +516,7 @@ public: Entity *getc_target(); void setc_target(Node *p_target); - //// TalentComponent //// + //// Talents //// void csend_request_rank_increase(int talentID); void csend_request_rank_decrease(int talentID); @@ -519,6 +527,20 @@ public: //PlayerTalent *sget_talent(int id, bool create = false); //PlayerTalent *cget_talent(int id, bool create = false); + //// Inventory //// + + Ref gets_bag() const; + Ref getc_bag() const; + + void sets_bag(const Ref bag); + void setc_bag(const Ref bag); + + Ref gets_target_bag() const; + void sets_target_bag(const Ref bag); + + Ref getc_target_bag() const; + void setc_target_bag(const Ref bag); + //// Data //// void adds_data(Ref data); void removes_data(int index); @@ -535,7 +557,7 @@ public: String random_name(); void setup(); - void _setup(); + virtual void _setup(); Dictionary to_dict(); void from_dict(const Dictionary &dict); @@ -590,6 +612,9 @@ private: String _s_player_name; String _c_player_name; + EntityEnums::EntityInteractionType _s_interaction_type; + EntityEnums::EntityInteractionType _c_interaction_type; + //// Stats //// Ref _health; @@ -699,6 +724,14 @@ private: //// Stat Allocations //// //int _unallocated_stats; //int _stat_allocations[Stat::STAT_ID_TOTAL_STATS]; + + //// Inventory //// + + Ref _s_bag; + Ref _c_bag; + + Ref _s_target_bag; + Ref _c_target_bag; }; #endif diff --git a/entities/player.cpp b/entities/player.cpp index 509d61c..3ed42b2 100644 --- a/entities/player.cpp +++ b/entities/player.cpp @@ -1,166 +1,22 @@ #include "player.h" -#include "../inventory/inventory.h" +#include "../inventory/bag.h" -//// Inventory //// +void Player::_setup() { + Entity::_setup(); -Ref Player::gets_inventory() const { - return _s_inventory; -} + if (gets_entity_data().is_valid()) { + Ref bag; + bag.instance(); -Ref Player::getc_inventory() const { - return _c_inventory; -} + bag->set_size(gets_entity_data()->get_bag_size()); -void Player::sets_inventory(const Ref inventory) { - _s_inventory = inventory; -} -void Player::setc_inventory(const Ref inventory) { - _c_inventory = inventory; -} - -Ref Player::gets_target_inventory() const { - return _s_target_inventory; -} - -void Player::sets_target_inventory(const Ref inventory) { - _s_target_inventory = inventory; -} - -Ref Player::getc_target_inventory() const { - return _c_target_inventory; -} - -void Player::setc_target_inventory(const Ref inventory) { - _c_target_inventory = inventory; -} - -bool Player::stry_to_add_item(int itemId, int count) { - return false; -} - -bool Player::stry_to_remove_item(int itemId, int count) { - return false; -} - -void Player::ssend_add_item(int slotId, int itemId, int count) { -} - -void Player::ssend_change_item_count(int slotId, int count) { -} - -void Player::ssend_remove_item(int slotId) { -} - -void Player::ssend_move_item(int slot1, int slot2) { -} - -void Player::ssend_sent_items(String items) { -} - -void Player::csend_swap_items(int slot1, int slot2) { -} - -void Player::csend_craft_item_request(int craftId) { -} - -void Player::creceive_add_item(int slotId, int itemId, int count) { -} - -void Player::creceive_change_item_count(int slotId, int count) { -} - -void Player::creceive_remove_item(int slotId) { -} - -void Player::creceive_move_item(int slot1, int slot2) { -} - -void Player::creceive_sent_items(String items) { -} - -void Player::sreceive_swap_items(int slot1, int slot2) { -} - -void Player::send_all_items() { -} - -bool Player::shas_item(int itemId, int count) { - /* - for (int i = 0; i < getSInventory()->Count; i += 1) { - if (((getSInventory()->GetData(i) != null) && (getSInventory()->GetData(i)->ItemID == itemId)) && (getSInventory()->GetData(i)->Count >= count)) { - return true; - } - } - return false;*/ - - return false; -} - -bool Player::chas_item(int itemId, int count) { - /* - for (int i = 0; i < getCInventory()->Count; i += 1) { - if (((getCInventory()->GetData(i) != null) && (getCInventory()->GetData(i)->ItemID == itemId)) && (getCInventory()->GetData(i)->Count >= count)) { - return true; - } - } - return false;*/ - - return false; -} - -int Player::cget_item_count(int itemId) { - return 0; -} - -int Player::sget_item_count(int itemId) { - return 0; -} - -bool Player::ccan_craft(CraftDataAttribute *cda) { - return false; -} - -bool Player::ctry_to_craft(CraftDataAttribute *cda) { - return false; -} - -bool Player::scan_craft(CraftDataAttribute *cda) { - return false; -} - -void Player::scraft(CraftDataAttribute *cda) { -} - -void Player::sreceive_craft_item_msg(int craftId) { -} - -void Player::cswap_items_in_slots(int slot1, int slot2) { + sets_bag(bag); + } } Player::Player() { } void Player::_bind_methods() { - //// Inventory System //// - - ADD_SIGNAL(MethodInfo("sitem_added", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"))); - ADD_SIGNAL(MethodInfo("citem_added", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"))); - - ClassDB::bind_method(D_METHOD("gets_inventory"), &Player::gets_inventory); - ClassDB::bind_method(D_METHOD("getc_inventory"), &Player::getc_inventory); - - ClassDB::bind_method(D_METHOD("sets_inventory", "inventory"), &Player::sets_inventory); - ClassDB::bind_method(D_METHOD("setc_inventory", "inventory"), &Player::setc_inventory); - - ClassDB::bind_method(D_METHOD("gets_target_inventory"), &Player::gets_target_inventory); - ClassDB::bind_method(D_METHOD("sets_target_inventory", "inventory"), &Player::sets_target_inventory); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "starget_inventory", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), "sets_target_inventory", "gets_target_inventory"); - - ClassDB::bind_method(D_METHOD("getc_target_inventory"), &Player::getc_target_inventory); - ClassDB::bind_method(D_METHOD("setc_target_inventory", "inventory"), &Player::setc_target_inventory); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "ctarget_inventory", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), "setc_target_inventory", "getc_target_inventory"); - - BIND_ENUM_CONSTANT(BACKPACK_SIZE); - BIND_ENUM_CONSTANT(MAX_BAG_SLOTS); } diff --git a/entities/player.h b/entities/player.h index c13d4e7..4523564 100644 --- a/entities/player.h +++ b/entities/player.h @@ -3,77 +3,22 @@ #include "entity.h" -class Inventory; +class Bag; class Player : public Entity { GDCLASS(Player, Entity); public: - enum InventorySizes { - BACKPACK_SIZE = 20, - MAX_BAG_SLOTS = 5, - }; - - //// Inventory //// + void _setup(); - Ref gets_inventory() const; - Ref getc_inventory() const; - - void sets_inventory(const Ref inventory); - void setc_inventory(const Ref inventory); - - Ref gets_target_inventory() const; - void sets_target_inventory(const Ref inventory); - - Ref getc_target_inventory() const; - void setc_target_inventory(const Ref inventory); - - bool add_item_to_inventory(Ref item); - - bool stry_to_add_item(int itemId, int count); - bool stry_to_remove_item(int itemId, int count); - void ssend_add_item(int slotId, int itemId, int count); - void ssend_change_item_count(int slotId, int count); - void ssend_remove_item(int slotId); - void ssend_move_item(int slot1, int slot2); - void ssend_sent_items(String items); - void csend_swap_items(int slot1, int slot2); - void csend_craft_item_request(int craftId); - void creceive_add_item(int slotId, int itemId, int count); - void creceive_change_item_count(int slotId, int count); - void creceive_remove_item(int slotId); - void creceive_move_item(int slot1, int slot2); - void creceive_sent_items(String items); - void sreceive_swap_items(int slot1, int slot2); - bool shas_item(int itemId, int count); - bool chas_item(int itemId, int count); - int cget_item_count(int itemId); - int sget_item_count(int itemId); - bool ccan_craft(CraftDataAttribute *cda); - bool ctry_to_craft(CraftDataAttribute *cda); - bool scan_craft(CraftDataAttribute *cda); - void scraft(CraftDataAttribute *cda); - void sreceive_craft_item_msg(int craftId); - void cswap_items_in_slots(int slot1, int slot2); - - void send_all_items(); - Player(); protected: static void _bind_methods(); private: - //// Inventory //// - - Ref _s_inventory; - Ref _c_inventory; - Ref _s_target_inventory; - Ref _c_target_inventory; - }; -VARIANT_ENUM_CAST(Player::InventorySizes); #endif diff --git a/entity_enums.cpp b/entity_enums.cpp index 0f8a79e..8b27d21 100644 --- a/entity_enums.cpp +++ b/entity_enums.cpp @@ -9,6 +9,7 @@ const String EntityEnums::BINDING_STRING_ENTITY_STATE_TYPES = "None,Stun,Root,Fr const String EntityEnums::BINDING_STRING_CHARCATER_SKELETON_POINTS = "Root,Pelvis,Spine,Spine 1,Spine 2,Neck,Head,Left Clavicle,Left upper Arm,Left Forearm,Left Hand,Left Thumb Base,Left Thumb End,Left Fingers Base,Left Fingers End,Right Clavicle,Right upper Arm,Right Forearm,Right Hand,Right Thumb Base,Right Thumb End,Right Fingers Base,Right Fingers End,Left Thigh,Left Calf,Left Foot,Right Thigh,Right Calf,Right Foot"; const String EntityEnums::BINDING_STRING_AI_STATES = "Off,Rest,Patrol,Follow Path,Regenerate,Attack"; const String EntityEnums::BINDING_STRING_ENTITY_IMMUNITY_FLAGS = "Stun,Root,Freeze,Silence,Disorient,Fear,Burning,Cold,Pacify,Magic,Poison,Physical,Curse,Bleed,Melee,Holy,Shadow,Nature,Fire,Frost,Lightning,Chaos,Slow,Crit,AOE,Damage,Fall Damage,Projectile,Debuff,Attacks"; +const String EntityEnums::BINDING_STRING_ENTITY_INTERACTION_TYPE = "Normal,Speak,Loot,Use,None"; const int EntityEnums::PLAYER_RESOURCE_TYPES_RAGE = 0; const int EntityEnums::PLAYER_RESOURCE_TYPES_MANA = 1; @@ -157,5 +158,11 @@ void EntityEnums::_bind_methods() { BIND_ENUM_CONSTANT(ENTITY_IMMUNITY_FLAG_DEBUFF); BIND_ENUM_CONSTANT(ENTITY_IMMUNITY_FLAG_ATTACKS); + BIND_ENUM_CONSTANT(ENITIY_INTERACTION_TYPE_NORMAL); + BIND_ENUM_CONSTANT(ENITIY_INTERACTION_TYPE_SPEAK); + BIND_ENUM_CONSTANT(ENITIY_INTERACTION_TYPE_LOOT); + BIND_ENUM_CONSTANT(ENITIY_INTERACTION_TYPE_USE); + BIND_ENUM_CONSTANT(ENITIY_INTERACTION_TYPE_NONE); + BIND_CONSTANT(MAX_LEVEL); } diff --git a/entity_enums.h b/entity_enums.h index 4799ee7..b46c7e8 100644 --- a/entity_enums.h +++ b/entity_enums.h @@ -17,6 +17,7 @@ public: static const String BINDING_STRING_CHARCATER_SKELETON_POINTS; static const String BINDING_STRING_AI_STATES; static const String BINDING_STRING_ENTITY_IMMUNITY_FLAGS; + static const String BINDING_STRING_ENTITY_INTERACTION_TYPE; static const int PLAYER_RESOURCE_TYPES_RAGE; static const int PLAYER_RESOURCE_TYPES_MANA; @@ -198,6 +199,14 @@ public: AI_STATE_ATTACK, }; + enum EntityInteractionType { + ENITIY_INTERACTION_TYPE_NORMAL, + ENITIY_INTERACTION_TYPE_SPEAK, + ENITIY_INTERACTION_TYPE_LOOT, + ENITIY_INTERACTION_TYPE_USE, + ENITIY_INTERACTION_TYPE_NONE, + }; + enum { MAX_LEVEL = 50, }; @@ -216,5 +225,6 @@ VARIANT_ENUM_CAST(EntityEnums::EntityStateTypeIndexes); VARIANT_ENUM_CAST(EntityEnums::CharacterSkeletonPoints); VARIANT_ENUM_CAST(EntityEnums::AIStates); VARIANT_ENUM_CAST(EntityEnums::EntityImmunityFlags); +VARIANT_ENUM_CAST(EntityEnums::EntityInteractionType); #endif diff --git a/inventory/bag.cpp b/inventory/bag.cpp index 4e2e6e5..65e5e59 100644 --- a/inventory/bag.cpp +++ b/inventory/bag.cpp @@ -11,92 +11,250 @@ void Bag::set_allowed_item_types(const int value) { _allowed_item_types = value; } -/* bool Bag::add_item(Ref item) { - ERR_FAIL_COND_V(!has_method("_add_item"), false); - - return call("_add_item", item); + ERR_FAIL_COND_V(!item.is_valid(), false); + + if (has_method("_add_item")) { + return call("_add_item", item); + } + + int max_stack = item->get_item_template()->get_stack_size(); + + if (max_stack > 1) { + for (int i = 0; i < _items.size(); ++i) { + Ref ii = _items.get(i); + + if (!ii.is_valid()) + continue; + + if (ii->get_stack_size() < max_stack) { + int fs = max_stack - ii->get_stack_size(); + + if (fs > item->get_stack_size()) { + ii->set_stack_size(ii->get_stack_size() + item->get_stack_size()); + + item->set_stack_size(0); + + emit_signal("item_count_changed", Ref(this), ii, i); + + return true; + } else { + ii->set_stack_size(max_stack); + item->set_stack_size(item->get_stack_size() - fs); + + emit_signal("item_count_changed", Ref(this), ii, i); + } + } + } + } + + item->set_bag(Ref(this)); + + for (int i = 0; i < _items.size(); ++i) { + Ref ii = _items.get(i); + + if (!ii.is_valid()) { + _items.set(i, item); + + emit_signal("item_added", Ref(this), item, i); + + if (get_valid_item_count() == _bag_size) { + emit_signal("overburdened", Ref(this)); + } + + return true; + } + } + + _items.push_back(item); + + emit_signal("item_added", Ref(this), item, _items.size() - 1); + + if (get_valid_item_count() == _bag_size) { + emit_signal("overburdened", Ref(this)); + } + + return true; } - Ref Bag::get_item(const int index) { - ERR_FAIL_COND_V(!has_method("_get_item"), Ref(NULL)); - - return call("_get_item", index); + if (has_method("_get_item")) { + return call("_get_item", index); + } + + ERR_FAIL_INDEX_V(index, _items.size(), Ref()); + + return _items.get(index); } Ref Bag::remove_item(const int index) { - ERR_FAIL_COND_V(!has_method("_remove_item"), Ref(NULL)); - - return call("_remove_item", index); + if (has_method("_remove_item")) { + return call("_remove_item", index); + } + + ERR_FAIL_INDEX_V(index, _items.size(), Ref()); + + Ref ii = _items.get(index); + + if (!ii.is_valid()) + return ii; + + ii->set_bag(Ref()); + + _items.set(index, Ref()); + + emit_signal("item_removed", Ref(this), ii, index); + + if (get_valid_item_count() + 1 == _bag_size) { + emit_signal("overburden_removed", Ref(this)); + } + + return ii; } void Bag::swap_items(const int item1_index, const int item2_index) { - ERR_FAIL_COND(!has_method("_swap_items")); - - call("_swap_items", item1_index, item2_index); + if (has_method("_swap_items")) { + call("_swap_items", item1_index, item2_index); + return; + } + + ERR_FAIL_INDEX(item1_index, _items.size()); + ERR_FAIL_INDEX(item2_index, _items.size()); + + Ref ii = _items.get(item1_index); + + _items.set(item1_index, _items.get(item2_index)); + + _items.set(item2_index, ii); + + emit_signal("item_swapped", Ref(this), item1_index, item2_index); } bool Bag::can_add_item(const Ref item) { - ERR_FAIL_COND_V(!has_method("_can_add_item"), false); - - return call("_can_add_item", item); + if (has_method("_can_add_item")) { + return call("_can_add_item", item); + } + + return true; } int Bag::get_item_count() { - ERR_FAIL_COND_V(!has_method("_get_item_count"), 0); - - return call("_get_item_count"); + if (has_method("_get_item_count")) { + return call("_get_item_count"); + } + + return _items.size(); } +int Bag::get_valid_item_count() { + if (has_method("_get_valid_item_count")) { + return call("_get_valid_item_count"); + } + + int ii = 0; + + for (int i = 0; i < _items.size(); ++i) { + if (_items.get(i).is_valid()) + ++ii; + } + + return ii; +} int Bag::get_size() { - ERR_FAIL_COND_V(!has_method("_get_size"), 0); - - return call("_get_size"); + if (has_method("_get_size")) { + return call("_get_size"); + } + + return _bag_size; } void Bag::set_size(const int size) { - ERR_FAIL_COND(!has_method("_set_size")); - - call("_set_size"); + if (has_method("_set_size")) { + call("_set_size", size); + return; + } + + int item_count = get_valid_item_count(); + + if (_bag_size > size && _bag_size > item_count && size <= item_count) { + _bag_size = size; + + emit_signal("overburdened", Ref(this)); + + return; + } + + _bag_size = size; } bool Bag::is_full() { - ERR_FAIL_COND_V(!has_method("_is_full"), true); - - return call("_is_full"); + if (has_method("_is_full")) { + return call("_is_full"); + } + + return false; } -*/ + +bool Bag::is_overburdened() { + if (has_method("_is_overburdened")) { + return call("_is_overburdened"); + } + + return _bag_size < get_valid_item_count(); +} + +Dictionary Bag::to_dict() { + return call("_to_dict"); +} +void Bag::from_dict(const Dictionary &dict) { + call("_from_dict", dict); +} + +Dictionary Bag::_to_dict() { + Dictionary dict; + + return dict; +} +void Bag::_from_dict(const Dictionary &dict) { + _items.clear(); +} + Bag::Bag() { _allowed_item_types = 0xFFFFFF; + _bag_size = 0; } Bag::~Bag() { + _items.clear(); } void Bag::_bind_methods() { - ADD_SIGNAL(MethodInfo("changed", PropertyInfo(Variant::OBJECT, "bag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"))); - + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "could_add"), "_add_item", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"), "_get_item", PropertyInfo(Variant::INT, "index"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"), "_remove_item", PropertyInfo(Variant::INT, "index"))); + BIND_VMETHOD(MethodInfo("_swap_items", PropertyInfo(Variant::INT, "item1_index"), PropertyInfo(Variant::INT, "item2_index"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "can"), "_can_add_item", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "count"), "_get_item_count")); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "count"), "_get_valid_item_count")); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "size"), "_get_size")); + BIND_VMETHOD(MethodInfo("_set_size", PropertyInfo(Variant::INT, "size"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "full"), "_is_full")); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "overburdened"), "_is_overburdened")); + + ADD_SIGNAL(MethodInfo("item_added", PropertyInfo(Variant::OBJECT, "bag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"), PropertyInfo(Variant::INT, "slot_id"))); + ADD_SIGNAL(MethodInfo("item_removed", PropertyInfo(Variant::OBJECT, "bag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"), PropertyInfo(Variant::INT, "slot_id"))); + ADD_SIGNAL(MethodInfo("item_swapped", PropertyInfo(Variant::OBJECT, "bag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), PropertyInfo(Variant::INT, "slot_id_1"), PropertyInfo(Variant::INT, "slot_id_2"))); + ADD_SIGNAL(MethodInfo("item_count_changed", PropertyInfo(Variant::OBJECT, "bag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"), PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"), PropertyInfo(Variant::INT, "slot_id"))); + ADD_SIGNAL(MethodInfo("overburdened", PropertyInfo(Variant::OBJECT, "bag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"))); + ADD_SIGNAL(MethodInfo("overburden_removed", PropertyInfo(Variant::OBJECT, "bag", PROPERTY_HINT_RESOURCE_TYPE, "Bag"))); + ClassDB::bind_method(D_METHOD("get_allowed_item_types"), &Bag::get_allowed_item_types); ClassDB::bind_method(D_METHOD("set_allowed_item_types", "count"), &Bag::set_allowed_item_types); ADD_PROPERTY(PropertyInfo(Variant::INT, "allowed_item_types", PROPERTY_HINT_FLAGS, ItemEnums::BINDING_STRING_ITEM_TYPE_FLAGS), "set_allowed_item_types", "get_allowed_item_types"); - /* - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "could_add"), "_add_item", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"))); - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"), "_get_item", PropertyInfo(Variant::INT, "index"))); - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"), "_remove_item", PropertyInfo(Variant::INT, "index"))); - BIND_VMETHOD(MethodInfo("_swap_items", PropertyInfo(Variant::INT, "item1_index"), PropertyInfo(Variant::INT, "item2_index"))); - - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "can"), "_can_add_item", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"))); - - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "count"), "_get_item_count")); - - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "size"), "_get_size")); - BIND_VMETHOD(MethodInfo("_set_size", PropertyInfo(Variant::INT, "size"))); - - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::BOOL, "full"), "_is_full")); - + + ClassDB::bind_method(D_METHOD("add_item", "item"), &Bag::add_item); ClassDB::bind_method(D_METHOD("get_item", "index"), &Bag::get_item); ClassDB::bind_method(D_METHOD("remove_item", "index"), &Bag::remove_item); @@ -109,5 +267,16 @@ void Bag::_bind_methods() { ClassDB::bind_method(D_METHOD("get_size"), &Bag::get_size); ClassDB::bind_method(D_METHOD("set_size", "size"), &Bag::set_size); - ClassDB::bind_method(D_METHOD("is_full"), &Bag::is_full);*/ + ClassDB::bind_method(D_METHOD("is_full"), &Bag::is_full); + ClassDB::bind_method(D_METHOD("is_overburdened"), &Bag::is_overburdened); + + //Serialization + BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict")); + + ClassDB::bind_method(D_METHOD("from_dict", "dict"), &Bag::from_dict); + ClassDB::bind_method(D_METHOD("to_dict"), &Bag::to_dict); + + ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &Bag::_from_dict); + ClassDB::bind_method(D_METHOD("_to_dict"), &Bag::_to_dict); } diff --git a/inventory/bag.h b/inventory/bag.h index 9e32398..214d5e0 100644 --- a/inventory/bag.h +++ b/inventory/bag.h @@ -15,8 +15,7 @@ class Bag : public Reference { public: int get_allowed_item_types() const; void set_allowed_item_types(const int value); - - /* + bool add_item(Ref item); Ref get_item(const int index); Ref remove_item(const int index); @@ -25,14 +24,19 @@ public: bool can_add_item(Ref item); int get_item_count(); + int get_valid_item_count(); int get_size(); void set_size(const int size); - bool is_full();*/ + bool is_full(); + bool is_overburdened(); - //to_dict(); - //from_dict(); + Dictionary to_dict(); + void from_dict(const Dictionary &dict); + + Dictionary _to_dict(); + void _from_dict(const Dictionary &dict); Bag(); ~Bag(); @@ -42,6 +46,8 @@ protected: private: int _allowed_item_types; + int _bag_size; + Vector > _items; }; #endif diff --git a/register_types.cpp b/register_types.cpp index 0d85a23..f3ce6b1 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -46,7 +46,7 @@ #include "inventory/bag.h" -#include "inventory/inventory.h" +//#include "inventory/inventory.h" #include "data/craft_data_attribute_helper.h" #include "data/craft_data_attribute.h" @@ -164,7 +164,7 @@ void register_entity_spell_system_types() { ClassDB::register_class(); ClassDB::register_class(); - ClassDB::register_class(); + //ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class();