protected Attack(AttackData data, T parent) { this.data = data; Parent = parent; timer = new SingleTimer(t => { if (ShouldAdvance(phase)) { AdvancePhase(); } else { isWaitingOnPhase = true; } }); phase = AttackPhases.Idle; phaseTicks = new Action <float>[] { WhilePreparing, WhileExecuting, WhileCooling, WhileResetting }; }
private void AdvancePhase() { int phaseIndex; do { phase = (AttackPhases)(((int)phase + 1) % 5); phaseIndex = (int)phase - 1; } // A phase is considered disabled if its duration is zero. while (phase != AttackPhases.Idle && data.Durations[phaseIndex] == 0); if (phase == AttackPhases.Complete) { return; } timer.Duration = data.Durations[phaseIndex]; timer.Tick = phaseTicks[phaseIndex]; timer.IsPaused = false; switch (phase) { case AttackPhases.Prepare: OnPrepare(); break; case AttackPhases.Execute: OnExecute(); break; case AttackPhases.Cooldown: OnCooldown(); break; case AttackPhases.Reset: OnReset(); break; } }
protected override bool ShouldAdvance(AttackPhases phase) { return(phase != AttackPhases.Prepare || ShouldRelease); }
public virtual void Cancel() { phase = AttackPhases.Complete; }
// This is useful when certain phases need to be stalled while waiting for another event to occur (e.g. once // the bow is drawn, an attack isn't executed until the button is released). protected virtual bool ShouldAdvance(AttackPhases phase) { return(true); }