From 3a3a6613cd9783f421df0a152c8675a669910557 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sun, 8 Sep 2024 15:14:44 -0700 Subject: add preliminary frontline losing streak bonus tracking --- Malmstone/Addons/PvPMatchAddon.cs | 60 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'Malmstone/Addons/PvPMatchAddon.cs') diff --git a/Malmstone/Addons/PvPMatchAddon.cs b/Malmstone/Addons/PvPMatchAddon.cs index 78e0e38..c3f726a 100644 --- a/Malmstone/Addons/PvPMatchAddon.cs +++ b/Malmstone/Addons/PvPMatchAddon.cs @@ -5,12 +5,16 @@ using Malmstone.Utils; using Dalamud.Game.Text.SeStringHandling; using System.Collections.Generic; using Dalamud.Game.Text.SeStringHandling.Payloads; +using FFXIVClientStructs.FFXIV.Component.GUI; +using Dalamud.Memory; +using static Malmstone.Services.PvPService; namespace Malmstone.Addons { internal class PvPMatchAddon { private Plugin Plugin; + public bool FrontlineRecordPostSetupEnabled = false; private enum PvPContentType { CrystallineConflict = 1, @@ -49,11 +53,14 @@ namespace Malmstone.Addons public void EnableFrontlinePostMatch() { Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PostSetup, "FrontlineRecord", OnFrontlineRecordTrigger); + Plugin.PvPService.CurrentFrontlineLosingBonus = -1; // Reset bonus tracking for now until config save is done + FrontlineRecordPostSetupEnabled = true; } public void DisableFrontlinePostMatch() { Plugin.AddonLifeCycle.UnregisterListener(AddonEvent.PostSetup, "FrontlineRecord", OnFrontlineRecordTrigger); + FrontlineRecordPostSetupEnabled = false; } public void EnableRivalWingsPostMatch() @@ -64,12 +71,13 @@ namespace Malmstone.Addons { 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(); + CheckFrontlineBonus(eventType, addonInfo); if (seriesInfo == null) return; if (Plugin.Configuration.ShowProgressionChatPostCC) ShowSeriesProgressionMessage(seriesInfo, PvPContentType.CrystallineConflict); @@ -77,6 +85,8 @@ namespace Malmstone.Addons private void OnFrontlineRecordTrigger(AddonEvent eventType, AddonArgs addonInfo) { + if (Plugin.Configuration.TrackFrontlineBonus) + CheckFrontlineBonus(eventType, addonInfo); PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo(); if (seriesInfo == null) return; if (Plugin.Configuration.ShowProgressionChatPostFL) @@ -91,6 +101,54 @@ namespace Malmstone.Addons ShowSeriesProgressionMessage(seriesInfo, PvPContentType.RivalWings); } + private void CheckFrontlineBonus(AddonEvent eventType, AddonArgs addonInfo) + { + PVPProfileFrontlineResults CurrentFrontlineResults = Plugin.PvPService.GetPVPProfileFrontlineResults(); + if (CurrentFrontlineResults.FirstPlace == 0 && + CurrentFrontlineResults.SecondPlace == 0 && + CurrentFrontlineResults.ThirdPlace == 0) return; + // Check placement of current Frontline match + FrontlinePlacement FrontlineMatchResult = FrontlinePlacement.Unknown; + if (CurrentFrontlineResults.FirstPlace > Plugin.PvPService.CachedFrontlineResults.FirstPlace) + { + FrontlineMatchResult = FrontlinePlacement.FirstPlace; + } + else if (CurrentFrontlineResults.SecondPlace > Plugin.PvPService.CachedFrontlineResults.SecondPlace) + { + FrontlineMatchResult = FrontlinePlacement.SecondPlace; + } + else if (CurrentFrontlineResults.ThirdPlace > Plugin.PvPService.CachedFrontlineResults.ThirdPlace) + { + FrontlineMatchResult = FrontlinePlacement.ThirdPlace; + } + if (FrontlineMatchResult != FrontlinePlacement.Unknown) + { + unsafe + { + var FrontlineResultUnit = (AtkUnitBase*)addonInfo.Addon; + if (FrontlineResultUnit == null) return; + var SeriesExpComponent = FrontlineResultUnit->GetComponentByNodeId(35); + var SeriesExpTextNode = (AtkTextNode*)SeriesExpComponent->GetTextNodeById(2); + byte* SeriesExpTextBytePointer = SeriesExpTextNode->GetText(); + nint SeriesExpTextAddr = (nint)SeriesExpTextBytePointer; + string SeriesExpText = MemoryHelper.ReadStringNullTerminated(SeriesExpTextAddr); + if (int.TryParse(SeriesExpText, out int SeriesExpEarned)) + { + int CurrentLossBonus = Plugin.PvPService.GenerateFrontlineBonus(FrontlineMatchResult, SeriesExpEarned); + } + else + { + Plugin.Chat.PrintError("[Malmstone Calculator] Unable to get earned Series EXP: " + SeriesExpText); + } + } + } + else + { + Plugin.Chat.PrintError("[Malmstone Calculator] Unable to get current Frontline match results"); + } + Plugin.PvPService.UpdateFrontlineResultCache(); + } + private void ShowSeriesProgressionToast(AddonEvent eventType, AddonArgs addonInfo) { PvPSeriesInfo? seriesInfo = Plugin.PvPService.GetPvPSeriesInfo(); -- cgit v1.2.3 From 031440201d24531d6a1d5a0e93579d76e1e4ba18 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sun, 8 Sep 2024 16:52:23 -0700 Subject: add saving functionality to frontline reward bonus - marks as outdated if FrontlineRecord listener is disabled at any point --- Malmstone/Addons/PvPMatchAddon.cs | 7 ++++++- Malmstone/Configuration.cs | 4 +++- Malmstone/Plugin.cs | 1 + Malmstone/Windows/MainWindow.cs | 18 +++++++++++++++--- 4 files changed, 25 insertions(+), 5 deletions(-) (limited to 'Malmstone/Addons/PvPMatchAddon.cs') diff --git a/Malmstone/Addons/PvPMatchAddon.cs b/Malmstone/Addons/PvPMatchAddon.cs index c3f726a..896001a 100644 --- a/Malmstone/Addons/PvPMatchAddon.cs +++ b/Malmstone/Addons/PvPMatchAddon.cs @@ -53,7 +53,8 @@ namespace Malmstone.Addons public void EnableFrontlinePostMatch() { Plugin.AddonLifeCycle.RegisterListener(AddonEvent.PostSetup, "FrontlineRecord", OnFrontlineRecordTrigger); - Plugin.PvPService.CurrentFrontlineLosingBonus = -1; // Reset bonus tracking for now until config save is done + Plugin.PvPService.CurrentFrontlineLosingBonus = Plugin.Configuration.SavedFrontlineRewardBonus; + Plugin.Configuration.OutdatedFrontlineRewardBonus = true; FrontlineRecordPostSetupEnabled = true; } @@ -121,6 +122,7 @@ namespace Malmstone.Addons { FrontlineMatchResult = FrontlinePlacement.ThirdPlace; } + Plugin.Logger.Debug("Frontline Match Result: " + FrontlineMatchResult.ToString()); if (FrontlineMatchResult != FrontlinePlacement.Unknown) { unsafe @@ -135,6 +137,9 @@ namespace Malmstone.Addons if (int.TryParse(SeriesExpText, out int SeriesExpEarned)) { int CurrentLossBonus = Plugin.PvPService.GenerateFrontlineBonus(FrontlineMatchResult, SeriesExpEarned); + Plugin.Logger.Debug("Series EXP Earned: " + SeriesExpEarned.ToString()); + Plugin.Configuration.SavedFrontlineRewardBonus = CurrentLossBonus; + Plugin.Configuration.OutdatedFrontlineRewardBonus = false; } else { diff --git a/Malmstone/Configuration.cs b/Malmstone/Configuration.cs index c4d091b..4f62a96 100644 --- a/Malmstone/Configuration.cs +++ b/Malmstone/Configuration.cs @@ -17,7 +17,9 @@ public class Configuration : IPluginConfiguration public bool ShowMainWindowOnPVPReward { get; set; } = true; public bool SkipProgressionToastAfterGoal { get; set; } = false; public bool SkipProgressionChatAfterGoal { get; set; } = false; - public bool TrackFrontlineBonus { get; set; } = false; + public bool TrackFrontlineBonus { get; set; } = true; + public int SavedFrontlineRewardBonus { get; set; } = -1; + public bool OutdatedFrontlineRewardBonus { get; set; } = false; // the below exist just to make saving less cumbersome public void Save() diff --git a/Malmstone/Plugin.cs b/Malmstone/Plugin.cs index 87ebb06..ada8202 100644 --- a/Malmstone/Plugin.cs +++ b/Malmstone/Plugin.cs @@ -24,6 +24,7 @@ public sealed class Plugin : IDalamudPlugin [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!; + [PluginService] internal static IPluginLog Logger { get; set; } = default!; private const string CommandName = "/pmalm"; diff --git a/Malmstone/Windows/MainWindow.cs b/Malmstone/Windows/MainWindow.cs index 8da004f..bd1ef5d 100644 --- a/Malmstone/Windows/MainWindow.cs +++ b/Malmstone/Windows/MainWindow.cs @@ -26,7 +26,7 @@ namespace Malmstone.Windows { SizeConstraints = new WindowSizeConstraints { - MinimumSize = new Vector2(460, 510), + MinimumSize = new Vector2(460, 530), MaximumSize = new Vector2(float.MaxValue, float.MaxValue) }; @@ -120,7 +120,7 @@ namespace Malmstone.Windows { if(Plugin.PvPService.CurrentFrontlineLosingBonus == 0) { - ImGui.TextColored(new Vector4(0.0f, 1.0f, 0.0f, 1.0f), "No Frontline Reward Bonus Currently Active"); + ImGui.Text("No Frontline Reward Bonus Currently Active"); } else { @@ -129,7 +129,19 @@ namespace Malmstone.Windows { ImGui.BeginTooltip(); ImGui.Text("You will earn a " + Plugin.PvPService.CurrentFrontlineLosingBonus + "%% bonus on PvP EXP, Series EXP, and Wolf Marks " + - "until attain First Place" ); + "until attaining First Place" ); + ImGui.EndTooltip(); + } + } + if (Plugin.Configuration.OutdatedFrontlineRewardBonus) + { + ImGui.SameLine(); + ImGui.TextColored(new Vector4(1.0f, 0.0f, 0.0f, 1.0f),"(Outdated)"); + if (ImGui.IsItemHovered()) + { + ImGui.BeginTooltip(); + ImGui.Text("This information may be outdated due to Frontline tracking loading and unloading!" + + "\nCalculations will refresh after your next match of Frontlines"); ImGui.EndTooltip(); } } -- cgit v1.2.3