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 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.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI;
using Lumina.Excel.GeneratedSheets;
using Character = Dalamud.Game.ClientState.Objects.Types.Character;
using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany;
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
namespace Deliveroo;
@ -41,10 +43,12 @@ public sealed class DeliverooPlugin : IDalamudPlugin
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
private readonly Configuration _configuration;
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
private readonly GcRewardsCache _gcRewardsCache;
private readonly ConfigWindow _configWindow;
private readonly TurnInWindow _turnInWindow;
private readonly IReadOnlyDictionary<uint, uint> _sealCaps;
private Stage _currentStageInternal = Stage.Stop;
private DateTime _continueAt = DateTime.MinValue;
@ -68,6 +72,8 @@ public sealed class DeliverooPlugin : IDalamudPlugin
_windowSystem.AddWindow(_configWindow);
_turnInWindow = new TurnInWindow(this, _pluginInterface, _configuration, _gcRewardsCache);
_windowSystem.AddWindow(_turnInWindow);
_sealCaps = dataManager.GetExcelSheet<GrandCompanyRank>()!.Where(x => x.RowId > 0)
.ToDictionary(x => x.RowId, x => x.MaxSeals);
_framework.Update += FrameworkUpdate;
_pluginInterface.UiBuilder.Draw += _windowSystem.Draw;
@ -252,7 +258,8 @@ public sealed class DeliverooPlugin : IDalamudPlugin
_turnInWindow.State = false;
CurrentStage = Stage.Stop;
}
else if (GetCurrentSealCount() <= 2000 + _selectedRewardItem.SealCost)
else if (GetCurrentSealCount() <=
_configuration.ReservedSealCount + _selectedRewardItem.SealCost)
{
_turnInWindow.State = false;
CurrentStage = Stage.Stop;
@ -267,7 +274,7 @@ public sealed class DeliverooPlugin : IDalamudPlugin
break;
case Stage.TargetQuartermaster:
if (GetCurrentSealCount() < 2000) // fixme this should be selectable/dependent on shop item
if (GetCurrentSealCount() < _configuration.ReservedSealCount)
{
CurrentStage = Stage.Stop;
break;
@ -499,7 +506,7 @@ public sealed class DeliverooPlugin : IDalamudPlugin
uint itemId = addonExchange->AtkValues[317 + i].UInt;
if (itemId == _selectedRewardItem.ItemId)
{
long toBuy = (GetCurrentSealCount() - 2000) / _selectedRewardItem.SealCost;
long toBuy = (GetCurrentSealCount() - _configuration.ReservedSealCount) / _selectedRewardItem.SealCost;
bool isVenture = _selectedRewardItem.ItemId == ItemIds.Venture;
if (isVenture)
toBuy = Math.Min(toBuy, 65000 - GetCurrentVentureCount());
@ -575,24 +582,7 @@ public sealed class DeliverooPlugin : IDalamudPlugin
};
}
private int GetSealCap()
{
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 uint GetSealCap() => _sealCaps.TryGetValue(GetGrandCompanyRank(), out var cap) ? cap : 0;
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.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using Dalamud.Plugin;
using Deliveroo.GameData;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
@ -34,106 +35,144 @@ internal sealed class ConfigWindow : Window
.Distinct()
.ToDictionary(x => x.ItemId, x => x);
Size = new Vector2(400, 300);
Size = new Vector2(420, 300);
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)
{
_configuration.ItemsAvailableForPurchase.Add(ItemIds.Venture);
_pluginInterface.SavePluginConfig(_configuration);
Save();
}
if (ImGui.BeginChild("Items", new Vector2(-1, -30), true, ImGuiWindowFlags.NoSavedSettings))
if (ImGui.BeginTabBar("DeliverooConfigTabs"))
{
for (int i = 0; i < _configuration.ItemsAvailableForPurchase.Count; ++i)
{
uint itemId = _configuration.ItemsAvailableForPurchase[i];
ImGui.PushID($"###Item{i}");
ImGui.BeginDisabled(_configuration.ItemsAvailableForPurchase.Count == 1 && itemId == ItemIds.Venture);
DrawBuyList();
DrawAdditionalSettings();
ImGui.Selectable(_itemLookup[itemId].Name);
if (ImGui.BeginDragDropSource())
{
ImGui.SetDragDropPayload("DeliverooDragDrop", nint.Zero, 0);
_dragDropSource = itemId;
ImGui.EndDragDropSource();
}
if (ImGui.BeginDragDropTarget() &&
_dragDropSource > 0 &&
ImGui.AcceptDragDropPayload("DeliverooDragDrop").NativePtr != null)
{
itemToAdd = _dragDropSource;
indexToAdd = i;
ImGui.EndDragDropTarget();
_dragDropSource = 0;
}
ImGui.OpenPopupOnItemClick($"###ctx{i}", ImGuiPopupFlags.MouseButtonRight);
if (ImGui.BeginPopup($"###ctx{i}"))
{
if (ImGui.Selectable($"Remove {_itemLookup[itemId].Name}"))
itemToRemove = itemId;
ImGui.EndPopup();
}
ImGui.EndDisabled();
ImGui.PopID();
}
ImGui.EndTabBar();
}
ImGui.EndChild();
if (itemToRemove != null)
{
_configuration.ItemsAvailableForPurchase.Remove(itemToRemove.Value);
_pluginInterface.SavePluginConfig(_configuration);
}
if (itemToAdd != null)
{
_configuration.ItemsAvailableForPurchase.Remove(itemToAdd.Value);
_configuration.ItemsAvailableForPurchase.Insert(indexToAdd, itemToAdd.Value);
_pluginInterface.SavePluginConfig(_configuration);
}
if (_plugin.GetGrandCompany() != GrandCompany.None)
{
List<(uint ItemId, string Name)> comboValues = _gcRewardsCache.Rewards[_plugin.GetGrandCompany()]
.Where(x => x.SubCategory == RewardSubCategory.Materials || x.SubCategory == RewardSubCategory.Materiel)
.Where(x => x.StackSize > 1)
.Where(x => !_configuration.ItemsAvailableForPurchase.Contains(x.ItemId))
.Select(x => (x.ItemId, x.Name))
.OrderBy(x => x.Name)
.ThenBy(x => x.GetHashCode())
.ToList();
comboValues.Insert(0, (0, ""));
int currentItem = 0;
if (ImGui.Combo("Add Item", ref currentItem, comboValues.Select(x => x.Name).ToArray(), comboValues.Count))
{
_configuration.ItemsAvailableForPurchase.Add(comboValues[currentItem].ItemId);
_pluginInterface.SavePluginConfig(_configuration);
}
}
else
{
int currentItem = 0;
ImGui.Combo("Add Item", ref currentItem, new string[] { "(Not part of a GC)" }, 1);
}
ImGui.Unindent(30);
}
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))
{
for (int i = 0; i < _configuration.ItemsAvailableForPurchase.Count; ++i)
{
uint itemId = _configuration.ItemsAvailableForPurchase[i];
ImGui.PushID($"###Item{i}");
ImGui.BeginDisabled(
_configuration.ItemsAvailableForPurchase.Count == 1 && itemId == ItemIds.Venture);
ImGui.Selectable(_itemLookup[itemId].Name);
if (ImGui.BeginDragDropSource())
{
ImGui.SetDragDropPayload("DeliverooDragDrop", nint.Zero, 0);
_dragDropSource = itemId;
ImGui.EndDragDropSource();
}
if (ImGui.BeginDragDropTarget() &&
_dragDropSource > 0 &&
ImGui.AcceptDragDropPayload("DeliverooDragDrop").NativePtr != null)
{
itemToAdd = _dragDropSource;
indexToAdd = i;
ImGui.EndDragDropTarget();
_dragDropSource = 0;
}
ImGui.OpenPopupOnItemClick($"###ctx{i}", ImGuiPopupFlags.MouseButtonRight);
if (ImGui.BeginPopup($"###ctx{i}"))
{
if (ImGui.Selectable($"Remove {_itemLookup[itemId].Name}"))
itemToRemove = itemId;
ImGui.EndPopup();
}
ImGui.EndDisabled();
ImGui.PopID();
}
}
ImGui.EndChild();
if (itemToRemove != null)
{
_configuration.ItemsAvailableForPurchase.Remove(itemToRemove.Value);
Save();
}
if (itemToAdd != null)
{
_configuration.ItemsAvailableForPurchase.Remove(itemToAdd.Value);
_configuration.ItemsAvailableForPurchase.Insert(indexToAdd, itemToAdd.Value);
Save();
}
if (_plugin.GetGrandCompany() != GrandCompany.None)
{
List<(uint ItemId, string Name)> comboValues = _gcRewardsCache.Rewards[_plugin.GetGrandCompany()]
.Where(x => x.SubCategory == RewardSubCategory.Materials ||
x.SubCategory == RewardSubCategory.Materiel)
.Where(x => x.StackSize > 1)
.Where(x => !_configuration.ItemsAvailableForPurchase.Contains(x.ItemId))
.Select(x => (x.ItemId, x.Name))
.OrderBy(x => x.Name)
.ThenBy(x => x.GetHashCode())
.ToList();
comboValues.Insert(0, (0, ""));
int currentItem = 0;
if (ImGui.Combo("Add Item", ref currentItem, comboValues.Select(x => x.Name).ToArray(),
comboValues.Count))
{
_configuration.ItemsAvailableForPurchase.Add(comboValues[currentItem].ItemId);
Save();
}
}
else
{
int currentItem = 0;
ImGui.Combo("Add Item", ref currentItem, new string[] { "(Not part of a GC)" }, 1);
}
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 Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using Dalamud.Logging;
using Dalamud.Plugin;
using Deliveroo.GameData;
using FFXIVClientStructs.FFXIV.Client.Game;
@ -93,49 +92,49 @@ internal sealed class TurnInWindow : Window
}
bool state = State;
if (ImGui.Checkbox("Handle GC turn ins/exchange automatically", ref state))
{
State = state;
}
if (ImGui.Checkbox("Handle GC turn ins/exchange automatically", ref state))
{
State = state;
}
ImGui.Indent(27);
if (Multiplier == 1m)
{
ImGui.TextColored(ImGuiColors.DalamudRed, "You do not have an active seal buff.");
}
ImGui.Indent(27);
if (Multiplier == 1m)
{
ImGui.TextColored(ImGuiColors.DalamudRed, "You do not have an active seal buff.");
}
else
{
ImGui.TextColored(ImGuiColors.HealerGreen, $"Current Buff: {(Multiplier - 1m) * 100:N0}%%");
}
ImGui.Spacing();
ImGui.BeginDisabled(state);
List<string> comboValues = new() { GcRewardItem.None.Name };
foreach (var itemId in _configuration.ItemsAvailableForPurchase)
{
var name = _gcRewardsCache.Rewards[grandCompany].First(x => x.ItemId == itemId).Name;
int itemCount = GetItemCount(itemId);
if (itemCount > 0)
comboValues.Add($"{name} ({itemCount:N0})");
else
{
ImGui.TextColored(ImGuiColors.HealerGreen, $"Current Buff: {(Multiplier - 1m) * 100:N0}%%");
}
comboValues.Add(name);
}
ImGui.Spacing();
ImGui.BeginDisabled(state);
if (ImGui.Combo("", ref _selectedAutoBuyItem, comboValues.ToArray(), comboValues.Count))
{
_configuration.SelectedPurchaseItemId = SelectedItemId;
_pluginInterface.SavePluginConfig(_configuration);
}
List<string> comboValues = new() { GcRewardItem.None.Name };
foreach (var itemId in _configuration.ItemsAvailableForPurchase)
{
var name = _gcRewardsCache.Rewards[grandCompany].First(x => x.ItemId == itemId).Name;
int itemCount = GetItemCount(itemId);
if (itemCount > 0)
comboValues.Add($"{name} ({itemCount:N0})");
else
comboValues.Add(name);
}
if (SelectedItem.IsValid() && SelectedItem.RequiredRank > _plugin.GetGrandCompanyRank())
ImGui.TextColored(ImGuiColors.DalamudRed, "Your rank isn't high enough to buy this item.");
if (ImGui.Combo("", ref _selectedAutoBuyItem, comboValues.ToArray(), comboValues.Count))
{
_configuration.SelectedPurchaseItemId = SelectedItemId;
_pluginInterface.SavePluginConfig(_configuration);
}
ImGui.EndDisabled();
ImGui.Unindent(27);
if (SelectedItem.IsValid() && SelectedItem.RequiredRank > _plugin.GetGrandCompanyRank())
ImGui.TextColored(ImGuiColors.DalamudRed, "Your rank isn't high enough to buy this item.");
ImGui.EndDisabled();
ImGui.Unindent(27);
ImGui.Separator();
ImGui.Text($"Debug (State): {_plugin.CurrentStage}");
ImGui.Separator();
ImGui.Text($"Debug (State): {_plugin.CurrentStage}");
}
private unsafe int GetItemCount(uint itemId)