Refactored changes + fixes for indicator.

This commit is contained in:
Ashby Issac 2026-02-02 16:43:43 +05:30
parent 7dc4cb5478
commit 1897a36a88
3 changed files with 45 additions and 35 deletions

View File

@ -8464,6 +8464,7 @@ MonoBehaviour:
diceRollHandler: {fileID: 1013177415}
diceValue: 6
maxDiceSixRollCounter: 2
totalStepsForCharacter: 57
diceText: {fileID: 953941044}
pointerDebug: {fileID: 102349503}
pointerMeshRend: {fileID: 102349501}

View File

@ -1,9 +1,9 @@
using TMPro;
using System;
using System.Collections.Generic;
using System.Linq;
using DG.Tweening;
using TMPro;
using UnityEngine;
using System.Collections.Generic;
public enum BotMove
{
@ -308,12 +308,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"CallTest: SelectPawnFromBotBase: {currentPlayerTypeTurn}");
var botPawnsDictForCurrentPlayer = botRuntimeMovementData[currentPlayerTypeTurn]; // set the data inside this dict
// check the data from the playerGameDataDict
// change playerPawnsDict to list
// only select the pawns that are active
// if no pawns have left the home select the first pawn inside the base should be selected
int savedPlayerId = -1;
PlayerPawn pawn = null;
@ -321,7 +315,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInHome == 0)
{
InitActivePlayers();
UpdateActivePlayersAndSetDisplay();
}
if (availPlayers.Count() < 1 && CanRollDiceAgain) // got a 6 roll value
@ -524,7 +518,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
else // if there are any other pawns that are in safe or moving state
{
// for player's logic
InitActivePlayers();
UpdateActivePlayersAndSetDisplay();
int customAvailPlayers = availPlayers.Count();
Debug.Log($"before CustomAvailablePlayers: {customAvailPlayers}");
@ -566,7 +560,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"CanRollDiceAgain: {CanRollDiceAgain}, canSwitchPlayer: {canSwitchPlayer}");
}
private void InitActivePlayers()
private void UpdateActivePlayersAndSetDisplay()
{
availPlayers = playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Values.Select(pawn => pawn)
.Where(pawn => pawn.GetPlayerState() == PlayerState.InSafeZone ||
@ -632,14 +626,14 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
{
Tile targetTile = tilesManager.RetrieveTileBasedOnIndex(playerGameData.startIndex);
UpdatePlayerCountOnTile(selectedPawn, false);
selectedPawn.ShowPlayerCountCanvas(false);
selectedPawn.MoveToTile(
GetAndInitPositionInsideSafeZone(selectedPawn, targetTile),
onComplete: () =>
{
playerGameDatasDict[playerGameData.playerType].totalPawnsInHome--;
UpdatePlayerState(selectedPawn, PlayerState.InSafeZone);
UpdatePlayerCountOnTile(selectedPawn, true);
ShowUpdatedPlayerCountOnTile(selectedPawn);
if (CheckForMaxDiceRollAttempt())
{
return;
@ -656,6 +650,16 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
}
else if (selectedPawn.GetPlayerState() == PlayerState.InFinishingPath)
{
Tile currentSittingTile = tilesManager.RetrieveFinishingTileBasedOnIndex(selectedPawn.PlayerType, selectedPawn.CurrentTileIndex);
currentSittingTile.ResetPlayerPawn(selectedPawn);
if (currentSittingTile.HasPawnsAvailable)
{
var playerPawns = currentSittingTile.GetPlayerPawns();
foreach (var pawn in playerPawns)
ShowUpdatedPlayerCountOnTile(pawn);
}
ApplyFinishingPathLogic(selectedPawn);
}
else if (selectedPawn.CurrentTileIndex == playerGameDatasDict[currentPlayerTypeTurn].endIndex)
@ -693,7 +697,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
if (safeTile.ContainsPlayerType(selectedPawn.PlayerType))
{
foreach (var pawn in playerPawns)
UpdatePlayerCountOnTile(pawn, true);
ShowUpdatedPlayerCountOnTile(pawn);
}
}
}
@ -704,7 +708,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
{
var playerPawns = currentSittingTile.GetPlayerPawns();
foreach (var pawn in playerPawns)
UpdatePlayerCountOnTile(pawn, true);
ShowUpdatedPlayerCountOnTile(pawn);
}
}
@ -719,7 +723,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 : finishingPathIndex + diceRolledValue;
Debug.Log($"TargetIdx: {targetIdx}, finishingPathIndex: {finishingPathIndex}");
UpdatePlayerCountOnTile(playerPawn, false);
playerPawn.ShowPlayerCountCanvas(false);
MoveThroughFinishingPath(playerPawn, finishingPathIndex, targetIdx);
}
@ -746,9 +751,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"currentPlayerTurnIndex: {currentPlayerTurnIndex}");
Debug.Log($"before SwitchPlayer availPlayers: {availPlayers.Count}, playerPawn: {playerPawn}");
if (availPlayers.Count < 1)
InitActivePlayers();
UpdateActivePlayersAndSetDisplay();
Debug.Log($"after SwitchPlayer availPlayers: {availPlayers.Count}, playerPawn: {playerPawn}");
SetDisplayCountForAllAvailPlayers(false);
@ -776,8 +780,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
diceSixRollCounter = 0;
diceText.text = $"{0}";
InitActivePlayers();
SetDisplayCountForAllAvailPlayers(true);
UpdateActivePlayersAndSetDisplay();
}
SetCanRollDiceForUser(!botTypesInGame.Contains(currentPlayerTypeTurn));
@ -804,9 +807,13 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
public void SetDisplayCountForAllAvailPlayers(bool state)
{
foreach (var pawn in availPlayers)
if (state)
{
UpdatePlayerCountOnTile(pawn, state);
availPlayers.ForEach(pawn => ShowUpdatedPlayerCountOnTile(pawn));
}
else
{
availPlayers.ForEach(pawn => pawn.ShowPlayerCountCanvas(false));
}
}
@ -827,7 +834,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
}
Debug.Log($"tile targetPosition: {targetPosition}");
UpdatePlayerCountOnTile(playerPawn, false);
playerPawn.ShowPlayerCountCanvas(false);
playerPawn.MoveToTile(
targetPosition,
@ -860,7 +867,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"nextTile.IsSafeZone: {nextTile.IsSafeZone}");
if (CanRollDiceAgain)
UpdatePlayerCountOnTile(playerPawn, true);
ShowUpdatedPlayerCountOnTile(playerPawn);
if (!nextTile.IsSafeZone)
{
@ -900,7 +907,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
}
nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
UpdatePlayerCountOnTile(playerPawn, true);
ShowUpdatedPlayerCountOnTile(playerPawn);
if (CheckForMaxDiceRollAttempt())
{
@ -1003,6 +1010,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
{
if (playerPawn.CurrentTileIndex == tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1)
{
playerPawn.ShowPlayerCountCanvas(false);
UpdatePlayerState(playerPawn, PlayerState.HasFinished);
playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished++;
@ -1044,15 +1052,18 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
else
{
// activate here
tilesManager.RetrieveFinishingTileBasedOnIndex(currentPlayerTypeTurn, playerPawn.CurrentTileIndex).InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
if (CheckForMaxDiceRollAttempt())
{
return;
}
if (CanRollDiceAgain)
ShowUpdatedPlayerCountOnTile(playerPawn);
SwitchPlayer();
}
UpdatePlayerCountOnTile(playerPawn, CanRollDiceAgain && playerPawn.CurrentTileIndex != tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1);
}
},
index);
@ -1064,14 +1075,13 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"CAnRollDiceForUser: {CanRollDiceForUser}");
}
private void UpdatePlayerCountOnTile(PlayerPawn playerPawn, bool show)
private void ShowUpdatedPlayerCountOnTile(PlayerPawn playerPawn)
{
Tile tile = playerPawn.GetPlayerState() == PlayerState.InFinishingPath ?
tilesManager.RetrieveFinishingTileBasedOnIndex(playerPawn.PlayerType, playerPawn.CurrentTileIndex)
: tilesManager.RetrieveTileBasedOnIndex(playerPawn.CurrentTileIndex);
playerPawn.ShowPlayerCountCanvas(show);
if (!show) return;
playerPawn.ShowPlayerCountCanvas(true);
int count = 0;
if (tile.IsSafeZone)
@ -1083,6 +1093,8 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
count = tile.TotalPawnsInTile;
}
Debug.Log($"ShowUpdatedPlayerCountOnTile: {count}");
playerPawn.PlayerCountCanvas.SetPlayerCount(count);
}

View File

@ -21,7 +21,6 @@ public class PlayerPawn : MonoBehaviour
{
[SerializeField] private PlayerState playerState;
[SerializeField] private Animator animator;
[SerializeField] private GameObject playerCountCanvasPrefab;
[SerializeField] private PlayerCountCanvas playerCountCanvas;
public PlayerCountCanvas PlayerCountCanvas => playerCountCanvas;
@ -170,8 +169,6 @@ public class PlayerPawn : MonoBehaviour
public void ShowPlayerCountCanvas(bool show)
{
if (playerCountCanvasPrefab == null) return;
playerCountCanvasPrefab.SetActive(show);
playerCountCanvas.gameObject.SetActive(show);
}
}