62 lines
1.4 KiB
C#
62 lines
1.4 KiB
C#
|
using System;
|
||
|
using UnityEngine;
|
||
|
|
||
|
// ReSharper disable once CheckNamespace
|
||
|
namespace BlueWaterProject
|
||
|
{
|
||
|
public class HouseInfo : MonoBehaviour, IDamageable
|
||
|
{
|
||
|
#region Property and variable
|
||
|
|
||
|
public IslandInfo IslandInfo { get; set; }
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region Unity built-in function
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
SetCurrentHp(AiStat.maxHp);
|
||
|
}
|
||
|
|
||
|
private void OnDisable()
|
||
|
{
|
||
|
RemoveIslandInfo();
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region Interface property and function
|
||
|
|
||
|
[field: SerializeField] public AiStat AiStat { get; set; }
|
||
|
|
||
|
public float GetCurrentHp() => AiStat.currentHp;
|
||
|
|
||
|
public void SetCurrentHp(float value) => AiStat.currentHp = value;
|
||
|
|
||
|
public void TakeDamage(AiStat attacker, AiStat defender, Vector3? attackPos = null)
|
||
|
{
|
||
|
var changeHp = Mathf.Max(defender.currentHp - attacker.atk, 0);
|
||
|
SetCurrentHp(changeHp);
|
||
|
|
||
|
// 건물 파괴
|
||
|
if (changeHp == 0f)
|
||
|
{
|
||
|
RemoveIslandInfo();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region Custom function
|
||
|
|
||
|
private void RemoveIslandInfo()
|
||
|
{
|
||
|
if (!IslandInfo) return;
|
||
|
|
||
|
IslandInfo.RemoveListElement(IslandInfo.HouseList, transform);
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|