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/eathena/buysellrecv.h" |
25 |
|
|
|
26 |
|
|
#include "notifymanager.h" |
27 |
|
|
|
28 |
|
|
#include "being/playerinfo.h" |
29 |
|
|
|
30 |
|
|
#include "const/resources/currency.h" |
31 |
|
|
|
32 |
|
|
#include "enums/resources/notifytypes.h" |
33 |
|
|
|
34 |
|
|
#include "gui/windows/buydialog.h" |
35 |
|
|
|
36 |
|
|
#include "gui/widgets/createwidget.h" |
37 |
|
|
|
38 |
|
|
#include "net/messagein.h" |
39 |
|
|
|
40 |
|
|
#include "net/ea/buysellrecv.h" |
41 |
|
|
|
42 |
|
|
#include "net/eathena/npcrecv.h" |
43 |
|
|
|
44 |
|
|
#include "resources/beinginfo.h" |
45 |
|
|
|
46 |
|
|
#include "resources/db/npcdb.h" |
47 |
|
|
|
48 |
|
|
#include "debug.h" |
49 |
|
|
|
50 |
|
|
extern int itemIdLen; |
51 |
|
|
|
52 |
|
|
namespace EAthena |
53 |
|
|
{ |
54 |
|
|
|
55 |
|
|
void BuySellRecv::processNpcBuy(Net::MessageIn &msg) |
56 |
|
|
{ |
57 |
|
|
msg.readInt16("len"); |
58 |
|
|
const int sz = 9 + itemIdLen; |
59 |
|
|
const int n_items = (msg.getLength() - 4) / sz; |
60 |
|
|
|
61 |
|
|
const BeingTypeId npcId = NpcRecv::mNpcTypeId; |
62 |
|
|
std::string currency; |
63 |
|
|
|
64 |
|
|
if (npcId != BeingTypeId_zero) |
65 |
|
|
{ |
66 |
|
|
const BeingInfo *const info = NPCDB::get(npcId); |
67 |
|
|
if (info != nullptr) |
68 |
|
|
currency = info->getCurrency(); |
69 |
|
|
else |
70 |
|
|
currency = DEFAULT_CURRENCY; |
71 |
|
|
} |
72 |
|
|
else |
73 |
|
|
{ |
74 |
|
|
currency = DEFAULT_CURRENCY; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
CREATEWIDGETV(Ea::BuySellRecv::mBuyDialog, BuyDialog, |
78 |
|
|
Ea::BuySellRecv::mNpcId, |
79 |
|
|
currency); |
80 |
|
|
Ea::BuySellRecv::mBuyDialog->setMoney( |
81 |
|
|
PlayerInfo::getAttribute(Attributes::MONEY)); |
82 |
|
|
|
83 |
|
|
for (int k = 0; k < n_items; k++) |
84 |
|
|
{ |
85 |
|
|
const int value = msg.readInt32("price"); |
86 |
|
|
msg.readInt32("dc value?"); |
87 |
|
|
const ItemTypeT type = static_cast<ItemTypeT>( |
88 |
|
|
msg.readUInt8("type")); |
89 |
|
|
const int itemId = msg.readItemId("item id"); |
90 |
|
|
const ItemColor color = ItemColor_one; |
91 |
|
|
Ea::BuySellRecv::mBuyDialog->addItem(itemId, type, color, 0, value); |
92 |
|
|
} |
93 |
|
|
Ea::BuySellRecv::mBuyDialog->sort(); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
void BuySellRecv::processNpcSellResponse(Net::MessageIn &msg) |
97 |
|
|
{ |
98 |
|
|
switch (msg.readUInt8("result")) |
99 |
|
|
{ |
100 |
|
|
case 0: |
101 |
|
|
NotifyManager::notify(NotifyTypes::SOLD); |
102 |
|
|
break; |
103 |
|
|
case 1: |
104 |
|
|
default: |
105 |
|
|
NotifyManager::notify(NotifyTypes::SELL_FAILED); |
106 |
|
|
break; |
107 |
|
|
case 2: |
108 |
|
|
NotifyManager::notify(NotifyTypes::SELL_TRADE_FAILED); |
109 |
|
|
break; |
110 |
|
|
case 3: |
111 |
|
|
NotifyManager::notify(NotifyTypes::SELL_UNSELLABLE_FAILED); |
112 |
|
|
break; |
113 |
|
|
} |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
void BuySellRecv::processNpcBuyResponse(Net::MessageIn &msg) |
117 |
|
|
{ |
118 |
|
|
const uint8_t response = msg.readUInt8("response"); |
119 |
|
|
if (response == 0U) |
120 |
|
|
{ |
121 |
|
|
NotifyManager::notify(NotifyTypes::BUY_DONE); |
122 |
|
|
return; |
123 |
|
|
} |
124 |
|
|
switch (response) |
125 |
|
|
{ |
126 |
|
|
case 1: |
127 |
|
|
NotifyManager::notify(NotifyTypes::BUY_FAILED_NO_MONEY); |
128 |
|
|
break; |
129 |
|
|
|
130 |
|
|
case 2: |
131 |
|
|
NotifyManager::notify(NotifyTypes::BUY_FAILED_OVERWEIGHT); |
132 |
|
|
break; |
133 |
|
|
|
134 |
|
|
case 3: |
135 |
|
|
NotifyManager::notify(NotifyTypes::BUY_FAILED_TOO_MANY_ITEMS); |
136 |
|
|
break; |
137 |
|
|
|
138 |
|
|
default: |
139 |
|
|
NotifyManager::notify(NotifyTypes::BUY_FAILED); |
140 |
|
|
break; |
141 |
|
|
} |
142 |
|
|
} |
143 |
|
|
|
144 |
|
2 |
} // namespace EAthena |