public override IncidentParms GenerateParms(IncidentCategoryDef incCat, IIncidentTarget target) { IncidentParms incidentParms = base.GenerateParms(incCat, target); incidentParms.questScriptDef = NaturalRandomQuestChooser.ChooseNaturalRandomQuest(incidentParms.points, target); return(incidentParms); }
public override bool TryExecuteEvent() { try { Slate slate = new Slate(); float points = StorytellerUtility.DefaultSiteThreatPointsNow(); QuestScriptDef script = NaturalRandomQuestChooser.ChooseNaturalRandomQuest(points, Find.CurrentMap); SetPoints(script, slate, points); GenerateQuest(script, slate); } catch (Exception ex) { Log.Error($"Failed to generate random quest reward. Exception: {ex.Message}"); return(false); } return(true); }
private static void GenerateQuests(int count, bool logDescOnly) { Action <QuestScriptDef, Slate> generateQuest = delegate(QuestScriptDef script, Slate slate) { int num = 0; for (int i = 0; i < count; i++) { if (script.IsRootDecree) { Pawn pawn = slate.Get <Pawn>("asker"); if (pawn.royalty.AllTitlesForReading.NullOrEmpty()) { pawn.royalty.SetTitle(Faction.Empire, RoyalTitleDefOf.Knight, grantRewards: false); Messages.Message("Dev: Gave " + RoyalTitleDefOf.Knight.label + " title to " + pawn.LabelCap, pawn, MessageTypeDefOf.NeutralEvent, historical: false); } Find.CurrentMap.StoryState.RecordDecreeFired(script); } if (count != 1 && !script.CanRun(slate)) { num++; } else if (!logDescOnly) { Quest quest = QuestUtility.GenerateQuestAndMakeAvailable(script, slate); if (!quest.hidden) { QuestUtility.SendLetterQuestAvailable(quest); } } else { Quest quest2 = QuestUtility.GenerateQuestAndMakeAvailable(script, slate); string text2 = quest2.name; if (slate.Exists("points")) { text2 = text2 + "(" + slate.Get("points", 0f) + " points)"; } if (slate.Exists("population")) { text2 = text2 + "(" + slate.Get("population", 0) + " population)"; } text2 += "\n--------------\n" + quest2.description + "\n--------------"; Log.Message(text2); Find.QuestManager.Remove(quest2); } } if (num != 0) { Messages.Message("Dev: Generated only " + (count - num) + " quests.", MessageTypeDefOf.RejectInput, historical: false); } }; Action <QuestScriptDef, Slate, Action> selectPoints = delegate(QuestScriptDef script, Slate slate, Action next) { List <DebugMenuOption> list3 = new List <DebugMenuOption>(); float localPoints = default(float); foreach (float item in DebugActionsUtility.PointsOptions(extended: false)) { localPoints = item; string text = item.ToString("F0") + " points"; if (script != null) { if (script.IsRootDecree) { slate.Set("asker", PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists.RandomElement()); } if (script == QuestScriptDefOf.LongRangeMineralScannerLump) { slate.Set("targetMineableThing", ThingDefOf.Gold); slate.Set("targetMineable", ThingDefOf.MineableGold); slate.Set("worker", PawnsFinder.AllMaps_FreeColonists.FirstOrDefault()); } slate.Set("points", localPoints); if (!script.CanRun(slate)) { text += " [not now]"; } } list3.Add(new DebugMenuOption(text, DebugMenuOptionMode.Action, delegate { slate.Set("points", localPoints); next(); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list3)); }; Action <Slate, Action> selectPopulation = delegate(Slate slate, Action next) { List <DebugMenuOption> list2 = new List <DebugMenuOption> { new DebugMenuOption("*Don't set", DebugMenuOptionMode.Action, next) }; int localPopulation = default(int); foreach (int item2 in DebugActionsUtility.PopulationOptions()) { localPopulation = item2; list2.Add(new DebugMenuOption(item2.ToString("F0") + " colony population", DebugMenuOptionMode.Action, delegate { slate.Set("population", localPopulation); next(); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list2)); }; List <DebugMenuOption> list = new List <DebugMenuOption>(); list.Add(new DebugMenuOption("*Natural random", DebugMenuOptionMode.Action, delegate { Slate slate3 = new Slate(); selectPoints(null, slate3, delegate { float points = slate3.Get("points", 0f); QuestScriptDef script2 = NaturalRandomQuestChooser.ChooseNaturalRandomQuest(points, Find.CurrentMap); if (script2.affectedByPopulation) { selectPopulation(slate3, delegate { generateQuest(script2, slate3); }); } else { generateQuest(script2, slate3); } }); })); foreach (QuestScriptDef scriptDef in DefDatabase <QuestScriptDef> .AllDefs.Where((QuestScriptDef x) => x.IsRootAny)) { QuestScriptDef localScriptDef = scriptDef; string defName = localScriptDef.defName; list.Add(new DebugMenuOption(defName, DebugMenuOptionMode.Action, delegate { Slate slate2 = new Slate(); if (localScriptDef.affectedByPoints && localScriptDef.affectedByPopulation) { selectPoints(localScriptDef, slate2, delegate { selectPopulation(slate2, delegate { generateQuest(localScriptDef, slate2); }); }); } else if (scriptDef.affectedByPoints) { selectPoints(localScriptDef, slate2, delegate { generateQuest(localScriptDef, slate2); }); } else if (localScriptDef.affectedByPopulation) { selectPopulation(slate2, delegate { generateQuest(localScriptDef, slate2); }); } else { generateQuest(localScriptDef, slate2); } })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list.OrderBy((DebugMenuOption op) => op.label))); }
public static void DecreeSelectionWeightsNow() { IIncidentTarget target = Find.CurrentMap; string label = "selection weight now\ntarget: " + target.ToString(); DebugTables.MakeTablesDialog(DefDatabase <QuestScriptDef> .AllDefsListForReading.Where((QuestScriptDef x) => x.IsRootDecree), new TableDataGetter <QuestScriptDef>("defName", (QuestScriptDef x) => x.defName), new TableDataGetter <QuestScriptDef>(label, (QuestScriptDef x) => NaturalRandomQuestChooser.GetNaturalDecreeSelectionWeight(x, target.StoryState).ToString("F3"))); }
public static void QuestSelectionWeightsNow() { List <DebugMenuOption> list = new List <DebugMenuOption>(); foreach (float item in DebugActionsUtility.PointsOptions(extended: true)) { float localPoints = item; list.Add(new DebugMenuOption(localPoints + " points", DebugMenuOptionMode.Action, delegate { IIncidentTarget target = Find.CurrentMap; string label = "selection weight now\ntarget: " + target.ToString() + "\npoints: " + localPoints.ToString("F0") + "\npopIntentQuest: " + StorytellerUtilityPopulation.PopulationIntentForQuest; DebugTables.MakeTablesDialog(DefDatabase <QuestScriptDef> .AllDefsListForReading.Where((QuestScriptDef x) => x.IsRootRandomSelected), new TableDataGetter <QuestScriptDef>("defName", (QuestScriptDef x) => x.defName), new TableDataGetter <QuestScriptDef>(label, (QuestScriptDef x) => NaturalRandomQuestChooser.GetNaturalRandomSelectionWeight(x, localPoints, target.StoryState).ToString("F3")), new TableDataGetter <QuestScriptDef>("increases\npopulation", (QuestScriptDef x) => x.rootIncreasesPopulation.ToStringCheckBlank()), new TableDataGetter <QuestScriptDef>("recency\nindex", (QuestScriptDef x) => (!target.StoryState.RecentRandomQuests.Contains(x)) ? "" : target.StoryState.RecentRandomQuests.IndexOf(x).ToString()), new TableDataGetter <QuestScriptDef>("total\nselection\nchance\nnow", (QuestScriptDef x) => NaturalRandomQuestChooser.DebugTotalNaturalRandomSelectionWeight(x, localPoints, target).ToString("F3"))); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list.OrderBy((DebugMenuOption op) => op.label))); }
private static void GenerateQuests(int count, bool logDescOnly) { List <DebugMenuOption> list = new List <DebugMenuOption>(); float localPoints = default(float); Slate testSlate = default(Slate); Action <QuestScriptDef> generate = delegate(QuestScriptDef script) { List <DebugMenuOption> list2 = new List <DebugMenuOption>(); foreach (float item in DebugActionsUtility.PointsOptions(extended: false)) { localPoints = item; string text = item.ToString("F0"); testSlate = new Slate(); testSlate.Set("points", localPoints); if (script != null) { if (script.IsRootDecree) { testSlate.Set("asker", PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonists.RandomElement()); } if (script == QuestScriptDefOf.LongRangeMineralScannerLump) { testSlate.Set("targetMineable", ThingDefOf.MineableGold); testSlate.Set("worker", PawnsFinder.AllMaps_FreeColonists.FirstOrDefault()); } if (!script.CanRun(testSlate)) { text += " [not now]"; } } list2.Add(new DebugMenuOption(text, DebugMenuOptionMode.Action, delegate { int num = 0; bool flag = script == null; for (int i = 0; i < count; i++) { if (flag) { script = NaturalRandomQuestChooser.ChooseNaturalRandomQuest(localPoints, Find.CurrentMap); Find.CurrentMap.StoryState.RecordRandomQuestFired(script); } if (script.IsRootDecree) { Pawn pawn = testSlate.Get <Pawn>("asker"); if (pawn.royalty.AllTitlesForReading.NullOrEmpty()) { pawn.royalty.SetTitle(Faction.Empire, RoyalTitleDefOf.Knight, grantRewards: false); Messages.Message("Dev: Gave " + RoyalTitleDefOf.Knight.label + " title to " + pawn.LabelCap, pawn, MessageTypeDefOf.NeutralEvent, historical: false); } Find.CurrentMap.StoryState.RecordDecreeFired(script); } if (count != 1 && !script.CanRun(testSlate)) { num++; } else if (!logDescOnly) { QuestUtility.SendLetterQuestAvailable(QuestUtility.GenerateQuestAndMakeAvailable(script, testSlate)); } else { Quest quest = QuestUtility.GenerateQuestAndMakeAvailable(script, testSlate); Log.Message(quest.name + " (" + localPoints + " points)\n--------------\n" + quest.description + "\n--------------"); Find.QuestManager.Remove(quest); } } if (num != 0) { Messages.Message("Dev: Generated only " + (count - num) + " quests.", MessageTypeDefOf.RejectInput, historical: false); } })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list2)); }; list.Add(new DebugMenuOption("*Natural random", DebugMenuOptionMode.Action, delegate { generate(null); })); foreach (QuestScriptDef item2 in DefDatabase <QuestScriptDef> .AllDefs.Where((QuestScriptDef x) => x.IsRootAny)) { QuestScriptDef localRuleDef = item2; string defName = localRuleDef.defName; list.Add(new DebugMenuOption(defName, DebugMenuOptionMode.Action, delegate { generate(localRuleDef); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list.OrderBy((DebugMenuOption op) => op.label))); }
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()); }
static bool TryExecuteWorkerPrefix(IncidentParms parms, IncidentDef ___def) { for (int i = 0; i < WG_GOM_setting.questnum; i++) { QuestUtility.SendLetterQuestAvailable(QuestUtility.GenerateQuestAndMakeAvailable(___def.questScriptDef ?? parms.questScriptDef ?? NaturalRandomQuestChooser.ChooseNaturalRandomQuest(parms.points, parms.target), parms.points)); } return(true); }
protected override bool TryExecuteWorker(IncidentParms parms) { // give quest - 1.1 ver! QuestUtility.SendLetterQuestAvailable(QuestUtility.GenerateQuestAndMakeAvailable(def.questScriptDef ?? parms.questScriptDef ?? NaturalRandomQuestChooser.ChooseNaturalRandomQuest(parms.points, parms.target), parms.points)); QuestUtility.SendLetterQuestAvailable(QuestUtility.GenerateQuestAndMakeAvailable(def.questScriptDef ?? parms.questScriptDef ?? NaturalRandomQuestChooser.ChooseNaturalRandomQuest(parms.points, parms.target), parms.points)); QuestUtility.SendLetterQuestAvailable(QuestUtility.GenerateQuestAndMakeAvailable(def.questScriptDef ?? parms.questScriptDef ?? NaturalRandomQuestChooser.ChooseNaturalRandomQuest(parms.points, parms.target), parms.points)); QuestUtility.SendLetterQuestAvailable(QuestUtility.GenerateQuestAndMakeAvailable(def.questScriptDef ?? parms.questScriptDef ?? NaturalRandomQuestChooser.ChooseNaturalRandomQuest(parms.points, parms.target), parms.points)); QuestUtility.SendLetterQuestAvailable(QuestUtility.GenerateQuestAndMakeAvailable(def.questScriptDef ?? parms.questScriptDef ?? NaturalRandomQuestChooser.ChooseNaturalRandomQuest(parms.points, parms.target), parms.points)); QuestUtility.SendLetterQuestAvailable(QuestUtility.GenerateQuestAndMakeAvailable(def.questScriptDef ?? parms.questScriptDef ?? NaturalRandomQuestChooser.ChooseNaturalRandomQuest(parms.points, parms.target), parms.points)); return(true); }