diff --git a/Assets/Scripts/EnemyAI.cs b/Assets/Scripts/EnemyAI.cs index 2204d539..6061f9de 100644 --- a/Assets/Scripts/EnemyAI.cs +++ b/Assets/Scripts/EnemyAI.cs @@ -1,30 +1,15 @@ using System; using System.Linq; using Actions; -using Grid; using UnityEngine; -using UnityEngine.Serialization; public class EnemyAI : MonoBehaviour { - public enum State { - WaitingForEnemyTurn, - TakingTurn, - Busy - } - - public static EnemyAI Instance { get; private set; } - public State CurrentState { get; private set; } private float timer; - private void Awake() { - if (Instance is not null) { - Debug.LogError($"There is more than one TurnSystem! {transform} - {Instance}"); - Destroy(gameObject); - return; - } - Instance = this; - CurrentState = State.WaitingForEnemyTurn; - } + //TODO implement A* pathfinding + private State CurrentState { get; set; } + + private void Awake() => CurrentState = State.WaitingForEnemyTurn; private void Start() => TurnSystem.Instance.OnTurnChanged += TurnSystem_OnTurnChanged; private void Update() { @@ -43,6 +28,7 @@ public class EnemyAI : MonoBehaviour { TurnSystem.Instance.NextTurn(); // No more enemies have actions they can take, end enemy turn } } + break; case State.Busy: break; @@ -60,13 +46,12 @@ public class EnemyAI : MonoBehaviour { timer = 2f; } - private static bool TryTakeEnemyAIAction(Action onEnemyAIActionComplete) - => UnitManager.Instance.EnemyUnitList.Any(enemyUnit => TryTakeEnemyAIAction(enemyUnit, onEnemyAIActionComplete)); + private static bool TryTakeEnemyAIAction(Action onEnemyAIActionComplete) => UnitManager.Instance.EnemyUnitList.Any(enemyUnit => TryTakeEnemyAIAction(enemyUnit, onEnemyAIActionComplete)); private static bool TryTakeEnemyAIAction(Unit enemyUnit, Action onEnemyAIActionComplete) { EnemyAIAction bestEnemyAIAction = null; BaseAction bestBaseAction = null; - + foreach (BaseAction baseAction in enemyUnit.BaseActionArray) { if (enemyUnit.ActionPoints < baseAction.ActionPointsCost) continue; //Enemy cannot afford this action if (bestEnemyAIAction == null) { @@ -89,4 +74,10 @@ public class EnemyAI : MonoBehaviour { return false; } } + + private enum State { + WaitingForEnemyTurn, + TakingTurn, + Busy + } } \ No newline at end of file