ManaPlus
itemrecv.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-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "net/eathena/itemrecv.h"
24 
25 #include "actormanager.h"
26 #include "itemcolormanager.h"
27 #include "logger.h"
28 
30 
31 #include "net/messagein.h"
32 
33 #include "debug.h"
34 
35 extern int packetVersion;
36 extern bool packets_zero;
37 
38 namespace EAthena
39 {
40 
42 {
43  const BeingId id = msg.readBeingId("id");
44  const int itemId = msg.readInt16("item id");
45  ItemTypeT itemType = ItemType::Unknown;
46  if (msg.getVersion() >= 20130000)
47  itemType = static_cast<ItemTypeT>(msg.readInt16("type"));
48  const Identified identified = fromInt(
49  msg.readUInt8("identify"), Identified);
50  const int x = msg.readInt16("x");
51  const int y = msg.readInt16("y");
52  const int subX = CAST_S32(msg.readInt8("subx"));
53  const int subY = CAST_S32(msg.readInt8("suby"));
54  const int amount = msg.readInt16("count");
55  if (packets_zero || packetVersion >= 20180418)
56  {
57  msg.readUInt8("show drop effect");
58  msg.readInt16("show effect mode");
59  }
60 
61  if (actorManager != nullptr)
62  {
64  itemId,
65  x, y,
66  itemType,
67  amount,
68  0,
70  identified,
72  subX, subY,
73  nullptr);
74  }
75 }
76 
78 {
79  const BeingId id = msg.readBeingId("id");
80  const int itemId = msg.readInt16("item id");
81  const ItemTypeT itemType = static_cast<ItemTypeT>(msg.readUInt8("type"));
82  const Identified identified = fromInt(
83  msg.readUInt8("identify"), Identified);
84  const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
85  const uint8_t refine = msg.readUInt8("refine");
86  int cards[maxCards];
87  for (int f = 0; f < maxCards; f++)
88  cards[f] = msg.readUInt16("card");
89  const int x = msg.readInt16("x");
90  const int y = msg.readInt16("y");
91  const int amount = msg.readInt16("amount");
92  const int subX = CAST_S32(msg.readInt8("subx"));
93  const int subY = CAST_S32(msg.readInt8("suby"));
94 
95  if (actorManager != nullptr)
96  {
98  itemId,
99  x, y,
100  itemType,
101  amount,
102  refine,
104  identified,
105  damaged,
106  subX, subY,
107  &cards[0]);
108  }
109 }
110 
112 {
114  msg.readInt16("len");
115  msg.readUInt8("type");
116  msg.readInt16("item id");
117  msg.readUInt8("len");
118  msg.readString(24, "name");
119  msg.readUInt8("monster name len");
120  msg.readString(24, "monster name");
121 }
122 
124 {
125  const BeingId id = msg.readBeingId("item object id");
126  const int itemId = msg.readInt16("item id");
127  const Identified identified = fromInt(
128  msg.readUInt8("identify"), Identified);
129  const int x = msg.readInt16("x");
130  const int y = msg.readInt16("y");
131  const int amount = msg.readInt16("amount");
132  const int subX = CAST_S32(msg.readInt8("sub x"));
133  const int subY = CAST_S32(msg.readInt8("sub y"));
134 
135  if (actorManager != nullptr)
136  {
138  itemId,
139  x, y,
141  amount,
142  0,
144  identified,
146  subX, subY,
147  nullptr);
148  }
149 }
150 
152 {
153  const BeingId id = msg.readBeingId("item object id");
154  const int itemId = msg.readInt16("item id");
155  const ItemTypeT itemType = static_cast<ItemTypeT>(
156  msg.readUInt8("type"));
157  const Identified identified = fromInt(
158  msg.readUInt8("identify"), Identified);
159  const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
160  const uint8_t refine = msg.readUInt8("refine");
161  int cards[maxCards];
162  for (int f = 0; f < maxCards; f++)
163  cards[f] = msg.readUInt16("card");
164  const int x = msg.readInt16("x");
165  const int y = msg.readInt16("y");
166  const int amount = msg.readInt16("amount");
167  const int subX = CAST_S32(msg.readInt8("sub x"));
168  const int subY = CAST_S32(msg.readInt8("sub y"));
169 
170  if (actorManager != nullptr)
171  {
173  itemId,
174  x, y,
175  itemType,
176  amount,
177  refine,
179  identified,
180  damaged,
181  subX, subY,
182  &cards[0]);
183  }
184 }
185 
186 } // namespace EAthena
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:98
static ItemColor getColorFromCards(const int *const cards)
void processItemVisible(Net::MessageIn &msg)
Definition: itemrecv.cpp:123
uint16_t readUInt16(const char *const str)
Definition: messagein.cpp:147
void processItemVisible2(Net::MessageIn &msg)
Definition: itemrecv.cpp:151
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:211
#define fromInt(val, name)
Definition: intdefines.h:45
bool Identified
Definition: identified.h:29
int BeingId
Definition: beingid.h:29
bool msg(InputEvent &event)
Definition: chat.cpp:38
const ItemColor ItemColor_one
Definition: itemcolor.h:29
signed char readInt8(const char *const str)
Definition: messagein.cpp:111
int packetVersion
Definition: client.cpp:124
int16_t readInt16(const char *const str)
Definition: messagein.cpp:125
bool packets_zero
Definition: client.cpp:131
#define CAST_S32
Definition: cast.h:29
#define fromBool(val, name)
Definition: booldefines.h:48
FloorItem * createItem(const BeingId id, const int itemId, const int x, const int y, const ItemTypeT itemType, const int amount, const int refine, const ItemColor color, const Identified identified, const Damaged damaged, const int subX, const int subY, const int *const cards)
void processItemDropped(Net::MessageIn &msg)
Definition: itemrecv.cpp:41
unsigned int getVersion() const
Definition: messagein.h:131
ItemType ::T ItemTypeT
Definition: itemtype.h:42
bool Damaged
Definition: damaged.h:29
void processItemDropped2(Net::MessageIn &msg)
Definition: itemrecv.cpp:77
std::string readString(int length, const char *const dstr)
Definition: messagein.cpp:355
#define UNIMPLEMENTEDPACKET
Definition: logger.h:55
const bool Damaged_false
Definition: damaged.h:29
#define maxCards
Definition: cards.h:24
ActorManager * actorManager
void processItemMvpDropped(Net::MessageIn &msg)
Definition: itemrecv.cpp:111