Exemplo n.º 1
0
        /// <summary>
        /// Inflict damage to this subject
        /// </summary>
        public void DoDamage(int damage, Subject dealer)
        {
            if (IsDead)
            {
                return;
            }
            if (!Options.Data.FriendlyFire && StaticUtil.SameTeam(this, dealer))
            {
                return;
            }

            LastAttacker = dealer;
            if (Stats.HitSound != null)
            {
                AudioSource.PlayClipAtPoint(Stats.HitSound, transform.position);
            }
            int damageProcessed = damage;

            #region #### Armor Calculation Block
            if (Armor > 0)
            {
                if (Stats.ArmorType == ArmorType.Absorb)
                {
                    Armor = Armor - damage; // Absorb damage
                    if (Armor < 0)          // If any armor is left, count as excess
                    {
                        damageProcessed = -Armor;
                        Armor           = 0;
                    }
                    else
                    {
                        damageProcessed = 0;
                    }
                }
                else
                {
                    damageProcessed = damage - Armor; // Nullify damage
                    if (Armor < 0)                    // if any is left, count as excess
                    {
                        damageProcessed = -Armor;
                        Armor           = 0;
                    }
                }
            }
            #endregion

            if (damageProcessed < 0)
            {
                damageProcessed = 0;
            }
            else if (damageProcessed > Stats.Health.Actual)
            {
                damageProcessed = (int)Stats.Health.Actual;
            }
            Health    -= damageProcessed;
            LastDamage = damageProcessed;

            Stats.DamageTaken += damageProcessed;
            LastAttacker.Stats.DamageDealt += damageProcessed;
            LastAttacker.Stats.ShotsConnected++;

            StaticUtil.SpawnFloatingText(this, transform.position, damageProcessed.ToString());

            if (OnAttacked != null)
            {
                OnAttacked();
            }
        }