scope Conceal initializer init
/*
During a "udg_UnitTypeEvent", GetUnitTypeId() will return the id the unit has morphed into. If you wish to
retrieve the previous ID, refer to the variable UnitTypeOf[UDex].
*/
globals
private constant integer UNIT_ID_NORMAL = 'h00Q'
private constant integer UNIT_ID_MORPHED = 'h00U'
private constant real AURA_RADIUS = 750.
private constant integer INVIS_ABIL = 'Apiv'
private constant integer ABIL_ID = 'A077'
private Table auraStorage = 0
endglobals
private struct AuraBuff extends AuraSysBuff
private static constant string TARGET_EFFECT = ""
private boolean removeInvis
// called when this buff is applied to an unit the first time
method on_apply takes nothing returns nothing
call BJDebugMsg("apply")
set this.removeInvis = false
if UnitAddAbility(this.as_target, INVIS_ABIL) then
set this.removeInvis = true
endif
endmethod
// called when the last AuraSys that inflicts this buff is removed from an unit
method on_remove takes nothing returns nothing
call BJDebugMsg("remove")
if this.removeInvis then
call UnitRemoveAbility(this.as_target, INVIS_ABIL)
endif
endmethod
endstruct
private struct AuraNode extends AuraSysNode
// called everytime a new AuraSys is added to the buff
method on_apply takes nothing returns nothing
endmethod
// called everytime an AuraSys is removed from the buff
method on_remove takes nothing returns nothing
endmethod
endstruct
private struct Aura extends AuraSys
implement AuraSysInit
private static constant integer BUFF_SPELL_ID = 'A0D6'
private static constant integer BUFF_ID = 'B01F'
method get_range takes nothing returns real
return AURA_RADIUS
endmethod
method active_cond takes nothing returns boolean
return UnitAlive(this.as_source)
endmethod
method filter takes unit u returns boolean
return IsUnitAlly(u, GetOwningPlayer(this.as_source)) and (not IsUnitType(u, UNIT_TYPE_STRUCTURE)) and UnitAlive(u) and (not IsUnitType(u, UNIT_TYPE_FLYING))
endmethod
method linger_filter takes unit u returns boolean
return UnitAlive(u)
endmethod
method new_node takes nothing returns AuraSysNode
return AuraNode.create()
endmethod
method new_buff takes nothing returns AuraSysBuff
return AuraBuff.create()
endmethod
method get_buff_typeid takes nothing returns integer
return AuraBuff.typeid
endmethod
method on_apply takes nothing returns nothing
endmethod
method on_remove takes nothing returns nothing
endmethod
endstruct
private function onMorph takes nothing returns nothing
local unit u = udg_UDexUnits[udg_UDex]
local integer uID = GetUnitTypeId(u)
local Aura aura
if uID == UNIT_ID_MORPHED then
call BJDebugMsg("new aura")
set aura = Aura.new(u)
set auraStorage[GetHandleId(u)] = aura
elseif uID == UNIT_ID_NORMAL then // alway check id in the else if because UnitType event happens for every morph.
set aura = auraStorage[GetHandleId(u)]
if aura != 0 then
call BJDebugMsg("delete aura")
call aura.delete()
call auraStorage.remove(GetHandleId(u))
endif
endif
set u = null
endfunction
private function onIndex takes nothing returns nothing
local Aura aura = Aura.new(udg_UDexUnits[udg_UDex])
set auraStorage[GetHandleId(udg_UDexUnits[udg_UDex])] = aura
endfunction
private function init takes nothing returns nothing
local trigger eventListener = CreateTrigger()
call TriggerRegisterVariableEvent(eventListener, "udg_UnitTypeEvent", EQUAL, 1.00)
call TriggerAddCondition(eventListener, function onMorph)
set auraStorage = Table.create()
call RegisterSpellIndexEvent(ABIL_ID, function onIndex)
endfunction
endscope