ManaPlus
traderecv.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 
24 #include "net/eathena/traderecv.h"
25 
26 #include "itemcolormanager.h"
27 #include "notifymanager.h"
28 
29 #include "being/playerinfo.h"
30 
32 
34 
35 #include "net/messagein.h"
36 
37 #include "net/ea/traderecv.h"
38 
40 
41 #include "resources/item/item.h"
43 
44 #include "debug.h"
45 
46 extern int serverVersion;
47 
48 namespace EAthena
49 {
50 
51 namespace TradeRecv
52 {
53  int mQuantity = 0;
54  int mItemIndex = -1;
55 } // namespace TradeRecv
56 
58 {
59  const std::string &partner = msg.readString(24, "name");
60  if (msg.getVersion() >= 6)
61  {
62  msg.readInt32("char id");
63  msg.readInt16("base level");
64  }
66 }
67 
69 {
70  const uint8_t type = msg.readUInt8("type");
71  msg.readInt32("char id");
72  msg.readInt16("base level");
74 }
75 
77 {
78  const int type = msg.readItemId("item id");
79  ItemTypeT itemType = ItemType::Unknown;
80  if (msg.getVersion() >= 20100223)
81  {
82  itemType = static_cast<ItemTypeT>(
83  msg.readUInt8("item type"));
84  }
85  const int amount = msg.readInt32("amount");
86  const uint8_t identify = msg.readUInt8("identify");
87  const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
88  const uint8_t refine = msg.readUInt8("refine");
89  int cards[maxCards];
90  for (int f = 0; f < maxCards; f++)
91  cards[f] = msg.readItemId("card");
92  ItemOptionsList *options = nullptr;
93  if (msg.getVersion() >= 20150226)
94  {
95  options = new ItemOptionsList;
96  for (int f = 0; f < 5; f ++)
97  {
98  const uint16_t idx = msg.readInt16("option index");
99  const uint16_t val = msg.readInt16("option value");
100  msg.readUInt8("option param");
101  options->add(idx, val);
102  }
103  }
104 
105  if (tradeWindow != nullptr)
106  {
107  if (type == 0)
108  {
109  tradeWindow->setMoney(amount);
110  }
111  else
112  {
113  tradeWindow->addItem2(type,
114  itemType,
115  cards,
116  options,
117  4,
118  false,
119  amount,
120  refine,
122  fromBool(identify, Identified),
123  damaged,
125  Equipm_false);
126  }
127  }
128  delete options;
129 }
130 
132 {
133  msg.readInt16("index");
134  const uint8_t res = msg.readUInt8("fail");
135  switch (res)
136  {
137  case 0: // Successfully added item
138  case 9: // silent added item
139  {
140  Item *const item = PlayerInfo::getInventory()->getItem(
141  mItemIndex);
142  if (item == nullptr)
143  return;
144  if (tradeWindow != nullptr)
145  {
146  tradeWindow->addItem2(item->getId(),
147  item->getType(),
148  item->getCards(),
149  item->getOptions(),
150  4,
151  true,
152  mQuantity,
153  item->getRefine(),
154  item->getColor(),
155  item->getIdentified(),
156  item->getDamaged(),
157  item->getFavorite(),
158  item->isEquipment());
159  }
160  item->increaseQuantity(-mQuantity);
161  mItemIndex = -1;
162  mQuantity = 0;
163  break;
164  }
165  case 1:
166  // Add item failed - player overweighted
169  break;
170  case 2:
172  break;
173  default:
176  break;
177  }
178 }
179 
181 {
183  // +++ here need clear trade window from partner side?
184 }
185 
186 } // namespace EAthena
#define fromBool(val, name)
Definition: booldefines.h:49
#define maxCards
Definition: cards.h:25
Item * getItem(const int index) const
Definition: inventory.cpp:83
static ItemColor getColorFromCards(const int *const cards)
Definition: item.h:50
uint8_t getRefine() const
Definition: item.h:141
const ItemOptionsList * getOptions() const
Definition: item.h:219
Equipm isEquipment() const
Definition: item.h:117
int getId() const
Definition: item.h:81
Favorite getFavorite() const
Definition: item.h:205
ItemColor getColor() const
Definition: item.h:181
Identified getIdentified() const
Definition: item.h:193
ItemTypeT getType() const
Definition: item.h:225
Damaged getDamaged() const
Definition: item.h:199
const int * getCards() const
Definition: item.h:214
void increaseQuantity(const int amount)
Definition: item.h:99
void setMoney(const int quantity)
void addItem2(const int id, const ItemTypeT type, const int *const cards, const ItemOptionsList *const options, const int sz, const bool own, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment) const
bool Damaged
Definition: damaged.h:30
int serverVersion
Definition: client.cpp:124
const bool Equipm_false
Definition: equipm.h:30
const bool Favorite_false
Definition: favorite.h:30
bool Identified
Definition: identified.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:59
#define UNIMPLEMENTEDPACKET
Definition: logger.h:56
bool msg(InputEvent &event)
Definition: chat.cpp:39
void processTradeRequest(Net::MessageIn &msg)
Definition: traderecv.cpp:57
void processTradeResponse(Net::MessageIn &msg)
Definition: traderecv.cpp:68
void processTradeUndo(Net::MessageIn &msg)
Definition: traderecv.cpp:180
void processTradeItemAdd(Net::MessageIn &msg)
Definition: traderecv.cpp:76
void processTradeItemAddResponse(Net::MessageIn &msg)
Definition: traderecv.cpp:131
void processTradeResponseContinue(const uint8_t type)
Definition: traderecv.cpp:62
void processTradeRequestContinue(const std::string &partner)
Definition: traderecv.cpp:145
@ Unknown
Definition: itemtype.h:30
void notify(const unsigned int message)
@ TRADE_ADD_PARTNER_OVER_WEIGHT
Definition: notifytypes.h:94
Inventory * getInventory()
Definition: playerinfo.cpp:195
void add(const uint16_t index, const uint16_t value)
TradeWindow * tradeWindow
Definition: tradewindow.cpp:65