Consider items with materia as separate items to non-melded items

This commit is contained in:
Liza 2024-06-23 22:35:26 +02:00
parent 6c172a84f4
commit 275656e320
Signed by: liza
GPG Key ID: 7199F8D727D55F67
13 changed files with 358 additions and 180 deletions

View File

@ -30,7 +30,9 @@ public sealed class ItemSortingTest
ClassJob = EClassJob.Marauder, ClassJob = EClassJob.Marauder,
EquipSlotCategory = EEquipSlotCategory.Ears, EquipSlotCategory = EEquipSlotCategory.Ears,
ItemUiCategory = 41, ItemUiCategory = 41,
Items = initialItemIds.Select(rowId => new EquipmentItem(items.GetRow(rowId)!, false)).ToList(), Items = initialItemIds.Select(rowId => new EquipmentItem(items.GetRow(rowId)!, false))
.Cast<BaseItem>()
.ToList(),
}; };

View File

@ -23,7 +23,7 @@ internal enum EBaseParam : byte
DirectHit = 22, DirectHit = 22,
Determination = 44, Determination = 44,
SpellSpeed = 46, SpellSpeed = 46,
SkillSpeed = 23, SkillSpeed = 45,
Craftsmanship = 70, Craftsmanship = 70,
Control = 71, Control = 71,

View File

@ -83,6 +83,9 @@ internal sealed class GameDataHolder
.ThenBy(x => x.OrderMinor) .ThenBy(x => x.OrderMinor)
.Select(x => (x.RowId, x.Name.ToString())) .Select(x => (x.RowId, x.Name.ToString()))
.ToList(); .ToList();
Materias = dataManager.GetExcelSheet<Materia>()!
.Where(x => x.RowId > 0 && Enum.IsDefined(typeof(EBaseParam), (byte)x.BaseParam.Row))
.ToDictionary(x => x.RowId, x => new MateriaStat((EBaseParam)x.BaseParam.Row, x.Value));
_allItemLists = _allItemLists =
dataManager.GetExcelSheet<Item>()! dataManager.GetExcelSheet<Item>()!
@ -117,7 +120,7 @@ internal sealed class GameDataHolder
ClassJob = x.Key.ClassJob, ClassJob = x.Key.ClassJob,
EquipSlotCategory = x.Key.EquipSlotCategory, EquipSlotCategory = x.Key.EquipSlotCategory,
ItemUiCategory = x.Key.ItemUiCategory, ItemUiCategory = x.Key.ItemUiCategory,
Items = x.ToList(), Items = x.Cast<BaseItem>().ToList(),
}) })
.ToList() .ToList()
.AsReadOnly(); .AsReadOnly();
@ -125,10 +128,10 @@ internal sealed class GameDataHolder
UpdateAndSortLists(); UpdateAndSortLists();
} }
public IReadOnlyList<(EClassJob ClassJob, string Name)> ClassJobNames { get; } public IReadOnlyList<(EClassJob ClassJob, string Name)> ClassJobNames { get; }
public IReadOnlyList<(uint ItemUiCategory, string Name)> ItemUiCategoryNames { get; } public IReadOnlyList<(uint ItemUiCategory, string Name)> ItemUiCategoryNames { get; }
public Dictionary<EClassJob, EBaseParam> PrimaryStats { get; } public Dictionary<EClassJob, EBaseParam> PrimaryStats { get; }
public Dictionary<uint, MateriaStat> Materias { get; set; }
public Dictionary<EBaseParam, string> StatNames { get; } = new() public Dictionary<EBaseParam, string> StatNames { get; } = new()
{ {

View File

@ -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.6</Version> <Version>0.7</Version>
<LangVersion>12</LangVersion> <LangVersion>12</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

View File

@ -17,6 +17,7 @@ using Gearsetter.Model;
using Gearsetter.Windows; using Gearsetter.Windows;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany; using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany;
using InventoryItem = FFXIVClientStructs.FFXIV.Client.Game.InventoryItem;
namespace Gearsetter; namespace Gearsetter;
@ -149,7 +150,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, byte? level) Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
{ {
string name = GetGearsetName(gearset); string name = GetGearsetName(gearset);
if (name.Contains('_', StringComparison.Ordinal) || if (name.Contains('_', StringComparison.Ordinal) ||
@ -210,7 +211,8 @@ public sealed class GearsetterPlugin : IDalamudPlugin
=> Encoding.UTF8.GetString(gearset->Name, 0x2F).Split((char)0)[0]; => Encoding.UTF8.GetString(gearset->Name, 0x2F).Split((char)0)[0];
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), List<MateriaStats>> inventoryItems,
EEquipSlotCategory equipSlotCategory, byte? level) EEquipSlotCategory equipSlotCategory, byte? level)
{ {
EClassJob classJob = (EClassJob)gearset->ClassJob; EClassJob classJob = (EClassJob)gearset->ClassJob;
@ -230,7 +232,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
return new List<SeString>(); return new List<SeString>();
} }
EquipmentItem?[] currentItems = gearsetItem.Select(x => new BaseItem?[] currentItems = gearsetItem.Select(x => new
{ {
ItemId = x.ItemID % 1_000_000, ItemId = x.ItemID % 1_000_000,
Hq = x.ItemID > 1_000_000 Hq = x.ItemID > 1_000_000
@ -253,35 +255,38 @@ public sealed class GearsetterPlugin : IDalamudPlugin
if (level == null) if (level == null)
level = GetLevel(classJob); level = GetLevel(classJob);
var bestItems = availableList.Items try
.Where(x => x.Level <= level)
.SelectMany(x =>
{
if (inventoryItems.TryGetValue((x.ItemId, x.Hq), out int count) && count > 0)
return Enumerable.Repeat(x, count);
else
return [];
})
.Take(gearsetItem.Length)
.ToList();
_pluginLog.Debug(
$"{equipSlotCategory}: {string.Join(" ", currentItems.Select(x => $"{x?.ItemId}|{x?.Hq}"))}");
foreach (var currentItem in currentItems)
{ {
var foundIndex = bestItems.FindIndex(x => availableList.ApplyFromInventory(inventoryItems, true);
currentItem != null && currentItem.ItemId == x.ItemId && currentItem.Hq == x.Hq);
if (foundIndex >= 0)
bestItems.RemoveAt(foundIndex);
}
return bestItems var bestItems = availableList.Items
.Select(x => new SeString(new TextPayload($"{label}: ")) .Where(x => x.Level <= level)
.Append(SeString.CreateItemLink(x.ItemId, x.Hq))).ToList(); .Where(x => x is Model.InventoryItem)
.Take(gearsetItem.Length)
.ToList();
_pluginLog.Debug(
$"{equipSlotCategory}: {string.Join(" ", currentItems.Select(x => $"{x?.ItemId}|{x?.Hq}"))}");
foreach (var currentItem in currentItems)
{
var foundIndex = bestItems.FindIndex(x =>
currentItem != null && currentItem.ItemId == x.ItemId && currentItem.Hq == x.Hq);
if (foundIndex >= 0)
bestItems.RemoveAt(foundIndex);
}
return bestItems
.Select(x => new SeString(new TextPayload($"{label}: "))
.Append(SeString.CreateItemLink(x.ItemId, x.Hq))).ToList();
}
finally
{
availableList.ClearFromInventory();
}
} }
private unsafe List<SeString> HandleOffHand(RaptureGearsetModule.GearsetEntry* gearset, private unsafe List<SeString> HandleOffHand(RaptureGearsetModule.GearsetEntry* gearset,
Dictionary<(uint ItemId, bool Hq), int> inventoryItems, byte? level) Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level)
{ {
var mainHand = gearset->ItemsSpan[0]; var mainHand = gearset->ItemsSpan[0];
if (mainHand.ItemID == 0) if (mainHand.ItemID == 0)
@ -300,9 +305,9 @@ public sealed class GearsetterPlugin : IDalamudPlugin
private unsafe void ChangeGearset(uint commandId, SeString seString) private unsafe void ChangeGearset(uint commandId, SeString seString)
=> RaptureGearsetModule.Instance()->EquipGearset((byte)commandId); => RaptureGearsetModule.Instance()->EquipGearset((byte)commandId);
public unsafe Dictionary<(uint ItemId, bool Hq), int> GetAllInventoryItems() internal unsafe Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> GetAllInventoryItems()
{ {
Dictionary<(uint, bool), int> inventoryItems = new(); Dictionary<(uint, bool), List<MateriaStats>> inventoryItems = new();
InventoryManager* inventoryManager = InventoryManager.Instance(); InventoryManager* inventoryManager = InventoryManager.Instance();
foreach (var inventoryType in _gameDataHolder.DefaultInventoryTypes) foreach (var inventoryType in _gameDataHolder.DefaultInventoryTypes)
{ {
@ -313,10 +318,27 @@ public sealed class GearsetterPlugin : IDalamudPlugin
if (item != null && item->ItemID != 0) if (item != null && item->ItemID != 0)
{ {
var key = (item->ItemID, item->Flags.HasFlag(InventoryItem.ItemFlags.HQ)); var key = (item->ItemID, item->Flags.HasFlag(InventoryItem.ItemFlags.HQ));
if (inventoryItems.TryGetValue(key, out var value)) if (!inventoryItems.TryGetValue(key, out var list))
inventoryItems[key] = value + 1; {
else list = new List<MateriaStats>();
inventoryItems[key] = 1; inventoryItems[key] = list;
}
byte materiaCount = item->GetMateriaCount();
var materias = Enumerable.Range(0, materiaCount)
.Select<int, (MateriaStat, byte)?>(slot =>
{
if (_gameDataHolder.Materias.TryGetValue(item->GetMateriaId((byte)slot),
out MateriaStat? value))
return (value, item->GetMateriaGrade((byte)slot));
else
return null;
})
.Where(x => x != null)
.Select(x => x!.Value)
.ToList();
list.Add(new MateriaStats(materias));
} }
} }
} }

View File

@ -0,0 +1,59 @@
using Gearsetter.GameData;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model;
internal abstract record BaseItem(Item Item, bool Hq, MateriaStats? MateriaStats = null)
{
public Item Item { get; } = Item;
public uint ItemId { get; } = Item.RowId;
public bool Hq { get; } = Hq;
public bool CanBeHq { get; } = Item.CanBeHq;
public string Name { get; } = Item.Name.ToString();
public byte Level { get; } = Item.LevelEquip;
public uint ItemLevel { get; } = Item.LevelItem.Row;
public byte Rarity { get; } = Item.Rarity;
public EEquipSlotCategory EquipSlotCategory { get; } = (EEquipSlotCategory)Item.EquipSlotCategory.Row;
public uint ItemUiCategory { get; } = Item.ItemUICategory.Row;
public abstract EClassJob ClassJob { get; init; }
public EquipmentStats Stats { get; } = new(Item, Hq, MateriaStats);
public int PrimaryStat { get; init; } = -1;
public int Damage
{
get
{
if (ClassJob.DealsMagicDamage())
return Item.DamageMag + Stats.Get(EBaseParam.DamageMag);
else if (ClassJob.DealsPhysicalDamage())
return Item.DamagePhys + Stats.Get(EBaseParam.DamagePhys);
else
return 0;
}
}
public bool HasAnyStat(params EBaseParam[] substats)
{
foreach (EBaseParam substat in substats)
{
if (Stats.Get(substat) > 0)
return true;
}
return false;
}
public bool IsCombatRelicWithoutSubstats()
{
return Rarity == 4
&& EquipSlotCategory is EEquipSlotCategory.OneHandedMainHand
or EEquipSlotCategory.TwoHandedMainHand
or EEquipSlotCategory.Shield
&& !ClassJob.IsCrafter()
&& !ClassJob.IsGatherer()
&& !HasAnyStat(EBaseParam.Crit,
EBaseParam.DirectHit, EBaseParam.Determination, EBaseParam.SkillSpeed,
EBaseParam.SpellSpeed, EBaseParam.Tenacity);
}
}

View File

@ -3,57 +3,7 @@ using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model; namespace Gearsetter.Model;
internal sealed record EquipmentItem(Item Item, bool Hq) internal sealed record EquipmentItem(Item Item, bool Hq) : BaseItem(Item, Hq)
{ {
public Item Item { get; } = Item; public override EClassJob ClassJob { get; init; } = EClassJob.Adventurer;
public uint ItemId { get; } = Item.RowId;
public bool Hq { get; } = Hq;
public bool CanBeHq { get; } = Item.CanBeHq;
public string Name { get; } = Item.Name.ToString();
public byte Level { get; } = Item.LevelEquip;
public uint ItemLevel { get; } = Item.LevelItem.Row;
public byte Rarity { get; } = Item.Rarity;
public EEquipSlotCategory EquipSlotCategory { get; } = (EEquipSlotCategory)Item.EquipSlotCategory.Row;
public uint ItemUiCategory { get; } = Item.ItemUICategory.Row;
public EClassJob ClassJob { get; init; } = EClassJob.Adventurer;
public EquipmentStats Stats { get; } = new(Item, Hq);
public int PrimaryStat { get; init; } = -1;
public int Damage
{
get
{
if (ClassJob.DealsMagicDamage())
return Item.DamageMag + Stats.Get(EBaseParam.DamageMag);
else if (ClassJob.DealsPhysicalDamage())
return Item.DamagePhys + Stats.Get(EBaseParam.DamagePhys);
else
return 0;
}
}
public bool HasAnyStat(params EBaseParam[] substats)
{
foreach (EBaseParam substat in substats)
{
if (Stats.Get(substat) > 0)
return true;
}
return false;
}
public bool IsCombatRelicWithoutSubstats()
{
return Rarity == 4
&& EquipSlotCategory is EEquipSlotCategory.OneHandedMainHand
or EEquipSlotCategory.TwoHandedMainHand
or EEquipSlotCategory.Shield
&& !ClassJob.IsCrafter()
&& !ClassJob.IsGatherer()
&& !HasAnyStat(EBaseParam.Crit,
EBaseParam.DirectHit, EBaseParam.Determination, EBaseParam.SkillSpeed,
EBaseParam.SpellSpeed, EBaseParam.Tenacity);
}
} }

View File

@ -7,28 +7,52 @@ namespace Gearsetter.Model;
internal sealed class EquipmentStats internal sealed class EquipmentStats
{ {
private readonly Dictionary<EBaseParam, short> _values; private readonly Dictionary<EBaseParam, short> _equipmentValues;
private readonly Dictionary<EBaseParam, short> _materiaValues;
public EquipmentStats(Item item, bool hq) public EquipmentStats(Item item, bool hq, MateriaStats? materiaStats)
{ {
_values = item.UnkData59.Where(x => x.BaseParam > 0) _equipmentValues = item.UnkData59.Where(x => x.BaseParam > 0)
.ToDictionary(x => (EBaseParam)x.BaseParam, x => x.BaseParamValue); .ToDictionary(x => (EBaseParam)x.BaseParam, x => x.BaseParamValue);
if (hq) if (hq)
{ {
foreach (var hqstat in item.UnkData73.Select(x => foreach (var hqstat in item.UnkData73.Select(x =>
((EBaseParam)x.BaseParamSpecial, x.BaseParamValueSpecial))) ((EBaseParam)x.BaseParamSpecial, x.BaseParamValueSpecial)))
{ {
if (_values.TryGetValue(hqstat.Item1, out var stat)) if (_equipmentValues.TryGetValue(hqstat.Item1, out var stat))
_values[hqstat.Item1] = (short)(stat + hqstat.BaseParamValueSpecial); _equipmentValues[hqstat.Item1] = (short)(stat + hqstat.BaseParamValueSpecial);
else else
_values[hqstat.Item1] = hqstat.BaseParamValueSpecial; _equipmentValues[hqstat.Item1] = hqstat.BaseParamValueSpecial;
}
}
_materiaValues = new();
if (materiaStats != null)
{
foreach (var materiaStat in materiaStats.Values)
{
if (_materiaValues.TryGetValue(materiaStat.Key, out var stat))
_materiaValues[materiaStat.Key] = (short)(stat + materiaStat.Value);
else
_materiaValues[materiaStat.Key] = materiaStat.Value;
} }
} }
} }
public short Get(EBaseParam param) public short Get(EBaseParam param)
{ {
_values.TryGetValue(param, out short v); return (short)(GetEquipment(param) + GetMateria(param));
}
public short GetEquipment(EBaseParam param)
{
_equipmentValues.TryGetValue(param, out short v);
return v;
}
public short GetMateria(EBaseParam param)
{
_materiaValues.TryGetValue(param, out short v);
return v; return v;
} }
} }

View File

@ -0,0 +1,9 @@
using Gearsetter.GameData;
using Lumina.Excel.GeneratedSheets;
namespace Gearsetter.Model;
internal sealed record InventoryItem(Item Item, bool Hq, MateriaStats MateriaStats, EClassJob ClassJob)
: BaseItem(Item, Hq, MateriaStats)
{
}

View File

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Dalamud.Logging;
using Gearsetter.GameData; using Gearsetter.GameData;
namespace Gearsetter.Model; namespace Gearsetter.Model;
@ -20,7 +19,8 @@ internal sealed class ItemList
public required EClassJob ClassJob { get; init; } public required EClassJob ClassJob { get; init; }
public required EEquipSlotCategory EquipSlotCategory { get; init; } public required EEquipSlotCategory EquipSlotCategory { get; init; }
public required uint ItemUiCategory { get; init; } public required uint ItemUiCategory { get; init; }
public required List<EquipmentItem> Items { get; set; } public required List<BaseItem> Items { get; set; }
public EBaseParam PrimaryStat { get; set; }
public IReadOnlyList<EBaseParam> SubstatPriorities { get; set; } = new List<EBaseParam>(); public IReadOnlyList<EBaseParam> SubstatPriorities { get; set; } = new List<EBaseParam>();
public void Sort() public void Sort()
@ -30,11 +30,11 @@ internal sealed class ItemList
.ToList(); .ToList();
var defaultItems = Items var defaultItems = Items
.Except(preferredItems) .Except(preferredItems)
.OrderDescending(new EquipmentItemComparer(SubstatPriorities)) .OrderDescending(new ItemComparer(SubstatPriorities))
.ToList(); .ToList();
// insert the preferred items // insert the preferred items
foreach (EquipmentItem preferredItem in preferredItems) foreach (BaseItem preferredItem in preferredItems)
{ {
int level = PreferredItems[preferredItem.ItemId]; int level = PreferredItems[preferredItem.ItemId];
int index = defaultItems.FindIndex(x => x.Level < level); int index = defaultItems.FindIndex(x => x.Level < level);
@ -68,15 +68,48 @@ internal sealed class ItemList
if (primaryStats.TryGetValue(ClassJob, out EBaseParam primaryStat)) if (primaryStats.TryGetValue(ClassJob, out EBaseParam primaryStat))
{ {
PrimaryStat = primaryStat;
Items = Items Items = Items
.Where(x => x is EquipmentItem)
.Cast<EquipmentItem>()
.Select(x => x with { PrimaryStat = x.Stats.Get(primaryStat) }) .Select(x => x with { PrimaryStat = x.Stats.Get(primaryStat) })
.Cast<BaseItem>()
.ToList(); .ToList();
} }
} }
private sealed class EquipmentItemComparer(IReadOnlyList<EBaseParam> substatPriorities) : IComparer<EquipmentItem> public void ApplyFromInventory(Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems,
bool includeWithoutMateria)
{ {
public int Compare(EquipmentItem? a, EquipmentItem? b) foreach (var inventoryItem in inventoryItems)
{
var basicItem = Items.SingleOrDefault(x =>
x.ItemId == inventoryItem.Key.ItemId && x.Hq == inventoryItem.Key.Hq);
if (basicItem == null)
continue;
foreach (var materias in inventoryItem.Value)
{
if (includeWithoutMateria || materias.Values.Count > 0)
Items.Add(
new InventoryItem(basicItem.Item, basicItem.Hq, materias, basicItem.ClassJob)
{
PrimaryStat = basicItem.Stats.Get(PrimaryStat)
});
}
}
Sort();
}
public void ClearFromInventory()
{
Items.RemoveAll(x => x is InventoryItem);
}
private sealed class ItemComparer(IReadOnlyList<EBaseParam> substatPriorities) : IComparer<BaseItem>
{
public int Compare(BaseItem? a, BaseItem? b)
{ {
ArgumentNullException.ThrowIfNull(a); ArgumentNullException.ThrowIfNull(a);
ArgumentNullException.ThrowIfNull(b); ArgumentNullException.ThrowIfNull(b);

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using Gearsetter.GameData;
namespace Gearsetter.Model;
internal sealed class MateriaStat(EBaseParam baseParam, short[] values)
{
public EBaseParam BaseParam { get; } = baseParam;
public List<short> Values { get; } = values.ToList();
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Gearsetter.GameData;
namespace Gearsetter.Model;
internal sealed class MateriaStats
{
private readonly List<(EBaseParam, short)> _list;
public MateriaStats(IEnumerable<(MateriaStat Stat, byte Grade)> materias)
{
foreach (var materia in materias)
{
if (Values.TryGetValue(materia.Stat.BaseParam, out short value))
Values[materia.Stat.BaseParam] = (short)(value + materia.Stat.Values[materia.Grade]);
else
Values[materia.Stat.BaseParam] = materia.Stat.Values[materia.Grade];
++Count;
}
_list = Enum.GetValues<EBaseParam>()
.Select(x => (x, Values.GetValueOrDefault(x, (short)0)))
.Where(x => x.Item2 > 0)
.ToList();
}
public Dictionary<EBaseParam, short> Values { get; } = new();
public byte Count { get; }
public override bool Equals(object? obj)
{
if (obj is not MateriaStats other)
return false;
return _list == other._list;
}
public override int GetHashCode()
{
int hash = 19;
hash = hash * 31 + Count;
foreach (var item in _list)
hash = hash * 31 + item.GetHashCode();
return hash;
}
}

View File

@ -9,6 +9,7 @@ using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using Gearsetter.GameData; using Gearsetter.GameData;
using Gearsetter.Model;
using ImGuiNET; using ImGuiNET;
namespace Gearsetter.Windows; namespace Gearsetter.Windows;
@ -109,102 +110,117 @@ internal sealed class EquipmentBrowserWindow : Window
ImGui.SameLine(); ImGui.SameLine();
ImGui.Checkbox("Hide normal quality items", ref _hideNormalQualityItems); ImGui.Checkbox("Hide normal quality items", ref _hideNormalQualityItems);
Dictionary<(uint, bool), int>? ownedItems = null; Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> ownedItems = _plugin.GetAllInventoryItems();
if (_onlyShowOwnedItems) try
ownedItems = _plugin.GetAllInventoryItems();
byte maxLevel = byte.MaxValue;
if (_onlyShowEquippableItems)
maxLevel = _plugin.GetLevel(_selectedClassJob);
bool includeDamage = _selectedEquipmentCategory is EEquipSlotCategory.OneHandedMainHand
or EEquipSlotCategory.Shield
or EEquipSlotCategory.TwoHandedMainHand
&& !itemList.ClassJob.IsCrafter()
&& !itemList.ClassJob.IsGatherer();
if (ImGui.BeginTable("ItemList", 2 + (includeDamage ? 1 : 0) + itemList.SubstatPriorities.Count,
ImGuiTableFlags.Borders | ImGuiTableFlags.Resizable))
{ {
ImGui.TableSetupColumn("Name", ImGuiTableColumnFlags.None, 300); itemList.ApplyFromInventory(ownedItems, _onlyShowOwnedItems);
ImGui.TableSetupColumn("Level", ImGuiTableColumnFlags.WidthFixed, 50);
if (includeDamage)
ImGui.TableSetupColumn("Damage", ImGuiTableColumnFlags.WidthFixed, 50);
foreach (var substat in itemList.SubstatPriorities)
ImGui.TableSetupColumn(_dataHolder.StatNames[substat], ImGuiTableColumnFlags.WidthFixed, 50);
ImGui.TableHeadersRow(); byte maxLevel = byte.MaxValue;
if (_onlyShowEquippableItems)
maxLevel = _plugin.GetLevel(_selectedClassJob);
foreach (var item in itemList.Items) bool includeDamage = _selectedEquipmentCategory is EEquipSlotCategory.OneHandedMainHand
or EEquipSlotCategory.Shield
or EEquipSlotCategory.TwoHandedMainHand
&& !itemList.ClassJob.IsCrafter()
&& !itemList.ClassJob.IsGatherer();
if (ImGui.BeginTable("ItemList", 2 + (includeDamage ? 1 : 0) + itemList.SubstatPriorities.Count,
ImGuiTableFlags.Borders | ImGuiTableFlags.Resizable))
{ {
if (ownedItems != null && !ownedItems.ContainsKey((item.ItemId, item.Hq))) ImGui.TableSetupColumn("Name", ImGuiTableColumnFlags.None, 300);
continue; ImGui.TableSetupColumn("Level", ImGuiTableColumnFlags.WidthFixed, 50);
if (includeDamage)
ImGui.TableSetupColumn("Damage", ImGuiTableColumnFlags.WidthFixed, 50);
foreach (var substat in itemList.SubstatPriorities)
ImGui.TableSetupColumn(_dataHolder.StatNames[substat], ImGuiTableColumnFlags.WidthFixed, 50);
if (item.Level > maxLevel) ImGui.TableHeadersRow();
continue;
if (_hideNormalQualityItems && item.CanBeHq && !item.Hq) foreach (var item in itemList.Items.DistinctBy(x => new { x.ItemId, x.Hq, Materia = x.MateriaStats?.GetHashCode() }))
continue;
ImGui.TableNextRow();
if (ImGui.TableNextColumn())
{ {
Vector4? color = item.Rarity switch if (item is not InventoryItem)
{ {
2 => ImGuiColors.ParsedGreen, if (_onlyShowOwnedItems)
3 => ImGuiColors.ParsedBlue, continue;
4 => ImGuiColors.ParsedPurple,
7 => ImGuiColors.ParsedPink,
_ => null,
};
string name = item.Name;
if (item.Hq)
name += $" {SeIconChar.HighQuality.ToIconString()}";
if (color != null)
ImGui.TextColored(color.Value, name);
else
ImGui.Text(name);
if (ImGui.IsItemClicked())
{
try
{
_chatGui.Print(SeString.CreateItemLink(item.ItemId, item.Hq));
}
catch (Exception)
{
// doesn't matter, just nice-to-have
}
} }
}
if (ImGui.TableNextColumn()) if (item.Level > maxLevel)
{ continue;
if (item.Level >= 50 && item.Level % 10 == 0)
ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{item.Level} ({item.ItemLevel})"));
else
ImGui.Text(item.Level.ToString(CultureInfo.InvariantCulture));
}
if (includeDamage && ImGui.TableNextColumn()) if (_hideNormalQualityItems && item.CanBeHq && !item.Hq)
ImGui.Text(item.Damage.ToString(CultureInfo.CurrentCulture)); continue;
ImGui.TableNextRow();
foreach (EBaseParam substat in itemList.SubstatPriorities)
{
if (ImGui.TableNextColumn()) if (ImGui.TableNextColumn())
{ {
var stat = item.Stats.Get(substat); Vector4? color = item.Rarity switch
if (stat == 0) {
ImGui.Text("-"); 2 => ImGuiColors.ParsedGreen,
3 => ImGuiColors.ParsedBlue,
4 => ImGuiColors.ParsedPurple,
7 => ImGuiColors.ParsedPink,
_ => null,
};
string name = item.Name;
if (item.Hq)
name += $" {SeIconChar.HighQuality.ToIconString()}";
if (item is InventoryItem { MateriaStats: not null } inventoryItem)
name +=
$" {string.Join("", Enumerable.Repeat(SeIconChar.Circle.ToIconString(), inventoryItem.MateriaStats.Count))}";
if (color != null)
ImGui.TextColored(color.Value, name);
else else
ImGui.Text(stat.ToString(CultureInfo.CurrentCulture)); ImGui.Text(name);
if (ImGui.IsItemClicked())
{
try
{
_chatGui.Print(SeString.CreateItemLink(item.ItemId, item.Hq));
}
catch (Exception)
{
// doesn't matter, just nice-to-have
}
}
}
if (ImGui.TableNextColumn())
{
if (item.Level >= 50 && item.Level % 10 == 0)
ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{item.Level} ({item.ItemLevel})"));
else
ImGui.Text(item.Level.ToString(CultureInfo.InvariantCulture));
}
if (includeDamage && ImGui.TableNextColumn())
ImGui.Text(item.Damage.ToString(CultureInfo.CurrentCulture));
foreach (EBaseParam substat in itemList.SubstatPriorities)
{
if (ImGui.TableNextColumn())
{
var estat = item.Stats.GetEquipment(substat);
var mstat = item.Stats.GetMateria(substat);
if (estat == 0 && mstat == 0)
ImGui.Text("-");
else if (mstat == 0)
ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{estat}"));
else
ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{estat} +{mstat}"));
}
} }
} }
}
ImGui.EndTable(); ImGui.EndTable();
}
}
finally
{
itemList.ClearFromInventory();
} }
} }