summaryrefslogtreecommitdiff
path: root/src/net/ea
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-08-27 16:07:33 +0300
committerAndrei Karas <akaras@inbox.ru>2015-08-27 16:07:33 +0300
commitf964252564162f70df2cda6b06b45245d0a383ad (patch)
tree7a7514d600d4a6f453477237deea3f6a52602cf2 /src/net/ea
parentd1ed605d722ea17a9d5576bdb306b9f4680d646f (diff)
downloadmanaplus-f964252564162f70df2cda6b06b45245d0a383ad.tar.gz
manaplus-f964252564162f70df2cda6b06b45245d0a383ad.tar.bz2
manaplus-f964252564162f70df2cda6b06b45245d0a383ad.tar.xz
manaplus-f964252564162f70df2cda6b06b45245d0a383ad.zip
Move receive code from inventoryhandler into separate file.
Diffstat (limited to 'src/net/ea')
-rw-r--r--src/net/ea/inventoryhandler.cpp232
-rw-r--r--src/net/ea/inventoryhandler.h28
-rw-r--r--src/net/ea/inventoryrecv.cpp257
-rw-r--r--src/net/ea/inventoryrecv.h69
4 files changed, 347 insertions, 239 deletions
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index b3821822e..e4409278c 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -36,6 +36,7 @@
#include "net/ea/eaprotocol.h"
#include "net/ea/equipbackend.h"
+#include "net/ea/inventoryrecv.h"
#include "utils/delete2.h"
@@ -43,50 +44,18 @@
#include "debug.h"
-const EquipSlot::Type EQUIP_POINTS[EquipSlot::VECTOREND] =
-{
- EquipSlot::LEGS_SLOT, // Lower Headgear
- EquipSlot::FIGHT1_SLOT, // Weapon
- EquipSlot::GLOVES_SLOT, // Garment
- EquipSlot::RING2_SLOT, // Accessory 1
- EquipSlot::RING1_SLOT, // Armor
- EquipSlot::FIGHT2_SLOT, // Shield
- EquipSlot::FEET_SLOT, // Footgear
- EquipSlot::NECK_SLOT, // Accessory 2
- EquipSlot::HEAD_SLOT, // Upper Headgear
- EquipSlot::TORSO_SLOT, // Middle Headgear
- EquipSlot::EVOL_RING1_SLOT, // Costume Top Headgear
- EquipSlot::EVOL_RING2_SLOT, // Costume Mid Headgear
- EquipSlot::PROJECTILE_SLOT, // Costume Low Headgear
- EquipSlot::COSTUME_ROBE_SLOT, // Costume Garment/Robe
- EquipSlot::MISSING1_SLOT, // Missing slot 1
- EquipSlot::MISSING2_SLOT, // Missing slot 2
- EquipSlot::SHADOW_ARMOR_SLOT, // Shadow Armor
- EquipSlot::SHADOW_WEAPON_SLOT, // Shadow Weapon
- EquipSlot::SHADOW_SHIELD_SLOT, // Shadow Shield
- EquipSlot::SHADOW_SHOES_SLOT, // Shadow Shoes
- EquipSlot::SHADOW_ACCESSORY2_SLOT, // Shadow Accessory 2
- EquipSlot::SHADOW_ACCESSORY1_SLOT, // Shadow Accessory 1
-};
-
namespace Ea
{
-EquipBackend InventoryHandler::mEquips;
-InventoryItems InventoryHandler::mInventoryItems;
-Inventory *InventoryHandler::mStorage = nullptr;
-PickupQueue InventoryHandler::mSentPickups;
-bool InventoryHandler::mDebugInventory = true;
-
InventoryHandler::InventoryHandler()
{
- mEquips.clear();
- mInventoryItems.clear();
- mStorage = nullptr;
+ InventoryRecv::mEquips.clear();
+ InventoryRecv::mInventoryItems.clear();
+ InventoryRecv::mStorage = nullptr;
storageWindow = nullptr;
- while (!mSentPickups.empty())
- mSentPickups.pop();
- mDebugInventory = true;
+ while (!InventoryRecv::mSentPickups.empty())
+ InventoryRecv::mSentPickups.pop();
+ InventoryRecv::mDebugInventory = true;
}
InventoryHandler::~InventoryHandler()
@@ -97,12 +66,12 @@ InventoryHandler::~InventoryHandler()
storageWindow = nullptr;
}
- delete2(mStorage);
+ delete2(InventoryRecv::mStorage);
}
void InventoryHandler::clear()
{
- delete2(mStorage);
+ delete2(InventoryRecv::mStorage);
}
bool InventoryHandler::canSplit(const Item *const item A_UNUSED) const
@@ -144,179 +113,6 @@ size_t InventoryHandler::getSize(const int type) const
return 0;
}
}
-int InventoryHandler::getSlot(const int eAthenaSlot)
-{
- if (eAthenaSlot == 0)
- return EquipSlot::VECTOREND;
-
- if (eAthenaSlot & 0x8000)
- return inventoryHandler->getProjectileSlot();
-
- unsigned int mask = 1;
- int position = 0;
- while (!(eAthenaSlot & mask))
- {
- mask <<= 1;
- position++;
- }
- return static_cast<int>(EQUIP_POINTS[position]);
-}
-
-void InventoryHandler::processPlayerInventoryRemove(Net::MessageIn &msg)
-{
- BLOCK_START("InventoryHandler::processPlayerInventoryRemove")
- Inventory *const inventory = localPlayer
- ? PlayerInfo::getInventory() : nullptr;
-
- const int index = msg.readInt16("index") - INVENTORY_OFFSET;
- const int amount = msg.readInt16("amount");
- if (inventory)
- {
- if (Item *const item = inventory->getItem(index))
- {
- item->increaseQuantity(-amount);
- if (item->getQuantity() == 0)
- inventory->removeItemAt(index);
- ArrowsListener::distributeEvent();
- }
- }
- BLOCK_END("InventoryHandler::processPlayerInventoryRemove")
-}
-
-void InventoryHandler::processPlayerInventoryUse(Net::MessageIn &msg)
-{
- BLOCK_START("InventoryHandler::processPlayerInventoryUse")
- Inventory *const inventory = localPlayer
- ? PlayerInfo::getInventory() : nullptr;
-
- const int index = msg.readInt16("index") - INVENTORY_OFFSET;
- msg.readInt16("item id");
- msg.readInt32("id?");
- const int amount = msg.readInt16("amount");
- msg.readUInt8("type");
-
- if (inventory)
- {
- if (Item *const item = inventory->getItem(index))
- {
- if (amount)
- item->setQuantity(amount);
- else
- inventory->removeItemAt(index);
- }
- }
- BLOCK_END("InventoryHandler::processPlayerInventoryUse")
-}
-
-void InventoryHandler::processItemUseResponse(Net::MessageIn &msg)
-{
- BLOCK_START("InventoryHandler::processItemUseResponse")
- Inventory *const inventory = localPlayer
- ? PlayerInfo::getInventory() : nullptr;
-
- const int index = msg.readInt16("index") - INVENTORY_OFFSET;
- const int amount = msg.readInt16("amount");
-
- if (msg.readUInt8("result") == 0)
- {
- NotifyManager::notify(NotifyTypes::USE_FAILED);
- }
- else
- {
- if (inventory)
- {
- if (Item *const item = inventory->getItem(index))
- {
- if (amount)
- item->setQuantity(amount);
- else
- inventory->removeItemAt(index);
- }
- }
- }
- BLOCK_END("InventoryHandler::processItemUseResponse")
-}
-
-void InventoryHandler::processPlayerStorageStatus(Net::MessageIn &msg)
-{
- BLOCK_START("InventoryHandler::processPlayerStorageStatus")
- /*
- * This is the closest we get to an "Open Storage" packet from the
- * server. It always comes after the two SMSG_PLAYER_STORAGE_...
- * packets that update storage contents.
- */
- msg.readInt16("used count");
- const int size = msg.readInt16("max size");
-
- if (!mStorage)
- mStorage = new Inventory(InventoryType::STORAGE, size);
-
- FOR_EACH (Ea::InventoryItems::const_iterator, it, mInventoryItems)
- {
- mStorage->setItem((*it).slot,
- (*it).id,
- (*it).type,
- (*it).quantity,
- (*it).refine,
- (*it).color,
- (*it).identified,
- (*it).damaged,
- (*it).favorite,
- (*it).equip,
- Equipped_false);
- }
- mInventoryItems.clear();
-
- if (!storageWindow)
- {
- CREATEWIDGETV(storageWindow, InventoryWindow, mStorage);
- }
- BLOCK_END("InventoryHandler::processPlayerStorageStatus")
-}
-
-void InventoryHandler::processPlayerStorageClose(Net::MessageIn &msg A_UNUSED)
-{
- BLOCK_START("InventoryHandler::processPlayerStorageClose")
- // Storage access has been closed
- // Storage window deletes itself
- if (storageWindow)
- {
- storageWindow->unsetInventory();
- storageWindow->close();
- }
- storageWindow = nullptr;
-
- if (mStorage)
- mStorage->clear();
-
- delete2(mStorage);
- BLOCK_END("InventoryHandler::processPlayerStorageClose")
-}
-
-void InventoryHandler::processPlayerAttackRange(Net::MessageIn &msg)
-{
- BLOCK_START("InventoryHandler::processPlayerAttackRange")
- const int range = msg.readInt16("range");
- if (localPlayer)
- localPlayer->setAttackRange(range);
- PlayerInfo::setStatBase(Attributes::ATTACK_RANGE, range);
- PlayerInfo::setStatMod(Attributes::ATTACK_RANGE, 0);
- BLOCK_END("InventoryHandler::processPlayerAttackRange")
-}
-
-void InventoryHandler::processPlayerArrowEquip(Net::MessageIn &msg)
-{
- BLOCK_START("InventoryHandler::processPlayerArrowEquip")
- int index = msg.readInt16("index");
- if (index <= 1)
- return;
-
- index -= INVENTORY_OFFSET;
- mEquips.setEquipment(inventoryHandler->getProjectileSlot(), index);
- ArrowsListener::distributeEvent();
- BLOCK_END("InventoryHandler::processPlayerArrowEquip")
-}
-
void InventoryHandler::destroyStorage()
{
BLOCK_START("InventoryHandler::closeStorage")
@@ -334,4 +130,14 @@ void InventoryHandler::forgotStorage()
storageWindow = nullptr;
}
+void InventoryHandler::pushPickup(const BeingId floorId)
+{
+ InventoryRecv::mSentPickups.push(floorId);
+}
+
+Inventory *InventoryHandler::getStorage() const
+{
+ return InventoryRecv::mStorage;
+}
+
} // namespace Ea
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h
index 29d24a1ac..3883ab0d4 100644
--- a/src/net/ea/inventoryhandler.h
+++ b/src/net/ea/inventoryhandler.h
@@ -68,40 +68,16 @@ class InventoryHandler notfinal : public Net::InventoryHandler
size_t getSize(const int type) const override final A_WARN_UNUSED;
- void pushPickup(const BeingId floorId)
- { mSentPickups.push(floorId); }
-
- static int getSlot(const int eAthenaSlot) A_WARN_UNUSED;
+ void pushPickup(const BeingId floorId);
void destroyStorage() override final;
void forgotStorage() override final;
- Inventory *getStorage() const override final
- { return mStorage; }
+ Inventory *getStorage() const override final;
protected:
InventoryHandler();
-
- static void processPlayerInventoryRemove(Net::MessageIn &msg);
-
- static void processPlayerInventoryUse(Net::MessageIn &msg);
-
- static void processItemUseResponse(Net::MessageIn &msg);
-
- static void processPlayerStorageStatus(Net::MessageIn &msg);
-
- static void processPlayerStorageClose(Net::MessageIn &msg);
-
- static void processPlayerAttackRange(Net::MessageIn &msg);
-
- static void processPlayerArrowEquip(Net::MessageIn &msg);
-
- static EquipBackend mEquips;
- static InventoryItems mInventoryItems;
- static Inventory *mStorage;
- static PickupQueue mSentPickups;
- static bool mDebugInventory;
};
} // namespace Ea
diff --git a/src/net/ea/inventoryrecv.cpp b/src/net/ea/inventoryrecv.cpp
new file mode 100644
index 000000000..810743d26
--- /dev/null
+++ b/src/net/ea/inventoryrecv.cpp
@@ -0,0 +1,257 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "net/ea/inventoryrecv.h"
+
+#include "notifymanager.h"
+
+#include "being/localplayer.h"
+
+#include "enums/equipslot.h"
+
+#include "enums/resources/notifytypes.h"
+
+#include "gui/widgets/createwidget.h"
+
+#include "net/messagein.h"
+
+#include "net/ea/eaprotocol.h"
+#include "net/ea/equipbackend.h"
+
+#include "utils/delete2.h"
+
+#include "listeners/arrowslistener.h"
+
+#include "debug.h"
+
+namespace Ea
+{
+
+namespace InventoryRecv
+{
+ const EquipSlot::Type EQUIP_POINTS[EquipSlot::VECTOREND] =
+ {
+ EquipSlot::LEGS_SLOT, // Lower Headgear
+ EquipSlot::FIGHT1_SLOT, // Weapon
+ EquipSlot::GLOVES_SLOT, // Garment
+ EquipSlot::RING2_SLOT, // Accessory 1
+ EquipSlot::RING1_SLOT, // Armor
+ EquipSlot::FIGHT2_SLOT, // Shield
+ EquipSlot::FEET_SLOT, // Footgear
+ EquipSlot::NECK_SLOT, // Accessory 2
+ EquipSlot::HEAD_SLOT, // Upper Headgear
+ EquipSlot::TORSO_SLOT, // Middle Headgear
+ EquipSlot::EVOL_RING1_SLOT, // Costume Top Headgear
+ EquipSlot::EVOL_RING2_SLOT, // Costume Mid Headgear
+ EquipSlot::PROJECTILE_SLOT, // Costume Low Headgear
+ EquipSlot::COSTUME_ROBE_SLOT, // Costume Garment/Robe
+ EquipSlot::MISSING1_SLOT, // Missing slot 1
+ EquipSlot::MISSING2_SLOT, // Missing slot 2
+ EquipSlot::SHADOW_ARMOR_SLOT, // Shadow Armor
+ EquipSlot::SHADOW_WEAPON_SLOT, // Shadow Weapon
+ EquipSlot::SHADOW_SHIELD_SLOT, // Shadow Shield
+ EquipSlot::SHADOW_SHOES_SLOT, // Shadow Shoes
+ EquipSlot::SHADOW_ACCESSORY2_SLOT, // Shadow Accessory 2
+ EquipSlot::SHADOW_ACCESSORY1_SLOT, // Shadow Accessory 1
+ };
+
+ EquipBackend mEquips;
+ InventoryItems mInventoryItems;
+ Inventory *mStorage = nullptr;
+ PickupQueue mSentPickups;
+ bool mDebugInventory = true;
+}
+
+void InventoryRecv::processPlayerInventoryRemove(Net::MessageIn &msg)
+{
+ BLOCK_START("InventoryRecv::processPlayerInventoryRemove")
+ Inventory *const inventory = localPlayer
+ ? PlayerInfo::getInventory() : nullptr;
+
+ const int index = msg.readInt16("index") - INVENTORY_OFFSET;
+ const int amount = msg.readInt16("amount");
+ if (inventory)
+ {
+ if (Item *const item = inventory->getItem(index))
+ {
+ item->increaseQuantity(-amount);
+ if (item->getQuantity() == 0)
+ inventory->removeItemAt(index);
+ ArrowsListener::distributeEvent();
+ }
+ }
+ BLOCK_END("InventoryRecv::processPlayerInventoryRemove")
+}
+
+void InventoryRecv::processPlayerInventoryUse(Net::MessageIn &msg)
+{
+ BLOCK_START("InventoryRecv::processPlayerInventoryUse")
+ Inventory *const inventory = localPlayer
+ ? PlayerInfo::getInventory() : nullptr;
+
+ const int index = msg.readInt16("index") - INVENTORY_OFFSET;
+ msg.readInt16("item id");
+ msg.readInt32("id?");
+ const int amount = msg.readInt16("amount");
+ msg.readUInt8("type");
+
+ if (inventory)
+ {
+ if (Item *const item = inventory->getItem(index))
+ {
+ if (amount)
+ item->setQuantity(amount);
+ else
+ inventory->removeItemAt(index);
+ }
+ }
+ BLOCK_END("InventoryRecv::processPlayerInventoryUse")
+}
+
+void InventoryRecv::processItemUseResponse(Net::MessageIn &msg)
+{
+ BLOCK_START("InventoryRecv::processItemUseResponse")
+ Inventory *const inventory = localPlayer
+ ? PlayerInfo::getInventory() : nullptr;
+
+ const int index = msg.readInt16("index") - INVENTORY_OFFSET;
+ const int amount = msg.readInt16("amount");
+
+ if (msg.readUInt8("result") == 0)
+ {
+ NotifyManager::notify(NotifyTypes::USE_FAILED);
+ }
+ else
+ {
+ if (inventory)
+ {
+ if (Item *const item = inventory->getItem(index))
+ {
+ if (amount)
+ item->setQuantity(amount);
+ else
+ inventory->removeItemAt(index);
+ }
+ }
+ }
+ BLOCK_END("InventoryRecv::processItemUseResponse")
+}
+
+void InventoryRecv::processPlayerStorageStatus(Net::MessageIn &msg)
+{
+ BLOCK_START("InventoryRecv::processPlayerStorageStatus")
+ /*
+ * This is the closest we get to an "Open Storage" packet from the
+ * server. It always comes after the two SMSG_PLAYER_STORAGE_...
+ * packets that update storage contents.
+ */
+ msg.readInt16("used count");
+ const int size = msg.readInt16("max size");
+
+ if (!mStorage)
+ mStorage = new Inventory(InventoryType::STORAGE, size);
+
+ FOR_EACH (Ea::InventoryItems::const_iterator, it, mInventoryItems)
+ {
+ mStorage->setItem((*it).slot,
+ (*it).id,
+ (*it).type,
+ (*it).quantity,
+ (*it).refine,
+ (*it).color,
+ (*it).identified,
+ (*it).damaged,
+ (*it).favorite,
+ (*it).equip,
+ Equipped_false);
+ }
+ mInventoryItems.clear();
+
+ if (!storageWindow)
+ {
+ CREATEWIDGETV(storageWindow, InventoryWindow, mStorage);
+ }
+ BLOCK_END("InventoryRecv::processPlayerStorageStatus")
+}
+
+void InventoryRecv::processPlayerStorageClose(Net::MessageIn &msg A_UNUSED)
+{
+ BLOCK_START("InventoryRecv::processPlayerStorageClose")
+ // Storage access has been closed
+ // Storage window deletes itself
+ if (storageWindow)
+ {
+ storageWindow->unsetInventory();
+ storageWindow->close();
+ }
+ storageWindow = nullptr;
+
+ if (mStorage)
+ mStorage->clear();
+
+ delete2(mStorage);
+ BLOCK_END("InventoryRecv::processPlayerStorageClose")
+}
+
+void InventoryRecv::processPlayerAttackRange(Net::MessageIn &msg)
+{
+ BLOCK_START("InventoryRecv::processPlayerAttackRange")
+ const int range = msg.readInt16("range");
+ if (localPlayer)
+ localPlayer->setAttackRange(range);
+ PlayerInfo::setStatBase(Attributes::ATTACK_RANGE, range);
+ PlayerInfo::setStatMod(Attributes::ATTACK_RANGE, 0);
+ BLOCK_END("InventoryRecv::processPlayerAttackRange")
+}
+
+void InventoryRecv::processPlayerArrowEquip(Net::MessageIn &msg)
+{
+ BLOCK_START("InventoryRecv::processPlayerArrowEquip")
+ int index = msg.readInt16("index");
+ if (index <= 1)
+ return;
+
+ index -= INVENTORY_OFFSET;
+ mEquips.setEquipment(inventoryHandler->getProjectileSlot(), index);
+ ArrowsListener::distributeEvent();
+ BLOCK_END("InventoryRecv::processPlayerArrowEquip")
+}
+
+int InventoryRecv::getSlot(const int eAthenaSlot)
+{
+ if (eAthenaSlot == 0)
+ return EquipSlot::VECTOREND;
+
+ if (eAthenaSlot & 0x8000)
+ return inventoryHandler->getProjectileSlot();
+
+ unsigned int mask = 1;
+ int position = 0;
+ while (!(eAthenaSlot & mask))
+ {
+ mask <<= 1;
+ position++;
+ }
+ return static_cast<int>(EQUIP_POINTS[position]);
+}
+
+} // namespace Ea
diff --git a/src/net/ea/inventoryrecv.h b/src/net/ea/inventoryrecv.h
new file mode 100644
index 000000000..b5ba2a4df
--- /dev/null
+++ b/src/net/ea/inventoryrecv.h
@@ -0,0 +1,69 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NET_EA_INVENTORYRECV_H
+#define NET_EA_INVENTORYRECV_H
+
+#include "localconsts.h"
+
+#include "enums/simpletypes/beingid.h"
+
+#include "net/inventoryhandler.h"
+
+#include "net/ea/inventoryitem.h"
+
+#include <queue>
+
+namespace Net
+{
+ class MessageIn;
+}
+
+namespace Ea
+{
+
+ class EquipBackend;
+
+ typedef std::vector<InventoryItem> InventoryItems;
+ typedef std::queue<BeingId> PickupQueue;
+
+ namespace InventoryRecv
+ {
+ extern EquipBackend mEquips;
+ extern InventoryItems mInventoryItems;
+ extern Inventory *mStorage;
+ extern PickupQueue mSentPickups;
+ extern bool mDebugInventory;
+
+ void processPlayerInventoryRemove(Net::MessageIn &msg);
+ void processPlayerInventoryUse(Net::MessageIn &msg);
+ void processItemUseResponse(Net::MessageIn &msg);
+ void processPlayerStorageStatus(Net::MessageIn &msg);
+ void processPlayerStorageClose(Net::MessageIn &msg);
+ void processPlayerAttackRange(Net::MessageIn &msg);
+ void processPlayerArrowEquip(Net::MessageIn &msg);
+
+ int getSlot(const int eAthenaSlot) A_WARN_UNUSED;
+ } // namespace InventoryRecv
+} // namespace Ea
+
+#endif // NET_EA_INVENTORYRECV_H