summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-04-22 09:21:01 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-05-08 14:02:51 +0200
commit62f1e23dff18a00066ce9a9df67e058d5e5d7bbd (patch)
tree3ae5e42f4df777184deda3e62d5be1a6a6ba9bbc
parent2e977bb3182332fce247c7bdee5db2c43c9de5ee (diff)
downloadmanaserv-62f1e23dff18a00066ce9a9df67e058d5e5d7bbd.tar.gz
manaserv-62f1e23dff18a00066ce9a9df67e058d5e5d7bbd.tar.xz
manaserv-62f1e23dff18a00066ce9a9df67e058d5e5d7bbd.zip
[Abilities] Added a autoconsume option
You do not need to reset the mana in the scripts if you do not want to. We will need this for attacks later since those do not nessecary have a script.
-rw-r--r--example/scripts/abilities.lua1
-rw-r--r--src/game-server/abilitycomponent.cpp10
-rw-r--r--src/game-server/abilitymanager.cpp2
-rw-r--r--src/game-server/abilitymanager.h2
4 files changed, 14 insertions, 1 deletions
diff --git a/example/scripts/abilities.lua b/example/scripts/abilities.lua
index d7449b0..263c20c 100644
--- a/example/scripts/abilities.lua
+++ b/example/scripts/abilities.lua
@@ -12,6 +12,5 @@ local spell1 = get_ability_info("Magic_Test Spell 1")
spell1:on_use(function(user, x, y, abilityId)
target = target or user
target:say("Kaaame...Haaame... HAAAAAA! " .. x .. " " .. y)
- user:set_ability_mana(abilityId, 0)
end)
spell1:on_recharged(function(ch) ch:say("Hoooooooo...") end)
diff --git a/src/game-server/abilitycomponent.cpp b/src/game-server/abilitycomponent.cpp
index c8610b5..eac5f1c 100644
--- a/src/game-server/abilitycomponent.cpp
+++ b/src/game-server/abilitycomponent.cpp
@@ -120,6 +120,11 @@ void AbilityComponent::useAbilityOnBeing(Entity &user, int id, Entity *b)
if (ability.abilityInfo->target != AbilityManager::TARGET_BEING)
return;
+ if (ability.abilityInfo->autoconsume) {
+ ability.currentPoints = 0;
+ signal_ability_changed.emit(id);
+ }
+
//tell script engine to cast the spell
Script *script = ScriptManager::currentState();
script->prepare(ability.abilityInfo->useCallback);
@@ -143,6 +148,11 @@ void AbilityComponent::useAbilityOnPoint(Entity &user, int id, int x, int y)
if (ability.abilityInfo->target != AbilityManager::TARGET_POINT)
return;
+ if (ability.abilityInfo->autoconsume) {
+ ability.currentPoints = 0;
+ signal_ability_changed.emit(id);
+ }
+
//tell script engine to cast the spell
Script *script = ScriptManager::currentState();
script->prepare(ability.abilityInfo->useCallback);
diff --git a/src/game-server/abilitymanager.cpp b/src/game-server/abilitymanager.cpp
index b492f65..eb828e8 100644
--- a/src/game-server/abilitymanager.cpp
+++ b/src/game-server/abilitymanager.cpp
@@ -100,6 +100,7 @@ void AbilityManager::readAbilityNode(xmlNodePtr abilityNode,
int neededMana = XML::getProperty(abilityNode, "needed", 0);
int rechargeAttribute = XML::getProperty(abilityNode,
"rechargeattribute", 0);
+ bool autoconsume = XML::getBoolProperty(abilityNode, "autoconsume", true);
if (rechargeable && neededMana <= 0)
{
@@ -117,6 +118,7 @@ void AbilityManager::readAbilityNode(xmlNodePtr abilityNode,
newInfo->rechargeable = rechargeable;
newInfo->neededPoints = neededMana;
newInfo->rechargeAttribute = rechargeAttribute;
+ newInfo->autoconsume = autoconsume;
newInfo->target = getTargetByString(XML::getProperty(abilityNode, "target",
std::string()));
diff --git a/src/game-server/abilitymanager.h b/src/game-server/abilitymanager.h
index b363d1f..2d23c48 100644
--- a/src/game-server/abilitymanager.h
+++ b/src/game-server/abilitymanager.h
@@ -45,6 +45,7 @@ public:
rechargeable(false),
rechargeAttribute(0),
neededPoints(0),
+ autoconsume(true),
target(TARGET_BEING)
{}
@@ -54,6 +55,7 @@ public:
bool rechargeable;
unsigned rechargeAttribute;
unsigned neededPoints;
+ bool autoconsume;
TargetMode target;
Script::Ref rechargedCallback;
Script::Ref useCallback;