local combat = createCombatObject()
function Position:getDirectionTo(toPosition)
local dir = NORTH
if(self.x > toPosition.x) then
dir = WEST
if(self.y > toPosition.y) then
dir = NORTHWEST
elseif(self.y < toPosition.y) then
dir = SOUTHWEST
end
elseif(self.x < toPosition.x) then
dir = EAST
if(self.y > toPosition.y) then
dir = NORTHEAST
elseif(self.y < toPosition.y) then
dir = SOUTHEAST
end
else
if(self.y > toPosition.y) then
dir = NORTH
elseif(self.y < toPosition.y) then
dir = SOUTH
end
end
return dir
end
local diagonals = {NORTHWEST, SOUTHWEST, NORTHEAST, SOUTHEAST}
function onCastSpell(cid, var)
if doCombat(cid, combat, var) then
local creature, target = Creature(cid), Creature(var:getNumber())
if not target then return true end
local level, maglevel = creature:getLevel(), creature:getMagicLevel()
local min = -((level / 5) + (maglevel * 1.4) + 8)
local max = -((level / 5) + (maglevel * 2.2) + 14)
local creature_pos, effect_pos = creature:getPosition(), target:getPosition()
local diagonal = math.abs(effect_pos.x - creature_pos.x) > 0 and math.abs(effect_pos.y - creature_pos.y) > 0
local distance = getDistanceBetween(effect_pos, creature_pos) - 1
doAreaCombatHealth(cid, COMBAT_ENERGYDAMAGE, effect_pos, 0, min, max, CONST_ME_ENERGYAREA)
for i = 1, distance > 4 and 4 or distance do
local direction = effect_pos:getDirectionTo(creature_pos)
if (diagonal and isInArray(diagonals, direction)) or (not diagonal and not isInArray(diagonals, direction)) then
effect_pos:getNextPosition(direction, 1)
doAreaCombatHealth(cid, COMBAT_ENERGYDAMAGE, effect_pos, 0, min, max, CONST_ME_ENERGYAREA)
end
end
return true
end
return false
end