public static Pawn GeneratePeacekeeper(PawnKindDef pawnKind, int tile) { var robot = PawnGenerator.GeneratePawn(new PawnGenerationRequest() { KindDef = pawnKind, Faction = Faction.OfPlayer, Context = PawnGenerationContext.NonPlayer, Tile = tile, FixedBiologicalAge = 0, FixedGender = Gender.Male, AllowAddictions = false, FixedMelanin = 0, CanGeneratePawnRelations = false, FixedIdeo = null, ForceNoIdeo = true }); robot.Name = new NameSingle(robot.Name.ToStringShort + " #" + ModSettings.peacekeeperNumber++); var hediff = HediffMaker.MakeHediff(RSDefOf.RSRobotConsciousness, robot); if (robot != null && !robot.health.hediffSet.HasHediff(RSDefOf.RSRobotConsciousness)) { robot.health.AddHediff(hediff, robot.health.hediffSet.GetBrain(), null, null); } var robotModExt = robot.def.GetModExtension <RSPeacekeeperModExt>(); var batteryHediff = HediffMaker.MakeHediff(RSDefOf.RSPeacekeeperBattery, robot); robot.health.AddHediff(batteryHediff, PeacekeeperUtility.GetTorso(robot), null, null); batteryHediff.Severity = robotModExt.batterySeverity; var allowedTraits = (robot.def as ThingDef_AlienRace)?.alienRace?.generalSettings?.forcedRaceTraitEntries?.Select(entry => entry.defName)?.ToList(); if (allowedTraits != null && allowedTraits.Count != 0) { foreach (var trait in robot.story.traits.allTraits.Reverse <Trait>()) { robot.story.traits.allTraits.Remove(trait); } foreach (var trait in allowedTraits) { robot.story.traits.GainTrait(new Trait(trait)); } } robot.playerSettings.hostilityResponse = HostilityResponseMode.Attack; robot.skills.skills.FirstOrDefault(x => x.def == SkillDefOf.Shooting).Level = robotModExt.shootingSkill; robot.skills.skills.FirstOrDefault(x => x.def == SkillDefOf.Melee).Level = robotModExt.meleeSkill; robot.guest.joinStatus = JoinStatus.JoinAsColonist; return(robot); }