summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/equipment.cpp32
-rw-r--r--src/equipment.h56
-rw-r--r--src/game.cpp3
-rw-r--r--src/gui/equipmentwindow.cpp63
-rw-r--r--src/gui/equipmentwindow.h47
-rw-r--r--src/gui/outfitwindow.cpp6
-rw-r--r--src/item.cpp2
-rw-r--r--src/net/ea/equipmenthandler.cpp179
-rw-r--r--src/net/ea/equipmenthandler.h5
-rw-r--r--src/net/ea/inventoryhandler.cpp7
10 files changed, 142 insertions, 258 deletions
diff --git a/src/equipment.cpp b/src/equipment.cpp
index f760067c..1b17d66d 100644
--- a/src/equipment.cpp
+++ b/src/equipment.cpp
@@ -29,19 +29,10 @@
#include <algorithm>
Equipment::Equipment()
-#ifdef EATHENA_SUPPORT
- : mArrows(-1)
-#endif
{
-#ifdef TMWSERV_SUPPORT
std::fill_n(mEquipment, EQUIPMENT_SIZE, (Item*) 0);
-#else
- std::fill_n(mEquipment, EQUIPMENT_SIZE, -1);
-#endif
}
-#ifdef TMWSERV_SUPPORT
-
Equipment::~Equipment()
{
clear();
@@ -55,29 +46,14 @@ void Equipment::clear()
std::fill_n(mEquipment, EQUIPMENT_SIZE, (Item*) 0);
}
-void Equipment::setEquipment(int index, int id)
+void Equipment::setEquipment(int index, int id, int quantity)
{
if (mEquipment[index] && mEquipment[index]->getId() == id)
return;
delete mEquipment[index];
- mEquipment[index] = (id > 0) ? new Item(id) : 0;
-}
-
-#else
+ mEquipment[index] = (id > 0) ? new Item(id, quantity) : 0;
-void Equipment::setEquipment(int index, int inventoryIndex)
-{
- mEquipment[index] = inventoryIndex;
- Item *item = player_node->getInventory()->getItem(inventoryIndex);
- if (item)
- item->setEquipped(true);
-}
-
-void Equipment::removeEquipment(int index)
-{
- if (index >= 0 && index < EQUIPMENT_SIZE)
- mEquipment[index] = -1;
+ if (mEquipment[index])
+ mEquipment[index]->setInvIndex(index);
}
-
-#endif
diff --git a/src/equipment.h b/src/equipment.h
index 5bebf78d..c7058269 100644
--- a/src/equipment.h
+++ b/src/equipment.h
@@ -22,11 +22,7 @@
#ifndef EQUIPMENT_H
#define EQUIPMENT_H
-#ifdef TMWSERV_SUPPORT
#define EQUIPMENT_SIZE 11
-#else
-#define EQUIPMENT_SIZE 10
-#endif
class Item;
@@ -38,63 +34,45 @@ class Equipment
*/
Equipment();
-#ifdef TMWSERV_SUPPORT
/**
* Destructor.
*/
~Equipment();
-#endif
+
+ enum EquipmentSlots
+ {
+ EQUIP_TORSO_SLOT = 0,
+ EQUIP_GLOVES_SLOT = 1,
+ EQUIP_HEAD_SLOT = 2,
+ EQUIP_LEGS_SLOT = 3,
+ EQUIP_FEET_SLOT = 4,
+ EQUIP_RING1_SLOT = 5,
+ EQUIP_RING2_SLOT = 6,
+ EQUIP_NECK_SLOT = 7,
+ EQUIP_FIGHT1_SLOT = 8,
+ EQUIP_FIGHT2_SLOT = 9,
+ EQUIP_PROJECTILE_SLOT = 10,
+ EQUIP_VECTOREND
+ };
/**
* Get equipment at the given slot.
*/
-#ifdef TMWSERV_SUPPORT
Item *getEquipment(int index)
-#else
- int getEquipment(int index) const
-#endif
{ return mEquipment[index]; }
-#ifdef TMWSERV_SUPPORT
/**
* Clears equipment.
*/
void clear();
-#endif
/**
* Set equipment at the given slot.
*/
-#ifdef TMWSERV_SUPPORT
- void setEquipment(int index, int id);
-#else
- void setEquipment(int index, int inventoryIndex);
-#endif
-
-#ifdef EATHENA_SUPPORT
- /**
- * Remove equipment from the given slot.
- */
- void removeEquipment(int index);
-
- /**
- * Returns the item used in the arrow slot.
- */
- int getArrows() const { return mArrows; }
-
- /**
- * Set the item used in the arrow slot.
- */
- void setArrows(int arrows) { mArrows = arrows; }
-#endif
+ void setEquipment(int index, int id, int quantity = 0);
private:
-#ifdef TMWSERV_SUPPORT
Item *mEquipment[EQUIPMENT_SIZE];
-#else
- int mEquipment[EQUIPMENT_SIZE];
- int mArrows;
-#endif
};
#endif
diff --git a/src/game.cpp b/src/game.cpp
index c7a1d4e7..e712bbb8 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -214,13 +214,12 @@ static void createGuiWindows()
partyWindow = new PartyWindow;
#ifdef TMWSERV_SUPPORT
magicDialog = new MagicDialog;
- equipmentWindow = new EquipmentWindow(player_node->mEquipment.get());
buddyWindow = new BuddyWindow;
guildWindow = new GuildWindow;
#else
buySellDialog = new BuySellDialog;
- equipmentWindow = new EquipmentWindow;
#endif
+ equipmentWindow = new EquipmentWindow(player_node->mEquipment.get());
npcDialog = new NpcDialog;
npcPostDialog = new NpcPostDialog;
storageWindow = new StorageWindow;
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 44006971..d6493ca2 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -50,28 +50,22 @@ static const int BOX_HEIGHT = 36;
// Positions of the boxes, 2nd dimension is X and Y respectively.
static const int boxPosition[][2] = {
- { 50, 208 }, // EQUIP_LEGS_SLOT
- { 8, 123 }, // EQUIP_FIGHT1_SLOT
+ { 90, 40 }, // EQUIP_TORSO_SLOT
{ 8, 78 }, // EQUIP_GLOVES_SLOT
- { 129, 168 }, // EQUIP_RING2_SLOT
+ { 70, 0 }, // EQUIP_HEAD_SLOT
+ { 50, 208 }, // EQUIP_LEGS_SLOT
+ { 90, 208 }, // EQUIP_FEET_SLOT
{ 8, 168 }, // EQUIP_RING1_SLOT
+ { 129, 168 }, // EQUIP_RING2_SLOT
+ { 50, 40 }, // EQUIP_NECK_SLOT
+ { 8, 123 }, // EQUIP_FIGHT1_SLOT
{ 129, 123 }, // EQUIP_FIGHT2_SLOT
- { 90, 208 }, // EQUIP_FEET_SLOT
- { 50, 40 }, // EQUIP_CAPE_SLOT
- { 70, 0 }, // EQUIP_HEAD_SLOT
- { 90, 40 }, // EQUIP_TORSO_SLOT
- { 129, 78 } // EQUIP_AMMO_SLOT
+ { 129, 78 } // EQUIP_PROJECTILE_SLOT
};
-#ifdef TMWSERV_SUPPORT
EquipmentWindow::EquipmentWindow(Equipment *equipment):
-#else
-EquipmentWindow::EquipmentWindow():
-#endif
Window(_("Equipment")),
-#ifdef TMWSERV_SUPPORT
mEquipment(equipment),
-#endif
mSelected(-1)
{
mItemPopup = new ItemPopup;
@@ -96,16 +90,11 @@ EquipmentWindow::EquipmentWindow():
add(playerBox);
add(mUnequip);
- for (int i = 0; i < EQUIP_VECTOREND; i++)
+ for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
{
mEquipBox[i].posX = boxPosition[i][0] + getPadding();
mEquipBox[i].posY = boxPosition[i][1] + getTitleBarHeight();
}
-
-#ifdef EATHENA_SUPPORT
- mEquipment = player_node->mEquipment.get();
- mInventory = player_node->getInventory();
-#endif
}
EquipmentWindow::~EquipmentWindow()
@@ -122,7 +111,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
Window::drawChildren(graphics);
- for (int i = 0; i < EQUIP_VECTOREND; i++)
+ for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
{
if (i == mSelected)
{
@@ -140,13 +129,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY,
BOX_WIDTH, BOX_HEIGHT));
-#ifdef TMWSERV_SUPPORT
Item *item = mEquipment->getEquipment(i);
-#else
- Item *item = (i != EQUIP_AMMO_SLOT) ?
- mInventory->getItem(mEquipment->getEquipment(i)) :
- mInventory->getItem(mEquipment->getArrows());
-#endif
if (item)
{
// Draw Item.
@@ -154,8 +137,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
g->drawImage(image,
mEquipBox[i].posX + 2,
mEquipBox[i].posY + 2);
-#ifdef EATHENA_SUPPORT
- if (i == EQUIP_AMMO_SLOT)
+ if (i == EQUIP_PROJECTILE_SLOT)
{
g->setColor(guiPalette->getColor(Palette::TEXT));
graphics->drawText(toString(item->getQuantity()),
@@ -163,7 +145,6 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
mEquipBox[i].posY - getFont()->getHeight(),
gcn::Graphics::CENTER);
}
-#endif
}
}
}
@@ -172,13 +153,7 @@ void EquipmentWindow::action(const gcn::ActionEvent &event)
{
if (event.getId() == "unequip" && mSelected > -1)
{
-#ifdef TMWSERV_SUPPORT // TODO: merge these!
Item *item = mEquipment->getEquipment(mSelected);
-#else
- Item *item = (mSelected != EQUIP_AMMO_SLOT) ?
- mInventory->getItem(mEquipment->getEquipment(mSelected)) :
- mInventory->getItem(mEquipment->getArrows());
-#endif
Net::getInventoryHandler()->unequipItem(item);
setSelected(-1);
}
@@ -186,20 +161,14 @@ void EquipmentWindow::action(const gcn::ActionEvent &event)
Item *EquipmentWindow::getItem(int x, int y) const
{
- for (int i = 0; i < EQUIP_VECTOREND; i++)
+ for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
{
gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
BOX_WIDTH, BOX_HEIGHT);
if (tRect.isPointInRect(x, y))
{
-#ifdef TMWSERV_SUPPORT
return mEquipment->getEquipment(i);
-#else
- return (i != EQUIP_AMMO_SLOT) ?
- mInventory->getItem(mEquipment->getEquipment(i)) :
- mInventory->getItem(mEquipment->getArrows());
-#endif
}
}
return NULL;
@@ -215,15 +184,9 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
{
// Checks if any of the presses were in the equip boxes.
- for (int i = 0; i < EQUIP_VECTOREND; i++)
+ for (int i = 0; i < Equipment::EQUIP_VECTOREND; i++)
{
-#ifdef TMWSERV_SUPPORT
Item *item = mEquipment->getEquipment(i);
-#else
- Item *item = (i != EQUIP_AMMO_SLOT) ?
- mInventory->getItem(mEquipment->getEquipment(i)) :
- mInventory->getItem(mEquipment->getArrows());
-#endif
gcn::Rectangle tRect(mEquipBox[i].posX, mEquipBox[i].posY,
BOX_WIDTH, BOX_HEIGHT);
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index 8bc350a4..a7b2c0d1 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -24,11 +24,11 @@
#include "gui/widgets/window.h"
+#include "equipment.h"
#include "guichanfwd.h"
#include <guichan/actionlistener.hpp>
-class Equipment;
class Inventory;
class Item;
class ItemPopup;
@@ -44,11 +44,7 @@ class EquipmentWindow : public Window, public gcn::ActionListener
/**
* Constructor.
*/
-#ifdef TMWSERV_SUPPORT
EquipmentWindow(Equipment *equipment);
-#else
- EquipmentWindow();
-#endif
/**
* Destructor.
@@ -64,40 +60,6 @@ class EquipmentWindow : public Window, public gcn::ActionListener
void mousePressed(gcn::MouseEvent& mouseEvent);
-#ifdef TMWSERV_SUPPORT
- enum EquipmentSlots
- {
- EQUIP_TORSO_SLOT = 0,
- EQUIP_ARMS_SLOT = 1,
- EQUIP_HEAD_SLOT = 2,
- EQUIP_LEGS_SLOT = 3,
- EQUIP_FEET_SLOT = 4,
- EQUIP_RING1_SLOT = 5,
- EQUIP_RING2_SLOT = 6,
- EQUIP_NECKLACE_SLOT = 7,
- EQUIP_FIGHT1_SLOT = 8,
- EQUIP_FIGHT2_SLOT = 9,
- EQUIP_PROJECTILE_SLOT = 10,
- EQUIP_VECTOREND
- };
-#else
- enum EquipmentSlots
- {
- EQUIP_LEGS_SLOT = 0,
- EQUIP_FIGHT1_SLOT,
- EQUIP_GLOVES_SLOT,
- EQUIP_RING2_SLOT,
- EQUIP_RING1_SLOT,
- EQUIP_FIGHT2_SLOT,
- EQUIP_FEET_SLOT,
- EQUIP_CAPE_SLOT,
- EQUIP_HEAD_SLOT,
- EQUIP_TORSO_SLOT,
- EQUIP_AMMO_SLOT,
- EQUIP_VECTOREND
- };
-#endif
-
private:
void mouseExited(gcn::MouseEvent &event);
void mouseMoved(gcn::MouseEvent &event);
@@ -107,9 +69,6 @@ class EquipmentWindow : public Window, public gcn::ActionListener
void setSelected(int index);
Equipment *mEquipment;
-#ifdef EATHENA_SUPPORT
- Inventory *mInventory;
-#endif
/**
* Equipment box.
@@ -120,12 +79,12 @@ class EquipmentWindow : public Window, public gcn::ActionListener
int posY;
};
- EquipBox mEquipBox[EQUIP_VECTOREND]; /**< Equipment Boxes. */
+ EquipBox mEquipBox[Equipment::EQUIP_VECTOREND]; /**< Equipment Boxes. */
ItemPopup *mItemPopup;
gcn::Button *mUnequip;
- int mSelected; /**< Index of selected item. */
+ int mSelected; /**< Index of selected item. */
};
extern EquipmentWindow *equipmentWindow;
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index f43e1440..58bb1348 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -153,14 +153,8 @@ void OutfitWindow::wearOutfit(int outfit)
//non vis is 3,4,7
if (i != 3 && i != 4 && i != 7)
{
-#ifdef TMWSERV_SUPPORT
if (!(item = player_node->mEquipment.get()->getEquipment(i)))
continue;
-#else
- if (!(item = player_node->getInventory()->getItem(
- player_node->mEquipment.get()->getEquipment(i))))
- continue;
-#endif
Net::getInventoryHandler()->unequipItem(item);
}
}
diff --git a/src/item.cpp b/src/item.cpp
index 2fadc035..312a7f63 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -43,10 +43,8 @@ void Item::setId(int id)
{
mId = id;
-#ifdef TMWSERV_SUPPORT
// Types 0 and 1 are not equippable items.
mEquipment = id && getInfo().getType() >= 2;
-#endif
// Load the associated image
if (mImage)
diff --git a/src/net/ea/equipmenthandler.cpp b/src/net/ea/equipmenthandler.cpp
index 0153b5da..0b6c5753 100644
--- a/src/net/ea/equipmenthandler.cpp
+++ b/src/net/ea/equipmenthandler.cpp
@@ -35,10 +35,98 @@
#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);
+ }
+ }
+}
+
+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[] = {
@@ -50,6 +138,7 @@ EquipmentHandler::EquipmentHandler()
0
};
handledMessages = _messages;
+ memset(equips, 0, sizeof(equips));
}
void EquipmentHandler::handleMessage(MessageIn &msg)
@@ -57,8 +146,6 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
int itemCount;
int index, equipPoint, itemId;
int type;
- int mask, position;
- Item *item;
Inventory *inventory = player_node->getInventory();
switch (msg.getId())
@@ -79,25 +166,9 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
msg.readInt8(); // refine
msg.skip(8); // card
- if (debugEquipment)
- {
- logger->log("Index: %d, ID: %d", index, itemId);
- }
-
inventory->setItem(index, itemId, 1, true);
- if (equipPoint)
- {
- mask = 1;
- position = 0;
- while (!(equipPoint & mask))
- {
- mask <<= 1;
- position++;
- }
- item = inventory->getItem(index);
- player_node->mEquipment->setEquipment(position, index);
- }
+ setEquipment(equipPoint, index, true);
}
break;
@@ -112,35 +183,7 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
break;
}
- // No point in searching when no point given
- if (!equipPoint)
- break;
-
- /*
- * An item may occupy more than 1 slot. If so, it's
- * only shown as equipped on the *first* slot.
- */
- mask = 1;
- position = 0;
- while (!(equipPoint & mask)) {
- mask <<= 1;
- position++;
- }
-
- if (debugEquipment)
- {
- logger->log("Equipping: %i %i %i at position %i",
- index, equipPoint, type, position);
- }
-
- item = inventory->getItem(player_node->mEquipment->getEquipment(position));
-
- // Unequip any existing equipped item in this position
- if (item)
- item->setEquipped(false);
-
- item = inventory->getItem(index);
- player_node->mEquipment->setEquipment(position, index);
+ setEquipment(equipPoint, index, true);
break;
case SMSG_PLAYER_UNEQUIP:
@@ -153,36 +196,7 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
break;
}
- if (!equipPoint) {
- // No point given, no point in searching
- break;
- }
-
- mask = 1;
- position = 0;
- while (!(equipPoint & mask)) {
- mask <<= 1;
- position++;
- }
-
- item = inventory->getItem(index);
- if (!item)
- break;
-
- item->setEquipped(false);
-
- if (equipPoint & 0x8000) { // Arrows
- player_node->mEquipment->setArrows(-1);
- }
- else {
- player_node->mEquipment->removeEquipment(position);
- }
-
- if (debugEquipment)
- {
- logger->log("Unequipping: %i %i(%i) %i",
- index, equipPoint, type, position);
- }
+ setEquipment(equipPoint, index, false);
break;
case SMSG_PLAYER_ATTACK_RANGE:
@@ -197,13 +211,8 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
index -= INVENTORY_OFFSET;
- item = inventory->getItem(index);
-
- if (item) {
- item->setEquipped(true);
- player_node->mEquipment->setArrows(index);
- logger->log("Arrows equipped: %i", index);
- }
+ logger->log("Arrows equipped: %i", index);
+ setEquipment(0x8000, index, true);
break;
}
}
diff --git a/src/net/ea/equipmenthandler.h b/src/net/ea/equipmenthandler.h
index 852be3c9..5239c486 100644
--- a/src/net/ea/equipmenthandler.h
+++ b/src/net/ea/equipmenthandler.h
@@ -24,8 +24,13 @@
#include "net/messagehandler.h"
+class Item;
+
namespace EAthena {
+void setEquipment(int eAthenaSlot, int index, bool equiped);
+Item *getRealEquipedItem(const Item *equipped);
+
class EquipmentHandler : public MessageHandler
{
public:
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index ebea1883..112d8371 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -21,6 +21,7 @@
#include "net/ea/inventoryhandler.h"
+#include "net/ea/equipmenthandler.h"
#include "net/ea/protocol.h"
#include "net/messagein.h"
@@ -302,11 +303,13 @@ void InventoryHandler::equipItem(const Item *item)
void InventoryHandler::unequipItem(const Item *item)
{
- if (!item)
+ const Item *real_item = item->isEquipped() ? item : getRealEquipedItem(item);
+
+ if (!real_item)
return;
MessageOut outMsg(CMSG_PLAYER_UNEQUIP);
- outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+ outMsg.writeInt16(real_item->getInvIndex() + INVENTORY_OFFSET);
}
void InventoryHandler::useItem(const Item *item)