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/traderecv.h" |
25 |
|
|
|
26 |
|
|
#include "notifymanager.h" |
27 |
|
|
|
28 |
|
|
#include "being/playerinfo.h" |
29 |
|
|
#include "being/playerrelation.h" |
30 |
|
|
#include "being/playerrelations.h" |
31 |
|
|
|
32 |
|
|
#include "const/net/inventory.h" |
33 |
|
|
|
34 |
|
|
#include "enums/resources/notifytypes.h" |
35 |
|
|
|
36 |
|
|
#include "gui/windows/tradewindow.h" |
37 |
|
|
|
38 |
|
|
#include "net/messagein.h" |
39 |
|
|
#include "net/tradehandler.h" |
40 |
|
|
|
41 |
|
|
#include "net/ea/traderecv.h" |
42 |
|
|
|
43 |
|
|
#include "resources/inventory/inventory.h" |
44 |
|
|
|
45 |
|
|
#include "resources/item/item.h" |
46 |
|
|
|
47 |
|
|
#include "utils/stringutils.h" |
48 |
|
|
|
49 |
|
|
#include "debug.h" |
50 |
|
|
|
51 |
|
|
extern std::string tradePartnerName; |
52 |
|
|
|
53 |
|
|
namespace TmwAthena |
54 |
|
|
{ |
55 |
|
|
|
56 |
|
|
void TradeRecv::processTradeRequest(Net::MessageIn &msg) |
57 |
|
|
{ |
58 |
|
|
Ea::TradeRecv::processTradeRequestContinue(msg.readString(24, "name")); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
void TradeRecv::processTradeItemAdd(Net::MessageIn &msg) |
62 |
|
|
{ |
63 |
|
|
const int amount = msg.readInt32("amount"); |
64 |
|
|
const int type = msg.readInt16("type"); |
65 |
|
|
const uint8_t identify = msg.readUInt8("identify"); |
66 |
|
|
msg.readUInt8("attribute"); |
67 |
|
|
const uint8_t refine = msg.readUInt8("refine"); |
68 |
|
|
int cards[maxCards]; |
69 |
|
|
for (int f = 0; f < maxCards; f++) |
70 |
|
|
cards[f] = msg.readUInt16("card"); |
71 |
|
|
|
72 |
|
|
if (tradeWindow != nullptr) |
73 |
|
|
{ |
74 |
|
|
if (type == 0) |
75 |
|
|
{ |
76 |
|
|
tradeWindow->setMoney(amount); |
77 |
|
|
} |
78 |
|
|
else |
79 |
|
|
{ |
80 |
|
|
tradeWindow->addItem2(type, |
81 |
|
|
ItemType::Unknown, |
82 |
|
|
cards, |
83 |
|
|
nullptr, |
84 |
|
|
4, |
85 |
|
|
false, |
86 |
|
|
amount, |
87 |
|
|
refine, |
88 |
|
|
ItemColor_one, |
89 |
|
|
fromBool(identify, Identified), |
90 |
|
|
Damaged_false, |
91 |
|
|
Favorite_false, |
92 |
|
|
Equipm_false); |
93 |
|
|
} |
94 |
|
|
} |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
void TradeRecv::processTradeItemAddResponse(Net::MessageIn &msg) |
98 |
|
|
{ |
99 |
|
|
// Trade: New Item add response (was 0x00ea, now 01b1) |
100 |
|
|
const int index = msg.readInt16("index") - INVENTORY_OFFSET; |
101 |
|
|
Item *item = nullptr; |
102 |
|
|
if (PlayerInfo::getInventory() != nullptr) |
103 |
|
|
item = PlayerInfo::getInventory()->getItem(index); |
104 |
|
|
|
105 |
|
|
if (item == nullptr) |
106 |
|
|
{ |
107 |
|
|
if (tradeWindow != nullptr) |
108 |
|
|
tradeWindow->receivedOk(true); |
109 |
|
|
return; |
110 |
|
|
} |
111 |
|
|
const int quantity = msg.readInt16("amount"); |
112 |
|
|
|
113 |
|
|
const uint8_t res = msg.readUInt8("status"); |
114 |
|
|
switch (res) |
115 |
|
|
{ |
116 |
|
|
case 0: |
117 |
|
|
// Successfully added item |
118 |
|
|
if (tradeWindow != nullptr) |
119 |
|
|
{ |
120 |
|
|
tradeWindow->addItem2(item->getId(), |
121 |
|
|
item->getType(), |
122 |
|
|
item->getCards(), |
123 |
|
|
nullptr, |
124 |
|
|
4, |
125 |
|
|
true, |
126 |
|
|
quantity, |
127 |
|
|
item->getRefine(), |
128 |
|
|
item->getColor(), |
129 |
|
|
item->getIdentified(), |
130 |
|
|
item->getDamaged(), |
131 |
|
|
item->getFavorite(), |
132 |
|
|
item->isEquipment()); |
133 |
|
|
} |
134 |
|
|
item->increaseQuantity(-quantity); |
135 |
|
|
break; |
136 |
|
|
case 1: |
137 |
|
|
// Add item failed - player overweighted |
138 |
|
|
NotifyManager::notify(NotifyTypes:: |
139 |
|
|
TRADE_ADD_PARTNER_OVER_WEIGHT); |
140 |
|
|
break; |
141 |
|
|
case 2: |
142 |
|
|
// Add item failed - player has no free slot |
143 |
|
|
NotifyManager::notify(NotifyTypes::TRADE_ADD_PARTNER_NO_SLOTS); |
144 |
|
|
break; |
145 |
|
|
case 3: |
146 |
|
|
// Add item failed - non tradable item |
147 |
|
|
NotifyManager::notify(NotifyTypes::TRADE_ADD_UNTRADABLE_ITEM); |
148 |
|
|
break; |
149 |
|
|
default: |
150 |
|
|
NotifyManager::notify(NotifyTypes::TRADE_ADD_ERROR); |
151 |
|
|
UNIMPLEMENTEDPACKETFIELD(res); |
152 |
|
|
logger->log("QQQ SMSG_TRADE_ITEM_ADD_RESPONSE: " |
153 |
|
|
+ toString(res)); |
154 |
|
|
break; |
155 |
|
|
} |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
void TradeRecv::processTradeResponse(Net::MessageIn &msg) |
159 |
|
|
{ |
160 |
|
|
if (tradePartnerName.empty() || |
161 |
|
|
!playerRelations.hasPermission(tradePartnerName, |
162 |
|
|
PlayerRelation::TRADE)) |
163 |
|
|
{ |
164 |
|
|
tradeHandler->respond(false); |
165 |
|
|
return; |
166 |
|
|
} |
167 |
|
|
const uint8_t type = msg.readUInt8("type"); |
168 |
|
|
Ea::TradeRecv::processTradeResponseContinue(type); |
169 |
|
|
} |
170 |
|
|
|
171 |
|
2 |
} // namespace TmwAthena |