init Pathfinding

Polish
Sascha 2023-05-16 16:04:41 +07:00
parent a701a64824
commit dfb10e1a38
1 changed files with 13 additions and 22 deletions

@ -1,30 +1,15 @@
using System; using System;
using System.Linq; using System.Linq;
using Actions; using Actions;
using Grid;
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization;
public class EnemyAI : MonoBehaviour { 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 float timer;
private void Awake() { //TODO implement A* pathfinding
if (Instance is not null) { private State CurrentState { get; set; }
Debug.LogError($"There is more than one TurnSystem! {transform} - {Instance}");
Destroy(gameObject); private void Awake() => CurrentState = State.WaitingForEnemyTurn;
return;
}
Instance = this;
CurrentState = State.WaitingForEnemyTurn;
}
private void Start() => TurnSystem.Instance.OnTurnChanged += TurnSystem_OnTurnChanged; private void Start() => TurnSystem.Instance.OnTurnChanged += TurnSystem_OnTurnChanged;
private void Update() { 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 TurnSystem.Instance.NextTurn(); // No more enemies have actions they can take, end enemy turn
} }
} }
break; break;
case State.Busy: case State.Busy:
break; break;
@ -60,8 +46,7 @@ public class EnemyAI : MonoBehaviour {
timer = 2f; timer = 2f;
} }
private static bool TryTakeEnemyAIAction(Action onEnemyAIActionComplete) private static bool TryTakeEnemyAIAction(Action onEnemyAIActionComplete) => UnitManager.Instance.EnemyUnitList.Any(enemyUnit => TryTakeEnemyAIAction(enemyUnit, onEnemyAIActionComplete));
=> UnitManager.Instance.EnemyUnitList.Any(enemyUnit => TryTakeEnemyAIAction(enemyUnit, onEnemyAIActionComplete));
private static bool TryTakeEnemyAIAction(Unit enemyUnit, Action onEnemyAIActionComplete) { private static bool TryTakeEnemyAIAction(Unit enemyUnit, Action onEnemyAIActionComplete) {
EnemyAIAction bestEnemyAIAction = null; EnemyAIAction bestEnemyAIAction = null;
@ -89,4 +74,10 @@ public class EnemyAI : MonoBehaviour {
return false; return false;
} }
} }
private enum State {
WaitingForEnemyTurn,
TakingTurn,
Busy
}
} }