Exemple #1
0
        /// <summary>
        /// Applies the dark adaptation hediff to cutebolds as they spawn if they don't have it.
        /// </summary>
        /// <param name="__instance">The pawn</param>
        /// <param name="map">The map they are located on. (unused)</param>
        /// <param name="respawningAfterLoad">If the pawn is spawning after a reload.</param>
        private static void CuteboldAdaptationSpawnSetupPostfix(Pawn __instance, Map map, bool respawningAfterLoad)
        {
            if (__instance.Dead || __instance?.def.defName != Cutebold_Assemblies.RaceName || __instance.kindDef == null)
            {
                return;
            }

            if (__instance.health.hediffSet.GetFirstHediffOfDef(Cutebold_DefOf.CuteboldDarkAdaptation) == null)
            {
                Hediff_CuteboldDarkAdaptation hediff = (Hediff_CuteboldDarkAdaptation)HediffMaker.MakeHediff(Cutebold_DefOf.CuteboldDarkAdaptation, __instance);
                float minSeverity = 0f;
                float maxSeverity = 0.1f;
                bool  goggles     = false;

                foreach (Apparel apparel in __instance.apparel.WornApparel)
                {
                    if (apparel.def == Cutebold_DefOf.Cutebold_Goggles)
                    {
                        goggles = true;
                    }
                }

                if (!(__instance.story.traits.HasTrait(TraitDef.Named("Wimp")) && __instance.health.hediffSet.PainTotal > 0.0f) && __instance.health.hediffSet.PainTotal <= 0.5f && !respawningAfterLoad)
                {
                    if (__instance.story.childhood != null && Cutebold_Patch_Names.CuteboldUndergroundChildBackstories.Contains(__instance.story.childhood))
                    {
                        minSeverity += 0.05f;
                        maxSeverity += 0.15f;
                    }

                    if (__instance.story.adulthood != null && Cutebold_Patch_Names.CuteboldUndergroundAdultBackstories.Contains(__instance.story.childhood))
                    {
                        minSeverity += 0.20f;
                        maxSeverity += 0.30f;
                    }

                    if (__instance.story.traits.HasTrait(TraitDefOf.Undergrounder))
                    {
                        minSeverity += 0.10f;
                        maxSeverity += 0.20f;
                    }

                    if (__instance.story.traits.HasTrait(TraitDef.Named("Wimp")) && !goggles)
                    {
                        minSeverity = minSeverity > 0.5f ? 0.5f : minSeverity;
                        maxSeverity = maxSeverity > 0.7f ? 0.7f : maxSeverity;
                    }
                    else if (goggles)
                    {
                        minSeverity = minSeverity * 3f + 0.3f;
                        maxSeverity = maxSeverity * 3f + 0.4f;
                    }
                }

                hediff.Severity = new FloatRange(minSeverity, maxSeverity).RandomInRange;

                __instance.health.AddHediff(hediff);
            }

            Hediff_CuteboldDarkAdaptation darkAdaptation = (Hediff_CuteboldDarkAdaptation)__instance.health.hediffSet.GetFirstHediffOfDef(Cutebold_DefOf.CuteboldDarkAdaptation);

            darkAdaptation.UpdateGoggles();
            darkAdaptation.UpdateEyes();
        }