using UnityEngine; using System.Linq; using System.Collections.Generic; public class SafeTile : Tile { [SerializeField] private Transform[] placementPoints; protected Queue placementQueue = new Queue(); protected Dictionary playerTypesDict = new Dictionary(); public int PlayerTypesCount => playerTypesDict.Count; public bool HasMoreThanOnePlayerType => playerTypesDict.Count > 1; public List GetPlayerPawns(PlayerType playerType) => playerTypesDict[playerType].playerPawns.Values.ToList(); public bool ContainsPlayerType(PlayerType playerType) => playerTypesDict.ContainsKey(playerType); private void Awake() { foreach (var placement in placementPoints) { placementQueue.Enqueue(placement); } } public override void InitPlayerPawn(PlayerPawn playerPawn, PlayerType playerType) { // PlayerPawn = playerPawn; if (!playerTypesDict.ContainsKey(playerType)) { playerTypesDict.Add( playerType, new PlayerTileData { playerCount = 1, playerPawns = new Dictionary() }); Debug.Log($"targetSafeTile. tileName: {name}, playerPawn.PlayerId: {playerPawn.PlayerId}"); 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}"); } else { Debug.Log($"tileName: {name}, playerPawn.PlayerId: {playerPawn.PlayerId}"); playerTypesDict[playerType].playerCount++; Debug.Log($"targetSafeTile. tileName: {name} Adding player {playerType} {playerTypesDict[playerType].playerCount}, tileName: {name}"); playerTypesDict[playerType].playerPawns.Add(playerPawn.PlayerId, playerPawn); } } public void UpdateSafeZonePlayerData(PlayerType playerType, PlayerPawn playerPawn) { if (playerTypesDict.ContainsKey(playerType)) { if (playerTypesDict[playerType].playerCount > 0) { Debug.Log($"targetSafeTile. tileName: {name} Removing player {playerType} {playerTypesDict[playerType].playerCount}, tileName: {name}"); playerTypesDict[playerType].playerCount--; Debug.Log($"targetSafeTile. tileName: {name} Removing player {playerType} after: {playerTypesDict[playerType].playerCount}"); 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}"); } } } } public PlayerType GetFirstPlayerType() => playerTypesDict.Keys.FirstOrDefault(); public int GetPlayerPawnsCountInTile(PlayerType playerType) { return playerTypesDict[playerType].playerPawns.Count; } public PlayerPawn IterateAndGetPlayerPawn(PlayerType playerType, int index) { return playerTypesDict[playerType].playerPawns[index + 1]; } public Transform GetPlacementPoint(PlayerType playerType) { return playerTypesDict[playerType].commonPlacementTransform; } public override void ResetTileData() { if (playerTypesDict != null && playerTypesDict.Count > 0) { playerTypesDict.Clear(); } } }