diff options
| -rw-r--r-- | Malmstone/Addons/PvPMatchAddon.cs | 162 | ||||
| -rw-r--r-- | Malmstone/Configuration.cs | 5 | ||||
| -rw-r--r-- | Malmstone/Malmstone.csproj | 2 | ||||
| -rw-r--r-- | Malmstone/Plugin.cs | 20 | ||||
| -rw-r--r-- | Malmstone/Utils/MalmstoneXPCalculator.cs | 10 | ||||
| -rw-r--r-- | Malmstone/Windows/ConfigWindow.cs | 102 | ||||
| -rw-r--r-- | Malmstone/Windows/MainWindow.cs | 11 |
7 files changed, 296 insertions, 16 deletions
diff --git a/Malmstone/Addons/PvPMatchAddon.cs b/Malmstone/Addons/PvPMatchAddon.cs new file mode 100644 index 0000000..0acb617 --- /dev/null +++ b/Malmstone/Addons/PvPMatchAddon.cs @@ -0,0 +1,162 @@ +using Dalamud.Game.Addon.Lifecycle.AddonArgTypes; +using Dalamud.Game.Addon.Lifecycle; +using Malmstone.Services; +using Malmstone.Utils; +using Dalamud.Game.Text.SeStringHandling; +using System.Collections.Generic; +using Dalamud.Game.Text.SeStringHandling.Payloads; + +namespace Malmstone.Addons +{ + internal class PvPMatchAddon + { + private Plugin Plugin; + private enum PvPContentType + { + CrystallineConflict = 1, + RivalWings = 2, + Frontlines = 3, + } + public PvPMatchAddon(Plugin Plugin) + { + this.Plugin = Plugin; + } + + public void EnablePostMatchProgressionToast() + { + Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PreSetup, "MKSRecord", ShowSeriesProgressionToast); + Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PreSetup, "FrontlineRecord", ShowSeriesProgressionToast); + Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PreSetup, "ManeuversRecord", ShowSeriesProgressionToast); + } + + public void DisablePostMatchProgressionToast() + { + Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PreSetup, "MKSRecord", ShowSeriesProgressionToast); + Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PreSetup, "FrontlineRecord", ShowSeriesProgressionToast); + Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PreSetup, "ManeuversRecord", ShowSeriesProgressionToast); + } + + public void EnableCrystallineConflictPostMatch() + { + Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PostSetup, "MKSRecord", OnCrystallineConflictRecordTrigger); + } + + public void DisableCrystallineConflictPostMatch() + { + Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PostSetup, "MKSRecord", OnCrystallineConflictRecordTrigger); + } + + public void EnableFrontlinePostMatch() + { + Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PostSetup, "FrontlineRecord", OnFrontlineRecordTrigger); + } + + public void DisableFrontlinePostMatch() + { + Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PostSetup, "FrontlineRecord", OnFrontlineRecordTrigger); + } + + public void EnableRivalWingsPostMatch() + { + Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PostSetup, "ManeuversRecord", OnRivalWingsRecordTrigger); + } + public void DisableRivalWingsPostMatch() + { + Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PostSetup, "ManeuversRecord", OnRivalWingsRecordTrigger); + } + + + // Runs on the result screen of the respective game mode + private void OnCrystallineConflictRecordTrigger(AddonEvent eventType, AddonArgs addonInfo) + { + PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo(); + if (seriesInfo == null) return; + if (Plugin.Configuration.ShowProgressionChatPostCC) + ShowSeriesProgressionMessage(seriesInfo, PvPContentType.CrystallineConflict); + } + + private void OnFrontlineRecordTrigger(AddonEvent eventType, AddonArgs addonInfo) + { + PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo(); + if (seriesInfo == null) return; + if (Plugin.Configuration.ShowProgressionChatPostFL) + ShowSeriesProgressionMessage(seriesInfo, PvPContentType.RivalWings); + } + + private void OnRivalWingsRecordTrigger(AddonEvent eventType, AddonArgs addonInfo) + { + PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo(); + if (seriesInfo == null) return; + if (Plugin.Configuration.ShowProgressionChatPostRW) + ShowSeriesProgressionMessage(seriesInfo, PvPContentType.RivalWings); + } + + private void ShowSeriesProgressionToast(AddonEvent eventType, AddonArgs addonInfo) + { + PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo(); + if (seriesInfo == null) return; + switch (Plugin.Configuration.PostmatchProgressionToastType) + { + case 0: + Plugin.ToastGui.ShowNormal("Series Level " + seriesInfo.CurrentSeriesRank + + " " + seriesInfo.SeriesExperience + "/" + MalmstoneXPCalculator.GetXPTargetForCurrentLevel(seriesInfo.CurrentSeriesRank) + " EXP"); + break; + case 1: + Plugin.ToastGui.ShowQuest("Series Level " + seriesInfo.CurrentSeriesRank + + " " + seriesInfo.SeriesExperience + "/" + MalmstoneXPCalculator.GetXPTargetForCurrentLevel(seriesInfo.CurrentSeriesRank) + " EXP"); + break; + case 2: + Plugin.ToastGui.ShowError("Series Level " + seriesInfo.CurrentSeriesRank + + " " + seriesInfo.SeriesExperience + "/" + MalmstoneXPCalculator.GetXPTargetForCurrentLevel(seriesInfo.CurrentSeriesRank) + " EXP"); + break; + default: + Plugin.ToastGui.ShowNormal("Series Level " + seriesInfo.CurrentSeriesRank + + " " + seriesInfo.SeriesExperience + "/" + MalmstoneXPCalculator.GetXPTargetForCurrentLevel(seriesInfo.CurrentSeriesRank) + " EXP"); + break; + } + + } + + private void ShowSeriesProgressionMessage(PvPSeriesInfo seriesInfo, PvPContentType contentType) + { + var seString = new SeString(new List<Payload>()); + switch (contentType) + { + case PvPContentType.CrystallineConflict: + MalmstoneXPCalculator.XpCalculationResult ccResultData = MalmstoneXPCalculator.CalculateCrystallineConflictMatches( + seriesInfo.CurrentSeriesRank, seriesInfo.CurrentSeriesRank + 1, seriesInfo.SeriesExperience); + if (ccResultData.CrystallineConflictLose == 0) break; + seString.Append(new TextPayload("[Crystalline Conflict to Level " + (seriesInfo.CurrentSeriesRank + 1) + "]\n")); + seString.Append(new UIForegroundPayload(35)); + seString.Append(new TextPayload($"Win: {ccResultData.CrystallineConflictWin} " + (ccResultData.CrystallineConflictWin == 1 ? "time" : "times") + "\n")); + seString.Append(new TextPayload($"Lose: {ccResultData.CrystallineConflictLose} " + (ccResultData.CrystallineConflictLose == 1 ? "time" : "times"))); + seString.Append(UIForegroundPayload.UIForegroundOff); + break; + case PvPContentType.Frontlines: + MalmstoneXPCalculator.XpCalculationResult flResultData = MalmstoneXPCalculator.CalculateCrystallineConflictMatches( + seriesInfo.CurrentSeriesRank, seriesInfo.CurrentSeriesRank + 1, seriesInfo.SeriesExperience); + if (flResultData.FrontlineDailyLose3rd == 0) break; + seString.Append(new TextPayload("[Frontlines to Level " + (seriesInfo.CurrentSeriesRank + 1) + "]\n")); + seString.Append(new UIForegroundPayload(518)); + seString.Append(new TextPayload($"Take 1st Place: {flResultData.FrontlineWin} " + (flResultData.FrontlineWin == 1 ? "time" : "times") +" (" + (flResultData.FrontlineDailyWin) + ")\n")); + seString.Append(new TextPayload($"Take 2nd Place: {flResultData.FrontlineWin} " + (flResultData.FrontlineWin == 1 ? "time" : "times") + " (" + (flResultData.FrontlineDailyLose2nd) + ")\n")); + seString.Append(new TextPayload($"Take 3rd Place: {flResultData.FrontlineWin} " + (flResultData.FrontlineWin == 1 ? "time" : "times") + " (" + (flResultData.FrontlineDailyLose3rd) + ")\n")); + seString.Append(UIForegroundPayload.UIForegroundOff); + break; + case PvPContentType.RivalWings: + MalmstoneXPCalculator.XpCalculationResult rwResultData = MalmstoneXPCalculator.CalculateRivalWingsMatches( + seriesInfo.CurrentSeriesRank, seriesInfo.CurrentSeriesRank + 1, seriesInfo.SeriesExperience); + if (rwResultData.RivalWingsLose == 0) break; + seString.Append(new TextPayload("[Rival Wings to Level " + (seriesInfo.CurrentSeriesRank + 1) + "]\n")); + seString.Append(new UIForegroundPayload(43)); + seString.Append(new TextPayload($"Win: {rwResultData.RivalWingsWin} " + (rwResultData.RivalWingsWin == 1 ? "time" : "times") + "\n")); + seString.Append(new TextPayload($"Lose: {rwResultData.RivalWingsLose} " + (rwResultData.RivalWingsLose == 1 ? "time" : "times"))); + seString.Append(UIForegroundPayload.UIForegroundOff); + break; + } + Plugin.Chat.Print(seString); + } + + + } +} diff --git a/Malmstone/Configuration.cs b/Malmstone/Configuration.cs index e0d5a3c..ce87dfd 100644 --- a/Malmstone/Configuration.cs +++ b/Malmstone/Configuration.cs @@ -10,6 +10,11 @@ public class Configuration : IPluginConfiguration public int Version { get; set; } = 0; public int DefaultTargetRankProperty { get; set; } = 1; + public int PostmatchProgressionToastType { get; set; } = 0; // 0 = normal, 1=quest, 2=error + public bool ShowProgressionToastPostMatch { get; set; } = true; + public bool ShowProgressionChatPostRW { get; set; } = true; + public bool ShowProgressionChatPostCC { get; set; } = true; + public bool ShowProgressionChatPostFL { get; set; } = true; // the below exist just to make saving less cumbersome public void Save() diff --git a/Malmstone/Malmstone.csproj b/Malmstone/Malmstone.csproj index 3f1e5c7..8aa6086 100644 --- a/Malmstone/Malmstone.csproj +++ b/Malmstone/Malmstone.csproj @@ -3,7 +3,7 @@ <Import Project="Dalamud.Plugin.Bootstrap.targets" /> <PropertyGroup> - <Version>1.0.0.0</Version> + <Version>1.0.5.0</Version> <Description>A PVP Series Malmstones Level Calculator</Description> <PackageProjectUrl>https://github.com/goatcorp/Malmstone</PackageProjectUrl> <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression> diff --git a/Malmstone/Plugin.cs b/Malmstone/Plugin.cs index 6f5e50c..b2cfde7 100644 --- a/Malmstone/Plugin.cs +++ b/Malmstone/Plugin.cs @@ -11,6 +11,7 @@ using Dalamud.Game.Text.SeStringHandling.Payloads; using System.Collections.Generic; using System.Linq; using Malmstone.Utils; +using Malmstone.Addons; namespace Malmstone; @@ -20,6 +21,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!; + [PluginService] internal static IAddonLifecycle AddonLifeCycle { get; private set; } = null!; + [PluginService] internal static IToastGui ToastGui { get; private set; } = null!; private const string CommandName = "/pmalm"; @@ -28,7 +31,9 @@ public sealed class Plugin : IDalamudPlugin public readonly WindowSystem WindowSystem = new("Malmstone"); private ConfigWindow ConfigWindow { get; init; } private MainWindow MainWindow { get; init; } + internal readonly PvPService PvPService; + internal PvPMatchAddon PvPAddon; public Plugin() { @@ -37,8 +42,21 @@ public sealed class Plugin : IDalamudPlugin ConfigWindow = new ConfigWindow(this); MainWindow = new MainWindow(this); PvPService = new PvPService(); + PvPAddon = new PvPMatchAddon(this); + if (Configuration.ShowProgressionChatPostCC) + PvPAddon.EnableCrystallineConflictPostMatch(); + if (Configuration.ShowProgressionChatPostRW) + PvPAddon.EnableRivalWingsPostMatch(); + if (Configuration.ShowProgressionChatPostFL) + PvPAddon.EnableFrontlinePostMatch(); + if (Configuration.ShowProgressionToastPostMatch) + PvPAddon.EnablePostMatchProgressionToast(); + if (Configuration.PostmatchProgressionToastType < 0 || Configuration.PostmatchProgressionToastType > 2) + { + Configuration.PostmatchProgressionToastType = 0; + } - WindowSystem.AddWindow(ConfigWindow); + WindowSystem.AddWindow(ConfigWindow); WindowSystem.AddWindow(MainWindow); CommandManager.AddHandler(CommandName, new CommandInfo(OnCommand) diff --git a/Malmstone/Utils/MalmstoneXPCalculator.cs b/Malmstone/Utils/MalmstoneXPCalculator.cs index ab6fcf9..cc555a6 100644 --- a/Malmstone/Utils/MalmstoneXPCalculator.cs +++ b/Malmstone/Utils/MalmstoneXPCalculator.cs @@ -108,6 +108,16 @@ namespace Malmstone.Utils }; } + public static int GetXPTargetForCurrentLevel(int currentLevel) + { + if (currentLevel >= PvpLevels.Length) + { + return InfinityLevelExp; + } + return PvpLevels[currentLevel]; + + } + private static int CalculateRemainingXpForLevels(int currentLevel, int goalLevel, int currentProgress) { int remainingXp = 0; diff --git a/Malmstone/Windows/ConfigWindow.cs b/Malmstone/Windows/ConfigWindow.cs index 2c2895b..e6376b3 100644 --- a/Malmstone/Windows/ConfigWindow.cs +++ b/Malmstone/Windows/ConfigWindow.cs @@ -8,14 +8,19 @@ namespace Malmstone.Windows; public class ConfigWindow : Window, IDisposable { private Configuration Configuration; + private Plugin Plugin; + private string[] ToastOptions = {"Normal", "Quest", "Error"}; - public ConfigWindow(Plugin plugin) : base("Malmstone Config") + public ConfigWindow(Plugin Plugin) : base("Malmstone Config") { - Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | - ImGuiWindowFlags.NoScrollWithMouse; - - Size = new Vector2(232, 150); - Configuration = plugin.Configuration; + Flags = ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse; + SizeConstraints = new WindowSizeConstraints + { + MinimumSize = new Vector2(350, 300), + MaximumSize = new Vector2(float.MaxValue, float.MaxValue) + }; + Configuration = Plugin.Configuration; + this.Plugin = Plugin; } public void Dispose() { } @@ -33,14 +38,93 @@ public class ConfigWindow : Window, IDisposable if (savedTargetSeriesRank < 1) savedTargetSeriesRank = 1; if (savedTargetSeriesRank > 107397) savedTargetSeriesRank = 107397; Configuration.DefaultTargetRankProperty = savedTargetSeriesRank; + Configuration.Save(); } - ImGui.Spacing(); + ImGui.Separator(); + + ImGui.Text("Show EXP progression after PVP matches"); + ImGui.SameLine(); + var showProgressionToastPostMatch = Configuration.ShowProgressionToastPostMatch; + if (ImGui.Checkbox("##ShowProgressionToastPostMatch", ref showProgressionToastPostMatch)) + { + Configuration.ShowProgressionToastPostMatch = showProgressionToastPostMatch; + if (showProgressionToastPostMatch) + Plugin.PvPAddon.EnablePostMatchProgressionToast(); + else + Plugin.PvPAddon.DisablePostMatchProgressionToast(); + Configuration.Save(); + } + + ImGui.Text("Notification Type"); + int selectedPostMatchToastType = Configuration.PostmatchProgressionToastType; + if (ImGui.Combo("##MatchOptions", ref selectedPostMatchToastType, ToastOptions, ToastOptions.Length)) + { + switch (selectedPostMatchToastType) + { + case 0: + Plugin.ToastGui.ShowNormal("[Malmstone Calculator] Normal Toast Selected"); + break; + case 1: + Plugin.ToastGui.ShowQuest("[Malmstone Calculator] Quest Toast Selected"); + break; + case 2: + Plugin.ToastGui.ShowError("[Malmstone Calculator] Error Toast Selected"); + break; + } + Configuration.PostmatchProgressionToastType = selectedPostMatchToastType; + Configuration.Save(); + } + + ImGui.Separator(); + ImGui.Text("Show matches until next rank in chat after"); + - if (ImGui.Button("Save and Close")) + var showCCMatchesRemainingPostGame = Configuration.ShowProgressionChatPostCC; + if (ImGui.Checkbox("##ShowCCMatchesRemainingPostGame", ref showCCMatchesRemainingPostGame)) { + Configuration.ShowProgressionChatPostCC = showCCMatchesRemainingPostGame; + if (showCCMatchesRemainingPostGame) + Plugin.PvPAddon.EnableCrystallineConflictPostMatch(); + else + Plugin.PvPAddon.DisableCrystallineConflictPostMatch(); Configuration.Save(); - IsOpen = false; } + ImGui.SameLine(); + ImGui.Text("Crystalline Conflict"); + + + var showFLMatchesRemainingPostGame = Configuration.ShowProgressionChatPostFL; + if (ImGui.Checkbox("##ShowFLMatchesRemainingPostGame", ref showFLMatchesRemainingPostGame)) + { + Configuration.ShowProgressionChatPostFL = showFLMatchesRemainingPostGame; + if (showFLMatchesRemainingPostGame) + Plugin.PvPAddon.EnableFrontlinePostMatch(); + else + Plugin.PvPAddon.DisableFrontlinePostMatch(); + Configuration.Save(); + } + ImGui.SameLine(); + ImGui.Text("Frontlines"); + + + var showRWMatchesRemainingPostGame = Configuration.ShowProgressionChatPostRW; + if (ImGui.Checkbox("##ShowRWMatchesRemainingPostGame", ref showRWMatchesRemainingPostGame)) + { + Configuration.ShowProgressionChatPostRW = showRWMatchesRemainingPostGame; + if (showRWMatchesRemainingPostGame) + Plugin.PvPAddon.EnableRivalWingsPostMatch(); + else + Plugin.PvPAddon.DisableRivalWingsPostMatch(); + Configuration.Save(); + } + ImGui.SameLine(); + ImGui.Text("Rival Wings"); + + + ImGui.Separator(); + ImGui.Spacing(); + ImGui.Text("Changes saved automatically"); + } } diff --git a/Malmstone/Windows/MainWindow.cs b/Malmstone/Windows/MainWindow.cs index 08550d4..3cd53a4 100644 --- a/Malmstone/Windows/MainWindow.cs +++ b/Malmstone/Windows/MainWindow.cs @@ -24,7 +24,7 @@ namespace Malmstone.Windows { SizeConstraints = new WindowSizeConstraints { - MinimumSize = new Vector2(440, 510), + MinimumSize = new Vector2(460, 510), MaximumSize = new Vector2(float.MaxValue, float.MaxValue) }; @@ -110,13 +110,14 @@ namespace Malmstone.Windows ImGui.Separator(); ImGui.Spacing(); + if (ImGui.Button("Settings")) + Plugin.ToggleConfigUI(); + ImGui.SameLine(); if (pvpInfo.CurrentSeriesRank != pvpInfo.ClaimedSeriesRank) { - ImGui.SameLine(); - ImGui.Text("Don't forget to claim your rank rewards!"); + ImGui.Text("Don't forget to claim your Series Malmstone rewards!"); } - if (ImGui.Button("Settings")) - Plugin.ToggleConfigUI(); + } else { |
