diff options
| -rw-r--r-- | Malmstone/Malmstone.csproj | 2 | ||||
| -rw-r--r-- | Malmstone/Malmstone.json | 2 | ||||
| -rw-r--r-- | Malmstone/Plugin.cs | 94 | ||||
| -rw-r--r-- | Malmstone/Windows/MainWindow.cs | 1 |
4 files changed, 94 insertions, 5 deletions
diff --git a/Malmstone/Malmstone.csproj b/Malmstone/Malmstone.csproj index dbc432f..4da4bfb 100644 --- a/Malmstone/Malmstone.csproj +++ b/Malmstone/Malmstone.csproj @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <Project Sdk="Microsoft.NET.Sdk"> - <Import Project="Dalamud.Plugin.Bootstrap.targets"/> + <Import Project="Dalamud.Plugin.Bootstrap.targets" /> <PropertyGroup> <Version>1.0.0.0</Version> diff --git a/Malmstone/Malmstone.json b/Malmstone/Malmstone.json index d93fcd7..1159d2a 100644 --- a/Malmstone/Malmstone.json +++ b/Malmstone/Malmstone.json @@ -2,7 +2,7 @@ "Author": "pinapelz", "Name": "Malmstone Calculator", "Punchline": "A PVP Series Malmstones Experience Calculator", - "Description": "Calculate how much more PVP you have to play before reaching a certain rank in the current PVP Series", + "Description": "Calculate how much more PVP you have to play before reaching a certain rank in the current PVP Series\nUse /pmalm to open the main window", "ApplicableVersion": "any", "Tags": [ "pvp", diff --git a/Malmstone/Plugin.cs b/Malmstone/Plugin.cs index 0455792..b78cccd 100644 --- a/Malmstone/Plugin.cs +++ b/Malmstone/Plugin.cs @@ -4,7 +4,12 @@ using Dalamud.Plugin; using Dalamud.Interface.Windowing; using Dalamud.Plugin.Services; using Malmstone.Windows; - +using Malmstone.Services; +using System; +using Dalamud.Game.Text.SeStringHandling; +using Dalamud.Game.Text.SeStringHandling.Payloads; +using System.Collections.Generic; +using System.Linq; namespace Malmstone; public sealed class Plugin : IDalamudPlugin @@ -13,6 +18,8 @@ public sealed class Plugin : IDalamudPlugin [PluginService] internal static ITextureProvider TextureProvider { get; private set; } = null!; [PluginService] internal static ICommandManager CommandManager { get; private set; } = null!; + [PluginService] internal static IChatGui Chat { get; private set; } = null!; + private const string CommandName = "/pmalm"; public Configuration Configuration { get; init; } @@ -20,6 +27,7 @@ public sealed class Plugin : IDalamudPlugin public readonly WindowSystem WindowSystem = new("Malmstone"); private ConfigWindow ConfigWindow { get; init; } private MainWindow MainWindow { get; init; } + private PvPService PvPService; public Plugin() { @@ -27,13 +35,14 @@ public sealed class Plugin : IDalamudPlugin ConfigWindow = new ConfigWindow(this); MainWindow = new MainWindow(this); + PvPService = new PvPService(); WindowSystem.AddWindow(ConfigWindow); WindowSystem.AddWindow(MainWindow); CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand) { - HelpMessage = "Open the Malmstone calculator main window" + HelpMessage = "/pmalm <rank> <all/cc/fl/rw> -- Displays PVP games left until a target rank. cc = Crystalline Conflict, fl = Frontlines, rw = Rivalwings" }); PluginInterface.UiBuilder.Draw += DrawUI; @@ -53,9 +62,88 @@ public sealed class Plugin : IDalamudPlugin private void OnCommand(string command, string args) { - ToggleMainUI(); + if (string.IsNullOrWhiteSpace(args)) + { + ToggleMainUI(); + return; + } + + var splitArgs = args.Split(' ', StringSplitOptions.RemoveEmptyEntries); + if (!int.TryParse(splitArgs[0], out int targetRank)) return; + var specs = new HashSet<string>(splitArgs.Skip(1).Select(spec => spec.ToLower())); + + var pvpInfo = PvPService.GetPvPSeriesInfo(); + if (pvpInfo == null) return; + + if (targetRank < 1) + { + Chat.PrintError("Can't have a target rank less than 1"); + return; + } + + if (targetRank > 107397) + { + Chat.PrintError("Can't have a target rank greater than 107397 (are you really gonna be able to reach that anyways?)"); + return; + } + + if (targetRank < pvpInfo.CurrentSeriesRank) + { + Chat.PrintError("You've already surpassed Rank " + targetRank); + return; + } + + var xpResult = Malmstone.Utils.MalmstoneXPCalculator.CalculateXp( + pvpInfo.CurrentSeriesRank, + targetRank, + pvpInfo.SeriesExperience); + + bool includeAll = specs.Contains("all"); + if (!specs.Any()) + { + includeAll = true; + } + var seString = new SeString(new List<Payload>()); + + if (includeAll || specs.Contains("cc")) + { + seString.Append(new TextPayload("Crystalline Conflict:\n")); + seString.Append(new UIForegroundPayload(35)); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Crystalline Conflict Win") ? $"Win: {xpResult.ActivityCounts["Crystalline Conflict Win"]} times\n" : "")); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Crystalline Conflict Lose") ? $"Lose: {xpResult.ActivityCounts["Crystalline Conflict Lose"]} times\n" : "")); + seString.Append(UIForegroundPayload.UIForegroundOff); + } + + if (includeAll || specs.Contains("fl")) + { + seString.Append(new TextPayload("\nFrontlines:\n")); + seString.Append(new UIForegroundPayload(518)); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Frontline Win") ? $"Take 1st Place: {xpResult.ActivityCounts["Frontline Win"]} times\n" : "")); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Frontline Lose 2nd") ? $"Take 2nd Place: {xpResult.ActivityCounts["Frontline Lose 2nd"]} times\n" : "")); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Frontline Lose 3rd") ? $"Take 3rd Place: {xpResult.ActivityCounts["Frontline Lose 3rd"]} times\n" : "")); + seString.Append(UIForegroundPayload.UIForegroundOff); + + seString.Append(new TextPayload("\nFrontlines (Roulette):\n")); + seString.Append(new UIForegroundPayload(518)); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Frontline Daily Win") ? $"Take 1st Place: {xpResult.ActivityCounts["Frontline Daily Win"]} times\n" : "")); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Frontline Daily Lose 2nd") ? $"Take 2nd Place: {xpResult.ActivityCounts["Frontline Daily Lose 2nd"]} times\n" : "")); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Frontline Daily Lose 3rd") ? $"Take 3rd Place: {xpResult.ActivityCounts["Frontline Daily Lose 3rd"]} times\n" : "")); + seString.Append(UIForegroundPayload.UIForegroundOff); + } + + if (includeAll || specs.Contains("rw")) + { + seString.Append(new TextPayload("\nRival Wings:\n")); + seString.Append(new UIForegroundPayload(43)); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Rival Wings Win") ? $"Win: {xpResult.ActivityCounts["Rival Wings Win"]} times\n" : "")); + seString.Append(new TextPayload(xpResult.ActivityCounts.ContainsKey("Rival Wings Lose") ? $"Lose: {xpResult.ActivityCounts["Rival Wings Lose"]} times\n" : "")); + seString.Append(UIForegroundPayload.UIForegroundOff); + } + + Chat.Print(seString); } + private void DrawUI() => WindowSystem.Draw(); public void ToggleConfigUI() => ConfigWindow.Toggle(); diff --git a/Malmstone/Windows/MainWindow.cs b/Malmstone/Windows/MainWindow.cs index a61db8b..111d877 100644 --- a/Malmstone/Windows/MainWindow.cs +++ b/Malmstone/Windows/MainWindow.cs @@ -37,6 +37,7 @@ namespace Malmstone.Windows public override void Draw() { + if (!IsOpen) return; var pvpInfo = PvPService.GetPvPSeriesInfo(); if (pvpInfo != null) { |
