Fixes: Player data is still cached after leaving end index of general tiles,
This commit is contained in:
parent
025b13a400
commit
be79221cbd
@ -236,7 +236,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
{
|
{
|
||||||
Debug.Log($"Switching player");
|
Debug.Log($"Switching player");
|
||||||
SwitchPlayer();
|
SwitchPlayer();
|
||||||
CanRollDice = true;
|
SetCanRollDiceForUser(currentPlayerTypeTurn, true);
|
||||||
}
|
}
|
||||||
// else if (botTypesInGame.Contains(currentPlayerTypeTurn) && CanRollDiceAgain)
|
// else if (botTypesInGame.Contains(currentPlayerTypeTurn) && CanRollDiceAgain)
|
||||||
// {
|
// {
|
||||||
@ -416,7 +416,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
|
|
||||||
public void OnDiceRolled(int rolledVal)
|
public void OnDiceRolled(int rolledVal)
|
||||||
{
|
{
|
||||||
CanRollDice = false;
|
SetCanRollDiceForUser(currentPlayerTypeTurn, false);
|
||||||
|
|
||||||
// add core dice logic here
|
// add core dice logic here
|
||||||
Debug.Log($"Tile Index :: LUDO :: rolledVal: {rolledVal} :: {currentPlayerTypeTurn}");
|
Debug.Log($"Tile Index :: LUDO :: rolledVal: {rolledVal} :: {currentPlayerTypeTurn}");
|
||||||
@ -439,7 +439,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
Debug.Log($"### AreAllPawnsInFinishingPath");
|
Debug.Log($"### AreAllPawnsInFinishingPath");
|
||||||
if (AreAllPawnsInFinishingPath())
|
if (AreAllPawnsInFinishingPath())
|
||||||
{
|
{
|
||||||
CanRollDice = true;
|
SetCanRollDiceForUser(currentPlayerTypeTurn, true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -552,7 +552,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
{
|
{
|
||||||
playerGameDatasDict[playerGameData.playerType].totalPawnsInHome--;
|
playerGameDatasDict[playerGameData.playerType].totalPawnsInHome--;
|
||||||
|
|
||||||
CanRollDice = true;
|
SetCanRollDiceForUser(playerPawn.PlayerType, true);
|
||||||
UpdatePlayerState(playerPawn, PlayerState.InSafeZone);
|
UpdatePlayerState(playerPawn, PlayerState.InSafeZone);
|
||||||
if (playerPawn.IsBotPlayer)
|
if (playerPawn.IsBotPlayer)
|
||||||
CheckDiceRollForBot(playerPawn);
|
CheckDiceRollForBot(playerPawn);
|
||||||
@ -561,15 +561,14 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath
|
else if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath)
|
||||||
|| playerPawn.CurrentTileIndex == playerGameDatasDict[currentPlayerTypeTurn].endIndex)
|
|
||||||
{
|
{
|
||||||
int finishingPathIndex = GetNextFinishingTileIndex(playerPawn);
|
ApplyFinishingPathLogic(playerPawn);
|
||||||
int targetIdx = finishingPathIndex + diceRolledValue > tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 ?
|
}
|
||||||
tilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1 : finishingPathIndex + diceRolledValue;
|
else if (playerPawn.CurrentTileIndex == playerGameDatasDict[currentPlayerTypeTurn].endIndex)
|
||||||
|
{
|
||||||
Debug.Log($"TargetIdx: {targetIdx}, finishingPathIndex: {finishingPathIndex}");
|
tilesManager.RetrieveTileBasedOnIndex(playerPawn.CurrentTileIndex).ResetPlayerPawn(playerPawn);
|
||||||
MoveThroughFinishingPath(playerPawn, finishingPathIndex, targetIdx);
|
ApplyFinishingPathLogic(playerPawn);
|
||||||
}
|
}
|
||||||
else if (playerPawn.GetPlayerState() == PlayerState.InSafeZone || playerPawn.GetPlayerState() == PlayerState.Moving)
|
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)
|
public int GetNextGeneralTileIndex(PlayerPawn playerPawn)
|
||||||
{
|
{
|
||||||
return playerPawn.CurrentTileIndex == tilesManager.GetGeneralTilesLength() - 1 ? 0 : playerPawn.CurrentTileIndex + 1;
|
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.
|
// play animation for moving back to base.
|
||||||
// TODO :: Send existing pawn back to base.
|
// TODO :: Send existing pawn back to base.
|
||||||
// means there's already a pawn there, move him back to the 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--)
|
for (int i = counter; i > 0; i--)
|
||||||
{
|
{
|
||||||
var pawn = nextTile.GetPlayerPawn();
|
var pawn = nextTile.GetPlayerPawn();
|
||||||
@ -735,13 +744,28 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
playerGameDatasDict[pawn.PlayerType].totalPawnsInHome++;
|
playerGameDatasDict[pawn.PlayerType].totalPawnsInHome++;
|
||||||
pawn.MoveBackToHome(playerBasePos);
|
pawn.MoveBackToHome(playerBasePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CanRollDiceAgain = true;
|
||||||
|
|
||||||
|
if (playerPawn.IsBotPlayer)
|
||||||
|
CheckDiceRollForBot(playerPawn);
|
||||||
|
else
|
||||||
|
SetCanRollDiceForUser(playerPawn.PlayerType, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
|
nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (playerPawn.IsBotPlayer && CanRollDiceAgain)
|
||||||
|
CheckDiceRollForBot(playerPawn);
|
||||||
|
}
|
||||||
|
|
||||||
SwitchPlayer(playerPawn);
|
if (!CanRollDiceAgain)
|
||||||
CanRollDice = true;
|
{
|
||||||
|
SwitchPlayer(playerPawn);
|
||||||
|
SetCanRollDiceForUser(playerPawn.PlayerType, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
index);
|
index);
|
||||||
@ -836,10 +860,10 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished == playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Count)
|
if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished == playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Count)
|
||||||
{
|
{
|
||||||
CanRollDiceAgain = false;
|
CanRollDiceAgain = false;
|
||||||
|
|
||||||
if (allPlayerTypes.Contains(currentPlayerTypeTurn))
|
if (allPlayerTypes.Contains(currentPlayerTypeTurn))
|
||||||
allPlayerTypes.Remove(currentPlayerTypeTurn);
|
allPlayerTypes.Remove(currentPlayerTypeTurn);
|
||||||
|
|
||||||
SwitchPlayer();
|
SwitchPlayer();
|
||||||
|
|
||||||
Debug.Log($"PlayerTypes: {allPlayerTypes.Count}");
|
Debug.Log($"PlayerTypes: {allPlayerTypes.Count}");
|
||||||
@ -855,10 +879,17 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
{
|
{
|
||||||
SwitchPlayer();
|
SwitchPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
CanRollDice = true;
|
SetCanRollDiceForUser(playerPawn.PlayerType, true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
index);
|
index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetCanRollDiceForUser(PlayerType playerType, bool state)
|
||||||
|
{
|
||||||
|
if (botTypesInGame.Contains(playerType)) return;
|
||||||
|
|
||||||
|
CanRollDice = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user