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 
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 "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 
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 
79  currency);
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  }
94 }
95 
97 {
98  switch (msg.readUInt8("result"))
99  {
100  case 0:
102  break;
103  case 1:
104  default:
106  break;
107  case 2:
109  break;
110  case 3:
112  break;
113  }
114 }
115 
117 {
118  const uint8_t response = msg.readUInt8("response");
119  if (response == 0U)
120  {
122  return;
123  }
124  switch (response)
125  {
126  case 1:
128  break;
129 
130  case 2:
132  break;
133 
134  case 3:
136  break;
137 
138  default:
140  break;
141  }
142 }
143 
144 } // namespace EAthena
int BeingTypeId
Definition: beingtypeid.h:30
const BeingTypeId BeingTypeId_zero
Definition: beingtypeid.h:30
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
int itemIdLen
Definition: client.cpp:130
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
bool info(InputEvent &event)
Definition: commands.cpp:57
void processNpcBuyResponse(Net::MessageIn &msg)
void processNpcBuy(Net::MessageIn &msg)
Definition: buysellrecv.cpp:55
void processNpcSellResponse(Net::MessageIn &msg)
Definition: buysellrecv.cpp:96
BeingTypeId mNpcTypeId
Definition: npcrecv.cpp:43
BuyDialog * mBuyDialog
Definition: buysellrecv.cpp:53
BeingInfo * get(const BeingTypeId id)
Definition: npcdb.cpp:188
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