Add /dbq request as an advanced form of /dbq crystals; split /dbq crystals into different options (crystals, shards and shards+crystals)
This commit is contained in:
parent
ee9e43c707
commit
bb11f13512
@ -5,13 +5,14 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Dalamud.Game.Command;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Services;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||
using LLib;
|
||||
|
||||
namespace KitchenSink.Commands
|
||||
{
|
||||
namespace KitchenSink.Commands;
|
||||
|
||||
internal sealed class DropboxQueue : IDisposable
|
||||
{
|
||||
private static readonly InventoryType[] DefaultInventoryTypes =
|
||||
@ -38,58 +39,80 @@ namespace KitchenSink.Commands
|
||||
_commandManager.AddHandler("/dbq", new CommandInfo(Queue)
|
||||
{
|
||||
HelpMessage =
|
||||
$"Queue items to be imported into dropbox{Environment.NewLine}\t/dbq item1:qty1 item2:qty2 [...] - queues items for the next trade (use * as quantity for 'all'){Environment.NewLine}\t/dbq clear - remove all items in the queue{Environment.NewLine}\t/dbq crystals - show the command to fill all shards & crystals to 9999"
|
||||
$"Queue items to be imported into dropbox{Environment.NewLine}" +
|
||||
$"\t/dbq item1:qty1 item2:qty2 [...] - queues items for the next trade (use * as quantity for 'all'){Environment.NewLine}n" +
|
||||
$"\t/dbq clear - remove all items in the queue{Environment.NewLine}" +
|
||||
$"\t/dbq request item1:qty1 item2:qty2 [...] - show the command to fill your inventory with the specific item quantities{Environment.NewLine}" +
|
||||
$"\t/dbq [shards/crystals/shards+crystals] - show the command to fill shards and/or crystals to 9999"
|
||||
});
|
||||
}
|
||||
|
||||
private void Queue(string command, string arguments)
|
||||
{
|
||||
if (arguments == "crystals")
|
||||
{
|
||||
ShowCrystals();
|
||||
}
|
||||
else if (arguments == "clear")
|
||||
string[] parts = arguments.Split(" ", 2);
|
||||
switch (parts[0])
|
||||
{
|
||||
case "shards":
|
||||
BuildRequest(string.Join(" ", Enumerable.Range(2, 6).Select(x => $"{x}:9999")));
|
||||
break;
|
||||
case "crystals":
|
||||
BuildRequest(string.Join(" ", Enumerable.Range(8, 6).Select(x => $"{x}:9999")));
|
||||
break;
|
||||
case "shards+crystals":
|
||||
BuildRequest(string.Join(" ", Enumerable.Range(2, 12).Select(x => $"{x}:9999")));
|
||||
break;
|
||||
case "request":
|
||||
BuildRequest(parts.Length == 2 ? parts[1] : string.Empty);
|
||||
break;
|
||||
case "clear":
|
||||
_dropboxApi.ClearQueue();
|
||||
break;
|
||||
default:
|
||||
AddToQueue(arguments);
|
||||
break;
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
private unsafe void BuildRequest(string arguments)
|
||||
{
|
||||
var parsedItems = arguments.Split(' ')
|
||||
.Select(x => x.Split(':'))
|
||||
.Select(x =>
|
||||
if (string.IsNullOrEmpty(arguments))
|
||||
{
|
||||
if (x.Length != 2)
|
||||
return ($"Unable to parse {string.Join(" ", x)}.", null);
|
||||
_chatGui.PrintError("Usage: /dbq request item1:qty1 item2:qty2 [...]");
|
||||
}
|
||||
|
||||
if (!uint.TryParse(x[0], out uint itemId))
|
||||
return ($"Unable to parse item id {x[0]}.", null);
|
||||
|
||||
int needed;
|
||||
if (x[1] == "*")
|
||||
needed = int.MaxValue;
|
||||
else if (!int.TryParse(x[1], out needed))
|
||||
return ($"Unable to parse quantity {x[1]}.", null);
|
||||
|
||||
return (string.Empty, new NeededItem(itemId, needed));
|
||||
}).ToList();
|
||||
if (parsedItems.Count == 0)
|
||||
InventoryManager* inventoryManger = InventoryManager.Instance();
|
||||
if (inventoryManger == null)
|
||||
return;
|
||||
|
||||
var problematic = parsedItems.Where(x => !string.IsNullOrEmpty(x.Item1)).Select(x => x.Item1).ToList();
|
||||
if (problematic.Count == 1)
|
||||
IReadOnlyList<NeededItem>? parsedItems = ParseArguments(arguments);
|
||||
if (parsedItems == null)
|
||||
return;
|
||||
|
||||
var missingItems = parsedItems
|
||||
.Select(item => item with
|
||||
{
|
||||
_chatGui.PrintError($"dbq: {problematic.First()}");
|
||||
Needed = item.Needed - inventoryManger->GetItemCountInContainer(item.ItemId, InventoryType.Crystals)
|
||||
})
|
||||
.Where(x => x.Needed > 0)
|
||||
.ToList();
|
||||
if (missingItems.Count == 0)
|
||||
{
|
||||
_chatGui.Print("No items need to be filled");
|
||||
return;
|
||||
}
|
||||
else if (problematic.Count >= 2)
|
||||
{
|
||||
_chatGui.PrintError("dbq: Multiple errors occured:");
|
||||
foreach (string problem in problematic)
|
||||
_chatGui.PrintError($" - {problem}");
|
||||
|
||||
_chatGui.Print(new SeStringBuilder().AddUiForeground("[KitchenSink] ", 504)
|
||||
.Append($"/dbq {string.Join(" ", missingItems)}").Build());
|
||||
}
|
||||
else
|
||||
|
||||
private void AddToQueue(string arguments)
|
||||
{
|
||||
IReadOnlyList<NeededItem>? parsedItems = ParseArguments(arguments);
|
||||
if (parsedItems == null)
|
||||
return;
|
||||
|
||||
Dictionary<uint, ItemCount> allItems = GetItemCounts();
|
||||
foreach (var neededItem in parsedItems.Select(x => x.Item2).Cast<NeededItem>())
|
||||
foreach (var neededItem in parsedItems)
|
||||
{
|
||||
if (!allItems.TryGetValue(neededItem.ItemId, out ItemCount? itemCount))
|
||||
continue;
|
||||
@ -113,7 +136,45 @@ namespace KitchenSink.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IReadOnlyList<NeededItem>? ParseArguments(string arguments)
|
||||
{
|
||||
var parsedItems = arguments.Split(' ')
|
||||
.Select(x => x.Split(':'))
|
||||
.Select(x =>
|
||||
{
|
||||
if (x.Length != 2)
|
||||
return ($"Unable to parse {string.Join(" ", x)}.", null);
|
||||
|
||||
if (!uint.TryParse(x[0], out uint itemId))
|
||||
return ($"Unable to parse item id {x[0]}.", null);
|
||||
|
||||
int needed;
|
||||
if (x[1] == "*")
|
||||
needed = int.MaxValue;
|
||||
else if (!int.TryParse(x[1], out needed))
|
||||
return ($"Unable to parse quantity {x[1]}.", null);
|
||||
|
||||
return (string.Empty, new NeededItem(itemId, needed));
|
||||
}).ToList();
|
||||
if (parsedItems.Count == 0)
|
||||
return null;
|
||||
|
||||
var problematic = parsedItems.Where(x => !string.IsNullOrEmpty(x.Item1)).Select(x => x.Item1).ToList();
|
||||
if (problematic.Count == 1)
|
||||
{
|
||||
_chatGui.PrintError($"dbq: {problematic.First()}");
|
||||
return null;
|
||||
}
|
||||
else if (problematic.Count >= 2)
|
||||
{
|
||||
_chatGui.PrintError("dbq: Multiple errors occured:");
|
||||
foreach (string problem in problematic)
|
||||
_chatGui.PrintError($" - {problem}");
|
||||
return null;
|
||||
}
|
||||
else
|
||||
return parsedItems.Select(x => x.Item2!).ToList().AsReadOnly();
|
||||
}
|
||||
|
||||
private unsafe Dictionary<uint, ItemCount> GetItemCounts()
|
||||
@ -157,26 +218,6 @@ namespace KitchenSink.Commands
|
||||
return allItems;
|
||||
}
|
||||
|
||||
private unsafe void ShowCrystals()
|
||||
{
|
||||
InventoryManager* inventoryManger = InventoryManager.Instance();
|
||||
if (inventoryManger == null)
|
||||
return;
|
||||
|
||||
var missingCrystals = Enumerable.Range(2, 12).Select(itemId => (uint)itemId)
|
||||
.Select(itemId => new NeededItem(itemId,
|
||||
9999 - inventoryManger->GetItemCountInContainer(itemId, InventoryType.Crystals)))
|
||||
.Where(x => x.Needed > 0)
|
||||
.ToList();
|
||||
if (missingCrystals.Count == 0)
|
||||
{
|
||||
_chatGui.Print("No crystals need to be filled");
|
||||
return;
|
||||
}
|
||||
|
||||
_chatGui.Print($"Command: /dbq {string.Join(" ", missingCrystals)}");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_commandManager.RemoveHandler("/dbq");
|
||||
@ -260,4 +301,3 @@ namespace KitchenSink.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Version>0.3</Version>
|
||||
<Version>0.4</Version>
|
||||
<LangVersion>12</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
|
Loading…
Reference in New Issue
Block a user