ManaPlus
inventoryrecv.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 
24 #include "net/ea/inventoryrecv.h"
25 
26 #include "notifymanager.h"
27 
28 #include "being/localplayer.h"
29 
30 #include "const/net/inventory.h"
31 
33 
35 
36 #include "net/inventoryhandler.h"
37 #include "net/messagein.h"
38 
39 #include "net/ea/equipbackend.h"
40 
41 #include "utils/delete2.h"
42 #include "utils/foreach.h"
43 
45 
46 #include "debug.h"
47 
48 namespace Ea
49 {
50 
51 namespace InventoryRecv
52 {
55  Inventory *mStorage = nullptr;
57  bool mDebugInventory = true;
58 } // namespace InventoryRecv
59 
61 {
62  BLOCK_START("InventoryRecv::processItemUseResponse")
63  Inventory *const inventory = localPlayer != nullptr
64  ? PlayerInfo::getInventory() : nullptr;
65 
66  const int index = msg.readInt16("index") - INVENTORY_OFFSET;
67  const int amount = msg.readInt16("amount");
68 
69  if (msg.readUInt8("result") == 0)
70  {
72  }
73  else
74  {
75  if (inventory != nullptr)
76  {
77  if (Item *const item = inventory->getItem(index))
78  {
79  if (amount != 0)
80  item->setQuantity(amount);
81  else
82  inventory->removeItemAt(index);
83  }
84  }
85  }
86  BLOCK_END("InventoryRecv::processItemUseResponse")
87 }
88 
90 {
91  BLOCK_START("InventoryRecv::processPlayerStorageStatus")
92  /*
93  * This is the closest we get to an "Open Storage" packet from the
94  * server. It always comes after the two SMSG_PLAYER_STORAGE_...
95  * packets that update storage contents.
96  */
97  msg.readInt16("used count");
98  const int size = msg.readInt16("max size");
99 
100  if (mStorage == nullptr)
102 
103  FOR_EACH (Ea::InventoryItems::const_iterator, it, mStorageItems)
104  {
105  mStorage->setItem((*it).slot,
106  (*it).id,
107  (*it).type,
108  (*it).quantity,
109  (*it).refine,
110  (*it).color,
111  (*it).identified,
112  (*it).damaged,
113  (*it).favorite,
114  (*it).equip,
116  }
117  mStorageItems.clear();
118 
119  if (storageWindow == nullptr)
120  {
122  }
123  BLOCK_END("InventoryRecv::processPlayerStorageStatus")
124 }
125 
127 {
128  BLOCK_START("InventoryRecv::processPlayerStorageClose")
129  // Storage access has been closed
130  // Storage window deletes itself
131  if (storageWindow != nullptr)
132  {
134  storageWindow->close();
135  }
136  storageWindow = nullptr;
137 
138  if (mStorage != nullptr)
139  mStorage->clear();
140 
142  BLOCK_END("InventoryRecv::processPlayerStorageClose")
143 }
144 
146 {
147  BLOCK_START("InventoryRecv::processPlayerAttackRange")
148  const int range = msg.readInt16("range");
149  if (localPlayer != nullptr)
150  localPlayer->setAttackRange(range);
152  range,
153  Notify_true);
155  0,
156  Notify_true);
157  BLOCK_END("InventoryRecv::processPlayerAttackRange")
158 }
159 
161 {
162  BLOCK_START("InventoryRecv::processPlayerArrowEquip")
163  int index = msg.readInt16("index");
164  if (index <= 1)
165  return;
166 
167  index -= INVENTORY_OFFSET;
170  BLOCK_END("InventoryRecv::processPlayerArrowEquip")
171 }
172 
173 } // namespace Ea
static void distributeEvent()
void setAttackRange(const int range)
Definition: being.h:843
void setEquipment(const int index, const int inventoryIndex)
Definition: equipbackend.h:78
void clear()
Definition: inventory.cpp:238
void removeItemAt(const int index)
Definition: inventory.cpp:254
Item * getItem(const int index) const
Definition: inventory.cpp:83
virtual void setItem(const int index, const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
Definition: inventory.cpp:141
Definition: item.h:50
virtual int getProjectileSlot() const =0
static const int INVENTORY_OFFSET
Definition: inventory.h:27
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:25
#define delete2(var)
Definition: delete2.h:25
const bool Equipped_false
Definition: equipped.h:30
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
Net::InventoryHandler * inventoryHandler
Definition: net.cpp:89
InventoryWindow * storageWindow
#define A_UNUSED
Definition: localconsts.h:160
LocalPlayer * localPlayer
bool msg(InputEvent &event)
Definition: chat.cpp:39
@ PLAYER_ATTACK_RANGE
Definition: attributes.h:52
EquipBackend mEquips
void processPlayerArrowEquip(Net::MessageIn &msg)
PickupQueue mSentPickups
void processPlayerStorageStatus(Net::MessageIn &msg)
void processPlayerAttackRange(Net::MessageIn &msg)
void processItemUseResponse(Net::MessageIn &msg)
Inventory * mStorage
void processPlayerStorageClose(Net::MessageIn &msg)
InventoryItems mStorageItems
std::queue< BeingId > PickupQueue
std::vector< InventoryItem > InventoryItems
int size()
Definition: emotedb.cpp:306
void notify(const unsigned int message)
Inventory * getInventory()
Definition: playerinfo.cpp:195
void setStatMod(const AttributesT id, const int value, const Notify notify)
Definition: playerinfo.cpp:159
void setStatBase(const AttributesT id, const int value, const Notify notify)
Definition: playerinfo.cpp:143
const bool Notify_true
Definition: notify.h:30
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79