Example #1
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);
        }
Example #2
0
        public static IEnumerable <Thing> TraverseBody(RecipeInfo recipeInfo, Corpse corpse, float skillChance)
        {
            BodyPartRecord        core  = corpse.InnerPawn.RaceProps.body.corePart;
            List <BodyPartRecord> queue = new List <BodyPartRecord> {
                core
            };
            HediffSet             hediffSet    = corpse.InnerPawn.health.hediffSet;
            List <Thing>          results      = new List <Thing>();
            List <BodyPartRecord> damagedParts = new List <BodyPartRecord>();

            while (queue.Count > 0)
            {
                BodyPartRecord part = queue.First();
                queue.Remove(part);
                //Drop parts and bionics that are higher on the body tree.
                if (TryGetParts(corpse, recipeInfo, part, skillChance, ref results, ref damagedParts) && core != part)
                {
                    continue;
                }
                queue.AddRange(part.parts.Where(x => !hediffSet.PartIsMissing(x)));
            }

            if (results.Count > recipeInfo.PartNumber)
            {
                Random random = new Random();
                return(results.OrderBy(i => random.Next()).Take(recipeInfo.PartNumber));
            }

            foreach (BodyPartRecord part in damagedParts)
            {
                DamageHarvested(corpse.InnerPawn, part);
            }

            return(results);
        }
Example #3
0
        private void DoPawnsFrostDamage(Map map)
        {
            List <Pawn> allPawnsSpawned = map.mapPawns.AllPawnsSpawned;

            for (int i = 0; i < allPawnsSpawned.Count; i++)
            {
                Pawn pawn = allPawnsSpawned[i];
                if (CanDamage(pawn, map))
                {
                    float num = 0.028758334f;
                    num *= pawn.GetStatValue(StatDefOf.ToxicSensitivity, true);
                    if (num != 0f)
                    {
                        float num2 = Mathf.Lerp(0.85f, 1.15f, Rand.ValueSeeded(pawn.thingIDNumber ^ 74374237));
                        num *= num2;
                        BodyPartRecord bodyPartRecord;
                        HediffSet      hediffSet = pawn.health.hediffSet;
                        if ((from x in pawn.RaceProps.body.AllPartsVulnerableToFrostbite
                             where !hediffSet.PartIsMissing(x)
                             select x).TryRandomElementByWeight((BodyPartRecord x) => x.def.frostbiteVulnerability, out bodyPartRecord))
                        {
                            int            num5      = Mathf.CeilToInt((float)bodyPartRecord.def.hitPoints * 0.5f);
                            DamageDef      frostbite = DamageDefOf.Cut;
                            float          amount    = (float)num5;
                            BodyPartRecord hitPart   = bodyPartRecord;
                            DamageInfo     dinfo     = new DamageInfo(frostbite, amount, 0f, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null);
                            pawn.TakeDamage(dinfo);
                        }
                    }
                }
            }
        }
 public static bool OnIntervalPassedPrefix(Pawn pawn, Hediff cause)
 {
     if (pawn.RaceProps.FleshType == XenomorphRacesDefOf.RRY_Xenomorph)
     {
         float      ambientTemperature = pawn.AmbientTemperature;
         FloatRange floatRange         = pawn.ComfortableTemperatureRange();
         FloatRange floatRange2        = pawn.SafeTemperatureRange();
         HediffSet  hediffSet          = pawn.health.hediffSet;
         HediffDef  hediffDef          = XenomorphDefOf.HypothermicSlowdown;
         Hediff     firstHediffOfDef   = hediffSet.GetFirstHediffOfDef(hediffDef, false);
         if (ambientTemperature < floatRange2.min)
         {
             float num  = Mathf.Abs(ambientTemperature - floatRange2.min);
             float num2 = num * 6.45E-05f;
             num2 = Mathf.Max(num2, 0.00075f);
             HealthUtility.AdjustSeverity(pawn, hediffDef, num2);
             if (pawn.Dead)
             {
                 return(true);
             }
         }
         if (firstHediffOfDef != null)
         {
             if (ambientTemperature > floatRange.min)
             {
                 float num3 = firstHediffOfDef.Severity * 0.027f;
                 num3 = Mathf.Clamp(num3, 0.0015f, 0.015f);
                 firstHediffOfDef.Severity -= num3;
             }
             else if (pawn.RaceProps.FleshType != XenomorphRacesDefOf.RRY_Xenomorph && ambientTemperature < 0f && firstHediffOfDef.Severity > 0.37f)
             {
                 float num4 = 0.025f * firstHediffOfDef.Severity;
                 if (Rand.Value < num4)
                 {
                     BodyPartRecord bodyPartRecord;
                     if ((from x in pawn.RaceProps.body.AllPartsVulnerableToFrostbite
                          where !hediffSet.PartIsMissing(x)
                          select x).TryRandomElementByWeight((BodyPartRecord x) => x.def.frostbiteVulnerability, out bodyPartRecord))
                     {
                         int            num5      = Mathf.CeilToInt((float)bodyPartRecord.def.hitPoints * 0.5f);
                         DamageDef      frostbite = DamageDefOf.Frostbite;
                         float          amount    = (float)num5;
                         BodyPartRecord hitPart   = bodyPartRecord;
                         DamageInfo     dinfo     = new DamageInfo(frostbite, amount, 0f, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null);
                         pawn.TakeDamage(dinfo);
                     }
                 }
             }
         }
         return(false);
     }
     else
     {
         return(true);
     }
 }
Example #5
0
        public static IEnumerable <BodyPartRecord> GetNotMissingParts(this HediffSet set, BodyPartHeight height = BodyPartHeight.Undefined, BodyPartDepth depth = BodyPartDepth.Undefined, List <BodyPartTagDef> tags = null, BodyPartRecord partParent = null)
        {
            List <BodyPartRecord> allPartsList = set.pawn.def.race.body.AllParts;
            int num;

            for (int i = 0; i < allPartsList.Count; i = num + 1)
            {
                BodyPartRecord bodyPartRecord = allPartsList[i];
                if (!set.PartIsMissing(bodyPartRecord) && (height == BodyPartHeight.Undefined || bodyPartRecord.height == height) && (depth == BodyPartDepth.Undefined || bodyPartRecord.depth == depth) && (tags == null || bodyPartRecord.def.tags.Any(x => tags.Contains(x))) && (partParent == null || bodyPartRecord.parent == partParent))
                {
                    yield return(bodyPartRecord);
                }
                num = i;
            }
            yield break;
        }
        public static IEnumerable <Thing> TraverseBody(RecipeInfo recipeInfo, Corpse corpse, float skillChance)
        {
            BodyPartRecord        core  = corpse.InnerPawn.RaceProps.body.corePart;
            List <BodyPartRecord> queue = new List <BodyPartRecord> {
                core
            };
            HediffSet    hediffSet = corpse.InnerPawn.health.hediffSet;
            List <Thing> results   = new List <Thing>();

            while (queue.Count > 0)
            {
                BodyPartRecord part = queue.First();
                queue.Remove(part);
                //Drop parts and bionics that are higher onthe body tree.
                if (TryGetParts(corpse, recipeInfo, part, skillChance, ref results) && core != part)
                {
                    continue;
                }
                queue.AddRange(part.parts.Where(x => !hediffSet.PartIsMissing(x)));
            }
            return(results);
        }
        private bool HasBionic(Corpse corpse)
        {
            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))
                {
                    return(true);
                }
                queue.AddRange(part.parts.Where(x => !hediffSet.PartIsMissing(x)));
            }

            return(false);
        }
Example #8
0
        public static int GiveHediffToRandomColinists(Map map, List <Pawn> pawnList, HediffDef hediff, int minNumber, int maxAfterCountNumber = 1)
        {
            int num = Rand.Range(minNumber, pawnList.Count - maxAfterCountNumber);

            for (int i = 0; i < num; i++)
            {
                Pawn                  pawn = pawnList.RandomElement();
                HediffSet             set  = pawn.health.hediffSet;
                BodyPartRecord        part;
                List <BodyPartRecord> allParts = (from x in pawn.RaceProps.body.AllParts where !set.PartIsMissing(x) select x).ToList();
                if (allParts.TryRandomElement(out part))
                {
                    pawn.health.AddHediff(hediff, part);
                }
            }

            return(num);
        }
        public static bool OnIntervalPassed(HediffGiver_Hypothermia __instance, Pawn pawn, Hediff cause)
        {
            float ambientTemperature = pawn.AmbientTemperature;
            //FloatRange floatRange = pawn.ComfortableTemperatureRange(); //REMOVED
            //FloatRange floatRange2 = pawn.SafeTemperatureRange(); //REMOVED
            float     comfortableTemperatureMin = pawn.GetStatValue(StatDefOf.ComfyTemperatureMin); //ADDED
            float     minTemp          = comfortableTemperatureMin - 10f;                           //ADDED
            HediffSet hediffSet        = pawn.health.hediffSet;
            HediffDef hediffDef        = pawn.RaceProps.FleshType == FleshTypeDefOf.Insectoid ? __instance.hediffInsectoid : __instance.hediff;
            Hediff    firstHediffOfDef = hediffSet.GetFirstHediffOfDef(hediffDef);

            //if (ambientTemperature < floatRange2.min) //REMOVED
            if (ambientTemperature < minTemp)             //ADDED
            {
                //float a = Mathf.Abs(ambientTemperature - floatRange2.min) * 6.45E-05f; //REMOVED
                float a = Mathf.Abs(ambientTemperature - minTemp) * 6.45E-05f;                 //ADDED
                a = Mathf.Max(a, 0.00075f);
                HealthUtility.AdjustSeverity(pawn, hediffDef, a);
                if (pawn.Dead)
                {
                    return(false);
                }
            }
            if (firstHediffOfDef == null)
            {
                return(false);
            }
            //if (ambientTemperature > floatRange.min) //REMOVED
            if (ambientTemperature > comfortableTemperatureMin)             //ADDED
            {
                float value = firstHediffOfDef.Severity * 0.027f;
                value = Mathf.Clamp(value, 0.0015f, 0.015f);
                firstHediffOfDef.Severity -= value;
            }
            else if (pawn.RaceProps.FleshType != FleshTypeDefOf.Insectoid && ambientTemperature < 0f && firstHediffOfDef.Severity > 0.37f)
            {
                float num = 0.025f * firstHediffOfDef.Severity;
                if (Rand.Value < num && pawn.RaceProps.body.AllPartsVulnerableToFrostbite.Where(x => !hediffSet.PartIsMissing(x)).TryRandomElementByWeight(x => x.def.frostbiteVulnerability, out BodyPartRecord result))
                {
                    int        num2  = Mathf.CeilToInt(result.def.hitPoints * 0.5f);
                    DamageInfo dinfo = new DamageInfo(DamageDefOf.Frostbite, num2, 0f, -1f, null, result);
                    pawn.TakeDamage(dinfo);
                }
            }
            return(false);
        }
Example #10
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            float percentSeverity = parent.Severity / parent.def.lethalSeverity;

            if (percentSeverity >= 0.98f && !parent.FullyImmune())
            {
                BodyPartRecord part = parent.Part;
                Pawn.TakeDamage(new DamageInfo(DamageDefOf.Frostbite, 100, 0, -1, null, part));

                HediffSet             set      = Pawn.health.hediffSet;
                List <BodyPartRecord> allParts = (from x in Pawn.RaceProps.body.AllParts where !set.PartIsMissing(x) select x).ToList();
                if (allParts.TryRandomElement(out part))
                {
                    Pawn.health.AddHediff(HediffDefOfLocal.Fibrodysplasia, part);
                }
            }
        }
Example #11
0
        public static bool CalculatePartEfficiency(ref float __result, HediffSet diffSet, BodyPartRecord part, bool ignoreAddedParts = false, List <CapacityImpactor> impactors = null)
        {
            BodyPartRecord rec;

            for (rec = part.parent; rec != null; rec = rec.parent)
            {
                if (diffSet.HasDirectlyAddedPartFor(rec))
                {
                    Hediff_AddedPart hediff_AddedPart = (from x in diffSet.GetHediffs <Hediff_AddedPart>()
                                                         where x.Part == rec
                                                         select x).First();
                    impactors?.Add(new CapacityImpactorHediff
                    {
                        hediff = hediff_AddedPart
                    });
                    __result = hediff_AddedPart.def.addedPartProps.partEfficiency;
                    return(false);
                }
            }

            if (part.parent != null && diffSet.PartIsMissing(part.parent))
            {
                __result = 0f;
                return(false);
            }

            float num = 1f;

            if (!ignoreAddedParts)
            {
                for (int i = 0; i < diffSet.hediffs.Count; i++)
                {
                    Hediff_AddedPart hediff_AddedPart2 = diffSet.hediffs[i] as Hediff_AddedPart;
                    if (hediff_AddedPart2 != null && hediff_AddedPart2.Part == part)
                    {
                        num *= hediff_AddedPart2.def.addedPartProps.partEfficiency;
                        if (hediff_AddedPart2.def.addedPartProps.partEfficiency != 1f)
                        {
                            impactors?.Add(new CapacityImpactorHediff
                            {
                                hediff = hediff_AddedPart2
                            });
                        }
                    }
                }
            }

            float b    = -1f;
            float num2 = 0f;
            bool  flag = false;

            for (int j = 0; j < diffSet.hediffs.Count; j++)
            {
                Hediff hediff1 = diffSet.hediffs[j];
                if (hediff1 != null && hediff1.Part == part && hediff1.CurStage != null)
                {
                    HediffStage curStage = hediff1.CurStage;
                    num2 += curStage.partEfficiencyOffset;
                    flag |= curStage.partIgnoreMissingHP;
                    if (curStage.partEfficiencyOffset != 0f && curStage.becomeVisible)
                    {
                        impactors?.Add(new CapacityImpactorHediff
                        {
                            hediff = hediff1
                        });
                    }
                }
            }

            if (!flag)
            {
                float num3 = diffSet.GetPartHealth(part) / part.def.GetMaxHealth(diffSet.pawn);
                if (num3 != 1f)
                {
                    if (DamageWorker_AddInjury.ShouldReduceDamageToPreservePart(part))
                    {
                        num3 = Mathf.InverseLerp(0.1f, 1f, num3);
                    }

                    impactors?.Add(new CapacityImpactorBodyPartHealth
                    {
                        bodyPart = part
                    });
                    num *= num3;
                }
            }

            num += num2;
            if (num > 0.0001f)
            {
                num = Mathf.Max(num, b);
            }

            __result = Mathf.Max(num, 0f);
            return(false);
        }
        public static bool OnIntervalPassed(HediffGiver_Hypothermia __instance, Pawn pawn, Hediff cause)
        {
            float     ambientTemperature        = pawn.AmbientTemperature;
            float     comfortableTemperatureMin = pawn.GetStatValue(StatDefOf.ComfyTemperatureMin, true);
            float     minTemp          = comfortableTemperatureMin - 10f;
            HediffSet hediffSet        = pawn.health.hediffSet;
            HediffDef hediffDef        = pawn.RaceProps.FleshType == FleshTypeDefOf.Insectoid ? __instance.hediffInsectoid : __instance.hediff;
            Hediff    firstHediffOfDef = hediffSet.GetFirstHediffOfDef(hediffDef, false);

            if (ambientTemperature < minTemp)
            {
                float sevOffset = Mathf.Max(Mathf.Abs(ambientTemperature - minTemp) * 6.45E-05f, 0.00075f);
                HealthUtility.AdjustSeverity(pawn, hediffDef, sevOffset);
                if (pawn.Dead)
                {
                    return(false);
                }
            }
            if (firstHediffOfDef == null)
            {
                return(false);
            }
            if (ambientTemperature > comfortableTemperatureMin)
            {
                float num = Mathf.Clamp(firstHediffOfDef.Severity * 0.027f, 0.0015f, 0.015f);
                firstHediffOfDef.Severity -= num;
            }
            else
            {
                BodyPartRecord result;
                if (pawn.RaceProps.FleshType == FleshTypeDefOf.Insectoid || (double)ambientTemperature >= 0.0 || ((double)firstHediffOfDef.Severity <= 0.370000004768372 || (double)Rand.Value >= (double)(0.025f * firstHediffOfDef.Severity)) || !pawn.RaceProps.body.AllPartsVulnerableToFrostbite.Where <BodyPartRecord>((Func <BodyPartRecord, bool>)(x => !hediffSet.PartIsMissing(x))).TryRandomElementByWeight <BodyPartRecord>((Func <BodyPartRecord, float>)(x => x.def.frostbiteVulnerability), out result))
                {
                    return(false);
                }
                int        num   = Mathf.CeilToInt(result.def.hitPoints * 0.5f);
                DamageInfo dinfo = new DamageInfo(DamageDefOf.Frostbite, (float)num, 0.0f, -1f, (Verse.Thing)null, result, (ThingDef)null, DamageInfo.SourceCategory.ThingOrUnknown, (Verse.Thing)null);
                pawn.TakeDamage(dinfo);
            }
            return(false);
        }