public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target) { CheckIfPacksAreEnabled(); StoryTellerVoteTracker voteTracker = Current.Game.GetComponent <StoryTellerVoteTracker>(); // get different voting packs List <StorytellerPack> allPacks = DefDatabase <StorytellerPack> .AllDefs.Where(s => s.enabled && voteTracker.HaveMinimumDaysBetweenEventsPassed(s) ).ToList(); if (allPacks == null || allPacks.Count < 1) { Log.Warning("No story teller packs found"); yield break; } // randomize allPacks.Shuffle(); StorytellerPack chosen = allPacks[0]; // let the comp do the work foreach (FiringIncident incident in chosen.StorytellerComp.MakeIntervalIncidents(target)) { yield return(incident); } yield break; }
public void LogStorytellerCompVote(StorytellerPack pack) { if (!StorytellerLastTickTracker.ContainsKey(pack.defName)) { StorytellerLastTickTracker.Add(pack.defName, 0); } StorytellerLastTickTracker[pack.defName] = Find.TickManager.TicksGame; }
public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target) { voteTracker = Current.Game.GetComponent <StoryTellerVoteTracker>(); if (!VoteHandler.voteActive && Rand.MTBEventOccurs(ToolkitSettings.ToryTalkerMTBDays, 60000f, 1000f)) { List <VotingIncidentEntry> entries = VotingIncidentsByWeight(); List <VotingIncidentEntry> winners = new List <VotingIncidentEntry>(); for (int i = 0; i < ToolkitSettings.VoteOptions && i < 12; i++) { winners.Add( entries.Where(s => !winners.Contains(s) ).RandomElementByWeight( (VotingIncidentEntry vi) => vi.weight) ); int index = Math.Max(winners.Count - 1, 0); winners[index].incident.helper = VotingIncidentMaker.makeVotingHelper(winners[index].incident); winners[index].incident.helper.target = target; if (!winners[index].incident.helper.IsPossible()) { entries.RemoveAt(i); i--; winners.RemoveAt(index); } } Dictionary <int, VotingIncident> incidents = new Dictionary <int, VotingIncident>(); for (int i = 0; i < winners.Count; i++) { incidents.Add(i, winners[i].incident); } StorytellerPack pack = DefDatabase <StorytellerPack> .GetNamed("ToryTalker"); VoteHandler.QueueVote(new Vote_ToryTalker(incidents, pack, "Which event should happen next?")); } yield break; }
public bool HaveMinimumDaysBetweenEventsPassed(StorytellerPack pack) { if (StorytellerLastTickTracker == null) { StorytellerLastTickTracker = new Dictionary <string, int>(); } if (!StorytellerLastTickTracker.ContainsKey(pack.defName)) { StorytellerLastTickTracker.Add(pack.defName, GenDate.DaysPassed < 2 ? 0 : Find.TickManager.TicksGame); return(true); } float daysBetweenEvents; switch (pack.defName) { case "ToryTalker": daysBetweenEvents = ToolkitSettings.ToryTalkerMTBDays; break; case "HodlBot": daysBetweenEvents = ToolkitSettings.HodlBotMTBDays; break; case "UristBot": daysBetweenEvents = ToolkitSettings.UristBotMTBDays; break; case "Milasandra": daysBetweenEvents = ((StorytellerCompProperties_ToolkitOnOffCycle)(DefDatabase <StorytellerPack> .GetNamed("Milasandra").StorytellerComp).props).minSpacingDays; break; case "Mercurius": daysBetweenEvents = ((StorytellerCompProperties_ToolkitCategoryMTB)(DefDatabase <StorytellerPack> .GetNamed("Mercurius").StorytellerComp).props).mtbDays; break; default: Log.Error("No MTB days for storyteller pack"); return(false); } return((daysBetweenEvents * GenDate.TicksPerDay) + StorytellerLastTickTracker[pack.defName] < Find.TickManager.TicksGame); }
public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target) { if (VoteHandler.voteActive || !Rand.MTBEventOccurs(ToolkitSettings.UristBotMTBDays, 60000f, 1000f)) { yield break; } IncidentWorker worker = new IncidentWorker_RaidEnemy(); IncidentParms parms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatSmall, target); worker.def = IncidentDefOf.RaidEnemy; parms.points = StorytellerUtility.DefaultThreatPointsNow(target); parms.raidStrategy = RaidStrategyDefOf.ImmediateAttack; parms.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn; if (!worker.CanFireNow(parms)) { yield break; } int choice = Rand.Range(0, 0); switch (choice) { case 0: parms.faction = Find.FactionManager.RandomEnemyFaction(false, false, false); Dictionary <int, RaidStrategyDef> allStrategies = new Dictionary <int, RaidStrategyDef>(); List <RaidStrategyDef> raidStrategyDefs = new List <RaidStrategyDef>(DefDatabase <RaidStrategyDef> .AllDefs); raidStrategyDefs.Shuffle(); foreach (RaidStrategyDef strat in raidStrategyDefs) { allStrategies.Add(allStrategies.Count, strat); } StorytellerPack named = DefDatabase <StorytellerPack> .GetNamed("UristBot", true); VoteHandler.QueueVote(new Vote_RaidStrategy(allStrategies, named, worker, this, parms, "How should the next raiders attack?")); break; } }
public bool HaveMinimumDaysBetweenEventsPassed(StorytellerPack pack) { if (StorytellerLastTickTracker == null) { StorytellerLastTickTracker = new Dictionary <string, int>(); } if (!StorytellerLastTickTracker.ContainsKey(pack.defName)) { StorytellerLastTickTracker.Add(pack.defName, GenDate.DaysPassed < 2 ? 0 : Find.TickManager.TicksGame); return(true); } float daysBetweenEvents; switch (pack.defName) { case "ToryTalker": daysBetweenEvents = ToolkitSettings.ToryTalkerMTBDays; break; case "HodlBot": daysBetweenEvents = ToolkitSettings.HodlBotMTBDays; break; case "UristBot": daysBetweenEvents = ToolkitSettings.UristBotMTBDays; break; default: Log.Error("No MTB days for storyteller pack"); return(false); } return((daysBetweenEvents * GenDate.TicksPerDay) + StorytellerLastTickTracker[pack.defName] < Find.TickManager.TicksGame); }
public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target) { if (VoteHandler.voteActive || !Rand.MTBEventOccurs(ToolkitSettings.HodlBotMTBDays, 60000f, 1000f)) { if (!forced) { yield break; } } if (Rand.Range(0, 1) == 1) { voteType = Vote_VotingIncident.VoteLabelType.Type; } List <VotingIncidentEntry> source = VotingIncidentsByWeight(); List <VotingIncidentEntry> winners = new List <VotingIncidentEntry>(); string str = null; switch (voteType) { case Vote_VotingIncident.VoteLabelType.Category: { EventCategory category = RandomCategory(); source = (from s in source where s.incident.eventCategory == category select s).ToList(); str = "Which " + category.ToString() + " event should happen?"; Helper.Log("rand cat picked " + category); break; } case Vote_VotingIncident.VoteLabelType.Type: { EventType randType = RandomType(); source = (from s in source where s.incident.eventType == randType select s).ToList(); str = "Which " + randType + " event should happen?"; Helper.Log("rand type picked " + randType); break; } } for (int i = 0; i < ToolkitSettings.VoteOptions; i++) { if (GenCollection.TryRandomElementByWeight <VotingIncidentEntry> (from s in source where !winners.Contains(s) select s, (Func <VotingIncidentEntry, float>)((VotingIncidentEntry vi) => vi.weight), out VotingIncidentEntry votingIncidentEntry)) { votingIncidentEntry.incident.Helper.target = target; if (votingIncidentEntry.incident.Helper.IsPossible()) { winners.Add(votingIncidentEntry); } } } if (winners.Count < 3) { Helper.Log("Less than 3 possible votes were found"); yield break; } Dictionary <int, VotingIncident> dictionary = new Dictionary <int, VotingIncident>(); for (int i = 0; i < winners.Count; i++) { dictionary.Add(i, winners[i].incident); } StorytellerPack named = DefDatabase <StorytellerPack> .GetNamed("HodlBot", true); VoteHandler.QueueVote(new Vote_HodlBot(dictionary, named, voteType, str)); }