2023-09-04 07:31:04 +00:00
|
|
|
using Sirenix.OdinInspector;
|
2023-08-21 18:08:11 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
namespace BlueWaterProject
|
|
|
|
{
|
|
|
|
public class HouseInfo : MonoBehaviour, IDamageable
|
|
|
|
{
|
|
|
|
#region Property and variable
|
2023-09-04 07:31:04 +00:00
|
|
|
|
|
|
|
[SerializeField] private IslandInfo islandInfo;
|
|
|
|
|
|
|
|
[SerializeField] private float maxHp = 500f;
|
2023-08-21 18:08:11 +00:00
|
|
|
|
2023-09-04 07:31:04 +00:00
|
|
|
[DisableIf("@true")]
|
|
|
|
[SerializeField] private float currentHp;
|
2023-08-21 18:08:11 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Unity built-in function
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
2023-09-04 07:31:04 +00:00
|
|
|
SetCurrentHp(maxHp);
|
2023-08-21 18:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
RemoveIslandInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Interface property and function
|
|
|
|
|
2023-08-31 07:38:08 +00:00
|
|
|
public void TakeDamage(float attackerPower, float attackerShieldPenetrationRate = default, Vector3? attackPos = null)
|
2023-08-21 18:08:11 +00:00
|
|
|
{
|
2023-09-04 07:31:04 +00:00
|
|
|
var changeHp = Mathf.Max(currentHp - attackerPower, 0);
|
2023-08-21 18:08:11 +00:00
|
|
|
SetCurrentHp(changeHp);
|
|
|
|
|
|
|
|
// 건물 파괴
|
|
|
|
if (changeHp == 0f)
|
|
|
|
{
|
2023-09-19 17:22:19 +00:00
|
|
|
Destroy(gameObject);
|
2023-08-21 18:08:11 +00:00
|
|
|
RemoveIslandInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Custom function
|
|
|
|
|
|
|
|
private void RemoveIslandInfo()
|
|
|
|
{
|
2023-09-11 07:16:02 +00:00
|
|
|
if (islandInfo == null) return;
|
2023-08-21 18:08:11 +00:00
|
|
|
|
2023-09-04 07:31:04 +00:00
|
|
|
islandInfo.RemoveListElement(islandInfo.HouseList, transform);
|
2023-09-20 06:43:24 +00:00
|
|
|
islandInfo.RemoveListElement(islandInfo.TargetAllList, transform);
|
2023-08-21 18:08:11 +00:00
|
|
|
}
|
2023-09-04 07:31:04 +00:00
|
|
|
|
|
|
|
public float GetCurrentHp() => currentHp;
|
|
|
|
public void SetCurrentHp(float value) => currentHp = value;
|
|
|
|
public void SetIslandInfo(IslandInfo island) => islandInfo = island;
|
2023-08-21 18:08:11 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|