Added auto selecting logic for player.

This commit is contained in:
Ashby Issac 2026-02-10 19:24:08 +05:30
parent 0814fce7af
commit 97cd17c0cf
3 changed files with 83 additions and 36 deletions

View File

@ -8476,24 +8476,28 @@ MonoBehaviour:
playersParent: {fileID: 1373272158} playersParent: {fileID: 1373272158}
totalPawnsInHome: 0 totalPawnsInHome: 0
totalPawnsFinished: 0 totalPawnsFinished: 0
totalPawnsInFinishingPath: 0
- playerType: 1 - playerType: 1
startIndex: 13 startIndex: 13
endIndex: 11 endIndex: 11
playersParent: {fileID: 1841959051} playersParent: {fileID: 1841959051}
totalPawnsInHome: 0 totalPawnsInHome: 0
totalPawnsFinished: 0 totalPawnsFinished: 0
totalPawnsInFinishingPath: 0
- playerType: 2 - playerType: 2
startIndex: 26 startIndex: 26
endIndex: 24 endIndex: 24
playersParent: {fileID: 1934858463} playersParent: {fileID: 1934858463}
totalPawnsInHome: 0 totalPawnsInHome: 0
totalPawnsFinished: 0 totalPawnsFinished: 0
totalPawnsInFinishingPath: 0
- playerType: 3 - playerType: 3
startIndex: 39 startIndex: 39
endIndex: 37 endIndex: 37
playersParent: {fileID: 1094154913} playersParent: {fileID: 1094154913}
totalPawnsInHome: 0 totalPawnsInHome: 0
totalPawnsFinished: 0 totalPawnsFinished: 0
totalPawnsInFinishingPath: 0
playerBaseHandler: {fileID: 433034051} playerBaseHandler: {fileID: 433034051}
--- !u!4 &896294589 stripped --- !u!4 &896294589 stripped
Transform: Transform:

View File

@ -76,7 +76,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
private bool CanRollDiceAgain = false; // used for when you get a 6 or when you reach the finish point private bool CanRollDiceAgain = false; // used for when you get a 6 or when you reach the finish point
private int diceSixRollCounter = 0; private int diceSixRollCounter = 0;
private List<PlayerPawn> availPlayers = new List<PlayerPawn>(); private List<PlayerPawn> availPlayersToMove = new List<PlayerPawn>();
private bool canSwitchPlayer = true; private bool canSwitchPlayer = true;
public bool CanRollDiceForUser public bool CanRollDiceForUser
@ -396,7 +396,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
// What happens when you get a 6 // What happens when you get a 6
private void SelectPawnFromBotBase() private void SelectPawnFromBotBase()
{ {
if (canSwitchPlayer || availPlayers.Count() < 1 && !CanRollDiceAgain || !botTypesInGame.Contains(currentPlayerTypeTurn)) if (canSwitchPlayer || availPlayersToMove.Count() < 1 && !CanRollDiceAgain || !botTypesInGame.Contains(currentPlayerTypeTurn))
{ {
Debug.Log($"returning from SelectPawnFromBotBase"); Debug.Log($"returning from SelectPawnFromBotBase");
return; // Have a better check here return; // Have a better check here
@ -408,7 +408,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
int savedPlayerId = -1; int savedPlayerId = -1;
PlayerPawn pawn = null; PlayerPawn pawn = null;
Debug.Log($"SelectPawnFromBotBase: availPlayers.Count(): {availPlayers.Count()}, CanRollDiceAgain: {CanRollDiceAgain}"); Debug.Log($"SelectPawnFromBotBase: availPlayers.Count(): {availPlayersToMove.Count()}, CanRollDiceAgain: {CanRollDiceAgain}");
if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInHome == 0) if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInHome == 0)
{ {
@ -428,7 +428,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
} }
Debug.Log($"Before Iterating"); Debug.Log($"Before Iterating");
foreach (var playerPawn in availPlayers) foreach (var playerPawn in availPlayersToMove)
{ {
int possibleSteps = 0; int possibleSteps = 0;
Tile possibleTileData = null; Tile possibleTileData = null;
@ -578,15 +578,12 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"Tile Index :: LUDO :: rolledVal: {rolledVal} :: {currentPlayerTypeTurn}"); Debug.Log($"Tile Index :: LUDO :: rolledVal: {rolledVal} :: {currentPlayerTypeTurn}");
diceRolledValue = rolledVal; diceRolledValue = rolledVal;
diceText.text = $"{diceRolledValue}"; diceText.text = $"{diceRolledValue}";
availPlayers = new List<PlayerPawn>(); availPlayersToMove = new List<PlayerPawn>();
InitActivePlayers();
if (!CanRollDiceAgain) if (!CanRollDiceAgain)
{ {
UpdateActivePlayersAndSetDisplay(true); SetDisplayCountForAllAvailPlayers(true);
}
else
{
InitActivePlayers();
} }
if (rolledVal == Ludo_3D_Constants.Max_Dice_Rolls) if (rolledVal == Ludo_3D_Constants.Max_Dice_Rolls)
@ -596,6 +593,27 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
// also play a simple animation before selecting // also play a simple animation before selecting
CanRollDiceAgain = true; CanRollDiceAgain = true;
diceSixRollCounter++; diceSixRollCounter++;
if (botTypesInGame != null && !botTypesInGame.Contains(currentPlayerTypeTurn))
{
var hasNoPlayersTraveling = Mathf.Abs(availPlayersToMove.Count - playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInFinishingPath) < 1;
Debug.Log($"availPlayersToMove.Count: {availPlayersToMove.Count}, hasNoPlayersTraveling: {hasNoPlayersTraveling}, totalPawnsInFinishingPath: {playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInFinishingPath}");
if (availPlayersToMove.Count < 1 || hasNoPlayersTraveling)
{
if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInHome > 0)
{
OnPawnSelected(playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Values
.FirstOrDefault(pawn => pawn.GetPlayerState() == PlayerState.InHome));
return;
}
}
else
{
if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInHome < 1 && CanMoveSoloPlayer())
return;
}
}
#if UNITY_EDITOR #if UNITY_EDITOR
pointerMeshRend.material = selectMat; pointerMeshRend.material = selectMat;
#endif #endif
@ -612,56 +630,75 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
} }
Debug.Log($"### EnablePlayerSelectionStates"); Debug.Log($"### EnablePlayerSelectionStates");
EnablePlayerSelectionStates(true); EnablePlayerSelectionStates(true);
// pointerMeshRend.materials[0] = selectMat; // pointerMeshRend.materials[0] = selectMat;
} }
else // if there are any other pawns that are in safe or moving state else // if there are any other pawns that are in safe or moving state
{ {
// for player's logic Debug.Log($"before CustomAvailablePlayers: {availPlayersToMove.Count}");
int customAvailPlayers = availPlayers.Count();
Debug.Log($"before CustomAvailablePlayers: {customAvailPlayers}");
List<int> indexesToRemove = new List<int>(); List<int> indexesToRemove = new List<int>();
for (int i = 0; i < availPlayers.Count; i++) for (int i = 0; i < availPlayersToMove.Count; i++)
{ {
Debug.Log($"## playerPawn.GetPlayerState(): {availPlayers[i].GetPlayerState()}"); Debug.Log($"## playerPawn.GetPlayerState(): {availPlayersToMove[i].GetPlayerState()}");
if (availPlayers[i].GetPlayerState() == PlayerState.InFinishingPath) if (availPlayersToMove[i].GetPlayerState() == PlayerState.InFinishingPath)
{ {
Debug.Log($"diceRolledValue: {diceRolledValue}, FinishingDataLen: {TilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn)}, playerPawn.CurrentTileIndex: {availPlayers[i].CurrentTileIndex}"); Debug.Log($"diceRolledValue: {diceRolledValue}, FinishingDataLen: {TilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn)}, playerPawn.CurrentTileIndex: {availPlayersToMove[i].CurrentTileIndex}");
if (diceRolledValue <= TilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - (availPlayers[i].CurrentTileIndex + 1)) if (diceRolledValue <= TilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - (availPlayersToMove[i].CurrentTileIndex + 1))
{ {
availPlayers[i].SetPlayerSelectionState(true); availPlayersToMove[i].SetPlayerSelectionState(true);
} }
else else
{ {
indexesToRemove.Add(i); indexesToRemove.Add(i);
availPlayers[i].SetPlayerSelectionState(false); availPlayersToMove[i].SetPlayerSelectionState(false);
availPlayers[i].ShowPlayerCountCanvas(false); availPlayersToMove[i].ShowPlayerCountCanvas(false);
customAvailPlayers--;
} }
continue; continue;
} }
availPlayers[i].SetPlayerSelectionState(true); availPlayersToMove[i].SetPlayerSelectionState(true);
} }
for (int idx = indexesToRemove.Count - 1; idx >= 0; idx--) for (int idx = indexesToRemove.Count - 1; idx >= 0; idx--)
availPlayers.RemoveAt(idx); availPlayersToMove.RemoveAt(idx);
// if (availPlayers.Count() < 1) Debug.Log($"CustomAvailablePlayers: {availPlayersToMove.Count}");
Debug.Log($"CustomAvailablePlayers: {customAvailPlayers}"); canSwitchPlayer = availPlayersToMove.Count < 1;
canSwitchPlayer = customAvailPlayers < 1;
CanRollDiceAgain = false; CanRollDiceAgain = false;
if (botTypesInGame != null && !botTypesInGame.Contains(currentPlayerTypeTurn) &&
availPlayersToMove.Count > 0)
{
if (CanMoveSoloPlayer())
{
EnablePlayerSelectionStates(false);
OnPawnSelected(availPlayersToMove[0]);
}
}
} }
Debug.Log($"CanRollDiceAgain: {CanRollDiceAgain}, canSwitchPlayer: {canSwitchPlayer}"); Debug.Log($"CanRollDiceAgain: {CanRollDiceAgain}, canSwitchPlayer: {canSwitchPlayer}");
} }
private bool CanMoveSoloPlayer()
{
if (availPlayersToMove.Count == 1)
{
if (availPlayersToMove[0].GetPlayerState() == PlayerState.InSafeZone || availPlayersToMove[0].GetPlayerState() == PlayerState.Moving
|| availPlayersToMove[0].GetPlayerState() == PlayerState.InFinishingPath)
{
return true;
}
}
return false;
}
private void UpdateActivePlayersAndSetDisplay(bool state) private void UpdateActivePlayersAndSetDisplay(bool state)
{ {
InitActivePlayers(); InitActivePlayers();
@ -670,7 +707,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
private void InitActivePlayers() private void InitActivePlayers()
{ {
availPlayers = playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Values.Select(pawn => pawn) availPlayersToMove = playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Values.Select(pawn => pawn)
.Where(pawn => pawn.GetPlayerState() == PlayerState.InSafeZone || .Where(pawn => pawn.GetPlayerState() == PlayerState.InSafeZone ||
pawn.GetPlayerState() == PlayerState.Moving || pawn.GetPlayerState() == PlayerState.Moving ||
pawn.GetPlayerState() == PlayerState.InFinishingPath).ToList(); pawn.GetPlayerState() == PlayerState.InFinishingPath).ToList();
@ -770,6 +807,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
else if (selectedPawn.CurrentTileIndex == playerGameDatasDict[currentPlayerTypeTurn].endIndex) else if (selectedPawn.CurrentTileIndex == playerGameDatasDict[currentPlayerTypeTurn].endIndex)
{ {
TilesManager.RetrieveTileBasedOnIndex(selectedPawn.CurrentTileIndex).ResetPlayerPawn(selectedPawn); TilesManager.RetrieveTileBasedOnIndex(selectedPawn.CurrentTileIndex).ResetPlayerPawn(selectedPawn);
playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInFinishingPath++;
ApplyFinishingPathLogic(selectedPawn); ApplyFinishingPathLogic(selectedPawn);
} }
else if (selectedPawn.GetPlayerState() == PlayerState.InSafeZone || selectedPawn.GetPlayerState() == PlayerState.Moving) else if (selectedPawn.GetPlayerState() == PlayerState.InSafeZone || selectedPawn.GetPlayerState() == PlayerState.Moving)
@ -843,10 +881,10 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"currentPlayerTurn: {currentPlayerTypeTurn}"); Debug.Log($"currentPlayerTurn: {currentPlayerTypeTurn}");
Debug.Log($"currentPlayerTurnIndex: {currentPlayerTurnIndex}"); Debug.Log($"currentPlayerTurnIndex: {currentPlayerTurnIndex}");
Debug.Log($"before SwitchPlayer availPlayers: {availPlayers.Count}, playerPawn: {playerPawn}"); Debug.Log($"before SwitchPlayer availPlayers: {availPlayersToMove.Count}, playerPawn: {playerPawn}");
UpdateActivePlayersAndSetDisplay(false); UpdateActivePlayersAndSetDisplay(false);
Debug.Log($"after SwitchPlayer availPlayers: {availPlayers.Count}, playerPawn: {playerPawn}"); Debug.Log($"after SwitchPlayer availPlayers: {availPlayersToMove.Count}, playerPawn: {playerPawn}");
Debug.Log($"after allPlayerTypes.Count: {allPlayerTypes.Count}"); Debug.Log($"after allPlayerTypes.Count: {allPlayerTypes.Count}");
if (allPlayerTypes.Count == 0) if (allPlayerTypes.Count == 0)
@ -906,11 +944,11 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
{ {
if (state) if (state)
{ {
availPlayers.ForEach(pawn => ShowUpdatedPlayerCountOnTile(pawn)); availPlayersToMove.ForEach(pawn => ShowUpdatedPlayerCountOnTile(pawn));
} }
else else
{ {
availPlayers.ForEach(pawn => pawn.ShowPlayerCountCanvas(false)); availPlayersToMove.ForEach(pawn => pawn.ShowPlayerCountCanvas(false));
} }
} }
@ -948,6 +986,9 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
{ {
// MoveThroughTiles(playerPawn, index, targetIndex); // MoveThroughTiles(playerPawn, index, targetIndex);
Debug.Log($"TargetIdx: {targetIndex - index}"); Debug.Log($"TargetIdx: {targetIndex - index}");
if (index == playerGameDatasDict[currentPlayerTypeTurn].endIndex)
playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInFinishingPath++;
CheckForGamePause(() => MoveThroughFinishingPath(playerPawn, 0, targetIndex - index)); CheckForGamePause(() => MoveThroughFinishingPath(playerPawn, 0, targetIndex - index));
} }
else if (nextTileIndex <= targetIndex) else if (nextTileIndex <= targetIndex)
@ -1066,6 +1107,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
UpdatePlayerState(playerPawn, PlayerState.HasFinished); UpdatePlayerState(playerPawn, PlayerState.HasFinished);
playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished++; playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished++;
playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInFinishingPath--;
Debug.Log($"playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished: {playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished}"); Debug.Log($"playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished: {playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished}");
Debug.Log($"playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Count: {playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Count}"); Debug.Log($"playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Count: {playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Count}");
@ -1185,7 +1227,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
playerGameDatasDict = null; playerGameDatasDict = null;
playerDatas = null; playerDatas = null;
availPlayers = null; availPlayersToMove = null;
botTypesInGame = null; botTypesInGame = null;
botRuntimeMovementData = null; botRuntimeMovementData = null;

View File

@ -27,6 +27,7 @@ public class PlayerGameData
public Dictionary<int, PlayerPawn> playerPawnsDict; public Dictionary<int, PlayerPawn> playerPawnsDict;
public int totalPawnsInHome = 0; public int totalPawnsInHome = 0;
public int totalPawnsFinished = 0; public int totalPawnsFinished = 0;
public int totalPawnsInFinishingPath = 0;
} }
[System.Serializable] [System.Serializable]