Refactored FindPossibleTileData function.

This commit is contained in:
Ashby Issac 2026-02-02 16:06:29 +05:30 committed by alantrix0012
parent 273c86d5b9
commit d07951dabf

View File

@ -24,6 +24,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
[SerializeField] private int diceValue = 0; [SerializeField] private int diceValue = 0;
[SerializeField] private int maxDiceSixRollCounter = 2; [SerializeField] private int maxDiceSixRollCounter = 2;
[SerializeField] private int totalStepsForCharacter = 57;
[SerializeField] private TextMeshProUGUI diceText; [SerializeField] private TextMeshProUGUI diceText;
@ -464,16 +465,24 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
private void FindPossibleTileData(PlayerPawn playerPawn, out int possibleSteps, out Tile possibleTileData) private void FindPossibleTileData(PlayerPawn playerPawn, out int possibleSteps, out Tile possibleTileData)
{ {
possibleSteps = playerGameDatasDict[playerPawn.PlayerType].playerPawnsDict[playerPawn.PlayerId].StepsTaken + diceRolledValue; int lastStepGenTile = totalStepsForCharacter - tilesManager.GetFinishingTileDataLength(playerPawn.PlayerType);//playerGameDatasDict[playerPawn.PlayerType].endIndex;
int lastStepGenTileIdx = playerGameDatasDict[playerPawn.PlayerType].endIndex;
int possibleTileIndex = playerPawn.CurrentTileIndex + diceRolledValue; int possibleTileIndex = playerPawn.CurrentTileIndex + diceRolledValue;
int totalStepsInGeneralPath = tilesManager.GetGeneralTilesLength() - 1; // including the first safe zone
int lastTileIndex = tilesManager.GetGeneralTilesLength() - 1; int lastTileIndex = tilesManager.GetGeneralTilesLength() - 1;
int index = possibleSteps > totalStepsInGeneralPath ? possibleTileIndex - lastStepGenTileIdx - 1 bool canGoingInsideFinishingPath = IsGoingInsideFinishingPath(playerPawn, out possibleSteps);
: possibleTileIndex > lastTileIndex ? possibleTileIndex - lastTileIndex - 1 : possibleTileIndex;
possibleTileData = possibleSteps > totalStepsInGeneralPath ? tilesManager.RetrieveFinishingTileBasedOnIndex(playerPawn.PlayerType, index) : tilesManager.RetrieveTileBasedOnIndex(index); int index = canGoingInsideFinishingPath ? possibleSteps - lastStepGenTile - 1
: possibleTileIndex > lastTileIndex ? possibleTileIndex - lastTileIndex - 1 : possibleTileIndex; // case for addressing the scenario when going through the last index of general tiles.
Debug.Log($"possibleTileIndex: {possibleTileIndex}, lastStepGenTileIdx: {lastStepGenTile}");
Debug.Log($"index: {index}");
possibleTileData = canGoingInsideFinishingPath ? tilesManager.RetrieveFinishingTileBasedOnIndex(playerPawn.PlayerType, index) : tilesManager.RetrieveTileBasedOnIndex(index);
}
public bool IsGoingInsideFinishingPath(PlayerPawn playerPawn, out int possibleSteps)
{
possibleSteps = playerGameDatasDict[playerPawn.PlayerType].playerPawnsDict[playerPawn.PlayerId].StepsTaken + diceRolledValue;
return possibleSteps > tilesManager.GetGeneralTilesLength() - 1;
} }
public void OnDiceRolled(int rolledVal) public void OnDiceRolled(int rolledVal)