Exemplo n.º 1
0
        /// <summary>
        /// Unsubscribe all subscribers from this instance events.
        /// </summary>
        private void UnsubscribeEvents()
        {
            if (OnHealthChanges != null)
            {
                foreach (Action <ChangedHealthArgs> handler in OnHealthChanges.GetInvocationList())
                {
                    OnHealthChanges -= handler;
                }
            }

            if (OnStopShowing != null)
            {
                foreach (Action <IShowable> handler in OnStopShowing.GetInvocationList())
                {
                    OnStopShowing -= handler;
                }
            }

            if (OnShowableDataChanges != null)
            {
                foreach (Action <ShowableData> handler in OnShowableDataChanges.GetInvocationList())
                {
                    OnShowableDataChanges -= handler;
                }
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
 public void Heal(int amount)
 {
     if (_health + amount <= _maxHealth)
     {
         _health += amount;
     }
     else
     {
         _health = _maxHealth;
     }
     OnHealthChanges?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 4
0
    public void Damage(int damage)
    {
        if (_health - damage >= 0)
        {
            _health -= damage;
        }
        else
        {
            _health = 0;
        }
        OnHealthChanges?.Invoke(this, EventArgs.Empty);

        if (_health == 0)
        {
            OnHealthZero?.Invoke(this, EventArgs.Empty);
        }
    }
Exemplo n.º 5
0
        /// <summary>
        /// Called when any squad unit has died.
        /// </summary>
        /// <param name="died">The died.</param>
        private void OnUnitDieHandler(IDying died)
        {
            died.OnDie -= OnUnitDieHandler;

            if (died is Unit unit)
            {
                unit.OnHealthChanges -= OnUnitHealthChangesHandler;
                units.Remove(unit);

                if (units.Count > 0)
                {
                    var changedHealth = GetChangedHealthArgs();
                    OnHealthChanges?.Invoke(changedHealth);
                }
                else
                {
                    OnStopShowing?.Invoke(this);
                    OnDie?.Invoke(this);
                }
            }
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        /// <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);
        }