#ifndef SHARED_ITEM_ITEMS_HH_ #define SHARED_ITEM_ITEMS_HH_ #include #include "shared/item/block.hh" #include "shared/item/item.hh" #include "shared/net/proto.hh" #include "shared/world/block.hh" namespace shared { namespace item { // Use this function over constructor to create a derived item. using item_t = std::shared_ptr; using items_t = std::array; using make_item_func_t = item_t (*)(const item::type_t&, const std::uint32_t&); item_t make_item(const item::type_t& type, const std::uint32_t& quantity) noexcept; item_t make_item(const proto::item& item) noexcept; // Class for an inventory (or possibly a chest in the future, etc). class items { public: items_t contents = {0}; public: items() noexcept {} items(const proto::item_array& proto) noexcept; public: // Adds or removes an arbitrary amount of items to the player. // Returns true of false based on whether the operation completed fully. bool maybe_add(const item::type_t& type, const std::uint32_t& quantity, const make_item_func_t& = make_item) noexcept; bool maybe_remove(const item::type_t& type, const std::uint32_t& quantity) noexcept; // Adds a single existing item, puts in new slot if necessary. void increment(const std::uint32_t& index, const make_item_func_t& = make_item) noexcept; // Removes a single existing item from an index, clears if needed. void decrement(const std::uint32_t& index) noexcept; public: void pack(proto::item_array* const proto) const noexcept; }; } // namespace item } // namespace shared #endif