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.readItemId("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"); // +++ need use int32
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"); // ++ need use int32
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  // +++ probably need add drop effect fields?
95 
96  if (actorManager != nullptr)
97  {
99  itemId,
100  x, y,
101  itemType,
102  amount,
103  refine,
105  identified,
106  damaged,
107  subX, subY,
108  &cards[0]);
109  }
110 }
111 
113 {
115  msg.readInt16("len");
116  msg.readUInt8("type");
117  msg.readItemId("item id");
118  msg.readUInt8("len");
119  msg.readString(24, "name");
120  msg.readUInt8("monster name len");
121  msg.readString(24, "monster name");
122 }
123 
125 {
126  const BeingId id = msg.readBeingId("item object id");
127  const int itemId = msg.readItemId("item id");
128  const Identified identified = fromInt(
129  msg.readUInt8("identify"), Identified);
130  const int x = msg.readInt16("x");
131  const int y = msg.readInt16("y");
132  const int amount = msg.readInt16("amount");
133  const int subX = CAST_S32(msg.readInt8("sub x"));
134  const int subY = CAST_S32(msg.readInt8("sub y"));
135 
136  if (actorManager != nullptr)
137  {
139  itemId,
140  x, y,
142  amount,
143  0,
145  identified,
147  subX, subY,
148  nullptr);
149  }
150 }
151 
153 {
154  const BeingId id = msg.readBeingId("item object id");
155  const int itemId = msg.readInt16("item id"); // +++ need use int32
156  const ItemTypeT itemType = static_cast<ItemTypeT>(
157  msg.readUInt8("type"));
158  const Identified identified = fromInt(
159  msg.readUInt8("identify"), Identified);
160  const Damaged damaged = fromBool(msg.readUInt8("attribute"), Damaged);
161  const uint8_t refine = msg.readUInt8("refine");
162  int cards[maxCards];
163  for (int f = 0; f < maxCards; f++)
164  cards[f] = msg.readUInt16("card"); // +++ need use int32
165  const int x = msg.readInt16("x");
166  const int y = msg.readInt16("y");
167  const int amount = msg.readInt16("amount");
168  const int subX = CAST_S32(msg.readInt8("sub x"));
169  const int subY = CAST_S32(msg.readInt8("sub y"));
170 
171  if (actorManager != nullptr)
172  {
174  itemId,
175  x, y,
176  itemType,
177  amount,
178  refine,
180  identified,
181  damaged,
182  subX, subY,
183  &cards[0]);
184  }
185 }
186 
187 } // namespace EAthena
unsigned char readUInt8(const char *const str)
Definition: messagein.cpp:103
static ItemColor getColorFromCards(const int *const cards)
void processItemVisible(Net::MessageIn &msg)
Definition: itemrecv.cpp:124
uint16_t readUInt16(const char *const str)
Definition: messagein.cpp:152
void processItemVisible2(Net::MessageIn &msg)
Definition: itemrecv.cpp:152
BeingId readBeingId(const char *const str)
Definition: messagein.cpp:223
#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:116
int packetVersion
Definition: client.cpp:124
int16_t readInt16(const char *const str)
Definition: messagein.cpp:130
bool packets_zero
Definition: client.cpp:132
#define CAST_S32
Definition: cast.h:29
#define fromBool(val, name)
Definition: booldefines.h:48
int getVersion() const
Definition: messagein.h:133
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
int readItemId(const char *const str)
Definition: messagein.cpp:216
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:367
#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:112