Health System

This commit is contained in:
ThomasCharester committed 2026-11-17 18:44:54 +03:00
1 parent 329cc98ade
commit cb05da5e89
87 files changed
+568550 -155362

No files matched your search

@@ -8,21 +8,20 @@ namespace Code.OfficeGame.BattleMode.Health
{
public class EntityHealth : MonoBehaviour
{
[SerializeField] private int maxHealth;
[SerializeField] private int currentHealth;
public ReactiveProperty<int> _maxHealth;
public ReactiveProperty<int> _currentHealth;
[SerializeField] private HealthData healthData;
public ReadOnlyReactiveProperty<int> MaxHealth => _maxHealth;
public ReadOnlyReactiveProperty<int> CurrentHealth => _currentHealth;
private ReactiveProperty<HealthData> _healthData;
public ReadOnlyReactiveProperty<HealthData> HealthData => _healthData;
public bool IsDead => _healthData.CurrentValue.CurrentHealth <= 0;
[SerializeField]
public Dictionary<HitBoxPartType, int> hitBoxPartModifier = new();
private void Awake()
{
_maxHealth = new ReactiveProperty<int>(maxHealth);
_currentHealth = new ReactiveProperty<int>(currentHealth);
_healthData = new ReactiveProperty<HealthData>(healthData);
}
public virtual void GetDamage(int damage, HitBoxPartType hitBoxPart)
@@ -32,15 +31,42 @@ namespace Code.OfficeGame.BattleMode.Health
GetHeal(-damage);
return;
}
_currentHealth.Value -= damage * hitBoxPartModifier[hitBoxPart];
var newCurrentHealth = _healthData.CurrentValue.CurrentHealth - damage * hitBoxPartModifier[hitBoxPart];
_healthData.Value = new HealthData()
{
MaxHealth = _healthData.CurrentValue.MaxHealth,
CurrentHealth = newCurrentHealth
};
Debug.Log($"{GetEntityId()} got {damage} damage in {hitBoxPart} and have {newCurrentHealth} health");
}
public virtual void GetHeal(int heal)
{
if (heal < 0) return;
_currentHealth.Value += heal;
var newCurrentHealth = _healthData.CurrentValue.CurrentHealth + heal;
_healthData.Value = new HealthData()
{
MaxHealth = _healthData.CurrentValue.MaxHealth,
CurrentHealth = newCurrentHealth
};
}
public virtual void SetHealthData(HealthData newHealthData)
{
_healthData.Value = newHealthData;
}
}
[Serializable]
public struct HealthData
{
public int MaxHealth;
public int CurrentHealth;
}
/// Социальные метрики