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 |
|
|
|
24 |
|
|
#include "net/tmwa/buysellhandler.h" |
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 |
|
|
|
44 |
|
|
BuySellHandler::BuySellHandler() : |
45 |
|
|
Ea::BuySellHandler() |
46 |
|
|
{ |
47 |
|
|
buySellHandler = this; |
48 |
|
|
Ea::BuySellRecv::mBuyDialog = nullptr; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
BuySellHandler::~BuySellHandler() |
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)); |
62 |
|
|
shopWindow->setAcceptPlayer(nick); |
63 |
|
|
ChatRecv::mShopRequestName = nick; |
64 |
|
|
if (config.getBoolValue("hideShopMessages")) |
65 |
|
|
{ |
66 |
|
|
chatHandler->privateMessage(nick, data); |
67 |
|
|
} |
68 |
|
|
else |
69 |
|
|
{ |
70 |
|
|
if (chatWindow != nullptr) |
71 |
|
|
chatWindow->addWhisper(nick, data, ChatMsgType::BY_PLAYER); |
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)); |
81 |
|
|
shopWindow->setAcceptPlayer(nick); |
82 |
|
|
ChatRecv::mShopRequestName = nick; |
83 |
|
|
if (config.getBoolValue("hideShopMessages")) |
84 |
|
|
{ |
85 |
|
|
chatHandler->privateMessage(nick, data); |
86 |
|
|
} |
87 |
|
|
else |
88 |
|
|
{ |
89 |
|
|
if (chatWindow != nullptr) |
90 |
|
|
chatWindow->addWhisper(nick, data, ChatMsgType::BY_PLAYER); |
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")) |
107 |
|
|
chatHandler->privateMessage(nick, data); |
108 |
|
|
else |
109 |
|
|
chatWindow->addWhisper(nick, data, ChatMsgType::BY_PLAYER); |
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")) |
126 |
|
|
chatHandler->privateMessage(nick, data); |
127 |
|
|
else |
128 |
|
|
chatWindow->addWhisper(nick, data, ChatMsgType::BY_PLAYER); |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
void BuySellHandler::close() const |
132 |
|
|
{ |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
} // namespace TmwAthena |