Пример #1
0
        public override string CompInspectStringExtra()
        {
            StringBuilder sb = new StringBuilder();

            switch (base.Stage)
            {
            case RotStage.Fresh:
                sb.Append("RotStateFresh".Translate());
                break;

            case RotStage.Rotting:
                sb.Append("RotStateRotting".Translate());
                break;

            case RotStage.Dessicated:
                sb.Append("RotStateDessicated".Translate());
                break;
            }
            float num = (float)this.PropsRot.TicksToRotStart - base.RotProgress;

            if (num > 0f)
            {
                float        num2      = GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, this.parent.Map);
                List <Thing> thingList = GridsUtility.GetThingList(this.parent.PositionHeld, this.parent.Map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] is Building_Refrigerator)
                    {
                        Building_Refrigerator building_Refrigerator = thingList[i] as Building_Refrigerator;
                        num2 = building_Refrigerator.CurrentTemp;
                        break;
                    }
                }
                num2 = (float)Mathf.RoundToInt(num2);
                float num3 = GenTemperature.RotRateAtTemperature(num2);
                int   ticksUntilRotAtCurrentTemp = base.TicksUntilRotAtCurrentTemp;
                if (num3 < 0.001f)
                {
                    sb.Append(Translator.Translate("CurrentlyFrozen") + ".");
                }
                else
                {
                    if (num3 < 0.999f)
                    {
                        sb.Append(Translator.Translate("CurrentlyRefrigerated", new object[]
                        {
                            GenDate.ToStringTicksToPeriodVague(ticksUntilRotAtCurrentTemp)
                        }) + ".");
                    }
                    else
                    {
                        sb.Append(Translator.Translate("NotRefrigerated", new object[]
                        {
                            GenDate.ToStringTicksToPeriodVague(ticksUntilRotAtCurrentTemp)
                        }) + ".");
                    }
                }
            }
            return(sb.ToString().TrimEndNewlines());
        }
 public void TickRottables()
 {
     if (storedDef == null || Find.TickManager.TicksAbs % 250 != 0)
     {
         return;
     }
     if (StoredIsRottable)
     {
         float rotProgress        = rotProgressInt;
         float num                = 1f;
         float temperatureForCell = GenTemperature.GetTemperatureForCell(Position, Map);
         num            *= GenTemperature.RotRateAtTemperature(temperatureForCell);
         rotProgressInt += Mathf.Round(num * 250f);
         if (rotProgressInt >= storedDef.GetCompProperties <CompProperties_Rottable>().TicksToRotStart)
         {
             Messages.Message("MessageRottedAwayInStorage".Translate(storedDef.label).CapitalizeFirst(), MessageTypeDefOf.SilentInput);
             storedDef      = null;
             ThingCount     = 0;
             rotProgressInt = 1;
         }
     }
     else
     {
         rotProgressInt = 0;
     }
 }
        public virtual void ChangeHeat(int ticks)
        {
            if (!IsActive())
            {
                return;
            }

            float targetTemp = GetTargetTemp();

            foreach (Thing thing in base.slotGroup.HeldThings)
            {
                CompDTemperature comp = thing.TryGetComp <CompDTemperature>();
                if (comp != null && comp.curTemp < targetTemp)
                {
                    comp.Diffuse(targetTemp * 2f, ticks);
                }

                if (ThermodynamicsSettings.warmersSlowRot)
                {
                    CompRottable rot = thing.TryGetComp <CompRottable>();
                    if (rot != null && GenTemperature.RotRateAtTemperature(thing.AmbientTemperature) == unrefrigeratedRotRate)
                    {
                        rot.RotProgress = rot.RotProgress - ticks * slowRotRateAmount;
                    }
                }
            }
        }
Пример #4
0
        public override string CompInspectStringExtra()
        {
            if (!this.Active)
            {
                return(null);
            }
            StringBuilder stringBuilder = new StringBuilder();

            switch (this.Stage)
            {
            case RotStage.Fresh:
                stringBuilder.Append("VCE_PlumsDrying".Translate() + ".");
                break;
            }
            if ((float)this.PropsRot.TicksToRotStart - this.RotProgress > 0f)
            {
                float num = GenTemperature.RotRateAtTemperature((float)Mathf.RoundToInt(this.parent.AmbientTemperature));
                int   ticksUntilRotAtCurrentTemp = this.TicksUntilRotAtCurrentTemp;
                stringBuilder.AppendLine();
                if (num < 0.001f)
                {
                    stringBuilder.Append("VCE_PlumsCurrentlyFrozen".Translate() + ".");
                }
                else if (num < 0.999f)
                {
                    stringBuilder.Append("VCE_PlumsCurrentlyRefrigerated".Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriod(true, false, true, true)) + ".");
                }
                else
                {
                    stringBuilder.Append("VCE_PlumsDryingCorrectly".Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriod(true, false, true, true)) + ".");
                }
            }
            return(stringBuilder.ToString());
        }
Пример #5
0
 private void Tick(int interval)
 {
     if (this.Active)
     {
         float rotProgress        = this.RotProgress;
         float ambientTemperature = base.parent.AmbientTemperature;
         float num = GenTemperature.RotRateAtTemperature(ambientTemperature);
         this.RotProgress += num * (float)interval;
         if (this.Stage == RotStage.Rotting && this.PropsRot.rotDestroys)
         {
             if (base.parent.Spawned && base.parent.Map.slotGroupManager.SlotGroupAt(base.parent.Position) != null)
             {
                 Messages.Message("MessageRottedAwayInStorage".Translate(base.parent.Label).CapitalizeFirst(), MessageTypeDefOf.NegativeEvent);
                 LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
             }
             base.parent.Destroy(DestroyMode.Vanish);
         }
         else if (Mathf.FloorToInt((float)(rotProgress / 60000.0)) != Mathf.FloorToInt((float)(this.RotProgress / 60000.0)) && this.ShouldTakeRotDamage())
         {
             if (this.Stage == RotStage.Rotting && this.PropsRot.rotDamagePerDay > 0.0)
             {
                 base.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(this.PropsRot.rotDamagePerDay), -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
             }
             else if (this.Stage == RotStage.Dessicated && this.PropsRot.dessicatedDamagePerDay > 0.0)
             {
                 base.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(this.PropsRot.dessicatedDamagePerDay), -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
             }
         }
     }
 }
Пример #6
0
        public int TicksUntilRotAtTemp(float temp)
        {
            int result;

            if (!this.Active)
            {
                result = 72000000;
            }
            else
            {
                float num = GenTemperature.RotRateAtTemperature(temp);
                if (num <= 0f)
                {
                    result = 72000000;
                }
                else
                {
                    float num2 = (float)this.PropsRot.TicksToRotStart - this.RotProgress;
                    if (num2 <= 0f)
                    {
                        result = 0;
                    }
                    else
                    {
                        result = Mathf.RoundToInt(num2 / num);
                    }
                }
            }
            return(result);
        }
Пример #7
0
        private void Tick(int interval)
        {
            if (!this.Active)
            {
                return;
            }
            float rotProgress        = this.RotProgress;
            float ambientTemperature = this.parent.AmbientTemperature;
            float num = GenTemperature.RotRateAtTemperature(ambientTemperature);

            this.RotProgress += num * (float)interval;
            if (this.Stage == RotStage.Rotting && this.PropsRot.rotDestroys)
            {
                if (this.parent.IsInAnyStorage() && this.parent.SpawnedOrAnyParentSpawned)
                {
                    Messages.Message("MessageRottedAwayInStorage".Translate(this.parent.Label, this.parent).CapitalizeFirst(), new TargetInfo(this.parent.PositionHeld, this.parent.MapHeld, false), MessageTypeDefOf.NegativeEvent, true);
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
                }
                this.parent.Destroy(DestroyMode.Vanish);
                return;
            }
            bool flag = Mathf.FloorToInt(rotProgress / 60000f) != Mathf.FloorToInt(this.RotProgress / 60000f);

            if (flag && this.ShouldTakeRotDamage())
            {
                if (this.Stage == RotStage.Rotting && this.PropsRot.rotDamagePerDay > 0f)
                {
                    this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.rotDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                }
                else if (this.Stage == RotStage.Dessicated && this.PropsRot.dessicatedDamagePerDay > 0f)
                {
                    this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.dessicatedDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                }
            }
        }
Пример #8
0
 private void Tick(int interval)
 {
     if (Active)
     {
         float rotProgress        = RotProgress;
         float ambientTemperature = parent.AmbientTemperature;
         float num = GenTemperature.RotRateAtTemperature(ambientTemperature);
         RotProgress += num * (float)interval;
         if (Stage == RotStage.Rotting && PropsRot.rotDestroys)
         {
             if (parent.IsInAnyStorage() && parent.SpawnedOrAnyParentSpawned)
             {
                 Messages.Message("MessageRottedAwayInStorage".Translate(parent.Label, parent).CapitalizeFirst(), new TargetInfo(parent.PositionHeld, parent.MapHeld), MessageTypeDefOf.NegativeEvent);
                 LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
             }
             parent.Destroy();
         }
         else if (Mathf.FloorToInt(rotProgress / 60000f) != Mathf.FloorToInt(RotProgress / 60000f) && ShouldTakeRotDamage())
         {
             if (Stage == RotStage.Rotting && PropsRot.rotDamagePerDay > 0f)
             {
                 parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(PropsRot.rotDamagePerDay)));
             }
             else if (Stage == RotStage.Dessicated && PropsRot.dessicatedDamagePerDay > 0f)
             {
                 parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(PropsRot.dessicatedDamagePerDay)));
             }
         }
     }
 }
Пример #9
0
        public override void CompTickRare()
        {
            if (this.parent.MapHeld != null && this.parent.Map != null)
            {
                HashSet <Thing> list        = new HashSet <Thing>(this.parent.MapHeld.thingGrid.ThingsListAtFast(this.parent.PositionHeld));
                var             isMeat      = this?.parent?.def.IsMeat ?? false;
                var             isSalted    = this?.parent?.def?.defName?.ToLowerInvariant()?.Contains("salted") ?? false;
                var             pantryShelf = list.FirstOrDefault(x => x is Building_RottableFixer && x.def.defName == "LotR_PantryShelf");
                var             saltPot     = list.FirstOrDefault(x => x is Building_RottableFixer && x.def.defName == "LotR_SaltBarrel");
                if (isMeat && !isSalted && saltPot != null)
                {
                    HandleMeatThatNeedsSalting(this.parent);
                    return;
                }

                float rotProgress        = this.RotProgress;
                float num                = 1f;
                float temperatureForCell = GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, this.parent.MapHeld);
                var   b = list.FirstOrDefault(x => x is Building_RottableFixer);
                if (b != null)
                {
                    if (!isMeat && b.def.defName == "LotR_PantryShelf")
                    {
                        num = 0.3f;
                    }
                    if (b.def.defName == "LotR_SaltBarrel")
                    {
                        num = 0.0666667f;
                    }
                }

                num *= GenTemperature.RotRateAtTemperature(temperatureForCell);
                this.RotProgress += Mathf.Round(num * 250f);
                if (this.Stage == RotStage.Rotting && this.PropsRot.rotDestroys)
                {
                    if (this.parent.Position.GetSlotGroup(this.parent.Map) != null)
                    {
                        Messages.Message("MessageRottedAwayInStorage".Translate(new object[]
                        {
                            this.parent.Label
                        }).CapitalizeFirst(), MessageTypeDefOf.SilentInput);
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
                    }
                    this.parent.Destroy(DestroyMode.Vanish);
                    return;
                }
                if (Mathf.FloorToInt(rotProgress / 60000f) != Mathf.FloorToInt(this.RotProgress / 60000f))
                {
                    if (this.Stage == RotStage.Rotting && this.PropsRot.rotDamagePerDay > 0f)
                    {
                        this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.rotDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                    }
                    else if (this.Stage == RotStage.Dessicated && this.PropsRot.dessicatedDamagePerDay > 0f && this.ShouldTakeDessicateDamage())
                    {
                        this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.dessicatedDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                    }
                }
            }
        }
        public override void CompTickRare()
        {
            if (parent.MapHeld == null || parent.Map == null)
            {
                return;
            }

            var rotProgress        = RotProgress;
            var num                = 1f;
            var temperatureForCell =
                GenTemperature.GetTemperatureForCell(parent.PositionHeld, parent.MapHeld);
            var list = parent.MapHeld.thingGrid.ThingsListAtFast(parent.PositionHeld);

            foreach (var thing in list)
            {
                if (thing is not Building_Refrigerator bf)
                {
                    continue;
                }

                temperatureForCell = bf.CurrentTemp;
                break;
            }

            num         *= GenTemperature.RotRateAtTemperature(temperatureForCell);
            RotProgress += Mathf.Round(num * 250f);
            if (Stage == RotStage.Rotting && PropsRot.rotDestroys)
            {
                if (parent.IsInAnyStorage() && parent.SpawnedOrAnyParentSpawned)
                {
                    Messages.Message("MessageRottedAwayInStorage".Translate(parent.Label).CapitalizeFirst(),
                                     new TargetInfo(parent.PositionHeld, parent.MapHeld),
                                     MessageTypeDefOf.NegativeEvent);
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers,
                                                         OpportunityType.GoodToKnow);
                }

                parent.Destroy();
                return;
            }

            if (Mathf.FloorToInt(rotProgress / 60000f) == Mathf.FloorToInt(RotProgress / 60000f) ||
                !ShouldTakeRotDamage())
            {
                return;
            }

            if (Stage == RotStage.Rotting && PropsRot.rotDamagePerDay > 0f)
            {
                parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                 GenMath.RoundRandom(PropsRot.rotDamagePerDay)));
            }
            else if (Stage == RotStage.Dessicated && PropsRot.dessicatedDamagePerDay > 0f)
            {
                parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                 GenMath.RoundRandom(PropsRot.dessicatedDamagePerDay)));
            }
        }
        public override string CompInspectStringExtra()
        {
            if (!this.Active)
            {
                return(null);
            }
            StringBuilder stringBuilder = new StringBuilder();
            RotStage      stage         = this.Stage;

            if (stage != RotStage.Fresh)
            {
                if (stage != RotStage.Rotting)
                {
                    if (stage == RotStage.Dessicated)
                    {
                        stringBuilder.Append("RotStateDessicated".Translate() + ".");
                    }
                }
                else
                {
                    stringBuilder.Append("RotStateRotting".Translate() + ".");
                }
            }
            else
            {
                stringBuilder.Append("RotStateFresh".Translate() + ".");
            }
            float num = (float)this.PropsRot.TicksToRotStart - this.RotProgress;

            if (num > 0f)
            {
                float num2 = this.parent.AmbientTemperature;
                num2 = (float)Mathf.RoundToInt(num2);
                float num3 = GenTemperature.RotRateAtTemperature(num2);
                int   ticksUntilRotAtCurrentTemp = this.TicksUntilRotAtCurrentTemp;
                stringBuilder.AppendLine();
                if (num3 < 0.001f)
                {
                    stringBuilder.Append("CurrentlyFrozen".Translate() + ".");
                }
                else if (num3 < 0.999f)
                {
                    stringBuilder.Append("CurrentlyRefrigerated".Translate(new object[]
                    {
                        ticksUntilRotAtCurrentTemp.ToStringTicksToPeriodVague(true, true)
                    }) + ".");
                }
                else
                {
                    stringBuilder.Append("NotRefrigerated".Translate(new object[]
                    {
                        ticksUntilRotAtCurrentTemp.ToStringTicksToPeriodVague(true, true)
                    }) + ".");
                }
            }
            return(stringBuilder.ToString());
        }
        public override bool FilterApplies(Thing thing)
        {
            CompRottable rot = thing.TryGetComp <CompRottable>();

            return
                (extraOption == 1 ? rot != null :
                 extraOption == 2 ? GenTemperature.RotRateAtTemperature(thing.AmbientTemperature) is float r && r > 0 && r < 1 :
                 extraOption == 3 ? GenTemperature.RotRateAtTemperature(thing.AmbientTemperature) <= 0 :
                 rot?.Stage == sel);
        }
Пример #13
0
        public override void CompTickRare()
        {
            if (this.parent.MapHeld != null && this.parent.Map != null)
            {
                float rotProgress        = this.RotProgress;
                float num                = 1f;
                float temperatureForCell =
                    GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, this.parent.MapHeld);
                List <Thing> list = this.parent.MapHeld.thingGrid.ThingsListAtFast(this.parent.PositionHeld);
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] is Building_Refrigerator)
                    {
                        var bf = list[i] as Building_Refrigerator;
                        temperatureForCell = bf.CurrentTemp;
                        break;
                    }
                }

                num *= GenTemperature.RotRateAtTemperature(temperatureForCell);
                this.RotProgress += Mathf.Round(num * 250f);
                if (this.Stage == RotStage.Rotting && this.PropsRot.rotDestroys)
                {
                    if (this.parent.IsInAnyStorage() && this.parent.SpawnedOrAnyParentSpawned)
                    {
                        Messages.Message("MessageRottedAwayInStorage".Translate(new object[]
                        {
                            this.parent.Label
                        }).CapitalizeFirst(), new TargetInfo(this.parent.PositionHeld, this.parent.MapHeld, false),
                                         MessageTypeDefOf.NegativeEvent, true);
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers,
                                                             OpportunityType.GoodToKnow);
                    }
                    this.parent.Destroy(DestroyMode.Vanish);
                    return;
                }
                bool flag = Mathf.FloorToInt(rotProgress / 60000f) != Mathf.FloorToInt(this.RotProgress / 60000f);
                if (flag && ShouldTakeRotDamage())
                {
                    if (this.Stage == RotStage.Rotting && this.PropsRot.rotDamagePerDay > 0f)
                    {
                        this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                              (float)GenMath.RoundRandom(this.PropsRot.rotDamagePerDay), 0f, -1f, null, null, null,
                                                              DamageInfo.SourceCategory.ThingOrUnknown, null));
                    }
                    else if (this.Stage == RotStage.Dessicated && this.PropsRot.dessicatedDamagePerDay > 0f)
                    {
                        this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                              (float)GenMath.RoundRandom(this.PropsRot.dessicatedDamagePerDay), 0f, -1f, null, null,
                                                              null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                    }
                }
            }
        }
Пример #14
0
        public static bool CompInspectStringCustomHopper(CompRottable __instance, ref string __result)
        {
            IEnumerable <Thing> things = GetCompRottableThings(__instance);

            if (things.OfType <NPDHopper_Storage>().Any())
            {
                Thing         t             = things.OfType <NPDHopper_Storage>().First();
                StringBuilder stringBuilder = new StringBuilder();
                RotStage      stage         = __instance.Stage;
                if (stage != RotStage.Fresh)
                {
                    if (stage != RotStage.Rotting)
                    {
                        if (stage == RotStage.Dessicated)
                        {
                            stringBuilder.Append("RotStateDessicated".Translate() + ".");
                        }
                    }
                    else
                    {
                        stringBuilder.Append("RotStateRotting".Translate() + ".");
                    }
                }
                else
                {
                    stringBuilder.Append("RotStateFresh".Translate() + ".");
                }
                float num = (float)__instance.PropsRot.TicksToRotStart - __instance.RotProgress;
                if (num > 0f)
                {
                    float num2 = t.TryGetComp <CompPowerTrader>().PowerOn ? (float)Mathf.RoundToInt(things.OfType <NPDHopper_Storage>().First().def.GetModExtension <HopperCustom>().setTemperature)
                        : __instance.parent.AmbientTemperature;
                    float num3 = GenTemperature.RotRateAtTemperature(num2);
                    int   ticksUntilRotAtCurrentTemp = TicksUntilRotAtSetTemp(__instance, num2);
                    stringBuilder.AppendLine();
                    if (num3 < 0.001f)
                    {
                        stringBuilder.Append("CurrentlyFrozen".Translate() + ".");
                    }
                    else if (num3 < 0.999f)
                    {
                        stringBuilder.Append("CurrentlyRefrigerated".Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriod()) + ".");
                    }
                    else
                    {
                        stringBuilder.Append("NotRefrigerated".Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriod()) + ".");
                    }
                }
                __result = stringBuilder.ToString();
                return(false);
            }
            return(true);
        }
        public static void Postfix(ref CompRottable __instance, ref int __result, float temp)
        {
            if (__result >= 72000000 || __result <= 0 || !__instance.parent.Spawned ||
                __instance.parent.Position.GetFirstThingWithComp <CompAYPreserve>(__instance.parent.Map) == null)
            {
                return;
            }

            var num  = GenTemperature.RotRateAtTemperature(temp);
            var num2 = __instance.PropsRot.TicksToRotStart - __instance.RotProgress;

            __result = Mathf.RoundToInt(num2 / num) * 2;
        }
Пример #16
0
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     this.compPowerTrader  = base.GetComp <CompPowerTrader>();
     this.compDTempControl = base.GetComp <CompDTempControl>();
     this.compRefuelable   = base.GetComp <CompRefuelable>();
     if (unrefrigeratedRotRate < 0)
     {
         unrefrigeratedRotRate = GenTemperature.RotRateAtTemperature(999f);
     }
     if (slowRotRateAmount < 0)
     {
         slowRotRateAmount = unrefrigeratedRotRate - GenTemperature.RotRateAtTemperature(1f);
     }
 }
Пример #17
0
        public override string CompInspectStringExtra()
        {
            if (!Active)
            {
                return(null);
            }

            var sb = new StringBuilder();

            switch (Stage)
            {
            case RotStage.Fresh:            sb.Append("RotStateFresh".Translate() + "."); break;

            case RotStage.Rotting:          sb.Append("RotStateRotting".Translate() + "."); break;

            case RotStage.Dessicated:       sb.Append("RotStateDessicated".Translate() + "."); break;
            }

            float progressUntilStartRot = PropsRot.TicksToRotStart - RotProgress;

            if (progressUntilStartRot > 0)
            {
                float cellTemp = parent.AmbientTemperature;
                cellTemp = Mathf.RoundToInt(cellTemp);        //Rounding here reduces dithering
                float rotRate = GenTemperature.RotRateAtTemperature(cellTemp);

                int ticksUntilStartRot = TicksUntilRotAtCurrentTemp;

                sb.AppendLine();
                if (rotRate < 0.001f)
                {
                    // frozen
                    sb.Append("CurrentlyFrozen".Translate() + ".");
                }
                else if (rotRate < 0.999f)
                {
                    // refrigerated
                    sb.Append("CurrentlyRefrigerated".Translate(ticksUntilStartRot.ToStringTicksToPeriod()) + ".");
                }
                else
                {
                    // not refrigerated
                    sb.Append("NotRefrigerated".Translate(ticksUntilStartRot.ToStringTicksToPeriod()) + ".");
                }
            }

            return(sb.ToString());
        }
        private void Tick(int interval)
        {
            if (!this.Active)
            {
                return;
            }
            float rotProgress = this.RotProgress;
            float num         = GenTemperature.RotRateAtTemperature(this.parent.AmbientTemperature);

            this.RotProgress += num * (float)interval;
            if (this.Stage == RotStage.Rotting && this.PropsRot.rotDestroys)
            {
                //The first main change from the rotting code is here
                //If the item reaches it's rotting time, a new item with the same stackCount is spawned on its location, and this item is destroyed

                //The map check is done... just in case

                if (this.parent.Map != null)
                {
                    int      stackCount  = this.parent.stackCount;
                    ThingDef newThingDef = ThingDef.Named(PropsRot.thingToTransformTo);
                    Thing    newThing    = GenSpawn.Spawn(newThingDef, this.parent.Position, this.parent.Map, WipeMode.Vanish);
                    newThing.stackCount = stackCount;
                    this.parent.Destroy(DestroyMode.Vanish);
                }
                else
                {
                    this.parent.Destroy(DestroyMode.Vanish);
                }



                return;
            }
            if (Mathf.FloorToInt(rotProgress / 60000f) != Mathf.FloorToInt(this.RotProgress / 60000f) && this.ShouldTakeRotDamage())
            {
                if (this.Stage == RotStage.Rotting && this.PropsRot.rotDamagePerDay > 0f)
                {
                    this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.rotDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                    return;
                }
                if (this.Stage == RotStage.Dessicated && this.PropsRot.dessicatedDamagePerDay > 0f)
                {
                    this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.dessicatedDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                }
            }
        }
Пример #19
0
        public override string CompInspectStringExtra()
        {
            if (!Active)
            {
                return(null);
            }
            StringBuilder stringBuilder = new StringBuilder();

            switch (Stage)
            {
            case RotStage.Fresh:
                stringBuilder.Append("RotStateFresh".Translate() + ".");
                break;

            case RotStage.Rotting:
                stringBuilder.Append("RotStateRotting".Translate() + ".");
                break;

            case RotStage.Dessicated:
                stringBuilder.Append("RotStateDessicated".Translate() + ".");
                break;
            }
            float num = (float)PropsRot.TicksToRotStart - RotProgress;

            if (num > 0f)
            {
                float ambientTemperature = parent.AmbientTemperature;
                ambientTemperature = (float)Mathf.RoundToInt(ambientTemperature);
                float num2 = GenTemperature.RotRateAtTemperature(ambientTemperature);
                int   ticksUntilRotAtCurrentTemp = TicksUntilRotAtCurrentTemp;
                stringBuilder.AppendLine();
                if (num2 < 0.001f)
                {
                    stringBuilder.Append("CurrentlyFrozen".Translate() + ".");
                }
                else if (num2 < 0.999f)
                {
                    stringBuilder.Append("CurrentlyRefrigerated".Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriod()) + ".");
                }
                else
                {
                    stringBuilder.Append("NotRefrigerated".Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriod()) + ".");
                }
            }
            return(stringBuilder.ToString());
        }
Пример #20
0
        // Token: 0x06000038 RID: 56 RVA: 0x00003884 File Offset: 0x00001A84
        private static void Ticky(CompRottable CR, int interval)
        {
            if (!CR.Active)
            {
                return;
            }

            interval = (int)(interval / 2f);
            var rotProgress = CR.RotProgress;
            var num         = GenTemperature.RotRateAtTemperature(CR.parent.AmbientTemperature);

            CR.RotProgress += num * interval;
            if (CR.Stage == RotStage.Rotting && CR.PropsRot.rotDestroys)
            {
                if (CR.parent.IsInAnyStorage() && CR.parent.SpawnedOrAnyParentSpawned)
                {
                    Messages.Message(
                        "MessageRottedAwayInStorage".Translate(CR.parent.Label, CR.parent).CapitalizeFirst(),
                        new TargetInfo(CR.parent.PositionHeld, CR.parent.MapHeld), MessageTypeDefOf.NegativeEvent);
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
                }

                CR.parent.Destroy();
                return;
            }

            if (Mathf.FloorToInt(rotProgress / 60000f) == Mathf.FloorToInt(CR.RotProgress / 60000f) ||
                !ShouldTakeRotDamage(CR))
            {
                return;
            }

            if (CR.Stage == RotStage.Rotting && CR.PropsRot.rotDamagePerDay > 0f)
            {
                CR.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                    GenMath.RoundRandom(CR.PropsRot.rotDamagePerDay)));
                return;
            }

            if (CR.Stage == RotStage.Dessicated && CR.PropsRot.dessicatedDamagePerDay > 0f)
            {
                CR.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                    GenMath.RoundRandom(CR.PropsRot.dessicatedDamagePerDay)));
            }
        }
Пример #21
0
        private void Tick(int interval)
        {
            if (!Active)
            {
                return;
            }

            float previousProgress = RotProgress;

            // Do rotting progress according to temperature
            float cellTemp = parent.AmbientTemperature;
            float rotRate  = GenTemperature.RotRateAtTemperature(cellTemp);

            RotProgress += rotRate * interval;

            //Destroy if needed
            //Should this be in StageChanged?
            if (Stage == RotStage.Rotting && PropsRot.rotDestroys)
            {
                if (parent.IsInAnyStorage() && parent.SpawnedOrAnyParentSpawned)
                {
                    Messages.Message("MessageRottedAwayInStorage".Translate(parent.Label, parent).CapitalizeFirst(), new TargetInfo(parent.PositionHeld, parent.MapHeld), MessageTypeDefOf.NegativeEvent);
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
                }

                parent.Destroy();
                return;
            }

            //Once per day...
            bool isNewDay = Mathf.FloorToInt(previousProgress / GenDate.TicksPerDay) != Mathf.FloorToInt(RotProgress / GenDate.TicksPerDay);

            if (isNewDay && ShouldTakeRotDamage())
            {
                if (Stage == RotStage.Rotting && PropsRot.rotDamagePerDay > 0)
                {
                    parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(PropsRot.rotDamagePerDay)));
                }
                else if (Stage == RotStage.Dessicated && PropsRot.dessicatedDamagePerDay > 0)
                {
                    parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(PropsRot.dessicatedDamagePerDay)));
                }
            }
        }
Пример #22
0
        internal static void                _CompTickRare(this CompRottable obj)
        {
            if (obj.InRefrigerator())
            {
                return;
            }
            float num = obj.rotProgress;

            obj.rotProgress += (float)Mathf.RoundToInt(1f * GenTemperature.RotRateAtTemperature(GenTemperature.GetTemperatureForCell(obj.parent.PositionHeld)) * 250f);
            if (
                (obj.Stage == RotStage.Rotting) &&
                (obj.PropsRot().rotDestroys)
                )
            {
                obj.parent.Destroy(DestroyMode.Vanish);
            }
            else
            {
                if (Mathf.FloorToInt(num / 60000f) == Mathf.FloorToInt(obj.rotProgress / 60000f))
                {
                    return;
                }
                if (
                    (obj.Stage == RotStage.Rotting) &&
                    (obj.PropsRot().rotDamagePerDay > 0.0f)
                    )
                {
                    obj.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(obj.PropsRot().rotDamagePerDay), (Thing)null, new BodyPartDamageInfo?(), (ThingDef)null));
                }
                else
                {
                    if (
                        (obj.Stage != RotStage.Dessicated) ||
                        (obj.PropsRot().dessicatedDamagePerDay <= 0.0f) ||
                        (!obj.ShouldTakeDessicateDamage())
                        )
                    {
                        return;
                    }
                    obj.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, GenMath.RoundRandom(obj.PropsRot().dessicatedDamagePerDay), (Thing)null, new BodyPartDamageInfo?(), (ThingDef)null));
                }
            }
        }
Пример #23
0
        private void Tick(int interval)
        {
            if (!this.Active)
            {
                return;
            }
            float rotProgress = this.RotProgress;
            float num         = GenTemperature.RotRateAtTemperature(this.parent.AmbientTemperature);

            this.RotProgress += num * (float)interval;
            if (this.Stage == RotStage.Rotting && this.PropsRot.rotDestroys)
            {
                if (this.parent.Map != null)
                {
                    int      stackCount  = this.parent.stackCount;
                    ThingDef newThingDef = ThingDef.Named("VCE_RawPrunes");
                    Thing    newThing    = GenSpawn.Spawn(newThingDef, this.parent.Position, this.parent.Map, WipeMode.Vanish);
                    newThing.stackCount = stackCount;
                    this.parent.Destroy(DestroyMode.Vanish);
                }
                else
                {
                    this.parent.Destroy(DestroyMode.Vanish);
                }



                return;
            }
            if (Mathf.FloorToInt(rotProgress / 60000f) != Mathf.FloorToInt(this.RotProgress / 60000f) && this.ShouldTakeRotDamage())
            {
                if (this.Stage == RotStage.Rotting && this.PropsRot.rotDamagePerDay > 0f)
                {
                    this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.rotDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                    return;
                }
                if (this.Stage == RotStage.Dessicated && this.PropsRot.dessicatedDamagePerDay > 0f)
                {
                    this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.dessicatedDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                }
            }
        }
        public int TicksUntilRotAtTemp(float temp)
        {
            if (!this.Active)
            {
                return(72000000);
            }
            float num = GenTemperature.RotRateAtTemperature(temp);

            if (num <= 0f)
            {
                return(72000000);
            }
            float num2 = (float)this.PropsRot.TicksToRotStart - this.RotProgress;

            if (num2 <= 0f)
            {
                return(0);
            }
            return(Mathf.RoundToInt(num2 / num));
        }
Пример #25
0
        internal static string              _CompInspectStringExtra(this CompRottable obj)
        {
            var stringBuilder = new StringBuilder();

            switch (obj.Stage)
            {
            case RotStage.Fresh:
                stringBuilder.AppendLine("RotStateFresh".Translate());
                break;

            case RotStage.Rotting:
                stringBuilder.AppendLine("RotStateRotting".Translate());
                break;

            case RotStage.Dessicated:
                stringBuilder.AppendLine("RotStateDessicated".Translate());
                break;
            }
            if (obj.InRefrigerator())
            {
                stringBuilder.AppendLine("RefrigeratedStorage".Translate());
            }
            else if ((obj.PropsRot().TicksToRotStart - obj.rotProgress) > 0.0f)
            {
                float num = GenTemperature.RotRateAtTemperature(Mathf.RoundToInt(GenTemperature.GetTemperatureForCell(obj.parent.Position)));
                int   rotAtCurrentTemp = obj.TicksUntilRotAtCurrentTemp;
                if (num < 1.0f / 1000.0f)
                {
                    stringBuilder.AppendLine("CurrentlyFrozen".Translate());
                }
                else if (num < 0.999000012874603f)
                {
                    stringBuilder.AppendLine("CurrentlyRefrigerated".Translate(rotAtCurrentTemp.TickstoDaysString()));
                }
                else
                {
                    stringBuilder.AppendLine("NotRefrigerated".Translate(rotAtCurrentTemp.TickstoDaysString()));
                }
            }
            return(stringBuilder.ToString());
        }
Пример #26
0
        public int TicksUntilRotAtTemp(float temp)
        {
            if (!Active)
            {
                return(GenDate.TicksPerYear * 20);
            }

            float rotRate = GenTemperature.RotRateAtTemperature(temp);

            if (rotRate <= 0)
            {
                return(GenDate.TicksPerYear * 20); //Will never rot. Just return a huge value. Hacky
            }
            float progressUntilStartRot = PropsRot.TicksToRotStart - RotProgress;

            if (progressUntilStartRot <= 0)
            {
                return(0); //Already rotten
            }
            return(Mathf.RoundToInt(progressUntilStartRot / rotRate));
        }
        public override string CompInspectStringExtra()
        {
            //The other changes are made here, to display custom strings regarding how well the item is "rotting" into the new one. No default, so they NEED
            //to be defined via XML

            if (!this.Active)
            {
                return(null);
            }
            StringBuilder stringBuilder = new StringBuilder();

            switch (this.Stage)
            {
            case RotStage.Fresh:
                stringBuilder.Append(PropsRot.maturingString.Translate() + ".");
                break;
            }
            if ((float)this.PropsRot.TicksToRotStart - this.RotProgress > 0f)
            {
                float num = GenTemperature.RotRateAtTemperature((float)Mathf.RoundToInt(this.parent.AmbientTemperature));
                int   ticksUntilRotAtCurrentTemp = this.TicksUntilRotAtCurrentTemp;
                stringBuilder.AppendLine();
                if (num < 0.001f)
                {
                    stringBuilder.Append(PropsRot.maturingStopped.Translate() + ".");
                }
                else if (num < 0.999f)
                {
                    stringBuilder.Append(PropsRot.maturingSlowly.Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriod(true, false, true, true)) + ".");
                }
                else
                {
                    stringBuilder.Append(PropsRot.maturingProperly.Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriod(true, false, true, true)) + ".");
                }
            }
            return(stringBuilder.ToString());
        }
Пример #28
0
        private static bool HopperTick(int interval, CompRottable __instance)
        {
            IEnumerable <Thing> things = GetCompRottableThings(__instance);

            if (!(things is null) && things.OfType <NPDHopper_Storage>().Any())
            {
                Thing t = things.OfType <NPDHopper_Storage>().First();
                foreach (Thing thing in things)
                {
                    NPDHopper_Storage hopper = thing as NPDHopper_Storage;
                    if (!(hopper is null))
                    {
                        float rotProgress = __instance.RotProgress;
                        float hopperTemp  = t.TryGetComp <CompPowerTrader>().PowerOn ? hopper.def.GetModExtension <HopperCustom>().setTemperature : __instance.parent.AmbientTemperature;
                        float num         = GenTemperature.RotRateAtTemperature(hopperTemp);
                        __instance.RotProgress += num * (float)interval;

                        if (__instance.Stage == RotStage.Rotting && __instance.PropsRot.rotDestroys)
                        {
                            if (__instance.parent.IsInAnyStorage() && __instance.parent.SpawnedOrAnyParentSpawned)
                            {
                                Messages.Message("MessageRottedAwayInStorage".Translate(__instance.parent.Label, __instance.parent).CapitalizeFirst(),
                                                 new TargetInfo(__instance.parent.PositionHeld, __instance.parent.MapHeld, false), MessageTypeDefOf.NegativeEvent, true);
                                LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
                            }
                            __instance.parent.Destroy(DestroyMode.Vanish);
                            return(false);
                        }
                        bool flag = Mathf.FloorToInt(rotProgress / 60000f) != Mathf.FloorToInt(__instance.RotProgress / 60000f);
                        //Should Take Rot Damage?
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #29
0
        public override void CompTickRare()
        {
            if (parent.MapHeld == null || parent.Map == null)
            {
                return;
            }

            var list     = new HashSet <Thing>(parent.MapHeld.thingGrid.ThingsListAtFast(parent.PositionHeld));
            var isMeat   = parent?.def.IsMeat ?? false;
            var isSalted = parent?.def?.defName?.ToLowerInvariant().Contains("salted") ?? false;
            var saltPot  =
                list.FirstOrDefault(x => x is Building_RottableFixer && x.def.defName == "LotR_SaltBarrel");

            if (isMeat && !isSalted && saltPot != null)
            {
                HandleMeatThatNeedsSalting(parent);
                return;
            }

            var rotProgress        = RotProgress;
            var num                = 1f;
            var temperatureForCell = GenTemperature.GetTemperatureForCell(parent.PositionHeld, parent.MapHeld);
            var b = list.FirstOrDefault(x => x is Building_RottableFixer);

            if (b != null)
            {
                if (!isMeat && b.def.defName == "LotR_PantryShelf")
                {
                    num = 0.3f;
                }

                if (b.def.defName == "LotR_SaltBarrel")
                {
                    num = 0.0666667f;
                }
            }

            num         *= GenTemperature.RotRateAtTemperature(temperatureForCell);
            RotProgress += Mathf.Round(num * 250f);
            if (Stage == RotStage.Rotting && PropsRot.rotDestroys)
            {
                if (parent.Position.GetSlotGroup(parent.Map) != null)
                {
                    Messages.Message("MessageRottedAwayInStorage".Translate(parent.Label).CapitalizeFirst(),
                                     MessageTypeDefOf.SilentInput);
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers,
                                                         OpportunityType.GoodToKnow);
                }

                parent.Destroy();
                return;
            }

            if (Mathf.FloorToInt(rotProgress / 60000f) == Mathf.FloorToInt(RotProgress / 60000f))
            {
                return;
            }

            if (Stage == RotStage.Rotting && PropsRot.rotDamagePerDay > 0f)
            {
                parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                 GenMath.RoundRandom(PropsRot.rotDamagePerDay)));
            }
            else if (Stage == RotStage.Dessicated && PropsRot.dessicatedDamagePerDay > 0f &&
                     ShouldTakeDessicateDamage())
            {
                parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                 GenMath.RoundRandom(PropsRot.dessicatedDamagePerDay)));
            }
        }
Пример #30
0
        public override string CompInspectStringExtra()
        {
            StringBuilder sb = new StringBuilder();

            switch (base.Stage)
            {
            case RotStage.Fresh:
                sb.AppendLine("RotStateFresh".Translate());
                break;

            case RotStage.Rotting:
                sb.AppendLine("RotStateRotting".Translate());
                break;

            case RotStage.Dessicated:
                sb.AppendLine("RotStateDessicated".Translate());
                break;
            }
            float num = (float)this.PropsRot.TicksToRotStart - base.RotProgress;

            if (num > 0f)
            {
                float        num2      = GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, this.parent.Map);
                List <Thing> thingList = GridsUtility.GetThingList(this.parent.PositionHeld, this.parent.Map);
                var          factor    = 1f;
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] is Building_RottableFixer)
                    {
                        var b      = thingList[i] as Building_RottableFixer;
                        var isMeat = this?.parent?.def.IsMeat ?? false;
                        if (!isMeat && b.def.defName == "LotR_PantryShelf")
                        {
                            factor = 3f;
                        }
                        if (b.def.defName == "LotR_SaltBarrel")
                        {
                            factor = 15f;
                        }
                        //num2 = building_Refrigerator.CurrentTemp;
                        break;
                    }
                }
                num2 = (float)Mathf.RoundToInt(num2);
                float num3 = GenTemperature.RotRateAtTemperature(num2);
                int   ticksUntilRotAtCurrentTemp = (int)(base.TicksUntilRotAtCurrentTemp * factor);
                if (num3 < 0.001f)
                {
                    sb.Append("CurrentlyFrozen".Translate() + ".");
                }
                else
                {
                    if (num3 < 0.999f)
                    {
                        sb.Append("CurrentlyRefrigerated".Translate(new object[]
                        {
                            ticksUntilRotAtCurrentTemp.ToStringTicksToPeriodVague()
                        }) + ".");
                    }
                    else
                    {
                        sb.Append("NotRefrigerated".Translate(new object[]
                        {
                            ticksUntilRotAtCurrentTemp.ToStringTicksToPeriodVague()
                        }) + ".");
                    }
                }
            }
            return(sb.ToString().TrimEndNewlines());
        }