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 extern int itemIdLen;
39 
40 namespace EAthena
41 {
42 
44 {
45  buyingStoreHandler = this;
46 }
47 
49 {
50  buyingStoreHandler = nullptr;
51 }
52 
53 void BuyingStoreHandler::create(const std::string &name,
54  const int maxMoney,
55  const bool flag,
56  const STD_VECTOR<ShopItem*> &items) const
57 {
58  if (packetVersion < 20100303)
59  return;
61  outMsg.writeInt16(CAST_S16(89 + items.size() * (6 + itemIdLen)), "len");
62  outMsg.writeInt32(maxMoney, "limit money");
63  outMsg.writeInt8(static_cast<int8_t>(flag), "flag");
64  outMsg.writeString(name, 80, "store name");
65  FOR_EACH (STD_VECTOR<ShopItem*>::const_iterator, it, items)
66  {
67  const ShopItem *const item = *it;
68  outMsg.writeItemId(item->getId(), "item id");
69  outMsg.writeInt16(CAST_S16(item->getQuantity()), "amount");
70  outMsg.writeInt32(item->getPrice(), "price");
71  }
72 }
73 
75 {
76  if (packetVersion < 20100420)
77  return;
80 }
81 
82 void BuyingStoreHandler::open(const Being *const being) const
83 {
84  if (being == nullptr)
85  return;
86  if (packetVersion < 20100420)
87  return;
89  outMsg.writeBeingId(being->getId(), "account id");
90 }
91 
92 void BuyingStoreHandler::sell(const Being *const being,
93  const int storeId,
94  const Item *const item,
95  const int amount) const
96 {
97  if ((being == nullptr) || (item == nullptr))
98  return;
99  if (packetVersion < 20100420)
100  return;
101 
103  outMsg.writeInt16(18, "len");
104  outMsg.writeBeingId(being->getId(), "account id");
105  outMsg.writeInt32(storeId, "store id");
106  outMsg.writeInt16(CAST_S16(
107  item->getInvIndex() + INVENTORY_OFFSET),
108  "index");
109  outMsg.writeItemId(item->getId(), "item id");
110  outMsg.writeInt16(CAST_S16(amount), "amount");
111 }
112 
113 } // 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:104
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:655
int getId() const
Definition: item.h:80
int CMSG_BUYINGSTORE_OPEN
int CMSG_BUYINGSTORE_CREATE
int packetVersion
Definition: client.cpp:124
#define CAST_S16
Definition: cast.h:27
Definition: being.h:93
int itemIdLen
Definition: client.cpp:129
void open(const Being *const being) const