ManaPlus
buyingstorehandler.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 "being/being.h"
24 #include "being/playerinfo.h"
25 
26 #include "const/net/inventory.h"
27 
28 #include "net/eathena/messageout.h"
30 
31 #include "utils/foreach.h"
32 
34 
35 #include "debug.h"
36 
37 extern int packetVersion;
38 
39 namespace EAthena
40 {
41 
43 {
44  buyingStoreHandler = this;
45 }
46 
48 {
49  buyingStoreHandler = nullptr;
50 }
51 
52 void BuyingStoreHandler::create(const std::string &name,
53  const int maxMoney,
54  const bool flag,
55  const STD_VECTOR<ShopItem*> &items) const
56 {
57  if (packetVersion < 20100303)
58  return;
60  outMsg.writeInt16(CAST_S16(89 + items.size() * 8), "len");
61  outMsg.writeInt32(maxMoney, "limit money");
62  outMsg.writeInt8(static_cast<int8_t>(flag), "flag");
63  outMsg.writeString(name, 80, "store name");
64  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
65  {
66  const ShopItem *const item = *it;
67  outMsg.writeInt16(CAST_S16(item->getId()), "item id");
68  outMsg.writeInt16(CAST_S16(item->getQuantity()), "amount");
69  outMsg.writeInt32(item->getPrice(), "price");
70  }
71 }
72 
74 {
75  if (packetVersion < 20100420)
76  return;
79 }
80 
81 void BuyingStoreHandler::open(const Being *const being) const
82 {
83  if (being == nullptr)
84  return;
85  if (packetVersion < 20100420)
86  return;
88  outMsg.writeBeingId(being->getId(), "account id");
89 }
90 
91 void BuyingStoreHandler::sell(const Being *const being,
92  const int storeId,
93  const Item *const item,
94  const int amount) const
95 {
96  if ((being == nullptr) || (item == nullptr))
97  return;
98  if (packetVersion < 20100420)
99  return;
100 
102  outMsg.writeInt16(18, "len");
103  outMsg.writeBeingId(being->getId(), "account id");
104  outMsg.writeInt32(storeId, "store id");
105  outMsg.writeInt16(CAST_S16(
106  item->getInvIndex() + INVENTORY_OFFSET),
107  "index");
108  outMsg.writeInt16(CAST_S16(item->getId()), "item id");
109  outMsg.writeInt16(CAST_S16(amount), "amount");
110 }
111 
112 } // namespace EAthena
int getInvIndex() const
Definition: item.h:164
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
BeingId getId() const
Definition: actorsprite.h:63
static const int INVENTORY_OFFSET
Definition: inventory.h:26
int CMSG_BUYINGSTORE_CLOSE
int CMSG_BUYINGSTORE_SELL
int getPrice() const
Definition: shopitem.h:131
int getQuantity() const
Definition: item.h:104
Definition: item.h:48
void create(const std::string &name, const int maxMoney, const bool flag, const std::vector< ShopItem *> &items) const
#define createOutPacket(name)
Definition: messageout.h:36
Net::BuyingStoreHandler * buyingStoreHandler
Definition: net.cpp:98
void sell(const Being *const being, const int storeId, const Item *const item, const int amount) const
void enableVending(const bool b)
Definition: playerinfo.cpp:654
int getId() const
Definition: item.h:80
int CMSG_BUYINGSTORE_OPEN
int CMSG_BUYINGSTORE_CREATE
int packetVersion
Definition: client.cpp:120
#define CAST_S16
Definition: cast.h:27
Definition: being.h:93
void open(const Being *const being) const