globals
timer kamuiTimer // timer
integer kamuiCount // counter
unit kamuiCaster // casting unit
unit kamuiVictim // casting unit
unit kamuiProtectile// casting unit
real kamuiDX // normalized x component of the moving path
real kamuiDY // normalized y component of the moving path
real kamuiX // caster x position, we save this, so the caster can walk while the spell is executing
real kamuiY // caster y position, we save this, so the caster can walk while the spell is executing
endglobals
function Trig_Kamui_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'YOURSPELLABILITYID' ) ) then
return false
endif
return true
endfunction
function exeKamui takes nothing returns nothing
local real range = 800 // range in wc3 units
local real speed = 256 // speed = length/second
local real width = 75 // the width of the path to search for targets
local real stunTime = 5 // stun time in seconds
local real dmgV = 1300 // damage to victim
local real dmgC = 250 // damage to caster
local group g = CreateGroup()
local unit u
local real curX
local real curY
set speed = speed*0.035
if kamuiVictim==null then
// no victim found yet
if range-speed*I2R(kamuiCount)<=0 then
// we reached the end without victim, clean up
call PauseTimer(kamuiTimer)
call DestroyTimer(kamuiTimer)
call RemoveUnit(kamuiProtectile)
else
// run; set current position
set curX = kamuiX-kamuiDX*speed*I2R(kamuiCount)
set curY = kamuiY-kamuiDY*speed*I2R(kamuiCount)
call SetUnitX(kamuiProtectile, curX)
call SetUnitY(kamuiProtectile, curY)
// look for units
call GroupEnumUnitsInRange(g, curX, curY, width/2, null)
loop
set u = FirstOfGroup(g)
exitwhen u==null
// found a unit, check if its hostile, alive and not magic immune
if IsUnitEnemy(u, GetOwningPlayer(kamuiCaster)) and GetUnitState(u, UNIT_STATE_LIFE)>0 and not(IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)) then
// we have found a victim, harhar :D, pause it
call PauseUnit(u, true)
set kamuiVictim = u
call RemoveUnit(kamuiProtectile)
// set counter to zero, so we can count 5 seconds stun
set kamuiCount = 0
// clear group, so we cant find more then one victim ;-)
call GroupClear(g)
endif
// next unit
call GroupRemoveUnit(g, u)
endloop
endif
else
// we got a victim
set stunTime = stunTime/0.035
if I2R(kamuiCount)>=stunTime then
// we reached 5 seconds, unpause
call PauseUnit(kamuiVictim, false)
// deal dmg
call UnitDamageTarget(kamuiCaster, kamuiVictim, dmgV, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
call UnitDamageTarget(kamuiCaster, kamuiCaster, dmgC, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
// clean up
call PauseTimer(kamuiTimer)
call DestroyTimer(kamuiTimer)
endif
endif
set kamuiCount = kamuiCount+1
call DestroyGroup(g)
set g = null
endfunction
function Trig_Kamui_Actions takes nothing returns nothing
local integer protType = 'PROTECTILEUNITTYPE'
// first get target point
local real dist
local location loc = GetSpellTargetLoc()
set kamuiDX = GetLocationX(loc)
set kamuiDY = GetLocationY(loc)
call RemoveLocation(loc)
set loc = null
// set vars for timer
set kamuiVictim = null
set kamuiCaster = GetTriggerUnit()
set kamuiCount = 0
set kamuiX = GetUnitX(kamuiCaster)
set kamuiY = GetUnitY(kamuiCaster)
// get normalized vector for path
set kamuiDX = kamuiX-kamuiDX
set kamuiDY = kamuiY-kamuiDY
set dist = SquareRoot(kamuiDX*kamuiDX+kamuiDY*kamuiDY)
// DIV by 0!
if dist == 0 then
return
endif
set kamuiDX=kamuiDX/dist
set kamuiDY=kamuiDY/dist
// init protectile
set kamuiProtectile = CreateUnit(GetOwningPlayer(kamuiCaster), protType, kamuiX, kamuiY, 0)
// init and start timer
set kamuiTimer = CreateTimer()
call TimerStart(kamuiTimer, 0.035, true, function exeKamui)
endfunction
//===========================================================================
function InitTrig_Kamui takes nothing returns nothing
set gg_trg_Kamui = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Kamui, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Kamui, Condition( function Trig_Kamui_Conditions ) )
call TriggerAddAction( gg_trg_Kamui, function Trig_Kamui_Actions )
endfunction