Argentum Online - Servidor
item.h
1 #ifndef ITEM_H
2 #define ITEM_H
3 
4 #include <stdint.h>
5 
6 #include <string>
7 
8 #include "../../../include/nlohmann/json.hpp"
9 #include "../../../include/types.h"
10 
11 class MaxStackExceedException : public std::exception {
12  public:
13  const char *what() const throw();
14 };
15 
16 class NegativeStackException : public std::exception {
17  public:
18  const char *what() const throw();
19 };
20 
21 typedef struct item_info {
22  std::string name;
23  ItemId id;
24  item_type_t type;
25  uint32_t sprite_id;
26  unsigned int gold_value;
27 } item_info_t;
28 
29 inline void to_json(nlohmann::json &j, const item_info_t &i) {
30  j["name"] = i.name;
31  j["id"] = i.id;
32  j["type"] = i.type;
33  j["sprite_id"] = i.sprite_id;
34  j["gold_value"] = i.gold_value;
35 }
36 
37 inline void from_json(const nlohmann::json &j, item_info_t &i) {
38  j["name"].get_to(i.name);
39  j["id"].get_to(i.id);
40  j["type"].get_to(i.type);
41  j["sprite_id"].get_to(i.sprite_id);
42  j["gold_value"].get_to(i.gold_value);
43 }
44 
45 class Item {
46  private:
48  uint32_t actual_stack;
49 
50  public:
51  Item();
52  Item(item_info_t item_info, uint32_t stack = 0);
53  virtual ~Item(){};
54  virtual nlohmann::json get_data() const;
55  virtual nlohmann::json get_persist_data() const;
56  void set_stack(uint32_t stack);
57  uint32_t get_stack() const;
58  ItemId get_id() const;
59  uint32_t get_sprite_id() const;
60  item_type_t get_type() const;
61  long int stack_difference(uint32_t other_stack);
62  void increase_stack(uint32_t stack);
63  void decrease_stack(uint32_t stack);
64  uint32_t get_gold_value() const;
65 };
66 
67 #endif // ITEM_H
Item
Definition: item.h:45
MaxStackExceedException
Definition: item.h:11
item_info
Definition: item.h:21
NegativeStackException
Definition: item.h:16