39 lines
1.4 KiB
C#
Executable File
39 lines
1.4 KiB
C#
Executable File
using System;
|
|
using UnityEngine;
|
|
|
|
public class CharacterCondition : MonoBehaviour
|
|
{
|
|
public event Action<object> OnKilledEvent;
|
|
public event Action<int> OnDamageHealthTakenEvent;
|
|
public event Action<int> OnDamageArmourTakenEvent;
|
|
public event Action<int> OnAmmunitionTakenEvent;
|
|
|
|
[SerializeField] private int HealthPoints;
|
|
[SerializeField] private int ArmourPoints;
|
|
[SerializeField] private int Ammunition;
|
|
|
|
public void Start()
|
|
{
|
|
|
|
}
|
|
|
|
public void GetDamage(float damage)
|
|
{
|
|
HealthPoints -= Mathf.RoundToInt(damage * (1 - ArmourPoints * 0.5f));
|
|
ArmourPoints -= Mathf.RoundToInt(Mathf.Sqrt(damage) * 5);
|
|
|
|
OnDamageHealthTakenEvent?.Invoke(HealthPoints);
|
|
OnDamageArmourTakenEvent?.Invoke(ArmourPoints);
|
|
if (HealthPoints < 0)
|
|
OnKilledEvent?.Invoke(gameObject);
|
|
}
|
|
public void GiveHealth(int health) => HealthPoints = Mathf.Clamp(health + HealthPoints, 0, 100);
|
|
public void SetHealth(int health) => HealthPoints = Mathf.Clamp(health, 0, 100);
|
|
public void GiveArmour(int armour) => ArmourPoints = Mathf.Clamp(armour + ArmourPoints, 0, 100);
|
|
public void SetArmour(int armour) => ArmourPoints = Mathf.Clamp(armour, 0, 100);
|
|
public void TakeAmmo(int ammo)
|
|
{
|
|
Ammunition += ammo;
|
|
OnAmmunitionTakenEvent?.Invoke(Ammunition);
|
|
}
|
|
} |