// The spell that calls the library function
scope LightChargeScope initializer InitTrig_Light_Charge
struct Data
private real base_heal = 6
private real level_factor_min = 2.4
private real level_factor_max = 3.5
private real level_factor_hot_min = 3.8
private real level_factor_hot_max = 4.8
private real spell_level
private real calc_min_ins
private real calc_max_ins
private real calc_min_hot
private real calc_max_hot
private integer hot
private integer instant
method calcHeal takes nothing returns nothing
set .calc_min_ins = (.base_heal)*(.level_factor_min*.spell_level)
set .calc_max_ins = (.base_heal)*(.level_factor_max*.spell_level)
set .calc_min_hot = (.base_heal*1.5)*(.level_factor_hot_min*.spell_level)
set .calc_max_hot = (.base_heal*1.5)*(.level_factor_hot_max*.spell_level)
set .hot = GetRandomInt(R2I(.calc_min_hot+0.5), R2I(.calc_max_hot+0.5))
set .instant = GetRandomInt(R2I(.calc_min_ins+0.5), R2I(.calc_max_ins+0.5))
endmethod
static method LightChargeConditions takes nothing returns boolean
if GetSpellAbilityId() == 'A003' then
return true
endif
return false
endmethod
static method startLightCharge takes nothing returns nothing
local Data d = Data.create()
set d.spell_level = GetUnitAbilityLevel(GetSpellAbilityUnit(),'A003')
call d.calcHeal()
call SetWidgetLife(GetSpellTargetUnit(), GetWidgetLife(GetSpellTargetUnit()) + d.instant)
call UnitHealOverTime(GetSpellAbilityUnit(),GetSpellTargetUnit(),d.hot, 5.0, 1)
call CreateHealTag(GetSpellTargetUnit(),d.instant,false)
endmethod
endstruct
function InitTrig_Light_Charge takes nothing returns nothing
local trigger inithot = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(inithot, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(inithot, Condition(function Data.LightChargeConditions))
call TriggerAddAction(inithot, function Data.startLightCharge)
endfunction
endscope
// The library
library HoT initializer Init requires PHeal, spelltext
private struct Data
private unit target = null
private unit caster = null
private real duration = 0
private real heal = 0
private real tick_count = 0
public real interval = 0
static method create takes unit caster, unit target, real heal, real duration, real interval returns Data
local Data d = Data.allocate()
set d.tick_count = 0
set d.target = target
set d.caster = caster
set d.heal = heal
set d.interval = interval
set d.duration = duration
return d
endmethod
static method hotRecurse takes nothing returns nothing
local Data d = GetTimerData(GetExpiredTimer())
local integer tick = R2I((d.heal / d.duration) * d.interval)
if d.tick_count <= d.duration and not (GetWidgetLife(d.target) > 0.5) then
call UnitHealTarget(d.caster, d.target, tick)
call CreateHealTag(d.target, tick, false)
set d.tick_count = d.tick_count + d.interval
else
call d.destroy()
endif
endmethod
method onDestroy takes nothing returns nothing
set .target = null
set .caster = null
endmethod
endstruct
function UnitHealOverTime takes unit caster, unit target, real heal, real duration, real interval returns nothing
local Data d = Data.create(caster, target, heal, duration, interval)
call SetTimerData
(d.
time, d
) call TimerStart
(d.
time, d.interval,
true,
function Data.hotRecurse
) endfunction
private function Init takes nothing returns nothing
endfunction
endlibrary