private void DoRow(Rect rect, StoreIncident thingDef, int index) { Widgets.DrawHighlightIfMouseover(rect); TooltipHandler.TipRegion(rect, thingDef.description); GUI.BeginGroup(rect); Rect rect2 = new Rect(4f, (rect.height - 20f) / 2f, 20f, 20f); //Widgets.ThingIcon(rect2, thingDef); Rect rect3 = new Rect(rect2.xMax + 4f, 0f, rect.width - 60, 24f); Text.Anchor = TextAnchor.MiddleLeft; Text.WordWrap = false; if (thingDef.cost < 1 && thingDef.defName != "Item") { GUI.color = Color.grey; } Widgets.Label(rect3, thingDef.label.CapitalizeFirst()); Rect rect4 = new Rect(rect3.width, rect3.y, 60, rect3.height); if (Widgets.ButtonText(rect4, "Edit")) { Type type = typeof(StoreIncidentEditor); Find.WindowStack.TryRemove(type); StoreIncidentEditor window = new StoreIncidentEditor(thingDef); Find.WindowStack.Add(window); } Text.Anchor = TextAnchor.UpperLeft; Text.WordWrap = true; GUI.color = Color.white; GUI.EndGroup(); }
public void DoExtraSetup(IncidentWorker worker, IncidentParms @params, StoreIncident incident) { if (!(worker is AnimalSpawnWorker spawnWorker)) { return; } if (!_predators.TryRandomElement(out string predator)) { predator = "Thrumbo"; } ThingDef thing = ThingDef.Named(predator); var power = 0.0f; if (thing?.race != null) { power += thing.tools.Sum(t => t.power); power /= thing.tools.Count; } spawnWorker.Quantity = power > 18f ? 2 : 3; spawnWorker.SpawnManhunter = true; spawnWorker.AnimalDef = PawnKindDef.Named(predator); spawnWorker.def = IncidentDef.Named("HerdMigration"); spawnWorker.Label = "TwitchStoriesLetterLabelPredators".Localize(); spawnWorker.Text = "ManhunterPackArrived".LocalizeKeyed(spawnWorker.AnimalDef.GetLabelPlural()); }
public StoreIncidentEditor(StoreIncident storeIncident) { this.doCloseButton = true; this.storeIncident = storeIncident; if (storeIncident == null) { throw new ArgumentNullException(); } StoreIncidentVariables storeIncidentVariables = DefDatabase <StoreIncidentVariables> .AllDefs.ToList().Find(s => s.defName == storeIncident.defName ); if (storeIncidentVariables != null) { this.storeIncidentVariables = storeIncidentVariables; this.variableIncident = true; this.extraWindowHeight = storeIncidentVariables.customSettingKeys != null ? (storeIncidentVariables.customSettingKeys.Count * 28f) + 28f : 0f; } karmaTypeStrings = Enum.GetNames(typeof(KarmaType)); setKarmaType = storeIncident.karmaType.ToString(); }
public static bool CheckTimesKarmaTypeHasBeenUsedRecently(StoreIncident incident) { // if they have max event setting off always return false if (!ToolkitSettings.MaxEvents) { return(false); } Store_Component component = Current.Game.GetComponent <Store_Component>(); switch (incident.karmaType) { case KarmaType.Bad: return(component.KarmaTypesInLogOf(incident.karmaType) >= ToolkitSettings.MaxBadEventsPerInterval); case KarmaType.Good: return(component.KarmaTypesInLogOf(incident.karmaType) >= ToolkitSettings.MaxGoodEventsPerInterval); case KarmaType.Neutral: return(component.KarmaTypesInLogOf(incident.karmaType) >= ToolkitSettings.MaxNeutralEventsPerInterval); case KarmaType.Doom: return(component.KarmaTypesInLogOf(incident.karmaType) >= ToolkitSettings.MaxBadEventsPerInterval); } return(false); }
public StoreIncidentEditor(StoreIncident storeIncident) { this.doCloseButton = true; this.storeIncident = storeIncident; if (storeIncident == null) { throw new ArgumentNullException(); } MakeSureSaveExists(true); StoreIncidentVariables storeIncidentVariables = DefDatabase <StoreIncidentVariables> .AllDefs.ToList().Find(s => s.defName == storeIncident.defName ); if (storeIncidentVariables != null) { this.storeIncidentVariables = storeIncidentVariables; this.variableIncident = true; } karmaTypeStrings = Enum.GetNames(typeof(KarmaType)); setKarmaType = storeIncident.karmaType.ToString(); }
private static bool CheckIfIncidentIsOnCooldownPrefix(StoreIncident incident, string username, ref bool __result) { EventItem itemEvent = Data.Events.Find(e => string.Equals(e.DefName, incident.defName)); __result = itemEvent == null || UsageService.IsOnCooldown(itemEvent, username); return(false); }
public StoreIncidentEditor([NotNull] StoreIncident storeIncident) : base(storeIncident) { onlyOneOfTypeAllowed = true; _eventType = storeIncident.GetModExtension <EventExtension>()?.EventType ?? EventTypes.Default; _costBuffer = storeIncident.cost.ToString(); _capBuffer = storeIncident.eventCap.ToString(); _wagerBuffer = (storeIncidentVariables?.maxWager ?? 0).ToString(); _karmaTypeOptions = Data.KarmaTypes.Values.Select(t => new FloatMenuOption(t.ToString(), () => storeIncident.karmaType = t)).ToList(); }
private static bool CheckIncident([NotNull] StoreIncident incident, string query) { if (incident.defName.Equals("Item")) { return(string.Equals(incident.abbreviation, query, StringComparison.InvariantCultureIgnoreCase)); } return(incident.cost > 0 && string.Equals(incident.abbreviation, query, StringComparison.InvariantCultureIgnoreCase)); }
public static void Charge([NotNull] this Viewer viewer, [NotNull] StoreIncident incident, float weight) { if (!ToolkitSettings.UnlimitedCoins) { viewer.TakeViewerCoins(incident.cost); } viewer.CalculateNewKarma(incident.karmaType, Mathf.CeilToInt(incident.cost * weight)); }
public static void Charge([NotNull] this Viewer viewer, [NotNull] StoreIncident incident) { if (!ToolkitSettings.UnlimitedCoins) { viewer.TakeViewerCoins(incident.cost); } viewer.CalculateNewKarma(incident.karmaType, incident.cost); }
/// <summary> /// Loads events from the given partial data. /// </summary> /// <param name="partialData">A collection of partial data to load</param> public static void LoadEventPartial([NotNull] IEnumerable <EventPartial> partialData) { var builder = new StringBuilder(); foreach (EventPartial partial in partialData) { EventItem existing = Events.Find(i => i.DefName.Equals(partial.DefName)); if (existing == null) { StoreIncident incident = DefDatabase <StoreIncident> .GetNamed(partial.DefName, false); if (incident == null) { builder.Append($" - {partial.Data?.Mod ?? "UNKNOWN"}:{partial.DefName}\n"); continue; } var e = new EventItem { Incident = incident, Name = partial.Name, Cost = partial.Cost, EventCap = partial.EventCap, KarmaType = partial.KarmaType }; if (e.IsVariables) { e.MaxWager = partial.MaxWager; } e.EventData = partial.EventData; Events.Add(e); continue; } existing.Name = partial.Name; existing.Cost = partial.Cost; existing.EventCap = partial.EventCap; existing.KarmaType = partial.KarmaType; if (existing.IsVariables) { existing.MaxWager = partial.MaxWager; } existing.EventData = partial.EventData; } if (builder.Length <= 0) { return; } builder.Insert(0, "The following events could not be loaded from the partial data provided:\n"); TkUtils.Logger.Warn(builder.ToString()); }
public void LogIncident(StoreIncident incident) { int currentTick = Find.TickManager.TicksGame; int logID = lastID; tickHistory.Add(logID, currentTick); abbreviationHistory.Add(logID, incident.abbreviation); karmaHistory.Add(logID, incident.karmaType.ToString()); lastID++; }
public static bool CopyExists(StoreIncident incident) { if (!EditorPathExists()) { throw new DirectoryNotFoundException(); } string filePath = incident.defName + ".json"; return(File.Exists(editorPath + filePath)); }
public static bool CheckIfKarmaTypeIsMaxed(StoreIncident incident, string username, bool separateChannel = false) { bool maxed = CheckTimesKarmaTypeHasBeenUsedRecently(incident); if (maxed) { Store_Component component = Current.Game.GetComponent <Store_Component>(); Toolkit.client.SendMessage($"@{username} {incident.label.CapitalizeFirst()} is maxed from karmatype, wait " + component.DaysTillIncidentIsPurchaseable(incident) + " days to purchase.", separateChannel); } return(maxed); }
public void CompletePurchase(StoreIncident incident) { Purchaser.Charge(Price, Proxy.Thing.ItemData?.Weight ?? 1f, Proxy.Thing.Data?.KarmaType ?? incident.karmaType); if (Proxy.Thing.Thing.race != null) { NotifyAnimalPurchaseComplete(); } else { NotifyItemPurchaseComplete(); } }
public static bool CheckIfIncidentIsOnCooldown(StoreIncident incident, string username, bool separateChannel = false) { if (!ToolkitSettings.EventsHaveCooldowns) { return(false); } bool maxed = component.IncidentsInLogOf(incident.abbreviation) >= incident.eventCap; if (maxed) { Log.Message("StoreIncident max per day reached for " + incident.label); client.SendMessage($"@{username} " + "TwitchToolkitEventOnCooldown".Translate(), separateChannel); } return(maxed); }
public static void LoadBackup(StoreIncident incident) { StoreIncidentSimple incidentSimple = DefDatabase <StoreIncidentSimple> .AllDefs.ToList().Find(s => s.defName == incident.defName); if (incidentSimple != null) { LoadBackupSimple(ref incidentSimple); return; } StoreIncidentVariables incidentVariables = DefDatabase <StoreIncidentVariables> .AllDefs.ToList().Find(s => s.defName == incident.defName); if (incidentVariables != null) { LoadBackupVariables(ref incidentVariables); return; } }
public static void SaveCopy(StoreIncident incident) { StoreIncidentSimple incidentSimple = DefDatabase <StoreIncidentSimple> .AllDefs.ToList().Find(s => s.defName == incident.defName); if (incidentSimple != null) { SaveCopy(incidentSimple); return; } StoreIncidentVariables incidentVariables = DefDatabase <StoreIncidentVariables> .AllDefs.ToList().Find(s => s.defName == incident.defName); if (incidentVariables != null) { SaveCopy(incidentVariables); return; } }
private void PerformEventLookup(string query) { StoreIncident result = DefDatabase <StoreIncident> .AllDefs.FirstOrDefault( i => i.cost > 0 && (i.abbreviation.ToToolkit().EqualsIgnoreCase(query.ToToolkit()) || i.defName.ToToolkit().EqualsIgnoreCase(query.ToToolkit())) ); if (result == null) { return; } EventTypes eventType = result.GetModExtension <EventExtension>()?.EventType ?? EventTypes.Default; switch (eventType) { case EventTypes.Default: NotifyLookupComplete("TKUtils.Price.Limited".LocalizeKeyed(result.abbreviation.CapitalizeFirst(), result.cost.ToString("N0"))); return; case EventTypes.Item: case EventTypes.PawnKind: case EventTypes.Trait: NotifyLookupComplete("TKUtils.Price.Overridden".LocalizeKeyed(eventType.ToString())); return; case EventTypes.Misc: NotifyLookupComplete("TKUtils.Price.External".Localize()); return; case EventTypes.Variable: NotifyLookupComplete( new[] { "TKUtils.Price.Variables".LocalizeKeyed(result.abbreviation.CapitalizeFirst(), result.cost.ToString("N0")), "TKUtils.Price.External".Localize() }.GroupedJoin() ); return; } }
public static bool CheckIfIncidentIsOnCooldown(StoreIncident incident, string username, bool separateChannel = false) { if (!ToolkitSettings.EventsHaveCooldowns) { return(false); } Store_Component component = Current.Game.GetComponent <Store_Component>(); bool maxed = component.IncidentsInLogOf(incident.abbreviation) >= incident.eventCap; if (maxed) { float days = component.DaysTillIncidentIsPurchaseable(incident); Toolkit.client.SendMessage($"@{username} {incident.label.CapitalizeFirst()} is maxed, wait " + days + $" day{(days != 1 ? "s" : "")} to purchase.", separateChannel); } return(maxed); }
public static void LoadCopy(StoreIncident incident) { string filePath = incident.defName + ".json"; try { using (StreamReader reader = File.OpenText(editorPath + filePath)) { string json = reader.ReadToEnd(); var node = JSON.Parse(json); if (node["abbreviation"] == null) { Log.Warning("Copy of store incident file is missing critical info, delete file " + editorPath + filePath); } incident.abbreviation = node["abbreviation"]; if (node["cost"] == null) { Log.Warning("Copy of store incident file is missing critical info, delete file " + editorPath + filePath); } incident.cost = node["cost"].AsInt; if (node["eventCap"] == null) { Log.Warning("Copy of store incident file is missing critical info, delete file " + editorPath + filePath); } incident.eventCap = node["eventCap"].AsInt; if (node["karmaType"] == null) { Log.Warning("Copy of store incident file is missing critical info, delete file " + editorPath + filePath); } incident.karmaType = (KarmaType)Enum.Parse(typeof(KarmaType), node["karmaType"], true); } } catch (UnauthorizedAccessException e) { Log.Warning(e.Message); } }
public void DoExtraSetup(IncidentWorker worker, IncidentParms @params, StoreIncident incident) { // A random disease incident doesn't need to do any extra setup. // This method exists solely because of the interface it implements. }
public IncidentCategoryDef ResolveCategory([NotNull] IncidentWorker worker, StoreIncident incident) { worker.def = DefDatabase <IncidentDef> .AllDefs.Where(i => i.workerClass.IsAssignableFrom(typeof(IncidentWorker_DiseaseHuman))).RandomElement(); return(worker.def.category); }
public void DoExtraSetup([NotNull] IncidentWorker worker, IncidentParms @params, StoreIncident incident) { worker.def = RimWorld.IncidentDefOf.TraderCaravanArrival; }
public IncidentCategoryDef ResolveCategory(IncidentWorker worker, StoreIncident incident) => IncidentCategoryDefOf.Misc;
public virtual bool IsPossible(StoreIncident incident, Viewer viewer) => false;
public override bool IsPossible(StoreIncident incident, Viewer viewer) => incident == IncidentDefOf.BuyPawn && viewer.username.Equals("crystalroseeve", StringComparison.InvariantCultureIgnoreCase);
public override void DoExtraSetup(IncidentWorker worker, IncidentParms @params, StoreIncident incident) { base.DoExtraSetup(worker, @params, incident); @params.raidStrategy = DefDatabase <RaidStrategyDef> .GetNamed("Siege"); @params.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn; }
public void DoExtraSetup([NotNull] IncidentWorker worker, IncidentParms @params, StoreIncident incident) { worker.def = IncidentDef.Named("Infestation"); }
public override bool IsPossible(StoreIncident incident, Viewer viewer) => incident == IncidentDefOf.BuyPawn && viewer.username.Equals("scavenging_mechanic", StringComparison.InvariantCultureIgnoreCase);