summaryrefslogtreecommitdiffstats
path: root/src/game-server
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-19 22:09:25 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-03-25 20:32:36 +0100
commit7aeb3b4a6c34a8f679719c207e51394d7e48828b (patch)
treec92af607288f041944f7a876e3a9478b35ba6499 /src/game-server
parent7aee56f062989c8901322a09b2da40bb028eb222 (diff)
downloadmanaserv-7aeb3b4a6c34a8f679719c207e51394d7e48828b.tar.gz
manaserv-7aeb3b4a6c34a8f679719c207e51394d7e48828b.tar.xz
manaserv-7aeb3b4a6c34a8f679719c207e51394d7e48828b.zip
Changed Effect to a component of Actor
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/commandhandler.cpp6
-rw-r--r--src/game-server/component.h1
-rw-r--r--src/game-server/effect.cpp30
-rw-r--r--src/game-server/effect.h41
-rw-r--r--src/game-server/item.cpp7
-rw-r--r--src/game-server/item.h2
-rw-r--r--src/game-server/state.cpp23
-rw-r--r--src/game-server/triggerareacomponent.h2
8 files changed, 60 insertions, 52 deletions
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp
index ad6a1bc..001f65f 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 fd477b9..90dda5a 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 b7c6c64..f994ec7 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 2e22d46..4ac6361 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 4402930..b7b0d78 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 2ce858c..e88c1f9 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 d84f35b..ab0dcd7 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 2185d8c..f766c81 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;