using System; using System.Collections; using System.Collections.Generic; using BITFALL.Entities.Inventory; using BITFALL.Items; using BITKit; using BITKit.Entities; using UnityEditor; using UnityEngine; namespace BITFALL.Entities { [CustomType(typeof(IKnockdown))] public sealed class EntityKnockdown :EntityComponent,IKnockdown { [SerializeField] private int knockedHealth; [SerializeField] private int initialKnockedHealth; public int KnockedHealth=>knockedHealth; public int InitialKnockedHealth { get => initialKnockedHealth; set => initialKnockedHealth = value; } public event Action OnKnockdown; public event Action OnRevive; public bool IsKnockdown { get;private set; } private readonly Optional knockedHeal=new(); [Inject] private IHealth _health; [Inject] private IEntityInventory _inventory; public override void OnStart() { _health.OnDamageFactory += OnDamageFactory; _health.OnSetAlive += OnSetAlive; _health.OnSetHealthPoint += OnSetHealthPoint; _inventory.OnUsedItem += OnUseItem; } private void OnSetHealthPoint(int obj) { if (obj <= 0 || !IsKnockdown || !_health.IsAlive) return; IsKnockdown = false; OnRevive?.Invoke(); } private void OnUseItem(IBasicItem arg) { if (IsKnockdown is false || arg.GetAssetable().TryGetProperty(out var reviveItem) is false) return; IsKnockdown = false; OnRevive?.Invoke(); } private void OnSetAlive(bool obj) { IsKnockdown = false; } private int OnDamageFactory(DamageMessage arg,int currentDamage) { if (IsKnockdown || _health.HealthPoint - currentDamage >=0 ) return currentDamage; IsKnockdown = true; OnKnockdown?.Invoke(); _health.HealthPoint = 0; return 0; } } }