ManaPlus
item.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef RESOURCES_ITEM_ITEM_H
25 #define RESOURCES_ITEM_ITEM_H
26 
28 
30 
37 
38 #include "resources/db/itemdb.h"
39 
40 #include "localconsts.h"
41 
42 class Image;
43 
44 struct ItemOptionsList;
45 
50 {
51  public:
55  Item(const int id,
56  const ItemTypeT type,
57  const int quantity,
58  const uint8_t refine,
59  const ItemColor color,
60  const Identified identified,
61  const Damaged damaged,
62  const Favorite favorite,
63  const Equipm equipment,
64  const Equipped equipped);
65 
67 
68 
71  virtual ~Item();
72 
76  void setId(const int id, const ItemColor color);
77 
82  { return mId; }
83 
88  { return mImage; }
89 
93  void setQuantity(const int quantity) noexcept2
94  { mQuantity = quantity; }
95 
99  void increaseQuantity(const int amount) noexcept2
100  { mQuantity += amount; }
101 
106  { return mQuantity; }
107 
111  void setEquipment(const Equipm equipment) noexcept2
112  { mEquipment = equipment; }
113 
118  { return mEquipment; }
119 
123  void setEquipped(const Equipped equipped) noexcept2
124  { mEquipped = equipped; }
125 
130  { return mEquipped; }
131 
135  void setRefine(const uint8_t refine) noexcept2
136  { mRefine = refine; }
137 
142  { return mRefine; }
143 
147  void setInEquipment(const bool inEquipment) noexcept2
148  { mInEquipment = inEquipment; }
149 
154  { return mInEquipment; }
155 
159  void setInvIndex(const int index) noexcept2
160  { mInvIndex = index; }
161 
166  { return mInvIndex; }
167 
172  { return ItemDB::get(mId); }
173 
174  std::string getName() const A_WARN_UNUSED;
175 
176  static Image *getImage(const int id,
177  const ItemColor color) A_WARN_UNUSED;
178 
179  bool isHaveTag(const int tagId) const A_WARN_UNUSED;
180 
182  { return mColor; }
183 
184  void setColor(const ItemColor color) noexcept2
185  { mColor = color; }
186 
187  const std::string &getDescription() const noexcept2 A_WARN_UNUSED
188  { return mDescription; }
189 
191  { mIdentified = b; }
192 
194  { return mIdentified; }
195 
197  { mDamaged = b; }
198 
200  { return mDamaged; }
201 
203  { mFavorite = b; }
204 
206  { return mFavorite; }
207 
208  void setCard(const int index, const int id);
209 
210  int getCard(const int index) const;
211 
212  void setCards(const int *const cards, const int size);
213 
214  const int *getCards() const noexcept2 A_WARN_UNUSED
215  { return mCards; }
216 
217  void setOptions(const ItemOptionsList *const options);
218 
220  { return mOptions; }
221 
222  void setType(const ItemTypeT type) noexcept2
223  { mType = type; }
224 
226  { return mType; }
227 
228  void setTag(const int tag) noexcept2
229  { mTag = tag; }
230 
232  { return mTag; }
233 
234  void addCard(const int card);
235 
236  void updateColor();
237 
238  static constexpr bool isItem(const int id) noexcept2 A_WARN_UNUSED
239  {
240  return id != 0 &&
241  id != CARD0_FORGE &&
242  id != CARD0_CREATE &&
243  id != CARD0_PET;
244  }
245 
246  int mId;
248  int mQuantity;
249  int mTag;
250 
251  protected:
253  std::string mDescription;
254  std::map <int, int> mTags;
257  uint8_t mRefine;
258  int mInvIndex;
266 };
267 
268 #endif // RESOURCES_ITEM_ITEM_H
#define CARD0_CREATE
Definition: cards.h:29
#define maxCards
Definition: cards.h:25
#define CARD0_PET
Definition: cards.h:30
#define CARD0_FORGE
Definition: cards.h:28
Definition: item.h:50
uint8_t getRefine() const
Definition: item.h:141
void setCard(const int index, const int id)
Definition: item.cpp:152
Identified mIdentified
Definition: item.h:263
int mQuantity
Definition: item.h:248
const ItemOptionsList * getOptions() const
Definition: item.h:219
void setQuantity(const int quantity)
Definition: item.h:93
Damaged mDamaged
Definition: item.h:264
virtual ~Item()
Definition: item.cpp:80
Equipm isEquipment() const
Definition: item.h:117
int mInvIndex
Definition: item.h:258
int mTag
Definition: item.h:249
int getTag() const
Definition: item.h:231
void setIdentified(const Identified b)
Definition: item.h:190
void setInvIndex(const int index)
Definition: item.h:159
ItemColor mColor
Definition: item.h:247
const ItemOptionsList * mOptions
Definition: item.h:256
uint8_t mRefine
Definition: item.h:257
int getCard(const int index) const
Definition: item.cpp:159
int getQuantity() const
Definition: item.h:105
void setRefine(const uint8_t refine)
Definition: item.h:135
void addCard(const int card)
Definition: item.cpp:177
Equipped isEquipped() const
Definition: item.h:129
int getInvIndex() const
Definition: item.h:165
std::string getName() const
Definition: item.cpp:140
int mId
Definition: item.h:246
const std::string & getDescription() const
Definition: item.h:187
bool isHaveTag(const int tagId) const
Definition: item.cpp:119
void setInEquipment(const bool inEquipment)
Definition: item.h:147
int getId() const
Definition: item.h:81
Favorite getFavorite() const
Definition: item.h:205
Image * getImage() const
Definition: item.h:87
void setDamaged(const Damaged b)
Definition: item.h:196
void setId(const int id, const ItemColor color)
Definition: item.cpp:91
static bool isItem(const int id)
Definition: item.h:238
void setTag(const int tag)
Definition: item.h:228
bool mInEquipment
Definition: item.h:262
Equipm mEquipment
Definition: item.h:260
ItemColor getColor() const
Definition: item.h:181
Identified getIdentified() const
Definition: item.h:193
ItemTypeT mType
Definition: item.h:259
ItemTypeT getType() const
Definition: item.h:225
Damaged getDamaged() const
Definition: item.h:199
const int * getCards() const
Definition: item.h:214
void setEquipment(const Equipm equipment)
Definition: item.h:111
void setOptions(const ItemOptionsList *const options)
Definition: item.cpp:189
void setEquipped(const Equipped equipped)
Definition: item.h:123
void setCards(const int *const cards, const int size)
Definition: item.cpp:166
Item(const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
Definition: item.cpp:46
void increaseQuantity(const int amount)
Definition: item.h:99
void updateColor()
Definition: item.cpp:195
Equipped mEquipped
Definition: item.h:261
void setType(const ItemTypeT type)
Definition: item.h:222
Image * mImage
Definition: item.h:252
void setColor(const ItemColor color)
Definition: item.h:184
std::map< int, int > mTags
Definition: item.h:254
void setFavorite(const Favorite b)
Definition: item.h:202
const ItemInfo & getInfo() const
Definition: item.h:171
std::string mDescription
Definition: item.h:253
Favorite mFavorite
Definition: item.h:265
int mCards[4]
Definition: item.h:255
bool isInEquipment() const
Definition: item.h:153
bool Damaged
Definition: damaged.h:30
bool Equipm
Definition: equipm.h:30
bool Equipped
Definition: equipped.h:30
bool Favorite
Definition: favorite.h:30
bool Identified
Definition: identified.h:30
uint16_t ItemColor
Definition: itemcolor.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define constexpr
Definition: localconsts.h:48
#define noexcept2
Definition: localconsts.h:50
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
int size()
Definition: emotedb.cpp:306
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792