public static void QuestExample()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (QuestScriptDef allDef in DefDatabase <QuestScriptDef> .AllDefs)
            {
                QuestScriptDef localRuleDef = allDef;
                list.Add(new DebugMenuOption(localRuleDef.defName, DebugMenuOptionMode.Action, delegate
                {
                    List <DebugMenuOption> list2 = new List <DebugMenuOption>();
                    float localPoints            = default(float);
                    foreach (float item in DebugActionsUtility.PointsOptions(extended: true))
                    {
                        localPoints = item;
                        list2.Add(new DebugMenuOption(item.ToString("F0"), DebugMenuOptionMode.Action, delegate
                        {
                            Slate slate = new Slate();
                            slate.Set("points", localPoints);
                            Quest saveable = QuestGen.Generate(localRuleDef, slate);
                            Log.Message(Scribe.saver.DebugOutputFor(saveable));
                        }));
                    }
                    Find.WindowStack.Add(new Dialog_DebugOptionListLister(list2));
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
Пример #2
0
        public virtual List <QuestInfo> GenerateQuests(QuestGiverManager questGiverManager)
        {
            List <QuestInfo> generatedQuests = new List <QuestInfo>();
            var questCountToGenerate         = def.maximumAvailableQuestCount != -1 ? (def.maximumAvailableQuestCount - questGiverManager.AvailableQuests.Count) : 100;
            var points             = StorytellerUtility.DefaultThreatPointsNow(Find.World);
            var questDefsToProcess = DefDatabase <QuestScriptDef> .AllDefs.Where(x => !x.isRootSpecial && x.IsRootAny).ToList();

            Log.Message($"quest count to generate: {questCountToGenerate} - points: {points}");

            while (generatedQuests.Count < questCountToGenerate)
            {
                if (!questDefsToProcess.Any())
                {
                    break;
                }
                var newQuestCandidate = questDefsToProcess.RandomElement();
                questDefsToProcess.Remove(newQuestCandidate);
                Log.Message($"newQuestCandidate is choosen: {newQuestCandidate}");
                try
                {
                    Slate slate = new Slate();
                    slate.Set("points", points);
                    if (newQuestCandidate == QuestScriptDefOf.LongRangeMineralScannerLump)
                    {
                        slate.Set("targetMineable", ThingDefOf.MineableGold);
                        slate.Set("worker", PawnsFinder.AllMaps_FreeColonists.FirstOrDefault());
                    }
                    if (newQuestCandidate.CanRun(slate))
                    {
                        Quest quest = QuestGen.Generate(newQuestCandidate, slate);
                        if (def.currency.Allows(questGiverManager, quest, Patch_AddSlateQuestTags.slate, out QuestInfo questInfo))
                        {
                            generatedQuests.Add(questInfo);
                            Log.Message($"Added new quest {quest.name}");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Message("Exception: " + ex);
                }
            }
            return(generatedQuests);
        }
Пример #3
0
        public static void Postfix(QuestScriptDef root, Slate initialVars, ref Quest __result)
        {
            if (RealInvolvedFactions(__result).Any(f => f.def.HasModExtension <ExcludeFromQuestsExtension>()))
            {
                // Log.Message($"QuestGen Generate - {__result.name} contains not allowed faction(s) - Regenerating quest...");
                Quest newResult = null;

                while (newResult == null || RealInvolvedFactions(newResult).Any(f => f.def.HasModExtension <ExcludeFromQuestsExtension>()))
                {
                    newResult = QuestGen.Generate(root, initialVars);
                    iterationNumber++;
                }

                __result = newResult;
            }
            if (iterationNumber > 0)
            {
                // Log.Message($"QuestGen Generate - Regenerated quest {iterationNumber} time - Regeneration ended...");
                iterationNumber = 0;
            }
        }
Пример #4
0
 public void UnlockQuest(Pawn pawn)
 {
     if (this.questToUnlock != null)
     {
         Slate slate = new Slate();
         slate.Set("points", StorytellerUtility.DefaultThreatPointsNow(pawn.Map));
         if (this.questToUnlock == QuestScriptDefOf.LongRangeMineralScannerLump)
         {
             slate.Set("targetMineable", ThingDefOf.MineableGold);
             slate.Set("worker", PawnsFinder.AllMaps_FreeColonists.FirstOrDefault());
         }
         Quest quest = QuestGen.Generate(this.questToUnlock, slate);
         Find.SignalManager.RegisterReceiver(quest);
         List <QuestPart> partsListForReading = quest.PartsListForReading;
         for (int i = 0; i < partsListForReading.Count; i++)
         {
             partsListForReading[i].PostQuestAdded();
         }
         quest.Initiate();
         this.used = true;
         Find.LetterStack.ReceiveLetter("VBE.LocationsOpened".Translate(), "VBE.LocationsOpenedDesc".Translate(), LetterDefOf.NeutralEvent,
                                        quest.QuestLookTargets.Where(t => t.IsWorldTarget || t.IsMapTarget).FirstOrDefault());
     }
 }
        public static void QuestRewardsSampled()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (QuestScriptDef quest in DefDatabase <QuestScriptDef> .AllDefsListForReading)
            {
                if (!quest.IsRootAny)
                {
                    continue;
                }
                QuestScriptDef localQuest = quest;
                list.Add(new DebugMenuOption(quest.defName, DebugMenuOptionMode.Action, delegate
                {
                    Dictionary <float, int> numQuestsRating1           = new Dictionary <float, int>();
                    Dictionary <float, int> numQuestsRating2           = new Dictionary <float, int>();
                    Dictionary <float, int> numQuestsRating3           = new Dictionary <float, int>();
                    Dictionary <float, float> rewardRating1min         = new Dictionary <float, float>();
                    Dictionary <float, float> rewardRating1max         = new Dictionary <float, float>();
                    Dictionary <float, float> rewardRating1accumulated = new Dictionary <float, float>();
                    Dictionary <float, float> rewardRating2min         = new Dictionary <float, float>();
                    Dictionary <float, float> rewardRating2max         = new Dictionary <float, float>();
                    Dictionary <float, float> rewardRating2accumulated = new Dictionary <float, float>();
                    Dictionary <float, float> rewardRating3min         = new Dictionary <float, float>();
                    Dictionary <float, float> rewardRating3max         = new Dictionary <float, float>();
                    Dictionary <float, float> rewardRating3accumulated = new Dictionary <float, float>();
                    float[] questRewardDebugPointLevels = QuestRewardDebugPointLevels;
                    foreach (float num in questRewardDebugPointLevels)
                    {
                        if (!(num < quest.rootMinPoints))
                        {
                            numQuestsRating1.Add(num, 0);
                            numQuestsRating2.Add(num, 0);
                            numQuestsRating3.Add(num, 0);
                            Slate slate = new Slate();
                            slate.Set("points", num);
                            slate.Set("debugDontGenerateRewardThings", var: true);
                            rewardRating1min.Add(num, 9999999f);
                            rewardRating2min.Add(num, 9999999f);
                            rewardRating3min.Add(num, 9999999f);
                            rewardRating1max.Add(num, -9999999f);
                            rewardRating2max.Add(num, -9999999f);
                            rewardRating3max.Add(num, -9999999f);
                            rewardRating1accumulated.Add(num, 0f);
                            rewardRating2accumulated.Add(num, 0f);
                            rewardRating3accumulated.Add(num, 0f);
                            for (int j = 0; j < 20; j++)
                            {
                                lastQuestGeneratedRewardValue = 0f;
                                Quest quest2 = QuestGen.Generate(localQuest, slate.DeepCopy());
                                float num2   = lastQuestGeneratedRewardValue;
                                if (quest2.challengeRating == 1)
                                {
                                    numQuestsRating1[num]++;
                                    rewardRating1min[num]          = Mathf.Min(rewardRating1min[num], num2);
                                    rewardRating1max[num]          = Mathf.Max(rewardRating1max[num], num2);
                                    rewardRating1accumulated[num] += num2;
                                }
                                else if (quest2.challengeRating == 2)
                                {
                                    numQuestsRating2[num]++;
                                    rewardRating2min[num]          = Mathf.Min(rewardRating2min[num], num2);
                                    rewardRating2max[num]          = Mathf.Max(rewardRating2max[num], num2);
                                    rewardRating2accumulated[num] += num2;
                                }
                                else if (quest2.challengeRating == 3)
                                {
                                    numQuestsRating3[num]++;
                                    rewardRating3min[num]          = Mathf.Min(rewardRating3min[num], num2);
                                    rewardRating3max[num]          = Mathf.Max(rewardRating3max[num], num2);
                                    rewardRating3accumulated[num] += num2;
                                }
                            }
                        }
                    }
                    DebugTables.MakeTablesDialog(QuestRewardDebugPointLevels, new TableDataGetter <float>("points", (float v) => v.ToString()), new TableDataGetter <float>("rating 1\nquest count\nof " + 20, (float v) => numQuestsRating1[v].ToString()), new TableDataGetter <float>("rating 1\nrewardValue\nmin", (float v) => (rewardRating1min[v] != 9999999f) ? ((int)rewardRating1min[v]).ToString() : "-"), new TableDataGetter <float>("rating 1\nrewardValue\navg", (float v) => (!(rewardRating1accumulated[v] <= 0f)) ? ((int)(rewardRating1accumulated[v] / (float)numQuestsRating1[v])).ToString() : "-"), new TableDataGetter <float>("rating 1\nrewardValue\nmax", (float v) => (rewardRating1max[v] != -9999999f) ? ((int)rewardRating1max[v]).ToString() : "-"), new TableDataGetter <float>("rating 2\nquest count\nof " + 20, (float v) => numQuestsRating2[v].ToString()), new TableDataGetter <float>("rating 2\nrewardValue\nmin", (float v) => (rewardRating2min[v] != 9999999f) ? ((int)rewardRating2min[v]).ToString() : "-"), new TableDataGetter <float>("rating 2\nrewardValue\navg", (float v) => (!(rewardRating2accumulated[v] <= 0f)) ? ((int)(rewardRating2accumulated[v] / (float)numQuestsRating2[v])).ToString() : "-"), new TableDataGetter <float>("rating 2\nrewardValue\nmax", (float v) => (rewardRating2max[v] != -9999999f) ? ((int)rewardRating2max[v]).ToString() : "-"), new TableDataGetter <float>("rating 3\nquest count\nof " + 20, (float v) => numQuestsRating3[v].ToString()), new TableDataGetter <float>("rating 3\nrewardValue\nmin", (float v) => (rewardRating3min[v] != 9999999f) ? ((int)rewardRating3min[v]).ToString() : "-"), new TableDataGetter <float>("rating 3\nrewardValue\navg", (float v) => (!(rewardRating3accumulated[v] <= 0f)) ? ((int)(rewardRating3accumulated[v] / (float)numQuestsRating3[v])).ToString() : "-"), new TableDataGetter <float>("rating 3\nrewardValue\nmax", (float v) => (rewardRating3max[v] != -9999999f) ? ((int)rewardRating3max[v]).ToString() : "-"));
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
        private static void RoyalFavorAvailability()
        {
            StorytellerCompProperties_OnOffCycle storytellerCompProperties_OnOffCycle = (StorytellerCompProperties_OnOffCycle)StorytellerDefOf.Cassandra.comps.Find(delegate(StorytellerCompProperties x)
            {
                StorytellerCompProperties_OnOffCycle storytellerCompProperties_OnOffCycle2 = x as StorytellerCompProperties_OnOffCycle;
                if (storytellerCompProperties_OnOffCycle2 == null)
                {
                    return(false);
                }
                if (storytellerCompProperties_OnOffCycle2.IncidentCategory != IncidentCategoryDefOf.GiveQuest)
                {
                    return(false);
                }
                return((storytellerCompProperties_OnOffCycle2.enableIfAnyModActive != null && storytellerCompProperties_OnOffCycle2.enableIfAnyModActive.Any((string m) => m.ToLower() == ModContentPack.RoyaltyModPackageId)) ? true : false);
            });
            float       onDays      = storytellerCompProperties_OnOffCycle.onDays;
            float       average     = storytellerCompProperties_OnOffCycle.numIncidentsRange.Average;
            float       num         = average / onDays;
            SimpleCurve simpleCurve = new SimpleCurve
            {
                new CurvePoint(0f, 35f),
                new CurvePoint(15f, 150f),
                new CurvePoint(150f, 5000f)
            };
            int num2 = 0;
            List <RoyalTitleDef> royalTitlesAwardableInSeniorityOrderForReading = FactionDefOf.Empire.RoyalTitlesAwardableInSeniorityOrderForReading;

            for (int i = 0; i < royalTitlesAwardableInSeniorityOrderForReading.Count; i++)
            {
                num2 += royalTitlesAwardableInSeniorityOrderForReading[i].favorCost;
                if (royalTitlesAwardableInSeniorityOrderForReading[i] == RoyalTitleDefOf.Count)
                {
                    break;
                }
            }
            float      num3       = 0f;
            int        num4       = 0;
            int        num5       = 0;
            int        num6       = 0;
            int        num7       = 0;
            int        num8       = -1;
            int        num9       = -1;
            int        num10      = -1;
            int        ticksGame  = Find.TickManager.TicksGame;
            StoryState storyState = new StoryState(Find.World);

            for (int j = 0; j < 200; j++)
            {
                Find.TickManager.DebugSetTicksGame(j * 60000);
                num3 += num * storytellerCompProperties_OnOffCycle.acceptFractionByDaysPassedCurve.Evaluate(j);
                while (num3 >= 1f)
                {
                    num3 -= 1f;
                    num4++;
                    float points = simpleCurve.Evaluate(j);
                    Slate slate  = new Slate();
                    slate.Set("points", points);
                    QuestScriptDef questScriptDef = DefDatabase <QuestScriptDef> .AllDefsListForReading.Where((QuestScriptDef x) => x.IsRootRandomSelected && x.CanRun(slate)).RandomElementByWeight((QuestScriptDef x) => NaturalRandomQuestChooser.GetNaturalRandomSelectionWeight(x, points, storyState));

                    Quest quest = QuestGen.Generate(questScriptDef, slate);
                    if (quest.InvolvedFactions.Contains(Faction.Empire))
                    {
                        num7++;
                    }
                    QuestPart_GiveRoyalFavor questPart_GiveRoyalFavor = (QuestPart_GiveRoyalFavor)quest.PartsListForReading.Find((QuestPart x) => x is QuestPart_GiveRoyalFavor);
                    if (questPart_GiveRoyalFavor != null)
                    {
                        num5 += questPart_GiveRoyalFavor.amount;
                        num6++;
                        if (num5 >= num2 && num8 < 0)
                        {
                            num8 = j;
                        }
                        if (num9 < 0 || questPart_GiveRoyalFavor.amount < num9)
                        {
                            num9 = questPart_GiveRoyalFavor.amount;
                        }
                        if (num10 < 0 || questPart_GiveRoyalFavor.amount > num10)
                        {
                            num10 = questPart_GiveRoyalFavor.amount;
                        }
                    }
                    storyState.RecordRandomQuestFired(questScriptDef);
                    quest.CleanupQuestParts();
                }
            }
            Find.TickManager.DebugSetTicksGame(ticksGame);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Results for: Days=" + 200 + ", intervalDays=" + onDays + ", questsPerInterval=" + average + ":");
            stringBuilder.AppendLine("Quests: " + num4);
            stringBuilder.AppendLine("Quests with honor: " + num6);
            stringBuilder.AppendLine("Quests from Empire: " + num7);
            stringBuilder.AppendLine("Min honor reward: " + num9);
            stringBuilder.AppendLine("Max honor reward: " + num10);
            stringBuilder.AppendLine("Total honor: " + num5);
            stringBuilder.AppendLine("Honor required for Count: " + num2);
            stringBuilder.AppendLine("Count title possible on day: " + num8);
            Log.Message(stringBuilder.ToString());
        }
Пример #7
0
        public void GenerateQuest()
        {
            List <QuestScriptDef> list = new List <QuestScriptDef>();

            if (this.specificQuests != null && this.specificQuests.Count > 0)
            {
                list = this.specificQuests;
            }
            else
            {
                list = DefDatabase <QuestScriptDef> .AllDefs
                       .Where(x => !x.isRootSpecial && x.root is QuestNode_Sequence sequence &&
                              sequence.nodes.Where(y => y is QuestNode_GetPawn getPawn &&
                                                   getPawn.storeAs.ToString() == "asker" || y is QuestNode_GetFaction getFaction &&
                                                   (getFaction.storeAs.ToString() == "faction" ||
                                                    getFaction.storeAs.ToString() == "askerFaction")).Count() > 0).InRandomOrder().ToList();
            }
            var questGiver = this.parent as Pawn;

            Log.Message(" - GenerateQuest - foreach (var script in DefDatabase<QuestScriptDef>.AllDefs.Where" +
                        "(x => x.root is QuestNode_Sequence sequence - 47", true);
            foreach (var script in list)
            {
                if (script.root is QuestNode_Sequence sequence)
                {
                    var newRoot = new QuestNode_Sequence();
                    var test2   = newRoot as QuestNode;
                    this.GetNewRoot(script.root, ref test2, questGiver, script);
                    var oldRoot = script.root;
                    //this.TestNode(script.root, questGiver, script);
                    var test3 = test2 as QuestNode_Sequence;
                    var test4 = test3.nodes.First();
                    //this.TestNode(test4, questGiver, script);
                    script.root = test4;
                    try
                    {
                        var slate = new Slate();
                        slate.Set <Pawn>("asker", questGiver, false);
                        slate.Set <Pawn>("joiner", questGiver, false);
                        slate.Set <Map>("map", this.parent.Map, false);
                        FloatRange value = StorytellerUtility.DefaultThreatPointsNow(this.parent.Map)
                                           * new FloatRange(0.7f, 1.3f);
                        ThingSetMakerParams parms2 = default(ThingSetMakerParams);
                        parms2.totalMarketValueRange = new FloatRange?(value);
                        parms2.makingFaction         = questGiver.Faction;
                        List <Thing> items            = ThingSetMakerDefOf.Reward_ItemsStandard.root.Generate(parms2);
                        var          TotalMarketValue = items.Sum(x => x.def.BaseMarketValue);

                        slate.Set <List <Thing> >("itemsReward_items", items, false);
                        slate.Set <float>("itemsReward_totalMarketValue", TotalMarketValue, false);
                        slate.Set <IEnumerable <ThingDef> >("itemStashThings", items.Select(x => x.def), false);
                        var enemyFactions = Find.FactionManager.AllFactions.Where
                                                (x => x != questGiver.Faction &&
                                                x.RelationWith(questGiver.Faction).kind == FactionRelationKind.Hostile);
                        if (enemyFactions != null && enemyFactions.Count() > 0)
                        {
                            var enemyFaction = enemyFactions.RandomElement();
                            slate.Set <Faction>("enemyFaction", enemyFaction);
                        }
                        slate.Set <ThingDef>("itemStashSingleThing", ThingDefOf.AIPersonaCore, false);
                        slate.Set <ThingDef>("targetMineable", ThingDefOf.MineableGold, false);
                        slate.Set <Pawn>("worker", PawnsFinder.AllMaps_FreeColonists.FirstOrDefault <Pawn>(), false);
                        slate.Set <float>("points", StorytellerUtility.DefaultThreatPointsNow(this.parent.Map), false);
                        slate.Set <Faction>("faction", questGiver.Faction, false);
                        slate.Set <Faction>("askerFaction", questGiver.Faction, false);

                        Find.CurrentMap.StoryState.RecordRandomQuestFired(script);
                        if (script.IsRootDecree)
                        {
                            Pawn pawn = slate.Get <Pawn>("asker", null, false);
                            if (pawn.royalty.AllTitlesForReading.NullOrEmpty <RoyalTitle>())
                            {
                                pawn.royalty.SetTitle(Faction.OfEmpire, RoyalTitleDefOf.Knight, false, false, true);
                                Messages.Message("Dev: Gave " + RoyalTitleDefOf.Knight.label + " title to " + pawn.LabelCap, pawn, MessageTypeDefOf.NeutralEvent, false);
                            }
                        }
                        if (script.CanRun(slate))
                        {
                            var quest = QuestGen.Generate(script, slate);
                            Find.QuestManager.Add(quest);
                            Log.Message(script + " - " + quest.name + " - " + quest.description);
                            Find.LetterStack.ReceiveLetter(quest.name, quest.description,
                                                           LetterDefOf.NeutralEvent, null, null, quest, null, null);
                            script.root = oldRoot;
                            //break;
                        }
                        else
                        {
                            Log.Message("Cant run " + script);
                            script.root = oldRoot;
                        }
                    }
                    catch { }
                }
            }
        }