100 lines
4.0 KiB
C#
Raw Permalink Normal View History

2026-01-23 12:46:59 +05:30
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
public class SafeTile : Tile
{
[SerializeField] private Transform[] placementPoints;
protected Queue<Transform> placementQueue = new Queue<Transform>();
2026-01-26 19:48:55 +05:30
protected Dictionary<PlayerType, PlayerTileData> playerTypesDict = new Dictionary<PlayerType, PlayerTileData>();
2026-01-23 12:46:59 +05:30
public int PlayerTypesCount => playerTypesDict.Count;
public bool HasMoreThanOnePlayerType => playerTypesDict.Count > 1;
2026-01-26 19:48:55 +05:30
public List<PlayerPawn> GetPlayerPawns(PlayerType playerType) => playerTypesDict[playerType].playerPawns.Values.ToList();
2026-02-04 12:32:18 +05:30
public List<PlayerPawn> GetFirstPlayerPawns() => playerTypesDict.FirstOrDefault().Value.playerPawns.Values.ToList();
2026-01-23 12:46:59 +05:30
2026-01-26 19:48:55 +05:30
public bool ContainsPlayerType(PlayerType playerType) => playerTypesDict.ContainsKey(playerType);
2026-01-23 12:46:59 +05:30
private void Awake()
{
foreach (var placement in placementPoints)
{
placementQueue.Enqueue(placement);
}
}
2026-01-26 19:48:55 +05:30
public override void InitPlayerPawn(PlayerPawn playerPawn, PlayerType playerType)
2026-01-23 12:46:59 +05:30
{
// PlayerPawn = playerPawn;
if (!playerTypesDict.ContainsKey(playerType))
{
playerTypesDict.Add(
playerType,
new PlayerTileData { playerCount = 1,
playerPawns = new Dictionary<int, PlayerPawn>()
});
Debug.Log($"targetSafeTile. tileName: {name}, playerPawn.PlayerId: {playerPawn.PlayerId}");
2026-01-23 12:46:59 +05:30
playerTypesDict[playerType].playerPawns.Add(playerPawn.PlayerId, playerPawn);
playerTypesDict[playerType].commonPlacementTransform = placementQueue.Dequeue();
Debug.Log($"targetSafeTile. tileName: {name} Adding player {playerType} {playerTypesDict[playerType].playerCount} tileName: {name}");
2026-01-23 12:46:59 +05:30
}
else
{
2026-01-28 16:57:27 +05:30
Debug.Log($"tileName: {name}, playerPawn.PlayerId: {playerPawn.PlayerId}");
2026-01-23 12:46:59 +05:30
playerTypesDict[playerType].playerCount++;
Debug.Log($"targetSafeTile. tileName: {name} Adding player {playerType} {playerTypesDict[playerType].playerCount}, tileName: {name}");
2026-01-23 12:46:59 +05:30
playerTypesDict[playerType].playerPawns.Add(playerPawn.PlayerId, playerPawn);
}
}
2026-01-26 19:48:55 +05:30
public void UpdateSafeZonePlayerData(PlayerType playerType, PlayerPawn playerPawn)
2026-01-23 12:46:59 +05:30
{
if (playerTypesDict.ContainsKey(playerType))
{
if (playerTypesDict[playerType].playerCount > 0)
{
Debug.Log($"targetSafeTile. tileName: {name} Removing player {playerType} {playerTypesDict[playerType].playerCount}, tileName: {name}");
2026-01-23 12:46:59 +05:30
playerTypesDict[playerType].playerCount--;
Debug.Log($"targetSafeTile. tileName: {name} Removing player {playerType} after: {playerTypesDict[playerType].playerCount}");
2026-01-23 12:46:59 +05:30
playerTypesDict[playerType].playerPawns.Remove(playerPawn.PlayerId);
if (playerTypesDict[playerType].playerCount == 0)
{
placementQueue.Enqueue(playerTypesDict[playerType].commonPlacementTransform);
playerTypesDict.Remove(playerType);
Debug.Log($"targetSafeTile. tileName: {name} Removing player {playerType}");
2026-01-23 12:46:59 +05:30
}
}
}
}
2026-01-26 19:48:55 +05:30
public PlayerType GetFirstPlayerType() => playerTypesDict.Keys.FirstOrDefault();
2026-01-23 12:46:59 +05:30
2026-01-26 19:48:55 +05:30
public int GetPlayerPawnsCountInTile(PlayerType playerType)
2026-01-23 12:46:59 +05:30
{
return playerTypesDict[playerType].playerPawns.Count;
}
2026-01-26 19:48:55 +05:30
public PlayerPawn IterateAndGetPlayerPawn(PlayerType playerType, int index)
2026-01-23 12:46:59 +05:30
{
return playerTypesDict[playerType].playerPawns[index + 1];
}
2026-01-26 19:48:55 +05:30
public Transform GetPlacementPoint(PlayerType playerType)
2026-01-23 12:46:59 +05:30
{
return playerTypesDict[playerType].commonPlacementTransform;
}
2026-02-02 19:27:17 +05:30
public override void ResetTileData()
{
Debug.Log($"Resetting tile in safe tile {name}");
2026-02-02 19:27:17 +05:30
if (playerTypesDict != null && playerTypesDict.Count > 0)
{
playerTypesDict.Clear();
}
}
2026-01-23 12:46:59 +05:30
}