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 |
|
|
|
33 |
|
|
/** |
34 |
|
|
* Represents an item in a shop inventory. It can store quantity and inventory |
35 |
|
|
* indices of duplicate entries in the shop as well. |
36 |
|
|
*/ |
37 |
|
|
class ShopItem final : public Item |
38 |
|
|
{ |
39 |
|
|
public: |
40 |
|
|
/** |
41 |
|
|
* Constructor. Creates a new ShopItem. |
42 |
|
|
* |
43 |
|
|
* @param inventoryIndex the inventory index of the item |
44 |
|
|
* @param id the id of the item |
45 |
|
|
* @param quantity number of available copies of the item |
46 |
|
|
* @param price price of the item |
47 |
|
|
*/ |
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 ¤cy); |
55 |
|
|
|
56 |
|
|
/** |
57 |
|
|
* Constructor. Creates a new ShopItem. Inventory index will be set to |
58 |
|
|
* -1 and quantity to 0. |
59 |
|
|
* |
60 |
|
|
* @param id the id of the item |
61 |
|
|
* @param price price of the item |
62 |
|
|
*/ |
63 |
|
|
ShopItem(const int id, |
64 |
|
|
const ItemTypeT type, |
65 |
|
|
const ItemColor color, |
66 |
|
|
const int price, |
67 |
|
|
const std::string ¤cy); |
68 |
|
|
|
69 |
|
|
A_DELETE_COPY(ShopItem) |
70 |
|
|
|
71 |
|
|
/** |
72 |
|
|
* Destructor. |
73 |
|
|
*/ |
74 |
|
|
~ShopItem(); |
75 |
|
|
|
76 |
|
|
/** |
77 |
|
|
* Add a duplicate. Id and price will be taken from this item. |
78 |
|
|
* |
79 |
|
|
* @param inventoryIndex the inventory index of the item |
80 |
|
|
* @param quantity number of available copies of the item |
81 |
|
|
*/ |
82 |
|
|
void addDuplicate(const int inventoryIndex, const int quantity); |
83 |
|
|
|
84 |
|
|
/** |
85 |
|
|
* Add a duplicate. Id and price will be taken from this item. |
86 |
|
|
* Needed for compatibility with ShopDuplicateItems (see) class |
87 |
|
|
* documentation). |
88 |
|
|
*/ |
89 |
|
|
void addDuplicate(); |
90 |
|
|
|
91 |
|
|
void update(); |
92 |
|
|
|
93 |
|
|
/** |
94 |
|
|
* Gets the quantity of the currently topmost duplicate. |
95 |
|
|
* |
96 |
|
|
* @return the quantity of the currently topmost duplicate |
97 |
|
|
*/ |
98 |
|
|
int getCurrentQuantity() const A_WARN_UNUSED |
99 |
|
|
{ |
100 |
|
|
return mDuplicates.empty() ? 0 : mDuplicates.top()->quantity; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
/** |
104 |
|
|
* Gets the inventory index of the currently topmost duplicate. |
105 |
|
|
* |
106 |
|
|
* @return the inventory index of the currently topmost duplicate |
107 |
|
|
*/ |
108 |
|
|
int getCurrentInvIndex() const A_WARN_UNUSED |
109 |
|
|
{ |
110 |
|
|
return mDuplicates.empty() ? mInvIndex : |
111 |
|
|
mDuplicates.top()->inventoryIndex; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
/** |
115 |
|
|
* Reduces the quantity of the topmost duplicate by the specified |
116 |
|
|
* amount. Also reduces the total quantity of this DuplicateItem. |
117 |
|
|
* Empty duplicates are automatically removed. |
118 |
|
|
* |
119 |
|
|
* If the amount is bigger than the quantity of the current topmost, |
120 |
|
|
* only sell as much as possible. Returns the amount actually sold (do |
121 |
|
|
* not ignore the return value!) |
122 |
|
|
* |
123 |
|
|
* @return the amount, that actually was sold. |
124 |
|
|
*/ |
125 |
|
|
int sellCurrentDuplicate(const int quantity); |
126 |
|
|
|
127 |
|
|
/** |
128 |
|
|
* Gets the price of the item. |
129 |
|
|
* |
130 |
|
|
* @return the price of the item |
131 |
|
|
*/ |
132 |
|
|
int getPrice() const noexcept2 A_WARN_UNUSED |
133 |
|
|
{ return mPrice; } |
134 |
|
|
|
135 |
|
|
/** |
136 |
|
|
* Gets the display name for the item in the shop list. |
137 |
|
|
* |
138 |
|
|
* @return the display name for the item in the shop list |
139 |
|
|
*/ |
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 |
|
|
|
146 |
|
|
bool isVisible() const noexcept2 A_WARN_UNUSED |
147 |
|
|
{ return mVisible; } |
148 |
|
|
|
149 |
|
|
void increaseUsedQuantity(const int amount); |
150 |
|
|
|
151 |
|
|
int getUsedQuantity() const noexcept2 A_WARN_UNUSED |
152 |
|
|
{ return mUsedQuantity; } |
153 |
|
|
|
154 |
|
|
void setDisabled(const bool b) noexcept2 |
155 |
|
|
{ mDisabled = b; } |
156 |
|
|
|
157 |
|
|
bool getDisabled() const noexcept2 A_WARN_UNUSED |
158 |
|
|
{ return mDisabled; } |
159 |
|
|
|
160 |
|
|
protected: |
161 |
|
|
void updateDisplayName(const int quantity); |
162 |
|
|
|
163 |
|
|
std::string mDisplayName; |
164 |
|
|
std::string mCurrency; |
165 |
|
|
|
166 |
|
|
/** |
167 |
|
|
* Struct to keep track of duplicates. |
168 |
|
|
*/ |
169 |
|
|
typedef struct |
170 |
|
|
{ |
171 |
|
|
int inventoryIndex; |
172 |
|
|
int quantity; |
173 |
|
|
} DuplicateItem; |
174 |
|
|
std::stack<DuplicateItem*> mDuplicates; /** <-- Stores duplicates */ |
175 |
|
|
int mPrice; |
176 |
|
|
int mUsedQuantity; |
177 |
|
|
bool mShowQuantity; |
178 |
|
|
bool mVisible; |
179 |
|
|
bool mDisabled; |
180 |
|
|
}; |
181 |
|
|
|
182 |
|
|
#endif // RESOURCES_ITEM_SHOPITEM_H |