public static IncidentHelper MakeIncident(StoreIncidentSimple def) { IncidentHelper helper = (IncidentHelper)Activator.CreateInstance(def.incidentHelper); helper.storeIncident = def; return(helper); }
public static void ResolvePurchase(Viewer viewer, ITwitchMessage twitchMessage, bool separateChannel = false) { List <string> command = twitchMessage.Message.Split(' ').ToList(); if (command.Count < 2) { return; } if (command[0] == "!levelskill") { command[0] = "levelskill"; command.Insert(0, "!buy"); } string productKey = command[1].ToLower(); string formattedMessage = string.Join(" ", command.ToArray()); StoreIncidentSimple incident = allStoreIncidentsSimple.Find(s => productKey.ToLower() == s.abbreviation); if (incident != null) { ResolvePurchaseSimple(viewer, twitchMessage, incident, formattedMessage); return; } StoreIncidentVariables incidentVariables = allStoreIncidentsVariables.Find(s => productKey.ToLower() == s.abbreviation); if (incidentVariables != null) { ResolvePurchaseVariables(viewer, twitchMessage, incidentVariables, formattedMessage); return; } Item item = StoreInventory.items.Find(s => s.abr == productKey); Helper.Log($"abr: {productKey} "); if (item != null) { List <String> commandSplit = twitchMessage.Message.Split(' ').ToList(); commandSplit.Insert(1, "item"); if (commandSplit.Count < 4) { commandSplit.Add("1"); } if (!int.TryParse(commandSplit[3], out int quantity)) { commandSplit.Insert(3, "1"); } formattedMessage = string.Join(" ", commandSplit.ToArray()); ResolvePurchaseVariables(viewer, twitchMessage, StoreIncidentDefOf.Item, formattedMessage); } return; }
public static void SaveCopy(StoreIncidentSimple incident) { if (!EditorPathExists()) { throw new DirectoryNotFoundException(); } string filePath = incident.defName + ".json"; StringBuilder json = new StringBuilder(); json.AppendLine("{"); json.AppendLine($"\t\"defName\":\"" + incident.defName + "\","); json.AppendLine($"\t\"abbreviation\":\"" + incident.abbreviation + "\","); json.AppendLine($"\t\"cost\":\"" + incident.cost + "\","); json.AppendLine($"\t\"eventCap\":\"" + incident.eventCap + "\","); json.AppendLine($"\t\"karmaType\":\"" + incident.karmaType + "\""); json.AppendLine("}"); Helper.Log(json.ToString()); using (StreamWriter streamWriter = File.CreateText(editorPath + filePath)) { streamWriter.Write(json.ToString()); } Log.Warning("Backup created"); }
public static void LoadBackup(StoreIncidentSimple incident) { StoreIncidentSimple incNew = simpleIncidentsBackup.ToList().Find(s => incident.defName == s.defName); incident.abbreviation = incNew.abbreviation; incident.cost = incNew.cost; incident.eventCap = incNew.eventCap; incident.karmaType = incNew.karmaType; incident.incidentHelper = incNew.incidentHelper; }
public static void LoadBackupSimple(ref StoreIncidentSimple incident) { string defName = incident.defName; StoreIncidentSimple incNew = simpleIncidentsBackup.ToList().Find(s => defName == s.defName); incident.abbreviation = incNew.abbreviation; incident.cost = incNew.cost; incident.eventCap = incNew.eventCap; incident.karmaType = incNew.karmaType; incident = incNew; }
public static void LoadBackup(StoreIncidentSimple incident) { Helper.Log("loading simple backup"); StoreIncidentSimple incNew = simpleIncidentsBackup.ToList().Find(s => incident.defName == s.defName); Helper.Log($"backup: {incNew.cost} - {incNew.defName}"); incident.abbreviation = incNew.abbreviation; incident.cost = incNew.cost; incident.eventCap = incNew.eventCap; incident.karmaType = incNew.karmaType; incident.incidentHelper = incNew.incidentHelper; }
private static bool ResolvePurchaseSimplePrefix( [NotNull] Viewer viewer, ITwitchMessage twitchMessage, [NotNull] StoreIncidentSimple incident, string formattedMessage ) { if (!Purchase_Handler.CheckIfViewerHasEnoughCoins(viewer, incident.cost)) { return(false); } if (Purchase_Handler.CheckIfKarmaTypeIsMaxed(incident, viewer.username)) { return(false); } if (!TryMakeIncident(incident, viewer, formattedMessage, out IncidentHelper inc)) { TkUtils.Logger.Warn(@$ "The incident " "{incident.defName}" " does not define an incident helper"); return(false); } if (!inc.IsPossible()) { MessageHelper.ReplyToUser(viewer.username, "TwitchToolkitEventNotPossible".Localize()); return(false); } viewer.Charge(incident); Current.Game.GetComponent <Coordinator>()?.QueueIncident(new IncidentProxy { SimpleIncident = inc }); Current.Game.GetComponent <Store_Component>()?.LogIncident(incident); Store_Logger.LogPurchase(viewer.username, twitchMessage.Message); if (!ToolkitSettings.PurchaseConfirmations) { return(false); } TwitchWrapper.SendChatMessage( Helper.ReplacePlaceholder("TwitchToolkitEventPurchaseConfirm".Localize(), viewer: viewer.username, first: incident.label.CapitalizeFirst()) ); return(false); }
private static bool TryMakeIncident(StoreIncidentSimple incident, Viewer viewer, string message, out IncidentHelper incidentHelper) { incidentHelper = StoreIncidentMaker.MakeIncident(incident); if (incidentHelper == null) { return(false); } incidentHelper.Viewer = viewer; incidentHelper.message = message; return(true); }
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; } }
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; } }
static Store_IncidentEditor() { List <StoreIncidentSimple> simpleIncidents = DefDatabase <StoreIncidentSimple> .AllDefs.ToList(); List <StoreIncidentVariables> variableIncidents = DefDatabase <StoreIncidentVariables> .AllDefs.ToList(); foreach (StoreIncidentSimple inc in simpleIncidents) { StoreIncidentSimple backup = new StoreIncidentSimple(); backup.defName = inc.defName; backup.abbreviation = inc.abbreviation; backup.cost = inc.cost; backup.eventCap = inc.eventCap; backup.karmaType = inc.karmaType; backup.incidentHelper = inc.incidentHelper; simpleIncidentsBackup.Add(backup); } foreach (StoreIncidentVariables inc in variableIncidents) { StoreIncidentVariables backup = new StoreIncidentVariables(); backup.defName = inc.defName; backup.abbreviation = inc.abbreviation; backup.cost = inc.cost; backup.eventCap = inc.eventCap; backup.karmaType = inc.karmaType; backup.incidentHelper = inc.incidentHelper; backup.minPointsToFire = inc.minPointsToFire; backup.variables = inc.variables; backup.maxWager = inc.maxWager; backup.syntax = inc.syntax; variableIncidentsBackup.Add(backup); } LoadCopies(); Store_IncidentEditor.UpdatePriceSheet(); }
public static void ResolvePurchaseSimple(Viewer viewer, TwitchIRCMessage message, StoreIncidentSimple incident, bool separateChannel = false) { int cost = incident.cost; if (cost < 1) { return; } if (CheckIfViewerIsInVariableCommandList(viewer.username, separateChannel)) { return; } if (!CheckIfViewerHasEnoughCoins(viewer, cost, separateChannel)) { return; } if (CheckIfKarmaTypeIsMaxed(incident, viewer.username, separateChannel)) { return; } if (CheckIfIncidentIsOnCooldown(incident, viewer.username, separateChannel)) { return; } IncidentHelper helper = StoreIncidentMaker.MakeIncident(incident); if (helper == null) { Helper.Log("Missing helper for incident " + incident.defName); return; } if (!helper.IsPossible()) { Toolkit.client.SendMessage($"@{viewer.username} " + "TwitchToolkitEventNotPossible".Translate(), separateChannel); return; } if (!ToolkitSettings.UnlimitedCoins) { viewer.TakeViewerCoins(cost); } Store_Component component = Current.Game.GetComponent <Store_Component>(); helper.Viewer = viewer; helper.message = message.Message; Ticker.IncidentHelpers.Enqueue(helper); Store_Logger.LogPurchase(viewer.username, message.Message); component.LogIncident(incident); viewer.CalculateNewKarma(incident.karmaType, cost); if (ToolkitSettings.PurchaseConfirmations) { Toolkit.client.SendMessage( Helper.ReplacePlaceholder( "TwitchToolkitEventPurchaseConfirm".Translate(), first: incident.label.CapitalizeFirst(), viewer: viewer.username ), separateChannel ); } }
public static void LoadCopy(StoreIncidentSimple incident) { LoadCopy(incident as StoreIncident); }
private static bool TryFindSimpleIncident(string query, [CanBeNull] out StoreIncidentSimple incidentSimple) { incidentSimple = Purchase_Handler.allStoreIncidentsSimple.Find(i => CheckIncident(i, query)); return(incidentSimple != null); }