public override IncidentParms GenerateParms(IncidentCategoryDef incCat, IIncidentTarget target) { IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(incCat, target); incidentParms.points *= this.Props.randomPointsFactorRange.RandomInRange; return(incidentParms); }
// RimWorld.StorytellerUtility public static void DefaultParmsNow_PostFix(ref IncidentParms __result, IncidentCategoryDef incCat, IIncidentTarget target) { if (!(target is Map map)) { return; } if (!(__result.points > 0)) { return; } try { var forceUsers = map.mapPawns.FreeColonistsSpawned.ToList() .FindAll(p => p.GetComp <CompForceUser>() != null); foreach (var pawn in forceUsers) { var compForce = pawn.GetComp <CompForceUser>(); if (compForce.ForceUserLevel > 0) { __result.points += 5 * compForce.ForceUserLevel; } } } catch (NullReferenceException) { } }
public BaseNormalIncidentHelper(IncidentCategoryDef incidentCategoryDef, IncidentDef incidentDef, IIncidentTarget target, bool shouldForceFire = false) { this.incidentDef = incidentDef; this.incidentCategoryDef = incidentCategoryDef; this.shouldForceFire = true; this.target = target; }
public WagerIncidentHelper(IncidentCategoryDef categoryDef, IncidentDef incidentDef, RaidStrategyDef raidStrat, PawnsArrivalModeDef arrivalMode) { this.categoryDef = categoryDef; this.incidentDef = incidentDef; raidStratDef = raidStrat; pawnArrivalModeDef = arrivalMode; }
public override IncidentParms GenerateParms(IncidentCategoryDef incCat, IIncidentTarget target) { IncidentParms incidentParms = base.GenerateParms(incCat, target); incidentParms.questScriptDef = NaturalRandomQuestChooser.ChooseNaturalRandomQuest(incidentParms.points, target); return(incidentParms); }
public static void ApplyRandom(IncidentCategoryDef def, float weight) { if (TryGetRandom(out StorytellerCompProperties_RandomMain comp)) { foreach (IncidentCategoryEntry e in comp.categoryWeights) { if (e.category == def) { e.weight = weight; } } } }
public static bool TryGetRandomWeight(IncidentCategoryDef def, out float weight) { if (TryGetRandom(out StorytellerCompProperties_RandomMain comp)) { foreach (IncidentCategoryEntry e in comp.categoryWeights) { if (e.category == def) { weight = e.weight; return(true); } } } weight = 0; return(false); }
public static bool ApplyRandom(IncidentCategoryDef def, float weight) { bool applied = false; if (TryGetRandom(out StorytellerCompProperties_RandomMain comp)) { foreach (IncidentCategoryEntry e in comp.categoryWeights) { if (e.category == def) { Log.Message($"{def.defName} weight of {weight} has been applied."); e.weight = weight; applied = true; } } } return(applied); }
public static string GetLabel(StorytellerCompPropertiesStats s) { StringBuilder sb = new StringBuilder(GetType(s.compClass).ToString()); IncidentCategoryDef cd = s.category?.Def; IncidentDef id = s.incident?.Def; if (cd != null) { sb.Append(" - "); sb.Append(Util.GetLabel(cd)); } if (id != null) { sb.Append(" - "); sb.Append(Util.GetLabel(id)); } return(sb.ToString()); }
public static void SetCategory(StorytellerCompProperties p, IncidentCategoryDef d) { if (p is StorytellerCompProperties_CategoryIndividualMTBByBiome f) { f.category = d; } else if (p is StorytellerCompProperties_CategoryMTB s) { s.category = d; } else if (p is StorytellerCompProperties_Disease t) { t.category = d; } else if (p is StorytellerCompProperties_OnOffCycle o) { SetCategory(o, d); } }
//RimWorld.StorytellerUtility public static void DefaultParmsNow_PostFix(IncidentCategoryDef incCat, IIncidentTarget target, ref IncidentParms __result) { Map map = (Map)__result.target; if (map != null) { if (__result.points > 0) { try { int numElderThings = map?.mapPawns?.FreeColonistsSpawned?.ToList()?.FindAll(p => p.def.defName == "Alien_ElderThing_Race_Standard")?.Count ?? 0; __result.points += numElderThings * 50; } catch (Exception e) { } } } }
public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target) { List <IncidentCategoryDef> triedCategories = new List <IncidentCategoryDef>(); List <IncidentDef> incidentDefs; if (!VoteHandler.voteActive && Rand.MTBEventOccurs(ToolkitSettings.HodlBotMTBDays, 60000f, 1000f)) { while (true) { incidentDefs = new List <IncidentDef>(); IncidentCategoryDef category = ChooseRandomCategory(target, triedCategories); IncidentParms parms = this.GenerateParms(category, target); IEnumerable <IncidentDef> options = from d in base.UsableIncidentsInCategory(category, target) where d.Worker.CanFireNow(parms) && (!d.NeedsParmsPoints || parms.points >= d.minThreatPoints) select d; for (int i = 0; options.Count() > 0 && incidentDefs.Count < ToolkitSettings.VoteOptions && i < 10; i++) { if (!options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef incDef)) { triedCategories.Add(category); break; } else { incidentDefs.Add(incDef); options = options.Where(s => s != incDef); } } if (incidentDefs.Count >= 2) { Dictionary <int, IncidentDef> incidents = new Dictionary <int, IncidentDef>(); for (int i = 0; i < incidentDefs.Count(); i++) { incidents.Add(i, incidentDefs.ToList()[i]); } VoteHandler.QueueVote(new VoteIncidentDef(incidents, this, parms)); yield break; } } } }
public static string GetLabel(StorytellerCompProperties p) { if (p == null) { Log.Warning("Cannot get label for null property"); return(null); } StringBuilder sb = new StringBuilder(GetType(p.compClass.Name).ToString()); IncidentCategoryDef cd = GetCategory(p); IncidentDef id = GetIncident(p); if (cd != null) { sb.Append(" - "); sb.Append(Util.GetLabel(cd)); } if (id != null) { sb.Append(" - "); sb.Append(Util.GetLabel(id)); } return(sb.ToString()); }
public WagerIncidentHelper(IncidentCategoryDef categoryDef, IncidentDef incidentDef) { this.categoryDef = categoryDef; this.incidentDef = incidentDef; }
public BaseNormalIncidentHelper(IncidentCategoryDef incidentCategoryDef, IncidentDef incidentDef, bool shouldForceFire = false) : this(incidentCategoryDef, incidentDef, Helper.AnyPlayerMap, shouldForceFire) { }
public BaseNormalIncidentHelper(IncidentCategoryDef incidentCategoryDef, IncidentDef incidentDef) : this(incidentCategoryDef, incidentDef, Helper.AnyPlayerMap) { }
public NormalIncidentHelper(IncidentCategoryDef incidentCategoryDef, IncidentDef incidentDef, IIncidentTarget target, bool shouldForceFire = false) : base(incidentCategoryDef, incidentDef, target, shouldForceFire) { }
public NormalIncidentHelper(IncidentCategoryDef incidentCategoryDef, IncidentDef incidentDef) : base(incidentCategoryDef, incidentDef) { }
public BasicVotingHelper(IncidentCategoryDef cat, IncidentDef incidentDef, bool shouldForceFire = false) : base(cat, incidentDef, shouldForceFire) { }
public BaseVotingHelper(IncidentCategoryDef cat, IncidentDef incidentDef, bool shouldForceFire = false) { category = cat; this.incidentDef = incidentDef; this.shouldForceFire = shouldForceFire; }
public IEnumerable <FiringIncident> MakeIntervalIncidentsThread() { if (Rand.MTBEventOccurs(Props.mtbDays, 60000f, 1000f) && !ToolkitSettings.TimedStorytelling) { bool targetIsRaidBeacon = incidentTarget.IncidentTargetTags().Contains(IncidentTargetTagDefOf.Map_RaidBeacon); List <IncidentCategoryDef> triedCategories = new List <IncidentCategoryDef>(); IncidentDef incDef; List <IncidentDef> pickedoptions = new List <IncidentDef>(); IEnumerable <IncidentDef> options; for (; ;) { IncidentCategoryDef category = this.ChooseRandomCategory(incidentTarget, triedCategories); Helper.Log($"Trying Category {category}"); parms = this.GenerateParms(category, incidentTarget); options = from d in base.UsableIncidentsInCategory(category, incidentTarget) where !d.NeedsParmsPoints || parms.points >= d.minThreatPoints select d; if (options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out incDef)) { break; } triedCategories.Add(category); if (triedCategories.Count >= this.Props.categoryWeights.Count) { goto Block_6; } Thread.Sleep(0); } Helper.Log($"Events Possible: {options.Count()}"); if (options.Count() > 1) { options = options.Where(k => k != incDef); pickedoptions.Add(incDef); for (int x = 0; x < ToolkitSettings.VoteOptions - 1 && x < options.Count(); x++) { options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef picked); if (picked != null) { options = options.Where(k => k != picked); pickedoptions.Add(picked); Thread.Sleep(0); } } Dictionary <int, IncidentDef> incidents = new Dictionary <int, IncidentDef>(); for (int i = 0; i < pickedoptions.Count(); i++) { incidents.Add(i, pickedoptions.ToList()[i]); } incidentOptions = new VoteIncidentDef(incidents, this, parms); Helper.Log("Events created"); yield return(null); } else if (options.Count() == 1) { yield return(new FiringIncident(incDef, this, parms)); } if (!this.Props.skipThreatBigIfRaidBeacon || !targetIsRaidBeacon || incDef.category != IncidentCategoryDefOf.ThreatBig) { // yield return new FiringIncident(incDef, this, parms); // _twitchstories.StartVote(options, this, parms); } Block_6 :; Thread.Sleep(0); } }
public static void SetCategory(StorytellerCompProperties_OnOffCycle s, IncidentCategoryDef v) { typeof(StorytellerCompProperties_OnOffCycle).GetField("category", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(s, v); }
public NormalIncidentHelper(IncidentCategoryDef incidentCategoryDef, IncidentDef incidentDef) : this(incidentCategoryDef, incidentDef, false) { }
public NormalIncidentHelper(IncidentCategoryDef incidentCategoryDef, IncidentDef incidentDef, bool shouldForceFire) { this.incidentDef = incidentDef; this.incidentCategoryDef = incidentCategoryDef; this.shouldForceFire = true; }
public void MakeRandomVoteEvent(IIncidentTarget target) { Helper.Log("Forcing vote event"); if (!VoteHandler.voteActive) { if (ToolkitSettings.TimedStorytelling) { bool targetIsRaidBeacon = target.IncidentTargetTags().Contains(IncidentTargetTagDefOf.Map_RaidBeacon); List <IncidentCategoryDef> triedCategories = new List <IncidentCategoryDef>(); IncidentDef incDef; List <IncidentDef> pickedoptions = new List <IncidentDef>(); IEnumerable <IncidentDef> options; IncidentCategoryDef category = this.ChooseRandomCategory(target, triedCategories); Helper.Log($"Trying Category{category}"); parms = this.GenerateParms(category, target); options = from d in base.UsableIncidentsInCategory(category, target) where !d.NeedsParmsPoints || parms.points >= d.minThreatPoints select d; if (options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out incDef)) { } triedCategories.Add(category); if (triedCategories.Count >= this.Props.categoryWeights.Count) { } Helper.Log($"Events Possible: {options.Count()}"); if (options.Count() > 1) { options = options.Where(k => k != incDef); pickedoptions.Add(incDef); for (int x = 0; x < ToolkitSettings.VoteOptions - 1 && x < options.Count(); x++) { options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef picked); if (picked != null) { options = options.Where(k => k != picked); pickedoptions.Add(picked); } } Dictionary <int, IncidentDef> incidents = new Dictionary <int, IncidentDef>(); for (int i = 0; i < pickedoptions.Count(); i++) { incidents.Add(i, pickedoptions.ToList()[i]); } if (incidents.Count > 1) { VoteHandler.QueueVote(new VoteIncidentDef(incidents, this, parms)); Helper.Log("Events created"); } } } } }
public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target) { if (Rand.MTBEventOccurs(this.Props.mtbDays, 60000f, 1000f)) { bool targetIsRaidBeacon = target.IncidentTargetTags().Contains(IncidentTargetTagDefOf.Map_RaidBeacon); List <IncidentCategoryDef> triedCategories = new List <IncidentCategoryDef>(); IncidentDef incDef; List <IncidentDef> pickedoptions = new List <IncidentDef>(); IEnumerable <IncidentDef> options; for (; ;) { IncidentCategoryDef category = this.ChooseRandomCategory(target, triedCategories); Helper.Log($"Trying Category{category}"); parms = this.GenerateParms(category, target); options = from d in base.UsableIncidentsInCategory(category, target) where !d.NeedsParmsPoints || parms.points >= d.minThreatPoints select d; if (options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out incDef)) { break; } triedCategories.Add(category); if (triedCategories.Count >= this.Props.categoryWeights.Count) { goto Block_6; } } Helper.Log($"Events Possible: {options.Count()}"); if (options.Count() > 1) { options = options.Where(k => k != incDef); pickedoptions.Add(incDef); for (int x = 0; x < (Settings.VoteOptions > options.Count() ? options.Count() - 1 : Settings.VoteOptions - 1); x++) { options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef picked); if (picked != null) { options = options.Where(k => k != picked); pickedoptions.Add(picked); } } VoteEvent evt = new VoteEvent(pickedoptions, this, parms); Ticker.VoteEvents.Enqueue(evt); Helper.Log("Events created"); yield break; } else if (options.Count() == 1) { yield return(new FiringIncident(incDef, this, parms)); } if (!this.Props.skipThreatBigIfRaidBeacon || !targetIsRaidBeacon || incDef.category != IncidentCategoryDefOf.ThreatBig) { // yield return new FiringIncident(incDef, this, parms); // _twitchstories.StartVote(options, this, parms); } Block_6 :; } yield break; }