From 06027d423e179ea3b479284c466725ed4c76ca7a Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Sat, 27 Apr 2013 18:09:51 +0200 Subject: [Abilities] Made a first example attack ability --- example/scripts/abilities.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'example') 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) -- cgit