library Psychic initializer init requires RepeatData, AutoIndex
/*
spell Write by Dorae.Mun
Requires RepeatData
AutoIndex
*/
globals
private constant real DAMAGE=100 //Ability Damage
private constant real TIME=.03 //Time loop
private constant real RANGE=700 //Area of effect
private constant string FX="Models\\PsychicTarget.mdl"
private constant string SFX="Models\\GrandUndeadAura.mdl"
private constant string SFX2="Models\\NewGroundEX.mdx"
private constant attacktype ATT=ATTACK_TYPE_HERO
private constant damagetype DMT=DAMAGE_TYPE_MAGIC
endglobals
function trig_con takes nothing returns boolean
return ( GetSpellAbilityId() == 'A000' )
endfunction
private struct Psychic extends RepeatData
unit caster
boolean isfly
real fly
integer face
group eG
group eG2
group eG3
real xx
real yy
unit dum
effect deff
private static effect array def
method isLoop takes nothing returns nothing
local unit e
local real x
local real y
local real dx
local real dy
call GroupAddGroup(this.eG,this.eG3)
//set this.eG3=this.eG
loop
set e=FirstOfGroup(this.eG3)
exitwhen e==null
set x=GetUnitX(e)
set y=GetUnitY(e)
set dx=x+GetRandomReal(0,10)*Cos((GetUnitFacing(e))*bj_DEGTORAD)
set dy=y+GetRandomReal(0,10)*Sin((GetUnitFacing(e))*bj_DEGTORAD)
call UnitAddAbility(e,'Amrf')
call SetUnitPosition(e,dx,dy)
call SetUnitFlyHeight(e,this.fly,0)
call SetUnitAnimationByIndex(e,(-1*this.face))
call UnitRemoveAbility(e,'Amrf')
call GroupRemoveUnit(this.eG3,e)
endloop
if this.isfly==true then
if this.fly>=600 then
set this.isfly=false
endif
set this.fly=this.fly+6
set this.face=this.face+2
else
if this.fly<=0 then
call this.stop()
endif
set this.fly=this.fly-100
endif
call GroupClear(this.eG3)
set e=null
endmethod
method isStart takes nothing returns nothing
local unit e
call PauseUnit(this.caster,true)
set this.dum=CreateUnit(Player(15),'h000',this.xx,this.yy,0)
set this.deff=AddSpecialEffectTarget(SFX,this.dum,"origin")
call GroupEnumUnitsInRange(this.eG2,this.xx,this.yy,RANGE,null)
loop
set e=FirstOfGroup(this.eG2)
exitwhen e==null
if IsUnitEnemy(e,GetOwningPlayer(this.caster)) and GetWidgetLife(e)>0.405 and IsUnitType(e,UNIT_TYPE_STRUCTURE)==false then
call GroupAddUnit(this.eG,e)
call PauseUnit(e,true)
call SetUnitTimeScalePercent(e,0)
set def[GetUnitId(e)]=AddSpecialEffectTarget(FX,e,"chest")
endif
call GroupRemoveUnit(this.eG2,e)
endloop
call GroupClear(this.eG2)
set e=null
endmethod
method isEnd takes nothing returns nothing
local unit e
call PauseUnit(this.caster,false)
loop
set e=FirstOfGroup(this.eG)
exitwhen e==null
call DestroyEffect(this.def[GetUnitId(e)])
call UnitDamageTarget(this.caster,e,DAMAGE,false,false,ATT,DMT,null)
call SetUnitAnimationByIndex(e,0)
call PauseUnit(e,false)
call SetUnitTimeScalePercent(e,100)
call DestroyEffect(AddSpecialEffect(SFX2,GetUnitX(e),GetUnitY(e)))
call GroupRemoveUnit(this.eG,e)
endloop
call RemoveUnit(this.dum)
call DestroyEffect(this.deff)
call GroupClear(this.eG)
call GroupClear(this.eG2)
call GroupClear(this.eG3)
call DestroyGroup(this.eG)
call DestroyGroup(this.eG2)
call DestroyGroup(this.eG3)
set this.dum=null
set this.caster=null
set e=null
endmethod
endstruct
function trig_act takes nothing returns nothing
local unit cast=GetTriggerUnit()
local real x=GetUnitX(cast)
local real y=GetUnitY(cast)
local Psychic this=Psychic.create(TIME,0) // struct will loop until use 'call this.stop'
set this.caster=cast // save variable cast with name this.caster
set this.isfly=true
set this.fly=0
set this.face=0
set this.eG=CreateGroup()
set this.eG2=CreateGroup()
set this.eG3=CreateGroup()
set this.xx=x
set this.yy=y
set cast=null
endfunction
//===========================================================================
function init takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( trig, Condition( function trig_con ) )
call TriggerAddAction( trig, function trig_act )
set trig=null
endfunction
endlibrary