Compare commits
No commits in common. "9db1a39af7fa1d3092c37f0608caebe5cd9a8041" and "fc4aeda01c6fc76cea8422a2a9e3289e66786c50" have entirely different histories.
9db1a39af7
...
fc4aeda01c
@ -1,9 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
using Random = UnityEngine.Random;
|
|
||||||
|
|
||||||
public class DiceView : MonoBehaviour, IBase
|
public class DiceView : MonoBehaviour, IBase
|
||||||
{
|
{
|
||||||
@ -13,21 +10,16 @@ public class DiceView : MonoBehaviour, IBase
|
|||||||
[SerializeField] private DiceSide[] diceSides;
|
[SerializeField] private DiceSide[] diceSides;
|
||||||
[SerializeField] private float sideValueTime = 1.2f;
|
[SerializeField] private float sideValueTime = 1.2f;
|
||||||
[SerializeField] private Vector3 startPos = new Vector3(0, 20, 0);
|
[SerializeField] private Vector3 startPos = new Vector3(0, 20, 0);
|
||||||
[SerializeField] private Button diceButton;
|
|
||||||
|
|
||||||
[Header("Physics Randomness")]
|
[Header("Physics Randomness")]
|
||||||
[SerializeField] private float baseSpinForce = 900f;
|
[SerializeField] private float baseSpinForce = 900f;
|
||||||
[SerializeField] private float sideForce = 0.18f;
|
[SerializeField] private float sideForce = 0.18f;
|
||||||
[SerializeField] private float liftForce = 0.1f;
|
[SerializeField] private float liftForce = 0.1f;
|
||||||
|
|
||||||
private List<int> probabilityValues = new List<int>() { 3, 4, 5 };
|
|
||||||
private Quaternion startRotation;
|
private Quaternion startRotation;
|
||||||
private Action<int> onRollingComplete = null;
|
private Action<int> onRollingComplete = null;
|
||||||
|
|
||||||
private IRollBase rollBase = null;
|
void Awake()
|
||||||
private bool hasNoActionOnRoll = false;
|
|
||||||
|
|
||||||
private void Awake()
|
|
||||||
{
|
{
|
||||||
rb = GetComponent<Rigidbody>();
|
rb = GetComponent<Rigidbody>();
|
||||||
rb.useGravity = false;
|
rb.useGravity = false;
|
||||||
@ -47,31 +39,31 @@ public class DiceView : MonoBehaviour, IBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator RollRoutine()
|
IEnumerator RollRoutine()
|
||||||
{
|
{
|
||||||
rolling = true;
|
rolling = true;
|
||||||
|
|
||||||
// MICRO DELAY → breaks physics sync between dice
|
// MICRO DELAY → breaks physics sync between dice
|
||||||
yield return new WaitForSeconds(Random.Range(0.01f, 0.06f));
|
yield return new WaitForSeconds(UnityEngine.Random.Range(0.01f, 0.06f));
|
||||||
|
|
||||||
rb.useGravity = true;
|
rb.useGravity = true;
|
||||||
|
|
||||||
// PER-DICE FORCE MULTIPLIER
|
// PER-DICE FORCE MULTIPLIER
|
||||||
float spinMultiplier = Random.Range(0.8f, 1.25f);
|
float spinMultiplier = UnityEngine.Random.Range(0.8f, 1.25f);
|
||||||
|
|
||||||
// RANDOM TORQUE
|
// RANDOM TORQUE
|
||||||
rb.AddTorque(
|
rb.AddTorque(
|
||||||
Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
UnityEngine.Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
||||||
Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
UnityEngine.Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
||||||
Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
UnityEngine.Random.Range(-baseSpinForce, baseSpinForce) * spinMultiplier,
|
||||||
ForceMode.Impulse
|
ForceMode.Impulse
|
||||||
);
|
);
|
||||||
|
|
||||||
// RANDOM SIDE FORCE
|
// RANDOM SIDE FORCE
|
||||||
Vector3 sideDir = new Vector3(
|
Vector3 sideDir = new Vector3(
|
||||||
Random.Range(-1f, 1f),
|
UnityEngine.Random.Range(-1f, 1f),
|
||||||
0f,
|
0f,
|
||||||
Random.Range(-1f, 1f)
|
UnityEngine.Random.Range(-1f, 1f)
|
||||||
).normalized;
|
).normalized;
|
||||||
|
|
||||||
rb.AddForce(sideDir * sideForce, ForceMode.Impulse);
|
rb.AddForce(sideDir * sideForce, ForceMode.Impulse);
|
||||||
@ -81,44 +73,28 @@ public class DiceView : MonoBehaviour, IBase
|
|||||||
|
|
||||||
yield return new WaitForSeconds(sideValueTime);
|
yield return new WaitForSeconds(sideValueTime);
|
||||||
|
|
||||||
int rolledVal = 0;
|
int value = GetDiceValue();
|
||||||
if (hasNoActionOnRoll)
|
|
||||||
{
|
|
||||||
if (rollBase.SixRollCount == 0)
|
|
||||||
{
|
|
||||||
rollBase.UpdateMaxRollCount(probabilityValues[Random.Range(0, probabilityValues.Count)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
rollBase.UpdateSixRollCount();
|
//TODO: Use the dice value as needed
|
||||||
rolledVal = rollBase.SixRollCount == rollBase.MaxRollCount ?
|
Debug.Log($"Dice rolled: {value}");
|
||||||
Ludo_3D_Constants.Max_Dice_Rolls : GetDiceValue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rolledVal = GetDiceValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rolledVal == Ludo_3D_Constants.Max_Dice_Rolls)
|
|
||||||
ResetRollData();
|
|
||||||
|
|
||||||
ResetDice();
|
ResetDice();
|
||||||
Debug.Log($"Dice rolled: {rolledVal}");
|
onRollingComplete?.Invoke(value);
|
||||||
onRollingComplete?.Invoke(rolledVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetDiceValue()
|
int GetDiceValue()
|
||||||
{
|
{
|
||||||
return Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1);
|
foreach (DiceSide side in diceSides)
|
||||||
|
{
|
||||||
|
if (side.OnGround())
|
||||||
|
return side.sideValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetRollData()
|
return 1;
|
||||||
{
|
|
||||||
if (rollBase != null) rollBase.ResetRollData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetDice()
|
public void ResetDice()
|
||||||
{
|
{
|
||||||
rollBase = null;
|
|
||||||
rb.useGravity = false;
|
rb.useGravity = false;
|
||||||
rb.velocity = Vector3.zero;
|
rb.velocity = Vector3.zero;
|
||||||
rb.angularVelocity = Vector3.zero;
|
rb.angularVelocity = Vector3.zero;
|
||||||
@ -126,25 +102,10 @@ public class DiceView : MonoBehaviour, IBase
|
|||||||
rolling = false;
|
rolling = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDiceButtonInteraction(bool status)
|
|
||||||
{
|
|
||||||
diceButton.interactable = status;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResetOnSessionEnd()
|
public void ResetOnSessionEnd()
|
||||||
{
|
{
|
||||||
ResetDice();
|
ResetDice();
|
||||||
transform.localRotation = startRotation;
|
transform.localRotation = startRotation;
|
||||||
onRollingComplete = null;
|
onRollingComplete = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitOnNoActionsAfterRoll(IRollBase rollBase, bool state)
|
|
||||||
{
|
|
||||||
hasNoActionOnRoll = state;
|
|
||||||
if (!state)
|
|
||||||
return;
|
|
||||||
|
|
||||||
this.rollBase = rollBase;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8476,28 +8476,24 @@ 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:
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 05273ddf992ca4671b13f0b4b9dde85d
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
public interface IRollBase
|
|
||||||
{
|
|
||||||
public int SixRollCount { get; }
|
|
||||||
|
|
||||||
public int MaxRollCount { get; }
|
|
||||||
|
|
||||||
void UpdateSixRollCount();
|
|
||||||
void UpdateMaxRollCount(int val);
|
|
||||||
void ResetRollData();
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 4683cbbafe11541cf8a71cdd12df62ac
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@ -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> availPlayersToMove = new List<PlayerPawn>();
|
private List<PlayerPawn> availPlayers = new List<PlayerPawn>();
|
||||||
private bool canSwitchPlayer = true;
|
private bool canSwitchPlayer = true;
|
||||||
|
|
||||||
public bool CanRollDiceForUser
|
public bool CanRollDiceForUser
|
||||||
@ -169,7 +169,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
|
|
||||||
private void HandleDiceRollWithDelay()
|
private void HandleDiceRollWithDelay()
|
||||||
{
|
{
|
||||||
Invoke(nameof(RollDiceForBot), botDiceRollDelay);
|
Invoke(nameof(HandleDiceRoll), botDiceRollDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitBotRuntimeData()
|
private void InitBotRuntimeData()
|
||||||
@ -240,7 +240,6 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
playerBaseHandler.ShowSelectedPlayerBase(currentPlayerTypeTurn, false);
|
playerBaseHandler.ShowSelectedPlayerBase(currentPlayerTypeTurn, false);
|
||||||
currentPlayerTypeTurn = playerType;
|
currentPlayerTypeTurn = playerType;
|
||||||
playerBaseHandler.ShowSelectedPlayerBase(currentPlayerTypeTurn, true);
|
playerBaseHandler.ShowSelectedPlayerBase(currentPlayerTypeTurn, true);
|
||||||
diceRollHandler.DiceView.SetDiceButtonInteraction(true);
|
|
||||||
|
|
||||||
UpdateTurnTimer();
|
UpdateTurnTimer();
|
||||||
}
|
}
|
||||||
@ -268,7 +267,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
currentPlayerTurnTimer.Init(currentPlayerTurnMaxTime, onComplete: () =>
|
currentPlayerTurnTimer.Init(currentPlayerTurnMaxTime, onComplete: () =>
|
||||||
{
|
{
|
||||||
Debug.Log($"currentPlayerTurnTimer: HandleDiceViewForUser");
|
Debug.Log($"currentPlayerTurnTimer: HandleDiceViewForUser");
|
||||||
RollDiceForUser();
|
diceRollHandler.HandleDiceViewForUser();
|
||||||
}, inProgress: (remTime) =>
|
}, inProgress: (remTime) =>
|
||||||
{
|
{
|
||||||
uIManager.UpdatePlayerTurnText(currentPlayerTypeTurn, currentPlayerTurnMaxTime - (int)remTime);
|
uIManager.UpdatePlayerTurnText(currentPlayerTypeTurn, currentPlayerTurnMaxTime - (int)remTime);
|
||||||
@ -350,7 +349,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
public void OnDiceInteracted()
|
public void OnDiceInteracted()
|
||||||
{
|
{
|
||||||
ResetCurrentPlayerTurnTimer();
|
ResetCurrentPlayerTurnTimer();
|
||||||
RollDiceForUser();
|
diceRollHandler.HandleDiceViewForUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RollDiceForPlayer(int rolledVal)
|
public void RollDiceForPlayer(int rolledVal)
|
||||||
@ -397,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 || availPlayersToMove.Count() < 1 && !CanRollDiceAgain || !botTypesInGame.Contains(currentPlayerTypeTurn))
|
if (canSwitchPlayer || availPlayers.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
|
||||||
@ -409,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(): {availPlayersToMove.Count()}, CanRollDiceAgain: {CanRollDiceAgain}");
|
Debug.Log($"SelectPawnFromBotBase: availPlayers.Count(): {availPlayers.Count()}, CanRollDiceAgain: {CanRollDiceAgain}");
|
||||||
|
|
||||||
if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInHome == 0)
|
if (playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInHome == 0)
|
||||||
{
|
{
|
||||||
@ -429,7 +428,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log($"Before Iterating");
|
Debug.Log($"Before Iterating");
|
||||||
foreach (var playerPawn in availPlayersToMove)
|
foreach (var playerPawn in availPlayers)
|
||||||
{
|
{
|
||||||
int possibleSteps = 0;
|
int possibleSteps = 0;
|
||||||
Tile possibleTileData = null;
|
Tile possibleTileData = null;
|
||||||
@ -516,7 +515,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (CanRollDiceAgain)
|
if (CanRollDiceAgain)
|
||||||
RollDiceForBot();
|
HandleDiceRoll();
|
||||||
else
|
else
|
||||||
SwitchPlayer();
|
SwitchPlayer();
|
||||||
}
|
}
|
||||||
@ -571,21 +570,23 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
return possibleSteps > TilesManager.GetGeneralTilesLength() - 1;
|
return possibleSteps > TilesManager.GetGeneralTilesLength() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HasNoPlayersTravelling() => Mathf.Abs(availPlayersToMove.Count - playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInFinishingPath) < 1;
|
|
||||||
|
|
||||||
public void OnDiceRolled(int rolledVal)
|
public void OnDiceRolled(int rolledVal)
|
||||||
{
|
{
|
||||||
SetCanRollDiceForUser(false);
|
SetCanRollDiceForUser(false);
|
||||||
diceRollHandler.DiceView.SetDiceButtonInteraction(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}");
|
||||||
diceRolledValue = rolledVal;
|
diceRolledValue = rolledVal;
|
||||||
diceText.text = $"{diceRolledValue}";
|
diceText.text = $"{diceRolledValue}";
|
||||||
|
availPlayers = new List<PlayerPawn>();
|
||||||
|
|
||||||
if (!CanRollDiceAgain)
|
if (!CanRollDiceAgain)
|
||||||
{
|
{
|
||||||
SetDisplayCountForAllAvailPlayers(true);
|
UpdateActivePlayersAndSetDisplay(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InitActivePlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rolledVal == Ludo_3D_Constants.Max_Dice_Rolls)
|
if (rolledVal == Ludo_3D_Constants.Max_Dice_Rolls)
|
||||||
@ -595,25 +596,6 @@ 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))
|
|
||||||
{
|
|
||||||
if (availPlayersToMove.Count < 1 || HasNoPlayersTravelling())
|
|
||||||
{
|
|
||||||
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
|
||||||
@ -632,73 +614,54 @@ 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
|
||||||
{
|
{
|
||||||
Debug.Log($"before CustomAvailablePlayers: {availPlayersToMove.Count}");
|
// for player's logic
|
||||||
|
|
||||||
|
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 < availPlayersToMove.Count; i++)
|
for (int i = 0; i < availPlayers.Count; i++)
|
||||||
{
|
{
|
||||||
Debug.Log($"## playerPawn.GetPlayerState(): {availPlayersToMove[i].GetPlayerState()}");
|
Debug.Log($"## playerPawn.GetPlayerState(): {availPlayers[i].GetPlayerState()}");
|
||||||
|
|
||||||
if (availPlayersToMove[i].GetPlayerState() == PlayerState.InFinishingPath)
|
if (availPlayers[i].GetPlayerState() == PlayerState.InFinishingPath)
|
||||||
{
|
{
|
||||||
Debug.Log($"diceRolledValue: {diceRolledValue}, FinishingDataLen: {TilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn)}, playerPawn.CurrentTileIndex: {availPlayersToMove[i].CurrentTileIndex}");
|
Debug.Log($"diceRolledValue: {diceRolledValue}, FinishingDataLen: {TilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn)}, playerPawn.CurrentTileIndex: {availPlayers[i].CurrentTileIndex}");
|
||||||
if (diceRolledValue <= TilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - (availPlayersToMove[i].CurrentTileIndex + 1))
|
if (diceRolledValue <= TilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - (availPlayers[i].CurrentTileIndex + 1))
|
||||||
{
|
{
|
||||||
availPlayersToMove[i].SetPlayerSelectionState(true);
|
availPlayers[i].SetPlayerSelectionState(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
indexesToRemove.Add(i);
|
indexesToRemove.Add(i);
|
||||||
availPlayersToMove[i].SetPlayerSelectionState(false);
|
availPlayers[i].SetPlayerSelectionState(false);
|
||||||
availPlayersToMove[i].ShowPlayerCountCanvas(false);
|
availPlayers[i].ShowPlayerCountCanvas(false);
|
||||||
|
customAvailPlayers--;
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
availPlayersToMove[i].SetPlayerSelectionState(true);
|
availPlayers[i].SetPlayerSelectionState(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int idx = indexesToRemove.Count - 1; idx >= 0; idx--)
|
for (int idx = indexesToRemove.Count - 1; idx >= 0; idx--)
|
||||||
availPlayersToMove.RemoveAt(idx);
|
availPlayers.RemoveAt(idx);
|
||||||
|
|
||||||
Debug.Log($"CustomAvailablePlayers: {availPlayersToMove.Count}");
|
// if (availPlayers.Count() < 1)
|
||||||
canSwitchPlayer = availPlayersToMove.Count < 1;
|
Debug.Log($"CustomAvailablePlayers: {customAvailPlayers}");
|
||||||
|
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();
|
||||||
@ -707,8 +670,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
|
|
||||||
private void InitActivePlayers()
|
private void InitActivePlayers()
|
||||||
{
|
{
|
||||||
availPlayersToMove = new List<PlayerPawn>();
|
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();
|
||||||
@ -746,48 +708,16 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
{
|
{
|
||||||
if (CanRollDiceAgain)
|
if (CanRollDiceAgain)
|
||||||
{
|
{
|
||||||
RollDiceForBot();
|
HandleDiceRoll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RollDiceForUser()
|
private void HandleDiceRoll()
|
||||||
{
|
|
||||||
InitActivePlayers();
|
|
||||||
bool canUsePawnsFromHome = CanUsePawnsFromHome();
|
|
||||||
diceRollHandler.HandleDiceViewForUser(
|
|
||||||
hasNoActionOnRoll: canUsePawnsFromHome,
|
|
||||||
playerBase: canUsePawnsFromHome ? PlayerBaseHandler.GetPlayerBase(currentPlayerTypeTurn) : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RollDiceForBot()
|
|
||||||
{
|
|
||||||
InitActivePlayers();
|
|
||||||
HandleDiceRollForBot();
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Summary:
|
|
||||||
* Scenario where the user/bot has no other move when some of the pawns/characters out of home
|
|
||||||
* are in finishing path and doesn't have a move from dice rolled value
|
|
||||||
*/
|
|
||||||
private bool CanUsePawnsFromHome()
|
|
||||||
{
|
|
||||||
return playerGameDatasDict[currentPlayerTypeTurn].totalPawnsInHome > 0 && HasNoPlayersTravelling();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void HandleDiceRollForBot()
|
|
||||||
{
|
{
|
||||||
if (isDebugAITest)
|
if (isDebugAITest)
|
||||||
diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal),
|
diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal), diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue);
|
||||||
diceValue == 0 ? UnityEngine.Random.Range(1, Ludo_3D_Constants.Max_Dice_Rolls + 1) : diceValue);
|
|
||||||
else
|
else
|
||||||
{
|
diceRollHandler.HandleDiceViewForBot((rollVal) => RollDiceForBot(rollVal));
|
||||||
bool canUsePawnsFromHome = CanUsePawnsFromHome();
|
|
||||||
diceRollHandler.HandleDiceViewForBot(
|
|
||||||
(rollVal) => RollDiceForBot(rollVal),
|
|
||||||
hasNoActionOnRoll: canUsePawnsFromHome,
|
|
||||||
playerBase: canUsePawnsFromHome ? PlayerBaseHandler.GetPlayerBase(currentPlayerTypeTurn) : null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPawnSelected(PlayerPawn selectedPawn)
|
public void OnPawnSelected(PlayerPawn selectedPawn)
|
||||||
@ -840,7 +770,6 @@ 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)
|
||||||
@ -914,10 +843,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: {availPlayersToMove.Count}, playerPawn: {playerPawn}");
|
Debug.Log($"before SwitchPlayer availPlayers: {availPlayers.Count}, playerPawn: {playerPawn}");
|
||||||
|
|
||||||
UpdateActivePlayersAndSetDisplay(false);
|
UpdateActivePlayersAndSetDisplay(false);
|
||||||
Debug.Log($"after SwitchPlayer availPlayers: {availPlayersToMove.Count}, playerPawn: {playerPawn}");
|
Debug.Log($"after SwitchPlayer availPlayers: {availPlayers.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)
|
||||||
@ -977,11 +906,11 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
{
|
{
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
availPlayersToMove.ForEach(pawn => ShowUpdatedPlayerCountOnTile(pawn));
|
availPlayers.ForEach(pawn => ShowUpdatedPlayerCountOnTile(pawn));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
availPlayersToMove.ForEach(pawn => pawn.ShowPlayerCountCanvas(false));
|
availPlayers.ForEach(pawn => pawn.ShowPlayerCountCanvas(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1019,9 +948,6 @@ 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)
|
||||||
@ -1139,9 +1065,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
// ShowUpdatedPlayerCountOnTile(playerPawn);
|
// ShowUpdatedPlayerCountOnTile(playerPawn);
|
||||||
|
|
||||||
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}");
|
||||||
@ -1261,7 +1185,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader
|
|||||||
|
|
||||||
playerGameDatasDict = null;
|
playerGameDatasDict = null;
|
||||||
playerDatas = null;
|
playerDatas = null;
|
||||||
availPlayersToMove = null;
|
availPlayers = null;
|
||||||
|
|
||||||
botTypesInGame = null;
|
botTypesInGame = null;
|
||||||
botRuntimeMovementData = null;
|
botRuntimeMovementData = null;
|
||||||
|
|||||||
@ -7,18 +7,13 @@ public class BasePlacementData
|
|||||||
public Transform placementTransform;
|
public Transform placementTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayerBase : MonoBehaviour, IRollBase
|
public class PlayerBase : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private PlayerType playerType;
|
[SerializeField] private PlayerType playerType;
|
||||||
[SerializeField] private BasePlacementData[] basePlacementDatas;
|
[SerializeField] private BasePlacementData[] basePlacementDatas;
|
||||||
[SerializeField] private PlayerPawn[] playerPawns;
|
[SerializeField] private PlayerPawn[] playerPawns;
|
||||||
[SerializeField] private GameObject playerBaseEffect;
|
[SerializeField] private GameObject playerBaseEffect;
|
||||||
|
|
||||||
private int sixRollCount, maxRollCount;
|
|
||||||
|
|
||||||
public int SixRollCount => sixRollCount;
|
|
||||||
public int MaxRollCount => maxRollCount;
|
|
||||||
|
|
||||||
public bool IsBotBase
|
public bool IsBotBase
|
||||||
{
|
{
|
||||||
get; private set;
|
get; private set;
|
||||||
@ -26,22 +21,6 @@ public class PlayerBase : MonoBehaviour, IRollBase
|
|||||||
|
|
||||||
public PlayerType GetPlayerType() => playerType;
|
public PlayerType GetPlayerType() => playerType;
|
||||||
|
|
||||||
public void UpdateSixRollCount()
|
|
||||||
{
|
|
||||||
sixRollCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResetRollData()
|
|
||||||
{
|
|
||||||
sixRollCount = 0;
|
|
||||||
maxRollCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateMaxRollCount(int val)
|
|
||||||
{
|
|
||||||
maxRollCount = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InitPlayerData()
|
public void InitPlayerData()
|
||||||
{
|
{
|
||||||
for (int idx = 0; idx < basePlacementDatas.Length; idx++)
|
for (int idx = 0; idx < basePlacementDatas.Length; idx++)
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using UnityEngine;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class PlayerBaseData
|
public class PlayerBaseData
|
||||||
|
|||||||
@ -27,7 +27,6 @@ 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]
|
||||||
|
|||||||
@ -29,7 +29,7 @@ public class DiceRollHandler : MonoBehaviour
|
|||||||
inputManager.SetDiceRollValue(rolledVal);
|
inputManager.SetDiceRollValue(rolledVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleDiceViewForUser(bool hasNoActionOnRoll = false, PlayerBase playerBase = null)
|
public void HandleDiceViewForUser()
|
||||||
{
|
{
|
||||||
if (!inputManager.GameplayManager.CanRollDiceForUser) return;
|
if (!inputManager.GameplayManager.CanRollDiceForUser) return;
|
||||||
|
|
||||||
@ -39,17 +39,11 @@ public class DiceRollHandler : MonoBehaviour
|
|||||||
if (inputManager.GameplayManager.IsDebugPlayerTest)
|
if (inputManager.GameplayManager.IsDebugPlayerTest)
|
||||||
OnUserDiceRollComplete(GetDiceTestVal());
|
OnUserDiceRollComplete(GetDiceTestVal());
|
||||||
else
|
else
|
||||||
{
|
diceView.Roll(onComplete: (rolledVal) => OnUserDiceRollComplete(rolledVal), false);
|
||||||
diceView.InitOnNoActionsAfterRoll(playerBase, hasNoActionOnRoll);
|
|
||||||
diceView.Roll(
|
|
||||||
(rolledVal) => OnUserDiceRollComplete(rolledVal),
|
|
||||||
false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleDiceViewForBot(Action<int> onComplete, bool hasNoActionOnRoll = false, PlayerBase playerBase = null)
|
public void HandleDiceViewForBot(Action<int> onComplete)
|
||||||
{
|
{
|
||||||
diceView.InitOnNoActionsAfterRoll(playerBase, hasNoActionOnRoll);
|
|
||||||
diceView.Roll(onComplete: onComplete, true);
|
diceView.Roll(onComplete: onComplete, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user