Skip to content

Commit

Permalink
Fixed random trait generation to include forced traits from custom xe…
Browse files Browse the repository at this point in the history
…notype
  • Loading branch information
edbmods committed Dec 26, 2022
1 parent 7e81e5a commit 71ecc1c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
9 changes: 1 addition & 8 deletions Source/CustomPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,7 @@ public void InitializeWithPawn(Pawn pawn) {
InitializeInjuriesAndImplantsFromPawn(pawn);

if (ModsConfig.BiotechActive) {
var customXenotypes = ReflectionUtil.GetStaticPropertyValue<List<CustomXenotype>>(typeof(CharacterCardUtility), "CustomXenotypes");
foreach (CustomXenotype c in customXenotypes) {
if (GeneUtility.PawnIsCustomXenotype(pawn, c)) {
customXenotype = c;
break;
}
}
XenotypeDef xenotypeDef = ReflectionUtil.GetFieldValue<XenotypeDef>(pawn.genes, "xenotype");
customXenotype = pawn.MatchGenesToCustomXenotype();
if (customXenotype != null) {
RandomizeCustomXenotype = customXenotype;
RandomizeXenotype = null;
Expand Down
15 changes: 15 additions & 0 deletions Source/ExtensionsPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,20 @@ public static void AssignToFaction(this Pawn pawn, Faction faction) {
field.SetValue(pawn, faction);
}

public static CustomXenotype MatchGenesToCustomXenotype(this Pawn pawn) {
if (!ModsConfig.BiotechActive) {
return null;
}
var customXenotypes = Reflection.CharacterCardUtility.CustomXenotypes;
if (customXenotypes == null) {
return null;
}
foreach (CustomXenotype c in customXenotypes) {
if (GeneUtility.PawnIsCustomXenotype(pawn, c)) {
return c;
}
}
return null;
}
}
}
11 changes: 8 additions & 3 deletions Source/Randomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ public Pawn GeneratePawnAsCloseToAsPossible(Pawn pawn) {
FixedChronologicalAge = pawn.ageTracker.AgeChronologicalYears,
FixedGender = pawn.gender,
FixedIdeology = pawn.Ideo,
DevelopmentalStage = pawn.DevelopmentalStage,
ForcedXenotype = pawn.genes?.Xenotype,
ForcedCustomXenotype = pawn.genes?.CustomXenotype
DevelopmentalStage = pawn.DevelopmentalStage
};
CustomXenotype customXenotype = pawn.MatchGenesToCustomXenotype();
if (customXenotype != null) {
request.ForcedCustomXenotype = customXenotype;
}
else {
request.ForcedXenotype = pawn.genes?.Xenotype;
}
Pawn result = AttemptToGeneratePawn(request.Request);
return result;
}
Expand Down
6 changes: 6 additions & 0 deletions Source/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ public static class CharacterCardUtility {
public static IEnumerable<WorkTags> WorkTagsFrom(WorkTags workTags) {
return (IEnumerable<WorkTags>)ReflectionCache.Instance.CharacterCardUtility_WorkTagsFrom.Invoke(null, new object[] { workTags });
}
public static List<CustomXenotype> CustomXenotypes {
get {
return ReflectionUtil.GetStaticPropertyValue<List<CustomXenotype>>(typeof(RimWorld.CharacterCardUtility), "CustomXenotypes");
}
}
}

public static class ScenPart_StartingAnimal {
public static IEnumerable<PawnKindDef> RandomPets(RimWorld.ScenPart_StartingAnimal scenPart) {
return (IEnumerable<PawnKindDef>)ReflectionCache.Instance.ScenPart_StartingAnimal_RandomPets.Invoke(scenPart, null);
Expand Down

0 comments on commit 71ecc1c

Please sign in to comment.