From fc31d8041c8af3d93ec2915a30413c8480f5f6e4 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Wed, 18 Oct 2023 10:12:27 +0200 Subject: [PATCH] Add option for a (lower) reserved seal cap at max GC rank --- Deliveroo/Configuration.cs | 4 ++- Deliveroo/Deliveroo.csproj | 2 +- Deliveroo/DeliverooPlugin.Exchange.cs | 4 +-- Deliveroo/DeliverooPlugin.GameFunctions.cs | 3 +- Deliveroo/DeliverooPlugin.SelectString.cs | 3 +- Deliveroo/DeliverooPlugin.SelectYesNo.cs | 2 +- Deliveroo/DeliverooPlugin.cs | 7 ++++- Deliveroo/Windows/ConfigWindow.cs | 32 ++++++++++++++++++---- 8 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Deliveroo/Configuration.cs b/Deliveroo/Configuration.cs index b1b680e..fef7aae 100644 --- a/Deliveroo/Configuration.cs +++ b/Deliveroo/Configuration.cs @@ -11,7 +11,9 @@ internal sealed class Configuration : IPluginConfiguration public List ItemsAvailableForPurchase { get; set; } = new(); public List ItemsToPurchase { get; set; } = new(); - public int ReservedSealCount { get; set; } = 0; + public int ReservedSealCount { get; set; } + public bool ReserveDifferentSealCountAtMaxRank { get; set; } + public int ReservedSealCountAtMaxRank { get; set; } /// /// A config-only setting, not exposed in the UI. diff --git a/Deliveroo/Deliveroo.csproj b/Deliveroo/Deliveroo.csproj index 6e8bca2..9e591a9 100644 --- a/Deliveroo/Deliveroo.csproj +++ b/Deliveroo/Deliveroo.csproj @@ -1,7 +1,7 @@ net7.0-windows - 2.11 + 2.12 11.0 enable true diff --git a/Deliveroo/DeliverooPlugin.Exchange.cs b/Deliveroo/DeliverooPlugin.Exchange.cs index 7089876..8468e11 100644 --- a/Deliveroo/DeliverooPlugin.Exchange.cs +++ b/Deliveroo/DeliverooPlugin.Exchange.cs @@ -11,7 +11,7 @@ partial class DeliverooPlugin { private void InteractWithQuartermaster(GameObject personnelOfficer, GameObject quartermaster) { - if (GetCurrentSealCount() < _configuration.ReservedSealCount) + if (GetCurrentSealCount() < EffectiveReservedSealCount) { CurrentStage = Stage.RequestStop; return; @@ -132,7 +132,7 @@ partial class DeliverooPlugin if (itemId == item.ItemId) { _pluginLog.Information($"Selecting item {itemId}, {i}"); - long toBuy = (GetCurrentSealCount() - _configuration.ReservedSealCount) / item.SealCost; + long toBuy = (GetCurrentSealCount() - EffectiveReservedSealCount) / item.SealCost; toBuy = Math.Min(toBuy, item.EffectiveLimit - GetItemCount(item.ItemId)); if (item.ItemId != ItemIds.Venture && !_configuration.IgnoreCertainLimitations) diff --git a/Deliveroo/DeliverooPlugin.GameFunctions.cs b/Deliveroo/DeliverooPlugin.GameFunctions.cs index fdd16b5..b1a1487 100644 --- a/Deliveroo/DeliverooPlugin.GameFunctions.cs +++ b/Deliveroo/DeliverooPlugin.GameFunctions.cs @@ -11,7 +11,6 @@ using FFXIVClientStructs.FFXIV.Client.Game.Control; using FFXIVClientStructs.FFXIV.Client.Game.UI; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Common.Math; -using FFXIVClientStructs.FFXIV.Component.GUI; namespace Deliveroo; @@ -96,6 +95,8 @@ partial class DeliverooPlugin private uint GetSealCap() => _sealCaps.TryGetValue(GetGrandCompanyRank(), out var cap) ? cap : 0; + public uint GetMaxSealCap() => _sealCaps[11]; + public unsafe int GetItemCount(uint itemId) { InventoryManager* inventoryManager = InventoryManager.Instance(); diff --git a/Deliveroo/DeliverooPlugin.SelectString.cs b/Deliveroo/DeliverooPlugin.SelectString.cs index 2f84e37..4aeafe9 100644 --- a/Deliveroo/DeliverooPlugin.SelectString.cs +++ b/Deliveroo/DeliverooPlugin.SelectString.cs @@ -86,8 +86,7 @@ partial class DeliverooPlugin _turnInWindow.State = false; CurrentStage = Stage.RequestStop; } - else if (GetCurrentSealCount() <= - _configuration.ReservedSealCount + GetNextItemToPurchase()!.SealCost) + else if (GetCurrentSealCount() <= EffectiveReservedSealCount + GetNextItemToPurchase()!.SealCost) { _turnInWindow.State = false; CurrentStage = Stage.RequestStop; diff --git a/Deliveroo/DeliverooPlugin.SelectYesNo.cs b/Deliveroo/DeliverooPlugin.SelectYesNo.cs index 61d61a9..87cdb15 100644 --- a/Deliveroo/DeliverooPlugin.SelectYesNo.cs +++ b/Deliveroo/DeliverooPlugin.SelectYesNo.cs @@ -31,7 +31,7 @@ partial class DeliverooPlugin addonSelectYesNo->AtkUnitBase.FireCallbackInt(0); var nextItem = GetNextItemToPurchase(item); - if (nextItem != null && GetCurrentSealCount() >= _configuration.ReservedSealCount + nextItem.SealCost) + if (nextItem != null && GetCurrentSealCount() >= EffectiveReservedSealCount + nextItem.SealCost) CurrentStage = Stage.SelectRewardTier; else CurrentStage = Stage.CloseGcExchange; diff --git a/Deliveroo/DeliverooPlugin.cs b/Deliveroo/DeliverooPlugin.cs index 9ee4ffe..9811369 100644 --- a/Deliveroo/DeliverooPlugin.cs +++ b/Deliveroo/DeliverooPlugin.cs @@ -118,6 +118,11 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin } } + public int EffectiveReservedSealCount => + _configuration.ReserveDifferentSealCountAtMaxRank && GetSealCap() == GetMaxSealCap() + ? _configuration.ReservedSealCountAtMaxRank + : _configuration.ReservedSealCount; + private void Login() { try @@ -205,7 +210,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin var nextItem = GetNextItemToPurchase(); - if (nextItem != null && GetCurrentSealCount() >= _configuration.ReservedSealCount + nextItem.SealCost) + if (nextItem != null && GetCurrentSealCount() >= EffectiveReservedSealCount + nextItem.SealCost) CurrentStage = Stage.TargetQuartermaster; if (_gameGui.TryGetAddonByName("GrandCompanySupplyList", out var gcSupplyList) && diff --git a/Deliveroo/Windows/ConfigWindow.cs b/Deliveroo/Windows/ConfigWindow.cs index 86a662a..a6a2fa3 100644 --- a/Deliveroo/Windows/ConfigWindow.cs +++ b/Deliveroo/Windows/ConfigWindow.cs @@ -39,12 +39,12 @@ internal sealed class ConfigWindow : Window _itemLookup = _gcRewardsCache.RewardLookup; - Size = new Vector2(420, 300); - SizeCondition = ImGuiCond.Appearing; + Size = new Vector2(440, 300); + SizeCondition = ImGuiCond.FirstUseEver; SizeConstraints = new WindowSizeConstraints { - MinimumSize = new Vector2(420, 300), + MinimumSize = new Vector2(440, 300), MaximumSize = new Vector2(9999, 9999), }; } @@ -261,14 +261,36 @@ internal sealed class ConfigWindow : Window { if (ImGui.BeginTabItem("Additional Settings")) { - ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 100); + ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 120); int reservedSealCount = _configuration.ReservedSealCount; if (ImGui.InputInt("Minimum Seals to keep (e.g. for Squadron Missions)", ref reservedSealCount, 1000)) { - _configuration.ReservedSealCount = Math.Max(0, Math.Min(90_000, reservedSealCount)); + _configuration.ReservedSealCount = Math.Max(0, Math.Min((int)_plugin.GetMaxSealCap(), reservedSealCount)); Save(); } + ImGui.BeginDisabled(reservedSealCount <= 0); + bool reserveDifferentSealCountAtMaxRank = _configuration.ReserveDifferentSealCountAtMaxRank; + if (ImGui.Checkbox("Use a different amount at max rank", ref reserveDifferentSealCountAtMaxRank)) + { + _configuration.ReserveDifferentSealCountAtMaxRank = reserveDifferentSealCountAtMaxRank; + Save(); + } + + if (reserveDifferentSealCountAtMaxRank) + { + ImGui.Indent(); + ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 100); + int reservedSealCountAtMaxRank = _configuration.ReservedSealCountAtMaxRank; + if (ImGui.InputInt("Minimum seals to keep at max rank", ref reservedSealCountAtMaxRank)) + { + _configuration.ReservedSealCountAtMaxRank = Math.Max(0, Math.Min((int)_plugin.GetMaxSealCap(), reservedSealCountAtMaxRank)); + Save(); + } + ImGui.Unindent(); + } + ImGui.EndDisabled(); + ImGui.EndTabItem(); } }