mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-05-11 22:42:10 +02:00
More work on the inventory.
This commit is contained in:
parent
53227bb6fe
commit
adc47a4ae7
1
SCsub
1
SCsub
@ -41,6 +41,7 @@ module_env.add_source_files(env.modules_sources,"entities/stats/stat_data.cpp")
|
||||
|
||||
module_env.add_source_files(env.modules_sources,"entities/player_talent.cpp")
|
||||
module_env.add_source_files(env.modules_sources,"inventory/bag_slot.cpp")
|
||||
module_env.add_source_files(env.modules_sources,"inventory/bag.cpp")
|
||||
|
||||
module_env.add_source_files(env.modules_sources,"spells/aura_infos.cpp")
|
||||
module_env.add_source_files(env.modules_sources,"spells/spell_cast_info.cpp")
|
||||
|
@ -1,67 +1,83 @@
|
||||
#include "bag.h"
|
||||
|
||||
Ref<BagSlot> Bag::get_slot(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _slots->size(), Ref<BagSlot>(NULL));
|
||||
|
||||
return(_slots->get(index));
|
||||
ERR_FAIL_INDEX_V(index, _slots->size(), Ref<BagSlot>(NULL));
|
||||
|
||||
return (_slots->get(index));
|
||||
}
|
||||
|
||||
Ref<BagSlot> Bag::get_and_remove_slot(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _slots->size(), Ref<BagSlot>(NULL));
|
||||
|
||||
Ref<BagSlot> slot = _slots->get(index);
|
||||
|
||||
_slots->set(index, Ref<BagSlot>(memnew(BagSlot()));
|
||||
ERR_FAIL_INDEX_V(index, _slots->size(), Ref<BagSlot>(NULL));
|
||||
|
||||
Ref<BagSlot> slot = _slots->get(index);
|
||||
|
||||
_slots->set(index, Ref<BagSlot>(memnew(BagSlot())));
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
int Bag::get_slot_count() {
|
||||
return _slots->size();
|
||||
return _slots->size();
|
||||
}
|
||||
|
||||
void Bag::set_slot_count(int count) {
|
||||
ERR_FAIL_COND(_slots->size() != 0);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
_slots->push_back(memnew(BagSlot()));
|
||||
}
|
||||
ERR_FAIL_COND(_slots->size() != 0);
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
_slots->push_back(memnew(BagSlot()));
|
||||
}
|
||||
}
|
||||
|
||||
bool Bag::try_to_add_item(Ref<ItemInstance> item, int count = 1) {
|
||||
ERR_FAIL_COND_V(!item.is_valid(), false);
|
||||
|
||||
for (int i = 0; i < _slots->size(); ++i) {
|
||||
Ref<BagSlot> slot = _slots->get(i);
|
||||
//cont
|
||||
}
|
||||
bool Bag::try_to_add_item(Ref<ItemInstance> item, int count) {
|
||||
ERR_FAIL_COND_V(!item.is_valid(), false);
|
||||
|
||||
for (int i = 0; i < _slots->size(); ++i) {
|
||||
Ref<BagSlot> slot = _slots->get(i);
|
||||
|
||||
if (!slot->has_item()) {
|
||||
slot->set_item(item);
|
||||
slot->set_count(count);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Bag::add_item_to_slot(Ref<ItemInstance> item, int slot_index) {
|
||||
}
|
||||
bool Bag::add_item_to_slot(Ref<ItemInstance> item, int slot_index, int count) {
|
||||
ERR_FAIL_COND_V(!item.is_valid(), false);
|
||||
|
||||
ERR_FAIL_INDEX_V(slot_index, _slots->size(), false);
|
||||
|
||||
Ref<BagSlot> slot = _slots->get(slot_index);
|
||||
|
||||
ERR_FAIL_COND_V(!slot.is_valid(), false);
|
||||
|
||||
if (slot->has_item()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
slot->set_item_count(item, count);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Bag::Bag() {
|
||||
_slots = memnew(Vector<Ref<BagSlot> >());
|
||||
_slots = memnew(Vector<Ref<BagSlot> >());
|
||||
}
|
||||
|
||||
Bag::~Bag() {
|
||||
_slots->clear();
|
||||
|
||||
memdelete(_slots);
|
||||
_slots->clear();
|
||||
|
||||
memdelete(_slots);
|
||||
}
|
||||
|
||||
void Bag::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_item"), &Bag::get_item);
|
||||
ClassDB::bind_method(D_METHOD("set_item", "item"), &Bag::set_item);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "ItemInstance"), "set_item", "get_item");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_count"), &Bag::get_count);
|
||||
ClassDB::bind_method(D_METHOD("set_count", "value"), &Bag::set_count);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_slot_id"), &Bag::get_slot_id);
|
||||
ClassDB::bind_method(D_METHOD("set_slot_id", "value"), &Bag::set_slot_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "slot_id"), "set_slot_id", "get_slot_id");
|
||||
ClassDB::bind_method(D_METHOD("get_slot", "index"), &Bag::get_slot);
|
||||
ClassDB::bind_method(D_METHOD("get_and_remove_slot", "index"), &Bag::get_and_remove_slot);
|
||||
ClassDB::bind_method(D_METHOD("get_slot_count"), &Bag::get_slot_count);
|
||||
ClassDB::bind_method(D_METHOD("set_slot_count", "count"), &Bag::set_slot_count);
|
||||
ClassDB::bind_method(D_METHOD("try_to_add_item", "item", "count"), &Bag::try_to_add_item, DEFVAL(1));
|
||||
ClassDB::bind_method(D_METHOD("add_item_to_slot", "item", "slot_index", "count"), &Bag::add_item_to_slot, DEFVAL(1));
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
int get_slot_count();
|
||||
void set_slot_count(int count);
|
||||
bool try_to_add_item(Ref<ItemInstance> item, int count = 1);
|
||||
bool add_item_to_slot(Ref<ItemInstance> item, int slot_index);
|
||||
bool add_item_to_slot(Ref<ItemInstance> item, int slot_index, int count = 1);
|
||||
|
||||
Bag();
|
||||
~Bag();
|
||||
|
@ -8,6 +8,11 @@ void BagSlot::set_item(Ref<ItemInstance> item) {
|
||||
_item = Ref<ItemInstance>(item);
|
||||
}
|
||||
|
||||
void BagSlot::set_item_count(Ref<ItemInstance> item, int count) {
|
||||
_item = Ref<ItemInstance>(item);
|
||||
_count = count;
|
||||
}
|
||||
|
||||
int BagSlot::get_count() {
|
||||
return _count;
|
||||
}
|
||||
@ -16,14 +21,23 @@ void BagSlot::set_count(int value) {
|
||||
_count = value;
|
||||
}
|
||||
|
||||
int BagSlot::get_slot_id() {
|
||||
int BagSlot::get_slot_index() {
|
||||
return _slot_index;
|
||||
}
|
||||
|
||||
void BagSlot::set_slot_id(int index) {
|
||||
void BagSlot::set_slot_index(int index) {
|
||||
_slot_index = index;
|
||||
}
|
||||
|
||||
bool BagSlot::has_item() {
|
||||
return _item.is_valid();
|
||||
}
|
||||
|
||||
void BagSlot::clear() {
|
||||
_item = Ref<ItemInstance>(NULL);
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
BagSlot::BagSlot() {
|
||||
_count = 0;
|
||||
}
|
||||
@ -47,8 +61,12 @@ void BagSlot::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_count", "value"), &BagSlot::set_count);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "count"), "set_count", "get_count");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_slot_id"), &BagSlot::get_slot_id);
|
||||
ClassDB::bind_method(D_METHOD("set_slot_id", "value"), &BagSlot::set_slot_id);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "slot_id"), "set_slot_id", "get_slot_id");
|
||||
ClassDB::bind_method(D_METHOD("get_slot_index"), &BagSlot::get_slot_index);
|
||||
ClassDB::bind_method(D_METHOD("set_slot_index", "value"), &BagSlot::set_slot_index);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "slot_index"), "set_slot_index", "get_slot_index");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_item_count", "item", "count"), &BagSlot::set_item_count, DEFVAL(1));
|
||||
ClassDB::bind_method(D_METHOD("has_item"), &BagSlot::has_item);
|
||||
ClassDB::bind_method(D_METHOD("clear"), &BagSlot::clear);
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,13 @@ class BagSlot : public Reference {
|
||||
public:
|
||||
Ref<ItemInstance> get_item();
|
||||
void set_item(Ref<ItemInstance> item);
|
||||
void set_item_count(Ref<ItemInstance> item, int count = 1);
|
||||
int get_count();
|
||||
void set_count(int value);
|
||||
int get_slot_index();
|
||||
void set_slot_index(int value);
|
||||
bool has_item();
|
||||
void clear();
|
||||
|
||||
BagSlot();
|
||||
BagSlot(Ref<ItemInstance> item);
|
||||
@ -25,7 +28,7 @@ protected:
|
||||
private:
|
||||
Ref<ItemInstance> _item;
|
||||
int _count;
|
||||
int _slot_ndex;
|
||||
int _slot_index;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "entities/stats/stat_data.h"
|
||||
#include "entities/player_talent.h"
|
||||
#include "inventory/bag_slot.h"
|
||||
#include "inventory/bag.h"
|
||||
|
||||
#include "data/craft_data_attribute_helper.h"
|
||||
#include "data/craft_data_attribute.h"
|
||||
@ -93,7 +94,7 @@ void register_entity_spell_system_types() {
|
||||
ClassDB::register_class<CharacterSpec>();
|
||||
|
||||
ClassDB::register_class<BagSlot>();
|
||||
|
||||
ClassDB::register_class<Bag>();
|
||||
|
||||
ClassDB::register_class<SpellDamageInfo>();
|
||||
ClassDB::register_class<SpellHealInfo>();
|
||||
|
Loading…
Reference in New Issue
Block a user