108 lines
3.2 KiB
C#
108 lines
3.2 KiB
C#
using System;
|
|
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
|
|
private SpriteRenderer _spriteRenderer;
|
|
|
|
// Stun
|
|
[Title("기절 효과")]
|
|
[SerializeField]
|
|
private ParticleSystem _stunParticle;
|
|
|
|
public bool IsStunned { get; private set; }
|
|
|
|
private Coroutine _stunCoolDownCoroutine;
|
|
|
|
// Slow
|
|
[Title("슬로우 효과")]
|
|
|
|
[SerializeField]
|
|
private Color _slowEffectColor;
|
|
|
|
public bool IsSlowedMoveSpeed { get; private set; }
|
|
private Coroutine _slowMoveSpeedCoolDownCoroutine;
|
|
|
|
// Variables
|
|
private bool _canApplyStatusEffect = true;
|
|
|
|
// Events
|
|
public event Action OnStartStun;
|
|
public event Action OnEndStun;
|
|
public event Action<float> OnStartSlowMoveSpeed;
|
|
public event Action OnEndSlowMoveSpeed;
|
|
|
|
// Hashes
|
|
private static readonly int _colorHash = Shader.PropertyToID("_Color");
|
|
|
|
#endregion
|
|
|
|
// Initialize methods
|
|
#region Initialize methods
|
|
|
|
public void InitializeComponents(SpriteRenderer spriteRenderer)
|
|
{
|
|
_spriteRenderer = spriteRenderer;
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Methods
|
|
#region Methods
|
|
|
|
// Event methods
|
|
public void HandleCanApplyStatusEffect() => _canApplyStatusEffect = true;
|
|
public void HandleCanNotApplyStatusEffect() => _canApplyStatusEffect = false;
|
|
|
|
// Stun
|
|
public void Stun(float duration)
|
|
{
|
|
if (!_canApplyStatusEffect) return;
|
|
|
|
IsStunned = true;
|
|
_stunParticle.Play();
|
|
OnStartStun?.Invoke();
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _stunCoolDownCoroutine, Utils.CoolDownCoroutine(duration, EndStun));
|
|
}
|
|
|
|
public void EndStun()
|
|
{
|
|
Utils.EndUniqueCoroutine(this, ref _stunCoolDownCoroutine);
|
|
_stunParticle.Stop();
|
|
OnEndStun?.Invoke();
|
|
IsStunned = false;
|
|
}
|
|
|
|
// Slow
|
|
public void SlowMoveSpeed(float duration, float moveSpeedCoefficient)
|
|
{
|
|
if (!_canApplyStatusEffect) return;
|
|
|
|
IsSlowedMoveSpeed = true;
|
|
_spriteRenderer.material.SetColor(_colorHash, _slowEffectColor);
|
|
OnStartSlowMoveSpeed?.Invoke(moveSpeedCoefficient);
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _slowMoveSpeedCoolDownCoroutine, Utils.CoolDownCoroutine(duration, EndSlowMoveSpeed));
|
|
}
|
|
|
|
public void EndSlowMoveSpeed()
|
|
{
|
|
Utils.EndUniqueCoroutine(this, ref _slowMoveSpeedCoolDownCoroutine);
|
|
_spriteRenderer.material.SetColor(_colorHash, Color.white);
|
|
OnEndSlowMoveSpeed?.Invoke();
|
|
IsSlowedMoveSpeed = false;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |