diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-19 22:09:25 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2013-03-25 20:32:36 +0100 |
commit | 7aeb3b4a6c34a8f679719c207e51394d7e48828b (patch) | |
tree | c92af607288f041944f7a876e3a9478b35ba6499 /src | |
parent | 7aee56f062989c8901322a09b2da40bb028eb222 (diff) | |
download | manaserv-7aeb3b4a6c34a8f679719c207e51394d7e48828b.tar.gz manaserv-7aeb3b4a6c34a8f679719c207e51394d7e48828b.tar.bz2 manaserv-7aeb3b4a6c34a8f679719c207e51394d7e48828b.tar.xz manaserv-7aeb3b4a6c34a8f679719c207e51394d7e48828b.zip |
Changed Effect to a component of Actor
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src')
-rw-r--r-- | src/game-server/commandhandler.cpp | 6 | ||||
-rw-r--r-- | src/game-server/component.h | 1 | ||||
-rw-r--r-- | src/game-server/effect.cpp | 30 | ||||
-rw-r--r-- | src/game-server/effect.h | 41 | ||||
-rw-r--r-- | src/game-server/item.cpp | 7 | ||||
-rw-r--r-- | src/game-server/item.h | 2 | ||||
-rw-r--r-- | src/game-server/state.cpp | 23 | ||||
-rw-r--r-- | src/game-server/triggerareacomponent.h | 2 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 2 |
9 files changed, 61 insertions, 53 deletions
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index ad6a1bc2..001f65f6 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -171,7 +171,7 @@ static CmdRef const cmdRef[] = }; -static void say(const std::string message, Character *player) +static void say(const std::string &message, Character *player) { GameState::sayTo(player, NULL, message); } @@ -1500,7 +1500,7 @@ static void handleEffect(Character *player, std::string &args) if (arguments.size() == 1) { int id = utils::stringToInt(arguments[0]); - Effects::show(id, player->getMap(), player); + Effects::show(id, player); } else if (arguments.size() == 2) { @@ -1511,7 +1511,7 @@ static void handleEffect(Character *player, std::string &args) say("Invalid target player.", player); return; } - Effects::show(id, p->getMap(), p); + Effects::show(id, p); } else if (arguments.size() == 3) { diff --git a/src/game-server/component.h b/src/game-server/component.h index fd477b90..90dda5a5 100644 --- a/src/game-server/component.h +++ b/src/game-server/component.h @@ -25,6 +25,7 @@ class Entity; enum ComponentType { + CT_Effect, CT_TriggerArea, CT_SpawnArea, CT_Item, diff --git a/src/game-server/effect.cpp b/src/game-server/effect.cpp index b7c6c643..f994ec77 100644 --- a/src/game-server/effect.cpp +++ b/src/game-server/effect.cpp @@ -1,6 +1,7 @@ /* * The Mana Server * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2012 The Mana Developers * * This file is part of The Mana Server. * @@ -20,29 +21,40 @@ #include "game-server/effect.h" -#include "game-server/mapcomposite.h" +#include "game-server/being.h" +#include "game-server/entity.h" #include "game-server/state.h" -void Effect::update() +const ComponentType EffectComponent::type; + +void EffectComponent::update(Entity &entity) { if (mHasBeenShown) - GameState::enqueueRemove(this); + GameState::enqueueRemove(static_cast<Actor*>(&entity)); } namespace Effects { void show(int id, MapComposite *map, const Point &pos) { - Effect *effect = new Effect(id); + Actor *effect = new Actor(OBJECT_EFFECT); + effect->addComponent(new EffectComponent(id)); effect->setMap(map); effect->setPosition(pos); + GameState::enqueueInsert(effect); } - void show(int id, MapComposite *map, Being *b) + + void show(int id, Being *b) { - Effect *effect = new Effect(id); - effect->setMap(map); - if (effect->setBeing(b)) - GameState::enqueueInsert(effect); + EffectComponent *effectComponent = new EffectComponent(id); + effectComponent->setBeing(b); + + Actor *effect = new Actor(OBJECT_EFFECT); + effect->addComponent(effectComponent); + effect->setMap(b->getMap()); + effect->setPosition(b->getPosition()); + + GameState::enqueueInsert(effect); } } diff --git a/src/game-server/effect.h b/src/game-server/effect.h index 2e22d46e..4ac63611 100644 --- a/src/game-server/effect.h +++ b/src/game-server/effect.h @@ -1,6 +1,7 @@ /* * The Mana Server * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2012 The Mana Developers * * This file is part of The Mana Server. * @@ -21,17 +22,21 @@ #ifndef EFFECT_H #define EFFECT_H -#include "game-server/actor.h" -#include "game-server/being.h" +#include "game-server/component.h" -class Effect : public Actor +class Being; +class MapComposite; +class Point; + +class EffectComponent : public Component { public: - Effect(int id) - : Actor(OBJECT_EFFECT) - , mEffectId(id) + static const ComponentType type = CT_Effect; + + EffectComponent(int id) + : mEffectId(id) , mHasBeenShown(false) - , mBeing(NULL) + , mBeing(0) {} int getEffectId() const @@ -43,26 +48,16 @@ class Effect : public Actor /** * Removes effect after it has been shown. */ - virtual void update(); + void update(Entity &entity); /** * Called when the object has been shown to a player in the state loop. */ - void show() + void setShown() { mHasBeenShown = true; } - - bool setBeing(Being *b) - { - if (b) - { - setPosition(b->getPosition()); - mBeing = b; - return true; - } else { - return false; - } - } + void setBeing(Being *b) + { mBeing = b; } private: int mEffectId; @@ -77,7 +72,7 @@ namespace Effects * Convenience methods to show an effect. */ void show(int id, MapComposite *map, const Point &pos); - void show(int id, MapComposite *map, Being *b); + void show(int id, Being *b); // TODO: get this in sync with effects.xml enum { @@ -85,4 +80,4 @@ namespace Effects }; } -#endif +#endif // EFFECT_H diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp index 44029303..b7b0d785 100644 --- a/src/game-server/item.cpp +++ b/src/game-server/item.cpp @@ -19,10 +19,6 @@ * along with The Mana Server. If not, see <http://www.gnu.org/licenses/>. */ - -#include <string> -#include <map> - #include "game-server/item.h" #include "common/configuration.h" @@ -33,6 +29,9 @@ #include "scripting/script.h" #include "scripting/scriptmanager.h" +#include <map> +#include <string> + bool ItemEffectAttrMod::apply(Being *itemUser) { LOG_DEBUG("Applying modifier."); diff --git a/src/game-server/item.h b/src/game-server/item.h index 2ce858c7..e88c1f98 100644 --- a/src/game-server/item.h +++ b/src/game-server/item.h @@ -311,7 +311,7 @@ class ItemComponent : public Component int getAmount() const { return mAmount; } - virtual void update(Entity &entity); + void update(Entity &entity); private: ItemClass *mType; diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index d84f35b2..ab0dcd79 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -355,10 +355,11 @@ static void informPlayer(MapComposite *map, Character *p) for (FixedActorIterator it(map->getAroundBeingIterator(p, visualRange)); it; ++it) { - assert((*it)->getType() == OBJECT_ITEM || - (*it)->getType() == OBJECT_EFFECT); - Actor *o = *it; + + assert(o->getType() == OBJECT_ITEM || + o->getType() == OBJECT_EFFECT); + Point opos = o->getPosition(); int oflags = o->getUpdateFlags(); bool willBeInRange = ppos.inRangeOf(opos, visualRange); @@ -394,21 +395,21 @@ static void informPlayer(MapComposite *map, Character *p) break; case OBJECT_EFFECT: { - Effect *o = static_cast< Effect * >(*it); - o->show(); + EffectComponent *e = o->getComponent<EffectComponent>(); + e->setShown(); // Don't show old effects if (!(oflags & UPDATEFLAG_NEW_ON_MAP)) break; - Being *b = o->getBeing(); - if (b) + + if (Being *b = e->getBeing()) { MessageOut effectMsg(GPMSG_CREATE_EFFECT_BEING); - effectMsg.writeInt16(o->getEffectId()); + effectMsg.writeInt16(e->getEffectId()); effectMsg.writeInt16(b->getPublicID()); gameHandler->sendTo(p, effectMsg); } else { MessageOut effectMsg(GPMSG_CREATE_EFFECT_POS); - effectMsg.writeInt16(o->getEffectId()); + effectMsg.writeInt16(e->getEffectId()); effectMsg.writeInt16(opos.x); effectMsg.writeInt16(opos.y); gameHandler->sendTo(p, effectMsg); @@ -559,7 +560,7 @@ bool GameState::insert(Entity *ptr) case OBJECT_EFFECT: LOG_DEBUG("Effect inserted: " - << static_cast<Effect*>(obj)->getEffectId()); + << obj->getComponent<EffectComponent>()->getEffectId()); break; case OBJECT_MONSTER: @@ -633,7 +634,7 @@ void GameState::remove(Entity *ptr) case OBJECT_EFFECT: LOG_DEBUG("Effect removed: " - << static_cast<Effect*>(ptr)->getEffectId()); + << ptr->getComponent<EffectComponent>()->getEffectId()); break; case OBJECT_MONSTER: diff --git a/src/game-server/triggerareacomponent.h b/src/game-server/triggerareacomponent.h index 2185d8cf..f766c815 100644 --- a/src/game-server/triggerareacomponent.h +++ b/src/game-server/triggerareacomponent.h @@ -79,7 +79,7 @@ class TriggerAreaComponent : public Component mOnce(once) {} - virtual void update(Entity &entity); + void update(Entity &entity); private: Rectangle mZone; diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 0dd6582d..705ee4c9 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -443,7 +443,7 @@ static int effect_create(lua_State *s) { // being mode Being *b = checkBeing(s, 2); - Effects::show(id, b->getMap(), b); + Effects::show(id, b); } else { |