/// <summary> /// Checks the race of this pawn. If the pawn is mutated enough it's race is changed to one of the hybrids /// </summary> /// <param name="pawn">The pawn.</param> /// <param name="addMissingMutations">if true, any missing mutations from the highest morph influence will be added</param> /// <param name="displayNotifications">if set to <c>true</c> display race shift notifications.</param> /// <exception cref="ArgumentNullException">pawn</exception> /// <exception cref="System.ArgumentNullException">pawn</exception> public static void CheckRace([NotNull] this Pawn pawn, bool addMissingMutations = true, bool displayNotifications = true) { if (pawn == null) { throw new ArgumentNullException(nameof(pawn)); } if (pawn.ShouldBeConsideredHuman()) { return; } MutationTracker mutTracker = pawn.GetMutationTracker(); var hInfluence = mutTracker.HighestInfluence; if (hInfluence == null) { return; } float morphInfluence = mutTracker.GetDirectNormalizedInfluence(hInfluence); int morphInfluenceCount = mutTracker.Count(); var isBelowChimeraThreshold = morphInfluence < CHIMERA_THRESHOLD && morphInfluenceCount > 1; MorphDef setMorph = GetMorphForPawn(pawn, isBelowChimeraThreshold, hInfluence, out MorphDef curMorph); if (setMorph?.raceSettings?.PawnCanBecomeHybrid(pawn) == false) { return; } if (curMorph != setMorph && setMorph != null) { RaceShiftUtilities.ChangePawnToMorph(pawn, setMorph, addMissingMutations, displayNotifications); } }
static void RunRaceCompCheck([NotNull] Pawn __instance) { var mTracker = __instance.GetComp <MorphTrackingComp>(); if (mTracker?.needsRaceCompCheck == true) { RaceShiftUtilities.AddRemoveDynamicRaceComps(__instance, __instance.def); mTracker.needsRaceCompCheck = false; } }
static void RunRaceCompCheck([NotNull] Pawn __instance) { //only check every so often if (!__instance.IsHashIntervalTick(60)) { return; } var mTracker = __instance.GetComp <MorphTrackingComp>(); if (mTracker?.needsRaceCompCheck == true) { RaceShiftUtilities.AddRemoveDynamicRaceComps(__instance, __instance.def); mTracker.needsRaceCompCheck = false; } }
private List <DebugMenuOption> GetRaceChangeOptions() { //var races = RaceGenerator.ImplicitRaces; var lst = new List <DebugMenuOption>(); foreach (MorphDef morph in DefDatabase <MorphDef> .AllDefs) { MorphDef local = morph; lst.Add(new DebugMenuOption(local.label, DebugMenuOptionMode.Tool, () => { Pawn pawn = Find.CurrentMap.thingGrid.ThingsAt(UI.MouseCell()).OfType <Pawn>().FirstOrDefault(); if (pawn != null && pawn.RaceProps.intelligence == Intelligence.Humanlike) { RaceShiftUtilities.ChangePawnToMorph(pawn, local); } })); } return(lst); }
/// <summary> Removes all mutations from a pawn (used post reversion). </summary> /// <param name="pawn">The pawn.</param> public static void RemoveAllMutations(Pawn pawn) { List <Hediff> hS2 = new List <Hediff>(pawn.health.hediffSet.hediffs); foreach (Hediff hediff in hS2) { Type hediffClass = hediff.def.hediffClass; if (hediffClass == typeof(Hediff_AddedMutation) || hediffClass == typeof(HediffGiver_TF)) { pawn.health.RemoveHediff(hediff); } } foreach (MorphTf hediffMorph in hS2.OfType <MorphTf>()) //do this second so the morph hediff can cleanup properly { pawn.health.RemoveHediff(hediffMorph); //remove ongoing morph hediffs } if (pawn.IsHybridRace()) { RaceShiftUtilities.RevertPawnToHuman(pawn); } }