Implemented Bags, and added a InteractionType enum.

This commit is contained in:
Relintai 2019-09-16 21:57:55 +02:00
parent f3a9a9e14a
commit 18925ee236
18 changed files with 496 additions and 360 deletions

2
SCsub
View File

@ -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")

View File

@ -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<Bag> ItemInstance::get_bag() const {
if (_bag == NULL) {
return Ref<Bag>(NULL);
}
return *_bag;
return _bag;
}
void ItemInstance::set_bag(const Ref<Bag> bag) {
if (_bag == NULL) {
_bag = memnew(Ref<Bag>(NULL));
} else {
_bag->unref();
(*_bag) = bag;
}
_bag = bag;
}
Ref<ItemTemplate> 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);

View File

@ -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<Bag> get_bag() const;
void set_bag(const Ref<Bag> 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<ItemTemplate> _item_template;
int _count;
int _stack_size;
Ref<Bag> *_bag;
Ref<Bag> _bag;
int _modifier_count;
Ref<ItemStatModifier> _modifiers[MAX_ITEM_STAT_MOD];

View File

@ -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<Texture> 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);

View File

@ -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<Texture> get_icon() const;
void set_icon(const Ref<Texture> value);
@ -147,8 +144,7 @@ private:
Ref<ItemVisual> _item_visual;
int _inventory_size_x;
int _inventory_size_y;
int _stack_size;
Ref<Texture> _icon;

View File

@ -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<Texture> 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;

View File

@ -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<EntityData> get_inherits();
void set_inherits(Ref<EntityData> 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;

View File

@ -1,5 +1,11 @@
#include "player_character_data.h"
Ref<EntityData> PlayerCharacterData::get_entity_data() {
return _entity_data;
}
void PlayerCharacterData::set_entity_data(Ref<EntityData> 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");
}

View File

@ -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<EntityData> get_entity_data();
void set_entity_data(Ref<EntityData> data);
PlayerCharacterData();
~PlayerCharacterData();
@ -18,6 +24,7 @@ protected:
static void _bind_methods();
private:
Ref<EntityData> _entity_data;
};

View File

@ -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<EntityData> 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;
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<EntityCreateInfo> 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<Bag> Entity::gets_bag() const {
return _s_bag;
}
Ref<Bag> Entity::getc_bag() const {
return _c_bag;
}
void Entity::sets_bag(const Ref<Bag> bag) {
_s_bag = bag;
SEND_RPC(rpc("setc_bag", bag), setc_bag(bag));
}
void Entity::setc_bag(const Ref<Bag> bag) {
_c_bag = bag;
}
Ref<Bag> Entity::gets_target_bag() const {
return _s_target_bag;
}
void Entity::sets_target_bag(const Ref<Bag> bag) {
_s_target_bag = bag;
SEND_RPC(rpc("setc_target_bag", bag), setc_target_bag(bag));
}
Ref<Bag> Entity::getc_target_bag() const {
return _c_target_bag;
}
void Entity::setc_target_bag(const Ref<Bag> bag) {
_c_target_bag = bag;
}
//// DATA ////
void Entity::adds_data(Ref<EntityDataContainer> 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"));

View File

@ -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<EntitySkill> 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<Bag> gets_bag() const;
Ref<Bag> getc_bag() const;
void sets_bag(const Ref<Bag> bag);
void setc_bag(const Ref<Bag> bag);
Ref<Bag> gets_target_bag() const;
void sets_target_bag(const Ref<Bag> bag);
Ref<Bag> getc_target_bag() const;
void setc_target_bag(const Ref<Bag> bag);
//// Data ////
void adds_data(Ref<EntityDataContainer> 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<Stat> _health;
@ -699,6 +724,14 @@ private:
//// Stat Allocations ////
//int _unallocated_stats;
//int _stat_allocations[Stat::STAT_ID_TOTAL_STATS];
//// Inventory ////
Ref<Bag> _s_bag;
Ref<Bag> _c_bag;
Ref<Bag> _s_target_bag;
Ref<Bag> _c_target_bag;
};
#endif

View File

@ -1,166 +1,22 @@
#include "player.h"
#include "../inventory/inventory.h"
#include "../inventory/bag.h"
//// Inventory ////
void Player::_setup() {
Entity::_setup();
Ref<Inventory> Player::gets_inventory() const {
return _s_inventory;
}
if (gets_entity_data().is_valid()) {
Ref<Bag> bag;
bag.instance();
Ref<Inventory> Player::getc_inventory() const {
return _c_inventory;
}
bag->set_size(gets_entity_data()->get_bag_size());
void Player::sets_inventory(const Ref<Inventory> inventory) {
_s_inventory = inventory;
}
void Player::setc_inventory(const Ref<Inventory> inventory) {
_c_inventory = inventory;
}
Ref<Inventory> Player::gets_target_inventory() const {
return _s_target_inventory;
}
void Player::sets_target_inventory(const Ref<Inventory> inventory) {
_s_target_inventory = inventory;
}
Ref<Inventory> Player::getc_target_inventory() const {
return _c_target_inventory;
}
void Player::setc_target_inventory(const Ref<Inventory> 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);
}

View File

@ -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<Inventory> gets_inventory() const;
Ref<Inventory> getc_inventory() const;
void sets_inventory(const Ref<Inventory> inventory);
void setc_inventory(const Ref<Inventory> inventory);
Ref<Inventory> gets_target_inventory() const;
void sets_target_inventory(const Ref<Inventory> inventory);
Ref<Inventory> getc_target_inventory() const;
void setc_target_inventory(const Ref<Inventory> inventory);
bool add_item_to_inventory(Ref<ItemInstance> 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<Inventory> _s_inventory;
Ref<Inventory> _c_inventory;
Ref<Inventory> _s_target_inventory;
Ref<Inventory> _c_target_inventory;
};
VARIANT_ENUM_CAST(Player::InventorySizes);
#endif

View File

@ -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);
}

View File

@ -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

View File

@ -11,92 +11,250 @@ void Bag::set_allowed_item_types(const int value) {
_allowed_item_types = value;
}
/*
bool Bag::add_item(Ref<ItemInstance> 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<ItemInstance> 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<Bag>(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<Bag>(this), ii, i);
}
}
}
}
item->set_bag(Ref<Bag>(this));
for (int i = 0; i < _items.size(); ++i) {
Ref<ItemInstance> ii = _items.get(i);
if (!ii.is_valid()) {
_items.set(i, item);
emit_signal("item_added", Ref<Bag>(this), item, i);
if (get_valid_item_count() == _bag_size) {
emit_signal("overburdened", Ref<Bag>(this));
}
return true;
}
}
_items.push_back(item);
emit_signal("item_added", Ref<Bag>(this), item, _items.size() - 1);
if (get_valid_item_count() == _bag_size) {
emit_signal("overburdened", Ref<Bag>(this));
}
return true;
}
Ref<ItemInstance> Bag::get_item(const int index) {
ERR_FAIL_COND_V(!has_method("_get_item"), Ref<ItemInstance>(NULL));
return call("_get_item", index);
if (has_method("_get_item")) {
return call("_get_item", index);
}
ERR_FAIL_INDEX_V(index, _items.size(), Ref<ItemInstance>());
return _items.get(index);
}
Ref<ItemInstance> Bag::remove_item(const int index) {
ERR_FAIL_COND_V(!has_method("_remove_item"), Ref<ItemInstance>(NULL));
return call("_remove_item", index);
if (has_method("_remove_item")) {
return call("_remove_item", index);
}
ERR_FAIL_INDEX_V(index, _items.size(), Ref<ItemInstance>());
Ref<ItemInstance> ii = _items.get(index);
if (!ii.is_valid())
return ii;
ii->set_bag(Ref<Bag>());
_items.set(index, Ref<ItemInstance>());
emit_signal("item_removed", Ref<Bag>(this), ii, index);
if (get_valid_item_count() + 1 == _bag_size) {
emit_signal("overburden_removed", Ref<Bag>(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<ItemInstance> ii = _items.get(item1_index);
_items.set(item1_index, _items.get(item2_index));
_items.set(item2_index, ii);
emit_signal("item_swapped", Ref<Bag>(this), item1_index, item2_index);
}
bool Bag::can_add_item(const Ref<ItemInstance> 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<Bag>(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);
}

View File

@ -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<ItemInstance> item);
Ref<ItemInstance> get_item(const int index);
Ref<ItemInstance> remove_item(const int index);
@ -25,14 +24,19 @@ public:
bool can_add_item(Ref<ItemInstance> 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<Ref<ItemInstance> > _items;
};
#endif

View File

@ -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<CharacterSpec>();
ClassDB::register_class<Bag>();
ClassDB::register_class<Inventory>();
//ClassDB::register_class<Inventory>();
ClassDB::register_class<SpellDamageInfo>();
ClassDB::register_class<SpellHealInfo>();