//TESH.scrollpos=22
//TESH.alwaysfold=0
scope confusion initializer init
//CONFIGURABLE:
globals
private constant integer SPELL_ID = 'A003'
private constant integer CURSE_DUMMY = 'h002'
private constant integer CURSE_SPELL = 'A004'
private constant integer CURSE_BUFF = 'B000'
private constant real INTERVAL = 0.1
private constant real AOE_BASE = 300.
private constant real AOE_INCREMENT = 50.
private constant real SEARCH_AOE = 500.
//Note: Duration depends on CURSE_SPELL duration; change it in object editor
endglobals
//NOT SO MUCH CONFIGURABLE:
globals
private group G1 = CreateGroup()
private group G2 = CreateGroup()
private group CURSED = CreateGroup()
private timer T = CreateTimer()
private unit DUMMY
private integer COUNT = 0
private unit array TARGET
private integer ID
private player OWNER
private unit U
endglobals
private function AoE takes integer lvl returns real
return AOE_BASE + (lvl - 1) * AOE_INCREMENT
endfunction
private function SearchTargets takes nothing returns boolean
local unit picked = GetFilterUnit()
if picked != U and GetWidgetLife(picked) > 0. then
call GroupAddUnit(G2, picked)
endif
set picked = null
return false
endfunction
private function ForceAttack takes nothing returns nothing
local unit picked = GetEnumUnit()
set ID = GetUnitId(picked)
if TARGET[ID] == null or GetWidgetLife(TARGET[ID]) == 0 then
set U = picked
call GroupEnumUnitsInRange(G1, GetUnitX(picked), GetUnitY(picked), SEARCH_AOE, Filter(function SearchTargets))
set TARGET[ID] = GroupPickRandomUnit(G2)
call GroupClear(G2)
else
call ClearSelectionForPlayer(GetOwningPlayer(picked))
call IssueTargetOrder(picked, "attack", TARGET[ID])
endif
if GetUnitAbilityLevel(picked, CURSE_BUFF) == 0 then
call IssueImmediateOrder(picked, "stop")
call GroupRemoveUnit(CURSED, picked)
set COUNT = COUNT - 1
endif
set picked = null
endfunction
private function callback takes nothing returns nothing
call ForGroup(CURSED, function ForceAttack)
if COUNT == 0 then
call PauseTimer(T)
endif
endfunction
private function filterFunc takes nothing returns boolean
local unit picked = GetFilterUnit()
if IsUnitEnemy(picked, OWNER) and GetWidgetLife(picked) > 0. and IsUnitType(picked, UNIT_TYPE_MAGIC_IMMUNE) == false then
call SetUnitX(DUMMY, GetUnitX(picked))
call SetUnitY(DUMMY, GetUnitY(picked))
call IssueTargetOrder(DUMMY, "curse", picked)
call GroupAddUnit(CURSED, picked)
set COUNT = COUNT + 1
endif
set picked = null
return false
endfunction
private function actions takes nothing returns boolean
local unit caster
local integer lvl
if GetSpellAbilityId() == SPELL_ID then
set caster = GetTriggerUnit()
set lvl = GetUnitAbilityLevel(caster, SPELL_ID)
set OWNER = GetOwningPlayer(caster)
call SetUnitOwner(DUMMY, OWNER, false)
call SetUnitAbilityLevel(DUMMY, CURSE_SPELL, lvl)
if COUNT == 0 then
call TimerStart(T, INTERVAL, true, function callback)
endif
call GroupEnumUnitsInRange(G1, GetSpellTargetX(), GetSpellTargetY(), AoE(lvl), Filter(function filterFunc))
endif
set caster = null
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function actions))
set DUMMY = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), CURSE_DUMMY, 0., 0., 0.)
endfunction
endscope