1. // The spell that calls the library function
  2.  
  3. scope LightChargeScope initializer InitTrig_Light_Charge
  4.  
  5. struct Data
  6.  
  7. private real base_heal = 6
  8. private real level_factor_min = 2.4
  9. private real level_factor_max = 3.5
  10. private real level_factor_hot_min = 3.8
  11. private real level_factor_hot_max = 4.8
  12. private real spell_level
  13. private real calc_min_ins
  14. private real calc_max_ins
  15. private real calc_min_hot
  16. private real calc_max_hot
  17. private integer hot
  18. private integer instant
  19.  
  20. method calcHeal takes nothing returns nothing
  21. set .calc_min_ins = (.base_heal)*(.level_factor_min*.spell_level)
  22. set .calc_max_ins = (.base_heal)*(.level_factor_max*.spell_level)
  23. set .calc_min_hot = (.base_heal*1.5)*(.level_factor_hot_min*.spell_level)
  24. set .calc_max_hot = (.base_heal*1.5)*(.level_factor_hot_max*.spell_level)
  25. set .hot = GetRandomInt(R2I(.calc_min_hot+0.5), R2I(.calc_max_hot+0.5))
  26. set .instant = GetRandomInt(R2I(.calc_min_ins+0.5), R2I(.calc_max_ins+0.5))
  27. endmethod
  28.  
  29. static method LightChargeConditions takes nothing returns boolean
  30. if GetSpellAbilityId() == 'A003' then
  31. return true
  32. endif
  33. return false
  34. endmethod
  35.  
  36. static method startLightCharge takes nothing returns nothing
  37. local Data d = Data.create()
  38. set d.spell_level = GetUnitAbilityLevel(GetSpellAbilityUnit(),'A003')
  39. call d.calcHeal()
  40. call SetWidgetLife(GetSpellTargetUnit(), GetWidgetLife(GetSpellTargetUnit()) + d.instant)
  41. call UnitHealOverTime(GetSpellAbilityUnit(),GetSpellTargetUnit(),d.hot, 5.0, 1)
  42. call CreateHealTag(GetSpellTargetUnit(),d.instant,false)
  43. endmethod
  44.  
  45. endstruct
  46.  
  47. function InitTrig_Light_Charge takes nothing returns nothing
  48. local trigger inithot = CreateTrigger()
  49. call TriggerRegisterAnyUnitEventBJ(inithot, EVENT_PLAYER_UNIT_SPELL_EFFECT)
  50. call TriggerAddCondition(inithot, Condition(function Data.LightChargeConditions))
  51. call TriggerAddAction(inithot, function Data.startLightCharge)
  52. endfunction
  53.  
  54. endscope
  55.  
  56. // The library
  57.  
  58. library HoT initializer Init requires PHeal, spelltext
  59.  
  60. private struct Data
  61.  
  62. private unit target = null
  63. private unit caster = null
  64. private real duration = 0
  65. private real heal = 0
  66. private real tick_count = 0
  67. public timer time = null
  68. public real interval = 0
  69.  
  70. static method create takes unit caster, unit target, real heal, real duration, real interval returns Data
  71. local Data d = Data.allocate()
  72. set d.tick_count = 0
  73. set d.time = NewTimer()
  74. set d.target = target
  75. set d.caster = caster
  76. set d.heal = heal
  77. set d.interval = interval
  78. set d.duration = duration
  79. return d
  80. endmethod
  81.  
  82. static method hotRecurse takes nothing returns nothing
  83. local Data d = GetTimerData(GetExpiredTimer())
  84. local integer tick = R2I((d.heal / d.duration) * d.interval)
  85. if d.tick_count <= d.duration and not (GetWidgetLife(d.target) > 0.5) then
  86. call UnitHealTarget(d.caster, d.target, tick)
  87. call CreateHealTag(d.target, tick, false)
  88. set d.tick_count = d.tick_count + d.interval
  89. else
  90. call d.destroy()
  91. endif
  92. endmethod
  93.  
  94. method onDestroy takes nothing returns nothing
  95. set .target = null
  96. set .caster = null
  97. call ReleaseTimer(.time)
  98. endmethod
  99.  
  100. endstruct
  101.  
  102. function UnitHealOverTime takes unit caster, unit target, real heal, real duration, real interval returns nothing
  103. local Data d = Data.create(caster, target, heal, duration, interval)
  104. call SetTimerData(d.time, d)
  105. call TimerStart(d.time, d.interval, true, function Data.hotRecurse)
  106. endfunction
  107.  
  108. private function Init takes nothing returns nothing
  109. endfunction
  110. endlibrary