ManaPlus
buyingstorerecv.cpp
Go to the documentation of this file.
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 
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 
33 
35 
37 
41 
42 #include "net/messagein.h"
43 
45 
46 #include "resources/item/item.h"
47 
48 #include "debug.h"
49 
50 extern int itemIdLen;
51 
52 namespace EAthena
53 {
54 
56 {
58 }
59 
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:
69  break;
70  case 2:
73  weight);
74  break;
75  case 8:
77  break;
78  }
79 }
80 
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  }
95 }
96 
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 
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  {
125  }
126 }
127 
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 
143  dstBeing->getId(),
144  storeId);
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 
166 {
167  const int16_t result = msg.readInt16("result");
168  switch (result)
169  {
170  case 3:
173  break;
174  case 4:
176  break;
177  default:
179  break;
180  }
181 }
182 
184 {
185  const int16_t result = msg.readInt16("result");
186  msg.readItemId("item id");
187  switch (result)
188  {
189  case 5:
192  break;
193  case 6:
196  break;
197  case 7:
200  break;
201  default:
204  break;
205  }
206 }
207 
209 {
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 
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);
243  }
244  }
245 }
246 
247 } // namespace EAthena
ActorManager * actorManager
int BeingId
Definition: beingid.h:30
int itemIdLen
Definition: client.cpp:130
Being * findBeing(const BeingId id) const
BeingId getId() const
Definition: actorsprite.h:64
static void distributeEvent()
Definition: being.h:96
void setBuyBoard(const std::string &text)
Definition: being.cpp:5336
static void distributeEvent(const bool b)
static void distributeEvent(const int slots)
void removeItemAt(const int index)
Definition: inventory.cpp:254
Item * getItem(const int index) const
Definition: inventory.cpp:83
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:94
Definition: item.h:50
void addItem(const Item *const item, const int price)
Definition: selldialog.cpp:238
void setMoney(const int amount)
Definition: selldialog.cpp:340
static const int INVENTORY_OFFSET
Definition: inventory.h:27
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
const ItemColor ItemColor_one
Definition: itemcolor.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
LocalPlayer * localPlayer
#define UNIMPLEMENTEDPACKET
Definition: logger.h:56
bool msg(InputEvent &event)
Definition: chat.cpp:39
void processBuyingStoreCreateFailed(Net::MessageIn &msg)
void processBuyingStoreSellFailed(Net::MessageIn &msg)
void processBuyingStoreOwnItems(Net::MessageIn &msg)
void processBuyingStoreDeleteItem(Net::MessageIn &msg)
void processBuyingStoreSellerSellFailed(Net::MessageIn &msg)
void processBuyingStoreItemsList(Net::MessageIn &msg)
void processBuyingStoreShowBoard(Net::MessageIn &msg)
void processBuyingStoreReport(Net::MessageIn &msg)
void processBuyingStoreHideBoard(Net::MessageIn &msg)
void processBuyingStoreOpen(Net::MessageIn &msg)
void notify(const unsigned int message)
@ BUYING_STORE_SELLER_SELL_FAILED_BALANCE
Definition: notifytypes.h:139
@ BUYING_STORE_SELLER_SELL_FAILED_DEAL
Definition: notifytypes.h:137
@ BUYING_STORE_SELL_FAILED_EMPTY
Definition: notifytypes.h:135
@ BUYING_STORE_CREATE_EMPTY
Definition: notifytypes.h:133
@ BUYING_STORE_SELL_FAILED
Definition: notifytypes.h:136
@ BUYING_STORE_SELL_FAILED_MONEY_LIMIT
Definition: notifytypes.h:134
@ BUYING_STORE_CREATE_FAILED_WEIGHT
Definition: notifytypes.h:132
@ BUYING_STORE_SELLER_SELL_FAILED
Definition: notifytypes.h:140
@ BUYING_STORE_CREATE_FAILED
Definition: notifytypes.h:131
@ BUYING_STORE_SELLER_SELL_FAILED_AMOUNT
Definition: notifytypes.h:138
Inventory * getInventory()
Definition: playerinfo.cpp:195
void enableVending(const bool b)
Definition: playerinfo.cpp:658
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:102