public override void Notify_GeneratedByQuestGen(SitePart part, Slate slate, List <Rule> outExtraDescriptionRules, Dictionary <string, string> outExtraDescriptionConstants) { base.Notify_GeneratedByQuestGen(part, slate, outExtraDescriptionRules, outExtraDescriptionConstants); ThingDef thingDef = slate.Get <ThingDef>("itemStashSingleThing"); IEnumerable <ThingDef> enumerable = slate.Get <IEnumerable <ThingDef> >("itemStashThings"); List <Thing> list; if (thingDef != null) { list = new List <Thing>(); list.Add(ThingMaker.MakeThing(thingDef)); } else if (enumerable != null) { list = new List <Thing>(); foreach (ThingDef item in enumerable) { list.Add(ThingMaker.MakeThing(item)); } } else { float x = slate.Get("points", 0f); ThingSetMakerParams parms = default(ThingSetMakerParams); parms.totalMarketValueRange = new FloatRange(0.7f, 1.3f) * QuestTuning.PointsToRewardMarketValueCurve.Evaluate(x); list = ThingSetMakerDefOf.Reward_ItemsStandard.root.Generate(parms); } part.things = new ThingOwner <Thing>(part, oneStackOnly: false); part.things.TryAddRangeOrTransfer(list, canMergeWithExistingStacks: false); slate.Set("generatedItemStashThings", list); outExtraDescriptionRules.Add(new Rule_String("itemStashContents", GenLabel.ThingsLabel(list))); outExtraDescriptionRules.Add(new Rule_String("itemStashContentsValue", GenThing.GetMarketValue(list).ToStringMoney())); }
public override void Notify_GeneratedByQuestGen(SitePart part, Slate slate, List <Rule> outExtraDescriptionRules, Dictionary <string, string> outExtraDescriptionConstants) { base.Notify_GeneratedByQuestGen(part, slate, outExtraDescriptionRules, outExtraDescriptionConstants); ThingDef thingDef = slate.Get <ThingDef>("itemStashSingleThing", null, false); IEnumerable <ThingDef> enumerable = slate.Get <IEnumerable <ThingDef> >("itemStashThings", null, false); List <Thing> list = this.GenThingList(); part.things = new ThingOwner <Thing>(part, false, LookMode.Deep); part.things.TryAddRangeOrTransfer(list, false, false); outExtraDescriptionRules.Add(new Rule_String("itemStashContents", GenLabel.ThingsLabel(list, " - "))); outExtraDescriptionRules.Add(new Rule_String("itemStashContentsValue", GenThing.GetMarketValue(list).ToStringMoney(null))); }
public override IEnumerable <QuestPart> GenerateQuestParts(int index, RewardsGeneratorParams parms, string customLetterLabel, string customLetterText, RulePack customLetterLabelRules, RulePack customLetterTextRules) { Slate slate = RimWorld.QuestGen.QuestGen.slate; for (int i = 0; i < items.Count; i++) { Pawn pawn = items[i] as Pawn; if (pawn != null) { RimWorld.QuestGen.QuestGen.AddToGeneratedPawns(pawn); if (!pawn.IsWorldPawn()) { Find.WorldPawns.PassToWorld(pawn); } } } if (parms.giveToCaravan) { QuestPart_GiveToCaravan questPart_GiveToCaravan = new QuestPart_GiveToCaravan(); questPart_GiveToCaravan.inSignal = slate.Get <string>("inSignal"); questPart_GiveToCaravan.Things = items; yield return(questPart_GiveToCaravan); } else { QuestPart_DropPods dropPods = new QuestPart_DropPods(); dropPods.inSignal = slate.Get <string>("inSignal"); if (!customLetterLabel.NullOrEmpty() || customLetterLabelRules != null) { RimWorld.QuestGen.QuestGen.AddTextRequest("root", delegate(string x) { dropPods.customLetterLabel = x; }, QuestGenUtility.MergeRules(customLetterLabelRules, customLetterLabel, "root")); } if (!customLetterText.NullOrEmpty() || customLetterTextRules != null) { RimWorld.QuestGen.QuestGen.AddTextRequest("root", delegate(string x) { dropPods.customLetterText = x; }, QuestGenUtility.MergeRules(customLetterTextRules, customLetterText, "root")); } dropPods.mapParent = slate.Get <Map>("map").Parent; dropPods.useTradeDropSpot = true; dropPods.Things = items; yield return(dropPods); } slate.Set("itemsReward_items", items); slate.Set("itemsReward_totalMarketValue", TotalMarketValue); }
protected override void RunInt() { Slate slate = QuestGen.slate; QuestPart_ShipsTradeRequest part = new QuestPart_ShipsTradeRequest(); part.map = slate.Get <Map>("map"); part.requester = requester.GetValue(slate); if (part.requester == null) { part.requester = IncidentWorkerTraderShip.MakeTraderShip(part.map); } part.requestedThingDef = requestedThingDef.GetValue(slate); part.requestedCount = requestedThingCount.GetValue(slate); part.inSignal = slate.Get <string>("inSignal"); QuestGen.quest.AddPart(part); }
protected override bool TestRunInt(Slate slate) { return (slate.Get <Map>("map") != null && requestedThingCount.GetValue(slate) > 0 && requestedThingDef.GetValue(slate) != null); }
public override void Notify_GeneratedByQuestGen(SitePart part, Slate slate, List <Rule> outExtraDescriptionRules, Dictionary <string, string> outExtraDescriptionConstants) { base.Notify_GeneratedByQuestGen(part, slate, outExtraDescriptionRules, outExtraDescriptionConstants); var asker = slate.Get <Pawn>("asker"); var site = part.ParentHolder as Site; site.SetFaction(asker.Faction); }
public override IEnumerable <QuestPart> GenerateQuestParts(int index, RewardsGeneratorParams parms, string customLetterLabel, string customLetterText, RulePack customLetterLabelRules, RulePack customLetterTextRules) { Slate slate = RimWorld.QuestGen.QuestGen.slate; RimWorld.QuestGen.QuestGen.AddToGeneratedPawns(pawn); if (!pawn.IsWorldPawn()) { Find.WorldPawns.PassToWorld(pawn); } if (parms.giveToCaravan) { QuestPart_GiveToCaravan questPart_GiveToCaravan = new QuestPart_GiveToCaravan(); questPart_GiveToCaravan.inSignal = slate.Get <string>("inSignal"); questPart_GiveToCaravan.Things = Gen.YieldSingle(pawn); yield return(questPart_GiveToCaravan); yield break; } QuestPart_PawnsArrive pawnsArrive = new QuestPart_PawnsArrive(); pawnsArrive.inSignal = slate.Get <string>("inSignal"); pawnsArrive.pawns.Add(pawn); pawnsArrive.arrivalMode = ((arrivalMode == ArrivalMode.DropPod) ? PawnsArrivalModeDefOf.CenterDrop : PawnsArrivalModeDefOf.EdgeWalkIn); pawnsArrive.joinPlayer = true; pawnsArrive.mapParent = slate.Get <Map>("map").Parent; if (!customLetterLabel.NullOrEmpty() || customLetterLabelRules != null) { RimWorld.QuestGen.QuestGen.AddTextRequest("root", delegate(string x) { pawnsArrive.customLetterLabel = x; }, QuestGenUtility.MergeRules(customLetterLabelRules, customLetterLabel, "root")); } if (!customLetterText.NullOrEmpty() || customLetterTextRules != null) { RimWorld.QuestGen.QuestGen.AddTextRequest("root", delegate(string x) { pawnsArrive.customLetterText = x; }, QuestGenUtility.MergeRules(customLetterTextRules, customLetterText, "root")); } yield return(pawnsArrive); }
protected override bool TestRunInt(Slate slate) { if (!TraderShips.settings.enableQuests) { return(false); } if (slate.Get <Map>("map") == null) { return(false); } return(true); }
public override bool Allows(QuestGiverManager questGiverManager, Quest quest, Slate slate, out QuestInfo questInfo) { var asker = slate.Get <Pawn>("asker"); if (asker?.Faction != null && asker.Faction.GoodwillWith(Faction.OfPlayer) >= minimunGoodwillRequirement) { var currencyInfo = new GoodwillCurrencyInfo(); currencyInfo.currency = Currency.Goodwill; currencyInfo.amount = questGiverManager.def.currency.costToAcceptQuest; questInfo = new QuestInfo(quest, asker.Faction, currencyInfo, onlyOneChoice: questGiverManager.def.onlyOneReward ? true : false); return(true); } questInfo = null; return(false); }
protected override bool TestRunInt(Slate slate) { var home = slate.Get <Map>("map"); var city = RandomNearbyCity(home, slate); if (city == null) { return(false); } slate.Set(storeAs.GetValue(slate), city); if (!string.IsNullOrEmpty(storeFactionAs.GetValue(slate))) { slate.Set(storeFactionAs.GetValue(slate), city.Faction); } return(true); }
public override IEnumerable <QuestPart> GenerateQuestParts(int index, RewardsGeneratorParams parms, string customLetterLabel, string customLetterText, RulePack customLetterLabelRules, RulePack customLetterTextRules) { Slate slate = RimWorld.QuestGen.QuestGen.slate; QuestPart_GiveRoyalFavor questPart_GiveRoyalFavor = new QuestPart_GiveRoyalFavor(); questPart_GiveRoyalFavor.faction = faction; questPart_GiveRoyalFavor.amount = amount; if (!parms.chosenPawnSignal.NullOrEmpty()) { questPart_GiveRoyalFavor.inSignal = QuestGenUtility.HardcodedSignalWithQuestID(parms.chosenPawnSignal); questPart_GiveRoyalFavor.signalListenMode = QuestPart.SignalListenMode.Always; } else { questPart_GiveRoyalFavor.inSignal = slate.Get <string>("inSignal"); questPart_GiveRoyalFavor.giveToAccepter = true; } yield return(questPart_GiveRoyalFavor); slate.Set("royalFavorReward_amount", amount); }
private void GenerateQuest(QuestScriptDef script, Slate slate) { if (script.IsRootDecree) { Pawn pawn = slate.Get <Pawn>("asker"); if (pawn.royalty.AllTitlesForReading.NullOrEmpty()) { pawn.royalty.SetTitle(Faction.OfEmpire, 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); } else { Quest quest = QuestUtility.GenerateQuestAndMakeAvailable(script, slate); if (!quest.hidden) { QuestUtility.SendLetterQuestAvailable(quest); } } }
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))); }
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))); }
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 { } } } }