public bool SetHealth(float hp, Entity setter, bool mod = true, DamageType type = DamageType.Regular) { if (Math.Abs(hp - health) < 0.01f) { return(false); } if (hp < health) { if (Unhittable || (PreventDamageInInvincibility && InvincibilityTimer > 0)) { return(false); } } var old = health; var h = MathUtils.Clamp(0, maxHealth, hp); var e = new HealthModifiedEvent { Amount = h - old, Who = Entity, From = setter, Type = type }; if (!Send(e)) { h = old + e.Amount; if (old > h) { InvincibilityTimer = mod ? InvincibilityTimerMax : 0.1f; } if (e.Amount > 0) { EmitParticles(HealthType.Regular); } health = h; Send(new PostHealthModifiedEvent { Amount = e.Amount, Who = Entity, From = setter, Type = type }); TryToKill(setter); return(true); } return(false); }
public override bool HasNoHealth(HealthModifiedEvent e = null) { return(base.HasNoHealth(e) && GetComponent <HeartsComponent>().Total == 0); }