ManaPlus
marketrecv.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "net/eathena/marketrecv.h"
23 
24 #include "notifymanager.h"
25 
26 #include "being/playerinfo.h"
27 
29 
31 
32 #include "gui/windows/buydialog.h"
33 
35 
36 #include "net/messagein.h"
37 
38 #include "net/eathena/npcrecv.h"
39 
40 #include "resources/beinginfo.h"
41 
42 #include "resources/db/npcdb.h"
43 
44 #include "debug.h"
45 
46 extern int itemIdLen;
47 
48 namespace EAthena
49 {
50 
51 namespace MarketRecv
52 {
53  BuyDialog *mBuyDialog = nullptr;
54 } // namespace MarketRecv
55 
56 
58 {
59  const int len = (msg.readInt16("len") - 4) / (11 + itemIdLen);
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);
81 
82  for (int f = 0; f < len; f ++)
83  {
84  const int itemId = msg.readItemId("item id");
85  const ItemTypeT type = static_cast<ItemTypeT>(msg.readUInt8("type"));
86  const int value = msg.readInt32("price");
87  const int amount = msg.readInt32("amount");
88  msg.readInt16("weight"); // +++ compare with item weight from db?
89  const ItemColor color = ItemColor_one;
90  mBuyDialog->addItem(itemId, type, color, amount, value);
91  }
92  mBuyDialog->sort();
93 }
94 
96 {
97  const int len = (msg.readInt16("len") - 5) / (6 + itemIdLen);
98  const int res = msg.readUInt8("result");
99  for (int f = 0; f < len; f ++)
100  {
101  msg.readItemId("item id");
102  msg.readInt16("amount");
103  msg.readInt32("price");
104  }
105  if (res != 0)
107  else
109 }
110 
111 } // namespace EAthena
int BeingId
Definition: beingid.h:30
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
#define fromInt(val, name)
Definition: intdefines.h:46
const ItemColor ItemColor_one
Definition: itemcolor.h:30
uint16_t ItemColor
Definition: itemcolor.h:30
ItemType ::T ItemTypeT
Definition: itemtype.h:43
int itemIdLen
Definition: client.cpp:130
bool msg(InputEvent &event)
Definition: chat.cpp:39
bool info(InputEvent &event)
Definition: commands.cpp:57
BuyDialog * mBuyDialog
Definition: marketrecv.cpp:53
void processMarketOpen(Net::MessageIn &msg)
Definition: marketrecv.cpp:57
void processMarketBuyAck(Net::MessageIn &msg)
Definition: marketrecv.cpp:95
BeingTypeId mNpcTypeId
Definition: npcrecv.cpp:43
BeingInfo * get(const BeingTypeId id)
Definition: npcdb.cpp:188
void notify(const unsigned int message)
int32_t getAttribute(const AttributesT id)
Definition: playerinfo.cpp:102