From be79221cbd5147f9e673dbf0db097b914728628e Mon Sep 17 00:00:00 2001 From: Ashby Issac Date: Thu, 29 Jan 2026 19:48:25 +0530 Subject: [PATCH] Fixes: Player data is still cached after leaving end index of general tiles, --- Assets/Scripts/Gameplay/GameplayManager.cs | 71 ++++++++++++++++------ 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/Assets/Scripts/Gameplay/GameplayManager.cs b/Assets/Scripts/Gameplay/GameplayManager.cs index fb6f57f..d01bf32 100644 --- a/Assets/Scripts/Gameplay/GameplayManager.cs +++ b/Assets/Scripts/Gameplay/GameplayManager.cs @@ -236,7 +236,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { Debug.Log($"Switching player"); SwitchPlayer(); - CanRollDice = true; + SetCanRollDiceForUser(currentPlayerTypeTurn, true); } // else if (botTypesInGame.Contains(currentPlayerTypeTurn) && CanRollDiceAgain) // { @@ -416,7 +416,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public void OnDiceRolled(int rolledVal) { - CanRollDice = false; + SetCanRollDiceForUser(currentPlayerTypeTurn, false); // add core dice logic here Debug.Log($"Tile Index :: LUDO :: rolledVal: {rolledVal} :: {currentPlayerTypeTurn}"); @@ -439,7 +439,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader Debug.Log($"### AreAllPawnsInFinishingPath"); if (AreAllPawnsInFinishingPath()) { - CanRollDice = true; + SetCanRollDiceForUser(currentPlayerTypeTurn, true); return; } @@ -552,7 +552,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { playerGameDatasDict[playerGameData.playerType].totalPawnsInHome--; - CanRollDice = true; + SetCanRollDiceForUser(playerPawn.PlayerType, true); UpdatePlayerState(playerPawn, PlayerState.InSafeZone); if (playerPawn.IsBotPlayer) CheckDiceRollForBot(playerPawn); @@ -561,15 +561,14 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader return; } - else if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath - || playerPawn.CurrentTileIndex == playerGameDatasDict[currentPlayerTypeTurn].endIndex) + else if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath) { - int finishingPathIndex = GetNextFinishingTileIndex(playerPawn); - int targetIdx = finishingPathIndex + diceRolledValue > tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 ? - tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 : finishingPathIndex + diceRolledValue; - - Debug.Log($"TargetIdx: {targetIdx}, finishingPathIndex: {finishingPathIndex}"); - MoveThroughFinishingPath(playerPawn, finishingPathIndex, targetIdx); + ApplyFinishingPathLogic(playerPawn); + } + else if (playerPawn.CurrentTileIndex == playerGameDatasDict[currentPlayerTypeTurn].endIndex) + { + tilesManager.RetrieveTileBasedOnIndex(playerPawn.CurrentTileIndex).ResetPlayerPawn(playerPawn); + ApplyFinishingPathLogic(playerPawn); } else if (playerPawn.GetPlayerState() == PlayerState.InSafeZone || playerPawn.GetPlayerState() == PlayerState.Moving) { @@ -605,6 +604,17 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } } + private void ApplyFinishingPathLogic(PlayerPawn playerPawn) + { + int finishingPathIndex = GetNextFinishingTileIndex(playerPawn); + int targetIdx = finishingPathIndex + diceRolledValue > tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 ? + tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 : finishingPathIndex + diceRolledValue; + + Debug.Log($"TargetIdx: {targetIdx}, finishingPathIndex: {finishingPathIndex}"); + MoveThroughFinishingPath(playerPawn, finishingPathIndex, targetIdx); + } + + public int GetNextGeneralTileIndex(PlayerPawn playerPawn) { return playerPawn.CurrentTileIndex == tilesManager.GetGeneralTilesLength() - 1 ? 0 : playerPawn.CurrentTileIndex + 1; @@ -720,8 +730,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader // play animation for moving back to base. // TODO :: Send existing pawn back to base. // means there's already a pawn there, move him back to the base. - var counter = nextTile.TotalPawnsInTile; - + int counter = nextTile.TotalPawnsInTile; for (int i = counter; i > 0; i--) { var pawn = nextTile.GetPlayerPawn(); @@ -735,13 +744,28 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader playerGameDatasDict[pawn.PlayerType].totalPawnsInHome++; pawn.MoveBackToHome(playerBasePos); } + + CanRollDiceAgain = true; + + if (playerPawn.IsBotPlayer) + CheckDiceRollForBot(playerPawn); + else + SetCanRollDiceForUser(playerPawn.PlayerType, true); } nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn); } + else + { + if (playerPawn.IsBotPlayer && CanRollDiceAgain) + CheckDiceRollForBot(playerPawn); + } - SwitchPlayer(playerPawn); - CanRollDice = true; + if (!CanRollDiceAgain) + { + SwitchPlayer(playerPawn); + SetCanRollDiceForUser(playerPawn.PlayerType, true); + } } }, index); @@ -836,10 +860,10 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished == playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Count) { CanRollDiceAgain = false; - + if (allPlayerTypes.Contains(currentPlayerTypeTurn)) allPlayerTypes.Remove(currentPlayerTypeTurn); - + SwitchPlayer(); Debug.Log($"PlayerTypes: {allPlayerTypes.Count}"); @@ -855,10 +879,17 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { SwitchPlayer(); } - - CanRollDice = true; + + SetCanRollDiceForUser(playerPawn.PlayerType, true); } }, index); } + + private void SetCanRollDiceForUser(PlayerType playerType, bool state) + { + if (botTypesInGame.Contains(playerType)) return; + + CanRollDice = true; + } }