ManaPlus
shopitem.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_SHOPITEM_H
25 #define RESOURCES_ITEM_SHOPITEM_H
26 
27 #include "resources/item/item.h"
28 
29 #include <stack>
30 
31 #include "localconsts.h"
32 
37 class ShopItem final : public Item
38 {
39  public:
48  ShopItem(const int inventoryIndex,
49  const int id,
50  const ItemTypeT type,
51  const ItemColor color,
52  const int quantity,
53  const int price,
54  const std::string &currency);
55 
63  ShopItem(const int id,
64  const ItemTypeT type,
65  const ItemColor color,
66  const int price,
67  const std::string &currency);
68 
70 
71 
74  ~ShopItem();
75 
82  void addDuplicate(const int inventoryIndex, const int quantity);
83 
89  void addDuplicate();
90 
91  void update();
92 
99  {
100  return mDuplicates.empty() ? 0 : mDuplicates.top()->quantity;
101  }
102 
109  {
110  return mDuplicates.empty() ? mInvIndex :
111  mDuplicates.top()->inventoryIndex;
112  }
113 
125  int sellCurrentDuplicate(const int quantity);
126 
133  { return mPrice; }
134 
140  const std::string &getDisplayName() const noexcept2 A_WARN_UNUSED
141  { return mDisplayName; }
142 
143  void setVisible(const bool b) noexcept2
144  { mVisible = b; }
145 
147  { return mVisible; }
148 
149  void increaseUsedQuantity(const int amount);
150 
152  { return mUsedQuantity; }
153 
154  void setDisabled(const bool b) noexcept2
155  { mDisabled = b; }
156 
158  { return mDisabled; }
159 
160  protected:
161  void updateDisplayName(const int quantity);
162 
163  std::string mDisplayName;
164  std::string mCurrency;
165 
169  typedef struct
170  {
172  int quantity;
173  } DuplicateItem;
174  std::stack<DuplicateItem*> mDuplicates;
175  int mPrice;
178  bool mVisible;
179  bool mDisabled;
180 };
181 
182 #endif // RESOURCES_ITEM_SHOPITEM_H
Definition: item.h:50
int mInvIndex
Definition: item.h:258
void setDisabled(const bool b)
Definition: shopitem.h:154
~ShopItem()
Definition: shopitem.cpp:90
bool getDisabled() const
Definition: shopitem.h:157
const std::string & getDisplayName() const
Definition: shopitem.h:140
int getCurrentQuantity() const
Definition: shopitem.h:98
bool mVisible
Definition: shopitem.h:178
int mUsedQuantity
Definition: shopitem.h:176
int getCurrentInvIndex() const
Definition: shopitem.h:108
void updateDisplayName(const int quantity)
Definition: shopitem.cpp:100
ShopItem(const int inventoryIndex, const int id, const ItemTypeT type, const ItemColor color, const int quantity, const int price, const std::string &currency)
Definition: shopitem.cpp:38
void increaseUsedQuantity(const int amount)
Definition: shopitem.cpp:159
bool isVisible() const
Definition: shopitem.h:146
bool mShowQuantity
Definition: shopitem.h:177
std::stack< DuplicateItem * > mDuplicates
Definition: shopitem.h:174
void setVisible(const bool b)
Definition: shopitem.h:143
std::string mCurrency
Definition: shopitem.h:164
std::string mDisplayName
Definition: shopitem.h:163
void addDuplicate()
Definition: shopitem.cpp:133
int getUsedQuantity() const
Definition: shopitem.h:151
void update()
Definition: shopitem.cpp:119
int mPrice
Definition: shopitem.h:175
bool mDisabled
Definition: shopitem.h:179
int getPrice() const
Definition: shopitem.h:132
int sellCurrentDuplicate(const int quantity)
Definition: shopitem.cpp:141
uint16_t ItemColor
Definition: itemcolor.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53