diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-18 11:06:01 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-18 11:06:01 +0000 |
commit | 546ae9ed020aefae6ee7470a92dff4901eceb53f (patch) | |
tree | e8af17d68d42c2af6a9055ff3d0dc932ff8f6ba0 /src | |
parent | 1e949983c13cab920a4cc445b2ed6429dd9aad5a (diff) | |
download | mana-client-546ae9ed020aefae6ee7470a92dff4901eceb53f.tar.gz mana-client-546ae9ed020aefae6ee7470a92dff4901eceb53f.tar.bz2 mana-client-546ae9ed020aefae6ee7470a92dff4901eceb53f.tar.xz mana-client-546ae9ed020aefae6ee7470a92dff4901eceb53f.zip |
Removed guess of being type from class number. Factored handler for new beings.
Diffstat (limited to 'src')
-rw-r--r-- | src/beingmanager.cpp | 27 | ||||
-rw-r--r-- | src/beingmanager.h | 2 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 41 |
3 files changed, 34 insertions, 36 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index a5be17d2..56865841 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include <cassert> + #include "beingmanager.h" #include "localplayer.h" @@ -28,6 +30,7 @@ #include "npc.h" #include "player.h" +#include "net/protocol.h" #include "utils/dtor.h" class FindBeingFunctor @@ -59,18 +62,24 @@ void BeingManager::setPlayer(LocalPlayer *player) mBeings.push_back(player); } -Being* BeingManager::createBeing(Uint16 id, Uint16 job) +Being* BeingManager::createBeing(int id, int type, int subtype) { Being *being; - if (job < 10) - being = new Player(id, job, mMap); - else if (job >= 100 & job < 200) - being = new NPC(id, job, mMap); - else if (job >= 1000 && job < 1200) - being = new Monster(id, job, mMap); - else - being = new Being(id, job, mMap); + switch (type) + { + case OBJECT_PLAYER: + being = new Player(id, subtype, mMap); + break; + case OBJECT_NPC: + being = new NPC(id, subtype, mMap); + break; + case OBJECT_MONSTER: + being = new Monster(id, subtype, mMap); + break; + default: + assert(false); + } mBeings.push_back(being); return being; diff --git a/src/beingmanager.h b/src/beingmanager.h index f97a23f4..81f85622 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -48,7 +48,7 @@ class BeingManager /** * Create a being and add it to the list of beings. */ - Being* createBeing(Uint16 id, Uint16 job); + Being *createBeing(int id, int type, int subtype); /** * Remove a Being. diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index b88d443e..020d24af 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -449,18 +449,18 @@ static void handleLooks(Being *being, MessageIn &msg) void BeingHandler::handleBeingEnterMessage(MessageIn &msg) { - int type = msg.readByte(); // type + int type = msg.readByte(); int id = msg.readShort(); Being::Action action = (Being::Action)msg.readByte(); - Uint16 px = msg.readShort(); - Uint16 py = msg.readShort(); + int px = msg.readShort(); + int py = msg.readShort(); + Being *being; switch (type) { case OBJECT_PLAYER: { std::string name = msg.readString(); - Being *being; if (player_node->getName() == name) { being = player_node; @@ -468,41 +468,30 @@ BeingHandler::handleBeingEnterMessage(MessageIn &msg) } else { - being = beingManager->createBeing(id, 0); + being = beingManager->createBeing(id, type, 0); being->setName(name); } being->setHairStyle(msg.readByte()); being->setHairColor(msg.readByte()); being->setSex(msg.readByte()); - being->mX = px; - being->mY = py; - being->setDestination(px, py); - being->setAction(action); handleLooks(being, msg); } break; case OBJECT_MONSTER: - { - int monsterId = msg.readShort(); - Being *being; - being = beingManager->createBeing(id, monsterId); - being->mX = px; - being->mY = py; - being->setDestination(px, py); - being->setAction(action); - } break; - case OBJECT_NPC: { - int npcId = msg.readShort(); - Being *being; - being = beingManager->createBeing(id, npcId); - being->mX = px; - being->mY = py; - being->setDestination(px, py); - being->setAction(action); + int subtype = msg.readShort(); + being = beingManager->createBeing(id, type, subtype); } break; + + default: + return; } + + being->mX = px; + being->mY = py; + being->setDestination(px, py); + being->setAction(action); } void BeingHandler::handleBeingLeaveMessage(MessageIn &msg) |