summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-12-07 11:34:29 -0700
committerJared Adams <jaxad0127@gmail.com>2009-12-07 11:34:29 -0700
commit2f310b3040dcb56bd9ed1868dfa4f74b3fd00136 (patch)
tree81957f3eef8130b51e3dd85578ef18f56c274139 /src/net
parentfc48c24c6d366e165cbcfbd022d9421790089890 (diff)
downloadmana-client-2f310b3040dcb56bd9ed1868dfa4f74b3fd00136.tar.gz
mana-client-2f310b3040dcb56bd9ed1868dfa4f74b3fd00136.tar.bz2
mana-client-2f310b3040dcb56bd9ed1868dfa4f74b3fd00136.tar.xz
mana-client-2f310b3040dcb56bd9ed1868dfa4f74b3fd00136.zip
Simplify Equipment handling
Also merge eAthena's EquipmentHandler and InventoryHander. Fixes http://mantis.themanaworld.org/view.php?id=888 .
Diffstat (limited to 'src/net')
-rw-r--r--src/net/ea/equipmenthandler.cpp234
-rw-r--r--src/net/ea/equipmenthandler.h45
-rw-r--r--src/net/ea/generalhandler.cpp3
-rw-r--r--src/net/ea/generalhandler.h1
-rw-r--r--src/net/ea/inventoryhandler.cpp120
-rw-r--r--src/net/ea/inventoryhandler.h48
-rw-r--r--src/net/manaserv/inventoryhandler.cpp5
-rw-r--r--src/net/manaserv/inventoryhandler.h41
8 files changed, 206 insertions, 291 deletions
diff --git a/src/net/ea/equipmenthandler.cpp b/src/net/ea/equipmenthandler.cpp
deleted file mode 100644
index 28a2940c..00000000
--- a/src/net/ea/equipmenthandler.cpp
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "net/ea/equipmenthandler.h"
-
-#include "net/ea/protocol.h"
-
-#include "net/messagein.h"
-
-#include "equipment.h"
-#include "inventory.h"
-#include "item.h"
-#include "localplayer.h"
-#include "log.h"
-
-#include "gui/widgets/chattab.h"
-
-#include "utils/gettext.h"
-
-const Equipment::EquipmentSlots EQUIP_POINTS[Equipment::EQUIP_VECTOREND] = {
- Equipment::EQUIP_LEGS_SLOT,
- Equipment::EQUIP_FIGHT1_SLOT,
- Equipment::EQUIP_GLOVES_SLOT,
- Equipment::EQUIP_RING2_SLOT,
- Equipment::EQUIP_RING1_SLOT,
- Equipment::EQUIP_FIGHT2_SLOT,
- Equipment::EQUIP_FEET_SLOT,
- Equipment::EQUIP_NECK_SLOT,
- Equipment::EQUIP_HEAD_SLOT,
- Equipment::EQUIP_TORSO_SLOT,
- Equipment::EQUIP_PROJECTILE_SLOT};
-
-Item *equips[Equipment::EQUIP_VECTOREND];
-
-namespace EAthena {
-
-enum { debugEquipment = 1 };
-
-void setEquipment(int eAthenaSlot, int index, bool equiped)
-{
- if (!eAthenaSlot)
- return;
-
- Item *item = player_node->getInventory()->getItem(index);
-
- if (!item)
- return;
-
- int position = 0;
-
- if (eAthenaSlot & 0x8000) { // Arrows
- position = Equipment::EQUIP_PROJECTILE_SLOT;
- }
- else
- {
- /*
- * An item may occupy more than 1 slot. If so, it's
- * only shown as equipped on the *first* slot.
- */
- int mask = 1;
- while (!(eAthenaSlot & mask))
- {
- mask <<= 1;
- position++;
- }
-
- position = EQUIP_POINTS[position];
- }
-
- if (equips[position])
- equips[position]->setEquipped(false);
-
- if (equiped && item)
- {
- equips[position] = item;
- item->setEquipped(true);
- player_node->mEquipment->setEquipment(position, item->getId(), item->getQuantity());
-
- if (debugEquipment)
- {
- logger->log("Equipping: %i %i at position %i",
- index, eAthenaSlot, position);
- }
- }
- else
- {
- equips[position] = NULL;
- player_node->mEquipment->setEquipment(position, -1);
-
- if (debugEquipment)
- {
- logger->log("Unequipping: %i %i at position %i",
- index, eAthenaSlot, position);
- }
- }
-}
-
-void clearEquipment()
-{
- for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
- {
- if (equips[i])
- {
- equips[i]->setEquipped(false);
- player_node->mEquipment->setEquipment(i, -1);
- }
-
- equips[i] = NULL;
- }
-}
-
-Item *getRealEquipedItem(const Item *equipped)
-{
- if (!equipped)
- return NULL;
-
- for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
- {
- if (equips[i] && equipped->getId() == equips[i]->getId())
- return equips[i];
- }
-
- return NULL;
-}
-
-EquipmentHandler::EquipmentHandler()
-{
- static const Uint16 _messages[] = {
- SMSG_PLAYER_EQUIPMENT,
- SMSG_PLAYER_EQUIP,
- SMSG_PLAYER_UNEQUIP,
- SMSG_PLAYER_ARROW_EQUIP,
- SMSG_PLAYER_ATTACK_RANGE,
- 0
- };
- handledMessages = _messages;
- memset(equips, 0, sizeof(equips));
-}
-
-void EquipmentHandler::handleMessage(Net::MessageIn &msg)
-{
- int itemCount;
- int index, equipPoint, itemId;
- int type;
- Inventory *inventory = player_node->getInventory();
-
- switch (msg.getId())
- {
- case SMSG_PLAYER_EQUIPMENT:
- msg.readInt16(); // length
- itemCount = (msg.getLength() - 4) / 20;
-
- for (int loop = 0; loop < itemCount; loop++)
- {
- index = msg.readInt16() - INVENTORY_OFFSET;
- itemId = msg.readInt16();
- msg.readInt8(); // type
- msg.readInt8(); // identify flag
- msg.readInt16(); // equip type
- equipPoint = msg.readInt16();
- msg.readInt8(); // attribute
- msg.readInt8(); // refine
- msg.skip(8); // card
-
- inventory->setItem(index, itemId, 1, true);
-
- setEquipment(equipPoint, index, true);
- }
- break;
-
- case SMSG_PLAYER_EQUIP:
- index = msg.readInt16() - INVENTORY_OFFSET;
- equipPoint = msg.readInt16();
- type = msg.readInt8();
-
- if (!type)
- {
- localChatTab->chatLog(_("Unable to equip."), BY_SERVER);
- break;
- }
-
- setEquipment(equipPoint, index, true);
- break;
-
- case SMSG_PLAYER_UNEQUIP:
- index = msg.readInt16() - INVENTORY_OFFSET;
- equipPoint = msg.readInt16();
- type = msg.readInt8();
-
- if (!type) {
- localChatTab->chatLog(_("Unable to unequip."), BY_SERVER);
- break;
- }
-
- setEquipment(equipPoint, index, false);
- break;
-
- case SMSG_PLAYER_ATTACK_RANGE:
- player_node->setAttackRange(msg.readInt16());
- break;
-
- case SMSG_PLAYER_ARROW_EQUIP:
- index = msg.readInt16();
-
- if (index <= 1)
- break;
-
- index -= INVENTORY_OFFSET;
-
- logger->log("Arrows equipped: %i", index);
- setEquipment(0x8000, index, true);
- break;
- }
-}
-
-} // namespace EAthena
diff --git a/src/net/ea/equipmenthandler.h b/src/net/ea/equipmenthandler.h
deleted file mode 100644
index 32ea83c4..00000000
--- a/src/net/ea/equipmenthandler.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * The Mana World
- * Copyright (C) 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef NET_EA_EQUIPMENTHANDLER_H
-#define NET_EA_EQUIPMENTHANDLER_H
-
-#include "net/ea/messagehandler.h"
-
-class Item;
-
-namespace EAthena {
-
-void setEquipment(int eAthenaSlot, int index, bool equiped);
-void clearEquipment();
-Item *getRealEquipedItem(const Item *equipped);
-
-class EquipmentHandler : public MessageHandler
-{
- public:
- EquipmentHandler();
-
- virtual void handleMessage(Net::MessageIn &msg);
-};
-
-} // namespace EAthena
-
-#endif // NET_EA_EQUIPMENTHANDLER_H
diff --git a/src/net/ea/generalhandler.cpp b/src/net/ea/generalhandler.cpp
index 3818afec..44542ddc 100644
--- a/src/net/ea/generalhandler.cpp
+++ b/src/net/ea/generalhandler.cpp
@@ -35,7 +35,6 @@
#include "net/ea/buysellhandler.h"
#include "net/ea/chathandler.h"
#include "net/ea/charserverhandler.h"
-#include "net/ea/equipmenthandler.h"
#include "net/ea/gamehandler.h"
#include "net/ea/inventoryhandler.h"
#include "net/ea/itemhandler.h"
@@ -75,7 +74,6 @@ GeneralHandler::GeneralHandler():
mBuySellHandler(new BuySellHandler),
mCharHandler(new CharServerHandler),
mChatHandler(new ChatHandler),
- mEquipmentHandler(new EquipmentHandler),
mGameHandler(new GameHandler),
mInventoryHandler(new InventoryHandler),
mItemHandler(new ItemHandler),
@@ -158,7 +156,6 @@ void GeneralHandler::load()
mNetwork->registerHandler(mBuySellHandler.get());
mNetwork->registerHandler(mChatHandler.get());
mNetwork->registerHandler(mCharHandler.get());
- mNetwork->registerHandler(mEquipmentHandler.get());
mNetwork->registerHandler(mGameHandler.get());
mNetwork->registerHandler(mInventoryHandler.get());
mNetwork->registerHandler(mItemHandler.get());
diff --git a/src/net/ea/generalhandler.h b/src/net/ea/generalhandler.h
index abedd2f4..29dbcd3f 100644
--- a/src/net/ea/generalhandler.h
+++ b/src/net/ea/generalhandler.h
@@ -59,7 +59,6 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler
MessageHandlerPtr mBuySellHandler;
MessageHandlerPtr mCharHandler;
MessageHandlerPtr mChatHandler;
- MessageHandlerPtr mEquipmentHandler;
MessageHandlerPtr mGameHandler;
MessageHandlerPtr mInventoryHandler;
MessageHandlerPtr mItemHandler;
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index fbd5c9b3..d7758321 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -21,7 +21,6 @@
#include "net/ea/inventoryhandler.h"
-#include "net/ea/equipmenthandler.h"
#include "net/ea/protocol.h"
#include "net/messagein.h"
@@ -48,8 +47,41 @@
extern Net::InventoryHandler *inventoryHandler;
+const Equipment::Slot EQUIP_POINTS[Equipment::EQUIP_VECTOREND] = {
+ Equipment::EQUIP_LEGS_SLOT,
+ Equipment::EQUIP_FIGHT1_SLOT,
+ Equipment::EQUIP_GLOVES_SLOT,
+ Equipment::EQUIP_RING2_SLOT,
+ Equipment::EQUIP_RING1_SLOT,
+ Equipment::EQUIP_FIGHT2_SLOT,
+ Equipment::EQUIP_FEET_SLOT,
+ Equipment::EQUIP_NECK_SLOT,
+ Equipment::EQUIP_HEAD_SLOT,
+ Equipment::EQUIP_TORSO_SLOT,
+ Equipment::EQUIP_PROJECTILE_SLOT};
+
namespace EAthena {
+int getSlot(int eAthenaSlot)
+{
+ if (eAthenaSlot == 0)
+ {
+ return Equipment::EQUIP_VECTOREND;
+ }
+
+ if (eAthenaSlot & 0x8000)
+ return Equipment::EQUIP_PROJECTILE_SLOT;
+
+ int mask = 1;
+ int position = 0;
+ while (!(eAthenaSlot & mask))
+ {
+ mask <<= 1;
+ position++;
+ }
+ return EQUIP_POINTS[position];
+}
+
enum { debugInventory = 1 };
InventoryHandler::InventoryHandler()
@@ -66,6 +98,11 @@ InventoryHandler::InventoryHandler()
SMSG_PLAYER_STORAGE_ADD,
SMSG_PLAYER_STORAGE_REMOVE,
SMSG_PLAYER_STORAGE_CLOSE,
+ SMSG_PLAYER_EQUIPMENT,
+ SMSG_PLAYER_EQUIP,
+ SMSG_PLAYER_UNEQUIP,
+ SMSG_PLAYER_ARROW_EQUIP,
+ SMSG_PLAYER_ATTACK_RANGE,
0
};
handledMessages = _messages;
@@ -74,7 +111,7 @@ InventoryHandler::InventoryHandler()
void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
- int number;
+ int number, flag;
int index, amount, itemId, equipType, arrow;
int identified, cards[4], itemType;
Inventory *inventory = player_node->getInventory();
@@ -87,7 +124,9 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
if (msg.getId() == SMSG_PLAYER_INVENTORY)
{
// Clear inventory - this will be a complete refresh
- clearEquipment();
+ mEquips.clear();
+ player_node->mEquipment->setBackend(&mEquips);
+
inventory->clear();
}
@@ -124,6 +163,8 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
if (Item *item = inventory->getItem(index))
item->setEquipment(true);
}
+
+ //const Item *item = inventory->getItem(index);
} else {
storage->setItem(index, itemId, amount, false);
}
@@ -281,6 +322,73 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
storage->clear();
player_node->setInStorage(false);
break;
+
+ case SMSG_PLAYER_EQUIPMENT:
+ msg.readInt16(); // length
+ number = (msg.getLength() - 4) / 20;
+
+ for (int loop = 0; loop < number; loop++)
+ {
+ index = msg.readInt16() - INVENTORY_OFFSET;
+ itemId = msg.readInt16();
+ msg.readInt8(); // type
+ msg.readInt8(); // identify flag
+ msg.readInt16(); // equip type
+ equipType = msg.readInt16();
+ msg.readInt8(); // attribute
+ msg.readInt8(); // refine
+ msg.skip(8); // card
+
+ inventory->setItem(index, itemId, 1, true);
+
+ mEquips.setEquipment(getSlot(equipType), index);
+ }
+ break;
+
+ case SMSG_PLAYER_EQUIP:
+ index = msg.readInt16() - INVENTORY_OFFSET;
+ equipType = msg.readInt16();
+ flag = msg.readInt8();
+
+ if (!flag)
+ {
+ localChatTab->chatLog(_("Unable to equip."), BY_SERVER);
+ }
+ else
+ {
+ mEquips.setEquipment(getSlot(equipType), index);
+ }
+ break;
+
+ case SMSG_PLAYER_UNEQUIP:
+ index = msg.readInt16() - INVENTORY_OFFSET;
+ equipType = msg.readInt16();
+ flag = msg.readInt8();
+
+ if (!flag) {
+ localChatTab->chatLog(_("Unable to unequip."), BY_SERVER);
+ }
+ else
+ {
+ mEquips.setEquipment(getSlot(equipType), 0);
+ }
+ break;
+
+ case SMSG_PLAYER_ATTACK_RANGE:
+ player_node->setAttackRange(msg.readInt16());
+ break;
+
+ case SMSG_PLAYER_ARROW_EQUIP:
+ index = msg.readInt16();
+
+ if (index <= 1)
+ break;
+
+ index -= INVENTORY_OFFSET;
+
+ logger->log("Arrows equipped: %i", index);
+ mEquips.setEquipment(Equipment::EQUIP_PROJECTILE_SLOT, index);
+ break;
}
}
@@ -296,14 +404,14 @@ void InventoryHandler::equipItem(const Item *item)
void InventoryHandler::unequipItem(const Item *item)
{
- const Item *real_item = item->isInEquipment() ? getRealEquipedItem(item)
+ /*const Item *real_item = item->isInEquipment() ? getRealEquipedItem(item)
: item;
if (!real_item)
- return;
+ return;*/
MessageOut outMsg(CMSG_PLAYER_UNEQUIP);
- outMsg.writeInt16(real_item->getInvIndex() + INVENTORY_OFFSET);
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
}
void InventoryHandler::useItem(const Item *item)
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h
index 83a2b440..82c2a36e 100644
--- a/src/net/ea/inventoryhandler.h
+++ b/src/net/ea/inventoryhandler.h
@@ -27,8 +27,53 @@
#include "net/ea/messagehandler.h"
+#include "equipment.h"
+#include "inventory.h"
+#include "localplayer.h"
+
namespace EAthena {
+class EquipBackend : public Equipment::Backend {
+ public:
+ Item *getEquipment(int index) const
+ {
+ int invyIndex = mEquipment[index];
+ if (invyIndex == 0)
+ {
+ return NULL;
+ }
+ return player_node->getInventory()->getItem(invyIndex);
+ }
+
+ void clear()
+ {
+ for (int i = 0; i < EQUIPMENT_SIZE; i++)
+ {
+ if (mEquipment[i])
+ {
+ Item* item = player_node->getInventory()->getItem(i);
+ if (item)
+ {
+ item->setEquipped(false);
+ }
+ }
+
+ mEquipment[i] = 0;
+ }
+ }
+
+ void setEquipment(int index, int inventoryIndex)
+ {
+ mEquipment[index] = inventoryIndex;
+ Item* item = player_node->getInventory()->getItem(inventoryIndex);
+ if (item)
+ item->setEquipped(true);
+ }
+
+ private:
+ int mEquipment[EQUIPMENT_SIZE];
+};
+
class InventoryHandler : public MessageHandler, public Net::InventoryHandler
{
public:
@@ -58,6 +103,9 @@ class InventoryHandler : public MessageHandler, public Net::InventoryHandler
StorageType destination);
size_t getSize(StorageType type) const;
+
+ private:
+ EquipBackend mEquips;
};
} // namespace EAthena
diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp
index ba4031ec..9bf727d1 100644
--- a/src/net/manaserv/inventoryhandler.cpp
+++ b/src/net/manaserv/inventoryhandler.cpp
@@ -61,6 +61,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
case GPMSG_INVENTORY_FULL:
player_node->clearInventory();
+ player_node->mEquipment->setBackend(&mEqiups);
// no break!
case GPMSG_INVENTORY:
@@ -76,7 +77,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
int id = msg.readInt16();
if (slot < EQUIPMENT_SIZE)
{
- player_node->mEquipment->setEquipment(slot, id);
+ mEqiups.setEquipment(slot, id);
}
else if (slot >= 32 && slot < 32 + getSize(INVENTORY))
{
@@ -104,7 +105,7 @@ void InventoryHandler::unequipItem(const Item *item)
// Tidy equipment directly to avoid weapon still shown bug, for instance
int equipSlot = item->getInvIndex();
logger->log("Unequipping %d", equipSlot);
- player_node->mEquipment->setEquipment(equipSlot, 0);
+ mEqiups.setEquipment(equipSlot, 0);
}
void InventoryHandler::useItem(const Item *item)
diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h
index d3feca0a..fd28738c 100644
--- a/src/net/manaserv/inventoryhandler.h
+++ b/src/net/manaserv/inventoryhandler.h
@@ -26,8 +26,46 @@
#include "net/manaserv/messagehandler.h"
+#include "equipment.h"
+
namespace ManaServ {
+class EquipBackend : public Equipment::Backend {
+ public:
+ EquipBackend()
+ { memset(mEquipment, 0, sizeof(mEquipment)); }
+
+ Item *getEquipment(int index) const
+ { return mEquipment[index]; }
+
+ void clear()
+ {
+ for (int i = 0; i < EQUIPMENT_SIZE; ++i)
+ delete mEquipment[i];
+
+ std::fill_n(mEquipment, EQUIPMENT_SIZE, (Item*) 0);
+ }
+
+ void setEquipment(int index, int id, int quantity = 0)
+ {
+ if (mEquipment[index] && mEquipment[index]->getId() == id)
+ return;
+
+ delete mEquipment[index];
+ mEquipment[index] = (id > 0) ? new Item(id, quantity) : 0;
+
+ if (mEquipment[index])
+ {
+ mEquipment[index]->setInvIndex(index);
+ mEquipment[index]->setEquipped(true);
+ mEquipment[index]->setInEquipment(true);
+ }
+ }
+
+ private:
+ Item *mEquipment[EQUIPMENT_SIZE];
+};
+
class InventoryHandler : public MessageHandler, Net::InventoryHandler
{
public:
@@ -57,6 +95,9 @@ class InventoryHandler : public MessageHandler, Net::InventoryHandler
StorageType destination);
size_t getSize(StorageType type) const;
+
+ private:
+ EquipBackend mEqiups;
};
} // namespace ManaServ