following
This commit is contained in:
parent
fd8778e9f2
commit
b7562d53ae
4 changed files with 20 additions and 57 deletions
|
|
@ -689,7 +689,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
health: 100
|
||||
maxHealth: 100
|
||||
maxMovement: 4
|
||||
maxMovement: 120
|
||||
currentTile: {fileID: 0}
|
||||
canMove: 1
|
||||
invincible: 0
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ public class Enemy : Entity
|
|||
[ContextMenu("ForceTurn")]
|
||||
public void StartTurn()
|
||||
{
|
||||
//attack the nearest player?
|
||||
TurnHandler.instance.UpdateTurns();
|
||||
closestPlayer = FindClosestPlayer();
|
||||
Debug.Log(closestPlayer);
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@ public class EnemyMovement : MonoBehaviour
|
|||
}
|
||||
|
||||
#endregion
|
||||
private Queue<TileObject> allMovableTiles = new();
|
||||
private Queue<TileObject> currentMovableTiles = new();
|
||||
private Queue<TileObject> frontier = new();
|
||||
private HashSet<TileObject> visited = new();
|
||||
private Dictionary<TileObject, TileObject> currentPaths = new();
|
||||
|
||||
public void PathfindToTarget(TileObject target, Enemy selectedEntity)
|
||||
{
|
||||
allMovableTiles.Clear();
|
||||
currentMovableTiles.Clear();
|
||||
frontier.Clear();
|
||||
visited.Clear();
|
||||
currentPaths.Clear();
|
||||
GetTilesInRange(selectedEntity);
|
||||
TileObject requestedTile = GetPathToTarget(target, selectedEntity);
|
||||
|
|
@ -34,71 +34,34 @@ public class EnemyMovement : MonoBehaviour
|
|||
}
|
||||
private void GetTilesInRange(Enemy selectedEntity)
|
||||
{
|
||||
foreach (TileObject tileObject in selectedEntity.currentTile.neighbors)
|
||||
frontier.Enqueue(selectedEntity.currentTile);
|
||||
while (frontier.Count > 0)
|
||||
{
|
||||
if (!tileObject.blocked && !tileObject.hasUnit)
|
||||
TileObject currentTile = frontier.Dequeue();
|
||||
foreach (TileObject neighboringTiles in currentTile.neighbors)
|
||||
{
|
||||
currentMovableTiles.Enqueue(tileObject);
|
||||
allMovableTiles.Enqueue(tileObject);
|
||||
currentPaths.Add(tileObject, selectedEntity.currentTile);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < selectedEntity.maxMovement - 1; i++)
|
||||
{
|
||||
foreach (TileObject tileObject in currentMovableTiles.ToArray())
|
||||
{
|
||||
foreach (TileObject neighboringTiles in tileObject.neighbors)
|
||||
if (!visited.Contains(neighboringTiles))
|
||||
{
|
||||
if (!neighboringTiles.blocked && !neighboringTiles.hasUnit)
|
||||
{
|
||||
currentMovableTiles.Enqueue(neighboringTiles);
|
||||
currentPaths.TryAdd(neighboringTiles, tileObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (TileObject tileObject in allMovableTiles.ToArray())
|
||||
{
|
||||
foreach (TileObject neighboringTiles in tileObject.neighbors)
|
||||
{
|
||||
if (!neighboringTiles.blocked && !neighboringTiles.hasUnit)
|
||||
{
|
||||
allMovableTiles.Enqueue(neighboringTiles);
|
||||
currentPaths.TryAdd(neighboringTiles, tileObject);
|
||||
visited.Add(neighboringTiles);
|
||||
frontier.Enqueue(neighboringTiles);
|
||||
currentPaths.TryAdd(neighboringTiles, currentTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
Debug.Log(frontier.Count);
|
||||
}
|
||||
|
||||
private TileObject GetPathToTarget(TileObject target, Enemy selectedEntity)
|
||||
{
|
||||
TileObject currentTile = target;
|
||||
List<TileObject> pathToTarget = new();
|
||||
TileObject pathTileInRange = null;
|
||||
while (currentTile != selectedEntity.currentTile)
|
||||
{
|
||||
pathToTarget.Add(currentTile);
|
||||
currentTile = currentPaths[currentTile];
|
||||
}
|
||||
|
||||
for (int i = 0; i < pathToTarget.Count; i++)
|
||||
{
|
||||
if (currentMovableTiles.Contains(pathToTarget[i]))
|
||||
{
|
||||
pathTileInRange = pathToTarget[i];
|
||||
return pathTileInRange;
|
||||
}
|
||||
}
|
||||
List<TileObject> pathToRange = new();
|
||||
/*if (pathTileInRange != null)
|
||||
{
|
||||
while (pathTileInRange != selectedEntity.currentTile)
|
||||
{
|
||||
pathToTarget.Add(pathTileInRange);
|
||||
pathTileInRange = currentPaths[pathTileInRange];
|
||||
}
|
||||
return pathToRange;
|
||||
}*/
|
||||
return null;
|
||||
pathToTarget.Reverse();
|
||||
int validMovementRange = Mathf.Min(pathToTarget.Count, selectedEntity.maxMovement) - 1;
|
||||
return pathToTarget[validMovementRange];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class TurnHandler : MonoBehaviour
|
|||
public enum GameState {PlayerTurn, EnemyTurn}
|
||||
public GameState currentGameState = GameState.PlayerTurn;
|
||||
|
||||
private int currentEnemy;
|
||||
private int currentEnemy = 0;
|
||||
|
||||
private void SortEnemies()
|
||||
{
|
||||
|
|
@ -53,13 +53,14 @@ public class TurnHandler : MonoBehaviour
|
|||
if (allDone)
|
||||
{
|
||||
currentGameState = GameState.EnemyTurn;
|
||||
enemyEntities[0].StartTurn();
|
||||
}
|
||||
}
|
||||
else if (currentGameState == GameState.EnemyTurn)
|
||||
{
|
||||
enemyEntities[currentEnemy].StartTurn();
|
||||
currentEnemy++;
|
||||
if (currentEnemy > enemyEntities.Count)
|
||||
if (currentEnemy > enemyEntities.Count - 1)
|
||||
{
|
||||
currentGameState = GameState.PlayerTurn;
|
||||
foreach (PlayerEntity player in playerEntities)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue