1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
4 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
5 |
|
|
* |
6 |
|
|
* This file is part of The ManaPlus Client. |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
11 |
|
|
* any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include "net/eathena/buyingstorerecv.h" |
23 |
|
|
|
24 |
|
|
#include "actormanager.h" |
25 |
|
|
#include "notifymanager.h" |
26 |
|
|
|
27 |
|
|
#include "being/localplayer.h" |
28 |
|
|
#include "being/playerinfo.h" |
29 |
|
|
|
30 |
|
|
#include "const/net/inventory.h" |
31 |
|
|
|
32 |
|
|
#include "enums/resources/notifytypes.h" |
33 |
|
|
|
34 |
|
|
#include "gui/windows/buyingstoreselldialog.h" |
35 |
|
|
|
36 |
|
|
#include "gui/widgets/createwidget.h" |
37 |
|
|
|
38 |
|
|
#include "listeners/arrowslistener.h" |
39 |
|
|
#include "listeners/buyingstoremodelistener.h" |
40 |
|
|
#include "listeners/buyingstoreslotslistener.h" |
41 |
|
|
|
42 |
|
|
#include "net/messagein.h" |
43 |
|
|
|
44 |
|
|
#include "resources/inventory/inventory.h" |
45 |
|
|
|
46 |
|
|
#include "resources/item/item.h" |
47 |
|
|
|
48 |
|
|
#include "debug.h" |
49 |
|
|
|
50 |
|
|
extern int itemIdLen; |
51 |
|
|
|
52 |
|
|
namespace EAthena |
53 |
|
|
{ |
54 |
|
|
|
55 |
|
|
void BuyingStoreRecv::processBuyingStoreOpen(Net::MessageIn &msg) |
56 |
|
|
{ |
57 |
|
|
BuyingStoreSlotsListener::distributeEvent(msg.readUInt8("slots")); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
void BuyingStoreRecv::processBuyingStoreCreateFailed(Net::MessageIn &msg) |
61 |
|
|
{ |
62 |
|
|
const int16_t result = msg.readInt16("result"); |
63 |
|
|
const int weight = msg.readInt32("weight"); |
64 |
|
|
switch (result) |
65 |
|
|
{ |
66 |
|
|
case 1: |
67 |
|
|
default: |
68 |
|
|
NotifyManager::notify(NotifyTypes::BUYING_STORE_CREATE_FAILED); |
69 |
|
|
break; |
70 |
|
|
case 2: |
71 |
|
|
NotifyManager::notify( |
72 |
|
|
NotifyTypes::BUYING_STORE_CREATE_FAILED_WEIGHT, |
73 |
|
|
weight); |
74 |
|
|
break; |
75 |
|
|
case 8: |
76 |
|
|
NotifyManager::notify(NotifyTypes::BUYING_STORE_CREATE_EMPTY); |
77 |
|
|
break; |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
void BuyingStoreRecv::processBuyingStoreOwnItems(Net::MessageIn &msg) |
82 |
|
|
{ |
83 |
|
|
const int count = (msg.readInt16("len") - 12) / (7 + itemIdLen); |
84 |
|
|
msg.readBeingId("account id"); |
85 |
|
|
msg.readInt32("money limit"); |
86 |
|
|
for (int f = 0; f < count; f ++) |
87 |
|
|
{ |
88 |
|
|
msg.readInt32("price"); |
89 |
|
|
msg.readInt16("amount"); |
90 |
|
|
msg.readUInt8("item type"); |
91 |
|
|
msg.readItemId("item id"); |
92 |
|
|
} |
93 |
|
|
PlayerInfo::enableVending(true); |
94 |
|
|
BuyingStoreModeListener::distributeEvent(true); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
void BuyingStoreRecv::processBuyingStoreShowBoard(Net::MessageIn &msg) |
98 |
|
|
{ |
99 |
|
|
if (actorManager == nullptr) |
100 |
|
|
return; |
101 |
|
|
const BeingId id = msg.readBeingId("owner id"); |
102 |
|
|
Being *const dstBeing = actorManager->findBeing(id); |
103 |
|
|
if (dstBeing != nullptr) |
104 |
|
|
{ |
105 |
|
|
dstBeing->setBuyBoard(msg.readString(80, "shop name")); |
106 |
|
|
} |
107 |
|
|
else |
108 |
|
|
{ |
109 |
|
|
msg.readString(80, "shop name"); |
110 |
|
|
} |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
void BuyingStoreRecv::processBuyingStoreHideBoard(Net::MessageIn &msg) |
114 |
|
|
{ |
115 |
|
|
if (actorManager == nullptr) |
116 |
|
|
return; |
117 |
|
|
const BeingId id = msg.readBeingId("owner id"); |
118 |
|
|
Being *const dstBeing = actorManager->findBeing(id); |
119 |
|
|
if (dstBeing != nullptr) |
120 |
|
|
dstBeing->setBuyBoard(std::string()); |
121 |
|
|
if (dstBeing == localPlayer) |
122 |
|
|
{ |
123 |
|
|
PlayerInfo::enableVending(false); |
124 |
|
|
BuyingStoreModeListener::distributeEvent(false); |
125 |
|
|
} |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
void BuyingStoreRecv::processBuyingStoreItemsList(Net::MessageIn &msg) |
129 |
|
|
{ |
130 |
|
|
if (actorManager == nullptr) |
131 |
|
|
return; |
132 |
|
|
const int count = (msg.readInt16("len") - 16) / (7 + itemIdLen); |
133 |
|
|
const BeingId id = msg.readBeingId("account id"); |
134 |
|
|
const int storeId = msg.readInt32("store id"); |
135 |
|
|
// +++ in future need use it too |
136 |
|
|
msg.readInt32("money limit"); |
137 |
|
|
|
138 |
|
|
const Being *const dstBeing = actorManager->findBeing(id); |
139 |
|
|
if (dstBeing == nullptr) |
140 |
|
|
return; |
141 |
|
|
|
142 |
|
|
SellDialog *const dialog = CREATEWIDGETR(BuyingStoreSellDialog, |
143 |
|
|
dstBeing->getId(), |
144 |
|
|
storeId); |
145 |
|
|
dialog->setMoney(PlayerInfo::getAttribute(Attributes::MONEY)); |
146 |
|
|
const Inventory *const inv = PlayerInfo::getInventory(); |
147 |
|
|
for (int f = 0; f < count; f ++) |
148 |
|
|
{ |
149 |
|
|
const int price = msg.readInt32("price"); |
150 |
|
|
const int amount = msg.readInt16("amount"); |
151 |
|
|
const ItemTypeT itemType = static_cast<ItemTypeT>( |
152 |
|
|
msg.readUInt8("item type")); |
153 |
|
|
const int itemId = msg.readItemId("item id"); |
154 |
|
|
|
155 |
|
|
if (inv == nullptr) |
156 |
|
|
continue; |
157 |
|
|
const Item *const item = inv->findItem(itemId, ItemColor_one); |
158 |
|
|
if (item == nullptr) |
159 |
|
|
continue; |
160 |
|
|
// +++ need add colors support |
161 |
|
|
dialog->addItem(itemId, itemType, ItemColor_one, amount, price); |
162 |
|
|
} |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
void BuyingStoreRecv::processBuyingStoreSellFailed(Net::MessageIn &msg) |
166 |
|
|
{ |
167 |
|
|
const int16_t result = msg.readInt16("result"); |
168 |
|
|
switch (result) |
169 |
|
|
{ |
170 |
|
|
case 3: |
171 |
|
|
NotifyManager::notify( |
172 |
|
|
NotifyTypes::BUYING_STORE_SELL_FAILED_MONEY_LIMIT); |
173 |
|
|
break; |
174 |
|
|
case 4: |
175 |
|
|
NotifyManager::notify(NotifyTypes::BUYING_STORE_SELL_FAILED_EMPTY); |
176 |
|
|
break; |
177 |
|
|
default: |
178 |
|
|
NotifyManager::notify(NotifyTypes::BUYING_STORE_SELL_FAILED); |
179 |
|
|
break; |
180 |
|
|
} |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
void BuyingStoreRecv::processBuyingStoreSellerSellFailed(Net::MessageIn &msg) |
184 |
|
|
{ |
185 |
|
|
const int16_t result = msg.readInt16("result"); |
186 |
|
|
msg.readItemId("item id"); |
187 |
|
|
switch (result) |
188 |
|
|
{ |
189 |
|
|
case 5: |
190 |
|
|
NotifyManager::notify( |
191 |
|
|
NotifyTypes::BUYING_STORE_SELLER_SELL_FAILED_DEAL); |
192 |
|
|
break; |
193 |
|
|
case 6: |
194 |
|
|
NotifyManager::notify( |
195 |
|
|
NotifyTypes::BUYING_STORE_SELLER_SELL_FAILED_AMOUNT); |
196 |
|
|
break; |
197 |
|
|
case 7: |
198 |
|
|
NotifyManager::notify( |
199 |
|
|
NotifyTypes::BUYING_STORE_SELLER_SELL_FAILED_BALANCE); |
200 |
|
|
break; |
201 |
|
|
default: |
202 |
|
|
NotifyManager::notify( |
203 |
|
|
NotifyTypes::BUYING_STORE_SELLER_SELL_FAILED); |
204 |
|
|
break; |
205 |
|
|
} |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
void BuyingStoreRecv::processBuyingStoreReport(Net::MessageIn &msg) |
209 |
|
|
{ |
210 |
|
|
UNIMPLEMENTEDPACKET; |
211 |
|
|
msg.readItemId("item id"); |
212 |
|
|
msg.readInt16("amount"); |
213 |
|
|
if (msg.getVersion() >= 20141016) |
214 |
|
|
{ |
215 |
|
|
msg.readInt32("money"); |
216 |
|
|
msg.readInt32("money limit"); |
217 |
|
|
msg.readInt32("char id"); |
218 |
|
|
msg.readInt32("date"); |
219 |
|
|
} |
220 |
|
|
else |
221 |
|
|
{ |
222 |
|
|
msg.readInt32("money limit"); |
223 |
|
|
} |
224 |
|
|
} |
225 |
|
|
|
226 |
|
|
void BuyingStoreRecv::processBuyingStoreDeleteItem(Net::MessageIn &msg) |
227 |
|
|
{ |
228 |
|
|
Inventory *const inventory = localPlayer != nullptr |
229 |
|
|
? PlayerInfo::getInventory() : nullptr; |
230 |
|
|
|
231 |
|
|
const int index = msg.readInt16("index") - INVENTORY_OFFSET; |
232 |
|
|
const int amount = msg.readInt16("amount"); |
233 |
|
|
msg.readInt32("price"); |
234 |
|
|
|
235 |
|
|
if (inventory != nullptr) |
236 |
|
|
{ |
237 |
|
|
if (Item *const item = inventory->getItem(index)) |
238 |
|
|
{ |
239 |
|
|
item->increaseQuantity(-amount); |
240 |
|
|
if (item->getQuantity() == 0) |
241 |
|
|
inventory->removeItemAt(index); |
242 |
|
|
ArrowsListener::distributeEvent(); |
243 |
|
|
} |
244 |
|
|
} |
245 |
|
|
} |
246 |
|
|
|
247 |
|
2 |
} // namespace EAthena |