summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-04-27 18:09:51 +0200
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-05-08 14:02:51 +0200
commit06027d423e179ea3b479284c466725ed4c76ca7a (patch)
tree8ef8d2228f11fff2f98349bc4fdfb143325b4f81
parentfc5378d555dcbd68769090c399362ba913c1f634 (diff)
downloadmanaserv-06027d423e179ea3b479284c466725ed4c76ca7a.tar.gz
manaserv-06027d423e179ea3b479284c466725ed4c76ca7a.tar.xz
manaserv-06027d423e179ea3b479284c466725ed4c76ca7a.zip
[Abilities] Made a first example attack ability
-rw-r--r--example/scripts/abilities.lua22
1 files changed, 20 insertions, 2 deletions
diff --git a/example/scripts/abilities.lua b/example/scripts/abilities.lua
index 263c20c..7c25eb0 100644
--- a/example/scripts/abilities.lua
+++ b/example/scripts/abilities.lua
@@ -11,6 +11,24 @@
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)
+ local s_x, s_y = user:position()
+ -- d_x, d_y will be the relative center of the attack
+ -- (it will be 1 tile in front of the attacker)
+ local d_x, d_y = x - s_x, y - s_y
+ local length = math.sqrt(d_x * d_x + d_y * d_y)
+ d_x = d_x / length * TILESIZE
+ d_y = d_x / length * TILESIZE
+
+ local target_x, target_y = s_x + d_x, s_y + d_y
+
+ -- Attack radius is TILESIZE
+ local affected_beings = get_beings_in_circle(target_x, target_y, TILESIZE)
+ for _, being in ipairs(affected_beings) do
+ if being ~= user then
+ local old_hp = being:base_attribute(ATTR_HP)
+ local new_hp = math.max(old_hp - 5, 0)
+ being:set_base_attribute(ATTR_HP, new_hp)
+ end
+ end
end)
-spell1:on_recharged(function(ch) ch:say("Hoooooooo...") end)
+--spell1:on_recharged(function(ch) ch:say("Hoooooooo...") end)