summaryrefslogtreecommitdiff
path: root/src/game-server/gamehandler.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-18 22:24:38 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-03-25 20:32:36 +0100
commit7aee56f062989c8901322a09b2da40bb028eb222 (patch)
tree2c3712c3926121d35b0ef569e1eeed8f42e34b32 /src/game-server/gamehandler.cpp
parent8ebd7ef2c200009e6d22b2cfaa3dd0d849155db6 (diff)
downloadmanaserv-7aee56f062989c8901322a09b2da40bb028eb222.tar.gz
manaserv-7aee56f062989c8901322a09b2da40bb028eb222.tar.bz2
manaserv-7aee56f062989c8901322a09b2da40bb028eb222.tar.xz
manaserv-7aee56f062989c8901322a09b2da40bb028eb222.zip
Changed Item to a component of Actor
Items also have positions, so the ItemComponent only makes sense as part of an Actor. Later on it will probably be part of an entity that also has an ActorComponent. Since it was annoying to update all the places where items were created, I've introduced a function for this. The component types are now prefixed with "CT_" because I wanted to introduce an 'Item' namespace which would otherwise be conflicting. The component types enum isn't used much in the code so it can look a bit ugly. Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/game-server/gamehandler.cpp')
-rw-r--r--src/game-server/gamehandler.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index 3b356a5c..eeccdcc5 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -488,15 +488,17 @@ void GameHandler::handlePickup(GameClient &client, MessageIn &message)
{
Actor *o = *i;
Point opos = o->getPosition();
+
if (o->getType() == OBJECT_ITEM && opos.x == x && opos.y == y)
{
- Item *item = static_cast< Item * >(o);
+ ItemComponent *item = o->getComponent<ItemComponent>();
ItemClass *ic = item->getItemClass();
int amount = item->getAmount();
+
if (!Inventory(client.character).insert(ic->getDatabaseID(),
- amount))
+ amount))
{
- GameState::remove(item);
+ GameState::remove(o);
// We only do this when items are to be kept in memory
// between two server restart.
@@ -504,8 +506,8 @@ void GameHandler::handlePickup(GameClient &client, MessageIn &message)
{
// Remove the floor item from map
accountHandler->removeFloorItems(map->getID(),
- ic->getDatabaseID(),
- amount, x, y);
+ ic->getDatabaseID(),
+ amount, x, y);
}
// log transaction
@@ -556,33 +558,32 @@ void GameHandler::handleDrop(GameClient &client, MessageIn &message)
if (ItemClass *ic = itemManager->getItem(inv.getItem(slot)))
{
int nb = inv.removeFromSlot(slot, amount);
- Item *item = new Item(ic, amount - nb);
- item->setMap(client.character->getMap());
- item->setPosition(client.character->getPosition());
- if (!GameState::insert(item))
+ MapComposite *map = client.character->getMap();
+ Point pos = client.character->getPosition();
+
+ Entity *item = Item::create(map, pos, ic, amount - nb);
+
+ if (!GameState::insertOrDelete(item))
{
// The map is full. Put back into inventory.
inv.insert(ic->getDatabaseID(), amount - nb);
- delete item;
return;
}
- Point pt = client.character->getPosition();
-
// We store the item in database only when the floor items are meant
// to be persistent between two server restarts.
if (!Configuration::getValue("game_floorItemDecayTime", 0))
{
// Create the floor item on map
accountHandler->createFloorItems(client.character->getMap()->getID(),
- ic->getDatabaseID(),
- amount, pt.x, pt.y);
+ ic->getDatabaseID(),
+ amount, pos.x, pos.y);
}
// log transaction
std::stringstream str;
str << "User dropped item " << ic->getDatabaseID()
- << " at " << pt.x << "x" << pt.y;
+ << " at " << pos.x << "x" << pos.y;
accountHandler->sendTransaction(client.character->getDatabaseID(),
TRANS_ITEM_DROP, str.str());
}