Make reserved seal count configurable, load seal cap from excel

This commit is contained in:
Liza 2023-09-22 08:59:31 +02:00
parent a9b72380cd
commit 7a5dbe095d
Signed by: liza
GPG Key ID: 7199F8D727D55F67
4 changed files with 180 additions and 150 deletions

View File

@ -9,4 +9,6 @@ internal sealed class Configuration : IPluginConfiguration
public List<uint> ItemsAvailableForPurchase { get; set; } = new(); public List<uint> ItemsAvailableForPurchase { get; set; } = new();
public uint SelectedPurchaseItemId { get; set; } = 0; public uint SelectedPurchaseItemId { get; set; } = 0;
public int ReservedSealCount { get; set; } = 0;
} }

View File

@ -22,7 +22,9 @@ using FFXIVClientStructs.FFXIV.Client.Game.UI;
using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI; using FFXIVClientStructs.FFXIV.Component.GUI;
using Lumina.Excel.GeneratedSheets;
using Character = Dalamud.Game.ClientState.Objects.Types.Character; using Character = Dalamud.Game.ClientState.Objects.Types.Character;
using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
namespace Deliveroo; namespace Deliveroo;
@ -41,10 +43,12 @@ public sealed class DeliverooPlugin : IDalamudPlugin
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
private readonly Configuration _configuration; private readonly Configuration _configuration;
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
private readonly GcRewardsCache _gcRewardsCache; private readonly GcRewardsCache _gcRewardsCache;
private readonly ConfigWindow _configWindow; private readonly ConfigWindow _configWindow;
private readonly TurnInWindow _turnInWindow; private readonly TurnInWindow _turnInWindow;
private readonly IReadOnlyDictionary<uint, uint> _sealCaps;
private Stage _currentStageInternal = Stage.Stop; private Stage _currentStageInternal = Stage.Stop;
private DateTime _continueAt = DateTime.MinValue; private DateTime _continueAt = DateTime.MinValue;
@ -68,6 +72,8 @@ public sealed class DeliverooPlugin : IDalamudPlugin
_windowSystem.AddWindow(_configWindow); _windowSystem.AddWindow(_configWindow);
_turnInWindow = new TurnInWindow(this, _pluginInterface, _configuration, _gcRewardsCache); _turnInWindow = new TurnInWindow(this, _pluginInterface, _configuration, _gcRewardsCache);
_windowSystem.AddWindow(_turnInWindow); _windowSystem.AddWindow(_turnInWindow);
_sealCaps = dataManager.GetExcelSheet<GrandCompanyRank>()!.Where(x => x.RowId > 0)
.ToDictionary(x => x.RowId, x => x.MaxSeals);
_framework.Update += FrameworkUpdate; _framework.Update += FrameworkUpdate;
_pluginInterface.UiBuilder.Draw += _windowSystem.Draw; _pluginInterface.UiBuilder.Draw += _windowSystem.Draw;
@ -252,7 +258,8 @@ public sealed class DeliverooPlugin : IDalamudPlugin
_turnInWindow.State = false; _turnInWindow.State = false;
CurrentStage = Stage.Stop; CurrentStage = Stage.Stop;
} }
else if (GetCurrentSealCount() <= 2000 + _selectedRewardItem.SealCost) else if (GetCurrentSealCount() <=
_configuration.ReservedSealCount + _selectedRewardItem.SealCost)
{ {
_turnInWindow.State = false; _turnInWindow.State = false;
CurrentStage = Stage.Stop; CurrentStage = Stage.Stop;
@ -267,7 +274,7 @@ public sealed class DeliverooPlugin : IDalamudPlugin
break; break;
case Stage.TargetQuartermaster: case Stage.TargetQuartermaster:
if (GetCurrentSealCount() < 2000) // fixme this should be selectable/dependent on shop item if (GetCurrentSealCount() < _configuration.ReservedSealCount)
{ {
CurrentStage = Stage.Stop; CurrentStage = Stage.Stop;
break; break;
@ -499,7 +506,7 @@ public sealed class DeliverooPlugin : IDalamudPlugin
uint itemId = addonExchange->AtkValues[317 + i].UInt; uint itemId = addonExchange->AtkValues[317 + i].UInt;
if (itemId == _selectedRewardItem.ItemId) if (itemId == _selectedRewardItem.ItemId)
{ {
long toBuy = (GetCurrentSealCount() - 2000) / _selectedRewardItem.SealCost; long toBuy = (GetCurrentSealCount() - _configuration.ReservedSealCount) / _selectedRewardItem.SealCost;
bool isVenture = _selectedRewardItem.ItemId == ItemIds.Venture; bool isVenture = _selectedRewardItem.ItemId == ItemIds.Venture;
if (isVenture) if (isVenture)
toBuy = Math.Min(toBuy, 65000 - GetCurrentVentureCount()); toBuy = Math.Min(toBuy, 65000 - GetCurrentVentureCount());
@ -575,24 +582,7 @@ public sealed class DeliverooPlugin : IDalamudPlugin
}; };
} }
private int GetSealCap() private uint GetSealCap() => _sealCaps.TryGetValue(GetGrandCompanyRank(), out var cap) ? cap : 0;
{
return GetGrandCompanyRank() switch
{
1 => 10_000,
2 => 15_000,
3 => 20_000,
4 => 25_000,
5 => 30_000,
6 => 35_000,
7 => 40_000,
8 => 45_000,
9 => 50_000,
10 => 80_000,
11 => 90_000,
_ => 0,
};
}
private unsafe int GetCurrentVentureCount() private unsafe int GetCurrentVentureCount()
{ {

View File

@ -1,8 +1,9 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using Dalamud.Plugin; using Dalamud.Plugin;
using Deliveroo.GameData; using Deliveroo.GameData;
using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Client.UI.Agent;
@ -34,30 +35,48 @@ internal sealed class ConfigWindow : Window
.Distinct() .Distinct()
.ToDictionary(x => x.ItemId, x => x); .ToDictionary(x => x.ItemId, x => x);
Size = new Vector2(400, 300); Size = new Vector2(420, 300);
SizeCondition = ImGuiCond.Appearing; SizeCondition = ImGuiCond.Appearing;
SizeConstraints = new WindowSizeConstraints
{
MinimumSize = new Vector2(420, 300),
MaximumSize = new Vector2(9999, 9999),
};
} }
public override unsafe void Draw() public override void Draw()
{ {
ImGui.Text("Items available for Auto-Buy:");
uint? itemToRemove = null;
uint? itemToAdd = null;
int indexToAdd = 0;
if (_configuration.ItemsAvailableForPurchase.Count == 0) if (_configuration.ItemsAvailableForPurchase.Count == 0)
{ {
_configuration.ItemsAvailableForPurchase.Add(ItemIds.Venture); _configuration.ItemsAvailableForPurchase.Add(ItemIds.Venture);
_pluginInterface.SavePluginConfig(_configuration); Save();
} }
if (ImGui.BeginTabBar("DeliverooConfigTabs"))
{
DrawBuyList();
DrawAdditionalSettings();
ImGui.EndTabBar();
}
}
private unsafe void DrawBuyList()
{
if (ImGui.BeginTabItem("Items for Auto-Buy"))
{
uint? itemToRemove = null;
uint? itemToAdd = null;
int indexToAdd = 0;
if (ImGui.BeginChild("Items", new Vector2(-1, -30), true, ImGuiWindowFlags.NoSavedSettings)) if (ImGui.BeginChild("Items", new Vector2(-1, -30), true, ImGuiWindowFlags.NoSavedSettings))
{ {
for (int i = 0; i < _configuration.ItemsAvailableForPurchase.Count; ++i) for (int i = 0; i < _configuration.ItemsAvailableForPurchase.Count; ++i)
{ {
uint itemId = _configuration.ItemsAvailableForPurchase[i]; uint itemId = _configuration.ItemsAvailableForPurchase[i];
ImGui.PushID($"###Item{i}"); ImGui.PushID($"###Item{i}");
ImGui.BeginDisabled(_configuration.ItemsAvailableForPurchase.Count == 1 && itemId == ItemIds.Venture); ImGui.BeginDisabled(
_configuration.ItemsAvailableForPurchase.Count == 1 && itemId == ItemIds.Venture);
ImGui.Selectable(_itemLookup[itemId].Name); ImGui.Selectable(_itemLookup[itemId].Name);
@ -99,20 +118,21 @@ internal sealed class ConfigWindow : Window
if (itemToRemove != null) if (itemToRemove != null)
{ {
_configuration.ItemsAvailableForPurchase.Remove(itemToRemove.Value); _configuration.ItemsAvailableForPurchase.Remove(itemToRemove.Value);
_pluginInterface.SavePluginConfig(_configuration); Save();
} }
if (itemToAdd != null) if (itemToAdd != null)
{ {
_configuration.ItemsAvailableForPurchase.Remove(itemToAdd.Value); _configuration.ItemsAvailableForPurchase.Remove(itemToAdd.Value);
_configuration.ItemsAvailableForPurchase.Insert(indexToAdd, itemToAdd.Value); _configuration.ItemsAvailableForPurchase.Insert(indexToAdd, itemToAdd.Value);
_pluginInterface.SavePluginConfig(_configuration); Save();
} }
if (_plugin.GetGrandCompany() != GrandCompany.None) if (_plugin.GetGrandCompany() != GrandCompany.None)
{ {
List<(uint ItemId, string Name)> comboValues = _gcRewardsCache.Rewards[_plugin.GetGrandCompany()] List<(uint ItemId, string Name)> comboValues = _gcRewardsCache.Rewards[_plugin.GetGrandCompany()]
.Where(x => x.SubCategory == RewardSubCategory.Materials || x.SubCategory == RewardSubCategory.Materiel) .Where(x => x.SubCategory == RewardSubCategory.Materials ||
x.SubCategory == RewardSubCategory.Materiel)
.Where(x => x.StackSize > 1) .Where(x => x.StackSize > 1)
.Where(x => !_configuration.ItemsAvailableForPurchase.Contains(x.ItemId)) .Where(x => !_configuration.ItemsAvailableForPurchase.Contains(x.ItemId))
.Select(x => (x.ItemId, x.Name)) .Select(x => (x.ItemId, x.Name))
@ -122,10 +142,11 @@ internal sealed class ConfigWindow : Window
comboValues.Insert(0, (0, "")); comboValues.Insert(0, (0, ""));
int currentItem = 0; int currentItem = 0;
if (ImGui.Combo("Add Item", ref currentItem, comboValues.Select(x => x.Name).ToArray(), comboValues.Count)) if (ImGui.Combo("Add Item", ref currentItem, comboValues.Select(x => x.Name).ToArray(),
comboValues.Count))
{ {
_configuration.ItemsAvailableForPurchase.Add(comboValues[currentItem].ItemId); _configuration.ItemsAvailableForPurchase.Add(comboValues[currentItem].ItemId);
_pluginInterface.SavePluginConfig(_configuration); Save();
} }
} }
else else
@ -134,6 +155,24 @@ internal sealed class ConfigWindow : Window
ImGui.Combo("Add Item", ref currentItem, new string[] { "(Not part of a GC)" }, 1); ImGui.Combo("Add Item", ref currentItem, new string[] { "(Not part of a GC)" }, 1);
} }
ImGui.Unindent(30); ImGui.EndTabItem();
} }
}
private void DrawAdditionalSettings()
{
if (ImGui.BeginTabItem("Additional Settings"))
{
ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 100);
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));
Save();
}
}
}
private void Save() => _pluginInterface.SavePluginConfig(_configuration);
} }

View File

@ -3,7 +3,6 @@ using System.Linq;
using System.Numerics; using System.Numerics;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using Dalamud.Plugin; using Dalamud.Plugin;
using Deliveroo.GameData; using Deliveroo.GameData;
using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game;