92 lines
2.4 KiB
C#
92 lines
2.4 KiB
C#
using DDD.Audios;
|
|
using DDD.Items;
|
|
using DDD.Interfaces;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace DDD
|
|
{
|
|
public class DamageableProps : MonoBehaviour, IDamageable
|
|
{
|
|
[Title("드롭 아이템")]
|
|
[SerializeField]
|
|
protected string CharacterIdx;
|
|
|
|
[field: Title("체력")]
|
|
[field: SerializeField]
|
|
public int MaxHealthPoint { get; private set; } = 1;
|
|
|
|
[field: SerializeField]
|
|
public int CurrentHealthPoint { get; private set; }
|
|
|
|
public bool IsInvincible { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public float InvincibilityDuration { get; private set; }
|
|
|
|
[Title("Die 설정")]
|
|
[SerializeField]
|
|
protected string DieSfxName;
|
|
|
|
[SerializeField]
|
|
protected ParticleSystem DieParticle;
|
|
|
|
[SerializeField]
|
|
protected Transform SpawnLocation;
|
|
|
|
protected virtual void OnEnable()
|
|
{
|
|
SetCurrentHealthPoint(MaxHealthPoint);
|
|
}
|
|
|
|
public virtual void SetCurrentHealthPoint(int changedHealthPoint)
|
|
{
|
|
CurrentHealthPoint = changedHealthPoint;
|
|
}
|
|
|
|
public virtual bool CanDamage()
|
|
{
|
|
return CurrentHealthPoint > 0;
|
|
}
|
|
|
|
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()
|
|
{
|
|
if (!string.IsNullOrEmpty(DieSfxName))
|
|
{
|
|
AudioManager.Instance.PlaySfx(DieSfxName);
|
|
}
|
|
|
|
if (DieParticle && SpawnLocation)
|
|
{
|
|
var dieParticleInstance = Instantiate(DieParticle, transform.position, DieParticle.transform.rotation, SpawnLocation);
|
|
dieParticleInstance.Play();
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(CharacterIdx))
|
|
{
|
|
//ItemManager.Instance.ItemDropRandomPosition(CharacterIdx, transform.position, 0f);
|
|
}
|
|
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
} |