Compare commits

...

5 Commits

3 changed files with 86 additions and 32 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DG.Tweening;
using TMPro;
using UnityEngine;
@ -80,6 +81,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
public void Initialize()
{
InterfaceManager.Instance?.RegisterInterface<GameplayManager>(this);
DOTween.useSafeMode = false;
}
public void InitializeData()
@ -234,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)
// {
@ -310,7 +312,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"AI playerPawn :: {playerPawn.name} :: state: {playerPawn.GetPlayerState()}, possibleLandingIndex: {possibleLandingIndex > playerGameDatasDict[currentPlayerTypeTurn].endIndex}");
Debug.Log($"AI playerPawn :: {playerPawn.name} :: possibleTileData.IsSafeZone: {possibleTileData.IsSafeZone}");
Debug.Log($"AI playerPawn :: {playerPawn.name} :: possibleTileData.PlayerPawn: {possibleTileData.PlayerPawn}");
Debug.Log($"AI playerPawn :: {playerPawn.name} :: possibleTileData.PlayerPawn: {possibleTileData.HasPawnsAvailable}");
if (playerPawn.GetPlayerState() == PlayerState.InFinishingPath || possibleLandingIndex > playerGameDatasDict[currentPlayerTypeTurn].endIndex)
{
@ -331,7 +333,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: safeMove");
botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.SafeMove;
}
else if (possibleTileData.PlayerPawn != null)
else if (possibleTileData.HasPawnsAvailable)
{
Debug.Log($"AI playerPawn :: {playerPawn.name} :: {playerPawn.PlayerId} :: attackMove");
botPawnsDictForCurrentPlayer[playerPawn.PlayerId] = BotMove.AttackMove;
@ -414,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}");
@ -437,7 +439,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"### AreAllPawnsInFinishingPath");
if (AreAllPawnsInFinishingPath())
{
CanRollDice = true;
SetCanRollDiceForUser(currentPlayerTypeTurn, true);
return;
}
@ -550,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);
@ -559,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)
{
@ -596,13 +597,24 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
}
else
{
currentSittingTile.ResetPlayerPawn();
currentSittingTile.ResetPlayerPawn(playerPawn);
}
MoveThroughTiles(playerPawn, nextTileIdx, targetIndex: targetIdx);
}
}
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;
@ -710,25 +722,45 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
Debug.Log($"nextTile.IsSafeZone: {nextTile.IsSafeZone}");
if (!nextTile.IsSafeZone)
{
Debug.Log($"nextTile.PlayerPawn: {nextTile.PlayerPawn}, {nextTile.transform.name}");
if (nextTile.PlayerPawn != null && playerPawn.PlayerType != nextTile.PlayerPawn.PlayerType)
Debug.Log($"nextTile.HasPawnsAvailable: {nextTile.HasPawnsAvailable}");
if (nextTile.HasPawnsAvailable && playerPawn.PlayerType != nextTile.CurrentHoldingPlayerType)
{
Debug.Log($"nextTile.PlayerPawn: {nextTile.CurrentHoldingPlayerType}, {nextTile.transform.name}");
Debug.Log($"nextTile.TotalPawnsInTile: {nextTile.TotalPawnsInTile}");
// 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 playerBasePos = playerBaseHandler.GetPlayerBase(nextTile.PlayerPawn.PlayerType)
.GetBasePlacementDataPosition(nextTile.PlayerPawn.PlayerId - 1);
Debug.Log($"playerBasePos: {playerBasePos}");
int counter = nextTile.TotalPawnsInTile;
for (int i = counter; i > 0; i--)
{
var pawn = nextTile.GetPlayerPawn();
Debug.Log($"pawn: {pawn}");
Debug.Log($"playerBase: {playerBaseHandler}");
var playerBasePos = playerBaseHandler.GetPlayerBase(pawn.PlayerType)
.GetBasePlacementDataPosition(pawn.PlayerId - 1);
Debug.Log($"playerBasePos: {playerBasePos}");
playerGameDatasDict[nextTile.PlayerPawn.PlayerType].totalPawnsInHome++;
nextTile.PlayerPawn.MoveBackToHome(playerBasePos);
playerGameDatasDict[pawn.PlayerType].totalPawnsInHome++;
pawn.MoveBackToHome(playerBasePos);
}
CanRollDiceAgain = true;
if (playerPawn.IsBotPlayer)
CheckDiceRollForBot(playerPawn);
else
SetCanRollDiceForUser(playerPawn.PlayerType, true);
}
nextTile.InitPlayerPawn(playerPawn, currentPlayerTypeTurn);
}
SwitchPlayer(playerPawn);
CanRollDice = true;
if (!CanRollDiceAgain)
{
SetCanRollDiceForUser(playerPawn.PlayerType, true);
}
}
},
index);
@ -819,14 +851,16 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
UpdatePlayerState(playerPawn, PlayerState.HasFinished);
playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished++;
Debug.Log($"totalPawnsFinished: {playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished}, playerPawnsDict.Count: {playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Count}");
if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsFinished == playerGameDatasDict[currentPlayerTypeTurn].playerPawnsDict.Count)
{
CanRollDiceAgain = false;
SwitchPlayer();
if (allPlayerTypes.Contains(currentPlayerTypeTurn))
allPlayerTypes.Remove(currentPlayerTypeTurn);
SwitchPlayer();
Debug.Log($"PlayerTypes: {allPlayerTypes.Count}");
}
else
@ -840,10 +874,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;
}
}

View File

@ -39,6 +39,7 @@ public class PlayerBase : MonoBehaviour
public Transform GetBasePlacementDataPosition(int idx)
{
Debug.Log($"Index: {idx}, basePlacementDatas[idx]: {basePlacementDatas[idx]}");
return basePlacementDatas[idx].placementTransform;
}
}

View File

@ -27,18 +27,30 @@ public class Tile : MonoBehaviour
protected int lastOccupiedIndex = 0;
public PlayerPawn PlayerPawn // Change implementation
private List<PlayerPawn> PlayerPawns = new List<PlayerPawn>(); // Change implementation
public bool HasPawnsAvailable => PlayerPawns.Count > 0;
public PlayerType CurrentHoldingPlayerType => PlayerPawns[0].PlayerType;
public int TotalPawnsInTile => PlayerPawns.Count;
public PlayerPawn GetPlayerPawn()
{
get; private set;
var pawn = PlayerPawns[0];
PlayerPawns.RemoveAt(0);
return pawn;
}
public virtual void InitPlayerPawn(PlayerPawn playerPawn, PlayerType playerType)
{
PlayerPawn = playerPawn;
PlayerPawns.Add(playerPawn);
Debug.Log($"Adding new PlayerPawn {playerPawn.name}, playerType: {playerType} to {name}");
Debug.Log($"Adding new PlayerPawn {PlayerPawns.Count} {name}");
}
public void ResetPlayerPawn()
public void ResetPlayerPawn(PlayerPawn movingPawn)
{
PlayerPawn = null;
PlayerPawns.Remove(movingPawn);
Debug.Log($"Resetting new PlayerPawn {movingPawn.name} {name}");
Debug.Log($"Resetting new PlayerPawn {PlayerPawns.Count} {name}");
}
}