2024-06-14 09:11:35 +00:00
|
|
|
using BlueWater.Audios;
|
|
|
|
using BlueWater.Interfaces;
|
2024-06-29 15:59:31 +00:00
|
|
|
using BlueWater.Items;
|
2024-06-14 09:11:35 +00:00
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BlueWater
|
|
|
|
{
|
|
|
|
public class DamageableProps : MonoBehaviour, IDamageable
|
|
|
|
{
|
2024-06-29 15:59:31 +00:00
|
|
|
[Title("드롭 아이템")]
|
|
|
|
[SerializeField]
|
|
|
|
protected int CharacterIdx;
|
|
|
|
|
2024-06-14 09:11:35 +00:00
|
|
|
[field: Title("체력")]
|
|
|
|
[field: SerializeField]
|
|
|
|
public int MaxHealthPoint { get; private set; } = 1;
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public int CurrentHealthPoint { get; private set; }
|
|
|
|
|
2024-06-16 21:29:06 +00:00
|
|
|
public bool IsInvincible { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public float InvincibilityDuration { get; private set; }
|
|
|
|
|
2024-06-14 09:11:35 +00:00
|
|
|
[Title("Die 설정")]
|
|
|
|
[SerializeField]
|
2024-06-23 20:37:15 +00:00
|
|
|
protected string DieSfxName;
|
2024-06-14 09:11:35 +00:00
|
|
|
|
|
|
|
[SerializeField]
|
2024-06-23 20:37:15 +00:00
|
|
|
protected ParticleSystem DieParticle;
|
2024-06-14 09:11:35 +00:00
|
|
|
|
|
|
|
protected Transform SpawnLocation;
|
2024-06-16 07:55:58 +00:00
|
|
|
|
|
|
|
protected virtual void OnEnable()
|
|
|
|
{
|
|
|
|
SetCurrentHealthPoint(MaxHealthPoint);
|
|
|
|
}
|
|
|
|
|
2024-06-14 09:11:35 +00:00
|
|
|
public virtual void SetCurrentHealthPoint(int changedHealthPoint)
|
|
|
|
{
|
|
|
|
CurrentHealthPoint = changedHealthPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual bool CanDamage()
|
|
|
|
{
|
2024-06-23 20:37:15 +00:00
|
|
|
return CurrentHealthPoint > 0;
|
2024-06-14 09:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void TakeDamage(int damageAmount)
|
|
|
|
{
|
|
|
|
var changeHp = Mathf.Max(CurrentHealthPoint - damageAmount, 0);
|
|
|
|
SetCurrentHealthPoint(changeHp);
|
|
|
|
|
|
|
|
if (changeHp == 0f)
|
|
|
|
{
|
|
|
|
Die();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void TryTakeDamage(int damageAmount)
|
|
|
|
{
|
|
|
|
if (!CanDamage()) return;
|
|
|
|
|
|
|
|
TakeDamage(damageAmount);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Die()
|
|
|
|
{
|
2024-06-23 20:37:15 +00:00
|
|
|
if (!string.IsNullOrEmpty(DieSfxName))
|
2024-06-14 09:11:35 +00:00
|
|
|
{
|
2024-06-23 20:37:15 +00:00
|
|
|
AudioManager.Instance.PlaySfx(DieSfxName);
|
2024-06-14 09:11:35 +00:00
|
|
|
}
|
|
|
|
|
2024-06-23 20:37:15 +00:00
|
|
|
if (DieParticle && SpawnLocation)
|
2024-06-14 09:11:35 +00:00
|
|
|
{
|
2024-06-28 08:44:52 +00:00
|
|
|
var dieParticleInstance = Instantiate(DieParticle, transform.position, DieParticle.transform.rotation, SpawnLocation);
|
|
|
|
dieParticleInstance.Play();
|
2024-06-14 09:11:35 +00:00
|
|
|
}
|
2024-06-29 15:59:31 +00:00
|
|
|
|
|
|
|
if (CharacterIdx != 0)
|
|
|
|
{
|
|
|
|
ItemManager.Instance.ItemDropRandomPosition(CharacterIdx, transform.position, 0f);
|
|
|
|
}
|
2024-06-14 09:11:35 +00:00
|
|
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|