1 #ifndef CORE_PLAYER_BAG_HPP
2 #define CORE_PLAYER_BAG_HPP
4 #include <BLIB/Serialization.hpp>
67 void getAll(std::vector<Item>& result)
const;
109 std::vector<Item> items;
113 friend struct bl::serial::SerializableObject<
Bag>;
124 struct SerializableObject<
core::player::Bag::Item> :
public SerializableObjectBase {
128 SerializableField<1, Item, Id>
id;
129 SerializableField<2, Item, unsigned int>
qty;
132 : SerializableObjectBase(
"BagItem")
133 , id(
"id", *this, &
Item::id, SerializableFieldBase::Required{})
134 , qty(
"qty", *this, &
Item::qty, SerializableFieldBase::Required{}) {}
138 struct SerializableObject<
core::player::Bag> :
public SerializableObjectBase {
141 SerializableField<1, Bag, std::vector<Bag::Item>>
items;
144 : SerializableObjectBase(
"Bag")
145 , items(
"items", *this, &
Bag::items, SerializableFieldBase::Required{}) {}
Type
The type classification of an item. This is used to determine when an item may be used and how to use...
Category
Represents a category that an item can belong to. Used for bag sorting.
Id
Represents an item in its simplist form.
Core classes and functionality for both the editor and game.
Basic inventory class for managing player items.
void getAll(std::vector< Item > &result) const
Returns all owned items.
void getByCategory(item::Category category, std::vector< Item > &result) const
Returns the set of owned items in the given category.
bool removeItem(item::Id item, unsigned int qty=1)
Removes the given item from the bag.
void addItem(item::Id item, unsigned int qty=1)
Adds the given item to the bag.
void getByType(item::Type type, std::vector< Item > &result) const
Returns the set of owned items of the given type.
unsigned int itemCount(item::Id item) const
Returns the number of the given item owned.
void clear()
Removes all items.
bool hasItem(item::Id item) const
Returns true if at least one of the given items is owned.
Simple struct representing a set of items in the bag.
item::Id id
The item in the bag.
Item()
Construct an empty item.
unsigned int qty
How many of the item are in the bag.
SerializableField< 1, Item, Id > id
SerializableField< 2, Item, unsigned int > qty
SerializableField< 1, Bag, std::vector< Bag::Item > > items