summaryrefslogtreecommitdiff
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-08-26 22:56:46 +0200
commit163c438e4f373989a8a82e47f38ac67d70b5a1bf (patch)
tree61ae2831e4ee89d127fbea3fbbeed161f2d0fddb
parent81f126ae001b1446dc0be37341f133dca5ab2923 (diff)
downloadmanaserv-163c438e4f373989a8a82e47f38ac67d70b5a1bf.tar.gz
manaserv-163c438e4f373989a8a82e47f38ac67d70b5a1bf.tar.bz2
manaserv-163c438e4f373989a8a82e47f38ac67d70b5a1bf.tar.xz
manaserv-163c438e4f373989a8a82e47f38ac67d70b5a1bf.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 263c20ce..7c25eb09 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)