scope PoisonArrow initializer Arrow
globals
private integer idSpell = 'A02A'
private integer idDummy = 'h015'
endglobals
private struct data
unit hero
unit dummy
real x
real y
real angle
group H
integer tick
timer t
endstruct
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == idSpell
endfunction
private function removetree takes nothing returns nothing
call KillDestructable( GetEnumDestructable() )
endfunction
private function MoveArrow takes nothing returns nothing
local timer t = GetExpiredTimer()
local data d = GetTimerData(t)
local group g = CreateGroup()
local integer lv = GetUnitAbilityLevel(d.hero,idSpell)
local integer lvl = GetUnitLevel(d.hero)
local real x = d.x
local real y = d.y
local real tx
local real ty
local unit temp
local location p
set p = GetUnitLoc(d.dummy)
call EnumDestructablesInCircleBJ(58,p,function removetree )
call RemoveLocation(p)
if d.tick < 200 then
set tx=x+20*d.tick*Cos(d.angle*bj_DEGTORAD)
set ty=y+20*d.tick*Sin(d.angle*bj_DEGTORAD)
call SetUnitPosition(d.dummy,tx,ty)
call GroupEnumUnitsInRange(g,tx,ty,100,null)
loop
set temp = FirstOfGroup(g)
exitwhen temp == null
if IsUnitEnemy(temp , GetOwningPlayer(d.dummy)) and IsUnitInGroup(temp, d.H) != true then
call UnitDamageTargetBJ(d.dummy,temp,DAMAGE(lv,lvl), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
call GroupRemoveUnit(g,temp)
endif
call GroupAddUnit(d.H,temp)
call GroupRemoveUnit(g,temp)
endloop
call DestroyGroup(g)
set temp = null
else
call RemoveUnit(d.dummy)
call GroupRemoveGroup(d.H,d.H)
call DestroyGroup(d.H)
set d.hero = null
set d.dummy = null
set d.H = null
call ReleaseTimer(d.t)
call d.destroy()
endif
call DestroyGroup(g)
set temp = null
set d.tick = d.tick + 1
set t = null
set p = null
endfunction
private function Actions takes nothing returns nothing
local data d = data.create()
local unit hero = GetSpellAbilityUnit()
local real x = GetUnitX(hero)
local real y = GetUnitY(hero)
local real tx = GetSpellTargetX()
local real ty = GetSpellTargetY()
local integer lv = GetUnitAbilityLevel(hero,idSpell)
local integer lvl = GetUnitLevel(hero)
local real angle = bj_RADTODEG*Atan2(ty-y,tx-x)
set d.hero = hero
set d.x = x
set d.y = y
set d.angle = angle
set d.dummy = CreateUnit(GetOwningPlayer(hero),idDummy,x,y,angle)
set d.tick = 1
set d.t = NewTimer()
set d.H = CreateGroup()
call SetTimerData(d.t,d)
call TimerStart(d.t,0.01,true,function MoveArrow )
set hero = null
endfunction
//===========================================================================
private function Arrow takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Conditions ) )
call TriggerAddAction( t, function Actions )
endfunction
endscope