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 namespace EAthena
50 {
51 
53 {
55 }
56 
58 {
59  const int16_t result = msg.readInt16("result");
60  const int weight = msg.readInt32("weight");
61  switch (result)
62  {
63  case 1:
64  default:
66  break;
67  case 2:
70  weight);
71  break;
72  case 8:
74  break;
75  }
76 }
77 
79 {
80  const int count = (msg.readInt16("len") - 12) / 9;
81  msg.readBeingId("account id");
82  msg.readInt32("money limit");
83  for (int f = 0; f < count; f ++)
84  {
85  msg.readInt32("price");
86  msg.readInt16("amount");
87  msg.readUInt8("item type");
88  msg.readInt16("item id");
89  }
92 }
93 
95 {
96  if (actorManager == nullptr)
97  return;
98  const BeingId id = msg.readBeingId("owner id");
99  Being *const dstBeing = actorManager->findBeing(id);
100  if (dstBeing != nullptr)
101  {
102  dstBeing->setBuyBoard(msg.readString(80, "shop name"));
103  }
104  else
105  {
106  msg.readString(80, "shop name");
107  }
108 }
109 
111 {
112  if (actorManager == nullptr)
113  return;
114  const BeingId id = msg.readBeingId("owner id");
115  Being *const dstBeing = actorManager->findBeing(id);
116  if (dstBeing != nullptr)
117  dstBeing->setBuyBoard(std::string());
118  if (dstBeing == localPlayer)
119  {
122  }
123 }
124 
126 {
127  if (actorManager == nullptr)
128  return;
129  const int count = (msg.readInt16("len") - 16) / 9;
130  const BeingId id = msg.readBeingId("account id");
131  const int storeId = msg.readInt32("store id");
132  // +++ in future need use it too
133  msg.readInt32("money limit");
134 
135  const Being *const dstBeing = actorManager->findBeing(id);
136  if (dstBeing == nullptr)
137  return;
138 
140  dstBeing->getId(),
141  storeId);
143  const Inventory *const inv = PlayerInfo::getInventory();
144  for (int f = 0; f < count; f ++)
145  {
146  const int price = msg.readInt32("price");
147  const int amount = msg.readInt16("amount");
148  const ItemTypeT itemType = static_cast<ItemTypeT>(
149  msg.readUInt8("item type"));
150  const int itemId = msg.readInt16("item id");
151 
152  if (inv == nullptr)
153  continue;
154  const Item *const item = inv->findItem(itemId, ItemColor_one);
155  if (item == nullptr)
156  continue;
157  // +++ need add colors support
158  dialog->addItem(itemId, itemType, ItemColor_one, amount, price);
159  }
160 }
161 
163 {
164  const int16_t result = msg.readInt16("result");
165  switch (result)
166  {
167  case 3:
170  break;
171  case 4:
173  break;
174  default:
176  break;
177  }
178 }
179 
181 {
182  const int16_t result = msg.readInt16("result");
183  msg.readInt16("item id");
184  switch (result)
185  {
186  case 5:
189  break;
190  case 6:
193  break;
194  case 7:
197  break;
198  default:
201  break;
202  }
203 }
204 
206 {
208  msg.readInt16("item id");
209  msg.readInt16("amount");
210  if (msg.getVersion() >= 20141016)
211  {
212  msg.readInt32("money");
213  msg.readInt32("money limit");
214  msg.readInt32("char id");
215  msg.readInt32("date");
216  }
217  else
218  {
219  msg.readInt32("money limit");
220  }
221 }
222 
224 {
225  Inventory *const inventory = localPlayer != nullptr
226  ? PlayerInfo::getInventory() : nullptr;
227 
228  const int index = msg.readInt16("index") - INVENTORY_OFFSET;
229  const int amount = msg.readInt16("amount");
230  msg.readInt32("price");
231 
232  if (inventory != nullptr)
233  {
234  if (Item *const item = inventory->getItem(index))
235  {
236  item->increaseQuantity(-amount);
237  if (item->getQuantity() == 0)
238  inventory->removeItemAt(index);
240  }
241  }
242 }
243 
244 } // namespace EAthena
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:98
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:211
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:192
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
int16_t readInt16(const char *const str)
Definition: messagein.cpp:125
void processBuyingStoreHideBoard(Net::MessageIn &msg)
void setBuyBoard(const std::string &text)
Definition: being.cpp:5336
void processBuyingStoreReport(Net::MessageIn &msg)
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
unsigned int getVersion() const
Definition: messagein.h:131
ItemType ::T ItemTypeT
Definition: itemtype.h:42
void enableVending(const bool b)
Definition: playerinfo.cpp:654
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:355
#define UNIMPLEMENTEDPACKET
Definition: logger.h:55
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
int32_t readInt32(const char *const str)
Definition: messagein.cpp:169
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