Example #1
0
    public virtual void DecayTick()
    {
        if (decay == null)
        {
            return;
        }
        float num = UnityEngine.Time.time - lastDecayTick;

        if (num < ConVar.Decay.tick)
        {
            return;
        }
        lastDecayTick = UnityEngine.Time.time;
        if (!decay.ShouldDecay(this))
        {
            return;
        }
        float num2 = num * ConVar.Decay.scale;

        if (ConVar.Decay.upkeep)
        {
            upkeepTimer += num2;
            if (upkeepTimer > 0f)
            {
                BuildingPrivlidge buildingPrivilege = GetBuildingPrivilege();
                if (buildingPrivilege != null)
                {
                    upkeepTimer -= buildingPrivilege.PurchaseUpkeepTime(this, Mathf.Max(upkeepTimer, 600f));
                }
            }
            if (upkeepTimer < 1f)
            {
                if (base.healthFraction < 1f && ConVar.Decay.upkeep_heal_scale > 0f && base.SecondsSinceAttacked > 600f)
                {
                    float num3 = num / decay.GetDecayDuration(this) * ConVar.Decay.upkeep_heal_scale;
                    Heal(MaxHealth() * num3);
                }
                return;
            }
            upkeepTimer = 1f;
        }
        decayTimer += num2;
        if (decayTimer < decay.GetDecayDelay(this))
        {
            return;
        }
        using (TimeWarning.New("DecayTick"))
        {
            float num4 = 1f;
            if (ConVar.Decay.upkeep)
            {
                if (!IsOutside())
                {
                    num4 *= ConVar.Decay.upkeep_inside_decay_scale;
                }
            }
            else
            {
                for (int i = 0; i < decayPoints.Length; i++)
                {
                    DecayPoint decayPoint = decayPoints[i];
                    if (decayPoint.IsOccupied(this))
                    {
                        num4 -= decayPoint.protection;
                    }
                }
            }
            if (num4 > 0f)
            {
                float num5 = num2 / decay.GetDecayDuration(this) * MaxHealth();
                Hurt(num5 * num4 * decayVariance, DamageType.Decay);
            }
        }
    }
    public virtual void DecayTick()
    {
        if ((PrefabAttribute)this.decay == (PrefabAttribute)null)
        {
            return;
        }
        float num1 = Time.get_time() - this.lastDecayTick;

        if ((double)num1 < (double)ConVar.Decay.tick)
        {
            return;
        }
        this.lastDecayTick = Time.get_time();
        if (!this.decay.ShouldDecay((BaseEntity)this))
        {
            return;
        }
        float num2 = num1 * ConVar.Decay.scale;

        if (ConVar.Decay.upkeep)
        {
            this.upkeepTimer += num2;
            if ((double)this.upkeepTimer > 0.0)
            {
                BuildingPrivlidge buildingPrivilege = this.GetBuildingPrivilege();
                if (Object.op_Inequality((Object)buildingPrivilege, (Object)null))
                {
                    this.upkeepTimer -= buildingPrivilege.PurchaseUpkeepTime(this, Mathf.Max(this.upkeepTimer, 600f));
                }
            }
            if ((double)this.upkeepTimer < 1.0)
            {
                if ((double)this.healthFraction >= 1.0 || (double)ConVar.Decay.upkeep_heal_scale <= 0.0 || (double)this.SecondsSinceAttacked <= 600.0)
                {
                    return;
                }
                this.Heal(this.MaxHealth() * (num1 / this.decay.GetDecayDuration((BaseEntity)this) * ConVar.Decay.upkeep_heal_scale));
                return;
            }
            this.upkeepTimer = 1f;
        }
        this.decayTimer += num2;
        if ((double)this.decayTimer < (double)this.decay.GetDecayDelay((BaseEntity)this))
        {
            return;
        }
        using (TimeWarning.New(nameof(DecayTick), 0.1f))
        {
            float num3 = 1f;
            if (ConVar.Decay.upkeep)
            {
                if (!this.IsOutside())
                {
                    num3 *= ConVar.Decay.upkeep_inside_decay_scale;
                }
            }
            else
            {
                for (int index = 0; index < this.decayPoints.Length; ++index)
                {
                    DecayPoint decayPoint = this.decayPoints[index];
                    if (decayPoint.IsOccupied((BaseEntity)this))
                    {
                        num3 -= decayPoint.protection;
                    }
                }
            }
            if ((double)num3 <= 0.0)
            {
                return;
            }
            this.Hurt(num2 / this.decay.GetDecayDuration((BaseEntity)this) * this.MaxHealth() * num3 * this.decayVariance, DamageType.Decay, (BaseEntity)null, true);
        }
    }
    public virtual void DecayTick()
    {
        if (this.decay == null)
        {
            return;
        }
        float single = UnityEngine.Time.time - this.lastDecayTick;

        if (single < ConVar.Decay.tick)
        {
            return;
        }
        this.lastDecayTick = UnityEngine.Time.time;
        if (!this.decay.ShouldDecay(this))
        {
            return;
        }
        float single1 = single * ConVar.Decay.scale;

        if (ConVar.Decay.upkeep)
        {
            this.upkeepTimer += single1;
            if (this.upkeepTimer > 0f)
            {
                BuildingPrivlidge buildingPrivilege = this.GetBuildingPrivilege();
                if (buildingPrivilege != null)
                {
                    this.upkeepTimer -= buildingPrivilege.PurchaseUpkeepTime(this, Mathf.Max(this.upkeepTimer, 600f));
                }
            }
            if (this.upkeepTimer < 1f)
            {
                if (base.healthFraction < 1f && ConVar.Decay.upkeep_heal_scale > 0f && base.SecondsSinceAttacked > 600f)
                {
                    float decayDuration = single / this.decay.GetDecayDuration(this) * ConVar.Decay.upkeep_heal_scale;
                    this.Heal(this.MaxHealth() * decayDuration);
                }
                return;
            }
            this.upkeepTimer = 1f;
        }
        this.decayTimer += single1;
        if (this.decayTimer < this.decay.GetDecayDelay(this))
        {
            return;
        }
        using (TimeWarning timeWarning = TimeWarning.New("DecayTick", 0.1f))
        {
            float upkeepInsideDecayScale = 1f;
            if (!ConVar.Decay.upkeep)
            {
                for (int i = 0; i < (int)this.decayPoints.Length; i++)
                {
                    DecayPoint decayPoint = this.decayPoints[i];
                    if (decayPoint.IsOccupied(this))
                    {
                        upkeepInsideDecayScale -= decayPoint.protection;
                    }
                }
            }
            else if (!this.IsOutside())
            {
                upkeepInsideDecayScale *= ConVar.Decay.upkeep_inside_decay_scale;
            }
            if (upkeepInsideDecayScale > 0f)
            {
                float decayDuration1 = single1 / this.decay.GetDecayDuration(this) * this.MaxHealth();
                this.Hurt(decayDuration1 * upkeepInsideDecayScale * this.decayVariance, DamageType.Decay, null, true);
            }
        }
    }