Character-specific item purchases
This commit is contained in:
parent
7a8cbd435f
commit
0666d785df
@ -1,4 +1,5 @@
|
|||||||
using System.IO;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
@ -12,6 +13,8 @@ internal sealed class CharacterConfiguration
|
|||||||
|
|
||||||
public bool DisableForCharacter { get; set; } = false;
|
public bool DisableForCharacter { get; set; } = false;
|
||||||
public bool UseHideArmouryChestItemsFilter { get; set; } = false;
|
public bool UseHideArmouryChestItemsFilter { get; set; } = false;
|
||||||
|
public bool OverrideItemsToPurchase { get; set; }
|
||||||
|
public List<Configuration.PurchasePriority> ItemsToPurchase { get; set; } = new();
|
||||||
|
|
||||||
public static string ResolveFilePath(DalamudPluginInterface pluginInterface, ulong localContentId)
|
public static string ResolveFilePath(DalamudPluginInterface pluginInterface, ulong localContentId)
|
||||||
=> Path.Join(pluginInterface.GetPluginConfigDirectory(), $"char.{localContentId:X}.json");
|
=> Path.Join(pluginInterface.GetPluginConfigDirectory(), $"char.{localContentId:X}.json");
|
||||||
|
@ -190,6 +190,25 @@ internal sealed class ConfigWindow : Window
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui.BeginDisabled(charConfiguration.DisableForCharacter);
|
ImGui.BeginDisabled(charConfiguration.DisableForCharacter);
|
||||||
|
|
||||||
|
bool overrideItemsToPurchase = charConfiguration.OverrideItemsToPurchase;
|
||||||
|
if (ImGui.Checkbox("Use custom purchase list for this character", ref overrideItemsToPurchase))
|
||||||
|
{
|
||||||
|
charConfiguration.OverrideItemsToPurchase = overrideItemsToPurchase;
|
||||||
|
charConfiguration.Save(_pluginInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (charConfiguration.ItemsToPurchase.Count > 1 ||
|
||||||
|
(charConfiguration.ItemsToPurchase.Count == 1 && charConfiguration.ItemsToPurchase[0].ItemId != GcRewardItem.None.ItemId))
|
||||||
|
{
|
||||||
|
ImGui.SameLine();
|
||||||
|
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Trash, "Clear"))
|
||||||
|
{
|
||||||
|
charConfiguration.ItemsToPurchase.Clear();
|
||||||
|
charConfiguration.Save(_pluginInterface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool useHideArmouryChestItemsFilter = charConfiguration.UseHideArmouryChestItemsFilter;
|
bool useHideArmouryChestItemsFilter = charConfiguration.UseHideArmouryChestItemsFilter;
|
||||||
if (ImGui.Checkbox("Use 'Hide Armoury Chest Items' filter", ref useHideArmouryChestItemsFilter))
|
if (ImGui.Checkbox("Use 'Hide Armoury Chest Items' filter", ref useHideArmouryChestItemsFilter))
|
||||||
{
|
{
|
||||||
|
@ -49,6 +49,12 @@ internal sealed class TurnInWindow : Window
|
|||||||
public decimal Multiplier { private get; set; }
|
public decimal Multiplier { private get; set; }
|
||||||
public string Error { private get; set; } = string.Empty;
|
public string Error { private get; set; } = string.Empty;
|
||||||
|
|
||||||
|
private bool UseCharacterSpecificItemsToPurchase => _plugin.CharacterConfiguration is {OverrideItemsToPurchase: true };
|
||||||
|
|
||||||
|
private IItemsToPurchase ItemsWrapper => UseCharacterSpecificItemsToPurchase
|
||||||
|
? new CharacterSpecificItemsToPurchase(_plugin.CharacterConfiguration!, _pluginInterface)
|
||||||
|
: new GlobalItemsToPurchase(_configuration, _pluginInterface);
|
||||||
|
|
||||||
public List<PurchaseItemRequest> SelectedItems
|
public List<PurchaseItemRequest> SelectedItems
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -58,7 +64,7 @@ internal sealed class TurnInWindow : Window
|
|||||||
return new List<PurchaseItemRequest>();
|
return new List<PurchaseItemRequest>();
|
||||||
|
|
||||||
var rank = _plugin.GetGrandCompanyRank();
|
var rank = _plugin.GetGrandCompanyRank();
|
||||||
return _configuration.ItemsToPurchase
|
return ItemsWrapper.GetItemsToPurchase()
|
||||||
.Where(x => x.ItemId != 0)
|
.Where(x => x.ItemId != 0)
|
||||||
.Select(x => new { Item = x, Reward = _gcRewardsCache.GetReward(grandCompany, x.ItemId) })
|
.Select(x => new { Item = x, Reward = _gcRewardsCache.GetReward(grandCompany, x.ItemId) })
|
||||||
.Where(x => x.Reward.RequiredRank <= rank)
|
.Where(x => x.Reward.RequiredRank <= rank)
|
||||||
@ -126,7 +132,6 @@ internal sealed class TurnInWindow : Window
|
|||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
ImGui.BeginDisabled(state);
|
ImGui.BeginDisabled(state);
|
||||||
|
|
||||||
ImGui.Text("Items to buy:");
|
|
||||||
DrawItemsToBuy(grandCompany);
|
DrawItemsToBuy(grandCompany);
|
||||||
|
|
||||||
ImGui.EndDisabled();
|
ImGui.EndDisabled();
|
||||||
@ -138,6 +143,9 @@ internal sealed class TurnInWindow : Window
|
|||||||
|
|
||||||
private void DrawItemsToBuy(GrandCompany grandCompany)
|
private void DrawItemsToBuy(GrandCompany grandCompany)
|
||||||
{
|
{
|
||||||
|
var itemsWrapper = ItemsWrapper;
|
||||||
|
ImGui.Text($"Items to buy ({itemsWrapper.Name}):");
|
||||||
|
|
||||||
List<(uint ItemId, string Name, uint Rank)> comboValues = new()
|
List<(uint ItemId, string Name, uint Rank)> comboValues = new()
|
||||||
{ (GcRewardItem.None.ItemId, GcRewardItem.None.Name, GcRewardItem.None.RequiredRank) };
|
{ (GcRewardItem.None.ItemId, GcRewardItem.None.Name, GcRewardItem.None.RequiredRank) };
|
||||||
foreach (uint itemId in _configuration.ItemsAvailableForPurchase)
|
foreach (uint itemId in _configuration.ItemsAvailableForPurchase)
|
||||||
@ -150,15 +158,14 @@ internal sealed class TurnInWindow : Window
|
|||||||
comboValues.Add((itemId, gcReward.Name, gcReward.RequiredRank));
|
comboValues.Add((itemId, gcReward.Name, gcReward.RequiredRank));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_configuration.ItemsToPurchase.Count == 0)
|
if (itemsWrapper.GetItemsToPurchase().Count == 0)
|
||||||
_configuration.ItemsToPurchase.Add(new Configuration.PurchasePriority
|
itemsWrapper.Add(new Configuration.PurchasePriority { ItemId = GcRewardItem.None.ItemId, Limit = 0 });
|
||||||
{ ItemId = GcRewardItem.None.ItemId, Limit = 0 });
|
|
||||||
|
|
||||||
int? itemToRemove = null;
|
int? itemToRemove = null;
|
||||||
for (int i = 0; i < _configuration.ItemsToPurchase.Count; ++i)
|
for (int i = 0; i < itemsWrapper.GetItemsToPurchase().Count; ++i)
|
||||||
{
|
{
|
||||||
ImGui.PushID($"ItemToBuy{i}");
|
ImGui.PushID($"ItemToBuy{i}");
|
||||||
var item = _configuration.ItemsToPurchase[i];
|
var item = itemsWrapper.GetItemsToPurchase()[i];
|
||||||
int comboValueIndex = comboValues.FindIndex(x => x.ItemId == item.ItemId);
|
int comboValueIndex = comboValues.FindIndex(x => x.ItemId == item.ItemId);
|
||||||
if (comboValueIndex < 0)
|
if (comboValueIndex < 0)
|
||||||
{
|
{
|
||||||
@ -175,7 +182,7 @@ internal sealed class TurnInWindow : Window
|
|||||||
_pluginInterface.SavePluginConfig(_configuration);
|
_pluginInterface.SavePluginConfig(_configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_configuration.ItemsToPurchase.Count >= 2)
|
if (itemsWrapper.GetItemsToPurchase().Count >= 2)
|
||||||
{
|
{
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (ImGuiComponents.IconButton($"###Remove{i}", FontAwesomeIcon.Times))
|
if (ImGuiComponents.IconButton($"###Remove{i}", FontAwesomeIcon.Times))
|
||||||
@ -196,13 +203,13 @@ internal sealed class TurnInWindow : Window
|
|||||||
if (item.ItemId == ItemIds.Venture)
|
if (item.ItemId == ItemIds.Venture)
|
||||||
item.Limit = Math.Min(item.Limit, 65_000);
|
item.Limit = Math.Min(item.Limit, 65_000);
|
||||||
|
|
||||||
_pluginInterface.SavePluginConfig(_configuration);
|
itemsWrapper.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item.Limit != 0)
|
else if (item.Limit != 0)
|
||||||
{
|
{
|
||||||
item.Limit = 0;
|
item.Limit = 0;
|
||||||
_pluginInterface.SavePluginConfig(_configuration);
|
itemsWrapper.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comboValueIndex > 0 && comboValues[comboValueIndex].Rank > _plugin.GetGrandCompanyRank())
|
if (comboValueIndex > 0 && comboValues[comboValueIndex].Rank > _plugin.GetGrandCompanyRank())
|
||||||
@ -217,17 +224,16 @@ internal sealed class TurnInWindow : Window
|
|||||||
|
|
||||||
if (itemToRemove != null)
|
if (itemToRemove != null)
|
||||||
{
|
{
|
||||||
_configuration.ItemsToPurchase.RemoveAt(itemToRemove.Value);
|
itemsWrapper.RemoveAt(itemToRemove.Value);
|
||||||
_pluginInterface.SavePluginConfig(_configuration);
|
_pluginInterface.SavePluginConfig(_configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_configuration.ItemsAvailableForPurchase.Any(x => _configuration.ItemsToPurchase.All(y => x != y.ItemId)))
|
if (_configuration.ItemsAvailableForPurchase.Any(x => itemsWrapper.GetItemsToPurchase().All(y => x != y.ItemId)))
|
||||||
{
|
{
|
||||||
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Plus, "Add Item"))
|
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Plus, "Add Item"))
|
||||||
{
|
{
|
||||||
_configuration.ItemsToPurchase.Add(new Configuration.PurchasePriority
|
itemsWrapper.Add(new Configuration.PurchasePriority { ItemId = GcRewardItem.None.ItemId, Limit = 0 });
|
||||||
{ ItemId = GcRewardItem.None.ItemId, Limit = 0 });
|
itemsWrapper.Save();
|
||||||
_pluginInterface.SavePluginConfig(_configuration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,4 +264,66 @@ internal sealed class TurnInWindow : Window
|
|||||||
return Math.Min(limit, slotsThatCanBeUsed * stackSize);
|
return Math.Min(limit, slotsThatCanBeUsed * stackSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private interface IItemsToPurchase
|
||||||
|
{
|
||||||
|
string Name { get; }
|
||||||
|
|
||||||
|
IReadOnlyList<Configuration.PurchasePriority> GetItemsToPurchase();
|
||||||
|
void Add(Configuration.PurchasePriority purchasePriority);
|
||||||
|
void RemoveAt(int index);
|
||||||
|
void Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class CharacterSpecificItemsToPurchase : IItemsToPurchase
|
||||||
|
{
|
||||||
|
private readonly CharacterConfiguration _characterConfiguration;
|
||||||
|
private readonly DalamudPluginInterface _pluginInterface;
|
||||||
|
|
||||||
|
public CharacterSpecificItemsToPurchase(CharacterConfiguration characterConfiguration, DalamudPluginInterface pluginInterface)
|
||||||
|
{
|
||||||
|
_characterConfiguration = characterConfiguration;
|
||||||
|
_pluginInterface = pluginInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name => _characterConfiguration.CachedPlayerName ?? "?";
|
||||||
|
|
||||||
|
public IReadOnlyList<Configuration.PurchasePriority> GetItemsToPurchase()
|
||||||
|
=> _characterConfiguration.ItemsToPurchase;
|
||||||
|
|
||||||
|
public void Add(Configuration.PurchasePriority purchasePriority)
|
||||||
|
=> _characterConfiguration.ItemsToPurchase.Add(purchasePriority);
|
||||||
|
|
||||||
|
public void RemoveAt(int index)
|
||||||
|
=> _characterConfiguration.ItemsToPurchase.RemoveAt(index);
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
=> _characterConfiguration.Save(_pluginInterface);
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class GlobalItemsToPurchase : IItemsToPurchase
|
||||||
|
{
|
||||||
|
private readonly Configuration _configuration;
|
||||||
|
private readonly DalamudPluginInterface _pluginInterface;
|
||||||
|
|
||||||
|
public GlobalItemsToPurchase(Configuration configuration, DalamudPluginInterface pluginInterface)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
_pluginInterface = pluginInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name => "all characters";
|
||||||
|
|
||||||
|
public IReadOnlyList<Configuration.PurchasePriority> GetItemsToPurchase()
|
||||||
|
=> _configuration.ItemsToPurchase;
|
||||||
|
|
||||||
|
public void Add(Configuration.PurchasePriority purchasePriority)
|
||||||
|
=> _configuration.ItemsToPurchase.Add(purchasePriority);
|
||||||
|
|
||||||
|
public void RemoveAt(int index)
|
||||||
|
=> _configuration.ItemsToPurchase.RemoveAt(index);
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
=> _pluginInterface.SavePluginConfig(_configuration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user