Troll-Brain
You can change this now in User CP.
- Reaction score
- 85
I've made this because SpellStruct is truly overkilled for my needs and anyway as SpellEvent don't do all the stuff i want.
Here these lack of features :
- In SpellStruct when the ENDCAST event fire you have to figure yourself it the spell was successfully casted or interrupted before the end.
- We can't get the responses events for spells which are not registered and i don't see why ...
- We can't safely use a spell which doesn't interrupt orders and have a cast time, like windwalk if you edit the cast time.
Else the systems could bug because an unit can have more than one spell active.
- The use of Table is overkilled in SpellEvent
- The user can't define himself when the spell is ended, can be done with a simple boolean in mine and SpellEvent.
Mostly because it's really spell dependant but for triggered spell it's also handy.
PS :
Here AutoIndex and UnitListModule
Here these lack of features :
- In SpellStruct when the ENDCAST event fire you have to figure yourself it the spell was successfully casted or interrupted before the end.
- We can't get the responses events for spells which are not registered and i don't see why ...
- We can't safely use a spell which doesn't interrupt orders and have a cast time, like windwalk if you edit the cast time.
Else the systems could bug because an unit can have more than one spell active.
- The use of Table is overkilled in SpellEvent
- The user can't define himself when the spell is ended, can be done with a simple boolean in mine and SpellEvent.
Mostly because it's really spell dependant but for triggered spell it's also handy.
JASS:
library AbilitiesEvents requires AutoIndex,UnitListModule
globals
private keyword init
private keyword s_spell
private hashtable HashT
endglobals
private function interface FunctionInterface takes nothing returns nothing
globals
s_spell Spell = 0
key SPELL_CHANNEL
key SPELL_CAST
key SPELL_EFFECT
key SPELL_FINISH // if the unit had succesfully finished the spell
key SPELL_ENDCAST // if the unit abort the spell before the end
endglobals
private struct s_spell
integer abilityId = 0
unit castingUnit = null
unit targetUnit = null
item targetItem = null
destructable targetDestructable = null
real targetX = 0.
real targetY = 0.
boolean isTargetPoint = false
boolean isTargetUnit = false
boolean isTargetItem = false
boolean isTargetDestructable = false
boolean isNoTarget = false
integer targetUnitTypeId = 0
integer targetDestructableTypeId = 0
integer targetItemTypeId = 0
boolean isEnded = false
implement UnitList
private static integer Index
private static timer Tim
private thistype S
private static FunctionInterface func
private static method create takes nothing returns thistype
local thistype this = .allocate()
set .castingUnit = GetSpellAbilityUnit()
set .targetUnit = GetSpellTargetUnit()
set .abilityId = GetSpellAbilityId()
if .targetUnit != null then
set .isTargetUnit = true
set .targetUnitTypeId = GetUnitTypeId(.targetUnit)
set .targetX = GetUnitX(.targetUnit)
set .targetY = GetUnitY(.targetUnit)
else
set .targetDestructable = GetSpellTargetDestructable()
if .targetDestructable != null then
set .isTargetDestructable = true
set .targetDestructableTypeId = GetDestructableTypeId(.targetDestructable)
set .targetX = GetDestructableX(.targetDestructable)
set .targetY = GetDestructableY(.targetDestructable)
else
set .targetItem = GetSpellTargetItem()
if .targetItem != null then
set .isTargetItem = true
set .targetItemTypeId = GetItemTypeId(.targetItem)
set .targetX = GetItemX(.targetItem)
set .targetY = GetItemY(.targetItem)
else
set .isNoTarget = true
set .targetX = GetSpellTargetX()
set .targetY = GetSpellTargetY()
endif
endif
endif
call .unitListAdd(.castingUnit)
return this
endmethod
private method onDestroy takes nothing returns nothing
call .unitListRemove()
endmethod
private static method DestroyInstances takes nothing returns nothing
loop
exitwhen .Index == 0
set .Index = .Index-1
call thistype(.Index).S.destroy()
endloop
endmethod
private static method OnChannel takes nothing returns boolean
set Spell = thistype.create()
//! runtextmacro t_FindSpellFunctionInterface("SPELL_CHANNEL")
return false
endmethod
private static method OnEndCast takes nothing returns boolean
//! runtextmacro t_FindWhichSpell()
set thistype(.Index).S = Spell
set .Index = .Index+1
call TimerStart(.Tim,0.,false,function thistype.DestroyInstances)
//! runtextmacro t_FindSpellFunctionInterface("SPELL_ENDCAST")
return false
endmethod
private static method OnCast takes nothing returns boolean
//! runtextmacro t_FindWhichSpell()
//! runtextmacro t_FindSpellFunctionInterface("SPELL_CAST")
return false
endmethod
private static method OnEffect takes nothing returns boolean
//! runtextmacro t_FindWhichSpell()
//! runtextmacro t_FindSpellFunctionInterface("SPELL_EFFECT")
return false
endmethod
private static method OnFinish takes nothing returns boolean
//! runtextmacro t_FindWhichSpell()
set Spell.isEnded = true
//! runtextmacro t_FindSpellFunctionInterface("SPELL_FINISH")
return false
endmethod
implement init
endstruct
function RegisterSpellEvent takes integer whichEvent, integer whichSpell, FunctionInterface whichFunc returns nothing
call SaveInteger(HashT,whichEvent,whichSpell,integer(whichFunc))
endfunction
private module init
static method onInit takes nothing returns nothing
local trigger trig
//! runtextmacro t_CreateSpellsTriggers("OnChannel","EVENT_PLAYER_UNIT_SPELL_CHANNEL")
//! runtextmacro t_CreateSpellsTriggers("OnCast","EVENT_PLAYER_UNIT_SPELL_CAST")
//! runtextmacro t_CreateSpellsTriggers("OnEffect","EVENT_PLAYER_UNIT_SPELL_EFFECT")
//! runtextmacro t_CreateSpellsTriggers("OnFinish","EVENT_PLAYER_UNIT_SPELL_FINISH")
//! runtextmacro t_CreateSpellsTriggers("OnEndCast","EVENT_PLAYER_UNIT_SPELL_ENDCAST")
set .Tim = CreateTimer()
set HashT = InitHashtable()
endmethod
endmodule
//! textmacro t_FindWhichSpell
set Spell = s_spell.unitFirst(GetSpellAbilityUnit())
loop
exitwhen Spell.abilityId == GetSpellAbilityId()
set Spell = Spell.unitNext
endloop
//! endtextmacro
//! textmacro t_CreateSpellsTriggers takes NAME , EVENT
set trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trig,$EVENT$)
call TriggerAddCondition(trig,function thistype.$NAME$)
//! endtextmacro
//! textmacro t_FindSpellFunctionInterface takes EVENT
set .func = FunctionInterface(LoadInteger(HashT,$EVENT$,Spell.abilityId))
if .func != 0 then
call .func.execute()
endif
return false
//! endtextmacro
endlibrary
PS :
Here AutoIndex and UnitListModule