summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/equipment.cpp8
-rw-r--r--src/equipment.h4
-rw-r--r--src/gui/storagewindow.cpp8
-rw-r--r--src/gui/trade.cpp11
-rw-r--r--src/inventory.cpp12
-rw-r--r--src/inventory.h13
-rw-r--r--src/localplayer.cpp26
-rw-r--r--src/localplayer.h10
-rw-r--r--src/main.cpp19
-rw-r--r--src/map.cpp4
-rw-r--r--src/net/ea/equipmenthandler.cpp45
-rw-r--r--src/net/ea/inventoryhandler.cpp104
-rw-r--r--src/net/ea/protocol.h3
13 files changed, 154 insertions, 113 deletions
diff --git a/src/equipment.cpp b/src/equipment.cpp
index c8e58b8c..8fc09fa9 100644
--- a/src/equipment.cpp
+++ b/src/equipment.cpp
@@ -36,7 +36,7 @@ Equipment::Equipment()
#ifdef TMWSERV_SUPPORT
std::fill_n(mEquipment, EQUIPMENT_SIZE, (Item*) 0);
#else
- std::fill_n(mEquipment, EQUIPMENT_SIZE, 0);
+ std::fill_n(mEquipment, EQUIPMENT_SIZE, -1);
#endif
}
@@ -74,4 +74,10 @@ void Equipment::setEquipment(int index, int inventoryIndex)
item->setEquipped(true);
}
+void Equipment::removeEquipment(int index)
+{
+ if (index >= 0 && index < EQUIPMENT_SIZE)
+ mEquipment[index] = -1;
+}
+
#endif
diff --git a/src/equipment.h b/src/equipment.h
index 7605175a..63555361 100644
--- a/src/equipment.h
+++ b/src/equipment.h
@@ -75,7 +75,7 @@ class Equipment
/**
* Remove equipment from the given slot.
*/
- void removeEquipment(int index) { if (index >= 0 && index < EQUIPMENT_SIZE) mEquipment[index] = 0; }
+ void removeEquipment(int index);
/**
* Returns the item used in the arrow slot.
@@ -90,7 +90,7 @@ class Equipment
private:
#ifdef TMWSERV_SUPPORT
- Item* mEquipment[EQUIPMENT_SIZE];
+ Item *mEquipment[EQUIPMENT_SIZE];
#else
int mEquipment[EQUIPMENT_SIZE];
int mArrows;
diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp
index 690758ed..8c25401d 100644
--- a/src/gui/storagewindow.cpp
+++ b/src/gui/storagewindow.cpp
@@ -187,17 +187,17 @@ Item* StorageWindow::getSelectedItem() const
return mItems->getSelectedItem();
}
-void StorageWindow::addStore(Item* item, int ammount)
+void StorageWindow::addStore(Item *item, int ammount)
{
MessageOut outMsg(CMSG_MOVE_TO_STORAGE);
- outMsg.writeInt16(item->getInvIndex());
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
outMsg.writeInt32(ammount);
}
-void StorageWindow::removeStore(Item* item, int ammount)
+void StorageWindow::removeStore(Item *item, int ammount)
{
MessageOut outMsg(CSMG_MOVE_FROM_STORAGE);
- outMsg.writeInt16(item->getInvIndex());
+ outMsg.writeInt16(item->getInvIndex() + STORAGE_OFFSET);
outMsg.writeInt32(ammount);
}
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 6926eb82..e6df9ad8 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -53,13 +53,10 @@
TradeWindow::TradeWindow():
Window(_("Trade: You")),
-#ifdef EATHENA_SUPPORT
- mMyInventory(new Inventory(INVENTORY_SIZE, 2)),
- mPartnerInventory(new Inventory(INVENTORY_SIZE, 2))
-#else
mMyInventory(new Inventory(INVENTORY_SIZE)),
- mPartnerInventory(new Inventory(INVENTORY_SIZE)),
- mStatus(PREPARING)
+ mPartnerInventory(new Inventory(INVENTORY_SIZE))
+#ifdef TMWSERV_SUPPORT
+ , mStatus(PREPARING)
#endif
{
setWindowName("Trade");
@@ -248,7 +245,7 @@ void TradeWindow::tradeItem(Item *item, int quantity)
// for that version only.
//addItem(item->getId(), true, quantity, item->isEquipment());
MessageOut outMsg(CMSG_TRADE_ITEM_ADD_REQUEST);
- outMsg.writeInt16(item->getInvIndex());
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
outMsg.writeInt32(quantity);
#endif
}
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 59f51e39..532d9ab6 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -37,9 +37,8 @@ struct SlotUsed : public std::unary_function<Item*, bool>
}
};
-Inventory::Inventory(int size, int offset):
- mSize(size),
- mOffset(offset)
+Inventory::Inventory(int size):
+ mSize(size)
{
mItems = new Item*[mSize];
std::fill_n(mItems, mSize, (Item*) 0);
@@ -135,7 +134,7 @@ bool Inventory::contains(Item *item) const
int Inventory::getFreeSlot() const
{
- Item **i = std::find_if(mItems + mOffset, mItems + mSize,
+ Item **i = std::find_if(mItems, mItems + mSize,
std::not1(SlotUsed()));
return (i == mItems + mSize) ? -1 : (i - mItems);
}
@@ -153,8 +152,3 @@ int Inventory::getLastUsedSlot() const
return -1;
}
-
-int Inventory::getInventorySize() const
-{
- return mSize - mOffset;
-}
diff --git a/src/inventory.h b/src/inventory.h
index 008b7ec4..07a9276e 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _INVENTORY_H
-#define _INVENTORY_H
+#ifndef INVENTORY_H
+#define INVENTORY_H
class Item;
@@ -37,7 +37,7 @@ class Inventory
/**
* Constructor.
*/
- Inventory(int size, int offset = 0);
+ Inventory(int size);
/**
* Destructor.
@@ -107,16 +107,11 @@ class Inventory
*/
int getLastUsedSlot() const;
- /**
- * Returns the number of slots available in the inventory.
- */
- int getInventorySize() const;
-
static const int NO_SLOT_INDEX = -1; /**< Slot has no index. */
+
protected:
Item **mItems; /**< The holder of items */
int mSize; /**< The max number of inventory items */
- int mOffset; /**< Offset used by the inventory */
};
#endif
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 68f9e4bc..553e473b 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -18,7 +18,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <cassert>
+
+#include "localplayer.h"
#include "configuration.h"
#include "equipment.h"
@@ -27,7 +28,6 @@
#include "graphics.h"
#include "inventory.h"
#include "item.h"
-#include "localplayer.h"
#include "map.h"
#include "monster.h"
#include "particle.h"
@@ -65,6 +65,8 @@
#include "utils/gettext.h"
#include "utils/stringutils.h"
+#include <cassert>
+
#ifdef TMWSERV_SUPPORT
const short walkingKeyboardDelay = 100;
#endif
@@ -110,13 +112,12 @@ LocalPlayer::LocalPlayer(int id, int job, Map *map):
mLastAction(-1),
mWalkingDir(0),
mDestX(0), mDestY(0),
+ mInventory(new Inventory(INVENTORY_SIZE)),
#ifdef TMWSERV_SUPPORT
mLocalWalkTime(-1),
- mInventory(new Inventory(INVENTORY_SIZE)),
mExpMessageTime(0)
#else
- mInventory(new Inventory(INVENTORY_SIZE, 2)),
- mStorage(new Inventory(STORAGE_SIZE, 1))
+ mStorage(new Inventory(STORAGE_SIZE))
#endif
{
// Variable to keep the local player from doing certain actions before a map
@@ -399,7 +400,7 @@ void LocalPlayer::equipItem(Item *item)
Net::GameServer::Player::equip(item->getInvIndex());
#else
MessageOut outMsg(CMSG_PLAYER_EQUIP);
- outMsg.writeInt16(item->getInvIndex());
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
outMsg.writeInt16(0);
#endif
}
@@ -427,7 +428,7 @@ void LocalPlayer::unequipItem(Item *item)
return;
MessageOut outMsg(CMSG_PLAYER_UNEQUIP);
- outMsg.writeInt16(item->getInvIndex());
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
// Tidy equipment directly to avoid weapon still shown bug, for instance
mEquipment->removeEquipment(item->getInvIndex());
@@ -436,7 +437,7 @@ void LocalPlayer::unequipItem(Item *item)
void LocalPlayer::useItem(Item *item)
{
MessageOut outMsg(CMSG_PLAYER_INVENTORY_USE);
- outMsg.writeInt16(item->getInvIndex());
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
outMsg.writeInt32(item->getId());
// Note: id is dest of item, usually player_node->account_ID ??
}
@@ -450,7 +451,7 @@ void LocalPlayer::dropItem(Item *item, int quantity)
#else
// TODO: Fix wrong coordinates of drops, serverside?
MessageOut outMsg(CMSG_PLAYER_INVENTORY_DROP);
- outMsg.writeInt16(item->getInvIndex());
+ outMsg.writeInt16(item->getInvIndex() + INVENTORY_OFFSET);
outMsg.writeInt16(quantity);
#endif
}
@@ -1194,12 +1195,9 @@ void LocalPlayer::loadTargetCursor(std::string filename, int width, int height,
assert(size > -1);
assert(size < 3);
- ImageSet* currentImageSet;
- SimpleAnimation* currentCursor;
-
ResourceManager *resman = ResourceManager::getInstance();
- currentImageSet = resman->getImageSet(filename, width, height);
+ ImageSet *currentImageSet = resman->getImageSet(filename, width, height);
Animation *anim = new Animation;
for (unsigned int i = 0; i < currentImageSet->size(); ++i)
@@ -1209,7 +1207,7 @@ void LocalPlayer::loadTargetCursor(std::string filename, int width, int height,
(16 - (currentImageSet->getHeight() / 2)));
}
- currentCursor = new SimpleAnimation(anim);
+ SimpleAnimation *currentCursor = new SimpleAnimation(anim);
const int index = outRange ? 1 : 0;
diff --git a/src/localplayer.h b/src/localplayer.h
index bff38796..7e48530e 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -526,14 +526,16 @@ class LocalPlayer : public Player
int mWalkingDir; /**< The direction the player is walking in. */
int mDestX; /**< X coordinate of destination. */
int mDestY; /**< Y coordinate of destination. */
-#ifdef TMWSERV_SUPPORT
- int mLocalWalkTime; /**< Timestamp used to control keyboard walk
- messages flooding */
-#endif
std::vector<int> mStatusEffectIcons;
Inventory *mInventory;
+
+#ifdef TMWSERV_SUPPORT
+ int mLocalWalkTime; /**< Timestamp used to control keyboard walk
+ messages flooding */
+#endif
+
#ifdef EATHENA_SUPPORT
Inventory *mStorage;
#endif
diff --git a/src/main.cpp b/src/main.cpp
index ad3063f6..b10a8c42 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1039,27 +1039,30 @@ int main(int argc, char *argv[])
initXML();
- // load branding information
+ // Load branding information
branding.init("data/branding.xml");
initHomeDir();
+
// Configure logger
logger = new Logger;
logger->setLogFile(homeDir + std::string("/tmw.log"));
- logger->setLogToStandardOut(config.getValue("logToStandardOut", 0));
// Log the tmw version
+ logger->log("The Mana World %s (%s)",
#ifdef PACKAGE_VERSION
-#ifdef TMWSERV_SUPPORT
- logger->log("The Mana World v%s TMWServ", PACKAGE_VERSION);
+ "v" PACKAGE_VERSION,
#else
- logger->log("The Mana World v%s eAthena", PACKAGE_VERSION);
+ "- version not defined",
#endif
+#ifdef TMWSERV_SUPPORT
+ "tmwserv");
#else
- logger->log("The Mana World - version not defined");
+ "eAthena");
#endif
initConfiguration(options);
+ logger->setLogToStandardOut(config.getValue("logToStandardOut", 0));
initEngine(options);
@@ -1077,9 +1080,9 @@ int main(int argc, char *argv[])
gcn::Container *top = static_cast<gcn::Container*>(gui->getTop());
#ifdef PACKAGE_VERSION
#ifdef TMWSERV_SUPPORT
- gcn::Label *versionLabel = new Label(strprintf("%s TMWserv", PACKAGE_VERSION));
+ gcn::Label *versionLabel = new Label(strprintf("%s (tmwserv)", PACKAGE_VERSION));
#else
- gcn::Label *versionLabel = new Label(strprintf("%s eAthena", PACKAGE_VERSION));
+ gcn::Label *versionLabel = new Label(strprintf("%s (eAthena)", PACKAGE_VERSION));
#endif
top->add(versionLabel, 25, 2);
#endif
diff --git a/src/map.cpp b/src/map.cpp
index 8f736424..0dc4759e 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -48,7 +48,9 @@ struct Location
/**
* Constructor.
*/
- Location(int px, int py, MetaTile *ptile):x(px),y(py),tile(ptile) {};
+ Location(int px, int py, MetaTile *ptile):
+ x(px), y(py), tile(ptile)
+ {}
/**
* Comparison operator.
diff --git a/src/net/ea/equipmenthandler.cpp b/src/net/ea/equipmenthandler.cpp
index f81bf7ed..d30b2681 100644
--- a/src/net/ea/equipmenthandler.cpp
+++ b/src/net/ea/equipmenthandler.cpp
@@ -35,6 +35,8 @@
#include "utils/gettext.h"
+enum { debugEquipment = 1 };
+
EquipmentHandler::EquipmentHandler()
{
static const Uint16 _messages[] = {
@@ -65,7 +67,7 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
for (int loop = 0; loop < itemCount; loop++)
{
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
itemId = msg.readInt16();
msg.readInt8(); // type
msg.readInt8(); // identify flag
@@ -75,6 +77,11 @@ 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)
@@ -93,21 +100,19 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
break;
case SMSG_PLAYER_EQUIP:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
equipPoint = msg.readInt16();
type = msg.readInt8();
- logger->log("Equipping: %i %i %i", index, equipPoint, type);
-
- if (!type) {
+ if (!type)
+ {
localChatTab->chatLog(_("Unable to equip."), BY_SERVER);
break;
}
- if (!equipPoint) {
- // No point given, no point in searching
+ // No point in searching when no point given
+ if (!equipPoint)
break;
- }
/*
* An item may occupy more than 1 slot. If so, it's
@@ -119,21 +124,25 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
mask <<= 1;
position++;
}
- logger->log("Position %i", position);
- item = player_node->getInventory()->getItem(player_node->mEquipment->getEquipment(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) {
+ if (item)
item->setEquipped(false);
- }
item = inventory->getItem(index);
player_node->mEquipment->setEquipment(position, index);
break;
case SMSG_PLAYER_UNEQUIP:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
equipPoint = msg.readInt16();
type = msg.readInt8();
@@ -166,8 +175,12 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
else {
player_node->mEquipment->removeEquipment(position);
}
- logger->log("Unequipping: %i %i(%i) %i",
- index, equipPoint, type, position);
+
+ if (debugEquipment)
+ {
+ logger->log("Unequipping: %i %i(%i) %i",
+ index, equipPoint, type, position);
+ }
break;
case SMSG_PLAYER_ATTACK_RANGE:
@@ -180,6 +193,8 @@ void EquipmentHandler::handleMessage(MessageIn &msg)
if (index <= 1)
break;
+ index -= INVENTORY_OFFSET;
+
item = inventory->getItem(index);
if (item) {
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index 5f7e6c6c..e1429093 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -44,6 +44,8 @@
#include <SDL_types.h>
+enum { debugInventory = 1 };
+
InventoryHandler::InventoryHandler()
{
static const Uint16 _messages[] = {
@@ -75,28 +77,26 @@ void InventoryHandler::handleMessage(MessageIn &msg)
{
case SMSG_PLAYER_INVENTORY:
case SMSG_PLAYER_STORAGE_ITEMS:
- switch (msg.getId()) {
- case SMSG_PLAYER_INVENTORY:
- // Clear inventory - this will be a complete refresh
- inventory->clear();
- break;
- case SMSG_PLAYER_STORAGE_ITEMS:
- /*
- * This packet will always be followed by a
- * SMSG_PLAYER_STORAGE_EQUIP packet. The two packets
- * together comprise a complete refresh of storage, so
- * clear storage here
- */
- storage->clear();
- break;
- default:
- logger->log("HOW DID WE GET HERE?");
- return;
+ if (msg.getId() == SMSG_PLAYER_INVENTORY)
+ {
+ // Clear inventory - this will be a complete refresh
+ inventory->clear();
+ }
+ else
+ {
+ /*
+ * This packet will always be followed by a
+ * SMSG_PLAYER_STORAGE_EQUIP packet. The two packets
+ * together comprise a complete refresh of storage, so
+ * clear storage here
+ */
+ storage->clear();
}
msg.readInt16(); // length
number = (msg.getLength() - 4) / 18;
- for (int loop = 0; loop < number; loop++) {
+ for (int loop = 0; loop < number; loop++)
+ {
index = msg.readInt16();
itemId = msg.readInt16();
itemType = msg.readInt8();
@@ -106,6 +106,17 @@ void InventoryHandler::handleMessage(MessageIn &msg)
for (int i = 0; i < 4; i++)
cards[i] = msg.readInt16();
+ index -= (msg.getId() == SMSG_PLAYER_INVENTORY) ?
+ INVENTORY_OFFSET : STORAGE_OFFSET;
+
+ if (debugInventory)
+ {
+ logger->log("Index: %d, ID: %d, Type: %d, Identified: %d, "
+ "Qty: %d, Cards: %d, %d, %d, %d",
+ index, itemId, itemType, identified, amount,
+ cards[0], cards[1], cards[2], cards[3]);
+ }
+
if (msg.getId() == SMSG_PLAYER_INVENTORY) {
inventory->setItem(index, itemId, amount, false);
@@ -115,8 +126,6 @@ void InventoryHandler::handleMessage(MessageIn &msg)
item->setEquipment(true);
}
} else {
- logger->log("Index:%d, ID:%d, Type:%d, Identified:%d, Qty:%d, Cards:%d, %d, %d, %d",
- index, itemId, itemType, identified, amount, cards[0], cards[1], cards[2], cards[3]);
storage->setItem(index, itemId, amount, false);
}
}
@@ -127,7 +136,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
number = (msg.getLength() - 4) / 20;
for (int loop = 0; loop < number; loop++) {
- index = msg.readInt16();
+ index = msg.readInt16() - STORAGE_OFFSET;
itemId = msg.readInt16();
itemType = msg.readInt8();
identified = msg.readInt8();
@@ -139,14 +148,20 @@ void InventoryHandler::handleMessage(MessageIn &msg)
for (int i = 0; i < 4; i++)
cards[i] = msg.readInt16();
- logger->log("Index:%d, ID:%d, Type:%d, Identified:%d, Qty:%d, Cards:%d, %d, %d, %d",
- index, itemId, itemType, identified, amount, cards[0], cards[1], cards[2], cards[3]);
+ if (debugInventory)
+ {
+ logger->log("Index: %d, ID: %d, Type: %d, Identified: %d, "
+ "Qty: %d, Cards: %d, %d, %d, %d",
+ index, itemId, itemType, identified, amount,
+ cards[0], cards[1], cards[2], cards[3]);
+ }
+
storage->setItem(index, itemId, amount, false);
}
break;
case SMSG_PLAYER_INVENTORY_ADD:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
amount = msg.readInt16();
itemId = msg.readInt16();
identified = msg.readInt8();
@@ -157,20 +172,26 @@ void InventoryHandler::handleMessage(MessageIn &msg)
equipType = msg.readInt16();
itemType = msg.readInt8();
- if (msg.readInt8() > 0) {
- if (config.getValue("showpickupchat", true)) {
+ if (msg.readInt8() > 0)
+ {
+ if (config.getValue("showpickupchat", true))
localChatTab->chatLog(_("Unable to pick up item"), BY_SERVER);
- }
- } else {
+ }
+ else
+ {
const ItemInfo &itemInfo = ItemDB::get(itemId);
const std::string amountStr =
(amount > 1) ? toString(amount) : "a";
- if (config.getValue("showpickupchat", true)) {
+
+ if (config.getValue("showpickupchat", true))
+ {
localChatTab->chatLog(strprintf(_("You picked up %s [%s]"),
amountStr.c_str(), itemInfo.getName().c_str()),
BY_SERVER);
}
- if (config.getValue("showpickupparticle", false)) {
+
+ if (config.getValue("showpickupparticle", false))
+ {
player_node->pickedUp(itemInfo.getName());
}
@@ -184,9 +205,10 @@ void InventoryHandler::handleMessage(MessageIn &msg)
break;
case SMSG_PLAYER_INVENTORY_REMOVE:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
amount = msg.readInt16();
- if (Item *item = inventory->getItem(index)) {
+ if (Item *item = inventory->getItem(index))
+ {
item->increaseQuantity(-amount);
if (item->getQuantity() == 0)
inventory->removeItemAt(index);
@@ -194,7 +216,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
break;
case SMSG_PLAYER_INVENTORY_USE:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
msg.readInt16(); // item id
msg.readInt32(); // id
amount = msg.readInt16();
@@ -205,7 +227,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
break;
case SMSG_ITEM_USE_RESPONSE:
- index = msg.readInt16();
+ index = msg.readInt16() - INVENTORY_OFFSET;
amount = msg.readInt16();
if (msg.readInt8() == 0) {
@@ -231,7 +253,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
/*
* Move an item into storage
*/
- index = msg.readInt16();
+ index = msg.readInt16() - STORAGE_OFFSET;
amount = msg.readInt32();
itemId = msg.readInt16();
identified = msg.readInt8();
@@ -240,10 +262,13 @@ void InventoryHandler::handleMessage(MessageIn &msg)
for (int i = 0; i < 4; i++)
cards[i] = msg.readInt16();
- if (Item *item = storage->getItem(index)) {
+ if (Item *item = storage->getItem(index))
+ {
item->setId(itemId);
item->increaseQuantity(amount);
- } else {
+ }
+ else
+ {
storage->setItem(index, itemId, amount, false);
}
break;
@@ -252,9 +277,10 @@ void InventoryHandler::handleMessage(MessageIn &msg)
/*
* Move an item out of storage
*/
- index = msg.readInt16();
+ index = msg.readInt16() - STORAGE_OFFSET;
amount = msg.readInt16();
- if (Item *item = storage->getItem(index)) {
+ if (Item *item = storage->getItem(index))
+ {
item->increaseQuantity(-amount);
if (item->getQuantity() == 0)
storage->removeItemAt(index);
diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h
index c96ff7b6..a70e47b4 100644
--- a/src/net/ea/protocol.h
+++ b/src/net/ea/protocol.h
@@ -22,6 +22,9 @@
#ifndef EA_PROTOCOL_H
#define EA_PROTOCOL_H
+static const int INVENTORY_OFFSET = 2;
+static const int STORAGE_OFFSET = 1;
+
/*********************************
* Packets from server to client *
*********************************/