- Joined
- Mar 10, 2009
- Messages
- 5,016
SOLVED!
This is my first ever vJASS struct spell, its a simple Damage Over Time...
My questions are;
1. Instead of using create, I can use allocate?
2. Why cant I use private static method?
3. Instead of "this" whreas I can use .u OR .r , I can assign for example "dot" whereas I can use dot.u OR dot.r, so is this always the case?
4. Did I release the timer correctly?
5. I really dont want to use TimerUtils, what are my options besides hashtables?
This is my first ever vJASS struct spell, its a simple Damage Over Time...
JASS:
library DoT initializer init uses TimerUtils
globals
private constant integer DOT_SPELLID = 'A000'
private constant string SFX = "Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeEmbers.mdl"
private constant string ATTPNT = "chest"
private constant attacktype ATT = ATTACK_TYPE_CHAOS
private constant damagetype DAM = DAMAGE_TYPE_FIRE
private constant real DURSPEED = 0.5
endglobals
private constant function DOT_DAMAGE takes integer i returns real
return 10. + i * 5
endfunction
private constant function DOT_DURATION takes integer i returns real
return 5. + i * 3
endfunction
private struct DamOT
unit u
unit t
real dam
real dur
integer level
effect sfx
static method action takes nothing returns nothing
local timer t = GetExpiredTimer()
local thistype this = GetTimerData(t)
if .dur > 0 and GetWidgetLife(.t) > 0.405 then
set .dur = .dur - DURSPEED
call UnitDamageTarget(.u, .t, .dam, false, false, ATT, DAM, null)
call BJDebugMsg("remaining time is " + R2S(.dur))
call BJDebugMsg("damage is " + R2S(.dam))
else
call ReleaseTimer(t)
call DestroyEffect(.sfx)
endif
set t = null
endmethod
static method creates takes nothing returns thistype
local thistype this = thistype.create()
local timer t = NewTimer()
set .u= GetTriggerUnit()
set .t = GetSpellTargetUnit()
set .level = GetUnitAbilityLevel(.u, DOT_SPELLID)
set .dam = DOT_DAMAGE(.level)
set .dur = DOT_DURATION(.level)
set .sfx = AddSpecialEffectTarget(SFX, .t, ATTPNT)
call SetTimerData(t, this)
call TimerStart(t, DURSPEED, true, function thistype.action)
set t = null
return this
endmethod
endstruct
private function DOT_CAST takes nothing returns boolean
if GetSpellAbilityId()==DOT_SPELLID then
call DamOT.creates()
endif
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, function DOT_CAST)
set t = null
endfunction
endlibrary
My questions are;
1. Instead of using create, I can use allocate?
2. Why cant I use private static method?
3. Instead of "this" whreas I can use .u OR .r , I can assign for example "dot" whereas I can use dot.u OR dot.r, so is this always the case?
4. Did I release the timer correctly?
5. I really dont want to use TimerUtils, what are my options besides hashtables?
Last edited: