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
|
2024-06-16 21:29:06 +00:00
|
|
|
[SerializeField]
|
2024-06-03 18:26:03 +00:00
|
|
|
private SpriteRenderer _spriteRenderer;
|
|
|
|
|
2024-06-16 21:29:06 +00:00
|
|
|
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;
|
2024-06-16 21:29:06 +00:00
|
|
|
|
|
|
|
public bool IsStunEnabled { get; private set; } = true;
|
2024-06-03 18:26:03 +00:00
|
|
|
public bool IsStunned { get; private set; }
|
2024-06-16 21:29:06 +00:00
|
|
|
|
2024-06-03 18:26:03 +00:00
|
|
|
private Coroutine _stunCoolDownCoroutine;
|
|
|
|
|
|
|
|
// Slow
|
|
|
|
[Title("슬로우 효과")]
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Color _slowEffectColor;
|
|
|
|
|
2024-06-16 21:29:06 +00:00
|
|
|
public bool IsSlowMoveEnabled { get; private set; } = true;
|
2024-06-03 18:26:03 +00:00
|
|
|
public bool IsSlowedMoveSpeed { get; private set; }
|
2024-06-16 21:29:06 +00:00
|
|
|
|
2024-06-03 18:26:03 +00:00
|
|
|
private Coroutine _slowMoveSpeedCoolDownCoroutine;
|
|
|
|
|
|
|
|
// Hashes
|
|
|
|
private static readonly int _colorHash = Shader.PropertyToID("_Color");
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2024-06-16 21:29:06 +00:00
|
|
|
// Unity events
|
|
|
|
#region Unity events
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
InitializeComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2024-06-03 18:26:03 +00:00
|
|
|
// Initialize methods
|
|
|
|
#region Initialize methods
|
|
|
|
|
2024-06-16 21:29:06 +00:00
|
|
|
[Button("컴포넌트 초기화")]
|
|
|
|
private void InitializeComponents()
|
2024-06-03 18:26:03 +00:00
|
|
|
{
|
2024-06-16 21:29:06 +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
|
2024-06-16 21:29:06 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
_stunParticle.Play();
|
|
|
|
|
2024-06-16 21:29:06 +00:00
|
|
|
IsStunned = true;
|
2024-06-03 18:26:03 +00:00
|
|
|
Utils.StartUniqueCoroutine(this, ref _stunCoolDownCoroutine, Utils.CoolDownCoroutine(duration, EndStun));
|
|
|
|
}
|
2024-06-24 13:14:14 +00:00
|
|
|
|
|
|
|
public void TryStun(float duration)
|
|
|
|
{
|
|
|
|
if (!CanStun()) return;
|
|
|
|
|
|
|
|
Stun(duration);
|
|
|
|
}
|
2024-06-03 18:26:03 +00:00
|
|
|
|
|
|
|
public void EndStun()
|
|
|
|
{
|
2024-06-16 21:29:06 +00:00
|
|
|
IsStunned = false;
|
|
|
|
|
2024-06-03 18:26:03 +00:00
|
|
|
_stunParticle.Stop();
|
2024-06-15 01:20:43 +00:00
|
|
|
_stunParticle.Clear();
|
2024-06-16 21:29:06 +00:00
|
|
|
Utils.EndUniqueCoroutine(this, ref _stunCoolDownCoroutine);
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Slow
|
2024-06-16 21:29:06 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
_spriteRenderer.material.SetColor(_colorHash, _slowEffectColor);
|
2024-06-16 21:29:06 +00:00
|
|
|
_physicMovable?.SetMoveSpeedCoefficient(moveSpeedCoefficient);
|
2024-06-03 18:26:03 +00:00
|
|
|
|
2024-06-16 21:29:06 +00:00
|
|
|
IsSlowedMoveSpeed = true;
|
2024-06-03 18:26:03 +00:00
|
|
|
Utils.StartUniqueCoroutine(this, ref _slowMoveSpeedCoolDownCoroutine, Utils.CoolDownCoroutine(duration, EndSlowMoveSpeed));
|
|
|
|
}
|
|
|
|
|
2024-06-24 13:14:14 +00:00
|
|
|
public void TrySlowMoveSpeed(float duration, float moveSpeedCoefficient)
|
|
|
|
{
|
|
|
|
if (!CanSlowMove()) return;
|
|
|
|
|
|
|
|
SlowMoveSpeed(duration, moveSpeedCoefficient);
|
|
|
|
}
|
|
|
|
|
2024-06-03 18:26:03 +00:00
|
|
|
public void EndSlowMoveSpeed()
|
|
|
|
{
|
|
|
|
IsSlowedMoveSpeed = false;
|
2024-06-16 21:29:06 +00:00
|
|
|
|
|
|
|
_spriteRenderer.material.SetColor(_colorHash, Color.white);
|
|
|
|
_physicMovable?.ResetMoveSpeedCoefficient();
|
|
|
|
Utils.EndUniqueCoroutine(this, ref _slowMoveSpeedCoolDownCoroutine);
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|