From 7465e9bf8fe03961c02b360002439c1072090bf0 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Fri, 5 Jan 2007 09:47:12 +0000 Subject: Implemented item dropping. --- ChangeLog | 9 +++++++++ src/defines.h | 6 +++--- src/game-server/gamehandler.cpp | 25 ++++++++++++++++++++++--- src/game-server/item.hpp | 8 ++++++-- src/game-server/player.cpp | 38 +++++++++----------------------------- src/game-server/testing.cpp | 20 +++++++++++++------- 6 files changed, 62 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index ab851eba..1de5e2db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-01-05 Guillaume Melquiond + + * src/game-server/player.cpp: Delayed update of persistent position. + * src/game-server/item.hpp: Added an amount property to items lying on + the ground. + * src/game-server/testing.cpp: Added a piece of equipment. + * src/game-server/defines.h, src/game-server/gamehandler.cpp: + Implemented item dropping. + 2007-01-04 Guillaume Melquiond * src/playerdata.hpp, src/playerdata.cpp, src/defines.h, diff --git a/src/defines.h b/src/defines.h index 049eba3d..68e6b4e9 100644 --- a/src/defines.h +++ b/src/defines.h @@ -137,7 +137,9 @@ enum { 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, // W*2 position - GPMSG_INVENTORY = 0x0120, // { B slot, W item id [, B amount ] }* + PGMSG_DROP = 0x0111, // B slot, B amount + PGMSG_EQUIP = 0x0112, // B slot + 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 @@ -152,8 +154,6 @@ enum { GPMSG_SAY = 0x02A1, // W being id, S text PGMSG_USE_ITEM = 0x0300, // L item id GPMSG_USE_RESPONSE = 0x0301, // B error - PGMSG_EQUIP = 0x0302, // L item id, B slot - GPMSG_EQUIP_RESPONSE = 0x0303, // B error GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }* // Chat diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index 6c9786ff..4d963129 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -26,6 +26,7 @@ #include "game-server/gamehandler.hpp" #include "game-server/item.hpp" +#include "game-server/itemmanager.hpp" #include "game-server/map.hpp" #include "game-server/mapcomposite.hpp" #include "game-server/state.hpp" @@ -252,15 +253,33 @@ void GameHandler::processMessage(NetComputer *comp, MessageIn &message) if (o->getType() == OBJECT_ITEM && opos.x == x && opos.y == y) { result.writeShort(GPMSG_INVENTORY); - ItemClass *item = static_cast< Item * >(o)->getItemClass(); - Inventory(computer.character, result).insert(item->getDatabaseID(), 1); - gameState->remove(o); + Item *item = static_cast< Item * >(o); + ItemClass *ic = item->getItemClass(); + Inventory(computer.character, result) + .insert(ic->getDatabaseID(), item->getAmount()); + gameState->remove(item); break; } } } } break; + case PGMSG_DROP: + { + int slot = message.readByte(); + int amount = message.readByte(); + Inventory inv(computer.character, result); + if (ItemClass *ic = itemManager->getItem(inv.getItem(slot))) + { + result.writeShort(GPMSG_INVENTORY); + int nb = inv.removeFromSlot(slot, amount); + Item *item = new Item(ic, amount - nb); + item->setMapId(computer.character->getMapId()); + item->setPosition(computer.character->getPosition()); + gameState->insert(item); + } + } break; + case PGMSG_WALK: { int x = message.readShort(); diff --git a/src/game-server/item.hpp b/src/game-server/item.hpp index 9d2ebb72..dd61dd2a 100644 --- a/src/game-server/item.hpp +++ b/src/game-server/item.hpp @@ -225,17 +225,21 @@ class ItemClass class Item: public Object { public: - Item(ItemClass *type) - : Object(OBJECT_ITEM), mType(type) + Item(ItemClass *type, int amount) + : Object(OBJECT_ITEM), mType(type), mAmount(amount) {} ItemClass *getItemClass() const { return mType; } + int getAmount() const + { return mAmount; } + virtual void update() {} private: ItemClass *mType; + unsigned char mAmount; }; #endif diff --git a/src/game-server/player.cpp b/src/game-server/player.cpp index 1f6fc935..8d5cbae0 100644 --- a/src/game-server/player.cpp +++ b/src/game-server/player.cpp @@ -39,8 +39,15 @@ void Player::update() setStat(STAT_SPEED, getRawStat(STAT_DEXTERITY)); // Update persistent data. - setPos(getPosition()); - setMap(getMapId()); + int mapId = getMapId(); + if (getMap() != mapId) + { + /* Only update on map change. This is on purpose. It prevents players + from respawning/reconnecting at the location they died. They will + reappear where they entered the map. */ + setMap(mapId); + setPos(getPosition()); + } // attacking if (mIsAttacking) @@ -55,30 +62,3 @@ void Player::update() } } } - -/* -bool Player::insertItem(int itemId, int amount) -{ - return inventory.insertItem(itemId, amount); -} - -bool Player::removeItem(int itemId, int amount) -{ - return inventory.removeItemById(itemId, amount); -} - -bool Player::hasItem(int itemId) -{ - return inventory.hasItem(itemId); -} - -bool Player::equip(int slot) -{ - return false; // TODO -} - -bool Player::unequip(int slot) -{ - return false; // TODO -} -*/ diff --git a/src/game-server/testing.cpp b/src/game-server/testing.cpp index 2565f3ec..61244974 100644 --- a/src/game-server/testing.cpp +++ b/src/game-server/testing.cpp @@ -14,6 +14,17 @@ static WarpAction warpA(3, 44 * 32 + 16, 80 * 32 + 16); static Rectangle rectB = { 42 * 32, 88 * 32, 5 * 32, 32 }; static WarpAction warpB(1, 58 * 32 + 16, 17 * 32 + 16); +static void dropItem(int map, int x, int y, int type) +{ + ItemClass *ic = itemManager->getItem(type); + assert(ic); + Item *i = new Item(ic, 1); + i->setMapId(map); + Point pos = { x, y }; + i->setPosition(pos); + gameState->insert(i); +} + void testingMap(int id) { switch (id) @@ -30,13 +41,8 @@ void testingMap(int id) being->setPosition(pos); gameState->insert(being); } - ItemClass *ic = itemManager->getItem(508); - assert(ic); - Item *i = new Item(ic); - i->setMapId(1); - Point pos = { 58 * 32 + 16, 20 * 32 + 16 }; - i->setPosition(pos); - gameState->insert(i); + dropItem(1, 58 * 32 + 16, 20 * 32 + 16, 508); + dropItem(1, 58 * 32 + 16, 21 * 32 + 16, 524); } break; case 3: -- cgit v1.2.3-60-g2f50