Example #1
0
        public static bool TryGetParts(Corpse corpse, RecipeInfo recipeInfo, BodyPartRecord part, float skillChance,
                                       ref List <Thing> result, ref List <BodyPartRecord> damagedParts)
        {
            if (IsCleanAndDroppable(corpse.InnerPawn, part))
            {
                damagedParts.Add(part);
                CompRottable rot = corpse.TryGetComp <CompRottable>();
                if (rot == null
                    ? corpse.Age <= recipeInfo.CorpseValidAge
                    : rot.RotProgress + (corpse.Age - rot.RotProgress) * recipeInfo.FrozenDecay <=
                    recipeInfo.CorpseValidAge)
                {
                    if (Rand.Chance(Math.Min(skillChance, recipeInfo.NaturalChance)))
                    {
                        result.Add(ThingMaker.MakeThing(part.def.spawnThingOnRemoved));
                    }
                    return(true);
                }
            }

            List <Hediff> bion = corpse.InnerPawn.health.hediffSet.hediffs.Where(x =>
                                                                                 part.Equals(x.Part) && x.def.spawnThingOnRemoved != null &&
                                                                                 (x is Hediff_Implant || x is Hediff_AddedPart)).ToList();

            if (bion.Count > 0)
            {
                result.AddRange(bion.Where(x => Rand.Chance(Math.Min(skillChance, recipeInfo.BionicChance)))
                                .Select(x => ThingMaker.MakeThing(x.def.spawnThingOnRemoved)));
                damagedParts.Add(part);
                return(true);
            }

            return(false);
        }
Example #2
0
        private void RefrigerateContents()
        {
            // Only refrigerate if it has power
            // Don't worry about idle power though
            if (compPower.PowerOn == false)
            {
                // Clear it out
                if (contents.Count > 0)
                {
                    contents = new List <RefrigeratorContents>();
                }
                // Now leave
                return;
            }

            // Look for things
            ScanForRottables();

            // Refrigerate the items
            foreach (RefrigeratorContents item in contents)
            {
                CompRottable compRottable = item.thing.TryGetComp <CompRottable>();
                item.thing.HitPoints     = item.HitPoints;
                compRottable.rotProgress = item.rotProgress;
            }
        }
Example #3
0
        public static void IsAllowed_Postfix(ThingFilter __instance, ref bool __result, Thing t)
        {
            if (!__result)
            {
                return;
            }

            MyWorldComponent world = Find.World.GetComponent <MyWorldComponent>();
            CompRottable     rot   = t.TryGetComp <CompRottable>();

            if (rot != null && world.ShowSpoilTime(__instance))
            {
                IntRange spoilTickRange = SpoilTimeCalc.convertToTicks(world.getSpoilTime(__instance));
                int      spoilTicks     = rot.TicksUntilRotAtTemp(25.0f);

                if (spoilTickRange.min == -1 || spoilTicks < spoilTickRange.min)
                {
                    __result = false;
                }
                else if (spoilTickRange.max != -1 && spoilTicks > spoilTickRange.max)
                {
                    __result = false;
                }
            }
        }
Example #4
0
        private void AgeCorpse(Thing thing)
        {
            CompRottable compRot = thing.TryGetComp <CompRottable>();

            if (compRot != null)
            {
                if (compRot.RotProgress <= (5000 + (5000 * pwrVal)))
                {
                    Corpse corpse = thing as Corpse;
                    if (corpse != null && verVal >= 3)
                    {
                        TransmutateEffects(corpse.Position, 10);
                        Pawn innerPawn = corpse.InnerPawn;
                        ResurrectionUtility.ResurrectWithSideEffects(innerPawn);
                        AgePawn(innerPawn, Mathf.RoundToInt((6 * 2500) * (1 + (.1f * verVal))), false);
                        HealthUtility.AdjustSeverity(innerPawn, HediffDef.Named("TM_ResurrectionHD"), 1f);
                        HealthUtility.AdjustSeverity(this.CasterPawn, HediffDef.Named("TM_ResurrectionHD"), 1f);
                    }
                }
                else
                {
                    compRot.RotProgress = compRot.RotProgress * (.4f - (.125f * pwrVal));
                    if (compRot.RotProgress <= 20000)
                    {
                        compRot.RotProgress = 20001;
                    }
                }
            }
        }
Example #5
0
        private void DrawDaysUntilRot(Rect rect, TransferableOneWay trad)
        {
            if (!trad.HasAnyThing)
            {
                return;
            }
            if (!trad.ThingDef.IsNutritionGivingIngestible)
            {
                return;
            }
            if (!cachedTicksUntilRot.TryGetValue(trad, out int num))
            {
                num = int.MaxValue;
                for (int i = 0; i < trad.things.Count; i++)
                {
                    CompRottable compRottable = trad.things[i].TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        num = Mathf.Min(num, DaysUntilRotCalculator.ApproxTicksUntilRot_AssumeTimePassesBy(compRottable, tile, null));
                    }
                }
                cachedTicksUntilRot.Add(trad, num);
            }
            if (num >= 36000000 || num >= 36000000f)
            {
                return;
            }
            Widgets.DrawHighlightIfMouseover(rect);
            float num2 = num / 60000f;

            GUI.color = Color.yellow;
            Widgets.Label(rect, num2.ToString("0.#"));
            GUI.color = Color.white;
            TooltipHandler.TipRegionByKey(rect, "DaysUntilRotTip");
        }
Example #6
0
        public static void Postfix(Pawn __instance, DamageInfo?dinfo, Hediff exactCulprit)
        {
            if (dinfo.HasValue)
            {
                if (dinfo.Value.Instigator != null)
                {
                    Thing         inst      = dinfo.Value.Instigator;
                    DessicatorExt desicator = inst.def.GetModExtension <DessicatorExt>();
                    if (desicator != null)
                    {
                        if (desicator.desicatedDef != null)
                        {
                            FieldInfo corpse = typeof(Pawn).GetField("Corpse", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
                            Traverse.Create(__instance);
                            corpse.SetValue(__instance, ThingMaker.MakeThing(desicator.desicatedDef));
                        }
                        else
                        {
                            CompRottable compRottable = __instance.Corpse.TryGetComp <CompRottable>();
                            compRottable.RotImmediately();
                        }
                    }
                }
            }
            HediffDef def = DefDatabase <HediffDef> .GetNamed("RT_HuskTouch");

            if (__instance.health.hediffSet.HasHediff(def))
            {
                //    Log.Message("husktouch present");
                CompRottable compRottable = __instance.Corpse.TryGetComp <CompRottable>();
                compRottable.RotImmediately();
            }
        }
 public static float ApproxDaysUntilRot(List <ThingCount> potentiallyFood, int tile, WorldPath path = null, float nextTileCostLeft = 0f, int caravanTicksPerMove = 3300)
 {
     DaysUntilRotCalculator.tmpTicksToArrive.Clear();
     if (path != null && path.Found)
     {
         CaravanArrivalTimeEstimator.EstimatedTicksToArriveToEvery(tile, path.LastNode, path, nextTileCostLeft, caravanTicksPerMove, Find.TickManager.TicksAbs, DaysUntilRotCalculator.tmpTicksToArrive);
     }
     DaysUntilRotCalculator.tmpNutritions.Clear();
     for (int i = 0; i < potentiallyFood.Count; i++)
     {
         ThingCount thingCount = potentiallyFood[i];
         if (thingCount.Count > 0 && thingCount.Thing.def.IsNutritionGivingIngestible)
         {
             CompRottable compRottable = thingCount.Thing.TryGetComp <CompRottable>();
             float        first;
             if (compRottable != null && compRottable.Active)
             {
                 first = (float)DaysUntilRotCalculator.ApproxTicksUntilRot_AssumeTimePassesBy(compRottable, tile, DaysUntilRotCalculator.tmpTicksToArrive) / 60000f;
             }
             else
             {
                 first = 600f;
             }
             float second = thingCount.Thing.GetStatValue(StatDefOf.Nutrition, true) * (float)thingCount.Count;
             DaysUntilRotCalculator.tmpNutritions.Add(new Pair <float, float>(first, second));
         }
     }
     return(GenMath.WeightedMedian(DaysUntilRotCalculator.tmpNutritions, 600f, 0.5f));
 }
        public override void TickRare()
        {
            base.TickRare();
            if (innerContainer.Count >= 5)
            {
                tickCounter++;
                if (tickCounter > digestionPeriod)
                {
                    foreach (Thing thing in innerContainer)
                    {
                        Pawn pawnSwallowed = thing as Pawn;
                        if (pawnSwallowed != null)
                        {
                            if (!pawnSwallowed.Dead)
                            {
                                pawnSwallowed.Kill(null);
                            }
                            CompRottable compRottable = pawnSwallowed.Corpse.TryGetComp <CompRottable>();


                            if (compRottable != null && compRottable.Stage == RotStage.Fresh)
                            {
                                compRottable.RotProgress += 100000000;
                            }
                        }
                    }
                    EjectContents();
                    tickCounter = 0;
                }
            }
        }
Example #9
0
 public override void DoCellSteadyEffects(IntVec3 c, Map map)
 {
     if (!c.Roofed(map))
     {
         List <Thing> thingList = c.GetThingList(map);
         for (int i = 0; i < thingList.Count; i++)
         {
             Thing thing = thingList[i];
             if (thing is Plant && thing.def.defName != PurpleIvyDefOf.PurpleIvy.defName)
             {
                 if (Rand.Value < 0.0065f)
                 {
                     thing.Kill(null, null);
                 }
             }
             else if (thing.def.category == ThingCategory.Item)
             {
                 CompRottable compRottable = thing.TryGetComp <CompRottable>();
                 if (compRottable != null && compRottable.Stage < RotStage.Dessicated)
                 {
                     compRottable.RotProgress += 3000f;
                 }
             }
         }
     }
 }
        public static void Postfix(ref string __result, CompRottable __instance)
        {
            if (!ThermodynamicsSettings.warmersSlowRot)
            {
                return;
            }

            ThingWithComps rotter = __instance.parent;
            Map            map    = rotter.Map;

            if (map != null)
            {
                List <Thing> thingList = map.thingGrid.ThingsListAt(rotter.PositionHeld);
                if (thingList != null)
                {
                    foreach (Thing thing in thingList)
                    {
                        if (thing is Building_HeatedStorage bhs && bhs.IsActive())
                        {
                            __result = __result.Replace("Not refrigerated", "Warmed");
                            break;
                        }
                    }
                }
            }
        }
Example #11
0
        private bool CanHarvest(Corpse corpse)
        {
            int maxage = Mathf.Max(Mod.BasicAutopsyCorpseAge.Value, Mod.AdvancedAutopsyCorpseAge.Value,
                                   Mod.GlitterAutopsyCorpseAge.Value);
            float decay = Mathf.Min(Mod.BasicAutopsyFrozenDecay.Value, Mod.AdvancedAutopsyFrozenDecay.Value,
                                    Mod.GlitterAutopsyFrozenDecay.Value);
            CompRottable rot       = corpse.TryGetComp <CompRottable>();
            bool         notRotten = rot == null
                ? corpse.Age <= maxage * 2500
                : rot.RotProgress + (corpse.Age - rot.RotProgress) * decay <=
                                     maxage * 2500;

            Pawn                  pawn  = corpse.InnerPawn;
            BodyPartRecord        core  = pawn.RaceProps.body.corePart;
            List <BodyPartRecord> queue = new List <BodyPartRecord> {
                core
            };
            HediffSet hediffSet = pawn.health.hediffSet;

            while (queue.Count > 0)
            {
                BodyPartRecord part = queue.First();
                queue.Remove(part);
                if (CanGetPart(pawn, part, notRotten) && core != part)
                {
                    return(true);
                }
                queue.AddRange(part.parts.Where(x => !hediffSet.PartIsMissing(x)));
            }

            return(false);
        }
        public static bool TryGetParts(Corpse corpse, RecipeInfo recipeInfo, BodyPartRecord part, float skillChance,
                                       ref List <Thing> result)
        {
            if (IsCleanAndDroppable(corpse.InnerPawn, part))
            {
                CompRottable rot = corpse.TryGetComp <CompRottable>();
                if ((rot == null
                        ? corpse.Age <= recipeInfo.CorpseValidAge
                        : rot.RotProgress <= recipeInfo.CorpseValidAge) &&
                    Rand.Chance(Math.Min(skillChance, recipeInfo.NaturalChance)))
                {
                    result.Add(ThingMaker.MakeThing(part.def.spawnThingOnRemoved));
                }
                return(true);
            }

            if (corpse.InnerPawn.health.hediffSet.hediffs.Any(x =>
                                                              x.Part == part && x.def.spawnThingOnRemoved != null &&
                                                              (x is Hediff_Implant || x is Hediff_AddedPart)))
            {
                result.AddRange(from hediff in corpse.InnerPawn.health.hediffSet.hediffs
                                where hediff.Part == part && hediff.def.spawnThingOnRemoved != null &&
                                (hediff is Hediff_Implant || hediff is Hediff_AddedPart) &&
                                Rand.Chance(Math.Min(skillChance, recipeInfo.BionicChance))
                                select ThingMaker.MakeThing(hediff.def.spawnThingOnRemoved));
                return(true);
            }

            return(false);
        }
Example #13
0
        private void AgeCorpse(Thing thing)
        {
            CompRottable compRot = thing.TryGetComp <CompRottable>();

            if (compRot != null)
            {
                if (compRot.RotProgress <= (5000 + (5000 * pwrVal)))
                {
                    Corpse corpse = thing as Corpse;
                    if (corpse != null && verVal >= 3)
                    {
                        TransmutateEffects(corpse.Position, 10);
                        Pawn innerPawn = corpse.InnerPawn;
                        ResurrectionUtility.ResurrectWithSideEffects(innerPawn);
                        AgePawn(innerPawn, Mathf.RoundToInt(6 * 2500 * (1 + (.1f * verVal))), false);
                        HealthUtility.AdjustSeverity(innerPawn, TorannMagicDefOf.TM_DeathReversalHD, 1f);
                        Projectile_Resurrection.ApplyHealthDefects(innerPawn, .25f, .3f);
                        Projectile_Resurrection.ReduceSkillsOfPawn(innerPawn, Rand.Range(.30f, .40f));
                        HealthUtility.AdjustSeverity(this.CasterPawn, TorannMagicDefOf.TM_DeathReversalHD, Rand.Range(.4f, .6f));
                        //Projectile_Resurrection.ApplyHealthDefects(this.CasterPawn, .15f, .2f);
                        Projectile_Resurrection.ReduceSkillsOfPawn(this.CasterPawn, Rand.Range(.15f, .25f));
                    }
                }
                else
                {
                    compRot.RotProgress = compRot.RotProgress * (.4f - (.125f * pwrVal));
                    if (compRot.RotProgress <= 20000)
                    {
                        compRot.RotProgress = 20001;
                    }
                }
            }
        }
        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;
                    }
                }
            }
        }
        public void                         ScanForRottables()
        {
            // Check for things removed
            for (int i = 0; i < contents.Count; ++i)
            {
                var item = contents[i];
                if ((item.thing == null) &&
                    (item.thingID != null))
                {
                    //Log.Message( "thingID.resolve:  '" + item.thingID + "'" );
                    item.thing = Find.ListerThings.AllThings.Find(t => t.ThingID == item.thingID);
                    //Log.Message( "thing.resolved:   '" + item.thing + "'" );
                }

                if ((item.thing.Destroyed) ||
                    (item.thing.StoringBuilding() != Building_Storage))
                {
                    // Modifing list, continue scan
                    contents.Remove(item);
                    continue;
                }
            }
            // Add new things
            foreach (Thing t in Building_Storage.slotGroup.HeldThings)
            {
                CompRottable compRottable = t.TryGetComp <CompRottable>();
                if ((compRottable != null) &&
                    (contents.Find(item => item.thing == t) == null))
                {
                    contents.Add(new RefrigeratorContents(t, compRottable));
                }
            }
        }
Example #16
0
        public static void CheckIfPawnShouldUnloadInventory(Pawn pawn, bool forced = false)
        {
            Job job = JobMaker.MakeJob(PickUpAndHaulJobDefOf.UnloadYourHauledInventory, pawn);
            CompHauledToInventory itemsTakenToInventory = pawn.TryGetComp <CompHauledToInventory>();

            if (itemsTakenToInventory == null)
            {
                return;
            }

            HashSet <Thing> carriedThing = itemsTakenToInventory.GetHashSet();

            if (pawn.Faction != Faction.OfPlayer || !pawn.RaceProps.Humanlike)
            {
                return;
            }
            if (carriedThing == null || carriedThing.Count == 0 || pawn.inventory.innerContainer.Count == 0)
            {
                return;
            }

            if (forced)
            {
                if (job.TryMakePreToilReservations(pawn, false))
                {
                    pawn.jobs.jobQueue.EnqueueFirst(job, JobTag.Misc);
                    return;
                }
            }

            if (MassUtility.EncumbrancePercent(pawn) >= 0.90f || carriedThing.Count >= 1)
            {
                if (job.TryMakePreToilReservations(pawn, false))
                {
                    pawn.jobs.jobQueue.EnqueueFirst(job, JobTag.Misc);
                    return;
                }
            }

            if (pawn.inventory.innerContainer?.Count >= 1)
            {
                foreach (Thing rottable in pawn.inventory.innerContainer)
                {
                    CompRottable compRottable = rottable.TryGetComp <CompRottable>();

                    if (compRottable?.TicksUntilRotAtCurrentTemp < 30000)
                    {
                        pawn.jobs.jobQueue.EnqueueFirst(job, JobTag.Misc);
                        return;
                    }
                }
            }

            if (Find.TickManager.TicksGame % 50 == 0 && pawn.inventory.innerContainer.Count < carriedThing.Count)
            {
                Verse.Log.Warning("[PickUpAndHaul] " + pawn + " inventory was found out of sync with haul index. Pawn will drop their inventory.");
                carriedThing.Clear();
                pawn.inventory.UnloadEverything = true;
            }
        }
Example #17
0
        public static bool Prefix(ref float temp, CompRottable __instance)
        {
            if (!ThermodynamicsSettings.warmersSlowRot)
            {
                return(true);
            }

            ThingWithComps rotter = __instance.parent;
            Map            map    = rotter.Map;

            if (map != null)
            {
                List <Thing> thingList = map.thingGrid.ThingsListAt(rotter.PositionHeld);
                if (thingList != null)
                {
                    foreach (Thing thing in thingList)
                    {
                        if (thing is Building_HeatedStorage bhs && bhs.IsActive())
                        {
                            temp = 1f;
                            break;
                        }
                    }
                }
            }
            return(true);
        }
        internal static CompRefrigerated    CompRefrigerated(this CompRottable obj)
        {
            IntVec3 checkPos = IntVec3.Invalid;

            if (obj.parent.holder != null)
            {
                checkPos = obj.parent.PositionHeld;
            }
            else
            {
                checkPos = obj.parent.Position;
            }
            if (
                (checkPos == IntVec3.Invalid) ||
                (!checkPos.InBounds())
                )
            {
                return(null);
            }
            var refrigerator = checkPos.GetThingList().FirstOrDefault(t => (
                                                                          (t.TryGetComp <CompRefrigerated>() != null)
                                                                          ));

            return(refrigerator?.TryGetComp <CompRefrigerated>());
        }
Example #19
0
 static void Postfix(CompRottable __instance)
 {
     if (Multiplayer.Client == null)
     {
         return;
     }
     Multiplayer.WorldComp.DirtyColonyTradeForMap(__instance.parent.Map);
 }
 internal static bool                ShouldTakeDessicateDamage(this CompRottable obj)
 {
     if (_ShouldTakeDessicateDamage == null)
     {
         _ShouldTakeDessicateDamage = typeof(CompRottable).GetMethod("ShouldTakeDessicateDamage", BindingFlags.Instance | BindingFlags.NonPublic);
     }
     return((bool)_ShouldTakeDessicateDamage.Invoke(obj, null));
 }
        public static void MakeColony(params ColonyMakerFlag[] flags)
        {
            bool godMode = DebugSettings.godMode;

            DebugSettings.godMode            = true;
            Thing.allowDestroyNonDestroyable = true;
            if (FixedColonyAnimalsDebug.usedCells == null)
            {
                FixedColonyAnimalsDebug.usedCells = new BoolGrid(FixedColonyAnimalsDebug.Map);
            }
            else
            {
                FixedColonyAnimalsDebug.usedCells.ClearAndResizeTo(FixedColonyAnimalsDebug.Map);
            }
            FixedColonyAnimalsDebug.overRect = new CellRect(FixedColonyAnimalsDebug.Map.Center.x - 50, FixedColonyAnimalsDebug.Map.Center.z - 50, 100, 100);
            FixedColonyAnimalsDebug.DeleteAllSpawnedPawns();
            GenDebug.ClearArea(FixedColonyAnimalsDebug.overRect, Find.CurrentMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef pawnKindDef in from k in DefDatabase <PawnKindDef> .AllDefs
                         where k.RaceProps.Animal && k != InternalDefOf.GR_FleshFlies
                         select k)
                {
                    CellRect cellRect;
                    if (!FixedColonyAnimalsDebug.TryGetFreeRect(6, 3, out cellRect))
                    {
                        return;
                    }
                    cellRect = cellRect.ContractedBy(1);
                    foreach (IntVec3 c in cellRect)
                    {
                        FixedColonyAnimalsDebug.Map.terrainGrid.SetTerrain(c, TerrainDefOf.Concrete);
                    }
                    GenSpawn.Spawn(PawnGenerator.GeneratePawn(pawnKindDef, null), cellRect.Cells.ElementAt(0), FixedColonyAnimalsDebug.Map, WipeMode.Vanish);
                    IntVec3 intVec   = cellRect.Cells.ElementAt(1);
                    Pawn    deadpawn = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(pawnKindDef, null), intVec, FixedColonyAnimalsDebug.Map, WipeMode.Vanish);
                    deadpawn.Kill(null);
                    CompRottable compRottable = ((Corpse)intVec.GetThingList(Find.CurrentMap).First((Thing t) => t is Corpse)).TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        compRottable.RotProgress += 1200000f;
                    }
                    if (pawnKindDef.RaceProps.leatherDef != null)
                    {
                        GenSpawn.Spawn(pawnKindDef.RaceProps.leatherDef, cellRect.Cells.ElementAt(2), FixedColonyAnimalsDebug.Map, WipeMode.Vanish);
                    }
                    if (pawnKindDef.RaceProps.meatDef != null)
                    {
                        GenSpawn.Spawn(pawnKindDef.RaceProps.meatDef, cellRect.Cells.ElementAt(3), FixedColonyAnimalsDebug.Map, WipeMode.Vanish);
                    }
                }
            }

            FixedColonyAnimalsDebug.ClearAllHomeArea();
            FixedColonyAnimalsDebug.FillWithHomeArea(FixedColonyAnimalsDebug.overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
Example #22
0
        private void AgeFood(Thing thing)
        {
            CompRottable compRot = thing.TryGetComp <CompRottable>();

            if (compRot != null)
            {
                compRot.RotProgress = compRot.RotProgress * (.4f - (.125f * pwrVal));
            }
        }
        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);
        }
        public override void TickRare()
        {
            if (this.CurrentTemp < -2000f)
            {
                this.CurrentTemp = GridsUtility.GetTemperature(base.Position, base.Map);
            }
            foreach (IntVec3 cell in this.AllSlotCells())
            {
                foreach (Thing thing in GridsUtility.GetThingList(cell, base.Map))
                {
                    CompRottable rottable = ThingCompUtility.TryGetComp <CompRottable>(thing);
                    if (rottable != null && !(rottable is CompBetterRottable))
                    {
                        ThingWithComps     thingWithComps     = thing as ThingWithComps;
                        CompBetterRottable compBetterRottable = new CompBetterRottable();
                        thingWithComps.AllComps.Remove(rottable);
                        thingWithComps.AllComps.Add(compBetterRottable);
                        compBetterRottable.props       = rottable.props;
                        compBetterRottable.parent      = thingWithComps;
                        compBetterRottable.RotProgress = rottable.RotProgress;
                    }

                    if (ThingCompUtility.TryGetComp <CompFrosty>(thing) == null && thing.def.defName == "Beer")
                    {
                        ThingWithComps thingWithComps = thing as ThingWithComps;
                        CompFrosty     compFrosty     = new CompFrosty();
                        thingWithComps.AllComps.Add(compFrosty);
                        compFrosty.props  = CompProperties_Frosty.Beer;
                        compFrosty.parent = thingWithComps;
                        ((TickList)typeof(TickManager).GetField("tickListRare", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Find.TickManager)).RegisterThing(thingWithComps);
                    }
                }
            }

            float roomTemperature   = GridsUtility.GetTemperature(base.Position, base.Map);
            float changetemperature = (roomTemperature - this.CurrentTemp) * 0.01f;
            float changeEnergy      = -changetemperature;
            float powerMultiplier   = 0f;

            if (this.CurrentTemp + changetemperature > this.DesiredTemp)
            {
                float change = Mathf.Max(this.DesiredTemp - (this.CurrentTemp + changetemperature), -1f);
                if (this.powerComp != null && this.powerComp.PowerOn)
                {
                    changetemperature += change;
                    changeEnergy      -= change * 1.25f;
                }
                powerMultiplier = change * -1f;
            }
            this.CurrentTemp += changetemperature;
            IntVec3 pos = base.Position + IntVec3.North.RotatedBy(base.Rotation);

            GenTemperature.PushHeat(pos, base.Map, changeEnergy * 1.25f);
            this.powerComp.PowerOutput = -((CompProperties_Power)this.powerComp.props).basePowerConsumption * (powerMultiplier * 0.9f + 0.1f);
        }
        public static bool Prefix(ref CompRottable __instance)
        {
            if (!__instance.parent.Spawned ||
                __instance.parent.Position.GetFirstThingWithComp <CompRottable>(__instance.parent.Map) == null)
            {
                return(true);
            }

            Ticky(__instance, 250);
            return(false);
        }
Example #26
0
 public static void Postfix(CompRottable __instance, RotStage __result)
 {
     if (__result == RotStage.Dessicated && __instance.parent is Corpse corpse &&
         (corpse.InnerPawn?.health?.hediffSet?.HasHediff(AlteredCarbonDefOf.AC_CorticalStack) ?? true))
     {
         var corticalStack = ThingMaker.MakeThing(AlteredCarbonDefOf.AC_FilledCorticalStack) as CorticalStack;
         corticalStack.SavePawnToCorticalStack(corpse.InnerPawn);
         GenPlace.TryPlaceThing(corticalStack, corpse.Position, corpse.Map, ThingPlaceMode.Near);
         corpse.InnerPawn.health.hediffSet.hediffs.RemoveAll(x => x.def == AlteredCarbonDefOf.AC_CorticalStack);
     }
 }
Example #27
0
 private static void Rot1Day()
 {
     foreach (Thing item in Find.CurrentMap.thingGrid.ThingsAt(UI.MouseCell()))
     {
         CompRottable compRottable = item.TryGetComp <CompRottable>();
         if (compRottable != null)
         {
             compRottable.RotProgress += 60000f;
         }
     }
 }
Example #28
0
        public override bool Matches(Thing t)
        {
            ThingWithComps thingWithComps = t as ThingWithComps;

            if (thingWithComps == null)
            {
                return(false);
            }
            CompRottable comp = thingWithComps.GetComp <CompRottable>();

            return(comp != null && !((CompProperties_Rottable)comp.props).rotDestroys && comp.Stage == RotStage.Fresh);
        }
Example #29
0
        public static float GetRotDays(Thing t)
        {
            float        result          = 99999f;
            CompRottable compRottable    = t.TryGetComp <CompRottable>();
            bool         hasRottableComp = compRottable != null;

            if (hasRottableComp)
            {
                result = compRottable.TicksUntilRotAtCurrentTemp.TicksToDays();
            }
            return(result);
        }
Example #30
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 RefrigeratorContents( Thing t, CompRottable compRottable )
 {
     thing = t;
     HitPoints = t.HitPoints;
     rotProgress = compRottable.rotProgress;
 }