161 lines
5.4 KiB
C#
161 lines
5.4 KiB
C#
using UnityEngine;
|
|
|
|
using Colosseum.Abnormalities;
|
|
using Colosseum.Skills;
|
|
|
|
namespace Colosseum.Player
|
|
{
|
|
/// <summary>
|
|
/// 플레이어의 전투 행동 가능 여부를 한 곳에서 판정하는 상태 관리자.
|
|
/// 이동, 점프, 스킬 사용 가능 여부를 사망/이상 상태/관전/시전 상태와 연동합니다.
|
|
/// </summary>
|
|
[DisallowMultipleComponent]
|
|
public class PlayerActionState : MonoBehaviour
|
|
{
|
|
[Header("References")]
|
|
[Tooltip("플레이어 네트워크 상태")]
|
|
[SerializeField] private PlayerNetworkController networkController;
|
|
|
|
[Tooltip("이상 상태 관리자")]
|
|
[SerializeField] private AbnormalityManager abnormalityManager;
|
|
|
|
[Tooltip("스킬 실행 관리자")]
|
|
[SerializeField] private SkillController skillController;
|
|
|
|
[Tooltip("관전 관리자")]
|
|
[SerializeField] private PlayerSpectator spectator;
|
|
|
|
/// <summary>
|
|
/// 사망 상태 여부
|
|
/// </summary>
|
|
public bool IsDead => networkController != null && networkController.IsDead;
|
|
|
|
/// <summary>
|
|
/// 기절 상태 여부
|
|
/// </summary>
|
|
public bool IsStunned => abnormalityManager != null && abnormalityManager.IsStunned;
|
|
|
|
/// <summary>
|
|
/// 침묵 상태 여부
|
|
/// </summary>
|
|
public bool IsSilenced => abnormalityManager != null && abnormalityManager.IsSilenced;
|
|
|
|
/// <summary>
|
|
/// 관전 상태 여부
|
|
/// </summary>
|
|
public bool IsSpectating => spectator != null && spectator.IsSpectating;
|
|
|
|
/// <summary>
|
|
/// 스킬 애니메이션 재생 중 여부
|
|
/// </summary>
|
|
public bool IsCastingSkill => skillController != null && skillController.IsPlayingAnimation;
|
|
|
|
/// <summary>
|
|
/// 현재 시전 중인 스킬
|
|
/// </summary>
|
|
public SkillData CurrentSkill => skillController != null ? skillController.CurrentSkill : null;
|
|
|
|
/// <summary>
|
|
/// 현재 시전 중인 스킬이 회피 스킬일 때의 회피 상태 여부.
|
|
/// 침묵은 회피 상태 자체를 끊지 않으며, 회피 스킬의 신규 사용만 막습니다.
|
|
/// </summary>
|
|
public bool IsEvading => IsCastingSkill && CurrentSkill != null && CurrentSkill.IsEvadeSkill;
|
|
|
|
/// <summary>
|
|
/// 입력을 받아도 되는지 여부
|
|
/// </summary>
|
|
public bool CanReceiveInput => !IsDead && !IsSpectating;
|
|
|
|
/// <summary>
|
|
/// 플레이어가 직접 이동 입력을 사용할 수 있는지 여부
|
|
/// </summary>
|
|
public bool CanMove => CanReceiveInput && !IsStunned && !BlocksMovementForCurrentSkill();
|
|
|
|
/// <summary>
|
|
/// 점프 가능 여부
|
|
/// </summary>
|
|
public bool CanJump => CanReceiveInput && !IsStunned && !BlocksJumpForCurrentSkill();
|
|
|
|
/// <summary>
|
|
/// 일반 스킬 시작 가능 여부
|
|
/// </summary>
|
|
public bool CanUseSkills => CanReceiveInput && !IsStunned && !IsSilenced && !IsEvading && !BlocksSkillUseForCurrentSkill();
|
|
|
|
/// <summary>
|
|
/// 특정 스킬의 시작 가능 여부.
|
|
/// 회피 스킬도 일반 스킬과 같은 시작 판정을 사용하되, 현재 시전 중인 스킬의 회피 차단 정책을 따릅니다.
|
|
/// </summary>
|
|
public bool CanStartSkill(SkillData skill)
|
|
{
|
|
if (skill == null)
|
|
return false;
|
|
|
|
if (!CanReceiveInput || IsStunned || IsSilenced || IsEvading)
|
|
return false;
|
|
|
|
if (skill.IsEvadeSkill)
|
|
return !BlocksEvadeForCurrentSkill();
|
|
|
|
return !BlocksSkillUseForCurrentSkill();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 현재 이동 속도 배율
|
|
/// </summary>
|
|
public float MoveSpeedMultiplier
|
|
{
|
|
get
|
|
{
|
|
if (!CanReceiveInput || IsStunned)
|
|
return 0f;
|
|
|
|
return abnormalityManager != null ? abnormalityManager.MoveSpeedMultiplier : 1f;
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (networkController == null)
|
|
networkController = GetComponent<PlayerNetworkController>();
|
|
if (abnormalityManager == null)
|
|
abnormalityManager = GetComponent<AbnormalityManager>();
|
|
if (skillController == null)
|
|
skillController = GetComponent<SkillController>();
|
|
if (spectator == null)
|
|
spectator = GetComponentInChildren<PlayerSpectator>();
|
|
}
|
|
|
|
private bool BlocksMovementForCurrentSkill()
|
|
{
|
|
if (!IsCastingSkill)
|
|
return false;
|
|
|
|
return CurrentSkill == null || CurrentSkill.BlockMovementWhileCasting;
|
|
}
|
|
|
|
private bool BlocksJumpForCurrentSkill()
|
|
{
|
|
if (!IsCastingSkill)
|
|
return false;
|
|
|
|
return CurrentSkill == null || CurrentSkill.BlockJumpWhileCasting;
|
|
}
|
|
|
|
private bool BlocksSkillUseForCurrentSkill()
|
|
{
|
|
if (!IsCastingSkill)
|
|
return false;
|
|
|
|
return CurrentSkill == null || CurrentSkill.BlockOtherSkillsWhileCasting;
|
|
}
|
|
|
|
private bool BlocksEvadeForCurrentSkill()
|
|
{
|
|
if (!IsCastingSkill)
|
|
return false;
|
|
|
|
return CurrentSkill == null || CurrentSkill.BlockEvadeWhileCasting;
|
|
}
|
|
}
|
|
}
|