2023-08-02 07:45:11 +00:00
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
2023-08-03 03:38:50 +00:00
|
|
|
using Random = UnityEngine.Random;
|
2023-08-02 07:45:11 +00:00
|
|
|
|
|
|
|
// ReSharper disable once CheckNamespace
|
2023-08-03 05:49:05 +00:00
|
|
|
namespace BlueWaterProject
|
2023-08-02 07:45:11 +00:00
|
|
|
{
|
|
|
|
[Serializable]
|
2023-08-03 03:38:50 +00:00
|
|
|
public abstract class AiController : MonoBehaviour, IDamageable
|
2023-08-02 07:45:11 +00:00
|
|
|
{
|
2023-08-03 03:38:50 +00:00
|
|
|
#region Property and variable
|
2023-08-02 07:45:11 +00:00
|
|
|
|
2023-08-03 05:32:17 +00:00
|
|
|
protected Animator aiAnimator;
|
2023-08-03 03:38:50 +00:00
|
|
|
|
|
|
|
private static readonly int DeathHash = Animator.StringToHash("Death");
|
|
|
|
private static readonly int DamageHash = Animator.StringToHash("TakeDamage");
|
2023-08-02 07:45:11 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2023-08-03 03:38:50 +00:00
|
|
|
#region abstract function
|
|
|
|
|
2023-08-03 05:32:17 +00:00
|
|
|
protected abstract void Attack();
|
2023-08-03 03:38:50 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2023-08-02 07:45:11 +00:00
|
|
|
#region Unity built-in function
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
2023-08-03 03:38:50 +00:00
|
|
|
aiAnimator = Utils.GetComponentAndAssert<Animator>(transform);
|
2023-08-02 07:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
2023-08-03 03:38:50 +00:00
|
|
|
SetCurrentHp(AiStat.maxHp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region interface property and function
|
|
|
|
|
|
|
|
[field: SerializeField] public AiStat AiStat { get; set; } = new();
|
|
|
|
|
|
|
|
public void TakeDamage(AiStat attacker, AiStat defender)
|
|
|
|
{
|
|
|
|
// 회피 성공 체크
|
|
|
|
if (Random.Range(0, 100) < defender.avoidanceRate)
|
|
|
|
{
|
|
|
|
// TODO : 회피 처리
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var finalDamage = Utils.CalcDamage(attacker, defender);
|
|
|
|
|
|
|
|
// 방패 막기 체크
|
|
|
|
if (finalDamage == 0f)
|
|
|
|
{
|
|
|
|
// TODO : 방패로 막힘 처리(애니메이션 등)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var changeHp = Mathf.Max(defender.currentHp - finalDamage, 0);
|
|
|
|
SetCurrentHp(changeHp);
|
|
|
|
|
|
|
|
// 죽었는지 체크
|
|
|
|
if (changeHp == 0f)
|
|
|
|
{
|
|
|
|
// TODO : 죽었을 때 처리(죽는 애니메이션 이후 사라지는 효과 등)
|
|
|
|
aiAnimator.SetTrigger(DeathHash);
|
|
|
|
return;
|
|
|
|
}
|
2023-08-02 07:45:11 +00:00
|
|
|
|
2023-08-03 03:38:50 +00:00
|
|
|
aiAnimator.SetTrigger(DamageHash);
|
2023-08-02 07:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Function
|
|
|
|
|
|
|
|
public void SetCurrentHp(float value) => AiStat.currentHp = value;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|