Beispiel #1
0
 public static bool TryApply(Pawn pawn, HediffDef hediff, List <BodyPartDef> partsToAffect, bool canAffectAnyLivePart = false, int countToAffect = 1, List <Hediff> outAddedHediffs = null)
 {
     if (canAffectAnyLivePart || partsToAffect != null)
     {
         bool result = false;
         for (int i = 0; i < countToAffect; i++)
         {
             IEnumerable <BodyPartRecord> source = pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null);
             if (partsToAffect != null)
             {
                 source = from p in source
                          where partsToAffect.Contains(p.def)
                          select p;
             }
             if (canAffectAnyLivePart)
             {
                 source = from p in source
                          where p.def.alive
                          select p;
             }
             source = from p in source
                      where !pawn.health.hediffSet.HasHediff(hediff, p, false) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(p)
                      select p;
             if (!source.Any <BodyPartRecord>())
             {
                 break;
             }
             BodyPartRecord partRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs);
             Hediff         hediff2    = HediffMaker.MakeHediff(hediff, pawn, partRecord);
             pawn.health.AddHediff(hediff2, null, null, null);
             if (outAddedHediffs != null)
             {
                 outAddedHediffs.Add(hediff2);
             }
             result = true;
         }
         return(result);
     }
     if (!pawn.health.hediffSet.HasHediff(hediff, false))
     {
         Hediff hediff3 = HediffMaker.MakeHediff(hediff, pawn, null);
         pawn.health.AddHediff(hediff3, null, null, null);
         if (outAddedHediffs != null)
         {
             outAddedHediffs.Add(hediff3);
         }
         return(true);
     }
     return(false);
 }
 public override void PostAdd(DamageInfo?dinfo)
 {
     if (Current.ProgramState != ProgramState.Playing || PawnGenerator.IsBeingGenerated(this.pawn))
     {
         this.IsFresh = false;
     }
     this.pawn.health.RestorePart(base.Part, this, false);
     for (int i = 0; i < base.Part.parts.Count; i++)
     {
         Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(this.def, this.pawn, null);
         hediff_MissingPart.IsFresh    = false;
         hediff_MissingPart.lastInjury = this.lastInjury;
         hediff_MissingPart.Part       = base.Part.parts[i];
         this.pawn.health.hediffSet.AddDirect(hediff_MissingPart, null, null);
     }
 }
Beispiel #3
0
 public override void Tick()
 {
     base.Tick();
     if (CurStageIndex >= 3 && pawn.IsHashIntervalTick(300) && HangoverSusceptible(pawn))
     {
         Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Hangover);
         if (firstHediffOfDef != null)
         {
             firstHediffOfDef.Severity = 1f;
             return;
         }
         firstHediffOfDef          = HediffMaker.MakeHediff(HediffDefOf.Hangover, pawn);
         firstHediffOfDef.Severity = 1f;
         pawn.health.AddHediff(firstHediffOfDef);
     }
 }
Beispiel #4
0
 public static void AdjustSeverity(Pawn pawn, HediffDef hdDef, float sevOffset)
 {
     if (sevOffset != 0f)
     {
         Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(hdDef);
         if (firstHediffOfDef != null)
         {
             firstHediffOfDef.Severity += sevOffset;
         }
         else if (sevOffset > 0f)
         {
             firstHediffOfDef          = HediffMaker.MakeHediff(hdDef, pawn);
             firstHediffOfDef.Severity = sevOffset;
             pawn.health.AddHediff(firstHediffOfDef);
         }
     }
 }
 public void PostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
 {
     if (ShouldBeDead())
     {
         if (!pawn.Destroyed)
         {
             pawn.Kill(dinfo);
         }
         return;
     }
     if (dinfo.Def.additionalHediffs != null)
     {
         List <DamageDefAdditionalHediff> additionalHediffs = dinfo.Def.additionalHediffs;
         for (int i = 0; i < additionalHediffs.Count; i++)
         {
             DamageDefAdditionalHediff damageDefAdditionalHediff = additionalHediffs[i];
             if (damageDefAdditionalHediff.hediff == null)
             {
                 continue;
             }
             float num = ((damageDefAdditionalHediff.severityFixed <= 0f) ? (totalDamageDealt * damageDefAdditionalHediff.severityPerDamageDealt) : damageDefAdditionalHediff.severityFixed);
             if (damageDefAdditionalHediff.victimSeverityScalingByInvBodySize)
             {
                 num *= 1f / pawn.BodySize;
             }
             if (damageDefAdditionalHediff.victimSeverityScaling != null)
             {
                 num *= pawn.GetStatValue(damageDefAdditionalHediff.victimSeverityScaling);
             }
             if (num >= 0f)
             {
                 Hediff hediff = HediffMaker.MakeHediff(damageDefAdditionalHediff.hediff, pawn);
                 hediff.Severity = num;
                 AddHediff(hediff, null, dinfo);
                 if (Dead)
                 {
                     return;
                 }
             }
         }
     }
     for (int j = 0; j < hediffSet.hediffs.Count; j++)
     {
         hediffSet.hediffs[j].Notify_PawnPostApplyDamage(dinfo, totalDamageDealt);
     }
 }
Beispiel #6
0
 public override void PostAdd(DamageInfo?dinfo)
 {
     base.PostAdd(dinfo);
     if (Current.ProgramState != ProgramState.Playing || PawnGenerator.IsBeingGenerated(pawn))
     {
         IsFresh = false;
     }
     pawn.health.RestorePart(base.Part, this, checkStateChange: false);
     for (int i = 0; i < base.Part.parts.Count; i++)
     {
         Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(def, pawn);
         hediff_MissingPart.IsFresh    = false;
         hediff_MissingPart.lastInjury = lastInjury;
         hediff_MissingPart.Part       = base.Part.parts[i];
         pawn.health.hediffSet.AddDirect(hediff_MissingPart);
     }
 }
Beispiel #7
0
 public override void PostAdd(DamageInfo?dinfo)
 {
     if (base.Part == null)
     {
         Log.Error("Part is null. It should be set before PostAdd for " + this.def + ".", false);
         return;
     }
     this.pawn.health.RestorePart(base.Part, this, false);
     for (int i = 0; i < base.Part.parts.Count; i++)
     {
         Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, this.pawn, null);
         hediff_MissingPart.IsFresh    = true;
         hediff_MissingPart.lastInjury = HediffDefOf.SurgicalCut;
         hediff_MissingPart.Part       = base.Part.parts[i];
         this.pawn.health.hediffSet.AddDirect(hediff_MissingPart, null, null);
     }
 }
 public override void Tick()
 {
     base.Tick();
     if (this.CurStageIndex >= 3 && this.pawn.IsHashIntervalTick(300) && this.HangoverSusceptible(this.pawn))
     {
         Hediff hediff = this.pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Hangover, false);
         if (hediff != null)
         {
             hediff.Severity = 1f;
         }
         else
         {
             hediff          = HediffMaker.MakeHediff(HediffDefOf.Hangover, this.pawn, null);
             hediff.Severity = 1f;
             this.pawn.health.AddHediff(hediff, null, null, null);
         }
     }
 }
Beispiel #9
0
        protected override void IngestedCalculateAmounts(Pawn ingester, float nutritionWanted, out int numTaken, out float nutritionIngested)
        {
            BodyPartRecord bodyPartRecord = this.GetBestBodyPartToEat(ingester, nutritionWanted);

            if (bodyPartRecord == null)
            {
                Log.Error(string.Concat(new object[]
                {
                    ingester,
                    " ate ",
                    this,
                    " but no body part was found. Replacing with core part."
                }));
                bodyPartRecord = this.InnerPawn.RaceProps.body.corePart;
            }
            float bodyPartNutrition = FoodUtility.GetBodyPartNutrition(this.InnerPawn, bodyPartRecord);

            if (bodyPartRecord == this.InnerPawn.RaceProps.body.corePart)
            {
                if (PawnUtility.ShouldSendNotificationAbout(this.InnerPawn) && this.InnerPawn.RaceProps.Humanlike)
                {
                    Messages.Message("MessageEatenByPredator".Translate(new object[]
                    {
                        this.InnerPawn.LabelShort,
                        ingester.LabelIndefinite()
                    }).CapitalizeFirst(), ingester, MessageTypeDefOf.NegativeEvent);
                }
                numTaken = 1;
            }
            else
            {
                Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, this.InnerPawn, bodyPartRecord);
                hediff_MissingPart.lastInjury = HediffDefOf.Bite;
                hediff_MissingPart.IsFresh    = true;
                this.InnerPawn.health.AddHediff(hediff_MissingPart, null, null);
                numTaken = 0;
            }
            if (ingester.RaceProps.Humanlike && Rand.Value < 0.05f)
            {
                FoodUtility.AddFoodPoisoningHediff(ingester, this);
            }
            nutritionIngested = bodyPartNutrition;
        }
Beispiel #10
0
        public static void AdjustSeverity(Pawn pawn, HediffDef hdDef, float sevOffset)
        {
            if (sevOffset == 0f)
            {
                return;
            }
            Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(hdDef, false);

            if (hediff != null)
            {
                hediff.Severity += sevOffset;
            }
            else if (sevOffset > 0f)
            {
                hediff          = HediffMaker.MakeHediff(hdDef, pawn, null);
                hediff.Severity = sevOffset;
                pawn.health.AddHediff(hediff, null, null, null);
            }
        }
Beispiel #11
0
        protected float FinalizeAndAddInjury(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageWorker.DamageResult result)
        {
            float result2;

            if (pawn.health.hediffSet.PartIsMissing(dinfo.HitPart))
            {
                result2 = 0f;
            }
            else
            {
                HediffDef     hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, dinfo.HitPart);
                Hediff_Injury hediff_Injury       = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null);
                hediff_Injury.Part   = dinfo.HitPart;
                hediff_Injury.source = dinfo.Weapon;
                hediff_Injury.sourceBodyPartGroup = dinfo.WeaponBodyPartGroup;
                hediff_Injury.sourceHediffDef     = dinfo.WeaponLinkedHediff;
                hediff_Injury.Severity            = totalDamage;
                if (dinfo.InstantPermanentInjury)
                {
                    HediffComp_GetsPermanent hediffComp_GetsPermanent = hediff_Injury.TryGetComp <HediffComp_GetsPermanent>();
                    if (hediffComp_GetsPermanent != null)
                    {
                        hediffComp_GetsPermanent.IsPermanent = true;
                    }
                    else
                    {
                        Log.Error(string.Concat(new object[]
                        {
                            "Tried to create instant permanent injury on Hediff without a GetsPermanent comp: ",
                            hediffDefFromDamage,
                            " on ",
                            pawn
                        }), false);
                    }
                }
                result2 = this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, result);
            }
            return(result2);
        }
Beispiel #12
0
 public void PostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
 {
     if (this.ShouldBeDead())
     {
         if (!this.pawn.Destroyed)
         {
             this.pawn.Kill(new DamageInfo?(dinfo), null);
         }
     }
     else
     {
         if (dinfo.Def.additionalHediffs != null)
         {
             List <DamageDefAdditionalHediff> additionalHediffs = dinfo.Def.additionalHediffs;
             for (int i = 0; i < additionalHediffs.Count; i++)
             {
                 DamageDefAdditionalHediff damageDefAdditionalHediff = additionalHediffs[i];
                 if (damageDefAdditionalHediff.hediff != null)
                 {
                     float num = totalDamageDealt * damageDefAdditionalHediff.severityPerDamageDealt;
                     if (num >= 0f)
                     {
                         Hediff hediff = HediffMaker.MakeHediff(damageDefAdditionalHediff.hediff, this.pawn, null);
                         hediff.Severity = num;
                         this.AddHediff(hediff, null, new DamageInfo?(dinfo));
                         if (this.Dead)
                         {
                             return;
                         }
                     }
                 }
             }
         }
         if (!this.Dead)
         {
             this.pawn.mindState.mentalStateHandler.Notify_DamageTaken(dinfo);
         }
     }
 }
Beispiel #13
0
 public static bool TryApply(Pawn pawn, HediffDef hediff, IEnumerable <BodyPartDef> partsToAffect, bool canAffectAnyLivePart = false, int countToAffect = 1, List <Hediff> outAddedHediffs = null)
 {
     if (canAffectAnyLivePart || partsToAffect != null)
     {
         bool result = false;
         for (int i = 0; i < countToAffect; i++)
         {
             IEnumerable <BodyPartRecord> source = pawn.health.hediffSet.GetNotMissingParts();
             if (partsToAffect != null)
             {
                 source = source.Where((BodyPartRecord p) => partsToAffect.Contains(p.def));
             }
             if (canAffectAnyLivePart)
             {
                 source = source.Where((BodyPartRecord p) => p.def.alive);
             }
             source = source.Where((BodyPartRecord p) => !pawn.health.hediffSet.HasHediff(hediff, p) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(p));
             if (!source.Any())
             {
                 break;
             }
             BodyPartRecord partRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs);
             Hediff         hediff2    = HediffMaker.MakeHediff(hediff, pawn, partRecord);
             pawn.health.AddHediff(hediff2);
             outAddedHediffs?.Add(hediff2);
             result = true;
         }
         return(result);
     }
     if (!pawn.health.hediffSet.HasHediff(hediff))
     {
         Hediff hediff3 = HediffMaker.MakeHediff(hediff, pawn);
         pawn.health.AddHediff(hediff3);
         outAddedHediffs?.Add(hediff3);
         return(true);
     }
     return(false);
 }
Beispiel #14
0
        protected override void IngestedCalculateAmounts(Pawn ingester, float nutritionWanted, out int numTaken, out float nutritionIngested)
        {
            //Determine part to take
            var part = GetBestBodyPartToEat(ingester, nutritionWanted);

            if (part == null)
            {
                Log.Error(ingester + " ate " + this + " but no body part was found. Replacing with core part.");
                part = InnerPawn.RaceProps.body.corePart;
            }

            //Determine the nutrition to gain
            float nut = FoodUtility.GetBodyPartNutrition(this, part);

            //Affect this thing
            //If ate core part, remove the whole corpse
            //Otherwise, remove the eaten body part
            if (part == InnerPawn.RaceProps.body.corePart)
            {
                if (PawnUtility.ShouldSendNotificationAbout(InnerPawn) && InnerPawn.RaceProps.Humanlike)
                {
                    Messages.Message("MessageEatenByPredator".Translate(InnerPawn.LabelShort, ingester.Named("PREDATOR"), InnerPawn.Named("EATEN")).CapitalizeFirst(), ingester, MessageTypeDefOf.NegativeEvent);
                }

                numTaken = 1;
            }
            else
            {
                var missing = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, InnerPawn, part);
                missing.lastInjury = HediffDefOf.Bite;
                missing.IsFresh    = true;
                InnerPawn.health.AddHediff(missing);

                numTaken = 0;
            }

            nutritionIngested = nut;
        }
 public void PostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
 {
     if (this.ShouldBeDead())
     {
         if (!this.pawn.Destroyed)
         {
             this.pawn.Kill(new DamageInfo?(dinfo), null);
         }
     }
     else if (dinfo.Def.additionalHediffs != null)
     {
         List <DamageDefAdditionalHediff> additionalHediffs = dinfo.Def.additionalHediffs;
         for (int i = 0; i < additionalHediffs.Count; i++)
         {
             DamageDefAdditionalHediff damageDefAdditionalHediff = additionalHediffs[i];
             if (damageDefAdditionalHediff.hediff != null)
             {
                 float num = totalDamageDealt * damageDefAdditionalHediff.severityPerDamageDealt;
                 if (damageDefAdditionalHediff.victimSeverityScaling != null)
                 {
                     num *= this.pawn.GetStatValue(damageDefAdditionalHediff.victimSeverityScaling, true);
                 }
                 if (num >= 0f)
                 {
                     Hediff hediff = HediffMaker.MakeHediff(damageDefAdditionalHediff.hediff, this.pawn, null);
                     hediff.Severity = num;
                     this.AddHediff(hediff, null, new DamageInfo?(dinfo), null);
                     if (this.Dead)
                     {
                         break;
                     }
                 }
             }
         }
     }
 }
        private HashSet <Hediff> CalculateMissingPartHediffsFromInjury(Hediff hediff)
        {
            HashSet <Hediff> missing = null;

            if (hediff.Part != null && hediff.Part != pawn.RaceProps.body.corePart && hediff.Severity >= hediffSet.GetPartHealth(hediff.Part))
            {
                missing = new HashSet <Hediff>();
                AddAllParts(hediff.Part);
            }
            return(missing);

            void AddAllParts(BodyPartRecord part)
            {
                Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, pawn);

                hediff_MissingPart.lastInjury = hediff.def;
                hediff_MissingPart.Part       = part;
                missing.Add(hediff_MissingPart);
                foreach (BodyPartRecord part in part.parts)
                {
                    AddAllParts(part);
                }
            }
        }
Beispiel #17
0
        public static void FlavorfulCombatTest()
        {
            List <DebugMenuOption>    list      = new List <DebugMenuOption>();
            IEnumerable <ManeuverDef> maneuvers = DefDatabase <ManeuverDef> .AllDefsListForReading;

            Func <ManeuverDef, RulePackDef>[] results = new Func <ManeuverDef, RulePackDef>[5]
            {
                (ManeuverDef m) => new RulePackDef[4]
                {
                    m.combatLogRulesHit,
                    m.combatLogRulesDeflect,
                    m.combatLogRulesMiss,
                    m.combatLogRulesDodge
                }.RandomElement(),
                (ManeuverDef m) => m.combatLogRulesHit,
                (ManeuverDef m) => m.combatLogRulesDeflect,
                (ManeuverDef m) => m.combatLogRulesMiss,
                (ManeuverDef m) => m.combatLogRulesDodge
            };
            string[] array = new string[5]
            {
                "(random)",
                "Hit",
                "Deflect",
                "Miss",
                "Dodge"
            };
            foreach (Pair <ManeuverDef, int> maneuverresult in maneuvers.Concat(null).Cross(Enumerable.Range(0, array.Length)))
            {
                DebugMenuOption item = new DebugMenuOption(string.Format("{0}/{1}", (maneuverresult.First == null) ? "(random)" : maneuverresult.First.defName, array[maneuverresult.Second]), DebugMenuOptionMode.Action, delegate
                {
                    CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                    {
                        StringBuilder stringBuilder7 = new StringBuilder();
                        ManeuverDef maneuver         = default(ManeuverDef);
                        for (int num3 = 0; num3 < 100; num3++)
                        {
                            maneuver = maneuverresult.First;
                            if (maneuver == null)
                            {
                                maneuver = maneuvers.RandomElement();
                            }
                            RulePackDef rulePackDef     = results[maneuverresult.Second](maneuver);
                            List <BodyPartRecord> list8 = null;
                            List <bool> list9           = null;
                            if (rulePackDef == maneuver.combatLogRulesHit)
                            {
                                list8 = new List <BodyPartRecord>();
                                list9 = new List <bool>();
                                bodyPartCreator(list8, list9);
                            }
                            ImplementOwnerTypeDef implementOwnerTypeDef;
                            string toolLabel;
                            if (!(from ttp in DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsMeleeWeapon && !td.tools.NullOrEmpty()).SelectMany((ThingDef td) => td.tools.Select((Tool tool) => new Pair <ThingDef, Tool>(td, tool)))
                                  where ttp.Second.capacities.Contains(maneuver.requiredCapacity)
                                  select ttp).TryRandomElement(out Pair <ThingDef, Tool> result))
                            {
                                Log.Warning("Melee weapon with tool with capacity " + maneuver.requiredCapacity + " not found.");
                                implementOwnerTypeDef = ImplementOwnerTypeDefOf.Bodypart;
                                toolLabel             = "(" + implementOwnerTypeDef.defName + ")";
                            }
                            else
                            {
                                implementOwnerTypeDef = ((result.Second == null) ? ImplementOwnerTypeDefOf.Bodypart : ImplementOwnerTypeDefOf.Weapon);
                                toolLabel             = ((result.Second != null) ? result.Second.label : ("(" + implementOwnerTypeDef.defName + ")"));
                            }
                            BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = new BattleLogEntry_MeleeCombat(rulePackDef, alwaysShowInCompact: false, RandomPawnForCombat(), RandomPawnForCombat(), implementOwnerTypeDef, toolLabel, result.First);
                            battleLogEntry_MeleeCombat.FillTargets(list8, list9, battleLogEntry_MeleeCombat.RuleDef.defName.Contains("Deflect"));
                            battleLogEntry_MeleeCombat.Debug_OverrideTicks(Rand.Int);
                            stringBuilder7.AppendLine(battleLogEntry_MeleeCombat.ToGameStringFromPOV(null));
                        }
                        Log.Message(stringBuilder7.ToString());
                    });
                });
                list.Add(item);
            }
            int rf = 0;

            while (rf < 2)
            {
                list.Add(new DebugMenuOption((rf == 0) ? "Ranged fire singleshot" : "Ranged fire burst", DebugMenuOptionMode.Action, delegate
                {
                    StringBuilder stringBuilder6 = new StringBuilder();
                    for (int num2 = 0; num2 < 100; num2++)
                    {
                        ThingDef thingDef = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement();
                        bool flag         = Rand.Value < 0.2f;
                        bool flag2        = !flag && Rand.Value < 0.95f;
                        BattleLogEntry_RangedFire battleLogEntry_RangedFire = new BattleLogEntry_RangedFire(RandomPawnForCombat(), flag ? null : RandomPawnForCombat(), flag2 ? null : thingDef, null, rf != 0);
                        battleLogEntry_RangedFire.Debug_OverrideTicks(Rand.Int);
                        stringBuilder6.AppendLine(battleLogEntry_RangedFire.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder6.ToString());
                }));
                int num = ++rf;
            }
            list.Add(new DebugMenuOption("Ranged impact hit", DebugMenuOptionMode.Action, delegate
            {
                CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                {
                    StringBuilder stringBuilder5 = new StringBuilder();
                    for (int n = 0; n < 100; n++)
                    {
                        ThingDef weaponDef3         = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement();
                        List <BodyPartRecord> list6 = new List <BodyPartRecord>();
                        List <bool> list7           = new List <bool>();
                        bodyPartCreator(list6, list7);
                        Pawn pawn2 = RandomPawnForCombat();
                        BattleLogEntry_RangedImpact battleLogEntry_RangedImpact3 = new BattleLogEntry_RangedImpact(RandomPawnForCombat(), pawn2, pawn2, weaponDef3, null, ThingDefOf.Wall);
                        battleLogEntry_RangedImpact3.FillTargets(list6, list7, Rand.Chance(0.5f));
                        battleLogEntry_RangedImpact3.Debug_OverrideTicks(Rand.Int);
                        stringBuilder5.AppendLine(battleLogEntry_RangedImpact3.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder5.ToString());
                });
            }));
            list.Add(new DebugMenuOption("Ranged impact miss", DebugMenuOptionMode.Action, delegate
            {
                StringBuilder stringBuilder4 = new StringBuilder();
                for (int l = 0; l < 100; l++)
                {
                    ThingDef weaponDef2 = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement();
                    BattleLogEntry_RangedImpact battleLogEntry_RangedImpact2 = new BattleLogEntry_RangedImpact(RandomPawnForCombat(), null, RandomPawnForCombat(), weaponDef2, null, ThingDefOf.Wall);
                    battleLogEntry_RangedImpact2.Debug_OverrideTicks(Rand.Int);
                    stringBuilder4.AppendLine(battleLogEntry_RangedImpact2.ToGameStringFromPOV(null));
                }
                Log.Message(stringBuilder4.ToString());
            }));
            list.Add(new DebugMenuOption("Ranged impact hit incorrect", DebugMenuOptionMode.Action, delegate
            {
                CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                {
                    StringBuilder stringBuilder3 = new StringBuilder();
                    for (int k = 0; k < 100; k++)
                    {
                        ThingDef weaponDef          = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement();
                        List <BodyPartRecord> list4 = new List <BodyPartRecord>();
                        List <bool> list5           = new List <bool>();
                        bodyPartCreator(list4, list5);
                        BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(RandomPawnForCombat(), RandomPawnForCombat(), RandomPawnForCombat(), weaponDef, null, ThingDefOf.Wall);
                        battleLogEntry_RangedImpact.FillTargets(list4, list5, Rand.Chance(0.5f));
                        battleLogEntry_RangedImpact.Debug_OverrideTicks(Rand.Int);
                        stringBuilder3.AppendLine(battleLogEntry_RangedImpact.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder3.ToString());
                });
            }));
            foreach (RulePackDef transition in DefDatabase <RulePackDef> .AllDefsListForReading.Where((RulePackDef def) => def.defName.Contains("Transition") && !def.defName.Contains("Include")))
            {
                list.Add(new DebugMenuOption(transition.defName, DebugMenuOptionMode.Action, delegate
                {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    for (int j = 0; j < 100; j++)
                    {
                        Pawn pawn                 = RandomPawnForCombat();
                        Pawn initiator            = RandomPawnForCombat();
                        BodyPartRecord partRecord = pawn.health.hediffSet.GetNotMissingParts().RandomElement();
                        BattleLogEntry_StateTransition battleLogEntry_StateTransition = new BattleLogEntry_StateTransition(pawn, transition, initiator, HediffMaker.MakeHediff(DefDatabase <HediffDef> .AllDefsListForReading.RandomElement(), pawn, partRecord), pawn.RaceProps.body.AllParts.RandomElement());
                        battleLogEntry_StateTransition.Debug_OverrideTicks(Rand.Int);
                        stringBuilder2.AppendLine(battleLogEntry_StateTransition.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder2.ToString());
                }));
            }
            foreach (RulePackDef damageEvent in DefDatabase <RulePackDef> .AllDefsListForReading.Where((RulePackDef def) => def.defName.Contains("DamageEvent") && !def.defName.Contains("Include")))
            {
                list.Add(new DebugMenuOption(damageEvent.defName, DebugMenuOptionMode.Action, delegate
                {
                    CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int i = 0; i < 100; i++)
                        {
                            List <BodyPartRecord> list2 = new List <BodyPartRecord>();
                            List <bool> list3           = new List <bool>();
                            bodyPartCreator(list2, list3);
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(RandomPawnForCombat(), damageEvent);
                            battleLogEntry_DamageTaken.FillTargets(list2, list3, deflected: false);
                            battleLogEntry_DamageTaken.Debug_OverrideTicks(Rand.Int);
                            stringBuilder.AppendLine(battleLogEntry_DamageTaken.ToGameStringFromPOV(null));
                        }
                        Log.Message(stringBuilder.ToString());
                    });
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
Beispiel #18
0
 public void AddDirect(Hediff hediff, DamageInfo?dinfo = default(DamageInfo?), DamageWorker.DamageResult damageResult = null)
 {
     if (hediff.def == null)
     {
         Log.Error("Tried to add health diff with null def. Canceling.");
     }
     else if (hediff.Part != null && !GetNotMissingParts().Contains(hediff.Part))
     {
         Log.Error("Tried to add health diff to missing part " + hediff.Part);
     }
     else
     {
         hediff.ageTicks = 0;
         hediff.pawn     = pawn;
         bool flag = false;
         for (int i = 0; i < hediffs.Count; i++)
         {
             if (hediffs[i].TryMergeWith(hediff))
             {
                 flag = true;
             }
         }
         if (!flag)
         {
             hediffs.Add(hediff);
             hediff.PostAdd(dinfo);
             if (pawn.needs != null && pawn.needs.mood != null)
             {
                 pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
             }
         }
         bool flag2 = hediff is Hediff_MissingPart;
         if (!(hediff is Hediff_MissingPart) && hediff.Part != null && hediff.Part != pawn.RaceProps.body.corePart && GetPartHealth(hediff.Part) == 0f && hediff.Part != pawn.RaceProps.body.corePart)
         {
             bool flag3 = HasDirectlyAddedPartFor(hediff.Part);
             Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, pawn);
             hediff_MissingPart.IsFresh    = !flag3;
             hediff_MissingPart.lastInjury = hediff.def;
             pawn.health.AddHediff(hediff_MissingPart, hediff.Part, dinfo);
             damageResult?.AddHediff(hediff_MissingPart);
             if (flag3)
             {
                 if (dinfo.HasValue)
                 {
                     hediff_MissingPart.lastInjury = HealthUtility.GetHediffDefFromDamage(dinfo.Value.Def, pawn, hediff.Part);
                 }
                 else
                 {
                     hediff_MissingPart.lastInjury = null;
                 }
             }
             flag2 = true;
         }
         DirtyCache();
         if (flag2 && pawn.apparel != null)
         {
             pawn.apparel.Notify_LostBodyPart();
         }
         if (hediff.def.causesNeed != null && !pawn.Dead)
         {
             pawn.needs.AddOrRemoveNeedsAsAppropriate();
         }
     }
 }
Beispiel #19
0
 public void AddHediff(HediffDef def, BodyPartRecord part = null, DamageInfo?dinfo = null)
 {
     this.AddHediff(HediffMaker.MakeHediff(def, this.pawn, null), part, dinfo);
 }
Beispiel #20
0
        public static void FlavorfulCombatTest()
        {
            List <DebugMenuOption>    list      = new List <DebugMenuOption>();
            IEnumerable <ManeuverDef> maneuvers = DefDatabase <ManeuverDef> .AllDefsListForReading;

            Func <ManeuverDef, RulePackDef>[] results = new Func <ManeuverDef, RulePackDef>[5]
            {
                (ManeuverDef m) => new RulePackDef[4]
                {
                    m.combatLogRulesHit,
                    m.combatLogRulesDeflect,
                    m.combatLogRulesMiss,
                    m.combatLogRulesDodge
                }.RandomElement(),
                (ManeuverDef m) => m.combatLogRulesHit,
                (ManeuverDef m) => m.combatLogRulesDeflect,
                (ManeuverDef m) => m.combatLogRulesMiss,
                (ManeuverDef m) => m.combatLogRulesDodge
            };
            string[] array = new string[5]
            {
                "(random)",
                "Hit",
                "Deflect",
                "Miss",
                "Dodge"
            };
            foreach (Pair <ManeuverDef, int> item2 in maneuvers.Concat(null).Cross(Enumerable.Range(0, array.Length)))
            {
                DebugMenuOption item = new DebugMenuOption(string.Format("{0}/{1}", (item2.First != null) ? item2.First.defName : "(random)", array[item2.Second]), DebugMenuOptionMode.Action, delegate
                {
                    CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                    {
                        StringBuilder stringBuilder7 = new StringBuilder();
                        for (int num2 = 0; num2 < 100; num2++)
                        {
                            ManeuverDef maneuver = item2.First;
                            if (maneuver == null)
                            {
                                maneuver = maneuvers.RandomElement();
                            }
                            RulePackDef rulePackDef     = results[item2.Second](maneuver);
                            List <BodyPartRecord> list8 = null;
                            List <bool> list9           = null;
                            if (rulePackDef == maneuver.combatLogRulesHit)
                            {
                                list8 = new List <BodyPartRecord>();
                                list9 = new List <bool>();
                                bodyPartCreator(list8, list9);
                            }
                            Pair <ThingDef, Tool> pair = (from ttp in (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                                                       where td.IsMeleeWeapon && !td.tools.NullOrEmpty()
                                                                       select td).SelectMany((ThingDef td) => from tool in td.tools
                                                                                             select new Pair <ThingDef, Tool>(td, tool))
                                                          where ttp.Second.capacities.Contains(maneuver.requiredCapacity)
                                                          select ttp).RandomElement();
                            BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = new BattleLogEntry_MeleeCombat(rulePackDef, alwaysShowInCompact: false, CombatLogTester.GenerateRandom(), CombatLogTester.GenerateRandom(), (pair.Second == null) ? ImplementOwnerTypeDefOf.Bodypart : ImplementOwnerTypeDefOf.Weapon, (pair.Second == null) ? "body part" : pair.Second.label, pair.First);
                            battleLogEntry_MeleeCombat.FillTargets(list8, list9, battleLogEntry_MeleeCombat.RuleDef.defName.Contains("Deflect"));
                            battleLogEntry_MeleeCombat.Debug_OverrideTicks(Rand.Int);
                            stringBuilder7.AppendLine(battleLogEntry_MeleeCombat.ToGameStringFromPOV(null));
                        }
                        Log.Message(stringBuilder7.ToString());
                    });
                });
                list.Add(item);
            }
            int rf;

            for (rf = 0; rf < 2; rf++)
            {
                list.Add(new DebugMenuOption((rf != 0) ? "Ranged fire burst" : "Ranged fire singleshot", DebugMenuOptionMode.Action, delegate
                {
                    StringBuilder stringBuilder6 = new StringBuilder();
                    for (int num = 0; num < 100; num++)
                    {
                        ThingDef thingDef = (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                             where td.IsRangedWeapon
                                             select td).RandomElement();
                        bool flag  = Rand.Value < 0.2f;
                        bool flag2 = !flag && Rand.Value < 0.95f;
                        BattleLogEntry_RangedFire battleLogEntry_RangedFire = new BattleLogEntry_RangedFire(CombatLogTester.GenerateRandom(), (!flag) ? CombatLogTester.GenerateRandom() : null, (!flag2) ? thingDef : null, null, rf != 0);
                        battleLogEntry_RangedFire.Debug_OverrideTicks(Rand.Int);
                        stringBuilder6.AppendLine(battleLogEntry_RangedFire.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder6.ToString());
                }));
            }
            list.Add(new DebugMenuOption("Ranged impact hit", DebugMenuOptionMode.Action, delegate
            {
                CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                {
                    StringBuilder stringBuilder5 = new StringBuilder();
                    for (int n = 0; n < 100; n++)
                    {
                        ThingDef weaponDef3 = (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                               where td.IsRangedWeapon
                                               select td).RandomElement();
                        List <BodyPartRecord> list6 = new List <BodyPartRecord>();
                        List <bool> list7           = new List <bool>();
                        bodyPartCreator(list6, list7);
                        Pawn pawn2 = CombatLogTester.GenerateRandom();
                        BattleLogEntry_RangedImpact battleLogEntry_RangedImpact3 = new BattleLogEntry_RangedImpact(CombatLogTester.GenerateRandom(), pawn2, pawn2, weaponDef3, null, ThingDefOf.Wall);
                        battleLogEntry_RangedImpact3.FillTargets(list6, list7, Rand.Chance(0.5f));
                        battleLogEntry_RangedImpact3.Debug_OverrideTicks(Rand.Int);
                        stringBuilder5.AppendLine(battleLogEntry_RangedImpact3.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder5.ToString());
                });
            }));
            list.Add(new DebugMenuOption("Ranged impact miss", DebugMenuOptionMode.Action, delegate
            {
                StringBuilder stringBuilder4 = new StringBuilder();
                for (int l = 0; l < 100; l++)
                {
                    ThingDef weaponDef2 = (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                           where td.IsRangedWeapon
                                           select td).RandomElement();
                    BattleLogEntry_RangedImpact battleLogEntry_RangedImpact2 = new BattleLogEntry_RangedImpact(CombatLogTester.GenerateRandom(), null, CombatLogTester.GenerateRandom(), weaponDef2, null, ThingDefOf.Wall);
                    battleLogEntry_RangedImpact2.Debug_OverrideTicks(Rand.Int);
                    stringBuilder4.AppendLine(battleLogEntry_RangedImpact2.ToGameStringFromPOV(null));
                }
                Log.Message(stringBuilder4.ToString());
            }));
            list.Add(new DebugMenuOption("Ranged impact hit incorrect", DebugMenuOptionMode.Action, delegate
            {
                CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                {
                    StringBuilder stringBuilder3 = new StringBuilder();
                    for (int k = 0; k < 100; k++)
                    {
                        ThingDef weaponDef = (from td in DefDatabase <ThingDef> .AllDefsListForReading
                                              where td.IsRangedWeapon
                                              select td).RandomElement();
                        List <BodyPartRecord> list4 = new List <BodyPartRecord>();
                        List <bool> list5           = new List <bool>();
                        bodyPartCreator(list4, list5);
                        BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(CombatLogTester.GenerateRandom(), CombatLogTester.GenerateRandom(), CombatLogTester.GenerateRandom(), weaponDef, null, ThingDefOf.Wall);
                        battleLogEntry_RangedImpact.FillTargets(list4, list5, Rand.Chance(0.5f));
                        battleLogEntry_RangedImpact.Debug_OverrideTicks(Rand.Int);
                        stringBuilder3.AppendLine(battleLogEntry_RangedImpact.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder3.ToString());
                });
            }));
            foreach (RulePackDef item3 in from def in DefDatabase <RulePackDef> .AllDefsListForReading
                     where def.defName.Contains("Transition") && !def.defName.Contains("Include")
                     select def)
            {
                list.Add(new DebugMenuOption(item3.defName, DebugMenuOptionMode.Action, delegate
                {
                    StringBuilder stringBuilder2 = new StringBuilder();
                    for (int j = 0; j < 100; j++)
                    {
                        Pawn pawn                 = CombatLogTester.GenerateRandom();
                        Pawn initiator            = CombatLogTester.GenerateRandom();
                        BodyPartRecord partRecord = pawn.health.hediffSet.GetNotMissingParts().RandomElement();
                        BattleLogEntry_StateTransition battleLogEntry_StateTransition = new BattleLogEntry_StateTransition(pawn, item3, initiator, HediffMaker.MakeHediff(DefDatabase <HediffDef> .AllDefsListForReading.RandomElement(), pawn, partRecord), pawn.RaceProps.body.AllParts.RandomElement());
                        battleLogEntry_StateTransition.Debug_OverrideTicks(Rand.Int);
                        stringBuilder2.AppendLine(battleLogEntry_StateTransition.ToGameStringFromPOV(null));
                    }
                    Log.Message(stringBuilder2.ToString());
                }));
            }
            foreach (RulePackDef item4 in from def in DefDatabase <RulePackDef> .AllDefsListForReading
                     where def.defName.Contains("DamageEvent") && !def.defName.Contains("Include")
                     select def)
            {
                list.Add(new DebugMenuOption(item4.defName, DebugMenuOptionMode.Action, delegate
                {
                    CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator)
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        for (int i = 0; i < 100; i++)
                        {
                            List <BodyPartRecord> list2 = new List <BodyPartRecord>();
                            List <bool> list3           = new List <bool>();
                            bodyPartCreator(list2, list3);
                            Pawn recipient = CombatLogTester.GenerateRandom();
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(recipient, item4);
                            battleLogEntry_DamageTaken.FillTargets(list2, list3, deflected: false);
                            battleLogEntry_DamageTaken.Debug_OverrideTicks(Rand.Int);
                            stringBuilder.AppendLine(battleLogEntry_DamageTaken.ToGameStringFromPOV(null));
                        }
                        Log.Message(stringBuilder.ToString());
                    });
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
        private static Pawn TryGenerateNewPawnInternal(ref PawnGenerationRequest request, out string error, bool ignoreScenarioRequirements, bool ignoreValidator)
        {
            error = null;
            Pawn pawn = (Pawn)ThingMaker.MakeThing(request.KindDef.race);

            pawnsBeingGenerated.Add(new PawnGenerationStatus(pawn, null));
            try
            {
                pawn.kindDef = request.KindDef;
                pawn.SetFactionDirect(request.Faction);
                PawnComponentsUtility.CreateInitialComponents(pawn);
                if (request.FixedGender.HasValue)
                {
                    pawn.gender = request.FixedGender.Value;
                }
                else if (pawn.RaceProps.hasGenders)
                {
                    if (Rand.Value < 0.5f)
                    {
                        pawn.gender = Gender.Male;
                    }
                    else
                    {
                        pawn.gender = Gender.Female;
                    }
                }
                else
                {
                    pawn.gender = Gender.None;
                }
                GenerateRandomAge(pawn, request);
                pawn.needs.SetInitialLevels();
                if (!request.Newborn && request.CanGeneratePawnRelations)
                {
                    GeneratePawnRelations(pawn, ref request);
                }
                if (pawn.RaceProps.Humanlike)
                {
                    Faction    faction;
                    FactionDef factionType = ((request.Faction != null) ? request.Faction.def : ((!Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction_NewTemp(out faction, tryMedievalOrBetter: false, allowDefeated: true)) ? Faction.OfAncients.def : faction.def));
                    pawn.story.melanin   = (request.FixedMelanin.HasValue ? request.FixedMelanin.Value : PawnSkinColors.RandomMelanin(request.Faction));
                    pawn.story.crownType = ((Rand.Value < 0.5f) ? CrownType.Average : CrownType.Narrow);
                    pawn.story.hairColor = PawnHairColors.RandomHairColor(pawn.story.SkinColor, pawn.ageTracker.AgeBiologicalYears);
                    PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName, factionType);
                    if (pawn.story != null)
                    {
                        if (request.FixedBirthName != null)
                        {
                            pawn.story.birthLastName = request.FixedBirthName;
                        }
                        else if (pawn.Name is NameTriple)
                        {
                            pawn.story.birthLastName = ((NameTriple)pawn.Name).Last;
                        }
                    }
                    pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, factionType);
                    GenerateTraits(pawn, request);
                    GenerateBodyType_NewTemp(pawn, request);
                    GenerateSkills(pawn);
                }
                if (pawn.RaceProps.Animal && request.Faction != null && request.Faction.IsPlayer)
                {
                    pawn.training.SetWantedRecursive(TrainableDefOf.Tameness, checkOn: true);
                    pawn.training.Train(TrainableDefOf.Tameness, null, complete: true);
                }
                GenerateInitialHediffs(pawn, request);
                if (!request.ForbidAnyTitle)
                {
                    RoyalTitleDef royalTitleDef = request.FixedTitle;
                    if (royalTitleDef == null)
                    {
                        if (request.KindDef.titleRequired != null)
                        {
                            royalTitleDef = request.KindDef.titleRequired;
                        }
                        else if (!request.KindDef.titleSelectOne.NullOrEmpty() && Rand.Chance(request.KindDef.royalTitleChance))
                        {
                            royalTitleDef = request.KindDef.titleSelectOne.RandomElementByWeight((RoyalTitleDef t) => t.commonality);
                        }
                    }
                    if (request.KindDef.minTitleRequired != null && (royalTitleDef == null || royalTitleDef.seniority < request.KindDef.minTitleRequired.seniority))
                    {
                        royalTitleDef = request.KindDef.minTitleRequired;
                    }
                    if (royalTitleDef != null)
                    {
                        Faction faction2 = ((request.Faction != null && request.Faction.def.HasRoyalTitles) ? request.Faction : Find.FactionManager.RandomRoyalFaction());
                        pawn.royalty.SetTitle(faction2, royalTitleDef, grantRewards: false);
                        if (request.Faction != null && !request.Faction.IsPlayer)
                        {
                            PurchasePermits(pawn, faction2);
                        }
                        int amount = 0;
                        if (royalTitleDef.GetNextTitle(faction2) != null)
                        {
                            amount = Rand.Range(0, royalTitleDef.GetNextTitle(faction2).favorCost - 1);
                        }
                        pawn.royalty.SetFavor_NewTemp(faction2, amount);
                        if (royalTitleDef.maxPsylinkLevel > 0)
                        {
                            Hediff_ImplantWithLevel hediff_ImplantWithLevel = HediffMaker.MakeHediff(HediffDefOf.PsychicAmplifier, pawn, pawn.health.hediffSet.GetBrain()) as Hediff_ImplantWithLevel;
                            pawn.health.AddHediff(hediff_ImplantWithLevel);
                            hediff_ImplantWithLevel.SetLevelTo(royalTitleDef.maxPsylinkLevel);
                        }
                    }
                }
                if (pawn.royalty != null)
                {
                    pawn.royalty.allowRoomRequirements    = request.KindDef.allowRoyalRoomRequirements;
                    pawn.royalty.allowApparelRequirements = request.KindDef.allowRoyalApparelRequirements;
                }
                if (pawn.workSettings != null && request.Faction != null && request.Faction.IsPlayer)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                if (request.Faction != null && pawn.RaceProps.Animal)
                {
                    pawn.GenerateNecessaryName();
                }
                if (Find.Scenario != null)
                {
                    Find.Scenario.Notify_NewPawnGenerating(pawn, request.Context);
                }
                if (!request.AllowDead && (pawn.Dead || pawn.Destroyed))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated dead pawn.";
                    return(null);
                }
                if (!request.AllowDowned && pawn.Downed)
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated downed pawn.";
                    return(null);
                }
                if (request.MustBeCapableOfViolence && ((pawn.story != null && pawn.WorkTagIsDisabled(WorkTags.Violent)) || (pawn.RaceProps.ToolUser && !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn incapable of violence.";
                    return(null);
                }
                if (request.KindDef != null && !request.KindDef.skills.NullOrEmpty())
                {
                    List <SkillRange> skills = request.KindDef.skills;
                    for (int i = 0; i < skills.Count; i++)
                    {
                        if (pawn.skills.GetSkill(skills[i].Skill).TotallyDisabled)
                        {
                            error = "Generated pawn incapable of required skill: " + skills[i].Skill.defName;
                            return(null);
                        }
                    }
                }
                if (request.KindDef.requiredWorkTags != 0 && (pawn.CombinedDisabledWorkTags & request.KindDef.requiredWorkTags) != 0)
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn with disabled requiredWorkTags.";
                    return(null);
                }
                if (!ignoreScenarioRequirements && request.Context == PawnGenerationContext.PlayerStarter && Find.Scenario != null && !Find.Scenario.AllowPlayerStartingPawn(pawn, tryingToRedress: false, request))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn doesn't meet scenario requirements.";
                    return(null);
                }
                if (!ignoreValidator && request.ValidatorPreGear != null && !request.ValidatorPreGear(pawn))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn didn't pass validator check (pre-gear).";
                    return(null);
                }
                if (!request.Newborn)
                {
                    GenerateGearFor(pawn, request);
                }
                if (!ignoreValidator && request.ValidatorPostGear != null && !request.ValidatorPostGear(pawn))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn didn't pass validator check (post-gear).";
                    return(null);
                }
                for (int j = 0; j < pawnsBeingGenerated.Count - 1; j++)
                {
                    if (pawnsBeingGenerated[j].PawnsGeneratedInTheMeantime == null)
                    {
                        pawnsBeingGenerated[j] = new PawnGenerationStatus(pawnsBeingGenerated[j].Pawn, new List <Pawn>());
                    }
                    pawnsBeingGenerated[j].PawnsGeneratedInTheMeantime.Add(pawn);
                }
                return(pawn);
            }
            finally
            {
                pawnsBeingGenerated.RemoveLast();
            }
        }