- Joined
- Feb 3, 2013
- Messages
- 277
JASS:
//! zinc
library StructTesting
{
interface Events
{
method onPreTermination() = null;
method onEffectStart() = null;
method onEffectEnd() = null;
}
struct Parent extends Events
{
unit cast;
real time, st, et;
static integer prev[1000], next[1000], rn[1000];
static integer ic = 0;
static timer tmr = CreateTimer();
static real period = 0.02500;
private method onTermination()
{
BJDebugMsg(I2S(this) + "onTermination!");
this.cast = null;
prev[next[this]] = prev[this];
next[prev[this]] = next[this];
rn[this] = rn[0];
rn[0] = this;
}
method onEffectStart()
{
BJDebugMsg(I2S(this) + "onEffectStart");
}
method onEffectEnd()
{
BJDebugMsg(I2S(this) + "onEffectEnd");
}
method onPreTermination()
{
BJDebugMsg(I2S(this) + "onPreTermination");
}
static method looping()
{
thistype this = next[0];
while (this!= 0)
{
if (this.time == this.et)
{
this.onEffectEnd();
this.onPreTermination();
this.onTermination();
}
else if (this.time == this.st)
{
this.onEffectStart();
}
this.time = this.time + period;
this = next[this];
}
if (next[0] == 0)
{
BJDebugMsg("Paused!");
PauseTimer(tmr);
}
}
static method create(unit u, real st, real et) -> thistype
{
thistype this = rn[0];
if (this == 0)
{
ic = ic + 1;
this = ic;
}
else
{
rn[0] = rn[this];
}
BJDebugMsg(I2S(this) + "onCreation!");
this.cast = u;
this.time = 0.;
this.st = st;
this.et = et;
next[this] = 0;
prev[this] = prev[0];
next[prev[0]] = this;
prev[0] = this;
if (prev[this] == 0)
{
BJDebugMsg("Timer Start!");
TimerStart(tmr, period, true, function thistype.looping);
}
return this;
}
}
struct Child extends Parent
{
static method onCast() -> boolean
{
unit u = GetTriggerUnit();
thistype.create(u, 2.5, 3.5);
u = null;
return false;
}
static method onInit()
{
trigger t = CreateTrigger();
TriggerRegisterPlayerUnitEvent(t, Player(0), EVENT_PLAYER_UNIT_SPELL_EFFECT, null);
TriggerAddCondition(t, function thistype.onCast);
}
}
}
//! endzinc
EDIT2: Fixed... copied from xe;;
Last edited: