public void Abort() { // If this handler cannot be aborted if (!SubSpell.CanBeAborted) { return; } // If already inactive - do nothing if (_state == SubSpellState.Ended) { return; } if (_projectile != null) { Object.Destroy(_projectile.gameObject); } _state = SubSpellState.Ended; FireEvent(SubSpellEvent.Ended, Source); if (SubSpell.AbortSpellIfAborted) { SpellHandler.Abort(); } }
public SubSpellHandler( SpellHandler spellHandler, SubSpell subSpell, Target source, Target target) { Assert.IsTrue(source.IsValid); Assert.IsTrue(target.IsValid); Assert.IsNotNull(subSpell); Assert.IsNotNull(spellHandler); SubSpell = subSpell; _spellHandler = spellHandler; Source = source; Target = target; _state = SubSpellState.Started; #if DEBUG TargetUtility.DebugDrawSourceAndTarget(source, target); #endif }
public void Update() { // If targets are invalid because of something - try to abort if (!Source.IsValid || !Target.IsValid) { Abort(); } // State machine switch (_state) { case SubSpellState.Ended: return; case SubSpellState.Started: FireEvent(SubSpellEvent.Started, Source); _timer = SubSpell.PreCastDelay.GetValue(Stacks); _state = SubSpellState.PreCastDelay; return; case SubSpellState.PreCastDelay: _timer -= Time.deltaTime; if (_timer < 0) { if (SubSpell.IsProjectileSubSpell) { _state = SubSpellState.ServicingProjectile; SpawnProjectile(); } else { _state = SubSpellState.FireDelay; _timer = 0; _fireStartedTime = Time.time; } FireEvent(SubSpellEvent.AfterPreCastDelay, Source); } break; case SubSpellState.FireDelay: _timer -= Time.deltaTime; if (_timer < 0) { _state = SubSpellState.Firing; } break; case SubSpellState.Firing: FireEvent(SubSpellEvent.OnFire, Source); var timeSinceFirstFire = Time.time - _fireStartedTime; if (timeSinceFirstFire > SubSpell.FireDuration.GetValue(Stacks)) { // Finished firing _state = SubSpellState.PostCastDelay; _timer = SubSpell.PostCastDelay.GetValue(Stacks); FireEvent(SubSpellEvent.AfterFinishedFire, Source); } else { // Back to delayed state. Still firing _state = SubSpellState.FireDelay; _timer = SubSpell.FireDelay.GetValue(Stacks); } break; case SubSpellState.ServicingProjectile: // If projectile was destroyed or inactive if (_projectile == null || !_projectile.IsActive) { _state = SubSpellState.PostCastDelay; _timer = SubSpell.PostCastDelay.GetValue(Stacks); } // Otherwise do nothing. Wait. break; case SubSpellState.PostCastDelay: _timer -= Time.deltaTime; if (_timer < 0) { _state = SubSpellState.Ended; FireEvent(SubSpellEvent.Ended, Source); } break; } }