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,15 +5,16 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Dalamud.Game.Command;
|
using Dalamud.Game.Command;
|
||||||
|
using Dalamud.Game.Text.SeStringHandling;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using FFXIVClientStructs.FFXIV.Client.Game;
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
using LLib;
|
using LLib;
|
||||||
|
|
||||||
namespace KitchenSink.Commands
|
namespace KitchenSink.Commands;
|
||||||
|
|
||||||
|
internal sealed class DropboxQueue : IDisposable
|
||||||
{
|
{
|
||||||
internal sealed class DropboxQueue : IDisposable
|
|
||||||
{
|
|
||||||
private static readonly InventoryType[] DefaultInventoryTypes =
|
private static readonly InventoryType[] DefaultInventoryTypes =
|
||||||
[
|
[
|
||||||
InventoryType.Inventory1,
|
InventoryType.Inventory1,
|
||||||
@ -38,58 +39,80 @@ namespace KitchenSink.Commands
|
|||||||
_commandManager.AddHandler("/dbq", new CommandInfo(Queue)
|
_commandManager.AddHandler("/dbq", new CommandInfo(Queue)
|
||||||
{
|
{
|
||||||
HelpMessage =
|
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)
|
private void Queue(string command, string arguments)
|
||||||
{
|
{
|
||||||
if (arguments == "crystals")
|
string[] parts = arguments.Split(" ", 2);
|
||||||
{
|
switch (parts[0])
|
||||||
ShowCrystals();
|
|
||||||
}
|
|
||||||
else if (arguments == "clear")
|
|
||||||
{
|
{
|
||||||
|
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();
|
_dropboxApi.ClearQueue();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
AddToQueue(arguments);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
private unsafe void BuildRequest(string arguments)
|
||||||
{
|
{
|
||||||
var parsedItems = arguments.Split(' ')
|
if (string.IsNullOrEmpty(arguments))
|
||||||
.Select(x => x.Split(':'))
|
|
||||||
.Select(x =>
|
|
||||||
{
|
{
|
||||||
if (x.Length != 2)
|
_chatGui.PrintError("Usage: /dbq request item1:qty1 item2:qty2 [...]");
|
||||||
return ($"Unable to parse {string.Join(" ", x)}.", null);
|
}
|
||||||
|
|
||||||
if (!uint.TryParse(x[0], out uint itemId))
|
InventoryManager* inventoryManger = InventoryManager.Instance();
|
||||||
return ($"Unable to parse item id {x[0]}.", null);
|
if (inventoryManger == 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;
|
return;
|
||||||
|
|
||||||
var problematic = parsedItems.Where(x => !string.IsNullOrEmpty(x.Item1)).Select(x => x.Item1).ToList();
|
IReadOnlyList<NeededItem>? parsedItems = ParseArguments(arguments);
|
||||||
if (problematic.Count == 1)
|
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.Print(new SeStringBuilder().AddUiForeground("[KitchenSink] ", 504)
|
||||||
_chatGui.PrintError("dbq: Multiple errors occured:");
|
.Append($"/dbq {string.Join(" ", missingItems)}").Build());
|
||||||
foreach (string problem in problematic)
|
|
||||||
_chatGui.PrintError($" - {problem}");
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
private void AddToQueue(string arguments)
|
||||||
{
|
{
|
||||||
|
IReadOnlyList<NeededItem>? parsedItems = ParseArguments(arguments);
|
||||||
|
if (parsedItems == null)
|
||||||
|
return;
|
||||||
|
|
||||||
Dictionary<uint, ItemCount> allItems = GetItemCounts();
|
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))
|
if (!allItems.TryGetValue(neededItem.ItemId, out ItemCount? itemCount))
|
||||||
continue;
|
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()
|
private unsafe Dictionary<uint, ItemCount> GetItemCounts()
|
||||||
@ -157,26 +218,6 @@ namespace KitchenSink.Commands
|
|||||||
return allItems;
|
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()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_commandManager.RemoveHandler("/dbq");
|
_commandManager.RemoveHandler("/dbq");
|
||||||
@ -259,5 +300,4 @@ namespace KitchenSink.Commands
|
|||||||
return itemQuantities != null;
|
return itemQuantities != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
<Version>0.3</Version>
|
<Version>0.4</Version>
|
||||||
<LangVersion>12</LangVersion>
|
<LangVersion>12</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
Loading…
Reference in New Issue
Block a user