ManaPlus
buysellrecv.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/tmwa/buysellrecv.h"
25 
26 #include "notifymanager.h"
27 
28 #include "being/playerinfo.h"
29 
31 
33 
34 #include "gui/windows/buydialog.h"
35 
37 
38 #include "net/messagein.h"
39 
40 #include "net/ea/buysellrecv.h"
41 
42 #include "debug.h"
43 
44 namespace TmwAthena
45 {
46 
48 {
49  msg.readInt16("len");
50  const unsigned int n_items = (msg.getLength() - 4U) / 11;
56 
57  for (unsigned int k = 0; k < n_items; k++)
58  {
59  const int value = msg.readInt32("price");
60  msg.readInt32("dc value?");
61  const ItemTypeT type = static_cast<ItemTypeT>(msg.readUInt8("type"));
62  const int itemId = msg.readInt16("item id");
63  const ItemColor color = ItemColor_one;
64  Ea::BuySellRecv::mBuyDialog->addItem(itemId, type, color, 0, value);
65  }
67 }
68 
70 {
71  switch (msg.readUInt8("result"))
72  {
73  case 0:
75  break;
76  case 1:
77  default:
79  break;
80  case 2:
82  break;
83  case 3:
85  break;
86  }
87 }
88 
90 {
91  const uint8_t response = msg.readUInt8("response");
92  if (response == 0U)
93  {
95  return;
96  }
97  // Reset player money since buy dialog already assumed purchase
98  // would go fine
99  if (Ea::BuySellRecv::mBuyDialog != nullptr)
100  {
103  }
104  switch (response)
105  {
106  case 1:
108  break;
109 
110  case 2:
112  break;
113 
114  case 3:
116  break;
117 
118  default:
120  break;
121  }
122 }
123 
124 } // namespace TmwAthena
void sort()
Definition: buydialog.cpp:472
ShopItem * addItem(const int id, const ItemTypeT type, const ItemColor color, const int amount, const int price)
Definition: buydialog.cpp:457
void setMoney(const int amount)
Definition: buydialog.cpp:437
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:25
const std::string DEFAULT_CURRENCY
Definition: currency.h:27
const ItemColor ItemColor_one
Definition: itemcolor.h:30
uint16_t ItemColor
Definition: itemcolor.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
bool msg(InputEvent &event)
Definition: chat.cpp:39
BuyDialog * mBuyDialog
Definition: buysellrecv.cpp:53
void notify(const unsigned int message)
@ SELL_UNSELLABLE_FAILED
Definition: notifytypes.h:41
@ SELL_TRADE_FAILED
Definition: notifytypes.h:40
@ BUY_FAILED_NO_MONEY
Definition: notifytypes.h:34
@ BUY_FAILED_TOO_MANY_ITEMS
Definition: notifytypes.h:36
@ BUY_FAILED_OVERWEIGHT
Definition: notifytypes.h:35
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:102
void processNpcBuyResponse(Net::MessageIn &msg)
Definition: buysellrecv.cpp:89
void processNpcSellResponse(Net::MessageIn &msg)
Definition: buysellrecv.cpp:69
void processNpcBuy(Net::MessageIn &msg)
Definition: buysellrecv.cpp:47