- Joined
- Apr 5, 2011
- Messages
- 245
Periodic Effect v1.1 (uses Indexer)
W.I.P.
Few words about:
- Allows dynamic register of periodic effects
(This means, you don't have to spend indexes on spells not present in the game while their codes are generated)
- No hashtables
(Less memory used)
Q: Why this is still W.I.P.?
A: This does not have internal overlap yet
(Version 10.0 coming )
Main code:
Example of usage:
W.I.P.
Few words about:
- Allows dynamic register of periodic effects
(This means, you don't have to spend indexes on spells not present in the game while their codes are generated)
- No hashtables
(Less memory used)
Q: Why this is still W.I.P.?
A: This does not have internal overlap yet
(Version 10.0 coming )
Main code:
JASS:
//======================
//=== PeriodicEffect ===
//======= v1.100 =======
/*************************************************************************
* Modules
* module PeriodicEffect
* (Should be implemented after called methods)
* Local user interface (requires PeriodicEffect module)
* static method RegisterPeriodicEffect takes nothing returns nothing
* - Registers thistype periodic effect
* static method UnitApplyPeriodicEffect takes unit target, unit caster, integer instances, real period, integer data returns nothing
* - Applies thistype periodic effect to the target unit
* static method onPeriodicEffect takes nothing returns nothing
* - Called when thistype periodic effect proces
* static method onEndPeriodicEffect takes nothing returns nothing
* - Called when thistype periodic effect ends
* Global user interface
* function GetPeriodicEffectTarget takes nothing returns unit
* - Returns target unit of the periodic effect executed
* function GetPeriodicEffectCaster takes nothing returns unit
* - Returns caster of the periodic effect executed
* function GetPeriodicEffectData takes nothing returns integer
* - Returns data of the periodic effect executed
* function GetPeriodicEffectTickCount takes nothing returns integer
* - Returns current tick count of the periodic effect executed
* Local spec interface
* readonly integer SPEC_PERIODIC_EFFECT_CODE
* - Stores thistype periodic effect code
* Global spec interface
* function UnitApplySpecPeriodicEffect takes integer CODE, unit target, unit caster, integer instances, real period, integer data returns nothing
* - Applies specified periodic effect to the target unit
*************************************************************************/
library PeriodicEffect initializer Init requires Indexer
globals
private integer Types
private trigger array EffectTrigger
private trigger array EndEffectTrigger
private integer Indexer
private integer array Code
private unit array Target
private unit array Caster
private integer array Data
private integer array TickCount
private timer array TickTimer
private integer WorkInteger
endglobals
private function Init takes nothing returns nothing
set Types = 0
set Indexer = CreateIndexer()
endfunction
private function Proc takes nothing returns nothing
local timer t = GetExpiredTimer()
set WorkInteger = 0
loop
exitwhen TickTimer[WorkInteger] == t
set WorkInteger = WorkInteger + 1
endloop
call TriggerEvaluate(EffectTrigger[Code[WorkInteger]])
set TickCount[WorkInteger] = TickCount[WorkInteger] - 1
if TickCount[WorkInteger] == 0 then
call TriggerEvaluate(EndEffectTrigger[Code[WorkInteger]])
call Deindex(Indexer, WorkInteger)
set Target[WorkInteger] = null
set Caster[WorkInteger] = null
call PauseTimer(t)
endif
set t = null
endfunction
//-=- Local interface -=-
module PeriodicEffect
readonly static integer SPEC_PERIODIC_EFFECT_CODE
static if thistype.onPeriodicEffect.exists then
private static method firePeriodicEffect takes nothing returns boolean
call thistype.onPeriodicEffect()
return false
endmethod
endif
static if thistype.onEndPeriodicEffect.exists then
private static method fireEndPeriodicEffect takes nothing returns boolean
call thistype.onEndPeriodicEffect()
return false
endmethod
endif
static method RegisterPeriodicEffect takes nothing returns nothing
static if thistype.onPeriodicEffect.exists then
set EffectTrigger[Types] = CreateTrigger()
call TriggerAddCondition(EffectTrigger[Types], Condition(function thistype.firePeriodicEffect))
endif
static if thistype.onEndPeriodicEffect.exists then
set EndEffectTrigger[Types] = CreateTrigger()
call TriggerAddCondition(EndEffectTrigger[Types], Condition(function thistype.fireEndPeriodicEffect))
endif
set thistype.SPEC_PERIODIC_EFFECT_CODE = Types
set Types = Types + 1
endmethod
static method UnitApplyPeriodicEffect takes unit target, unit caster, integer instances, real period, integer data returns nothing
call UnitApplySpecPeriodicEffect(thistype.SPEC_PERIODIC_EFFECT_CODE, target, caster, instances, period, data)
endmethod
endmodule
//-=- Global interface -=-
function GetPeriodicEffectTarget takes nothing returns unit
return Target[WorkInteger]
endfunction
function GetPeriodicEffectCaster takes nothing returns unit
return Caster[WorkInteger]
endfunction
function GetPeriodicEffectData takes nothing returns integer
return Data[WorkInteger]
endfunction
function GetPeriodicEffectTickCount takes nothing returns integer
return TickCount[WorkInteger]
endfunction
function UnitApplySpecPeriodicEffect takes integer CODE, unit target, unit caster, integer instances, real period, integer data returns nothing
set WorkInteger = Index(Indexer)
set Code[WorkInteger] = CODE
set Target[WorkInteger] = target
set Caster[WorkInteger] = caster
set TickCount[WorkInteger] = instances
set Data[WorkInteger] = data
if TickTimer[WorkInteger] == null then
set TickTimer[WorkInteger] = CreateTimer()
endif
call TimerStart(TickTimer[WorkInteger], period, true, function Proc)
endfunction
endlibrary
Example of usage:
JASS:
//========================
//=== SpellColdEmbrace ===
//======== v1.100 ========
library SpellColdEmbrace requires Assist, PeriodicEffect
//=== Settings ===
globals
private constant integer ABILCODE = 'X038'
private constant integer ARMOR_ABILITY = 'X039'
//----------------
private constant integer INSTANCES = 4
private constant real PERIOD = 1
private constant boolean STOP_ANIMATION = true
private constant boolean CHANGE_HEIGHT = true
endglobals
static if CHANGE_HEIGHT then
globals
private constant integer HOVER_ABILITY = 'Amrf'
//----------------
private constant real HEIGHT_CHANGE_RATE = 200
endglobals
endif
struct SpellColdEmbrace extends array
private static real array HEAL_ABSOLUTE
private static real array HEAL_RELATIVE
private static method onInit takes nothing returns nothing
set HEAL_ABSOLUTE[1] = 20
set HEAL_ABSOLUTE[2] = 20
set HEAL_ABSOLUTE[3] = 20
set HEAL_ABSOLUTE[4] = 20
set HEAL_RELATIVE[1] = .03
set HEAL_RELATIVE[2] = .04
set HEAL_RELATIVE[3] = .05
set HEAL_RELATIVE[4] = .06
//================
call RegisterPeriodicEffect()
endmethod
static method onPeriodicEffect takes nothing returns nothing
set Assist.workUnit = GetPeriodicEffectTarget()
set Assist.workInteger = GetPeriodicEffectData()
call SetWidgetLife(Assist.workUnit, GetWidgetLife(Assist.workUnit) + (HEAL_ABSOLUTE[Assist.workInteger] + GetUnitState(Assist.workUnit, UNIT_STATE_MAX_LIFE) * HEAL_RELATIVE[Assist.workInteger]) * PERIOD)
endmethod
static method onEndPeriodicEffect takes nothing returns nothing
set Assist.workUnit = GetPeriodicEffectTarget()
call UnitRemoveAbility(Assist.workUnit, ARMOR_ABILITY)
static if STOP_ANIMATION then
call SetUnitTimeScale(Assist.workUnit, 1)
endif
static if CHANGE_HEIGHT then
set Assist.workReal = GetUnitDefaultFlyHeight(Assist.workUnit)
if Assist.workReal > 0 then
call SetUnitFlyHeight(Assist.workUnit, Assist.workReal, HEIGHT_CHANGE_RATE)
endif
endif
endmethod
implement PeriodicEffect
//----------------
static method onSpellEffect takes nothing returns nothing
if GetSpellAbilityId() == ABILCODE then
set Assist.workUnit = GetSpellTargetUnit()
call UnitApplyPeriodicEffect(Assist.workUnit, null, INSTANCES, PERIOD, GetUnitAbilityLevel(GetTriggerUnit(), ABILCODE))
call UnitAddAbility(Assist.workUnit, ARMOR_ABILITY)
static if STOP_ANIMATION then
call SetUnitTimeScale(Assist.workUnit, 0)
endif
static if CHANGE_HEIGHT then
if GetUnitDefaultFlyHeight(Assist.workUnit) > 0 then
call UnitAddAbility(Assist.workUnit, HOVER_ABILITY)
call UnitRemoveAbility(Assist.workUnit, HOVER_ABILITY)
call SetUnitFlyHeight(Assist.workUnit, 0, HEIGHT_CHANGE_RATE)
endif
endif
endif
endmethod
endstruct
endlibrary
Last edited: