diff options
| author | Pinapelz <yukais@pinapelz.com> | 2024-09-08 15:14:44 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2024-09-08 15:14:44 -0700 |
| commit | 3a3a6613cd9783f421df0a152c8675a669910557 (patch) | |
| tree | 0f7bc304079e7e829b4897953a0d4fb57a0d4e0f | |
| parent | 728d9ff38a19f0a8b72bcb004d56edabec138af8 (diff) | |
add preliminary frontline losing streak bonus tracking
| -rw-r--r-- | Malmstone/Addons/PvPMatchAddon.cs | 60 | ||||
| -rw-r--r-- | Malmstone/Configuration.cs | 2 | ||||
| -rw-r--r-- | Malmstone/Plugin.cs | 9 | ||||
| -rw-r--r-- | Malmstone/Services/PVPService.cs | 148 | ||||
| -rw-r--r-- | Malmstone/Windows/ConfigWindow.cs | 30 | ||||
| -rw-r--r-- | Malmstone/Windows/MainWindow.cs | 35 |
6 files changed, 277 insertions, 7 deletions
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(); diff --git a/Malmstone/Configuration.cs b/Malmstone/Configuration.cs index 1d0ed84..c4d091b 100644 --- a/Malmstone/Configuration.cs +++ b/Malmstone/Configuration.cs @@ -1,5 +1,4 @@ using Dalamud.Configuration; -using Dalamud.Plugin; using System; namespace Malmstone; @@ -18,6 +17,7 @@ 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; // the below exist just to make saving less cumbersome public void Save() diff --git a/Malmstone/Plugin.cs b/Malmstone/Plugin.cs index 5ed6a65..87ebb06 100644 --- a/Malmstone/Plugin.cs +++ b/Malmstone/Plugin.cs @@ -48,12 +48,14 @@ public sealed class Plugin : IDalamudPlugin PvPAddon.EnableCrystallineConflictPostMatch(); if (Configuration.ShowProgressionChatPostRW) PvPAddon.EnableRivalWingsPostMatch(); - if (Configuration.ShowProgressionChatPostFL) + if (Configuration.ShowProgressionChatPostFL || Configuration.TrackFrontlineBonus) PvPAddon.EnableFrontlinePostMatch(); if (Configuration.ShowProgressionToastPostMatch) PvPAddon.EnablePostMatchProgressionToast(); if (Configuration.ShowMainWindowOnPVPReward) EnablePVPRewardWindowAddon(); + + PvPService.UpdateFrontlineResultCache(); if (Configuration.PostmatchProgressionToastType < 0 || Configuration.PostmatchProgressionToastType > 2) { @@ -84,13 +86,13 @@ public sealed class Plugin : IDalamudPlugin PvPAddon.DisableCrystallineConflictPostMatch(); if (Configuration.ShowProgressionChatPostRW) PvPAddon.DisableRivalWingsPostMatch(); - if (Configuration.ShowProgressionChatPostFL) + if (Configuration.ShowProgressionChatPostFL || Configuration.TrackFrontlineBonus) PvPAddon.DisableFrontlinePostMatch(); if (Configuration.ShowProgressionToastPostMatch) PvPAddon.DisablePostMatchProgressionToast(); if(Configuration.ShowMainWindowOnPVPReward) DisablePVPRewardWindowAddon(); - + CommandManager.RemoveHandler(CommandName); } @@ -254,5 +256,6 @@ private void OnCommand(string command, string args) AddonLifeCycle.UnregisterListener(AddonEvent.PostSetup, "PvpReward", MainWindow.OnOpenPVPRewardWindow); AddonLifeCycle.UnregisterListener(AddonEvent.PreFinalize, "PvpReward", MainWindow.OnClosePVPRewardWindow); } + } diff --git a/Malmstone/Services/PVPService.cs b/Malmstone/Services/PVPService.cs index cf08fea..ef16df9 100644 --- a/Malmstone/Services/PVPService.cs +++ b/Malmstone/Services/PVPService.cs @@ -4,6 +4,22 @@ namespace Malmstone.Services { public class PvPService { + public int CurrentFrontlineLosingBonus = -1; + + public enum FrontlinePlacement + { + FirstPlace = 1, SecondPlace = 2, ThirdPlace = 3, Unknown=4 + } + + public struct PVPProfileFrontlineResults + { + public uint FirstPlace; + public uint SecondPlace; + public uint ThirdPlace; + } + + public PVPProfileFrontlineResults CachedFrontlineResults; + public PvPSeriesInfo? GetPvPSeriesInfo() { unsafe @@ -21,6 +37,138 @@ namespace Malmstone.Services return null; } } + + public bool UpdateFrontlineResultCache() + { + unsafe + { + var pvpProfile = PvPProfile.Instance(); + if (pvpProfile != null && pvpProfile->IsLoaded != 0) + { + CachedFrontlineResults = new PVPProfileFrontlineResults + { + FirstPlace = pvpProfile->FrontlineTotalFirstPlace, + SecondPlace = pvpProfile->FrontlineTotalSecondPlace, + ThirdPlace = pvpProfile->FrontlineTotalThirdPlace + }; + return true; + } + return false; + } + } + + public int GenerateFrontlineBonus(FrontlinePlacement FrontlineResult, int EarnedSeriesEXP) + { + // Calculates the current Frontline Bonus + // 1000 (no bonus), 1100, 1200, 1300, 1400, 1500 3rd + // 1250 (no bonus), 1375, 1500, 1625, 1750, 1875 2nd + // 1500 (no bonus), 1650, 1800, 1950, 2100, 2250 1st + if (FrontlineResult == FrontlinePlacement.ThirdPlace) + { + switch (EarnedSeriesEXP) + { + case 1000: + CurrentFrontlineLosingBonus = 0; + return 0; + case 1100: + CurrentFrontlineLosingBonus = 10; + return 10; + case 1200: + CurrentFrontlineLosingBonus = 20; + return 20; + case 1300: + CurrentFrontlineLosingBonus = 30; + return 30; + case 1400: + CurrentFrontlineLosingBonus = 40; + return 40; + case 1500: + CurrentFrontlineLosingBonus = 50; + return 50; + default: + return -1; + } + } + else if (FrontlineResult == FrontlinePlacement.SecondPlace) + { + switch (EarnedSeriesEXP) + { + case 1250: + CurrentFrontlineLosingBonus = 0; + return 0; + case 1375: + CurrentFrontlineLosingBonus = 10; + return 10; + case 1500: + CurrentFrontlineLosingBonus = 20; + return 20; + case 1625: + CurrentFrontlineLosingBonus = 30; + return 30; + case 2100: + CurrentFrontlineLosingBonus = 40; + return 40; + case 2250: + CurrentFrontlineLosingBonus = 50; + return 50; + default: + return -1; + } + } + else if (FrontlineResult == FrontlinePlacement.FirstPlace) + { + switch (EarnedSeriesEXP) + { + case 1500: + CurrentFrontlineLosingBonus = 0; + return 0; + case 1650: + CurrentFrontlineLosingBonus = 10; + return 10; + case 1800: + CurrentFrontlineLosingBonus = 20; + return 20; + case 1950: + CurrentFrontlineLosingBonus = 30; + return 30; + case 1750: + CurrentFrontlineLosingBonus = 40; + return 40; + case 1875: + CurrentFrontlineLosingBonus = 50; + return 50; + default: + return -1; + } + } + return -1; + } + + public PVPProfileFrontlineResults GetPVPProfileFrontlineResults() + { + unsafe + { + var pvpProfile = PvPProfile.Instance(); + if (pvpProfile != null && pvpProfile->IsLoaded != 0) + { + return new PVPProfileFrontlineResults + { + FirstPlace = pvpProfile->FrontlineTotalFirstPlace, + SecondPlace = pvpProfile->FrontlineTotalSecondPlace, + ThirdPlace = pvpProfile->FrontlineTotalThirdPlace, + + }; + } + } + return new PVPProfileFrontlineResults + { + FirstPlace = 0, + SecondPlace = 0, + ThirdPlace = 0, + + }; + } + } public class PvPSeriesInfo diff --git a/Malmstone/Windows/ConfigWindow.cs b/Malmstone/Windows/ConfigWindow.cs index 93af7b5..0dc4e11 100644 --- a/Malmstone/Windows/ConfigWindow.cs +++ b/Malmstone/Windows/ConfigWindow.cs @@ -151,9 +151,9 @@ public class ConfigWindow : Window, IDisposable if (ImGui.Checkbox("##ShowFLMatchesRemainingPostGame", ref showFLMatchesRemainingPostGame)) { Configuration.ShowProgressionChatPostFL = showFLMatchesRemainingPostGame; - if (showFLMatchesRemainingPostGame) + if (showFLMatchesRemainingPostGame && !Plugin.PvPAddon.FrontlineRecordPostSetupEnabled) Plugin.PvPAddon.EnableFrontlinePostMatch(); - else + else if (!showFLMatchesRemainingPostGame && !Configuration.TrackFrontlineBonus) Plugin.PvPAddon.DisableFrontlinePostMatch(); Configuration.Save(); } @@ -166,6 +166,32 @@ public class ConfigWindow : Window, IDisposable ImGui.SameLine(); ImGui.Text("Frontlines"); + ImGui.SameLine(); + ImGui.Spacing(); + ImGui.SameLine(); + + var trackFrontlineBonus = Configuration.TrackFrontlineBonus; + if (ImGui.Checkbox("##TrackFrontlineBonus", ref trackFrontlineBonus)) + { + Configuration.TrackFrontlineBonus = trackFrontlineBonus; + if (trackFrontlineBonus && !Plugin.PvPAddon.FrontlineRecordPostSetupEnabled) + Plugin.PvPAddon.EnableFrontlinePostMatch(); + else if(!trackFrontlineBonus && !Configuration.ShowProgressionChatPostFL) + Plugin.PvPAddon.DisableFrontlinePostMatch(); + Configuration.Save(); + } + if (ImGui.IsItemHovered()) + { + ImGui.BeginTooltip(); + ImGui.Text("(EXPERIMENTAL) Track the reward bonus you get for consecutive losses in Frontline" + + "\n3rd place = +10 percent bonus (max 50 percent)" + + "\n2nd place = Current bonus is kept" + + "\n1st Place = Bonus reset to 0\n"); + ImGui.EndTooltip(); + } + ImGui.SameLine(); + ImGui.Text("Track Frontline Reward Bonus"); + var showRWMatchesRemainingPostGame = Configuration.ShowProgressionChatPostRW; if (ImGui.Checkbox("##ShowRWMatchesRemainingPostGame", ref showRWMatchesRemainingPostGame)) diff --git a/Malmstone/Windows/MainWindow.cs b/Malmstone/Windows/MainWindow.cs index 0e91c4d..8da004f 100644 --- a/Malmstone/Windows/MainWindow.cs +++ b/Malmstone/Windows/MainWindow.cs @@ -101,6 +101,41 @@ namespace Malmstone.Windows ImGui.BulletText($"Take 2nd Place: {xpResult.FrontlineDailyLose2nd} " + (xpResult.FrontlineDailyLose2nd == 1 ? "time" : "times")); ImGui.BulletText($"Take 3rd Place: {xpResult.FrontlineDailyLose3rd} " + (xpResult.FrontlineDailyLose3rd == 1 ? "time" : "times")); + + if (Plugin.Configuration.TrackFrontlineBonus) + { + if (Plugin.PvPService.CurrentFrontlineLosingBonus == -1) + { + ImGui.TextColored(new Vector4(0.0f, 1.0f, 0.0f, 1.0f), "Complete a Frontline match to view current reward bonus"); + if (ImGui.IsItemHovered()) + { + ImGui.BeginTooltip(); + ImGui.Text("This calculates the losing streak bonus you receive after consecutive losses in Frontlines" + + "\nPlay a match of Frontline to confirm your existing losing bonus" + + "\nYou can turn off tracking entirely in the settings"); + ImGui.EndTooltip(); + } + } + else + { + if(Plugin.PvPService.CurrentFrontlineLosingBonus == 0) + { + ImGui.TextColored(new Vector4(0.0f, 1.0f, 0.0f, 1.0f), "No Frontline Reward Bonus Currently Active"); + } + else + { + ImGui.TextColored(new Vector4(0.0f, 1.0f, 0.0f, 1.0f), "You'll receive a " + Plugin.PvPService.CurrentFrontlineLosingBonus + "%% reward boost next Frontline match"); + if (ImGui.IsItemHovered()) + { + ImGui.BeginTooltip(); + ImGui.Text("You will earn a " + Plugin.PvPService.CurrentFrontlineLosingBonus + "%% bonus on PvP EXP, Series EXP, and Wolf Marks " + + "until attain First Place" ); + ImGui.EndTooltip(); + } + } + } + } + ImGui.Spacing(); ImGui.Separator(); |
