2026-01-21 20:27:45 +05:30
|
|
|
using System;
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
using UnityEngine;
|
2026-02-12 21:34:08 +05:30
|
|
|
using UnityEngine.Serialization;
|
2026-01-21 20:27:45 +05:30
|
|
|
|
|
|
|
|
public enum PlayerState
|
|
|
|
|
{
|
|
|
|
|
InHome,
|
|
|
|
|
InSafeZone,
|
|
|
|
|
Moving,
|
|
|
|
|
InFinishingPath,
|
|
|
|
|
HasFinished
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 20:55:55 +05:30
|
|
|
public enum PawnType
|
|
|
|
|
{
|
|
|
|
|
User,
|
|
|
|
|
Bot
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 20:27:45 +05:30
|
|
|
public class PlayerPawn : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] private PlayerState playerState;
|
2026-01-29 15:54:13 +05:30
|
|
|
[SerializeField] private Animator animator;
|
2026-02-12 21:34:08 +05:30
|
|
|
[SerializeField] private PlayerIndicatorCanvas playerIndicatorCanvas;
|
2026-01-30 19:04:14 +05:30
|
|
|
|
2026-02-06 14:06:52 +05:30
|
|
|
private PlayerBase playerBase;
|
2026-01-26 19:48:55 +05:30
|
|
|
private GameplayManager gameplayManager;
|
2026-02-06 14:06:52 +05:30
|
|
|
|
2026-02-12 21:34:08 +05:30
|
|
|
public PlayerIndicatorCanvas PlayerIndicatorCanvas => playerIndicatorCanvas;
|
2026-02-06 14:06:52 +05:30
|
|
|
|
|
|
|
|
public int PlayerId { get; private set; }
|
|
|
|
|
public int StepsTaken { get; private set; }
|
|
|
|
|
public int CurrentTileIndex { get; private set; }
|
|
|
|
|
public bool IsBotPlayer { get; private set; }
|
|
|
|
|
public bool CanSelectPlayer { get; private set; }
|
|
|
|
|
public PlayerType PlayerType { get; private set; }
|
2026-01-28 16:57:27 +05:30
|
|
|
|
2026-01-27 20:55:55 +05:30
|
|
|
public void AssignBotPlayerState(bool state)
|
|
|
|
|
{
|
|
|
|
|
IsBotPlayer = state;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-21 20:27:45 +05:30
|
|
|
public void SetPlayerSelectionState(bool state)
|
|
|
|
|
{
|
2026-01-29 15:45:49 +05:30
|
|
|
CanSelectPlayer = state;
|
2026-02-12 21:34:08 +05:30
|
|
|
Debug.Log($"### SetPlayerSelectionState: {name} :: {state}, ");
|
|
|
|
|
ShowPlayerSelCanvas(state);
|
2026-01-21 20:27:45 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveToTile(Vector3 startingPoint, Action onComplete, int tileIndex)
|
|
|
|
|
{
|
2026-01-28 16:57:27 +05:30
|
|
|
StepsTaken++;
|
2026-01-21 20:27:45 +05:30
|
|
|
CurrentTileIndex = tileIndex;
|
2026-01-29 15:54:13 +05:30
|
|
|
animator?.SetTrigger("Jump");
|
2026-01-29 18:34:30 +05:30
|
|
|
|
|
|
|
|
// SFX
|
|
|
|
|
SoundManager soundManager = InterfaceManager.Instance?.GetInterfaceInstance<SoundManager>();
|
|
|
|
|
soundManager?.PlayGameSoundClip(SoundType.Jump);
|
|
|
|
|
|
2026-01-29 15:54:13 +05:30
|
|
|
transform.DOMove(startingPoint, 0.6f).onComplete = () =>
|
|
|
|
|
{
|
|
|
|
|
animator?.ResetTrigger("Jump");
|
|
|
|
|
|
2026-01-29 18:34:30 +05:30
|
|
|
// Rotate Player
|
2026-01-29 15:54:13 +05:30
|
|
|
TilesManager tilesManager = InterfaceManager.Instance.GetInterfaceInstance<TilesManager>();
|
2026-02-12 21:34:08 +05:30
|
|
|
SetGameplayManager();
|
2026-01-29 15:54:13 +05:30
|
|
|
|
2026-02-02 16:37:43 +05:30
|
|
|
Vector3 lookDirection = Vector3.zero;
|
|
|
|
|
|
2026-02-02 19:27:17 +05:30
|
|
|
Debug.Log($"nextIndex :: playerState: {playerState}");
|
2026-02-02 16:37:43 +05:30
|
|
|
if (playerState == PlayerState.InFinishingPath)
|
|
|
|
|
{
|
|
|
|
|
int nextIndex = CurrentTileIndex + 1;
|
|
|
|
|
int maxIndex = tilesManager.GetFinishingTileDataLength(PlayerType) - 1;
|
|
|
|
|
|
|
|
|
|
if (nextIndex <= maxIndex)
|
|
|
|
|
{
|
|
|
|
|
lookDirection = tilesManager.RetrieveFinishingTileBasedOnIndex(PlayerType, nextIndex).transform.position - transform.position;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (gameplayManager.IsGoingInsideFinishingPath(this, out int possibleSteps))
|
|
|
|
|
{
|
2026-02-02 19:27:17 +05:30
|
|
|
lookDirection = tilesManager.RetrieveFinishingTileBasedOnIndex(PlayerType, 0).transform.position - transform.position;
|
2026-02-02 16:37:43 +05:30
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-02-02 20:12:00 +05:30
|
|
|
int nextIndex = gameplayManager.TilesManager.GetNextGeneralTileIndex(CurrentTileIndex);
|
2026-02-02 19:27:17 +05:30
|
|
|
Debug.Log($"nextIndex :: {nextIndex}, currentIndex: {CurrentTileIndex}");
|
2026-02-02 16:37:43 +05:30
|
|
|
lookDirection = tilesManager.RetrieveTileBasedOnIndex(nextIndex).transform.position - transform.position;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-02 19:27:17 +05:30
|
|
|
lookDirection = lookDirection.normalized;
|
2026-01-29 15:54:13 +05:30
|
|
|
lookDirection.y = 0;
|
2026-02-02 19:27:17 +05:30
|
|
|
|
2026-02-02 16:37:43 +05:30
|
|
|
if (lookDirection != Vector3.zero)
|
|
|
|
|
{
|
2026-02-02 19:27:17 +05:30
|
|
|
// transform.LookAt(transform.position + lookDirection);
|
2026-02-02 16:37:43 +05:30
|
|
|
transform.DOLookAt(transform.position + lookDirection, 0.2f);
|
|
|
|
|
}
|
2026-02-06 14:06:52 +05:30
|
|
|
|
|
|
|
|
Debug.Log($"Dotween:: MoveToTile.OnComplete {PlayerType}, {transform.position}: {StepsTaken != 0}");
|
|
|
|
|
if (StepsTaken != 0)
|
|
|
|
|
onComplete?.Invoke();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
transform.position = playerBase.GetBasePlacementDataPosition(PlayerId - 1).position;
|
|
|
|
|
}
|
2026-01-29 15:54:13 +05:30
|
|
|
};
|
2026-01-21 20:27:45 +05:30
|
|
|
}
|
|
|
|
|
|
2026-01-23 13:33:16 +05:30
|
|
|
public void MoveToCustomTilePosition(Vector3 targetPoint)
|
2026-01-22 20:50:41 +05:30
|
|
|
{
|
2026-01-29 15:54:13 +05:30
|
|
|
transform.DOMove(targetPoint, 1f);
|
2026-01-22 20:50:41 +05:30
|
|
|
}
|
|
|
|
|
|
2026-01-21 20:27:45 +05:30
|
|
|
// when he is defeated
|
2026-01-29 15:54:13 +05:30
|
|
|
public void MoveBackToHome(Transform transformData)
|
2026-01-21 20:27:45 +05:30
|
|
|
{
|
2026-01-30 09:35:31 +05:30
|
|
|
Debug.Log($"MoveBackToHome");
|
2026-01-29 15:54:13 +05:30
|
|
|
transform.position = transformData.position;
|
|
|
|
|
transform.rotation = transformData.rotation;
|
2026-01-28 16:57:27 +05:30
|
|
|
SetPlayerState(PlayerState.InHome);
|
2026-02-12 21:34:08 +05:30
|
|
|
ShowPlayerSelCanvas(false);
|
2026-01-28 16:57:27 +05:30
|
|
|
StepsTaken = 0;
|
2026-01-21 20:27:45 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PlayerState GetPlayerState() => playerState;
|
|
|
|
|
|
|
|
|
|
public void SetPlayerState(PlayerState state)
|
|
|
|
|
{
|
|
|
|
|
playerState = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMouseDown()
|
|
|
|
|
{
|
|
|
|
|
SetGameplayManager();
|
2026-02-04 21:47:34 +05:30
|
|
|
if (gameplayManager.GameManager.CurrentGameState == GameState.IsPaused || IsBotPlayer || !CanSelectPlayer) return;
|
|
|
|
|
|
2026-01-21 20:27:45 +05:30
|
|
|
gameplayManager.OnPawnSelected(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetGameplayManager()
|
|
|
|
|
{
|
|
|
|
|
gameplayManager = gameplayManager ?? InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
|
|
|
|
|
}
|
2026-01-23 12:46:59 +05:30
|
|
|
|
2026-02-06 14:06:52 +05:30
|
|
|
public void Init(PlayerBase playerBase, BasePlacementData basePlacementData, PlayerType playerType)
|
2026-01-23 12:46:59 +05:30
|
|
|
{
|
2026-02-06 14:06:52 +05:30
|
|
|
this.playerBase = playerBase;
|
2026-01-30 21:51:33 +05:30
|
|
|
PlayerId = basePlacementData.playerBaseId;
|
2026-01-26 13:03:50 +05:30
|
|
|
PlayerType = playerType;
|
2026-01-30 21:51:33 +05:30
|
|
|
|
|
|
|
|
MoveBackToHome(basePlacementData.placementTransform);
|
2026-01-23 12:46:59 +05:30
|
|
|
}
|
2026-01-30 19:04:14 +05:30
|
|
|
|
|
|
|
|
public void ShowPlayerCountCanvas(bool show)
|
|
|
|
|
{
|
2026-02-12 21:34:08 +05:30
|
|
|
// add the player count canvas to the object and show from here.
|
|
|
|
|
// playerIndicatorCanvas.gameObject.SetActive(show);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowPlayerSelCanvas(bool show)
|
|
|
|
|
{
|
|
|
|
|
playerIndicatorCanvas.gameObject.SetActive(show);
|
2026-01-30 19:04:14 +05:30
|
|
|
}
|
2026-02-02 19:27:17 +05:30
|
|
|
|
|
|
|
|
public void ResetData()
|
|
|
|
|
{
|
|
|
|
|
SetPlayerState(PlayerState.InHome);
|
|
|
|
|
StepsTaken = 0;
|
|
|
|
|
PlayerId = 0;
|
2026-02-12 21:34:08 +05:30
|
|
|
if (playerIndicatorCanvas.gameObject.activeInHierarchy)
|
|
|
|
|
ShowPlayerSelCanvas(false);
|
2026-02-02 19:27:17 +05:30
|
|
|
}
|
2026-01-21 20:27:45 +05:30
|
|
|
}
|