summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-04-01 11:09:41 -0600
committerJared Adams <jaxad0127@gmail.com>2009-04-01 11:09:41 -0600
commit2a11fd111231a7e40c560e0240578a2b4a2126c2 (patch)
treee6024c5e40fc96ad4ec85b8e4136a4982a35eb02 /src
parent33048e36c1fdc642459b0101ad0ab9c63807a3e7 (diff)
downloadmana-2a11fd111231a7e40c560e0240578a2b4a2126c2.tar.gz
mana-2a11fd111231a7e40c560e0240578a2b4a2126c2.tar.bz2
mana-2a11fd111231a7e40c560e0240578a2b4a2126c2.tar.xz
mana-2a11fd111231a7e40c560e0240578a2b4a2126c2.zip
Make eAthena's inventory handler
Also cleanup some related #ifdefs in LocalPlayer.
Diffstat (limited to 'src')
-rw-r--r--src/gui/inventorywindow.cpp10
-rw-r--r--src/gui/popupmenu.cpp4
-rw-r--r--src/gui/storagewindow.cpp27
-rw-r--r--src/gui/storagewindow.h4
-rw-r--r--src/itemshortcut.cpp4
-rw-r--r--src/localplayer.cpp40
-rw-r--r--src/localplayer.h4
-rw-r--r--src/net/ea/inventoryhandler.cpp63
-rw-r--r--src/net/ea/inventoryhandler.h18
-rw-r--r--src/net/inventoryhandler.h6
10 files changed, 118 insertions, 62 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 51c1372c..0b130581 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -164,24 +164,18 @@ void InventoryWindow::action(const gcn::ActionEvent &event)
if (event.getId() == "use")
{
-#ifdef TMWSERV_SUPPORT
if (item->isEquipment()) {
+#ifdef TMWSERV_SUPPORT
player_node->equipItem(item);
- }
- else {
- player_node->useItem(item->getInvIndex());
- }
#else
- if (item->isEquipment())
- {
if (item->isEquipped())
player_node->unequipItem(item);
else
player_node->equipItem(item);
+#endif
}
else
player_node->useItem(item);
-#endif
}
else if (event.getId() == "drop")
{
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index d0281c1f..41e266a5 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -268,11 +268,7 @@ void PopupMenu::handleLink(const std::string &link)
}
else
{
-#ifdef TMWSERV_SUPPORT
- player_node->useItem(mItem->getInvIndex());
-#else
player_node->useItem(mItem);
-#endif
}
}
diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp
index 8c25401d..59b6de7a 100644
--- a/src/gui/storagewindow.cpp
+++ b/src/gui/storagewindow.cpp
@@ -41,10 +41,8 @@
#include "../localplayer.h"
#include "../units.h"
-#include "../net/messageout.h"
-#ifdef EATHENA_SUPPORT
-#include "../net/ea/protocol.h"
-#endif
+#include "../net/net.h"
+#include "../net/ea/inventoryhandler.h"
#include "../resources/iteminfo.h"
@@ -187,21 +185,24 @@ Item* StorageWindow::getSelectedItem() const
return mItems->getSelectedItem();
}
-void StorageWindow::addStore(Item *item, int ammount)
+void StorageWindow::addStore(Item *item, int amount)
{
- MessageOut outMsg(CMSG_MOVE_TO_STORAGE);
- outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
- outMsg.writeInt32(ammount);
+ // Net::getInvyHandler()->moveItem(Net::InvyHandler::INVENTORY,
+ invyHandler->moveItem(Net::InvyHandler::INVENTORY,
+ item->getInvIndex(), amount,
+ Net::InvyHandler::STORAGE);
}
-void StorageWindow::removeStore(Item *item, int ammount)
+void StorageWindow::removeStore(Item *item, int amount)
{
- MessageOut outMsg(CSMG_MOVE_FROM_STORAGE);
- outMsg.writeInt16(item->getInvIndex() + STORAGE_OFFSET);
- outMsg.writeInt32(ammount);
+ // Net::getInvyHandler()->moveItem(Net::InvyHandler::STORAGE,
+ invyHandler->moveItem(Net::InvyHandler::STORAGE,
+ item->getInvIndex(), amount,
+ Net::InvyHandler::INVENTORY);
}
void StorageWindow::close()
{
- MessageOut outMsg(CMSG_CLOSE_STORAGE);
+ // Net::getInvyHandler()->closeStorage();
+ invyHandler->closeStorage();
}
diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h
index de0937b5..a4db14bf 100644
--- a/src/gui/storagewindow.h
+++ b/src/gui/storagewindow.h
@@ -73,12 +73,12 @@ class StorageWindow : public Window, gcn::ActionListener,
/**
* Add the specified ammount of the specified item to storage
*/
- void addStore(Item* item, int ammount);
+ void addStore(Item* item, int amount);
/**
* Remove the specified ammount of the specified item from storage
*/
- void removeStore(Item* item, int ammount);
+ void removeStore(Item* item, int amount);
/**
* Closes the Storage Window, as well as telling the server that the
diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp
index 2dea8c56..bd247300 100644
--- a/src/itemshortcut.cpp
+++ b/src/itemshortcut.cpp
@@ -81,11 +81,7 @@ void ItemShortcut::useItem(int index)
}
else
{
-#ifdef TMWSERV_SUPPORT
- player_node->useItem(item->getInvIndex());
-#else
player_node->useItem(item);
-#endif
}
}
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index f4ba142c..19e59f9e 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -52,10 +52,9 @@
#include "net/tmwserv/chatserver/guild.h"
#include "net/tmwserv/chatserver/party.h"
#else
-#include "net/messageout.h"
+#include "net/ea/inventoryhandler.h"
#include "net/ea/partyhandler.h"
#include "net/ea/playerhandler.h"
-#include "net/ea/protocol.h"
#include "net/ea/skillhandler.h"
#include "net/ea/tradehandler.h"
#endif
@@ -413,12 +412,11 @@ void LocalPlayer::moveInvItem(Item *item, int newIndex)
void LocalPlayer::equipItem(Item *item)
{
+ // Net::getInvyHandler()->equipItem(item);
#ifdef TMWSERV_SUPPORT
Net::GameServer::Player::equip(item->getInvIndex());
#else
- MessageOut outMsg(CMSG_PLAYER_EQUIP);
- outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
- outMsg.writeInt16(0);
+ invyHandler->equipItem(item);
#endif
}
@@ -432,20 +430,16 @@ void LocalPlayer::unequipItem(int slot)
mEquipment->setEquipment(slot, 0);
}
-void LocalPlayer::useItem(int slot)
-{
- Net::GameServer::Player::useItem(slot);
-}
-
#else
void LocalPlayer::unequipItem(Item *item)
{
- if (!item)
- return;
-
- MessageOut outMsg(CMSG_PLAYER_UNEQUIP);
- outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+ // Net::getInvyHandler()->unequipItem(item);
+#ifdef TMWSERV_SUPPORT
+ Net::GameServer::Player::unequip(item->getInvIndex());
+#else
+ invyHandler->unequipItem(item);
+#endif
// Tidy equipment directly to avoid weapon still shown bug, for instance
mEquipment->removeEquipment(item->getInvIndex());
@@ -453,23 +447,23 @@ void LocalPlayer::unequipItem(Item *item)
void LocalPlayer::useItem(Item *item)
{
- MessageOut outMsg(CMSG_PLAYER_INVENTORY_USE);
- outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
- outMsg.writeInt32(item->getId());
- // Note: id isn't used, but the server wants it
+ // Net::getInvyHandler()->useItem(item);
+#ifdef TMWSERV_SUPPORT
+ Net::GameServer::Player::useItem(item->getInvIndex());
+#else
+ invyHandler->useItem(item);
+#endif
}
#endif
void LocalPlayer::dropItem(Item *item, int quantity)
{
+ // Net::getInvyHandler()->dropItem(item, quantity);
#ifdef TMWSERV_SUPPORT
Net::GameServer::Player::drop(item->getInvIndex(), quantity);
#else
- // TODO: Fix wrong coordinates of drops, serverside? (what's wrong here?)
- MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP);
- outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
- outMsg.writeInt16(quantity);
+ invyHandler->dropItem(item, quantity);
#endif
}
diff --git a/src/localplayer.h b/src/localplayer.h
index a049f67f..45174e64 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -216,11 +216,7 @@ class LocalPlayer : public Player
void unequipItem(Item *item);
#endif
-#ifdef TMWSERV_SUPPORT
- void useItem(int slot);
-#else
void useItem(Item *item);
-#endif
void dropItem(Item *item, int quantity);
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index e1429093..79e7d2da 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -24,6 +24,7 @@
#include "net/ea/protocol.h"
#include "net/messagein.h"
+#include "net/messageout.h"
#include "configuration.h"
#include "inventory.h"
@@ -46,6 +47,8 @@
enum { debugInventory = 1 };
+InventoryHandler *invyHandler;
+
InventoryHandler::InventoryHandler()
{
static const Uint16 _messages[] = {
@@ -63,6 +66,7 @@ InventoryHandler::InventoryHandler()
0
};
handledMessages = _messages;
+ invyHandler = this;
}
void InventoryHandler::handleMessage(MessageIn &msg)
@@ -295,3 +299,62 @@ void InventoryHandler::handleMessage(MessageIn &msg)
break;
}
}
+
+void InventoryHandler::equipItem(Item *item)
+{
+ if (!item)
+ return;
+
+ MessageOut outMsg(CMSG_PLAYER_EQUIP);
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+ outMsg.writeInt16(0);
+}
+
+void InventoryHandler::unequipItem(Item *item)
+{
+ if (!item)
+ return;
+
+ MessageOut outMsg(CMSG_PLAYER_UNEQUIP);
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+}
+
+void InventoryHandler::useItem(Item *item)
+{
+ if (!item)
+ return;
+
+ MessageOut outMsg(CMSG_PLAYER_INVENTORY_USE);
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+ outMsg.writeInt32(item->getId()); // unused
+}
+
+void InventoryHandler::dropItem(Item *item, int amount)
+{
+ // TODO: Fix wrong coordinates of drops, serverside? (what's wrong here?)
+ MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP);
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
+ outMsg.writeInt16(amount);
+}
+
+void InventoryHandler::closeStorage()
+{
+ MessageOut outMsg(CMSG_CLOSE_STORAGE);
+}
+
+void InventoryHandler::moveItem(StorageType source, int slot, int amount,
+ StorageType destination)
+{
+ if (source == INVENTORY && destination == STORAGE)
+ {
+ MessageOut outMsg(CMSG_MOVE_TO_STORAGE);
+ outMsg.writeInt16(slot + INVENTORY_OFFSET);
+ outMsg.writeInt32(amount);
+ }
+ else if (source == STORAGE && destination == INVENTORY)
+ {
+ MessageOut outMsg(CSMG_MOVE_FROM_STORAGE);
+ outMsg.writeInt16(slot + STORAGE_OFFSET);
+ outMsg.writeInt32(amount);
+ }
+}
diff --git a/src/net/ea/inventoryhandler.h b/src/net/ea/inventoryhandler.h
index a35021f5..def4285f 100644
--- a/src/net/ea/inventoryhandler.h
+++ b/src/net/ea/inventoryhandler.h
@@ -23,13 +23,29 @@
#define NET_EA_INVENTORYHANDLER_H
#include "net/messagehandler.h"
+#include "net/net.h"
-class InventoryHandler : public MessageHandler
+class InventoryHandler : public MessageHandler, public Net::InvyHandler
{
public:
InventoryHandler();
virtual void handleMessage(MessageIn &msg);
+
+ virtual void equipItem(Item *item);
+
+ virtual void unequipItem(Item *item);
+
+ virtual void useItem(Item *item);
+
+ virtual void dropItem(Item *item, int amount);
+
+ virtual void closeStorage();
+
+ virtual void moveItem(StorageType source, int slot, int amount,
+ StorageType destination);
};
+extern InventoryHandler *invyHandler;
+
#endif // NET_EA_INVENTORYHANDLER_H
diff --git a/src/net/inventoryhandler.h b/src/net/inventoryhandler.h
index ebd35489..cbd1b6c5 100644
--- a/src/net/inventoryhandler.h
+++ b/src/net/inventoryhandler.h
@@ -34,11 +34,11 @@ class InvyHandler
virtual void unequipItem(Item *item) {}
- virtual void useItem(int slot, Item *item) {}
+ virtual void useItem(Item *item) {}
- virtual void dropItem(int slot, int amount) {}
+ virtual void dropItem(Item *item, int amount) {}
- virtual void splitItem(int slot, int amount) {}
+ virtual void splitItem(Item *item, int amount) {}
virtual void openStorage() {}