using System; using System.Collections; using System.Collections.Generic; using BITKit.Entities; using UnityEngine; namespace BITKit { public class AutoHealComponent : EntityComponent,IHealthCallback,IDamageCallback { [SerializeField] private IntervalUpdate healDelayInterval; [SerializeField] private IntervalUpdate healInterval; [SerializeField] private int healIncrement; private readonly ValidHandle allowHeal = new(); private IHealth _health; public override void Initialize(IEntity _entity) { base.Initialize(_entity); _entity.RegisterCallback(this); _entity.RegisterCallback(this); } public override void OnStart() { _health = entity.Get(); } private void Update() { if (!allowHeal.Allow || !healDelayInterval.AllowUpdateWithoutReset || !healInterval.AllowUpdate) return; _health.HealthPoint= Mathf.Clamp(_health.HealthPoint+healIncrement,0,_health.MaxHealthPoint); if (_health.HealthPoint == _health.MaxHealthPoint) { allowHeal.RemoveElement(this); } } public void OnSetAlive(bool alive) { allowHeal.SetDisableElements(this,alive is false); } public void OnSetHP(int hp) { } public void OnGetDamage(DamageMessage message) { allowHeal.AddElement(this); healDelayInterval.Reset(); } } }