Remove event deallocation function call in DiceView due to flow breakage because of timer in delay. Added a debug test bool inside GameplayManager for testing dice logic without dice animation. Fixed issue with additional steps being kept track for player (PlayerPawn.cs) Bound restart logic for the Game over popup alone. Added a maxDiceSixRollCounter for keeping track of how many times 6 can be rolled. Fixed issue with wrong player being selected while restart is clicked. Fixed indexing logical errors while finding possible tile data. Fixed issue with player attacking another player and moving constantly. Fixed issue with player not switching when there is no option for dice roll. Handled dice roll logic when pawns are in finishing path. Fixed indexing issue with availPlayers collection where wrong indexes were being selected for removing from the collection. Fixed issue with tile data not resetting on restart. Restructured logic for showing winners inside Game Over popup. Restructured GameOverPopup and GameOverScreen with respect to showing/hiding screens/popups.
152 lines
3.7 KiB
C#
152 lines
3.7 KiB
C#
using System;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
public enum PlayerState
|
|
{
|
|
InHome,
|
|
InSafeZone,
|
|
Moving,
|
|
InFinishingPath,
|
|
HasFinished
|
|
}
|
|
|
|
public enum PawnType
|
|
{
|
|
User,
|
|
Bot
|
|
}
|
|
|
|
public class PlayerPawn : MonoBehaviour
|
|
{
|
|
[SerializeField] private PlayerState playerState;
|
|
[SerializeField] private Animator animator;
|
|
[SerializeField] private GameObject playerCountCanvasPrefab;
|
|
[SerializeField] private PlayerCountCanvas playerCountCanvas;
|
|
|
|
public PlayerCountCanvas PlayerCountCanvas => playerCountCanvas;
|
|
|
|
public bool CanSelectPlayer
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
private GameplayManager gameplayManager;
|
|
|
|
public int CurrentTileIndex
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
public int PlayerId
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
public PlayerType PlayerType
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
public bool IsBotPlayer
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
public int StepsTaken
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
public void AssignBotPlayerState(bool state)
|
|
{
|
|
IsBotPlayer = state;
|
|
}
|
|
|
|
public void SetPlayerSelectionState(bool state)
|
|
{
|
|
CanSelectPlayer = state;
|
|
if (CanSelectPlayer)
|
|
{
|
|
// TODO :: Play animation for selecting any of the players
|
|
}
|
|
}
|
|
|
|
public void MoveToTile(Vector3 startingPoint, Action onComplete, int tileIndex)
|
|
{
|
|
StepsTaken++;
|
|
CurrentTileIndex = tileIndex;
|
|
animator?.SetTrigger("Jump");
|
|
|
|
// SFX
|
|
SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>();
|
|
soundManager?.PlayGameSoundClip(SoundType.Jump);
|
|
|
|
transform.DOMove(startingPoint, 0.6f).onComplete = () =>
|
|
{
|
|
animator?.ResetTrigger("Jump");
|
|
|
|
// Rotate Player
|
|
TilesManager tilesManager = InterfaceManager.Instance.GetInterfaceInstance<TilesManager>();
|
|
gameplayManager = gameplayManager ?? InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
|
|
|
|
int nextTileIndex = gameplayManager.GetNextGeneralTileIndex(this);
|
|
Vector3 lookDirection = tilesManager.RetrieveTileBasedOnIndex(nextTileIndex).transform.position - transform.position;
|
|
lookDirection.y = 0;
|
|
transform.DOLookAt(transform.position + lookDirection, 0.2f);
|
|
|
|
onComplete?.Invoke();
|
|
};
|
|
}
|
|
|
|
public void MoveToCustomTilePosition(Vector3 targetPoint)
|
|
{
|
|
transform.DOMove(targetPoint, 1f);
|
|
}
|
|
|
|
// when he is defeated
|
|
public void MoveBackToHome(Transform transformData)
|
|
{
|
|
Debug.Log($"MoveBackToHome");
|
|
transform.position = transformData.position;
|
|
transform.rotation = transformData.rotation;
|
|
SetPlayerState(PlayerState.InHome);
|
|
StepsTaken = 0;
|
|
}
|
|
|
|
public PlayerState GetPlayerState() => playerState;
|
|
|
|
public void SetPlayerState(PlayerState state)
|
|
{
|
|
playerState = state;
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
if (IsBotPlayer || !CanSelectPlayer) return;
|
|
|
|
SetGameplayManager();
|
|
gameplayManager.OnPawnSelected(this);
|
|
}
|
|
|
|
private void SetGameplayManager()
|
|
{
|
|
gameplayManager = gameplayManager ?? InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
|
|
}
|
|
|
|
public void Init(BasePlacementData basePlacementData, PlayerType playerType)
|
|
{
|
|
PlayerId = basePlacementData.playerBaseId;
|
|
PlayerType = playerType;
|
|
|
|
MoveBackToHome(basePlacementData.placementTransform);
|
|
}
|
|
|
|
public void ShowPlayerCountCanvas(bool show)
|
|
{
|
|
if (playerCountCanvasPrefab == null) return;
|
|
|
|
playerCountCanvasPrefab.SetActive(show);
|
|
}
|
|
}
|