CapersProject/Assets/02.Scripts/Character/Player/Combat/CombatStatus.cs

140 lines
4.0 KiB
C#
Raw Normal View History

2024-06-03 18:26:03 +00:00
using BlueWater.Interfaces;
using BlueWater.Utility;
using Sirenix.OdinInspector;
using UnityEngine;
namespace BlueWater.Players.Combat
{
public class CombatStatus : MonoBehaviour, IStunnable, ISlowable
{
// Variables
#region Variables
// Components
[SerializeField]
2024-06-03 18:26:03 +00:00
private SpriteRenderer _spriteRenderer;
private IPhysicMovable _physicMovable;
private IDashable _dashable;
private IComboAttackable _comboAttackable;
private ISkillHandler _skillHandler;
2024-06-03 18:26:03 +00:00
// Stun
[Title("기절 효과")]
[SerializeField]
private ParticleSystem _stunParticle;
public bool IsStunEnabled { get; private set; } = true;
2024-06-03 18:26:03 +00:00
public bool IsStunned { get; private set; }
2024-06-03 18:26:03 +00:00
private Coroutine _stunCoolDownCoroutine;
// Slow
[Title("슬로우 효과")]
[SerializeField]
private Color _slowEffectColor;
public bool IsSlowMoveEnabled { get; private set; } = true;
2024-06-03 18:26:03 +00:00
public bool IsSlowedMoveSpeed { get; private set; }
2024-06-03 18:26:03 +00:00
private Coroutine _slowMoveSpeedCoolDownCoroutine;
// Hashes
private static readonly int _colorHash = Shader.PropertyToID("_Color");
#endregion
// Unity events
#region Unity events
private void Awake()
{
InitializeComponents();
}
#endregion
2024-06-03 18:26:03 +00:00
// Initialize methods
#region Initialize methods
[Button("컴포넌트 초기화")]
private void InitializeComponents()
2024-06-03 18:26:03 +00:00
{
_spriteRenderer = GetComponentInChildren<SpriteRenderer>();
_physicMovable = GetComponent<IPhysicMovable>();
_dashable = GetComponent<IDashable>();
_comboAttackable = GetComponent<IComboAttackable>();
_skillHandler = GetComponent<ISkillHandler>();
2024-06-03 18:26:03 +00:00
}
#endregion
// Methods
#region Methods
// Stun
public bool CanStun()
{
if (!IsStunEnabled) return false;
var isDashing = _dashable?.IsDashing ?? false;
var isActivatingSkill = _skillHandler?.IsActivatingSkill ?? false;
return !isDashing && !isActivatingSkill;
}
2024-06-03 18:26:03 +00:00
public void Stun(float duration)
{
if (!IsStunEnabled) return;
2024-06-03 18:26:03 +00:00
_stunParticle.Play();
IsStunned = true;
2024-06-03 18:26:03 +00:00
Utils.StartUniqueCoroutine(this, ref _stunCoolDownCoroutine, Utils.CoolDownCoroutine(duration, EndStun));
}
public void EndStun()
{
IsStunned = false;
2024-06-03 18:26:03 +00:00
_stunParticle.Stop();
_stunParticle.Clear();
Utils.EndUniqueCoroutine(this, ref _stunCoolDownCoroutine);
2024-06-03 18:26:03 +00:00
}
// Slow
public bool CanSlowMove()
{
if (!IsSlowMoveEnabled) return false;
var isDashing = _dashable?.IsDashing ?? false;
var isActivatingSkill = _skillHandler?.IsActivatingSkill ?? false;
return !isDashing && !isActivatingSkill;
}
2024-06-03 18:26:03 +00:00
public void SlowMoveSpeed(float duration, float moveSpeedCoefficient)
{
if (!IsSlowMoveEnabled) return;
2024-06-03 18:26:03 +00:00
_spriteRenderer.material.SetColor(_colorHash, _slowEffectColor);
_physicMovable?.SetMoveSpeedCoefficient(moveSpeedCoefficient);
2024-06-03 18:26:03 +00:00
IsSlowedMoveSpeed = true;
2024-06-03 18:26:03 +00:00
Utils.StartUniqueCoroutine(this, ref _slowMoveSpeedCoolDownCoroutine, Utils.CoolDownCoroutine(duration, EndSlowMoveSpeed));
}
public void EndSlowMoveSpeed()
{
IsSlowedMoveSpeed = false;
_spriteRenderer.material.SetColor(_colorHash, Color.white);
_physicMovable?.ResetMoveSpeedCoefficient();
Utils.EndUniqueCoroutine(this, ref _slowMoveSpeedCoolDownCoroutine);
2024-06-03 18:26:03 +00:00
}
#endregion
}
}