summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-01-04 22:28:08 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-01-04 22:28:08 +0000
commit90290b7aaf2a55187598e67c31d33f5735f574ce (patch)
tree64826ee1d40e993ab70c9d6f077ded33c747edf0 /src
parent4eec29ac0f6a9b05562ac0fbe3d4e5d7e82deeac (diff)
downloadMana-90290b7aaf2a55187598e67c31d33f5735f574ce.tar.gz
Mana-90290b7aaf2a55187598e67c31d33f5735f574ce.tar.bz2
Mana-90290b7aaf2a55187598e67c31d33f5735f574ce.tar.xz
Mana-90290b7aaf2a55187598e67c31d33f5735f574ce.zip
Client-side hack for picking up items.
Diffstat (limited to 'src')
-rw-r--r--src/gui/itemcontainer.cpp19
-rw-r--r--src/inventory.cpp2
-rw-r--r--src/localplayer.cpp7
-rw-r--r--src/net/gameserver/player.cpp20
-rw-r--r--src/net/gameserver/player.h9
-rw-r--r--src/net/inventoryhandler.cpp22
-rw-r--r--src/net/protocol.h4
7 files changed, 40 insertions, 43 deletions
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 5bcd000d..2c84b19b 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -48,7 +48,7 @@ ItemContainer::ItemContainer(Inventory *inventory):
mSelImg = resman->getImage("graphics/gui/selection.png");
if (!mSelImg) logger->error("Unable to load selection.png");
- mMaxItems = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2
+ mMaxItems = mInventory->getLastUsedSlot() + 1;
addMouseListener(this);
}
@@ -62,7 +62,7 @@ void ItemContainer::logic()
{
gcn::Widget::logic();
- int i = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2
+ int i = mInventory->getLastUsedSlot() + 1;
if (i != mMaxItems) {
mMaxItems = i;
@@ -89,11 +89,7 @@ void ItemContainer::draw(gcn::Graphics* graphics)
selectNone();
}
- /*
- * eAthena seems to start inventory from the 3rd slot. Still a mystery to
- * us why, make sure not to copy this oddity to our own server.
- */
- for (int i = 2; i < INVENTORY_SIZE; i++)
+ for (int i = 0; i < INVENTORY_SIZE; i++)
{
Item *item = mInventory->getItem(i);
@@ -101,8 +97,8 @@ void ItemContainer::draw(gcn::Graphics* graphics)
continue;
}
- int itemX = ((i - 2) % columns) * gridWidth;
- int itemY = ((i - 2) / columns) * gridHeight;
+ int itemX = (i % columns) * gridWidth;
+ int itemY = (i / columns) * gridHeight;
// Draw selection image below selected item
if (mSelectedItem == item)
@@ -141,8 +137,7 @@ void ItemContainer::setWidth(int width)
columns = 1;
}
- setHeight(((mMaxItems / columns) +
- (mMaxItems % columns > 0 ? 1 : 0)) * gridHeight);
+ setHeight((mMaxItems + columns - 1) / columns * gridHeight);
}
Item* ItemContainer::getItem()
@@ -184,7 +179,7 @@ void ItemContainer::mousePress(int mx, int my, int button)
if (button == gcn::MouseInput::LEFT || gcn::MouseInput::RIGHT)
{
- int index = mx / gridWidth + ((my / gridHeight) * columns) + 2;
+ int index = mx / gridWidth + ((my / gridHeight) * columns);
if (index > INVENTORY_SIZE) {
index = INVENTORY_SIZE - 1;
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 0467df10..ac0bce18 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -103,7 +103,7 @@ bool Inventory::contains(Item *item)
int Inventory::getFreeSlot()
{
- Item *i = std::find_if(mItems + 2, mItems + INVENTORY_SIZE,
+ Item *i = std::find_if(mItems, mItems + INVENTORY_SIZE,
std::not1(SlotUsed()));
return (i == mItems + INVENTORY_SIZE) ? -1 : (i - mItems);
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 8076c538..b3e13a2a 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -152,11 +152,8 @@ void LocalPlayer::pickUp(FloorItem *item)
int dy = item->getY() - mY / 32;
if (dx * dx + dy * dy < 4) {
- // XXX Convert for new server
- /*
- MessageOut outMsg(CMSG_ITEM_PICKUP);
- outMsg.writeLong(item->getId());
- */
+ int id = item->getId();
+ Net::GameServer::Player::pickUp(id >> 16, id & 0xFFFF);
mPickUpTarget = NULL;
} else {
setDestination(item->getX() * 32 + 16, item->getY() * 32 + 16);
diff --git a/src/net/gameserver/player.cpp b/src/net/gameserver/player.cpp
index 0a47a6bc..763f3d28 100644
--- a/src/net/gameserver/player.cpp
+++ b/src/net/gameserver/player.cpp
@@ -32,38 +32,30 @@
void Net::GameServer::Player::say(const std::string &text)
{
MessageOut msg(PGMSG_SAY);
-
msg.writeString(text);
-
Net::GameServer::connection->send(msg);
}
-void Net::GameServer::Player::walk(short x, short y)
+void Net::GameServer::Player::walk(int x, int y)
{
MessageOut msg(PGMSG_WALK);
-
msg.writeShort(x);
msg.writeShort(y);
-
Net::GameServer::connection->send(msg);
}
-void Net::GameServer::Player::useItem(int itemId)
+void Net::GameServer::Player::pickUp(int x, int y)
{
- MessageOut msg(PGMSG_USE_ITEM);
-
- msg.writeLong(itemId);
-
+ MessageOut msg(PGMSG_PICKUP);
+ msg.writeShort(x);
+ msg.writeShort(y);
Net::GameServer::connection->send(msg);
}
-void Net::GameServer::Player::equip(int itemId, char slot)
+void Net::GameServer::Player::equip(int slot)
{
MessageOut msg(PGMSG_EQUIP);
-
- msg.writeLong(itemId);
msg.writeByte(slot);
-
Net::GameServer::connection->send(msg);
}
diff --git a/src/net/gameserver/player.h b/src/net/gameserver/player.h
index d8f572ae..a5429e65 100644
--- a/src/net/gameserver/player.h
+++ b/src/net/gameserver/player.h
@@ -28,17 +28,14 @@
namespace Net
{
- class Connection;
-
namespace GameServer
{
namespace Player
{
void say(const std::string &text);
- void walk(short x, short y);
-// void pickUp(...);
- void useItem(int itemId);
- void equip(int itemId, char slot);
+ void walk(int x, int y);
+ void pickUp(int x, int y);
+ void equip(int slot);
void attack(unsigned char direction);
}
}
diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp
index f003d77a..c6cc4a55 100644
--- a/src/net/inventoryhandler.cpp
+++ b/src/net/inventoryhandler.cpp
@@ -37,11 +37,14 @@
InventoryHandler::InventoryHandler()
{
static const Uint16 _messages[] = {
+ /*
SMSG_PLAYER_INVENTORY,
SMSG_PLAYER_INVENTORY_ADD,
SMSG_PLAYER_INVENTORY_REMOVE,
SMSG_PLAYER_INVENTORY_USE,
SMSG_ITEM_USE_RESPONSE,
+ */
+ GPMSG_INVENTORY,
0
};
handledMessages = _messages;
@@ -49,11 +52,22 @@ InventoryHandler::InventoryHandler()
void InventoryHandler::handleMessage(MessageIn &msg)
{
- Sint32 number;
- Sint16 index, amount, itemId, equipType;
-
switch (msg.getId())
{
+ case GPMSG_INVENTORY:
+ while (msg.getUnreadLength())
+ {
+ int slot = msg.readByte();
+ int id = msg.readShort();
+ int amount = slot >= 32 ? msg.readByte() : 1;
+ Item *it = player_node->getInvItem(slot - 32);
+ it->setId(id);
+ it->setQuantity(amount);
+ };
+ break;
+
+
+#if 0
case SMSG_PLAYER_INVENTORY:
// Only called on map load / warp. First reset all items
// to not load them twice on map change.
@@ -125,5 +139,7 @@ void InventoryHandler::handleMessage(MessageIn &msg)
player_node->getInvItem(index)->setQuantity(amount);
}
break;
+#endif
+
}
}
diff --git a/src/net/protocol.h b/src/net/protocol.h
index 27f5a7c8..4896b977 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -147,8 +147,8 @@ enum {
// Game
GPMSG_PLAYER_MAP_CHANGE = 0x0100, // S filename, W x, W y
GPMSG_PLAYER_SERVER_CHANGE = 0x0101, // B*32 token, S game address, W game port
- PGMSG_PICKUP = 0x0110,
- GPMSG_PICKUP_RESPONSE = 0x0111,
+ PGMSG_PICKUP = 0x0110, // W*2 position
+ GPMSG_INVENTORY = 0x0120, // { B slot, W item id [, B amount] }*
GPMSG_BEING_ENTER = 0x0200, // B type, W being id
// player: S name, B hair style, B hair color, B gender
// monster: W type id