diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/ea/itemhandler.cpp | 25 | ||||
-rw-r--r-- | src/net/ea/playerhandler.cpp | 16 | ||||
-rw-r--r-- | src/net/manaserv/itemhandler.cpp | 4 | ||||
-rw-r--r-- | src/net/manaserv/playerhandler.cpp | 10 |
4 files changed, 26 insertions, 29 deletions
diff --git a/src/net/ea/itemhandler.cpp b/src/net/ea/itemhandler.cpp index 2f65c064..8b8f2b22 100644 --- a/src/net/ea/itemhandler.cpp +++ b/src/net/ea/itemhandler.cpp @@ -21,7 +21,6 @@ #include "net/ea/itemhandler.h" -#include "engine.h" #include "flooritemmanager.h" #include "net/messagein.h" @@ -43,28 +42,24 @@ ItemHandler::ItemHandler() void ItemHandler::handleMessage(Net::MessageIn &msg) { - Uint32 id; - Uint16 x, y; - int itemId; - switch (msg.getId()) { case SMSG_ITEM_VISIBLE: case SMSG_ITEM_DROPPED: - id = msg.readInt32(); - itemId = msg.readInt16(); - msg.readInt8(); // identify flag - x = msg.readInt16(); - y = msg.readInt16(); - msg.skip(4); // amount,subX,subY / subX,subY,amount + { + int id = msg.readInt32(); + int itemId = msg.readInt16(); + msg.readInt8(); // identify flag + int x = msg.readInt16(); + int y = msg.readInt16(); + msg.skip(4); // amount,subX,subY / subX,subY,amount - floorItemManager->create(id, itemId, x, y, engine->getCurrentMap()); + floorItemManager->create(id, itemId, x, y); + } break; case SMSG_ITEM_REMOVE: - FloorItem *item; - item = floorItemManager->findById(msg.readInt32()); - if (item) + if (FloorItem *item = floorItemManager->findById(msg.readInt32())) floorItemManager->destroy(item); break; } diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 156e8b26..0c290815 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -21,7 +21,7 @@ #include "net/ea/playerhandler.h" -#include "engine.h" +#include "game.h" #include "localplayer.h" #include "log.h" #include "npc.h" @@ -179,9 +179,8 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) case SMSG_PLAYER_WARP: { std::string mapPath = msg.readString(16); - bool nearby; - Uint16 x = msg.readInt16(); - Uint16 y = msg.readInt16(); + int x = msg.readInt16(); + int y = msg.readInt16(); logger->log("Warping to %s (%d, %d)", mapPath.c_str(), x, y); @@ -191,17 +190,20 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) */ player_node->stopAttack(); - nearby = (engine->getCurrentMapName() == mapPath); + Game *game = Game::instance(); + + const std::string ¤tMap = game->getCurrentMapName(); + bool sameMap = (currentMap == mapPath); // Switch the actual map, deleting the previous one if necessary mapPath = mapPath.substr(0, mapPath.rfind(".")); - engine->changeMap(mapPath); + game->changeMap(mapPath); float scrollOffsetX = 0.0f; float scrollOffsetY = 0.0f; /* Scroll if neccessary */ - if (!nearby + if (!sameMap || (abs(x - player_node->getTileX()) > MAP_TELEPORT_SCROLL_DISTANCE) || (abs(y - player_node->getTileY()) > MAP_TELEPORT_SCROLL_DISTANCE)) { diff --git a/src/net/manaserv/itemhandler.cpp b/src/net/manaserv/itemhandler.cpp index 3d89487c..79a0caf0 100644 --- a/src/net/manaserv/itemhandler.cpp +++ b/src/net/manaserv/itemhandler.cpp @@ -21,11 +21,9 @@ #include "net/manaserv/itemhandler.h" -#include "engine.h" #include "flooritemmanager.h" #include "net/manaserv/protocol.h" - #include "net/manaserv/messagein.h" namespace ManaServ { @@ -56,7 +54,7 @@ void ItemHandler::handleMessage(Net::MessageIn &msg) if (itemId) { - floorItemManager->create(id, itemId, x / 32, y / 32, engine->getCurrentMap()); + floorItemManager->create(id, itemId, x / 32, y / 32); } else if (FloorItem *item = floorItemManager->findById(id)) { diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 9225b765..624a442a 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -23,7 +23,7 @@ #include "net/manaserv/beinghandler.h" #include "effectmanager.h" -#include "engine.h" +#include "game.h" #include "localplayer.h" #include "log.h" #include "particle.h" @@ -304,12 +304,14 @@ void PlayerHandler::handleMapChangeMessage(Net::MessageIn &msg) const std::string mapName = msg.readString(); const unsigned short x = msg.readInt16(); const unsigned short y = msg.readInt16(); - const bool nearby = (engine->getCurrentMapName() == mapName); + + Game *game = Game::instance(); + const bool sameMap = (game->getCurrentMapName() == mapName); logger->log("Changing map to %s (%d, %d)", mapName.c_str(), x, y); // Switch the actual map, deleting the previous one - engine->changeMap(mapName); + game->changeMap(mapName); current_npc = 0; @@ -318,7 +320,7 @@ void PlayerHandler::handleMapChangeMessage(Net::MessageIn &msg) float scrollOffsetY = 0.0f; /* Scroll if neccessary */ - if (!nearby + if (!sameMap || (abs(x - (int) playerPos.x) > MAP_TELEPORT_SCROLL_DISTANCE) || (abs(y - (int) playerPos.y) > MAP_TELEPORT_SCROLL_DISTANCE)) { |