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(); }
public static float RollProportionalGamePoints(StoreIncidentVariables incident, float pointsWager, float gamePoints) { int cost = incident.cost; int totalPossible = incident.maxWager - incident.minPointsToFire; float coinsPerThreatPoint = (totalPossible / 2) / gamePoints; float pointsPurchased = pointsWager / coinsPerThreatPoint; float rollToCoinRatio = totalPossible / 8; int totalRolls = (int)Math.Round(pointsWager / rollToCoinRatio); int highestRoll = 65; for (int i = 0; i < totalRolls; i++) { int roll = Verse.Rand.Range(65, 125); if (roll > highestRoll) { highestRoll = roll; } } float finalPoints = pointsPurchased * ((float)highestRoll / 100f); Helper.Log($"wager: {pointsWager} gamePoints: {gamePoints} pointsPurchased: {pointsPurchased} totalRolls: {totalRolls} highestRoll: {highestRoll} finalPoints: {finalPoints}"); Store_Logger.LogString($"wager: {pointsWager} gamePoints: {gamePoints} pointsPurchased: {pointsPurchased} totalRolls: {totalRolls} highestRoll: {highestRoll} finalPoints: {finalPoints}"); return(Math.Max(finalPoints, 35)); }
public static void LoadCopy(StoreIncidentVariables incident) { LoadCopy(incident as StoreIncident); string filePath = incident.defName + ".json"; try { using (StreamReader reader = File.OpenText(editorPath + filePath)) { string json = reader.ReadToEnd(); var node = JSON.Parse(json); if (node["minPointsToFire"] == null) { Log.Warning("Copy of store incident file is missing critical info, delete file " + editorPath + filePath); } incident.minPointsToFire = node["baseCost"].AsInt; if (node["maxWager"] == null) { Log.Warning("Copy of store incident file is missing critical info, delete file " + editorPath + filePath); } incident.maxWager = node["maxWager"].AsInt; } } catch (UnauthorizedAccessException e) { Log.Warning(e.Message); } }
public static void SaveCopy(StoreIncidentVariables 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($"\t\"minPointsToFire\":\"" + incident.minPointsToFire + "\","); json.AppendLine($"\t\"maxWager\":\"" + incident.maxWager + "\","); json.AppendLine("}"); Helper.Log(json.ToString()); using (StreamWriter streamWriter = File.CreateText(editorPath + filePath)) { streamWriter.Write(json.ToString()); } Log.Warning("Backup created"); }
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 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; }
private static bool IsOnCooldown(StoreIncidentVariables incident, [NotNull] Viewer viewer) { if (incident == StoreIncidentDefOf.Item) { return(Purchase_Handler.CheckIfCarePackageIsOnCooldown(viewer.username)); } if (incident != IncidentDefOf.Sanctuary && Purchase_Handler.CheckIfKarmaTypeIsMaxed(incident, viewer.username)) { return(true); } return(Purchase_Handler.CheckIfIncidentIsOnCooldown(incident, viewer.username)); }
private static bool TryMakeIncident(StoreIncidentVariables incident, Viewer viewer, string message, out IncidentHelperVariables incidentHelper) { incidentHelper = StoreIncidentMaker.MakeIncidentVariables(incident); if (incidentHelper == null) { return(false); } incidentHelper.Viewer = viewer; incidentHelper.message = message; return(true); }
public static void LoadBackup(StoreIncidentVariables incident) { StoreIncidentVariables incNew = variableIncidentsBackup.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; incident.minPointsToFire = incNew.minPointsToFire; incident.variables = incNew.variables; incident.minPointsToFire = incNew.minPointsToFire; incident.syntax = incNew.syntax; }
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; } }
public static bool CheckIfCarePackageIsOnCooldown(string username, bool separateChannel = false) { if (!ToolkitSettings.MaxEvents) { return(false); } Store_Component component = Current.Game.GetComponent <Store_Component>(); StoreIncidentVariables incident = DefDatabase <StoreIncidentVariables> .GetNamed("Item"); if (component.IncidentsInLogOf(incident.abbreviation) >= ToolkitSettings.MaxCarePackagesPerInterval) { float daysTill = component.DaysTillIncidentIsPurchaseable(incident); Toolkit.client.SendMessage($"@{username} care packages are on cooldown, wait " + daysTill + $" day{(daysTill != 1 ? "s" : "")}.", separateChannel); return(true); } return(false); }
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(); }
private static bool ResolvePurchaseVariablesPrefix( [NotNull] Viewer viewer, ITwitchMessage twitchMessage, [NotNull] StoreIncidentVariables incident, string formattedMessage ) { if (!Purchase_Handler.CheckIfViewerHasEnoughCoins(viewer, incident.cost) || IsOnCooldown(incident, viewer)) { return(false); } if (!TryMakeIncident(incident, viewer, formattedMessage, out IncidentHelperVariables inc)) { TkUtils.Logger.Warn(@$ "The incident " "{incident.defName}" " does not define an incident helper"); return(false); } Purchase_Handler.viewerNamesDoingVariableCommands.Add(viewer.username.ToLowerInvariant()); if (!inc.IsPossible(formattedMessage, viewer)) { Purchase_Handler.viewerNamesDoingVariableCommands.Remove(viewer.username.ToLowerInvariant()); return(false); } Store_Logger.LogPurchase(viewer.username, twitchMessage.Message); Current.Game.GetComponent <Coordinator>()?.QueueIncident(new IncidentProxy { VariablesIncident = inc }); Current.Game.GetComponent <Store_Component>()?.LogIncident(incident); return(false); }
private static bool TryFindVariableIncident(string query, [CanBeNull] out StoreIncidentVariables incidentVariables) { incidentVariables = Purchase_Handler.allStoreIncidentsVariables.Find(i => CheckIncident(i, query)); return(incidentVariables != null); }
public static void ResolvePurchaseVariables(Viewer viewer, TwitchIRCMessage message, StoreIncidentVariables incident, bool separateChannel = false) { int cost = incident.cost; if (cost < 1 && incident.defName != "Item") { return; } if (CheckIfViewerIsInVariableCommandList(viewer.username, separateChannel)) { return; } if (!CheckIfViewerHasEnoughCoins(viewer, cost, separateChannel)) { return; } if (incident != DefDatabase <StoreIncidentVariables> .GetNamed("Item")) { if (CheckIfKarmaTypeIsMaxed(incident, viewer.username, separateChannel)) { return; } } else { if (CheckIfCarePackageIsOnCooldown(viewer.username, separateChannel)) { return; } } if (CheckIfIncidentIsOnCooldown(incident, viewer.username, separateChannel)) { return; } viewerNamesDoingVariableCommands.Add(viewer.username); IncidentHelperVariables helper = StoreIncidentMaker.MakeIncidentVariables(incident); if (helper == null) { Helper.Log("Missing helper for incident " + incident.defName); return; } if (!helper.IsPossible(message.Message, viewer, separateChannel)) { if (viewerNamesDoingVariableCommands.Contains(viewer.username)) { viewerNamesDoingVariableCommands.Remove(viewer.username); } return; } Store_Component component = Current.Game.GetComponent <Store_Component>(); helper.Viewer = viewer; helper.message = message.Message; Ticker.IncidentHelperVariables.Enqueue(helper); Store_Logger.LogPurchase(viewer.username, message.Message); component.LogIncident(incident); }
public static bool PointsWagerIsValid(string wager, Viewer viewer, ref int pointsWager, ref StoreIncidentVariables incident, bool separateChannel = false, int quantity = 1, int maxPrice = 25000) { try { if (!int.TryParse(wager, out checked (pointsWager))) { ViewerDidWrongSyntax(viewer.username, incident.syntax); return(false); } pointsWager = checked (pointsWager * quantity); } catch (OverflowException e) { Helper.Log(e.Message); TwitchWrapper.SendChatMessage($"@{viewer.username} points wager is invalid."); return(false); } if (incident.maxWager > 0 && incident.maxWager > incident.cost && pointsWager > incident.maxWager) { TwitchWrapper.SendChatMessage($"@{viewer.username} you cannot spend more than {incident.maxWager} coins on {incident.abbreviation.CapitalizeFirst()}"); return(false); } //|| (incident.minPointsToFire > 0 && pointsWager < incident.minPointsToFire) if (pointsWager < incident.cost || pointsWager < incident.minPointsToFire) { TwitchWrapper.SendChatMessage(Helper.ReplacePlaceholder( "TwitchToolkitMinPurchaseNotMet".Translate(), viewer: viewer.username, amount: pointsWager.ToString(), first: incident.cost.ToString() )); return(false); } if (!Purchase_Handler.CheckIfViewerHasEnoughCoins(viewer, pointsWager)) { return(false); } return(true); }
public static void ResolvePurchaseVariables(Viewer viewer, IRCMessage message, StoreIncidentVariables incident, bool separateChannel = false) { int cost = incident.cost; if (cost < 1 && incident.defName != "Item") { return; } if (CheckIfViewerIsInVariableCommandList(viewer.username, separateChannel)) { return; } if (!CheckIfViewerHasEnoughCoins(viewer, cost, separateChannel)) { return; } if (CheckIfKarmaTypeIsMaxed(incident.karmaType, viewer.username, separateChannel)) { return; } if (CheckIfIncidentIsOnCooldown(incident, viewer.username, separateChannel)) { return; } viewerNamesDoingVariableCommands.Add(viewer.username); IncidentHelperVariables helper = StoreIncidentMaker.MakeIncidentVariables(incident); if (helper == null) { Log.Warning("Missing helper for incident " + incident.defName); return; } if (!helper.IsPossible(message.Message, viewer, separateChannel)) { if (viewerNamesDoingVariableCommands.Contains(viewer.username)) { viewerNamesDoingVariableCommands.Remove(viewer.username); } return; } QueuePlayerMessage(viewer, message.Message, incident.variables); Ticker.IncidentHelperVariables.Enqueue(helper); Store_Logger.LogPurchase(viewer.username, message.Message); component.LogIncident(incident); }