Compare commits

...

3 Commits
v2.0 ... master

16 changed files with 91 additions and 252 deletions

View File

@ -4,6 +4,7 @@ using System.Linq;
using Gearsetter.GameData; using Gearsetter.GameData;
using Gearsetter.Model; using Gearsetter.Model;
using LLib.GameData; using LLib.GameData;
using LLib.Gear;
using Lumina.Excel.Sheets; using Lumina.Excel.Sheets;
using Xunit; using Xunit;
@ -16,6 +17,10 @@ public sealed class ItemSortingTest
[Fact] [Fact]
public void Test1() public void Test1()
{ {
var gearStatsCalculator = new GearStatsCalculator(_lumina.GetExcelSheet<ItemLevel>()!,
_lumina.GetExcelSheet<ExtendedBaseParam>()!,
_lumina.GetExcelSheet<Materia>()!,
_lumina.GetExcelSheet<Item>()!);
var items = _lumina.GetExcelSheet<Item>()!; var items = _lumina.GetExcelSheet<Item>()!;
List<uint> initialItemIds = List<uint> initialItemIds =
[ [
@ -30,12 +35,13 @@ public sealed class ItemSortingTest
32558, 32558,
]; ];
var itemList = new ItemList var itemList = new ItemList
{ {
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)) Items = initialItemIds.Select(rowId => new EquipmentItem(items.GetRow(rowId), false, gearStatsCalculator.CalculateGearStats(items.GetRow(rowId), false, [])))
.Cast<BaseItem>() .Cast<BaseItem>()
.ToList(), .ToList(),
}; };

View File

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Dalamud.Configuration; using Dalamud.Configuration;
using Gearsetter.GameData; using LLib.Gear;
namespace Gearsetter; namespace Gearsetter;

View File

@ -1,34 +0,0 @@
namespace Gearsetter.GameData;
internal enum EBaseParam : byte
{
None = 0,
Strength = 1,
Dexterity = 2,
Vitality = 3,
Intelligence = 4,
Mind = 5,
Piety = 6,
GP = 10,
CP = 11,
DamagePhys = 12,
DamageMag = 13,
DefensePhys = 21,
DefenseMag = 24,
Tenacity = 19,
Crit = 27,
DirectHit = 22,
Determination = 44,
SpellSpeed = 46,
SkillSpeed = 45,
Craftsmanship = 70,
Control = 71,
Gathering = 72,
Perception = 73,
}

View File

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Dalamud;
using Dalamud.Game; using Dalamud.Game;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game;
using Gearsetter.Model; using Gearsetter.Model;
using LLib.GameData; using LLib.GameData;
using LLib.Gear;
using Lumina.Excel.Sheets; using Lumina.Excel.Sheets;
namespace Gearsetter.GameData; namespace Gearsetter.GameData;
@ -14,12 +14,15 @@ namespace Gearsetter.GameData;
internal sealed class GameDataHolder internal sealed class GameDataHolder
{ {
private readonly Configuration _configuration; private readonly Configuration _configuration;
private readonly GearStatsCalculator _gearStatsCalculator;
private readonly Dictionary<uint, List<EClassJob>> _classJobCategories; private readonly Dictionary<uint, List<EClassJob>> _classJobCategories;
private readonly IReadOnlyList<ItemList> _allItemLists; private readonly IReadOnlyList<ItemList> _allItemLists;
public GameDataHolder(IDataManager dataManager, Configuration configuration) public GameDataHolder(IDataManager dataManager, Configuration configuration,
GearStatsCalculator gearStatsCalculator)
{ {
_configuration = configuration; _configuration = configuration;
_gearStatsCalculator = gearStatsCalculator;
_classJobCategories = dataManager.GetExcelSheet<ClassJobCategory>() _classJobCategories = dataManager.GetExcelSheet<ClassJobCategory>()
.ToDictionary(x => x.RowId, x => .ToDictionary(x => x.RowId, x =>
new Dictionary<EClassJob, bool> new Dictionary<EClassJob, bool>
@ -87,9 +90,6 @@ 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.RowId))
.ToDictionary(x => x.RowId, x => new MateriaStat((EBaseParam)x.BaseParam.RowId, x.Value.ToArray()));
_allItemLists = _allItemLists =
dataManager.GetExcelSheet<Item>() dataManager.GetExcelSheet<Item>()
@ -135,7 +135,6 @@ internal sealed class GameDataHolder
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()
{ {
@ -207,8 +206,14 @@ internal sealed class GameDataHolder
private IEnumerable<(EquipmentItem Item, List<EClassJob> ClassJobs)> LoadItem(Item item) private IEnumerable<(EquipmentItem Item, List<EClassJob> ClassJobs)> LoadItem(Item item)
{ {
var classJobCategories = _classJobCategories[item.ClassJobCategory.RowId]; var classJobCategories = _classJobCategories[item.ClassJobCategory.RowId];
yield return (new EquipmentItem(item, false), classJobCategories); yield return (
new EquipmentItem(item, false, _gearStatsCalculator.CalculateGearStats(item, false, [])),
classJobCategories);
if (item.CanBeHq) if (item.CanBeHq)
yield return (new EquipmentItem(item, true), classJobCategories); {
yield return (
new EquipmentItem(item, true, _gearStatsCalculator.CalculateGearStats(item, true, [])),
classJobCategories);
}
} }
} }

View File

@ -1,6 +1,6 @@
<Project Sdk="Dalamud.NET.Sdk/11.0.0"> <Project Sdk="Dalamud.NET.Sdk/11.0.0">
<PropertyGroup> <PropertyGroup>
<Version>2.0</Version> <Version>2.1</Version>
<OutputPath>dist</OutputPath> <OutputPath>dist</OutputPath>
</PropertyGroup> </PropertyGroup>

View File

@ -17,6 +17,7 @@ using Gearsetter.GameData;
using Gearsetter.Model; using Gearsetter.Model;
using Gearsetter.Windows; using Gearsetter.Windows;
using LLib.GameData; using LLib.GameData;
using LLib.Gear;
using Lumina.Excel.Sheets; using Lumina.Excel.Sheets;
using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany; using GrandCompany = FFXIVClientStructs.FFXIV.Client.UI.Agent.GrandCompany;
using InventoryItem = FFXIVClientStructs.FFXIV.Client.Game.InventoryItem; using InventoryItem = FFXIVClientStructs.FFXIV.Client.Game.InventoryItem;
@ -35,6 +36,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
private readonly IClientState _clientState; private readonly IClientState _clientState;
private readonly GearsetterIpc _gearsetterIpc; private readonly GearsetterIpc _gearsetterIpc;
private readonly Configuration _configuration; private readonly Configuration _configuration;
private readonly GearStatsCalculator _gearStatsCalculator;
private readonly GameDataHolder _gameDataHolder; private readonly GameDataHolder _gameDataHolder;
private readonly EquipmentBrowserWindow _equipmentBrowserWindow; private readonly EquipmentBrowserWindow _equipmentBrowserWindow;
private readonly ConfigWindow _configWindow; private readonly ConfigWindow _configWindow;
@ -62,7 +64,8 @@ public sealed class GearsetterPlugin : IDalamudPlugin
} }
_configuration = configuration; _configuration = configuration;
_gameDataHolder = new GameDataHolder(dataManager, _configuration); _gearStatsCalculator = new GearStatsCalculator(dataManager);
_gameDataHolder = new GameDataHolder(dataManager, _configuration, _gearStatsCalculator);
_equipmentBrowserWindow = new EquipmentBrowserWindow(this, _gameDataHolder, _clientState, _chatGui); _equipmentBrowserWindow = new EquipmentBrowserWindow(this, _gameDataHolder, _clientState, _chatGui);
_windowSystem.AddWindow(_equipmentBrowserWindow); _windowSystem.AddWindow(_equipmentBrowserWindow);
_configWindow = new ConfigWindow(_pluginInterface, _configuration); _configWindow = new ConfigWindow(_pluginInterface, _configuration);
@ -175,19 +178,19 @@ public sealed class GearsetterPlugin : IDalamudPlugin
name.Contains("Bozja", StringComparison.OrdinalIgnoreCase)) name.Contains("Bozja", StringComparison.OrdinalIgnoreCase))
return null; return null;
return new GearsetData(_dataManager, gearset, name); return new GearsetData(_dataManager, _gearStatsCalculator, gearset, name);
} }
internal unsafe List<RecommendedItemChange> GetRecommendedUpgrades(RaptureGearsetModule.GearsetEntry* gearset, internal unsafe List<RecommendedItemChange> GetRecommendedUpgrades(RaptureGearsetModule.GearsetEntry* gearset,
byte? level = null) byte? level = null)
{ {
GearsetData gearsetData = new GearsetData(_dataManager, gearset, GetGearsetName(gearset)); GearsetData gearsetData = new GearsetData(_dataManager, _gearStatsCalculator, gearset, GetGearsetName(gearset));
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems = GetAllInventoryItems(); Dictionary<(uint ItemId, bool Hq), List<EquipmentStats>> inventoryItems = GetAllInventoryItems();
return GetRecommendedUpgrades(gearsetData, inventoryItems, level); return GetRecommendedUpgrades(gearsetData, inventoryItems, level);
} }
private List<RecommendedItemChange> GetRecommendedUpgrades(GearsetData gearset, private List<RecommendedItemChange> GetRecommendedUpgrades(GearsetData gearset,
Dictionary<(uint ItemId, bool Hql), List<MateriaStats>> inventoryItems, byte? level) Dictionary<(uint ItemId, bool Hql), List<EquipmentStats>> inventoryItems, byte? level)
{ {
List<RecommendedItemChange> Handle(string label, List<RecommendedItemChange> Handle(string label,
(EquipmentItem?, RaptureGearsetModule.GearsetItemIndex)[] gearsetItems, (EquipmentItem?, RaptureGearsetModule.GearsetItemIndex)[] gearsetItems,
@ -225,7 +228,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
private bool HandleGearset(GearsetData gearset, private bool HandleGearset(GearsetData gearset,
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level) Dictionary<(uint ItemId, bool Hq), List<EquipmentStats>> inventoryItems, byte? level)
{ {
List<RecommendedItemChange> upgrades = GetRecommendedUpgrades(gearset, inventoryItems, level); List<RecommendedItemChange> upgrades = GetRecommendedUpgrades(gearset, inventoryItems, level);
if (upgrades.Count == 0) if (upgrades.Count == 0)
@ -258,7 +261,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
private List<RecommendedItemChange> HandleGearsetItem(string label, GearsetData gearset, private List<RecommendedItemChange> HandleGearsetItem(string label, GearsetData gearset,
(EquipmentItem? Item, RaptureGearsetModule.GearsetItemIndex Slot)[] gearsetItems, (EquipmentItem? Item, RaptureGearsetModule.GearsetItemIndex Slot)[] gearsetItems,
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, Dictionary<(uint ItemId, bool Hq), List<EquipmentStats>> inventoryItems,
EEquipSlotCategory equipSlotCategory, byte? level) EEquipSlotCategory equipSlotCategory, byte? level)
{ {
EClassJob classJob = gearset.ClassJob; EClassJob classJob = gearset.ClassJob;
@ -338,7 +341,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
} }
private List<RecommendedItemChange> HandleOffHand(GearsetData gearset, private List<RecommendedItemChange> HandleOffHand(GearsetData gearset,
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, byte? level) Dictionary<(uint ItemId, bool Hq), List<EquipmentStats>> inventoryItems, byte? level)
{ {
var mainHand = gearset.MainHand; var mainHand = gearset.MainHand;
if (mainHand == null) if (mainHand == null)
@ -372,8 +375,8 @@ public sealed class GearsetterPlugin : IDalamudPlugin
if (item != null && item->ItemId == baseItem.ItemId && if (item != null && item->ItemId == baseItem.ItemId &&
item->Flags.HasFlag(InventoryItem.ItemFlags.HighQuality) == baseItem.Hq) item->Flags.HasFlag(InventoryItem.ItemFlags.HighQuality) == baseItem.Hq)
{ {
MateriaStats expectedMateriaStats = baseItem.MateriaStats ?? new([]); EquipmentStats expectedMateriaStats = baseItem.Stats;
MateriaStats actualMateriaStats = FetchMateriaStats(item); EquipmentStats actualMateriaStats = FetchMateriaStats(item);
if (expectedMateriaStats == actualMateriaStats) if (expectedMateriaStats == actualMateriaStats)
return new RecommendedItemChange(item->ItemId, inventoryType, i, targetSlot, text); return new RecommendedItemChange(item->ItemId, inventoryType, i, targetSlot, text);
@ -384,9 +387,9 @@ public sealed class GearsetterPlugin : IDalamudPlugin
return new RecommendedItemChange(baseItem.ItemId, null, null, targetSlot, text); return new RecommendedItemChange(baseItem.ItemId, null, null, targetSlot, text);
} }
internal unsafe Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> GetAllInventoryItems() internal unsafe Dictionary<(uint ItemId, bool Hq), List<EquipmentStats>> GetAllInventoryItems()
{ {
Dictionary<(uint, bool), List<MateriaStats>> inventoryItems = new(); Dictionary<(uint, bool), List<EquipmentStats>> inventoryItems = new();
InventoryManager* inventoryManager = InventoryManager.Instance(); InventoryManager* inventoryManager = InventoryManager.Instance();
foreach (var inventoryType in _gameDataHolder.DefaultInventoryTypes) foreach (var inventoryType in _gameDataHolder.DefaultInventoryTypes)
{ {
@ -399,7 +402,7 @@ public sealed class GearsetterPlugin : IDalamudPlugin
var key = (item->ItemId, item->Flags.HasFlag(InventoryItem.ItemFlags.HighQuality)); var key = (item->ItemId, item->Flags.HasFlag(InventoryItem.ItemFlags.HighQuality));
if (!inventoryItems.TryGetValue(key, out var list)) if (!inventoryItems.TryGetValue(key, out var list))
{ {
list = new List<MateriaStats>(); list = new List<EquipmentStats>();
inventoryItems[key] = list; inventoryItems[key] = list;
} }
@ -411,22 +414,8 @@ public sealed class GearsetterPlugin : IDalamudPlugin
return inventoryItems; return inventoryItems;
} }
private unsafe MateriaStats FetchMateriaStats(InventoryItem* item) private unsafe EquipmentStats FetchMateriaStats(InventoryItem* item)
{ => _gearStatsCalculator.CalculateGearStats(item);
// FIXME item->GetMateriaCount is broken on API 10, so this seems to be somewhat slow
List<(MateriaStat, byte)> materias = new();
for (int slot = 0; slot < 5; ++slot)
{
var materiaId = item->Materia[slot];
if (materiaId == 0)
break;
if (_gameDataHolder.Materias.TryGetValue(materiaId, out MateriaStat? value))
materias.Add((value, item->MateriaGrades[slot]));
}
return new MateriaStats(materias);
}
internal unsafe byte GetLevel(EClassJob classJob) internal unsafe byte GetLevel(EClassJob classJob)
{ {

View File

@ -1,10 +1,12 @@
using Gearsetter.GameData; using System.Linq;
using Gearsetter.GameData;
using LLib.GameData; using LLib.GameData;
using LLib.Gear;
using Lumina.Excel.Sheets; using Lumina.Excel.Sheets;
namespace Gearsetter.Model; namespace Gearsetter.Model;
internal abstract record BaseItem(Item Item, bool Hq, MateriaStats? MateriaStats = null) internal abstract record BaseItem(Item Item, bool Hq, EquipmentStats Stats)
{ {
public Item Item { get; } = Item; public Item Item { get; } = Item;
public uint ItemId { get; } = Item.RowId; public uint ItemId { get; } = Item.RowId;
@ -17,7 +19,7 @@ internal abstract record BaseItem(Item Item, bool Hq, MateriaStats? MateriaStats
public EEquipSlotCategory EquipSlotCategory { get; } = (EEquipSlotCategory)Item.EquipSlotCategory.RowId; public EEquipSlotCategory EquipSlotCategory { get; } = (EEquipSlotCategory)Item.EquipSlotCategory.RowId;
public uint ItemUiCategory { get; } = Item.ItemUICategory.RowId; public uint ItemUiCategory { get; } = Item.ItemUICategory.RowId;
public abstract EClassJob ClassJob { get; init; } public abstract EClassJob ClassJob { get; init; }
public EquipmentStats Stats { get; } = new(Item, Hq, MateriaStats); public EquipmentStats Stats { get; } = Stats;
public int PrimaryStat { get; init; } = -1; public int PrimaryStat { get; init; } = -1;
@ -35,15 +37,7 @@ internal abstract record BaseItem(Item Item, bool Hq, MateriaStats? MateriaStats
} }
public bool HasAnyStat(params EBaseParam[] substats) public bool HasAnyStat(params EBaseParam[] substats)
{ => substats.Any(x => Stats.Has(x));
foreach (EBaseParam substat in substats)
{
if (Stats.Get(substat) > 0)
return true;
}
return false;
}
public bool IsCombatRelicWithoutSubstats() public bool IsCombatRelicWithoutSubstats()
{ {

View File

@ -1,10 +1,10 @@
using Gearsetter.GameData; using LLib.GameData;
using LLib.GameData; using LLib.Gear;
using Lumina.Excel.Sheets; using Lumina.Excel.Sheets;
namespace Gearsetter.Model; namespace Gearsetter.Model;
internal sealed record EquipmentItem(Item Item, bool Hq) : BaseItem(Item, Hq) internal sealed record EquipmentItem(Item Item, bool Hq, EquipmentStats Stats) : BaseItem(Item, Hq, Stats)
{ {
public override EClassJob ClassJob { get; init; } = EClassJob.Adventurer; public override EClassJob ClassJob { get; init; } = EClassJob.Adventurer;
} }

View File

@ -1,63 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Gearsetter.GameData; using LLib.Gear;
using Lumina.Excel.Sheets;
namespace Gearsetter.Model; namespace Gearsetter.Model;
internal sealed class EquipmentStats
{
private readonly Dictionary<EBaseParam, short> _equipmentValues;
private readonly Dictionary<EBaseParam, short> _materiaValues;
public EquipmentStats(Item item, bool hq, MateriaStats? materiaStats)
{
_equipmentValues = Enumerable.Range(0, item.BaseParam.Count)
.Where(i => item.BaseParam[i].RowId > 0)
.ToDictionary(i => (EBaseParam)item.BaseParam[i].RowId, i => item.BaseParamValue[i]);
if (hq)
{
for (int i = 0; i < item.BaseParamSpecial.Count; ++i)
{
EBaseParam baseParam = (EBaseParam)item.BaseParamSpecial[i].RowId;
if (baseParam == EBaseParam.None)
continue;
var baseParamValue = item.BaseParamValueSpecial[i];
if (_equipmentValues.TryGetValue(baseParam, out var stat))
_equipmentValues[baseParam] = (short)(stat + baseParamValue);
else
_equipmentValues[baseParam] = baseParamValue;
}
}
_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)
{
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;
}
}

View File

@ -1,40 +1,43 @@
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Client.UI.Misc; using FFXIVClientStructs.FFXIV.Client.UI.Misc;
using LLib.GameData; using LLib.GameData;
using LLib.Gear;
using Lumina.Excel.Sheets; using Lumina.Excel.Sheets;
namespace Gearsetter.Model; namespace Gearsetter.Model;
internal sealed class GearsetData internal sealed class GearsetData
{ {
public unsafe GearsetData(IDataManager dataManager, RaptureGearsetModule.GearsetEntry* gearset, string name) public unsafe GearsetData(IDataManager dataManager, GearStatsCalculator gearStatsCalculator,
RaptureGearsetModule.GearsetEntry* gearset, string name)
{ {
Id = gearset->Id; Id = gearset->Id;
ClassJob = (EClassJob)gearset->ClassJob; ClassJob = (EClassJob)gearset->ClassJob;
Name = name; Name = name;
MainHand = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.MainHand); MainHand = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.MainHand);
OffHand = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.OffHand); OffHand = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.OffHand);
Head = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Head); Head = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.Head);
Body = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Body); Body = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.Body);
Hands = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Hands); Hands = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.Hands);
Legs = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Legs); Legs = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.Legs);
Feet = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Feet); Feet = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.Feet);
Ears = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Ears); Ears = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.Ears);
Neck = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Neck); Neck = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.Neck);
Wrists = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.Wrists); Wrists = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.Wrists);
RingLeft = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.RingLeft); RingLeft = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.RingLeft);
RingRight = GetItem(dataManager, gearset, RaptureGearsetModule.GearsetItemIndex.RingRight); RingRight = GetItem(dataManager, gearStatsCalculator, gearset, RaptureGearsetModule.GearsetItemIndex.RingRight);
} }
private static unsafe EquipmentItem? GetItem(IDataManager dataManager, RaptureGearsetModule.GearsetEntry* gearset, private static unsafe EquipmentItem? GetItem(IDataManager dataManager, GearStatsCalculator gearStatsCalculator,
RaptureGearsetModule.GearsetItemIndex index) RaptureGearsetModule.GearsetEntry* gearset, RaptureGearsetModule.GearsetItemIndex index)
{ {
var gearsetItem = gearset->GetItem(index); var gearsetItem = gearset->GetItem(index);
if (gearsetItem.ItemId == 0) if (gearsetItem.ItemId == 0)
return null; return null;
var item = dataManager.GetExcelSheet<Item>().GetRow(gearsetItem.ItemId % 1_000_000); var item = dataManager.GetExcelSheet<Item>().GetRow(gearsetItem.ItemId % 1_000_000);
return new EquipmentItem(item, gearsetItem.ItemId > 1_000_000); bool hq = gearsetItem.ItemId > 1_000_000;
return new EquipmentItem(item, hq, gearStatsCalculator.CalculateGearStats(item, hq, []));
} }
public byte Id { get; } public byte Id { get; }

View File

@ -1,9 +1,10 @@
using LLib.GameData; using LLib.GameData;
using LLib.Gear;
using Lumina.Excel.Sheets; using Lumina.Excel.Sheets;
namespace Gearsetter.Model; namespace Gearsetter.Model;
internal sealed record InventoryItem(Item Item, bool Hq, MateriaStats MateriaStats, EClassJob ClassJob) internal sealed record InventoryItem(Item Item, bool Hq, EquipmentStats Stats, EClassJob ClassJob)
: BaseItem(Item, Hq, MateriaStats) : BaseItem(Item, Hq, Stats)
{ {
} }

View File

@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Gearsetter.GameData; using Gearsetter.GameData;
using LLib.GameData; using LLib.GameData;
using LLib.Gear;
namespace Gearsetter.Model; namespace Gearsetter.Model;
@ -22,7 +23,7 @@ internal sealed class ItemList
public required uint ItemUiCategory { get; init; } public required uint ItemUiCategory { get; init; }
public required List<BaseItem> Items { get; set; } public required List<BaseItem> Items { get; set; }
public EBaseParam PrimaryStat { get; set; } public EBaseParam PrimaryStat { get; set; }
public IReadOnlyList<EBaseParam> SubstatPriorities { get; set; } = new List<EBaseParam>(); public IReadOnlyList<EBaseParam> SubstatPriorities { get; private set; } = new List<EBaseParam>();
public void Sort() public void Sort()
{ {
@ -62,7 +63,7 @@ internal sealed class ItemList
} }
} }
public void ApplyFromInventory(Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> inventoryItems, public void ApplyFromInventory(Dictionary<(uint ItemId, bool Hq), List<EquipmentStats>> inventoryItems,
bool includeWithoutMateria) bool includeWithoutMateria)
{ {
foreach (var inventoryItem in inventoryItems) foreach (var inventoryItem in inventoryItems)
@ -72,11 +73,11 @@ internal sealed class ItemList
if (basicItem == null) if (basicItem == null)
continue; continue;
foreach (var materias in inventoryItem.Value) foreach (var inventoryStats in inventoryItem.Value)
{ {
if (includeWithoutMateria || materias.Values.Count > 0) if (includeWithoutMateria || inventoryStats.HasMateria())
Items.Add( Items.Add(
new InventoryItem(basicItem.Item, basicItem.Hq, materias, basicItem.ClassJob) new InventoryItem(basicItem.Item, basicItem.Hq, inventoryStats, basicItem.ClassJob)
{ {
PrimaryStat = basicItem.Stats.Get(PrimaryStat) PrimaryStat = basicItem.Stats.Get(PrimaryStat)
}); });
@ -172,7 +173,7 @@ internal sealed class ItemList
return string.CompareOrdinal(a.Name, b.Name); return string.CompareOrdinal(a.Name, b.Name);
} }
public static bool TryGetPreferredItemPriority(BaseItem self, BaseItem other, out byte priority) private static bool TryGetPreferredItemPriority(BaseItem self, BaseItem other, out byte priority)
{ {
if (PreferredItems.TryGetValue(self.ItemId, out byte levelSelf)) if (PreferredItems.TryGetValue(self.ItemId, out byte levelSelf))
{ {

View File

@ -1,11 +0,0 @@
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

@ -1,64 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Gearsetter.GameData;
namespace Gearsetter.Model;
internal sealed class MateriaStats : IEquatable<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)
{
return ReferenceEquals(this, obj) || obj is MateriaStats other && Equals(other);
}
public override int GetHashCode()
{
return _list.GetHashCode();
}
public bool Equals(MateriaStats? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return _list.SequenceEqual(other._list);
}
public static bool operator ==(MateriaStats? left, MateriaStats? right)
{
return Equals(left, right);
}
public static bool operator !=(MateriaStats? left, MateriaStats? right)
{
return !Equals(left, right);
}
public override string ToString()
{
return $"Materias[{string.Join(", ", _list.Select(x => $"{x.Item1}:{x.Item2}"))}]";
}
}

View File

@ -11,6 +11,7 @@ using Gearsetter.GameData;
using Gearsetter.Model; using Gearsetter.Model;
using ImGuiNET; using ImGuiNET;
using LLib.GameData; using LLib.GameData;
using LLib.Gear;
using LLib.ImGui; using LLib.ImGui;
namespace Gearsetter.Windows; namespace Gearsetter.Windows;
@ -111,7 +112,7 @@ internal sealed class EquipmentBrowserWindow : LWindow
ImGui.SameLine(); ImGui.SameLine();
ImGui.Checkbox("Hide normal quality items", ref _hideNormalQualityItems); ImGui.Checkbox("Hide normal quality items", ref _hideNormalQualityItems);
Dictionary<(uint ItemId, bool Hq), List<MateriaStats>> ownedItems = _plugin.GetAllInventoryItems(); Dictionary<(uint ItemId, bool Hq), List<EquipmentStats>> ownedItems = _plugin.GetAllInventoryItems();
try try
{ {
itemList.ApplyFromInventory(ownedItems, _onlyShowOwnedItems); itemList.ApplyFromInventory(ownedItems, _onlyShowOwnedItems);
@ -144,7 +145,7 @@ internal sealed class EquipmentBrowserWindow : LWindow
ImGui.PushStyleColor(ImGuiCol.HeaderHovered, hoverColor); ImGui.PushStyleColor(ImGuiCol.HeaderHovered, hoverColor);
foreach (var item in itemList.Items.DistinctBy(x => new foreach (var item in itemList.Items.DistinctBy(x => new
{ x.ItemId, x.Hq, Materia = x.MateriaStats?.GetHashCode() })) { x.ItemId, x.Hq, Stats = x.Stats.GetHashCode() }))
{ {
if (item is not InventoryItem) if (item is not InventoryItem)
{ {
@ -174,9 +175,9 @@ internal sealed class EquipmentBrowserWindow : LWindow
string name = item.Name; string name = item.Name;
if (item.Hq) if (item.Hq)
name += $" {SeIconChar.HighQuality.ToIconString()}"; name += $" {SeIconChar.HighQuality.ToIconString()}";
if (item is InventoryItem { MateriaStats: not null } inventoryItem) if (item is InventoryItem { Stats.MateriaCount: > 0 } inventoryItem)
name += name +=
$" {string.Join("", Enumerable.Repeat(SeIconChar.Circle.ToIconString(), inventoryItem.MateriaStats!.Count))}"; $" {string.Join("", Enumerable.Repeat(SeIconChar.Circle.ToIconString(), inventoryItem.Stats.MateriaCount))}";
if (color != null) if (color != null)
ImGui.PushStyleColor(ImGuiCol.Text, color.Value); ImGui.PushStyleColor(ImGuiCol.Text, color.Value);
@ -222,6 +223,12 @@ internal sealed class EquipmentBrowserWindow : LWindow
ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{estat}")); ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{estat}"));
else else
ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{estat} +{mstat}")); ImGui.Text(string.Create(CultureInfo.InvariantCulture, $"{estat} +{mstat}"));
if (item.Stats.IsOvercapped(substat))
{
ImGui.SameLine();
ImGui.Text(SeIconChar.Debuff.ToIconString());
}
} }
} }
} }

2
LLib

@ -1 +1 @@
Subproject commit e4bbc05ede6f6f01e7028b24614ed8cb333e909c Subproject commit 783fea977a2524dd63e717367fc026c52efe6c23