public override void CompPostTick(ref float severityAdjustment) { float mtbDays = Props.probabilityPerStage[parent.CurStageIndex].mtbDays; if (!(mtbDays > 0f) || !base.Pawn.IsHashIntervalTick(60)) { return; } ChangeImplantLevel_Probability changeImplantLevel_Probability = Props.probabilityPerStage[parent.CurStageIndex]; if ((lastChangeLevelTick < 0 || (float)(Find.TickManager.TicksGame - lastChangeLevelTick) >= changeImplantLevel_Probability.minIntervalDays * 60000f) && Rand.MTBEventOccurs(mtbDays, 60000f, 60f)) { Hediff_ImplantWithLevel hediff_ImplantWithLevel = parent.pawn.health.hediffSet.GetFirstHediffOfDef(Props.implant) as Hediff_ImplantWithLevel; if (hediff_ImplantWithLevel != null) { hediff_ImplantWithLevel.ChangeLevel(Props.levelOffset); lastChangeLevelTick = Find.TickManager.TicksGame; Messages.Message("MessageLostImplantLevelFromHediff".Translate(parent.pawn.Named("PAWN"), hediff_ImplantWithLevel.LabelBase, parent.Label), parent.pawn, MessageTypeDefOf.NegativeEvent); } } }
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(); } }