From 90290b7aaf2a55187598e67c31d33f5735f574ce Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Thu, 4 Jan 2007 22:28:08 +0000 Subject: Client-side hack for picking up items. --- src/net/gameserver/player.cpp | 20 ++++++-------------- src/net/gameserver/player.h | 9 +++------ src/net/inventoryhandler.cpp | 22 +++++++++++++++++++--- src/net/protocol.h | 4 ++-- 4 files changed, 30 insertions(+), 25 deletions(-) (limited to 'src/net') 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 -- cgit v1.2.3-70-g09d2