public static bool Prefix(Slate slate, out Faction faction, QuestNode_GetPawn __instance, ref bool __result) { Log.Message($"Trying to get factions for quest {__instance}"); __result = Internal(slate, out faction, __instance); Log.Message($"Result is {__result}, faction is {faction}"); return(false); }
private static bool Internal(Slate slate, out Faction faction, QuestNode_GetPawn __instance) { Log.Message($"Parameters are royal titles: {__instance.mustHaveRoyalTitleInCurrentFaction.GetValue(slate)}, " + $"non hostile: {__instance.mustBeNonHostileToPlayer.GetValue(slate)}, " + $"allow permanent enemy: {!(__instance.allowPermanentEnemyFaction.GetValue(slate) ?? false) }, " + $"min tech level: {__instance.minTechLevel.GetValue(slate)}"); return(Find.FactionManager.GetFactions(allowHidden : false, allowDefeated : false, allowNonHumanlike : false).Where(delegate(Faction x) { if (__instance.mustHaveRoyalTitleInCurrentFaction.GetValue(slate) && !x.def.HasRoyalTitles) { return false; } if (__instance.mustBeNonHostileToPlayer.GetValue(slate) && x.HostileTo(Faction.OfPlayer)) { return false; } if (!(__instance.allowPermanentEnemyFaction.GetValue(slate) ?? false) && x.def.permanentEnemy) { return false; } return ((int)x.def.techLevel >= (int)__instance.minTechLevel.GetValue(slate)) ? true : false; }).TryRandomElement(out faction)); }
static bool Prefix(ref QuestNode_GetPawn __instance, ref Pawn __result, Slate slate, Faction faction = null) { if (faction == FactionColonies.getPlayerColonyFaction()) { List <PawnKindDef> list = new List <PawnKindDef>(); foreach (ThingDef def in Find.World.GetComponent <FactionFC>().raceFilter.AllowedThingDefs) { list.Add(def.race.AnyPawnKind); } Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(list.RandomElement(), faction, PawnGenerationContext.NonPlayer, -1, true, false, false, false, true, false, 1f, false, true, true, true, false, false, false, false, 0f, null, 1f, null, null, null, null, null, null, null, null, null, null, null)); Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide); if (pawn.royalty != null && pawn.royalty.AllTitlesForReading.Any <RoyalTitle>()) { QuestPart_Hyperlinks questPart_Hyperlinks = new QuestPart_Hyperlinks(); questPart_Hyperlinks.pawns.Add(pawn); QuestGen.quest.AddPart(questPart_Hyperlinks); } __result = pawn; return(false); } else { return(true); } }