ManaPlus
cashshoprecv.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 
23 
24 #include "notifymanager.h"
25 
27 
29 
30 #include "gui/windows/buydialog.h"
31 
33 
34 #include "net/messagein.h"
35 
36 #include "net/eathena/npcrecv.h"
37 
38 #include "resources/beinginfo.h"
39 
40 #include "resources/db/npcdb.h"
41 
42 #include "debug.h"
43 
44 extern int packetVersion;
45 extern int itemIdLen;
46 
47 namespace EAthena
48 {
49 
50 namespace CashShopRecv
51 {
53 } // namespace CashShopRecv
54 
56 {
57  int count;
58  int blockSize = 11;
59  if (itemIdLen == 4)
60  blockSize += 2;
61  if (packetVersion >= 20070711)
62  count = (msg.readInt16("len") - 12) / blockSize;
63  else
64  count = (msg.readInt16("len") - 8) / blockSize;
65 
66  const BeingTypeId npcId = NpcRecv::mNpcTypeId;
67  std::string currency;
68 
69  if (npcId != BeingTypeId_zero)
70  {
71  const BeingInfo *const info = NPCDB::get(npcId);
72  if (info != nullptr)
73  currency = info->getCurrency();
74  else
75  currency = DEFAULT_CURRENCY;
76  }
77  else
78  {
79  currency = DEFAULT_CURRENCY;
80  }
83  currency);
84  const int points = msg.readInt32("cash points");
85 
86  mBuyDialog->setMoney(points);
87 
88  if (packetVersion >= 20070711)
89  msg.readInt32("kafra points");
90  for (int f = 0; f < count; f ++)
91  {
92  msg.readInt32("price");
93  const int value = msg.readInt32("discount price");
94  const ItemTypeT type = static_cast<ItemTypeT>(
95  msg.readUInt8("item type"));
96  const int itemId = msg.readItemId("item id");
97  const ItemColor color = ItemColor_one;
98  mBuyDialog->addItem(itemId, type, color, 0, value);
99  }
100  mBuyDialog->sort();
101 }
102 
104 {
105  msg.readInt32("cash points");
106  msg.readInt32("kafra points");
107  const uint16_t res = msg.readInt16("error");
108  switch (res)
109  {
110  case 0:
112  break;
113  case 1:
115  break;
116  case 2:
118  break;
119  case 3:
121  break;
122  case 4:
124  break;
125  case 5:
127  break;
128  case 6:
130  break;
131  default:
133  break;
134  }
135 }
136 
138 {
140  msg.readInt32("cash points");
141  msg.readInt32("kafra points");
142 }
143 
145 {
147  msg.readInt32("id");
148  msg.readInt16("result");
149  msg.readInt32("cash points");
150  msg.readInt32("kafra points");
151 }
152 
154 {
156  const int count = (msg.readInt16("len") - 10) / 6;
157  msg.readInt32("tab");
158  const int itemsCount = msg.readInt16("count");
159  if (count != itemsCount)
160  logger->log("error: wrong list count");
161 
162  for (int f = 0; f < count; f ++)
163  {
164  msg.readInt16("item id"); // item id size always 16 bit
165  msg.readInt32("price");
166  }
167 }
168 
170 {
172  int blockSize = 6;
173  if (itemIdLen == 4)
174  blockSize += 2;
175  const int count = (msg.readInt16("len") - 8) / blockSize;
176  const int itemsCount = msg.readInt16("count");
177  msg.readInt16("tab");
178  if (count != itemsCount)
179  logger->log("error: wrong list count");
180 
181  for (int f = 0; f < count; f ++)
182  {
183  msg.readItemId("item id");
184  msg.readInt32("price");
185  }
186 }
187 
188 } // namespace EAthena
int BeingId
Definition: beingid.h:30
int BeingTypeId
Definition: beingtypeid.h:30
const BeingTypeId BeingTypeId_zero
Definition: beingtypeid.h:30
int itemIdLen
Definition: client.cpp:130
int packetVersion
Definition: client.cpp:125
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
void log(const char *const log_text,...)
Definition: logger.cpp:269
#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
Logger * logger
Definition: logger.cpp:89
#define UNIMPLEMENTEDPACKETFIELD(field)
Definition: logger.h:59
#define UNIMPLEMENTEDPACKET
Definition: logger.h:56
bool msg(InputEvent &event)
Definition: chat.cpp:39
bool info(InputEvent &event)
Definition: commands.cpp:57
void processCashShopBuy(Net::MessageIn &msg)
void processCashShopSchedule(Net::MessageIn &msg)
void processCashShopBuyAck(Net::MessageIn &msg)
void processCashShopOpen(Net::MessageIn &msg)
void processCashShopPoints(Net::MessageIn &msg)
void processCashShopTabPriceList(Net::MessageIn &msg)
BeingTypeId mNpcTypeId
Definition: npcrecv.cpp:43
BeingInfo * get(const BeingTypeId id)
Definition: npcdb.cpp:188
void notify(const unsigned int message)
@ BUY_FAILED_NPC_NOT_FOUND
Definition: notifytypes.h:235
@ BUY_FAILED_WRONG_ITEM
Definition: notifytypes.h:237
@ BUY_FAILED_NO_MONEY
Definition: notifytypes.h:34
@ BUY_FAILED_SYSTEM_ERROR
Definition: notifytypes.h:236
@ BUY_FAILED_OVERWEIGHT
Definition: notifytypes.h:35