- Joined
- Apr 23, 2011
- Messages
- 460
After reading through other spells, and tutorials and what not, I have come up with this, and I'm not exactly sure what could be wrong with it... ideas to fix? Or just trash it.
JASS:
library ArcDrain initializer init uses RegisterPlayerUnitEvent
globals
private constant integer SPELL_ID = 'ArcD'
private constant integer BUFF_ID = 'Arcs'
private constant real MSPEED = .35
private constant real TIMERTIME = 4.
private constant real TURNOVER = .25
endglobals
struct ArcDrain
private real TIMEOUT
private boolean DEALLOCATEME
private timer TIMER
private unit CASTER
private unit TARGET
private real DRAIN
private method destroy takes nothing returns nothing
set this.CASTER = null
set this.TARGET = null
set this.TIMER = null
call this.deallocate()
endmethod
private method drainer takes nothing returns nothing
if this.TIMEOUT <= 0 then
call DestroyTimer(this.TIMER)
set this.DEALLOCATEME = true
endif
call SetUnitState(this.TARGET, UNIT_STATE_MANA, (GetUnitState(this.TARGET, UNIT_STATE_MANA) - this.DRAIN))
call SetUnitState(this.CASTER, UNIT_STATE_MANA, (GetUnitState(this.CASTER, UNIT_STATE_MANA) + R2I(this.DRAIN * TURNOVER)))
set this.TIMEOUT = this.TIMEOUT - 1
if this.DEALLOCATEME then
call this.deallocate()
endif
endmethod
private static method periodic takes nothing returns nothing
local thistype this
call this.drainer()
endmethod
private static method spell takes nothing returns nothing
local thistype this = thistype.create()
set this.CASTER = GetSpellAbilityUnit()
set this.TARGET = GetSpellTargetUnit()
set this.DRAIN = ((GetUnitAbilityLevel(this.CASTER, SPELL_ID)*20)+50)
if not IsUnitType(this.TARGET, UNIT_TYPE_DEAD) and not IsUnitAlly(this.TARGET, Player(GetPlayerId(GetOwningPlayer(this.CASTER)))) then
call UnitAddAbility(this.TARGET, BUFF_ID)
set this.TIMER = CreateTimer()
set this.TIMEOUT = TIMERTIME
call TimerStart(this.TIMER, 1., true, function thistype.periodic)
else
call .destroy()
endif
endmethod
static method cast takes nothing returns nothing
if GetSpellAbilityId() == SPELL_ID then
call thistype.spell()
return
endif
endmethod
endstruct
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST, function ArcDrain.cast)
set t = null
endfunction
endlibrary