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(float attackerPower, float attackerShieldPenetrationRate = default, Vector3? attackPos = null)
|
|
{
|
|
var changeHp = Mathf.Max(AiStat.CurrentHp - attackerPower, 0);
|
|
SetCurrentHp(changeHp);
|
|
|
|
// 건물 파괴
|
|
if (changeHp == 0f)
|
|
{
|
|
RemoveIslandInfo();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Custom function
|
|
|
|
private void RemoveIslandInfo()
|
|
{
|
|
if (!IslandInfo) return;
|
|
|
|
IslandInfo.RemoveListElement(IslandInfo.HouseList, transform);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |