/// <summary> /// Updates the showable health in the UI. /// </summary> protected void UpdateShowableHealth() { var changedHealth = new ChangedHealthArgs( currentHealth: HealPoints, fullness: HealPoints > 0 ? (float)HealPoints / Parameters.HealPointsMax : 0, description: UnitDescription ); OnHealthChanges?.Invoke(changedHealth); }
/// <summary> /// Applies the damage. /// </summary> /// <param name="attacker">The attacker.</param> /// <param name="damage">The damage.</param> /// <exception cref="ArgumentOutOfRangeException">damage - Must be greater than or equal to 0.</exception> public void ApplyDamage(ITeamMember attacker, float damage) { if (damage < 0) { throw new ArgumentOutOfRangeException(nameof(damage), "Must be greater than or equal to 0."); } HealPoints -= (int)damage; if (HealPoints <= 0) { Die(); } var changedHealth = new ChangedHealthArgs( currentHealth: HealPoints, fullness: HealPoints > 0 ? (float)HealPoints / healPointsMax : 0f, description: GetHealthDescription() ); OnHealthChanges?.Invoke(changedHealth); }
/// <summary> /// Called when the health of any unit within the squad has changed. /// </summary> /// <param name="changedHealthArgs">The changed health arguments.</param> private void OnUnitHealthChangesHandler(ChangedHealthArgs changedHealthArgs) { var changedHealth = GetChangedHealthArgs(); OnHealthChanges?.Invoke(changedHealth); }
/// <summary> /// Called when the health has changed. /// </summary> /// <param name="changedHealthArgs">The changed health arguments.</param> private void OnHealthChangesHandler(ChangedHealthArgs changedHealthArgs) { UpdateDescription(changedHealthArgs.Description); }
/// <summary> /// Called when the health has changed. /// </summary> /// <param name="changedHealthArgs">The changed health arguments.</param> public void OnHealthChangesHandler(ChangedHealthArgs changedHealthArgs) { healthImage.fillAmount = changedHealthArgs.Fullness; }