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  const BeingId id = msg.readBeingId("owner id");
97  Being *const dstBeing = actorManager->findBeing(id);
98  if (dstBeing != nullptr)
99  {
100  dstBeing->setBuyBoard(msg.readString(80, "shop name"));
101  }
102  else
103  {
104  msg.readString(80, "shop name");
105  }
106 }
107 
109 {
110  const BeingId id = msg.readBeingId("owner id");
111  Being *const dstBeing = actorManager->findBeing(id);
112  if (dstBeing != nullptr)
113  dstBeing->setBuyBoard(std::string());
114  if (dstBeing == localPlayer)
115  {
118  }
119 }
120 
122 {
123  const int count = (msg.readInt16("len") - 16) / 9;
124  const BeingId id = msg.readBeingId("account id");
125  const int storeId = msg.readInt32("store id");
126  // +++ in future need use it too
127  msg.readInt32("money limit");
128 
129  const Being *const dstBeing = actorManager->findBeing(id);
130  if (dstBeing == nullptr)
131  return;
132 
134  dstBeing->getId(),
135  storeId);
137  const Inventory *const inv = PlayerInfo::getInventory();
138  for (int f = 0; f < count; f ++)
139  {
140  const int price = msg.readInt32("price");
141  const int amount = msg.readInt16("amount");
142  const ItemTypeT itemType = static_cast<ItemTypeT>(
143  msg.readUInt8("item type"));
144  const int itemId = msg.readInt16("item id");
145 
146  if (inv == nullptr)
147  continue;
148  const Item *const item = inv->findItem(itemId, ItemColor_one);
149  if (item == nullptr)
150  continue;
151  // +++ need add colors support
152  dialog->addItem(itemId, itemType, ItemColor_one, amount, price);
153  }
154 }
155 
157 {
158  const int16_t result = msg.readInt16("result");
159  switch (result)
160  {
161  case 3:
164  break;
165  case 4:
167  break;
168  default:
170  break;
171  }
172 }
173 
175 {
176  const int16_t result = msg.readInt16("result");
177  msg.readInt16("item id");
178  switch (result)
179  {
180  case 5:
183  break;
184  case 6:
187  break;
188  case 7:
191  break;
192  default:
195  break;
196  }
197 }
198 
200 {
202  msg.readInt16("item id");
203  msg.readInt16("amount");
204  if (msg.getVersion() >= 20141016)
205  {
206  msg.readInt32("money");
207  msg.readInt32("money limit");
208  msg.readInt32("char id");
209  msg.readInt32("date");
210  }
211  else
212  {
213  msg.readInt32("money limit");
214  }
215 }
216 
218 {
219  Inventory *const inventory = localPlayer != nullptr
220  ? PlayerInfo::getInventory() : nullptr;
221 
222  const int index = msg.readInt16("index") - INVENTORY_OFFSET;
223  const int amount = msg.readInt16("amount");
224  msg.readInt32("price");
225 
226  if (inventory != nullptr)
227  {
228  if (Item *const item = inventory->getItem(index))
229  {
230  item->increaseQuantity(-amount);
231  if (item->getQuantity() == 0)
232  inventory->removeItemAt(index);
234  }
235  }
236 }
237 
238 } // namespace EAthena
virtual unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:74
void processBuyingStoreCreateFailed(Net::MessageIn &msg)
virtual BeingId readBeingId(const char *const str)=0
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
virtual int16_t readInt16(const char *const str)=0
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
void processBuyingStoreHideBoard(Net::MessageIn &msg)
void setBuyBoard(const std::string &text)
Definition: being.cpp:5307
void processBuyingStoreReport(Net::MessageIn &msg)
void setMoney(const int amount)
Definition: selldialog.cpp:318
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:216
unsigned int getVersion() const
Definition: messagein.h:127
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)
virtual int32_t readInt32(const char *const str)=0
virtual std::string readString(int length, const char *const dstr)
Definition: messagein.cpp:219
#define UNIMPLEMENTEDPACKET
Definition: logger.h:55
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
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