2026-01-21 20:27:45 +05:30
|
|
|
using System;
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
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-01-30 19:04:14 +05:30
|
|
|
[SerializeField] private GameObject playerCountCanvasPrefab;
|
|
|
|
|
[SerializeField] private PlayerCountCanvas playerCountCanvas;
|
|
|
|
|
|
|
|
|
|
public PlayerCountCanvas PlayerCountCanvas => playerCountCanvas;
|
2026-01-21 20:27:45 +05:30
|
|
|
|
2026-01-29 15:45:49 +05:30
|
|
|
public bool CanSelectPlayer
|
2026-01-28 20:57:35 +05:30
|
|
|
{
|
|
|
|
|
get; private set;
|
|
|
|
|
}
|
2026-01-29 15:45:49 +05:30
|
|
|
|
2026-01-26 19:48:55 +05:30
|
|
|
private GameplayManager gameplayManager;
|
|
|
|
|
|
2026-01-21 20:27:45 +05:30
|
|
|
public int CurrentTileIndex
|
|
|
|
|
{
|
|
|
|
|
get; private set;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-23 12:46:59 +05:30
|
|
|
public int PlayerId
|
|
|
|
|
{
|
|
|
|
|
get; private set;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-26 19:48:55 +05:30
|
|
|
public PlayerType PlayerType
|
2026-01-26 13:03:50 +05:30
|
|
|
{
|
|
|
|
|
get; private set;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 20:55:55 +05:30
|
|
|
public bool IsBotPlayer
|
|
|
|
|
{
|
|
|
|
|
get; private set;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 16:57:27 +05:30
|
|
|
public int StepsTaken
|
|
|
|
|
{
|
|
|
|
|
get; private set;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
if (CanSelectPlayer)
|
2026-01-21 20:27:45 +05:30
|
|
|
{
|
2026-01-26 19:48:55 +05:30
|
|
|
// TODO :: Play animation for selecting any of the players
|
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>();
|
|
|
|
|
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();
|
|
|
|
|
};
|
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-28 16:57:27 +05:30
|
|
|
StepsTaken++;
|
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);
|
|
|
|
|
StepsTaken = 0;
|
2026-01-21 20:27:45 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PlayerState GetPlayerState() => playerState;
|
|
|
|
|
|
|
|
|
|
public void SetPlayerState(PlayerState state)
|
|
|
|
|
{
|
|
|
|
|
playerState = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMouseDown()
|
|
|
|
|
{
|
2026-01-29 15:45:49 +05:30
|
|
|
if (IsBotPlayer || !CanSelectPlayer) return;
|
2026-01-21 20:27:45 +05:30
|
|
|
|
|
|
|
|
SetGameplayManager();
|
|
|
|
|
gameplayManager.OnPawnSelected(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetGameplayManager()
|
|
|
|
|
{
|
|
|
|
|
gameplayManager = gameplayManager ?? InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
|
|
|
|
|
}
|
2026-01-23 12:46:59 +05:30
|
|
|
|
2026-01-30 21:51:33 +05:30
|
|
|
public void Init(BasePlacementData basePlacementData, PlayerType playerType)
|
2026-01-23 12:46:59 +05:30
|
|
|
{
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (playerCountCanvasPrefab == null) return;
|
|
|
|
|
|
|
|
|
|
playerCountCanvasPrefab.SetActive(show);
|
|
|
|
|
}
|
2026-01-21 20:27:45 +05:30
|
|
|
}
|