Add /gup [level] that shows all gearsets for the current class as if you were that level

This commit is contained in:
Liza 2024-06-17 21:41:58 +02:00
parent 63f65e9589
commit 7febb06f3e
Signed by: liza
GPG Key ID: 7199F8D727D55F67

View File

@ -88,9 +88,15 @@ public sealed class GearsetterPlugin : IDalamudPlugin
private void ToggleEquipmentBrowser(string command, string arguments) private void ToggleEquipmentBrowser(string command, string arguments)
=> _equipmentBrowserWindow.Toggle(); => _equipmentBrowserWindow.Toggle();
private void ShowUpgrades(string command, string arguments) => ShowUpgrades(); private void ShowUpgrades(string command, string arguments)
{
byte? level = null;
if (arguments.Length > 0 && byte.TryParse(arguments, out byte parsedLevel))
level = parsedLevel;
ShowUpgrades(level);
}
private unsafe void ShowUpgrades() private unsafe void ShowUpgrades(byte? level = null)
{ {
var inventoryItems = GetAllInventoryItems(); var inventoryItems = GetAllInventoryItems();
@ -98,13 +104,20 @@ public sealed class GearsetterPlugin : IDalamudPlugin
if (gearsetModule == null) if (gearsetModule == null)
return; return;
bool onlyCurrentJob = level != null;
if (onlyCurrentJob)
_chatGui.Print("Checking only gearsets for your current class/job...");
bool anyUpgrade = false; bool anyUpgrade = false;
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
{ {
var gearset = gearsetModule->GetGearset(i); var gearset = gearsetModule->GetGearset(i);
if (gearset != null && gearset->Flags.HasFlag(RaptureGearsetModule.GearsetFlag.Exists)) if (gearset != null && gearset->Flags.HasFlag(RaptureGearsetModule.GearsetFlag.Exists))
{ {
anyUpgrade |= HandleGearset(gearset, inventoryItems); if (onlyCurrentJob && gearset->ClassJob != _clientState.LocalPlayer!.ClassJob.Id)
continue;
anyUpgrade |= HandleGearset(gearset, inventoryItems, level);
} }
} }
@ -113,7 +126,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
} }
private unsafe bool HandleGearset(RaptureGearsetModule.GearsetEntry* gearset, private unsafe bool HandleGearset(RaptureGearsetModule.GearsetEntry* gearset,
Dictionary<(uint ItemId, bool Hq), int> inventoryItems) Dictionary<(uint ItemId, bool Hq), int> inventoryItems, byte? level)
{ {
string name = GetGearsetName(gearset); string name = GetGearsetName(gearset);
if (name.Contains('_', StringComparison.Ordinal) || if (name.Contains('_', StringComparison.Ordinal) ||
@ -121,22 +134,27 @@ public sealed class GearsetterPlugin : IDalamudPlugin
name.Contains("Bozja", StringComparison.OrdinalIgnoreCase)) name.Contains("Bozja", StringComparison.OrdinalIgnoreCase))
return false; return false;
List<SeString> Handle(string label, int[] spanIds, EEquipSlotCategory category)
{
return HandleGearsetItem(label, gearset, spanIds.Select(x => gearset->ItemsSpan[x]).ToArray(),
inventoryItems, category, level);
}
List<List<SeString>> upgrades = new() List<List<SeString>> upgrades = new()
{ {
HandleGearsetItem("Main Hand", gearset, [gearset->ItemsSpan[0]], inventoryItems, EEquipSlotCategory.None), Handle("Main Hand", [0], EEquipSlotCategory.None),
HandleOffHand(gearset, inventoryItems), HandleOffHand(gearset, inventoryItems, level),
HandleGearsetItem("Head", gearset, [gearset->ItemsSpan[2]], inventoryItems, EEquipSlotCategory.Head), Handle("Head", [2], EEquipSlotCategory.Head),
HandleGearsetItem("Body", gearset, [gearset->ItemsSpan[3]], inventoryItems, EEquipSlotCategory.Body), Handle("Body", [3], EEquipSlotCategory.Body),
HandleGearsetItem("Hands", gearset, [gearset->ItemsSpan[4]], inventoryItems, EEquipSlotCategory.Hands), Handle("Hands", [4], EEquipSlotCategory.Hands),
HandleGearsetItem("Legs", gearset, [gearset->ItemsSpan[6]], inventoryItems, EEquipSlotCategory.Legs), Handle("Legs", [6], EEquipSlotCategory.Legs),
HandleGearsetItem("Feet", gearset, [gearset->ItemsSpan[7]], inventoryItems, EEquipSlotCategory.Feet), Handle("Feet", [7], EEquipSlotCategory.Feet),
HandleGearsetItem("Ears", gearset, [gearset->ItemsSpan[8]], inventoryItems, EEquipSlotCategory.Ears), Handle("Ears", [8], EEquipSlotCategory.Ears),
HandleGearsetItem("Neck", gearset, [gearset->ItemsSpan[9]], inventoryItems, EEquipSlotCategory.Neck), Handle("Neck", [9], EEquipSlotCategory.Neck),
HandleGearsetItem("Wrists", gearset, [gearset->ItemsSpan[10]], inventoryItems, EEquipSlotCategory.Wrists), Handle("Wrists", [10], EEquipSlotCategory.Wrists),
HandleGearsetItem("Rings", gearset, [gearset->ItemsSpan[11], gearset->ItemsSpan[12]], inventoryItems, Handle("Rings", [11, 12], EEquipSlotCategory.Rings),
EEquipSlotCategory.Rings),
}; };
List<SeString> flatUpgrades = upgrades.SelectMany(x => x).ToList(); List<SeString> flatUpgrades = upgrades.SelectMany(x => x).ToList();
@ -152,6 +170,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
.Append(name) .Append(name)
.Add(RawPayload.LinkTerminator) .Add(RawPayload.LinkTerminator)
.AddUiForegroundOff() .AddUiForegroundOff()
.AddText(level != null ? $" at {level}" : "")
.Build()); .Build());
foreach (var upgrade in flatUpgrades) foreach (var upgrade in flatUpgrades)
@ -169,7 +188,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
private unsafe List<SeString> HandleGearsetItem(string label, RaptureGearsetModule.GearsetEntry* gearset, private unsafe List<SeString> HandleGearsetItem(string label, RaptureGearsetModule.GearsetEntry* gearset,
RaptureGearsetModule.GearsetItem[] gearsetItem, Dictionary<(uint ItemId, bool Hq), int> inventoryItems, RaptureGearsetModule.GearsetItem[] gearsetItem, Dictionary<(uint ItemId, bool Hq), int> inventoryItems,
EEquipSlotCategory equipSlotCategory) EEquipSlotCategory equipSlotCategory, byte? level)
{ {
EClassJob classJob = (EClassJob)gearset->ClassJob; EClassJob classJob = (EClassJob)gearset->ClassJob;
var itemLists = _gameDataHolder.GetItemLists(classJob); var itemLists = _gameDataHolder.GetItemLists(classJob);
@ -208,7 +227,9 @@ public sealed class GearsetterPlugin : IDalamudPlugin
if (availableList == null) if (availableList == null)
return new List<SeString>(); return new List<SeString>();
var level = GetLevel(classJob); if (level == null)
level = GetLevel(classJob);
var bestItems = availableList.Items var bestItems = availableList.Items
.Where(x => x.Level <= level) .Where(x => x.Level <= level)
.SelectMany(x => .SelectMany(x =>
@ -237,7 +258,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
private unsafe List<SeString> HandleOffHand(RaptureGearsetModule.GearsetEntry* gearset, private unsafe List<SeString> HandleOffHand(RaptureGearsetModule.GearsetEntry* gearset,
Dictionary<(uint ItemId, bool Hq), int> inventoryItems) Dictionary<(uint ItemId, bool Hq), int> inventoryItems, byte? level)
{ {
var mainHand = gearset->ItemsSpan[0]; var mainHand = gearset->ItemsSpan[0];
if (mainHand.ItemID == 0) if (mainHand.ItemID == 0)
@ -250,7 +271,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
return new List<SeString>(); return new List<SeString>();
return HandleGearsetItem("Off Hand", gearset, [gearset->ItemsSpan[1]], inventoryItems, return HandleGearsetItem("Off Hand", gearset, [gearset->ItemsSpan[1]], inventoryItems,
EEquipSlotCategory.Shield); EEquipSlotCategory.Shield, level);
} }
private unsafe void ChangeGearset(uint commandId, SeString seString) private unsafe void ChangeGearset(uint commandId, SeString seString)