104 lines
2.0 KiB
C#
104 lines
2.0 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;
|
|
|
|
private bool canSelectPlayerFromHome;
|
|
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 void AssignBotPlayerState(bool state)
|
|
{
|
|
IsBotPlayer = state;
|
|
}
|
|
|
|
public void SetPlayerSelectionState(bool state)
|
|
{
|
|
canSelectPlayerFromHome = state;
|
|
if (canSelectPlayerFromHome)
|
|
{
|
|
// TODO :: Play animation for selecting any of the players
|
|
}
|
|
}
|
|
|
|
public void MoveToTile(Vector3 startingPoint, Action onComplete, int tileIndex)
|
|
{
|
|
CurrentTileIndex = tileIndex;
|
|
transform.DOMove(startingPoint, 0.1f).onComplete = () => onComplete?.Invoke();
|
|
}
|
|
|
|
public void MoveToCustomTilePosition(Vector3 targetPoint)
|
|
{
|
|
transform.DOMove(targetPoint, 0.1f);
|
|
}
|
|
|
|
// when he is defeated
|
|
public void MoveBackToHome()
|
|
{
|
|
|
|
}
|
|
|
|
public PlayerState GetPlayerState() => playerState;
|
|
|
|
public void SetPlayerState(PlayerState state)
|
|
{
|
|
playerState = state;
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
if (IsBotPlayer || !canSelectPlayerFromHome) return;
|
|
|
|
SetGameplayManager();
|
|
gameplayManager.OnPawnSelected(this);
|
|
}
|
|
|
|
private void SetGameplayManager()
|
|
{
|
|
gameplayManager = gameplayManager ?? InterfaceManager.Instance.GetInterfaceInstance<GameplayManager>();
|
|
}
|
|
|
|
public void Init(int id, PlayerType playerType)
|
|
{
|
|
PlayerId = id;
|
|
PlayerType = playerType;
|
|
}
|
|
}
|