ManaPlus
buyingstorerecv.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2018 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
22 
23 #include "actormanager.h"
24 #include "notifymanager.h"
25 
26 #include "being/localplayer.h"
27 #include "being/playerinfo.h"
28 
29 #include "const/net/inventory.h"
30 
32 
34 
36 
40 
41 #include "net/messagein.h"
42 
44 
45 #include "resources/item/item.h"
46 
47 #include "debug.h"
48 
49 extern int itemIdLen;
50 
51 namespace EAthena
52 {
53 
55 {
57 }
58 
60 {
61  const int16_t result = msg.readInt16("result");
62  const int weight = msg.readInt32("weight");
63  switch (result)
64  {
65  case 1:
66  default:
68  break;
69  case 2:
72  weight);
73  break;
74  case 8:
76  break;
77  }
78 }
79 
81 {
82  const int count = (msg.readInt16("len") - 12) / (7 + itemIdLen);
83  msg.readBeingId("account id");
84  msg.readInt32("money limit");
85  for (int f = 0; f < count; f ++)
86  {
87  msg.readInt32("price");
88  msg.readInt16("amount");
89  msg.readUInt8("item type");
90  msg.readItemId("item id");
91  }
94 }
95 
97 {
98  if (actorManager == nullptr)
99  return;
100  const BeingId id = msg.readBeingId("owner id");
101  Being *const dstBeing = actorManager->findBeing(id);
102  if (dstBeing != nullptr)
103  {
104  dstBeing->setBuyBoard(msg.readString(80, "shop name"));
105  }
106  else
107  {
108  msg.readString(80, "shop name");
109  }
110 }
111 
113 {
114  if (actorManager == nullptr)
115  return;
116  const BeingId id = msg.readBeingId("owner id");
117  Being *const dstBeing = actorManager->findBeing(id);
118  if (dstBeing != nullptr)
119  dstBeing->setBuyBoard(std::string());
120  if (dstBeing == localPlayer)
121  {
124  }
125 }
126 
128 {
129  if (actorManager == nullptr)
130  return;
131  const int count = (msg.readInt16("len") - 16) / (7 + itemIdLen);
132  const BeingId id = msg.readBeingId("account id");
133  const int storeId = msg.readInt32("store id");
134  // +++ in future need use it too
135  msg.readInt32("money limit");
136 
137  const Being *const dstBeing = actorManager->findBeing(id);
138  if (dstBeing == nullptr)
139  return;
140 
142  dstBeing->getId(),
143  storeId);
145  const Inventory *const inv = PlayerInfo::getInventory();
146  for (int f = 0; f < count; f ++)
147  {
148  const int price = msg.readInt32("price");
149  const int amount = msg.readInt16("amount");
150  const ItemTypeT itemType = static_cast<ItemTypeT>(
151  msg.readUInt8("item type"));
152  const int itemId = msg.readItemId("item id");
153 
154  if (inv == nullptr)
155  continue;
156  const Item *const item = inv->findItem(itemId, ItemColor_one);
157  if (item == nullptr)
158  continue;
159  // +++ need add colors support
160  dialog->addItem(itemId, itemType, ItemColor_one, amount, price);
161  }
162 }
163 
165 {
166  const int16_t result = msg.readInt16("result");
167  switch (result)
168  {
169  case 3:
172  break;
173  case 4:
175  break;
176  default:
178  break;
179  }
180 }
181 
183 {
184  const int16_t result = msg.readInt16("result");
185  msg.readItemId("item id");
186  switch (result)
187  {
188  case 5:
191  break;
192  case 6:
195  break;
196  case 7:
199  break;
200  default:
203  break;
204  }
205 }
206 
208 {
210  msg.readItemId("item id");
211  msg.readInt16("amount");
212  if (msg.getVersion() >= 20141016)
213  {
214  msg.readInt32("money");
215  msg.readInt32("money limit");
216  msg.readInt32("char id");
217  msg.readInt32("date");
218  }
219  else
220  {
221  msg.readInt32("money limit");
222  }
223 }
224 
226 {
227  Inventory *const inventory = localPlayer != nullptr
228  ? PlayerInfo::getInventory() : nullptr;
229 
230  const int index = msg.readInt16("index") - INVENTORY_OFFSET;
231  const int amount = msg.readInt16("amount");
232  msg.readInt32("price");
233 
234  if (inventory != nullptr)
235  {
236  if (Item *const item = inventory->getItem(index))
237  {
238  item->increaseQuantity(-amount);
239  if (item->getQuantity() == 0)
240  inventory->removeItemAt(index);
242  }
243  }
244 }
245 
246 } // namespace EAthena
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:103
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:223
void processBuyingStoreCreateFailed(Net::MessageIn &msg)
Item * findItem(const int itemId, const ItemColor color) const
Definition: inventory.cpp:93
void processBuyingStoreDeleteItem(Net::MessageIn &msg)
BeingId getId() const
Definition: actorsprite.h:63
Inventory * getInventory()
Definition: playerinfo.cpp:193
int BeingId
Definition: beingid.h:29
static const int INVENTORY_OFFSET
Definition: inventory.h:26
bool msg(InputEvent &event)
Definition: chat.cpp:38
const ItemColor ItemColor_one
Definition: itemcolor.h:29
static void distributeEvent(const int slots)
void notify(const unsigned int message)
void removeItemAt(const int index)
Definition: inventory.cpp:253
int itemIdLen
Definition: client.cpp:129
int16_t readInt16(const char *const str)
Definition: messagein.cpp:130
void processBuyingStoreHideBoard(Net::MessageIn &msg)
void setBuyBoard(const std::string &text)
Definition: being.cpp:5336
void processBuyingStoreReport(Net::MessageIn &msg)
int getVersion() const
Definition: messagein.h:133
void setMoney(const int amount)
Definition: selldialog.cpp:339
LocalPlayer * localPlayer
void processBuyingStoreOpen(Net::MessageIn &msg)
Being * findBeing(const BeingId id) const
Definition: item.h:48
static void distributeEvent(const bool b)
void processBuyingStoreItemsList(Net::MessageIn &msg)
void addItem(const Item *const item, const int price)
Definition: selldialog.cpp:237
int readItemId(const char *const str)
Definition: messagein.cpp:216
ItemType ::T ItemTypeT
Definition: itemtype.h:42
void enableVending(const bool b)
Definition: playerinfo.cpp:655
void processBuyingStoreSellFailed(Net::MessageIn &msg)
static void distributeEvent()
void processBuyingStoreShowBoard(Net::MessageIn &msg)
std::string readString(int length, const char *const dstr)
Definition: messagein.cpp:367
#define UNIMPLEMENTEDPACKET
Definition: logger.h:55
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
int32_t readInt32(const char *const str)
Definition: messagein.cpp:174
Item * getItem(const int index) const
Definition: inventory.cpp:82
void processBuyingStoreSellerSellFailed(Net::MessageIn &msg)
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:100
Definition: being.h:93
void processBuyingStoreOwnItems(Net::MessageIn &msg)
ActorManager * actorManager