diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actorspritemanager.cpp | 4 | ||||
-rw-r--r-- | src/actorspritemanager.h | 6 | ||||
-rw-r--r-- | src/flooritem.cpp | 16 | ||||
-rw-r--r-- | src/flooritem.h | 12 | ||||
-rw-r--r-- | src/net/manaserv/itemhandler.cpp | 18 | ||||
-rw-r--r-- | src/net/tmwa/itemhandler.cpp | 14 |
6 files changed, 34 insertions, 36 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index a4b61ed3..2437f7f7 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -124,9 +124,9 @@ Being *ActorSpriteManager::createBeing(int id, ActorSprite::Type type, int subty return being; } -FloorItem *ActorSpriteManager::createItem(int id, int itemId, int x, int y) +FloorItem *ActorSpriteManager::createItem(int id, int itemId, const Vector &pos) { - FloorItem *floorItem = new FloorItem(id, itemId, x, y, mMap); + FloorItem *floorItem = new FloorItem(id, itemId, pos, mMap); mActors.insert(floorItem); return floorItem; diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h index d6aa609b..64703396 100644 --- a/src/actorspritemanager.h +++ b/src/actorspritemanager.h @@ -59,8 +59,12 @@ class ActorSpriteManager /** * Create a FloorItem and add it to the list of ActorSprites. + * + * @param id the unique ID of this item instance + * @param itemId the item ID + * @param position the position in pixels */ - FloorItem *createItem(int id, int itemId, int x, int y); + FloorItem *createItem(int id, int itemId, const Vector &position); /** * Destroys the given ActorSprite at the end of diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 8805ba88..07903a79 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -22,23 +22,27 @@ #include "flooritem.h" #include "net/net.h" +#include "net/playerhandler.h" #include "resources/itemdb.h" #include "resources/iteminfo.h" FloorItem::FloorItem(int id, int itemId, - int x, - int y, + const Vector &position, Map *map): ActorSprite(id), mItemId(itemId), - mX(x), - mY(y) + mX(0), mY(0) { - setMap(map); + mPos = position; - mPos = map->getTileCenter(x, y); + setMap(map); + if (map) + { + mX = (int)position.x / map->getTileWidth(); + mY = (int)position.y / map->getTileHeight(); + } setupSpriteDisplay(itemDb->get(itemId).getDisplay()); } diff --git a/src/flooritem.h b/src/flooritem.h index e599c939..0bcc380f 100644 --- a/src/flooritem.h +++ b/src/flooritem.h @@ -35,16 +35,14 @@ class FloorItem : public ActorSprite /** * Constructor. * - * @param id the unique ID of this item instance - * @param itemId the item ID - * @param x the x position in tiles - * @param y the y position in tiles - * @param map the map this item is on + * @param id the unique ID of this item instance + * @param itemId the item ID + * @param position the position in pixels + * @param map the map this item is on */ FloorItem(int id, int itemId, - int x, - int y, + const Vector &position, Map *map); Type getType() const { return FLOOR_ITEM; } diff --git a/src/net/manaserv/itemhandler.cpp b/src/net/manaserv/itemhandler.cpp index af3457db..d8365d79 100644 --- a/src/net/manaserv/itemhandler.cpp +++ b/src/net/manaserv/itemhandler.cpp @@ -26,8 +26,6 @@ #include "net/manaserv/manaserv_protocol.h" #include "net/manaserv/messagein.h" -#include "game.h" -#include "map.h" #include "log.h" namespace ManaServ { @@ -58,21 +56,7 @@ void ItemHandler::handleMessage(Net::MessageIn &msg) if (itemId) { - if (Game *game = Game::instance()) - { - if (Map *map = game->getCurrentMap()) - { - actorSpriteManager->createItem(id, itemId, - x / map->getTileWidth(), - y / map->getTileHeight()); - } - else - { - logger->log( - "ItemHandler: An item wasn't created " - "because of Game/Map not initialized..."); - } - } + actorSpriteManager->createItem(id, itemId, Vector(x, y)); } else if (FloorItem *item = actorSpriteManager->findItem(id)) { diff --git a/src/net/tmwa/itemhandler.cpp b/src/net/tmwa/itemhandler.cpp index a8e98860..e452ccf2 100644 --- a/src/net/tmwa/itemhandler.cpp +++ b/src/net/tmwa/itemhandler.cpp @@ -21,12 +21,14 @@ #include "net/tmwa/itemhandler.h" -#include "actorspritemanager.h" - #include "net/messagein.h" #include "net/tmwa/protocol.h" +#include "actorspritemanager.h" +#include "game.h" +#include "map.h" + namespace TmwAthena { ItemHandler::ItemHandler() @@ -54,7 +56,13 @@ void ItemHandler::handleMessage(Net::MessageIn &msg) int y = msg.readInt16(); msg.skip(4); // amount,subX,subY / subX,subY,amount - actorSpriteManager->createItem(id, itemId, x, y); + Game *game = Game::instance(); + if (!game) + break; + + if (Map *map = game->getCurrentMap()) + actorSpriteManager->createItem(id, itemId, + map->getTileCenter(x, y)); } break; |