Name | Type | is_array | initial_value |
library UnitBlindTarget
globals
private constant integer DUMMY_ID = 'e000'
private constant integer ABIL_ID = 'A002'
private constant integer BUFF_ID = 'B001'
private integer UNSELECTABLE = 'Aloc'
private constant integer ORDER_ID = 852190
private constant timer TIMER = CreateTimer()
private constant group GROUP = CreateGroup()
private constant real TIME = .031250000
private unit DUMMY
real array BLIND_RESISTANCE
endglobals
private struct BlindTarget
static integer i1 = 0
static integer i2 = 0
static integer i3 = 0
static integer array i4
static unit array u
static real array d
static method callback takes nothing returns boolean
local integer i = 1
loop
exitwhen i > i1
set .i3 = .i4[i]
if .d[.i3] <= 0.0 or IsUnitType(.u[.i3],UNIT_TYPE_DEAD) then
call UnitRemoveAbility(.u[.i3],BUFF_ID)
call GroupRemoveUnit(GROUP,.u[.i3])
set .i4[i] = .i4[.i1]
set .i4[.i1] = i3
set .i1 = .i1 - 1
set i = i - 1
if .i1 == 0 then
call PauseTimer(TIMER)
endif
else
set .d[.i3] = .d[.i3] - TIME
endif
set i = i + 1
endloop
return false
endmethod
static method Exe takes unit target,real duration,boolean stack returns boolean
local integer i = 0
local integer id = GetUnitUserData(target)
local real r = (duration/100.0)*BLIND_RESISTANCE[id]
if IsUnitInGroup(target,GROUP)then
set i = 1
loop
exitwhen i > .i1
set .i3 = .i4[i]
if target == .u[.i3] then
if stack then
set .d[.i3] = .d[.i3] + duration-r
else
set .d[.i3] = duration-r
endif
endif
set i = i + 1
endloop
else
if .i1 == 0 then
call TimerStart(TIMER,TIME,true,function BlindTarget.callback)
endif
set .i1 = .i1 + 1
if .i1 > .i2 then
set .i4[.i1] = .i1
set .i2 = .i1
endif
set .i3 = .i4[.i1]
set .u[.i3] = target
set .d[.i3] = duration-r
call SetUnitX(DUMMY,GetUnitX(target))
call SetUnitY(DUMMY,GetUnitY(target))
call IssueTargetOrderById(DUMMY,ORDER_ID,target)
call GroupAddUnit(GROUP,target)
endif
return false
endmethod
static method onInit takes nothing returns nothing
set DUMMY = CreateUnit(Player(15),DUMMY_ID,0.,0.,0.)
call UnitAddAbility(DUMMY,ABIL_ID)
if 0 == GetUnitAbilityLevel(DUMMY,UNSELECTABLE) then
call UnitAddAbility(DUMMY,UNSELECTABLE)
endif
endmethod
endstruct
function IsUnitBlinded takes unit target returns boolean
return IsUnitInGroup(target,GROUP)
endfunction
function UnitBlindTargetStack takes unit target,real duration returns nothing
call BlindTarget.Exe(target,duration,true)
endfunction
function UnitBlindTargetNonStack takes unit target,real duration returns nothing
call BlindTarget.Exe(target,duration,false)
endfunction
endlibrary
function Trig_TEST_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
call UnitBlindTargetStack(GetTriggerUnit(),3.0)
set u = null
endfunction
//===========================================================================
function InitTrig_How_to_use takes nothing returns nothing
set gg_trg_How_to_use = CreateTrigger( )
call TriggerRegisterPlayerSelectionEventBJ( gg_trg_How_to_use, Player(0), true )
call TriggerAddAction( gg_trg_How_to_use, function Trig_TEST_Actions )
endfunction