protected override void RunInt()
        {
            Slate slate = QuestGen.slate;
            PawnsArrivalModeDef   pawnsArrivalModeDef = arrivalMode.GetValue(slate) ?? PawnsArrivalModeDefOf.EdgeWalkIn;
            QuestPart_PawnsArrive pawnsArrive         = new QuestPart_PawnsArrive();

            pawnsArrive.inSignal = QuestGenUtility.HardcodedSignalWithQuestID(inSignal.GetValue(slate)) ?? QuestGen.slate.Get <string>("inSignal");
            pawnsArrive.pawns.AddRange(pawns.GetValue(slate));
            pawnsArrive.arrivalMode = pawnsArrivalModeDef;
            pawnsArrive.joinPlayer  = joinPlayer.GetValue(slate);
            pawnsArrive.mapParent   = QuestGen.slate.Get <Map>("map").Parent;
            if (pawnsArrivalModeDef.walkIn)
            {
                pawnsArrive.spawnNear = walkInSpot.GetValue(slate) ?? QuestGen.slate.Get <IntVec3?>("walkInSpot") ?? IntVec3.Invalid;
            }
            if (!customLetterLabel.GetValue(slate).NullOrEmpty() || customLetterLabelRules.GetValue(slate) != null)
            {
                QuestGen.AddTextRequest("root", delegate(string x)
                {
                    pawnsArrive.customLetterLabel = x;
                }, QuestGenUtility.MergeRules(customLetterLabelRules.GetValue(slate), customLetterLabel.GetValue(slate), "root"));
            }
            if (!customLetterText.GetValue(slate).NullOrEmpty() || customLetterTextRules.GetValue(slate) != null)
            {
                QuestGen.AddTextRequest("root", delegate(string x)
                {
                    pawnsArrive.customLetterText = x;
                }, QuestGenUtility.MergeRules(customLetterTextRules.GetValue(slate), customLetterText.GetValue(slate), "root"));
            }
            QuestGen.quest.AddPart(pawnsArrive);
            if (!isSingleReward.GetValue(slate))
            {
                return;
            }
            QuestPart_Choice questPart_Choice = new QuestPart_Choice();

            questPart_Choice.inSignalChoiceUsed = pawnsArrive.inSignal;
            QuestPart_Choice.Choice choice = new QuestPart_Choice.Choice();
            choice.questParts.Add(pawnsArrive);
            foreach (Pawn pawn in pawnsArrive.pawns)
            {
                choice.rewards.Add(new Reward_Pawn
                {
                    pawn          = pawn,
                    detailsHidden = rewardDetailsHidden.GetValue(slate)
                });
            }
            questPart_Choice.choices.Add(choice);
            QuestGen.quest.AddPart(questPart_Choice);
        }
Beispiel #2
0
        public static void PawnsArrive(this Quest quest, IEnumerable <Pawn> pawns, string inSignal = null, MapParent mapParent = null, PawnsArrivalModeDef arrivalMode = null, bool joinPlayer = false, IntVec3?walkInSpot = null, string customLetterLabel = null, string customLetterText = null, RulePack customLetterLabelRules = null, RulePack customLetterTextRules = null, bool isSingleReward = false, bool rewardDetailsHidden = false)
        {
            _ = QuestGen.slate;
            PawnsArrivalModeDef   pawnsArrivalModeDef = arrivalMode ?? PawnsArrivalModeDefOf.EdgeWalkIn;
            QuestPart_PawnsArrive pawnsArrive         = new QuestPart_PawnsArrive();

            pawnsArrive.inSignal = QuestGenUtility.HardcodedSignalWithQuestID(inSignal) ?? QuestGen.slate.Get <string>("inSignal");
            pawnsArrive.pawns.AddRange(pawns);
            pawnsArrive.arrivalMode = pawnsArrivalModeDef;
            pawnsArrive.joinPlayer  = joinPlayer;
            pawnsArrive.mapParent   = mapParent ?? QuestGen.slate.Get <Map>("map").Parent;
            if (pawnsArrivalModeDef.walkIn)
            {
                pawnsArrive.spawnNear = walkInSpot ?? QuestGen.slate.Get <IntVec3?>("walkInSpot") ?? IntVec3.Invalid;
            }
            if (!customLetterLabel.NullOrEmpty() || customLetterLabelRules != null)
            {
                QuestGen.AddTextRequest("root", delegate(string x)
                {
                    pawnsArrive.customLetterLabel = x;
                }, QuestGenUtility.MergeRules(customLetterLabelRules, customLetterLabel, "root"));
            }
            if (!customLetterText.NullOrEmpty() || customLetterTextRules != null)
            {
                QuestGen.AddTextRequest("root", delegate(string x)
                {
                    pawnsArrive.customLetterText = x;
                }, QuestGenUtility.MergeRules(customLetterTextRules, customLetterText, "root"));
            }
            QuestGen.quest.AddPart(pawnsArrive);
            if (!isSingleReward)
            {
                return;
            }
            QuestPart_Choice questPart_Choice = new QuestPart_Choice();

            questPart_Choice.inSignalChoiceUsed = pawnsArrive.inSignal;
            QuestPart_Choice.Choice choice = new QuestPart_Choice.Choice();
            choice.questParts.Add(pawnsArrive);
            foreach (Pawn pawn in pawnsArrive.pawns)
            {
                choice.rewards.Add(new Reward_Pawn
                {
                    pawn          = pawn,
                    detailsHidden = rewardDetailsHidden
                });
            }
            questPart_Choice.choices.Add(choice);
            QuestGen.quest.AddPart(questPart_Choice);
        }
        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);
        }