ManaPlus
inventoryhandler.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 "const/net/inventory.h"
27 
28 #include "enums/equipslot.h"
29 
30 #include "net/tmwa/messageout.h"
31 #include "net/tmwa/protocolout.h"
32 
33 #include "resources/item/item.h"
34 
35 #include "debug.h"
36 
37 // missing EQUIP_RING1_SLOT
39 {
41  EquipSlot::FEET_SLOT, // 1 SPRITE_HAIR
42  EquipSlot::LEGS_SLOT, // 2 SPRITE_WEAPON
43  EquipSlot::TORSO_SLOT, // 3 SPRITE_HEAD_BOTTOM
45  EquipSlot::NECK_SLOT, // 5 SPRITE_RING
47  EquipSlot::HEAD_SLOT, // 7 SPRITE_CLOTHES_COLOR
48  EquipSlot::RING2_SLOT, // 8 0
49  EquipSlot::GLOVES_SLOT, // 9 SPRITE_SHOES
50  EquipSlot::FIGHT1_SLOT, // 10 SPRITE_BODY
51  EquipSlot::FIGHT2_SLOT, // 11 SPRITE_FLOOR
52  EquipSlot::EVOL_RING1_SLOT, // 12 SPRITE_ROBE
53  EquipSlot::EVOL_RING2_SLOT, // 13 SPRITE_EVOL2
54 };
55 
56 namespace TmwAthena
57 {
58 
61 {
62  inventoryHandler = this;
63 }
64 
66 {
67  inventoryHandler = nullptr;
68 }
69 
70 void InventoryHandler::equipItem(const Item *const item) const
71 {
72  if (item == nullptr)
73  return;
74 
75  createOutPacket(CMSG_PLAYER_EQUIP);
76  outMsg.writeInt16(CAST_S16(
77  item->getInvIndex() + INVENTORY_OFFSET), "index");
78  outMsg.writeInt16(0, "unused");
79 }
80 
81 void InventoryHandler::unequipItem(const Item *const item) const
82 {
83  if (item == nullptr)
84  return;
85 
86  createOutPacket(CMSG_PLAYER_UNEQUIP);
87  outMsg.writeInt16(CAST_S16(
88  item->getInvIndex() + INVENTORY_OFFSET), "index");
89 }
90 
91 void InventoryHandler::useItem(const Item *const item) const
92 {
93  if (item == nullptr)
94  return;
95 
96  createOutPacket(CMSG_PLAYER_INVENTORY_USE);
97  outMsg.writeInt16(CAST_S16(
98  item->getInvIndex() + INVENTORY_OFFSET), "index");
99  outMsg.writeInt32(item->getId(), "item id");
100 }
101 
102 void InventoryHandler::useItem(const Item *const item,
103  const int16_t useType A_UNUSED) const
104 {
105  if (item == nullptr)
106  return;
107 
108  createOutPacket(CMSG_PLAYER_INVENTORY_USE);
109  outMsg.writeInt16(CAST_S16(
110  item->getInvIndex() + INVENTORY_OFFSET), "index");
111  outMsg.writeInt32(item->getId(), "item id");
112 }
113 
114 void InventoryHandler::dropItem(const Item *const item, const int amount) const
115 {
116  if (item == nullptr)
117  return;
118 
119  createOutPacket(CMSG_PLAYER_INVENTORY_DROP);
120  outMsg.writeInt16(CAST_S16(
121  item->getInvIndex() + INVENTORY_OFFSET), "index");
122  outMsg.writeInt16(CAST_S16(amount), "amount");
123 }
124 
126 {
127  createOutPacket(CMSG_CLOSE_STORAGE);
128 }
129 
131  const int slot,
132  const int amount,
133  const InventoryTypeT destination) const
134 {
135  if (source == InventoryType::Inventory &&
136  destination == InventoryType::Storage)
137  {
138  createOutPacket(CMSG_MOVE_TO_STORAGE);
139  outMsg.writeInt16(CAST_S16(slot + INVENTORY_OFFSET),
140  "index");
141  outMsg.writeInt32(amount, "amount");
142  }
143  else if (source == InventoryType::Storage &&
144  destination == InventoryType::Inventory)
145  {
146  createOutPacket(CMSG_MOVE_FROM_STORAGE);
147  outMsg.writeInt16(CAST_S16(slot + STORAGE_OFFSET),
148  "index");
149  outMsg.writeInt32(amount, "amount");
150  }
151 }
152 
153 void InventoryHandler::useCard(const Item *const item A_UNUSED)
154 {
155 }
156 
157 void InventoryHandler::insertCard(const int cardIndex A_UNUSED,
158  const int itemIndex A_UNUSED) const
159 {
160 }
161 
163  const bool favorite A_UNUSED) const
164 {
165 }
166 
167 void InventoryHandler::selectEgg(const Item *const item A_UNUSED) const
168 {
169 }
170 
171 int InventoryHandler::convertFromServerSlot(const int serverSlot) const
172 {
173  if (serverSlot < 0 || serverSlot > 13)
174  return 0;
175 
176  return CAST_S32(EQUIP_CONVERT[serverSlot]);
177 }
178 
180  const int type A_UNUSED) const
181 {
182 }
183 
184 void InventoryHandler::identifyItem(const Item *const item A_UNUSED) const
185 {
186 }
187 
188 void InventoryHandler::mergeItemsAck(const STD_VECTOR<Item*> &items A_UNUSED)
189  const
190 {
191 }
192 
194 {
195 }
196 
198 {
199 }
200 
202 {
203 }
204 
206 {
207 }
208 
209 } // namespace TmwAthena
int BeingId
Definition: beingid.h:30
#define CAST_S16
Definition: cast.h:28
#define CAST_S32
Definition: cast.h:30
Definition: item.h:50
int getInvIndex() const
Definition: item.h:165
int getId() const
Definition: item.h:81
void identifyItem(const Item *const item) const
void favoriteItem(const Item *const item, const bool favorite) const
int convertFromServerSlot(const int serverSlot) const
void moveItem2(const InventoryTypeT source, const int slot, const int amount, const InventoryTypeT destination) const
void selectEgg(const Item *const item) const
void useItem(const Item *const item) const
void mergeItemsAck(const std::vector< Item * > &items) const
void unequipItem(const Item *const item) const
void dropItem(const Item *const item, const int amount) const
void insertCard(const int cardIndex, const int itemIndex) const
void selectCart(const BeingId accountId, const int type) const
void equipItem(const Item *const item) const
void useCard(const Item *const item)
static const int STORAGE_OFFSET
Definition: inventory.h:28
static const int INVENTORY_OFFSET
Definition: inventory.h:27
const EquipSlot::Type EQUIP_CONVERT[]
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89
InventoryType ::T InventoryTypeT
Definition: inventorytype.h:42
#define A_UNUSED
Definition: localconsts.h:160
#define createOutPacket(name)
Definition: messageout.h:37
@ FIGHT1_SLOT
Definition: equipslot.h:41
@ EVOL_RING1_SLOT
Definition: equipslot.h:44
@ HEAD_SLOT
Definition: equipslot.h:35
@ LEGS_SLOT
Definition: equipslot.h:36
@ GLOVES_SLOT
Definition: equipslot.h:34
@ PROJECTILE_SLOT
Definition: equipslot.h:43
@ NECK_SLOT
Definition: equipslot.h:40
@ TORSO_SLOT
Definition: equipslot.h:33
@ FIGHT2_SLOT
Definition: equipslot.h:42
@ RING2_SLOT
Definition: equipslot.h:39
@ EVOL_RING2_SLOT
Definition: equipslot.h:45
@ FEET_SLOT
Definition: equipslot.h:37