ManaPlus
buysellhandler.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "configuration.h"
27 
28 #include "gui/windows/chatwindow.h"
29 #include "gui/windows/shopwindow.h"
30 
31 #include "net/chathandler.h"
32 
33 #include "net/ea/buysellrecv.h"
34 
35 #include "net/tmwa/chatrecv.h"
36 
37 #include "utils/timer.h"
38 
39 #include "debug.h"
40 
41 namespace TmwAthena
42 {
43 
46 {
47  buySellHandler = this;
49 }
50 
52 {
53  buySellHandler = nullptr;
54 }
55 
56 void BuySellHandler::requestSellList(const std::string &nick) const
57 {
58  if (nick.empty() || shopWindow == nullptr)
59  return;
60 
61  const std::string data("!selllist " + toString(tick_time));
64  if (config.getBoolValue("hideShopMessages"))
65  {
67  }
68  else
69  {
70  if (chatWindow != nullptr)
72  }
73 }
74 
75 void BuySellHandler::requestBuyList(const std::string &nick) const
76 {
77  if (nick.empty() || (shopWindow == nullptr))
78  return;
79 
80  const std::string data("!buylist " + toString(tick_time));
83  if (config.getBoolValue("hideShopMessages"))
84  {
86  }
87  else
88  {
89  if (chatWindow != nullptr)
91  }
92 }
93 
94 void BuySellHandler::sendBuyRequest(const std::string &nick,
95  const ShopItem *const item,
96  const int amount) const
97 {
98  if ((chatWindow == nullptr) || nick.empty() || (item == nullptr) ||
99  amount < 1 || amount > item->getQuantity())
100  {
101  return;
102  }
103  const std::string data = strprintf("!buyitem %d %d %d",
104  item->getId(), item->getPrice(), amount);
105 
106  if (config.getBoolValue("hideShopMessages"))
108  else
110 }
111 
112 void BuySellHandler::sendSellRequest(const std::string &nick,
113  const ShopItem *const item,
114  const int amount) const
115 {
116  if ((chatWindow == nullptr) || nick.empty() || (item == nullptr) ||
117  amount < 1 || amount > item->getQuantity())
118  {
119  return;
120  }
121 
122  const std::string data = strprintf("!sellitem %d %d %d",
123  item->getId(), item->getPrice(), amount);
124 
125  if (config.getBoolValue("hideShopMessages"))
127  else
129 }
130 
132 {
133 }
134 
135 } // namespace TmwAthena
Net::BuySellHandler * buySellHandler
Definition: net.cpp:100
Net::ChatHandler * chatHandler
Definition: net.cpp:86
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
void addWhisper(const std::string &nick, const std::string &mes, const ChatMsgTypeT own)
bool getBoolValue(const std::string &key) const
int getQuantity() const
Definition: item.h:105
int getId() const
Definition: item.h:81
virtual void privateMessage(const std::string &recipient, const std::string &text) const =0
int getPrice() const
Definition: shopitem.h:132
void setAcceptPlayer(const std::string &name)
Definition: shopwindow.h:121
void requestSellList(const std::string &nick) const
void sendBuyRequest(const std::string &nick, const ShopItem *const item, const int amount) const
void sendSellRequest(const std::string &nick, const ShopItem *const item, const int amount) const
void requestBuyList(const std::string &nick) const
Configuration config
uint32_t data
volatile int tick_time
Definition: timer.cpp:53
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
BuyDialog * mBuyDialog
Definition: buysellrecv.cpp:53
std::string mShopRequestName
Definition: chatrecv.cpp:57
ShopWindow * shopWindow
Definition: shopwindow.cpp:101
std::string strprintf(const char *const format,...)