private void DecideTactic() { if (currentTactic != null && !currentTactic.CanReact()) return; DecideTarget(); if (CheckForDanger()) { if (currentTactic == null || !(currentTactic is Defensive)) { currentTactic = new Defensive(this.owner); } } else { if ((currentTactic == null || !(currentTactic is Offensive)) && lastAttackTime >= AttackDelay && TargetWithinRange) { currentTactic = new Offensive(this.owner); lastAttackTime = 0f; } } if(currentTactic == null) { // Go into ready stance, eventually currentTactic = new Defensive(this.owner); // but honestly this is fine for now. } }
/// <summary> /// Actually performs the actions dictated by the current tactic. /// </summary> private void PerformTactic() { MoveTowardTarget(); currentTactic.Perform(); if(currentTactic is Offensive) { if (((Offensive)currentTactic).isDone) { currentTactic = null; } } else { lastAttackTime += Time.fixedDeltaTime; } }