aboutsummaryrefslogtreecommitdiff
path: root/src/shared/item/item.hh
blob: 37741897f2ade5af58cf38f760fd3ae421b5f161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef SHARED_ITEM_ITEM_HH_
#define SHARED_ITEM_ITEM_HH_

#include <cstdint>

#include "shared/net/proto.hh"
#include "shared/world/block.hh"
#include "shared/world/chunk.hh"

namespace shared {
namespace item {

// ABC for items that exist in a player's inventory. (TODO abc lol)
class item {
public:
    using type_t = std::uint32_t;

public:
    type_t type;
    std::uint32_t quantity;

public:
    item(const type_t& type, const std::uint32_t& quantity) noexcept
        : type(type), quantity(quantity) {}
    item(const proto::item& item) noexcept
        : type(item.type()), quantity(item.quantity()) {}
    virtual ~item() noexcept {}

public:
    static std::uint32_t get_max_stack(const type_t& type) noexcept;

public:
    virtual type_t get_type() const noexcept {
        return this->type;
    }

public: // protobuf stuff
    void pack(proto::item* const proto,
              const std::uint32_t inventory_index) const noexcept {
        proto->set_type(this->type);
        proto->set_quantity(this->quantity);
        proto->set_index(inventory_index);
    }
};

} // namespace item
} // namespace shared

#endif