summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/defines.h3
-rw-r--r--src/game-server/effect.cpp7
-rw-r--r--src/game-server/effect.hpp22
-rw-r--r--src/game-server/state.cpp19
-rw-r--r--src/scripting/lua.cpp31
5 files changed, 70 insertions, 12 deletions
diff --git a/src/defines.h b/src/defines.h
index a3a7e2f9..7a93f02f 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -192,7 +192,8 @@ enum {
PGMSG_USE_ITEM = 0x0300, // B slot
GPMSG_USE_RESPONSE = 0x0301, // B error
GPMSG_BEINGS_DAMAGE = 0x0310, // { W being id, W amount }*
- GPMSG_CREATE_EFFECT = 0x0320, // W effect id, W*2 position
+ GPMSG_CREATE_EFFECT_POS = 0x0320, // W effect id, W*2 position
+ GPMSG_CREATE_EFFECT_BEING = 0x0321, // W effect id, W BeingID
// Guild
PCMSG_GUILD_CREATE = 0x0350, // S name
diff --git a/src/game-server/effect.cpp b/src/game-server/effect.cpp
index 4cdbfff5..8d2f9495 100644
--- a/src/game-server/effect.cpp
+++ b/src/game-server/effect.cpp
@@ -39,4 +39,11 @@ namespace Effects
effect->setPosition(pos);
GameState::enqueueInsert(effect);
}
+ void show(int id, MapComposite *map, Being *b)
+ {
+ Effect *effect = new Effect(id);
+ effect->setMap(map);
+ if (effect->setBeing(b))
+ GameState::enqueueInsert(effect);
+ }
}
diff --git a/src/game-server/effect.hpp b/src/game-server/effect.hpp
index 49a12596..15db5d2e 100644
--- a/src/game-server/effect.hpp
+++ b/src/game-server/effect.hpp
@@ -23,6 +23,7 @@
#define _TMWSERV_EFFECT_H
#include "game-server/actor.hpp"
+#include "game-server/being.hpp"
class Effect : public Actor
{
@@ -31,11 +32,15 @@ class Effect : public Actor
: Actor(OBJECT_EFFECT)
, mEffectId(id)
, mHasBeenShown(false)
+ , mBeing(NULL)
{}
int getEffectId() const
{ return mEffectId; }
+ Being *getBeing() const
+ { return mBeing; }
+
/**
* Removes effect after it has been shown.
*/
@@ -47,18 +52,33 @@ class Effect : public Actor
void show()
{ mHasBeenShown = true; }
+
+ bool setBeing(Being *b)
+ {
+ if (b)
+ {
+ setPosition(b->getPosition());
+ mBeing = b;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
private:
int mEffectId;
bool mHasBeenShown;
+ Being *mBeing;
};
namespace Effects
{
/**
- * Convenience method to show an effect.
+ * Convenience methods to show an effect.
*/
void show(int id, MapComposite *map, const Point &pos);
+ void show(int id, MapComposite *map, Being *b);
// TODO: get this in sync with effects.xml
enum {
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index dcfb9139..faca3c1a 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -400,11 +400,20 @@ static void informPlayer(MapComposite *map, Character *p)
// Don't show old effects
if (!(oflags & UPDATEFLAG_NEW_ON_MAP))
break;
- MessageOut effectMsg(GPMSG_CREATE_EFFECT);
- effectMsg.writeShort(o->getEffectId());
- effectMsg.writeShort(opos.x);
- effectMsg.writeShort(opos.y);
- gameHandler->sendTo(p, effectMsg);
+ Being *b = o->getBeing();
+ if (b)
+ {
+ MessageOut effectMsg(GPMSG_CREATE_EFFECT_BEING);
+ effectMsg.writeShort(o->getEffectId());
+ effectMsg.writeShort(b->getPublicID());
+ gameHandler->sendTo(p, effectMsg);
+ } else {
+ MessageOut effectMsg(GPMSG_CREATE_EFFECT_POS);
+ effectMsg.writeShort(o->getEffectId());
+ effectMsg.writeShort(opos.x);
+ effectMsg.writeShort(opos.y);
+ gameHandler->sendTo(p, effectMsg);
+ }
}
break;
default: break;
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 4b2513e6..38177e98 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -1030,12 +1030,18 @@ static int being_register(lua_State *s)
/**
* Triggers a special effect from the clients effects.xml
* tmw.effect_create (id, x, y)
+ * tmw.effect_create (id,being)
*/
static int effect_create(lua_State *s)
{
if (!lua_isnumber(s, 1) ||
- !lua_isnumber(s, 2) ||
- !lua_isnumber(s, 3))
+ (
+ !lua_isnumber(s, 2) ||
+ !lua_isnumber(s, 3)
+ ) && (
+ !lua_isuserdata(s, 2)
+ )
+ )
{
raiseScriptError(s, "effect_create called with incorrect parameters.");
return 0;
@@ -1046,10 +1052,25 @@ static int effect_create(lua_State *s)
MapComposite *m = t->getMap();
int id = lua_tointeger(s, 1);
- int x = lua_tointeger(s, 2);
- int y = lua_tointeger(s, 3);
- Effects::show(id, m, Point(x, y));
+ if (lua_isuserdata(s, 2))
+ {
+ // being mode
+ Being *b = getBeing(s, 2);
+ if (!b)
+ {
+ raiseScriptError(s, "effect_create called on non-existent being");
+ return 0;
+ }
+ Effects::show(id, m, b);
+ }
+ else
+ {
+ // positional mode
+ int x = lua_tointeger(s, 2);
+ int y = lua_tointeger(s, 3);
+ Effects::show(id, m, Point(x, y));
+ }
return 0;
}