protected override bool TestRunInt(Slate slate)
        {
            if (!Find.Storyteller.difficultyValues.allowViolentQuests)
            {
                return(false);
            }
            if (!QuestGen_Pawns.GetPawnTest(CivilianPawnParams, out var _))
            {
                return(false);
            }
            if (Faction.Empire.PlayerRelationKind == FactionRelationKind.Hostile)
            {
                return(false);
            }
            if (!TryFindEnemyFaction(out var _))
            {
                return(false);
            }
            Map map = QuestGen_Get.GetMap();

            if (!TryFindShuttleCrashPosition(map, Faction.Empire, ThingDefOf.ShuttleCrashed.size, out var spot))
            {
                return(false);
            }
            if (!TryFindRaidWalkInPosition(map, spot, out var _))
            {
                return(false);
            }
            return(true);
        }
        protected override void RunInt()
        {
            Quest      quest            = QuestGen.quest;
            Slate      slate            = QuestGen.slate;
            Map        map              = QuestGen_Get.GetMap();
            Faction    faction          = slate.Get <Faction>("faction");
            FloatRange marketValueRange = slate.Get <FloatRange>("marketValueRange");
            Pawn       val              = slate.Get <Pawn>("rewardGiver");

            quest.ReservePawns(Gen.YieldSingle(val));
            quest.ReserveFaction(faction);
            int num = Rand.Range(5, 20) * 60000;

            slate.Set("rewardDelayTicks", num);
            quest.Delay(num, delegate
            {
                ThingSetMakerParams parms   = default(ThingSetMakerParams);
                parms.totalMarketValueRange = marketValueRange;
                parms.qualityGenerator      = QualityGenerator.Reward;
                parms.makingFaction         = faction;
                List <Thing> list           = ThingSetMakerDefOf.Reward_ItemsStandard.root.Generate(parms);
                slate.Set("listOfRewards", GenLabel.ThingsLabel(list));
                quest.DropPods(map.Parent, list, null, null, "[rewardLetterText]", null, true);
                QuestGen_End.End(quest, QuestEndOutcome.Unknown);
            }, null, null, null, reactivatable: false, null, null, isQuestTimeout: false, null, null, "RewardDelay");
        }
        protected override void RunInt()
        {
            if (!ModLister.RoyaltyInstalled)
            {
                Log.ErrorOnce("Shuttle crash rescue is a Royalty-specific game system. If you want to use this code please check ModLister.RoyaltyInstalled before calling it. See rules on the Ludeon forum for more info.", 8811221);
                return;
            }
            Quest quest       = QuestGen.quest;
            Slate slate       = QuestGen.slate;
            Map   map         = QuestGen_Get.GetMap();
            float questPoints = slate.Get("points", 0f);

            slate.Set("map", map);
            slate.Set("rescueDelay", 20000);
            slate.Set("leaveDelay", 30000);
            slate.Set("rescueShuttleAfterRaidDelay", 10000);
            int max  = Mathf.FloorToInt(MaxCiviliansByPointsCurve.Evaluate(questPoints));
            int num  = Rand.Range(1, max);
            int max2 = Mathf.FloorToInt(MaxSoldiersByPointsCurve.Evaluate(questPoints));
            int num2 = Rand.Range(1, max2);

            TryFindEnemyFaction(out var enemyFaction);
            Thing crashedShuttle = ThingMaker.MakeThing(ThingDefOf.ShuttleCrashed);

            TryFindShuttleCrashPosition(map, Faction.Empire, crashedShuttle.def.size, out var shuttleCrashPosition);
            List <Pawn> civilians = new List <Pawn>();
            List <Pawn> list      = new List <Pawn>();

            for (int i = 0; i < num - 1; i++)
            {
                Pawn pawn = quest.GetPawn(CivilianPawnParams);
                civilians.Add(pawn);
                list.Add(pawn);
            }
            Quest quest2 = quest;

            QuestGen_Pawns.GetPawnParms parms = new QuestGen_Pawns.GetPawnParms
            {
                mustBeOfFaction = Faction.Empire,
                canGeneratePawn = true,
                mustBeWorldPawn = true,
                seniorityRange  = new FloatRange(100f, MaxAskerSeniorityByPointsCurve.Evaluate(questPoints)),
                mustHaveRoyalTitleInCurrentFaction = true
            };
            Pawn asker = quest2.GetPawn(parms);

            civilians.Add(asker);
            PawnKindDef mustBeOfKind = new PawnKindDef[3]
            {
                PawnKindDefOf.Empire_Fighter_Trooper,
                PawnKindDefOf.Empire_Fighter_Janissary,
                PawnKindDefOf.Empire_Fighter_Cataphract
            }.RandomElement();
            List <Pawn> soldiers = new List <Pawn>();

            for (int j = 0; j < num2; j++)
            {
                Quest quest3 = quest;
                parms = new QuestGen_Pawns.GetPawnParms
                {
                    mustBeOfFaction = Faction.Empire,
                    canGeneratePawn = true,
                    mustBeOfKind    = mustBeOfKind,
                    mustBeWorldPawn = true
                };
                Pawn pawn2 = quest3.GetPawn(parms);
                soldiers.Add(pawn2);
            }
            List <Pawn> allPassengers = new List <Pawn>();

            allPassengers.AddRange(soldiers);
            allPassengers.AddRange(civilians);
            quest.BiocodeWeapons(allPassengers);
            Thing rescueShuttle = QuestGen_Shuttle.GenerateShuttle(Faction.Empire, allPassengers, null, acceptColonists: false, onlyAcceptColonists: false, onlyAcceptHealthy: false, -1, dropEverythingIfUnsatisfied: false, leaveImmediatelyWhenSatisfied: true, dropEverythingOnArrival: false, stayAfterDroppedEverythingOnArrival: false, null, null, -1, null, permitShuttle: false, hideControls: true, allPassengers.Cast <Thing>().ToList());

            quest.Delay(120, delegate
            {
                quest.Letter(LetterDefOf.NegativeEvent, null, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, label: "LetterLabelShuttleCrashed".Translate(), text: "LetterTextShuttleCrashed".Translate(), lookTargets: Gen.YieldSingle(crashedShuttle));
                quest.SpawnSkyfaller(map, ThingDefOf.ShuttleCrashing, Gen.YieldSingle(crashedShuttle), Faction.OfPlayer, shuttleCrashPosition);
                quest.DropPods(map.Parent, allPassengers, null, null, null, null, dropSpot: shuttleCrashPosition, sendStandardLetter: false);
                quest.DefendPoint(map.Parent, shuttleCrashPosition, soldiers, Faction.Empire, null, null, 12f, isCaravanSendable: false, addFleeToil: false);
                IntVec3 position = shuttleCrashPosition + IntVec3.South;
                quest.WaitForEscort(map.Parent, civilians, Faction.Empire, position, null, addFleeToil: false);
                string inSignal4 = QuestGenUtility.HardcodedSignalWithQuestID("rescueShuttle.Spawned");
                quest.ExitOnShuttle(map.Parent, allPassengers, Faction.Empire, rescueShuttle, inSignal4, addFleeToil: false);
                quest.SendShuttleAwayOnCleanup(rescueShuttle);
                quest.ShuttleDelay(20000, civilians, delegate
                {
                    quest.Letter(LetterDefOf.NeutralEvent, null, null, Faction.Empire, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, Gen.YieldSingle(rescueShuttle), filterDeadPawnsFromLookTargets: false, "[rescueShuttleArrivedLetterText]", null, "[rescueShuttleArrivedLetterLabel]");
                    quest.SpawnSkyfaller(map, ThingDefOf.ShuttleIncoming, Gen.YieldSingle(rescueShuttle), Faction.Empire, null, null, lookForSafeSpot: false, tryLandInShipLandingZone: false, crashedShuttle);
                    quest.ShuttleLeaveDelay(rescueShuttle, 30000, null, null, null, delegate
                    {
                        quest.SendShuttleAway(rescueShuttle);
                        quest.End(QuestEndOutcome.Fail, 0, null, null, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
                    });
                }, null, null, alert: true);
                IntVec3 walkIntSpot = default(IntVec3);
                TryFindRaidWalkInPosition(map, shuttleCrashPosition, out walkIntSpot);
                float soldiersTotalCombatPower = 0f;
                for (int k = 0; k < soldiers.Count; k++)
                {
                    soldiersTotalCombatPower += soldiers[k].kindDef.combatPower;
                }
                quest.Delay(10000, delegate
                {
                    List <Pawn> list2 = PawnGroupMakerUtility.GeneratePawns(new PawnGroupMakerParms
                    {
                        faction   = enemyFaction,
                        groupKind = PawnGroupKindDefOf.Combat,
                        points    = (questPoints + soldiersTotalCombatPower) * 0.37f,
                        tile      = map.Tile
                    }).ToList();
                    for (int l = 0; l < list2.Count; l++)
                    {
                        Find.WorldPawns.PassToWorld(list2[l]);
                        QuestGen.AddToGeneratedPawns(list2[l]);
                    }
                    QuestPart_PawnsArrive questPart_PawnsArrive = new QuestPart_PawnsArrive();
                    questPart_PawnsArrive.pawns.AddRange(list2);
                    questPart_PawnsArrive.arrivalMode        = PawnsArrivalModeDefOf.EdgeWalkIn;
                    questPart_PawnsArrive.joinPlayer         = false;
                    questPart_PawnsArrive.mapParent          = map.Parent;
                    questPart_PawnsArrive.spawnNear          = walkIntSpot;
                    questPart_PawnsArrive.inSignal           = QuestGen.slate.Get <string>("inSignal");
                    questPart_PawnsArrive.sendStandardLetter = false;
                    quest.AddPart(questPart_PawnsArrive);
                    quest.AssaultThings(map.Parent, list2, enemyFaction, allPassengers, null, null, excludeFromLookTargets: true);
                    quest.Letter(LetterDefOf.ThreatBig, null, null, enemyFaction, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, list2, filterDeadPawnsFromLookTargets: false, "[raidArrivedLetterText]", null, "[raidArrivedLetterLabel]");
                }, null, null, null, reactivatable: false, null, null, isQuestTimeout: false, null, null, "RaidDelay");
            });
            string text  = QuestGenUtility.HardcodedSignalWithQuestID("rescueShuttle.SentSatisfied");
            string text2 = QuestGenUtility.HardcodedSignalWithQuestID("rescueShuttle.SentUnsatisfied");

            string[] inSignalsShuttleSent = new string[2]
            {
                text,
                text2
            };
            string text3    = QuestGenUtility.HardcodedSignalWithQuestID("rescueShuttle.Destroyed");
            string inSignal = QuestGenUtility.HardcodedSignalWithQuestID("asker.Destroyed");

            quest.GoodwillChangeShuttleSentThings(Faction.Empire, list, -5, null, inSignalsShuttleSent, text3, "GoodwillChangeReason_CiviliansLost".Translate(), canSendMessage: true, canSendHostilityLetter: false, QuestPart.SignalListenMode.Always);
            quest.GoodwillChangeShuttleSentThings(Faction.Empire, Gen.YieldSingle(asker), -10, null, inSignalsShuttleSent, text3, "GoodwillChangeReason_CommanderLost".Translate(), canSendMessage: true, canSendHostilityLetter: false, QuestPart.SignalListenMode.Always);
            quest.Leave(allPassengers, "", sendStandardLetter: false);
            quest.Letter(LetterDefOf.PositiveEvent, text, null, Faction.Empire, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[questCompletedSuccessLetterText]", null, "[questCompletedSuccessLetterLabel]");
            string questSuccess = QuestGen.GenerateNewSignal("QuestSuccess");

            quest.SignalPass(delegate
            {
                RewardsGeneratorParams rewardsGeneratorParams = default(RewardsGeneratorParams);
                rewardsGeneratorParams.rewardValue            = questPoints;
                rewardsGeneratorParams.allowGoodwill          = true;
                rewardsGeneratorParams.allowRoyalFavor        = true;
                RewardsGeneratorParams parms2 = rewardsGeneratorParams;
                quest.GiveRewards(parms2, null, null, null, null, null, null, null, null, addCampLootReward: false, asker, addShuttleLootReward: true);
                QuestGen_End.End(quest, QuestEndOutcome.Success);
            }, questSuccess);
            quest.SignalPass(null, text, questSuccess);
            quest.AnyOnTransporter(allPassengers, rescueShuttle, delegate
            {
                quest.AnyOnTransporter(Gen.YieldSingle(asker), rescueShuttle, delegate
                {
                    quest.Letter(LetterDefOf.PositiveEvent, null, null, Faction.Empire, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[questCompletedCiviliansLostSuccessLetterText]", null, "[questCompletedCiviliansLostSuccessLetterLabel]");
                    quest.SignalPass(null, null, questSuccess);
                }, delegate
                {
                    quest.Letter(LetterDefOf.NegativeEvent, null, null, Faction.Empire, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[askerLostLetterText]", null, "[askerLostLetterLabel]");
                    QuestGen_End.End(quest, QuestEndOutcome.Fail);
                });
            }, delegate
            {
                quest.Letter(LetterDefOf.NegativeEvent, null, null, Faction.Empire, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[allLostLetterText]", null, "[allLostLetterLabel]");
                QuestGen_End.End(quest, QuestEndOutcome.Fail);
            }, text2);
            quest.Letter(LetterDefOf.NegativeEvent, inSignal, null, Faction.Empire, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, Gen.YieldSingle(asker), filterDeadPawnsFromLookTargets: false, "[askerDiedLetterText]", null, "[askerDiedLetterLabel]");
            quest.End(QuestEndOutcome.Fail, 0, null, inSignal);
            quest.Letter(LetterDefOf.NegativeEvent, text3, null, Faction.Empire, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, Gen.YieldSingle(rescueShuttle), filterDeadPawnsFromLookTargets: false, "[shuttleDestroyedLetterText]", null, "[shuttleDestroyedLetterLabel]");
            quest.End(QuestEndOutcome.Fail, 0, null, text3);
            quest.End(QuestEndOutcome.Fail, 0, null, QuestGenUtility.HardcodedSignalWithQuestID("asker.LeftMap"), QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            string inSignal2 = QuestGenUtility.HardcodedSignalWithQuestID("askerFaction.BecameHostileToPlayer");

            quest.End(QuestEndOutcome.Fail, 0, null, inSignal2, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.InvalidPreAcceptance, 0, null, inSignal2, QuestPart.SignalListenMode.NotYetAcceptedOnly);
            slate.Set("asker", asker);
            slate.Set("askerFaction", asker.Faction);
            slate.Set("enemyFaction", enemyFaction);
            slate.Set("soldiers", soldiers);
            slate.Set("civilians", civilians);
            slate.Set("civilianCountMinusOne", civilians.Count - 1);
            slate.Set("rescueShuttle", rescueShuttle);
        }
        protected override void RunInt()
        {
            if (!ModLister.RoyaltyInstalled)
            {
                Log.ErrorOnce("Hospitality refugee is a Royalty-specific game system. If you want to use this code please check ModLister.RoyaltyInstalled before calling it. See rules on the Ludeon forum for more info.", 8811221);
                return;
            }
            Quest quest       = QuestGen.quest;
            Slate slate       = QuestGen.slate;
            Map   map         = QuestGen_Get.GetMap();
            int   num         = (slate.Exists("population") ? slate.Get("population", 0) : map.mapPawns.FreeColonistsSpawnedCount);
            int   lodgerCount = Mathf.Max(Mathf.RoundToInt(LodgerCountBasedOnColonyPopulationFactorRange.RandomInRange * (float)num), 1);

            lodgerCount = Mathf.Min(lodgerCount, MaxLodgerCount);
            int questDurationDays       = QuestDurationDaysRange.RandomInRange;
            int questDurationTicks      = questDurationDays * 60000;
            List <FactionRelation> list = new List <FactionRelation>();

            foreach (Faction item4 in Find.FactionManager.AllFactionsListForReading)
            {
                if (!item4.def.permanentEnemy)
                {
                    list.Add(new FactionRelation
                    {
                        other    = item4,
                        goodwill = 0,
                        kind     = FactionRelationKind.Neutral
                    });
                }
            }
            Faction faction = FactionGenerator.NewGeneratedFactionWithRelations(FactionDefOf.OutlanderRefugee, list);

            faction.hidden    = true;
            faction.temporary = true;
            faction.hostileFromMemberCapture = false;
            Find.FactionManager.Add(faction);
            string      lodgerRecruitedSignal = QuestGenUtility.HardcodedSignalWithQuestID("lodgers.Recruited");
            string      text = QuestGenUtility.HardcodedSignalWithQuestID("lodgers.Arrested");
            string      lodgerDestroyedSignal = QuestGenUtility.HardcodedSignalWithQuestID("lodgers.Destroyed");
            string      lodgerKidnapped       = QuestGenUtility.HardcodedSignalWithQuestID("lodgers.Kidnapped");
            string      lodgerLeftMap         = QuestGenUtility.HardcodedSignalWithQuestID("lodgers.LeftMap");
            string      lodgerBanished        = QuestGenUtility.HardcodedSignalWithQuestID("lodgers.Banished");
            List <Pawn> pawns = new List <Pawn>();

            for (int i = 0; i < lodgerCount; i++)
            {
                Pawn pawn = quest.GeneratePawn(PawnKindDefOf.Refugee, faction, allowAddictions: true, null, 0f, mustBeCapableOfViolence: true, null, 0f, 0f, ensureNonNumericName: false, forceGenerateNewPawn: true);
                pawns.Add(pawn);
                quest.PawnJoinOffer(pawn, "LetterJoinOfferLabel".Translate(pawn.Named("PAWN")), "LetterJoinOfferTitle".Translate(pawn.Named("PAWN")), "LetterJoinOfferText".Translate(pawn.Named("PAWN"), map.Parent.Named("MAP")), delegate
                {
                    quest.Letter(LetterDefOf.PositiveEvent, null, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, label: "LetterLabelMessageRecruitSuccess".Translate() + ": " + pawn.LabelShortCap, text: "MessageRecruitJoinOfferAccepted".Translate(pawn.Named("RECRUITEE")));
                    quest.SignalPass(null, null, lodgerRecruitedSignal);
                });
            }
            slate.Set("lodgers", pawns);
            faction.leader = pawns.First();
            Pawn var = pawns.First();

            quest.SetFactionHidden(faction);
            QuestPart_ExtraFaction extraFactionPart = quest.ExtraFaction(faction, pawns, ExtraFactionType.MiniFaction, areHelpers: false, lodgerRecruitedSignal);

            quest.PawnsArrive(pawns, null, map.Parent, null, joinPlayer: true, null, "[lodgersArriveLetterLabel]", "[lodgersArriveLetterText]");
            QuestPart_Choice questPart_Choice = quest.RewardChoice();

            QuestPart_Choice.Choice item = new QuestPart_Choice.Choice
            {
                rewards =
                {
                    (Reward) new Reward_VisitorsHelp(),
                    (Reward) new Reward_PossibleFutureReward()
                }
            };
            questPart_Choice.choices.Add(item);
            bool   mutiny = false;
            string assaultColonySignal = QuestGen.GenerateNewSignal("AssaultColony");
            Action item2 = delegate
            {
                int num4 = Mathf.FloorToInt(MutinyTimeRange.RandomInRange * (float)questDurationTicks);
                quest.Delay(num4, delegate
                {
                    quest.Letter(LetterDefOf.ThreatBig, null, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[mutinyLetterText]", null, "[mutinyLetterLabel]");
                    quest.SignalPass(null, null, assaultColonySignal);
                    QuestGen_End.End(quest, QuestEndOutcome.Unknown);
                }, null, null, null, reactivatable: false, null, null, isQuestTimeout: false, null, null, "Mutiny (" + num4.ToStringTicksToDays() + ")");
                mutiny = true;
            };
            Action item3 = delegate
            {
                Pawn factionOpponent = quest.GetPawn(new QuestGen_Pawns.GetPawnParms
                {
                    mustBeWorldPawn          = true,
                    mustBeFactionLeader      = true,
                    canGeneratePawn          = true,
                    mustBeNonHostileToPlayer = true
                });
                slate.Set("factionOpponent", factionOpponent);
                int num2 = Mathf.FloorToInt(BetrayalOfferTimeRange.RandomInRange * (float)questDurationTicks);
                quest.Delay(num2, delegate
                {
                    float val2                        = (float)lodgerCount * 300f;
                    FloatRange value                  = new FloatRange(0.7f, 1.3f) * val2 * Find.Storyteller.difficultyValues.EffectiveQuestRewardValueFactor;
                    ThingSetMakerParams parms         = default(ThingSetMakerParams);
                    parms.totalMarketValueRange       = value;
                    parms.qualityGenerator            = QualityGenerator.Reward;
                    parms.makingFaction               = faction;
                    List <Thing> betrayalRewardThings = ThingSetMakerDefOf.Reward_ItemsStandard.root.Generate(parms);
                    quest.BetrayalOffer(pawns, extraFactionPart.extraFaction, factionOpponent, delegate
                    {
                        float num3 = 0f;
                        for (int j = 0; j < betrayalRewardThings.Count; j++)
                        {
                            num3 += betrayalRewardThings[j].MarketValue * (float)betrayalRewardThings[j].stackCount;
                        }
                        slate.Set("betrayalRewards", GenLabel.ThingsLabel(betrayalRewardThings));
                        slate.Set("betrayalRewardMarketValue", num3);
                        quest.DropPods(map.Parent, betrayalRewardThings, null, null, null, null, true, useTradeDropSpot: false, joinPlayer: false, makePrisoners: false, null, null, QuestPart.SignalListenMode.Always, null, destroyItemsOnCleanup: false);
                        quest.FactionGoodwillChange(factionOpponent.Faction, 10, null, canSendMessage: true, canSendHostilityLetter: true, "GoodwillChangeReason_AttackedFaction".Translate(faction), getLookTargetFromSignal: true, QuestPart.SignalListenMode.Always);
                        quest.Letter(LetterDefOf.PositiveEvent, null, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.Always, betrayalRewardThings, filterDeadPawnsFromLookTargets: false, "[betrayalOfferRewardLetterText]", null, "[betrayalOfferRewardLetterLabel]");
                    }, delegate
                    {
                        quest.DestroyThingsOrPassToWorld(betrayalRewardThings, null, questLookTargets: true, QuestPart.SignalListenMode.Always);
                        quest.Letter(LetterDefOf.NegativeEvent, null, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.Always, null, filterDeadPawnsFromLookTargets: false, "[betrayalOfferFailedLetterText]", null, "[betrayalOfferFailedLetterLabel]");
                    }, delegate
                    {
                        (quest.Letter(LetterDefOf.BetrayVisitors, null, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[betrayalOffserLetterText]", null, "[betrayalOfferLetterLabel]").letter as ChoiceLetter_BetrayVisitors).pawns.AddRange(pawns);
                    }, new List <string>
                    {
                        lodgerDestroyedSignal,
                        lodgerKidnapped,
                        lodgerLeftMap,
                        lodgerBanished
                    }, null, QuestPart.SignalListenMode.Always);
                }, null, null, null, reactivatable: false, null, null, isQuestTimeout: false, null, null, "BetrayalOffer (" + num2.ToStringTicksToDays() + ")");
            };

            if (new List <Tuple <float, Action> >
            {
                Tuple.Create(0.25f, item2),
                Tuple.Create(0.25f, item3),
                Tuple.Create <float, Action>(0.5f, delegate
                {
                })
            }.TryRandomElementByWeight((Tuple <float, Action> t) => t.Item1, out var result))
            {
                result.Item2();
            }
            QuestPart_RefugeeInteractions questPart_RefugeeInteractions = new QuestPart_RefugeeInteractions();

            questPart_RefugeeInteractions.inSignalEnable                          = QuestGen.slate.Get <string>("inSignal");
            questPart_RefugeeInteractions.inSignalDestroyed                       = lodgerDestroyedSignal;
            questPart_RefugeeInteractions.inSignalArrested                        = text;
            questPart_RefugeeInteractions.inSignalSurgeryViolation                = QuestGenUtility.HardcodedSignalWithQuestID("lodgers.SurgeryViolation");
            questPart_RefugeeInteractions.inSignalKidnapped                       = lodgerKidnapped;
            questPart_RefugeeInteractions.inSignalRecruited                       = lodgerRecruitedSignal;
            questPart_RefugeeInteractions.inSignalAssaultColony                   = assaultColonySignal;
            questPart_RefugeeInteractions.inSignalLeftMap                         = lodgerLeftMap;
            questPart_RefugeeInteractions.inSignalBanished                        = lodgerBanished;
            questPart_RefugeeInteractions.outSignalDestroyed_AssaultColony        = QuestGen.GenerateNewSignal("LodgerDestroyed_AssaultColony");
            questPart_RefugeeInteractions.outSignalDestroyed_LeaveColony          = QuestGen.GenerateNewSignal("LodgerDestroyed_LeaveColony");
            questPart_RefugeeInteractions.outSignalDestroyed_BadThought           = QuestGen.GenerateNewSignal("LodgerDestroyed_BadThought");
            questPart_RefugeeInteractions.outSignalArrested_AssaultColony         = QuestGen.GenerateNewSignal("LodgerArrested_AssaultColony");
            questPart_RefugeeInteractions.outSignalArrested_LeaveColony           = QuestGen.GenerateNewSignal("LodgerArrested_LeaveColony");
            questPart_RefugeeInteractions.outSignalArrested_BadThought            = QuestGen.GenerateNewSignal("LodgerArrested_BadThought");
            questPart_RefugeeInteractions.outSignalSurgeryViolation_AssaultColony = QuestGen.GenerateNewSignal("LodgerSurgeryViolation_AssaultColony");
            questPart_RefugeeInteractions.outSignalSurgeryViolation_LeaveColony   = QuestGen.GenerateNewSignal("LodgerSurgeryViolation_LeaveColony");
            questPart_RefugeeInteractions.outSignalSurgeryViolation_BadThought    = QuestGen.GenerateNewSignal("LodgerSurgeryViolation_BadThought");
            questPart_RefugeeInteractions.outSignalLast_Destroyed                 = QuestGen.GenerateNewSignal("LastLodger_Destroyed");
            questPart_RefugeeInteractions.outSignalLast_Arrested                  = QuestGen.GenerateNewSignal("LastLodger_Arrested");
            questPart_RefugeeInteractions.outSignalLast_Kidnapped                 = QuestGen.GenerateNewSignal("LastLodger_Kidnapped");
            questPart_RefugeeInteractions.outSignalLast_Recruited                 = QuestGen.GenerateNewSignal("LastLodger_Recruited");
            questPart_RefugeeInteractions.outSignalLast_LeftMapAllHealthy         = QuestGen.GenerateNewSignal("LastLodger_LeftMapAllHealthy");
            questPart_RefugeeInteractions.outSignalLast_LeftMapAllNotHealthy      = QuestGen.GenerateNewSignal("LastLodger_LeftMapAllNotHealthy");
            questPart_RefugeeInteractions.outSignalLast_Banished                  = QuestGen.GenerateNewSignal("LastLodger_Banished");
            questPart_RefugeeInteractions.pawns.AddRange(pawns);
            questPart_RefugeeInteractions.faction          = faction;
            questPart_RefugeeInteractions.mapParent        = map.Parent;
            questPart_RefugeeInteractions.signalListenMode = QuestPart.SignalListenMode.Always;
            quest.AddPart(questPart_RefugeeInteractions);
            string lodgerArrestedOrRecruited = QuestGen.GenerateNewSignal("Lodger_ArrestedOrRecruited");

            quest.AnySignal(new List <string>
            {
                lodgerRecruitedSignal,
                text
            }, null, new List <string>
            {
                lodgerArrestedOrRecruited
            });
            if (!mutiny)
            {
                quest.Delay(questDurationTicks, delegate
                {
                    quest.SignalPassWithFaction(faction, null, delegate
                    {
                        quest.Letter(LetterDefOf.PositiveEvent, null, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgersLeavingLetterText]", null, "[lodgersLeavingLetterLabel]");
                    });
                    quest.Leave(pawns, null, sendStandardLetter: false, leaveOnCleanup: false, lodgerArrestedOrRecruited);
                }, null, null, null, reactivatable: false, null, null, isQuestTimeout: false, "GuestsDepartsIn".Translate(), "GuestsDepartsOn".Translate(), "QuestDelay");
            }
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalDestroyed_BadThought, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgerDiedMemoryThoughtLetterText]", null, "[lodgerDiedMemoryThoughtLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalDestroyed_AssaultColony, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgerDiedAttackPlayerLetterText]", null, "[lodgerDiedAttackPlayerLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalDestroyed_LeaveColony, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgerDiedLeaveMapLetterText]", null, "[lodgerDiedLeaveMapLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalLast_Destroyed, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgersAllDiedLetterText]", null, "[lodgersAllDiedLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalArrested_BadThought, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgerArrestedMemoryThoughtLetterText]", null, "[lodgerArrestedMemoryThoughtLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalArrested_AssaultColony, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgerArrestedAttackPlayerLetterText]", null, "[lodgerArrestedAttackPlayerLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalArrested_LeaveColony, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgerArrestedLeaveMapLetterText]", null, "[lodgerArrestedLeaveMapLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalLast_Arrested, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgersAllArrestedLetterText]", null, "[lodgersAllArrestedLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalSurgeryViolation_BadThought, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgerViolatedMemoryThoughtLetterText]", null, "[lodgerViolatedMemoryThoughtLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalSurgeryViolation_AssaultColony, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgerViolatedAttackPlayerLetterText]", null, "[lodgerViolatedAttackPlayerLetterLabel]");
            quest.Letter(LetterDefOf.NegativeEvent, questPart_RefugeeInteractions.outSignalSurgeryViolation_LeaveColony, null, null, null, useColonistsFromCaravanArg: false, QuestPart.SignalListenMode.OngoingOnly, null, filterDeadPawnsFromLookTargets: false, "[lodgerViolatedLeaveMapLetterText]", null, "[lodgerViolatedLeaveMapLetterLabel]");
            quest.AddMemoryThought(pawns, ThoughtDefOf.OtherTravelerDied, questPart_RefugeeInteractions.outSignalDestroyed_BadThought);
            quest.AddMemoryThought(pawns, ThoughtDefOf.OtherTravelerArrested, questPart_RefugeeInteractions.outSignalArrested_BadThought);
            quest.AddMemoryThought(pawns, ThoughtDefOf.OtherTravelerSurgicallyViolated, questPart_RefugeeInteractions.outSignalSurgeryViolation_BadThought);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalDestroyed_AssaultColony, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalDestroyed_LeaveColony, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalLast_Destroyed);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalArrested_AssaultColony, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalArrested_LeaveColony, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalLast_Arrested);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalSurgeryViolation_AssaultColony, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalSurgeryViolation_LeaveColony, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalLast_Kidnapped, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.Fail, 0, null, questPart_RefugeeInteractions.outSignalLast_Banished, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.Success, 0, null, questPart_RefugeeInteractions.outSignalLast_Recruited, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.End(QuestEndOutcome.Success, 0, null, questPart_RefugeeInteractions.outSignalLast_LeftMapAllNotHealthy, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            quest.SignalPass(delegate
            {
                if (Rand.Chance(0.5f))
                {
                    float val = (float)(lodgerCount * questDurationDays) * 55f;
                    FloatRange marketValueRange = new FloatRange(0.7f, 1.3f) * val * Find.Storyteller.difficultyValues.EffectiveQuestRewardValueFactor;
                    quest.AddQuestRefugeeDelayedReward(quest.AccepterPawn, faction, pawns, marketValueRange);
                }
                quest.End(QuestEndOutcome.Success, 0, null, null, QuestPart.SignalListenMode.OngoingOnly, sendStandardLetter: true);
            }, questPart_RefugeeInteractions.outSignalLast_LeftMapAllHealthy);
            slate.Set("lodgerCount", lodgerCount);
            slate.Set("lodgersCountMinusOne", lodgerCount - 1);
            slate.Set("asker", var);
            slate.Set("map", map);
            slate.Set("questDurationTicks", questDurationTicks);
            slate.Set("faction", faction);
        }
 protected override bool TestRunInt(Slate slate)
 {
     return(QuestGen_Get.GetMap() != null);
 }