diff --git a/Dalamud/Game/Inventory/GameInventoryItem.cs b/Dalamud/Game/Inventory/GameInventoryItem.cs index 085200742..e5363d92a 100644 --- a/Dalamud/Game/Inventory/GameInventoryItem.cs +++ b/Dalamud/Game/Inventory/GameInventoryItem.cs @@ -1,7 +1,9 @@ +using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Dalamud.Data; +using Dalamud.Game.Inventory.Records; using Dalamud.Utility; using FFXIVClientStructs.FFXIV.Client.Game; @@ -160,6 +162,25 @@ public unsafe struct GameInventoryItem : IEquatable } } + public IReadOnlyList MateriaEntries + { + get + { + if (ItemUtil.IsEventItem(this.BaseItemId) || this.IsMateriaUsedForDate) + return []; + + var result = new List(); + for (byte i = 0; i < this.InternalItem.GetMateriaCount(); i++) + { + var entry = new MateriaEntry(this.InternalItem.GetMateriaId(i), this.InternalItem.GetMateriaGrade(i)); + if (entry.IsValid()) + result.Add(entry); + } + + return result; + } + } + /// /// Gets the address of native inventory item in the game.
/// Can be 0 if this instance of does not point to a valid set of container type and slot.
diff --git a/Dalamud/Game/Inventory/Records/MateriaEntry.cs b/Dalamud/Game/Inventory/Records/MateriaEntry.cs new file mode 100644 index 000000000..4c7528123 --- /dev/null +++ b/Dalamud/Game/Inventory/Records/MateriaEntry.cs @@ -0,0 +1,42 @@ +using Dalamud.Data; + +using Lumina.Excel; +using Lumina.Excel.Sheets; + +namespace Dalamud.Game.Inventory.Records; + +/// +/// A record to hold easy information about a given piece of Materia. +/// +public record MateriaEntry +{ + /// + /// Initializes a new instance of the class. + /// + /// The ID of the materia. + /// The grade of the materia. + public MateriaEntry(ushort typeId, byte gradeValue) + { + this.Type = LuminaUtils.CreateRef(typeId); + this.Grade = LuminaUtils.CreateRef(gradeValue); + } + + /// + /// Gets the Lumina row for this Materia. + /// + public RowRef Type { get; } + + /// + /// Gets the Lumina row for this Materia's grade. + /// + public RowRef Grade { get; } + + /// + /// Checks if this MateriaEntry is valid. + /// + /// True if valid, false otherwise. + internal bool IsValid() + { + return this.Type.IsValid && this.Grade.IsValid; + } +}