ManaPlus
auctionhandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
23 
24 #include "const/net/inventory.h"
25 
26 #include "net/eathena/messageout.h"
28 
29 #include "resources/item/item.h"
30 
31 #include "debug.h"
32 
33 namespace EAthena
34 {
35 
37 {
38  auctionHandler = this;
39 }
40 
42 {
43  auctionHandler = nullptr;
44 }
45 
47 {
48  createOutPacket(CMSG_AUCTION_CANCEL_REG);
49  outMsg.writeInt16(0, "type"); // unused
50 }
51 
52 void AuctionHandler::setItem(const Item *const item,
53  const int amount) const
54 {
55  if (item == nullptr)
56  return;
57  createOutPacket(CMSG_AUCTION_SET_ITEM);
58  outMsg.writeInt16(CAST_S16(
59  item->getInvIndex() + INVENTORY_OFFSET), "index");
60  outMsg.writeInt32(amount, "amount"); // always 1
61 }
62 
63 void AuctionHandler::reg(const int currentPrice,
64  const int maxPrice,
65  const int hours) const
66 {
67  createOutPacket(CMSG_AUCTION_REGISTER);
68  outMsg.writeInt32(currentPrice, "now money");
69  outMsg.writeInt32(maxPrice, "max money");
70  outMsg.writeInt32(hours, "delete hour");
71 }
72 
73 void AuctionHandler::cancel(const int auctionId) const
74 {
75  createOutPacket(CMSG_AUCTION_CANCEL);
76  outMsg.writeInt32(auctionId, "auction id");
77 }
78 
79 void AuctionHandler::close(const int auctionId) const
80 {
81  createOutPacket(CMSG_AUCTION_CLOSE);
82  outMsg.writeInt32(auctionId, "auction id");
83 }
84 
85 void AuctionHandler::bid(const int auctionId,
86  const int money) const
87 {
88  createOutPacket(CMSG_AUCTION_BID);
89  outMsg.writeInt32(auctionId, "auction id");
90  outMsg.writeInt32(money, "money");
91 }
92 
94  const int auctionId,
95  const std::string &text,
96  const int page) const
97 {
98  createOutPacket(CMSG_AUCTION_SEARCH);
99  outMsg.writeInt16(CAST_S16(type), "search type");
100  outMsg.writeInt32(auctionId, "auction id");
101  outMsg.writeString(text, 24, "search text");
102  outMsg.writeInt16(CAST_S16(page), "page");
103 }
104 
106 {
107  createOutPacket(CMSG_AUCTION_BUY_SELL);
108  outMsg.writeInt16(1, "buy/sell type");
109 }
110 
112 {
113  createOutPacket(CMSG_AUCTION_BUY_SELL);
114  outMsg.writeInt16(0, "buy/sell type");
115 }
116 
117 } // namespace EAthena
Net::AuctionHandler * auctionHandler
Definition: net.cpp:102
AuctionSearchType ::T AuctionSearchTypeT
#define CAST_S16
Definition: cast.h:28
void cancel(const int auctionId) const
void reg(const int currentPrice, const int maxPrice, const int hours) const
void setItem(const Item *const item, const int amount) const
void search(const AuctionSearchTypeT type, const int auctionId, const std::string &text, const int page) const
void close(const int auctionId) const
void bid(const int auctionId, const int money) const
Definition: item.h:50
int getInvIndex() const
Definition: item.h:165
static const int INVENTORY_OFFSET
Definition: inventory.h:27
#define createOutPacket(name)
Definition: messageout.h:37