library OnDamage initializer i requires DamageEvent
globals
private unit array Source
private unit array Target
private real array Amount
private boolean array Spell
private boolean array AoE
private boolean array DoT
private integer Count = 0
boolean SPLL = false
boolean AOE = false
boolean DOT = false
boolean DamageMod = false
endglobals
function DealDamage takes unit source,unit target,real amount, boolean spell,boolean aoe,boolean dot returns nothing
if DamageMod then
set Count = Count + 1
set Source[Count] = source
set Target[Count] = target
set Amount[Count] = amount
set Spell[Count] = spell
set AoE[Count] = aoe
set DoT[Count] = dot
else
set SPLL = spell
set AOE = aoe
set DOT = dot
set DamageMod = true
call UnitDamageTarget(source,target,amount,true,true,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
set DamageMod = false
set SPLL = false
set AOE = false
set DOT = false
endif
endfunction
private function OnDamage_Actions takes nothing returns nothing
if not(SPLL) and not(AOE) and not(DOT) then//Basic attack
if GetUnitAbilityLevel(source,'A016') > 0 then
call AddUnitState(source,UNIT_STATE_MANA,GetHeroInt(source,true))
endif
endif
set DamageMod = false
if Count > 0 then
set SPLL = Spell[Count]
set AOE = AoE[Count]
set DOT = DoT[Count]
set Count = Count - 1
call UnitDamageTarget(Source[Count+1],Target[Count+1],Amount[Count+1],true,true,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
set SPLL = false
set AOE = false
set DOT = false
endif
endfunction
private function i takes nothing returns nothing
call AddDamageHandler(function OnDamage_Actions)
endfunction
endlibrary