Added new CapMechanic

This commit is contained in:
mamontow 2021-09-01 00:37:24 +03:00
parent 2a33f6acf4
commit be9e4bb16b
5 changed files with 264 additions and 388 deletions

File diff suppressed because it is too large Load Diff

View File

@ -49,14 +49,14 @@ public class CaptureController : MonoBehaviour
private void TryToCaptureTile() private void TryToCaptureTile()
{ {
TileInfo tile = _playerState.currentTile; TileInfo tile = _playerState.currentTile;
if (_playerState.ownerIndex != tile.tileOwnerIndex) if (_playerState.ownerIndex != tile.tileOwnerIndex)
{ {
_playerState.SetNewState(CharacterState.Capture); _playerState.SetNewState(CharacterState.Capture);
if (tile.easyCaptureFor.Contains(_playerState.ownerIndex) || tile.isLocked) if (tile.easyCaptureFor.Contains(_playerState.ownerIndex) || tile.easyCaptureForAll)
{ {
CaptureTile(tile); CaptureTile(tile);
} }
else else
{ {
@ -71,8 +71,12 @@ public class CaptureController : MonoBehaviour
StartCoroutine(_currentCoroutine); StartCoroutine(_currentCoroutine);
} }
} }
}
else
{
TileManagment.SetPlayerTilesCapState(_playerState);
} }
} }

View File

@ -156,7 +156,7 @@ public class DeathChecker : MonoBehaviour
private void PlayerDeadActions(PlayerState player) private void PlayerDeadActions(PlayerState player)
{ {
List<TileInfo> playerTiles = TileManagment.GetCharacterTiles(player); List<TileInfo> playerTiles = TileManagment.GetCharacterTiles(player);
TileManagment.LockTiles(playerTiles, true); TileManagment.SetEasyCapState(playerTiles, true);
player.SetDead(); player.SetDead();
Debug.Log("player " + player.name + " dead"); Debug.Log("player " + player.name + " dead");
@ -174,7 +174,7 @@ public class DeathChecker : MonoBehaviour
TileInfo resTile = GetAvailableResTile(player, playerTiles); TileInfo resTile = GetAvailableResTile(player, playerTiles);
if (resTile) if (resTile)
{ {
TileManagment.LockTiles(playerTiles, false); TileManagment.SetEasyCapState(playerTiles, false);
player.SetAlive(resTile.tilePosition); player.SetAlive(resTile.tilePosition);

View File

@ -18,7 +18,7 @@ public class TileInfo : MonoBehaviour
public bool isBorderTile = false; public bool isBorderTile = false;
public bool isLocked = false; public bool easyCaptureForAll = false;
#region Pathfinding values #region Pathfinding values
[Header("Pathfinding Settings")] [Header("Pathfinding Settings")]

View File

@ -86,7 +86,7 @@ public class TileManagment : MonoBehaviour
public static void ChangeTileOwner(TileInfo tile, PlayerState newPlayer) public static void ChangeTileOwner(TileInfo tile, PlayerState newPlayer)
{ {
tile.isLocked = false; tile.easyCaptureForAll = false;
TileOwner newOwner = newPlayer.ownerIndex; TileOwner newOwner = newPlayer.ownerIndex;
TileOwner oldOwner = tile.tileOwnerIndex; TileOwner oldOwner = tile.tileOwnerIndex;
tile.tileOwnerIndex = newOwner; tile.tileOwnerIndex = newOwner;
@ -98,6 +98,7 @@ public class TileManagment : MonoBehaviour
OnAnyTileCaptured?.Invoke(newPlayer); OnAnyTileCaptured?.Invoke(newPlayer);
CheckSurroundedTiles(levelTiles, newOwner, oldOwner); CheckSurroundedTiles(levelTiles, newOwner, oldOwner);
SetAllPLayersTilesCapState(GameManager.activePlayers);
} }
@ -245,11 +246,11 @@ public class TileManagment : MonoBehaviour
return playerTiles; return playerTiles;
} }
public static void LockTiles(List<TileInfo> tiles, bool lockState) public static void SetEasyCapState(List<TileInfo> tiles, bool capState)
{ {
foreach (TileInfo tile in tiles) foreach (TileInfo tile in tiles)
{ {
tile.isLocked = lockState; tile.easyCaptureForAll = capState;
} }
} }
@ -344,6 +345,62 @@ public class TileManagment : MonoBehaviour
} }
public static void SetPlayerTilesCapState(PlayerState player)
{
List<TileInfo> playerTiles = charTiles[(int)player.ownerIndex];
foreach (TileInfo tile in playerTiles)
{
tile.easyCaptureForAll = true;
}
List<TileInfo> playerConnectedTiles = GetConnectedTiles(levelTiles, player.ownerIndex, player.currentTile);
foreach (TileInfo tile in playerConnectedTiles)
{
tile.easyCaptureForAll = false;
}
}
public static void SetAllPLayersTilesCapState(List<PlayerState> activePlayers)
{
foreach (PlayerState player in activePlayers)
{
SetPlayerTilesCapState(player);
}
}
public static List<TileInfo> GetConnectedTiles(List<TileInfo> allTiles, TileOwner ownerIndex, TileInfo startTile)
{
List<TileInfo> connectedTiles = new List<TileInfo>();
var q = new Queue<TileInfo>(allTiles.Count);
q.Enqueue(startTile);
int iterations = 0;
while (q.Count > 0)
{
var tile = q.Dequeue();
if (q.Count > allTiles.Count)
{
throw new Exception("The algorithm is probably looping. Queue size: " + q.Count);
}
if (connectedTiles.Contains(tile))
{
continue;
}
connectedTiles.Add(tile);
var myAdjacentTiles = GetOwnerAdjacentTiles(tile, ownerIndex);
foreach (TileInfo newTile in myAdjacentTiles)
{
q.Enqueue(newTile);
}
iterations++;
}
return connectedTiles;
}
public static void CheckIfSurroundedByOwner(List<TileInfo> tiles, TileOwner ownerIndex, TileInfo startTile) public static void CheckIfSurroundedByOwner(List<TileInfo> tiles, TileOwner ownerIndex, TileInfo startTile)
{ {
List<TileInfo> connectedTiles = new List<TileInfo>(); List<TileInfo> connectedTiles = new List<TileInfo>();