summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-07-18 21:08:18 -0600
committerJared Adams <jaxad0127@gmail.com>2009-07-18 21:08:18 -0600
commit5c3f23831986dda46d1c41b8316dd901f1bf3164 (patch)
tree4949ea4b2ce9564636da33b11351f94ec04cfbf3 /src
parent1923fcab4fc9aefd3eaa97fd9ca9b1c507bb4bcb (diff)
downloadmanaserv-5c3f23831986dda46d1c41b8316dd901f1bf3164.tar.gz
manaserv-5c3f23831986dda46d1c41b8316dd901f1bf3164.tar.bz2
manaserv-5c3f23831986dda46d1c41b8316dd901f1bf3164.tar.xz
manaserv-5c3f23831986dda46d1c41b8316dd901f1bf3164.zip
Change status effects to prevent duplication
Also add some functions for manipulating status effects: * removeStatusEffect * getStatusEffectTime * setStatusEffectTime
Diffstat (limited to 'src')
-rw-r--r--src/game-server/being.cpp43
-rw-r--r--src/game-server/being.hpp18
-rw-r--r--src/scripting/lua.cpp53
3 files changed, 101 insertions, 13 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index a68ed1f5..66a13a60 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -298,10 +298,18 @@ int Being::getModifiedAttribute(int attr) const
void Being::applyStatusEffect(int id, int timer)
{
- Status newStatus;
- newStatus.status = StatusManager::getStatus(id);
- newStatus.time = timer;
- mStatus.push_back(newStatus);
+ if (mAction == DEAD)
+ return;
+
+ Status newStatus;
+ newStatus.status = StatusManager::getStatus(id);
+ newStatus.time = timer;
+ mStatus[id] = newStatus;
+}
+
+void Being::removeStatusEffect(int id)
+{
+ setStatusEffectTime(id, 0);
}
bool Being::hasStatusEffect(int id)
@@ -309,12 +317,25 @@ bool Being::hasStatusEffect(int id)
StatusEffects::iterator it = mStatus.begin();
while (it != mStatus.end())
{
- if (it->status->getId() == id)
+ if (it->second.status->getId() == id)
return true;
}
return false;
}
+unsigned Being::getStatusEffectTime(int id)
+{
+ StatusEffects::iterator it = mStatus.find(id);
+ if (it != mStatus.end()) return it->second.time;
+ else return 0;
+}
+
+void Being::setStatusEffectTime(int id, int time)
+{
+ StatusEffects::iterator it = mStatus.find(id);
+ if (it != mStatus.end()) it->second.time = time;
+}
+
void Being::update()
{
int oldHP = getModifiedAttribute(BASE_ATTR_HP);
@@ -358,15 +379,15 @@ void Being::update()
StatusEffects::iterator it = mStatus.begin();
while (it != mStatus.end())
{
- it->time--;
- if (it->time > 0 && mAction != DEAD)
+ it->second.time--;
+ if (it->second.time > 0 && mAction != DEAD)
{
- it->status->tick(this, it->time);
+ it->second.status->tick(this, it->second.time);
}
- else
+
+ if (it->second.time <= 0 || mAction == DEAD)
{
- it = mStatus.erase(it);
- continue;
+ mStatus.erase(it);
}
it++;
}
diff --git a/src/game-server/being.hpp b/src/game-server/being.hpp
index 5c431503..93372b2a 100644
--- a/src/game-server/being.hpp
+++ b/src/game-server/being.hpp
@@ -24,6 +24,7 @@
#include <string>
#include <vector>
#include <list>
+#include <map>
#include "limits.h"
#include "defines.h"
@@ -102,7 +103,7 @@ struct Status
unsigned time; // Number of ticks
};
-typedef std::vector< Status > StatusEffects;
+typedef std::map< int, Status > StatusEffects;
typedef std::vector< AttributeModifier > AttributeModifiers;
/**
@@ -285,10 +286,25 @@ class Being : public Actor
void applyStatusEffect(int id, int time);
/**
+ * Removes the status effect
+ */
+ void removeStatusEffect(int id);
+
+ /**
* Returns true if the being has a status effect
*/
bool hasStatusEffect(int id);
+ /**
+ * Returns the time of the status effect if in effect, or 0 if not
+ */
+ unsigned getStatusEffectTime(int id);
+
+ /**
+ * Changes the time of the status effect (if in effect)
+ */
+ void setStatusEffectTime(int id, int time);
+
/** Gets the name of the being. */
const std::string &getName() const
{ return mName; }
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 230c8a3c..7361cea0 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -501,7 +501,23 @@ static int being_apply_status(lua_State *s)
}
/**
- * Returns true if a being has a status effect
+ * Removes the given status effect
+ * tmw.being_remove_status(Being *being, int id)
+ */
+static int being_remove_status(lua_State *s)
+{
+ if (!lua_isuserdata(s, 1) || !lua_isnumber(s, 2))
+ {
+ raiseScriptError(s, "being_remove_status called with incorrect parameters.");
+ return 0;
+ }
+ Being *being = getBeing(s, 1);
+ being->removeStatusEffect(lua_tointeger(s,2));
+ return 1;
+}
+
+/**
+ * Returns true if a being has the given status effect
* tmw.being_has_status(Being *being, int id)
*/
static int being_has_status(lua_State *s)
@@ -516,6 +532,38 @@ static int being_has_status(lua_State *s)
return 1;
}
+/**
+ * Returns the time left on the given status effect
+ * tmw.being_get_status_time(Being *being, int id)
+ */
+static int being_get_status_time(lua_State *s)
+{
+ if (!lua_isuserdata(s, 1) || !lua_isnumber(s, 2))
+ {
+ raiseScriptError(s, "being_time_status called with incorrect parameters.");
+ return 0;
+ }
+ Being *being = getBeing(s, 1);
+ lua_pushinteger(s, being->getStatusEffectTime(lua_tointeger(s,2)));
+ return 1;
+}
+
+/**
+ * Sets the time left on the given status effect
+ * tmw.being_set_status_time(Being *being, int id)
+ */
+static int being_set_status_time(lua_State *s)
+{
+ if (!lua_isuserdata(s, 1) || !lua_isnumber(s, 2) || !lua_isnumber(s, 3))
+ {
+ raiseScriptError(s, "being_time_status called with incorrect parameters.");
+ return 0;
+ }
+ Being *being = getBeing(s, 1);
+ being->setStatusEffectTime(lua_tointeger(s,2), lua_tointeger(s,3));
+ return 1;
+}
+
/**
* Returns the Thing type of the given Being
@@ -1283,7 +1331,10 @@ LuaScript::LuaScript():
{ "exp_for_level", &exp_for_level },
{ "monster_create", &monster_create },
{ "being_apply_status", &being_apply_status },
+ { "being_remove_status", &being_remove_status },
{ "being_has_status", &being_has_status },
+ { "being_set_status_time", &being_set_status_time},
+ { "being_get_status_time", &being_get_status_time},
{ "being_type", &being_type },
{ "being_walk", &being_walk },
{ "being_say", &being_say },