summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-01-05 09:47:12 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-01-05 09:47:12 +0000
commit7465e9bf8fe03961c02b360002439c1072090bf0 (patch)
tree9e25884ea13a29e370625ddf51c7eedb6326931b /src/game-server
parent59e483ca6d2ec680f438787b4b3213534380c871 (diff)
downloadmanaserv-7465e9bf8fe03961c02b360002439c1072090bf0.tar.gz
manaserv-7465e9bf8fe03961c02b360002439c1072090bf0.tar.bz2
manaserv-7465e9bf8fe03961c02b360002439c1072090bf0.tar.xz
manaserv-7465e9bf8fe03961c02b360002439c1072090bf0.zip
Implemented item dropping.
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/gamehandler.cpp25
-rw-r--r--src/game-server/item.hpp8
-rw-r--r--src/game-server/player.cpp38
-rw-r--r--src/game-server/testing.cpp20
4 files changed, 50 insertions, 41 deletions
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: