- Joined
- Oct 11, 2012
- Messages
- 711
Hi all. If the spell is cast on ally unit, it periodically heals ally unit and remove negative buffs from it. If being cast on enemy, it damages it periodically.
I am still learning vJass, so this spell must be too simple to you guys. I just want to know if I am coding in the right way.
I am still learning vJass, so this spell must be too simple to you guys. I just want to know if I am coding in the right way.
JASS:
scope spell
//Configuration Starts
globals
private constant integer AB_ID='A00T'
private real duration=40.
private constant real period=0.50
endglobals
private constant function Heal takes integer level returns real
return level * 50.
endfunction
private constant function Damage takes integer level returns real
return level * 10.
endfunction
private function Unit_Filter takes unit enemy, player casterOwner returns boolean
return /*
*/IsUnitEnemy(enemy,casterOwner) and /*
*/ not IsUnitType(enemy, UNIT_TYPE_MAGIC_IMMUNE) and /*
*/ not IsUnitType(enemy, UNIT_TYPE_STRUCTURE) /*
*/
endfunction
//Configuration Ends
native UnitAlive takes unit id returns boolean
globals
private hashtable ht=InitHashtable()
endglobals
private struct Rejuvenation
private timer t
private unit caster
private unit target
private real dur
private thistype next
private thistype prev
private static integer count = 0
private method destroy takes nothing returns nothing
call this.deallocate()
set this.next.prev = this.prev
set this.prev.next = this.next
set count = count - 1
if count == 0 then
if LIBRARY_TimerUtils then
call ReleaseTimer(this.t)
else
call PauseTimer(this.t)
//call DestroyTimer(this.t) Fixed this, thanks Ruke.
endif
endif
set this.caster = null
set this.target = null
//set this.t=null Fixed this accordingly
endmethod
private static method callback takes nothing returns nothing
local thistype this = thistype(0).next
loop
exitwhen this == 0
set this.dur = this.dur - period
if this.dur <= 0.00 or not UnitAlive(this.target) then
call this.destroy()
endif
if Unit_Filter(this.target,GetOwningPlayer(this.caster)) then
call UnitDamageTarget(this.caster,this.target,Damage(GetUnitAbilityLevel(this.caster,AB_ID)),true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_DEMOLITION,null)
else
call UnitRemoveBuffs(this.target,false,true)
call SetUnitState(this.target,UNIT_STATE_LIFE,GetUnitState(this.target,UNIT_STATE_LIFE)+Heal(GetUnitAbilityLevel(this.caster,AB_ID)))
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIma\\AImaTarget.mdl",this.target,"origin"))
endif
set this = this.next
endloop
endmethod
private static method run takes nothing returns nothing
local thistype this=thistype.allocate()
set this.next = 0
set this.prev = thistype(0).prev
set thistype(0).prev.next = this
set thistype(0).prev = this
set count = count + 1
if count == 1 then
static if LIBRARY_TimerUtils then
set this.t=NewTimer()
call TimerStart(this.t,period,true,function thistype.callback)
else
set this.t=CreateTimer()
call TimerStart(this.t, period, true, function thistype.callback)
endif
endif
set this.dur=duration
set this.target=GetSpellTargetUnit()
set this.caster=GetTriggerUnit()
endmethod
private static method cast takes nothing returns boolean
if GetSpellAbilityId()==AB_ID then
call thistype.run()
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function thistype.cast))
set t=null
endmethod
endstruct
endscope
Last edited: