diff --git a/Glamourer/Services/ItemManager.cs b/Glamourer/Services/ItemManager.cs index 5741e75..59e8228 100644 --- a/Glamourer/Services/ItemManager.cs +++ b/Glamourer/Services/ItemManager.cs @@ -100,6 +100,9 @@ public class ItemManager : IDisposable return item; } + public EquipItem Resolve(FullEquipType type, CustomItemId id) + => id.IsItem ? Resolve(type, id.Item) : EquipItem.FromId(id); + public EquipItem Identify(EquipSlot slot, SetId id, Variant variant) { slot = slot.ToSlot(); diff --git a/Glamourer/State/WeaponState.cs b/Glamourer/State/WeaponState.cs new file mode 100644 index 0000000..a06ff79 --- /dev/null +++ b/Glamourer/State/WeaponState.cs @@ -0,0 +1,65 @@ +using Glamourer.Events; +using Glamourer.Services; +using Penumbra.GameData.Enums; +using Penumbra.GameData.Structs; + +namespace Glamourer.State; + +/// Currently unused. +public unsafe struct WeaponState +{ + private fixed ulong _weapons[FullEquipTypeExtensions.NumWeaponTypes]; + private fixed byte _sources[FullEquipTypeExtensions.NumWeaponTypes]; + + public CustomItemId? this[FullEquipType type] + { + get + { + if (!ToIndex(type, out var idx)) + return null; + + var weapon = _weapons[idx]; + if (weapon == 0) + return null; + + return new CustomItemId(weapon); + } + } + + public EquipItem Get(ItemManager items, EquipItem value) + { + var id = this[value.Type]; + if (id == null) + return value; + + var item = items.Resolve(value.Type, id.Value); + return item.Type != value.Type ? value : item; + } + + public void Set(FullEquipType type, EquipItem value, StateChanged.Source source) + { + if (!ToIndex(type, out var idx)) + return; + + _weapons[idx] = value.Id.Id; + _sources[idx] = (byte)source; + } + + public void RemoveFixedDesignSources() + { + for (var i = 0; i < FullEquipTypeExtensions.NumWeaponTypes; ++i) + { + if (_sources[i] is (byte) StateChanged.Source.Fixed) + _sources[i] = (byte) StateChanged.Source.Manual; + } + } + + private static bool ToIndex(FullEquipType type, out int index) + { + index = ToIndex(type); + return index is >= 0 and < FullEquipTypeExtensions.NumWeaponTypes; + } + + private static int ToIndex(FullEquipType type) + => (int)type - FullEquipTypeExtensions.WeaponTypesOffset; +} diff --git a/Penumbra.GameData b/Penumbra.GameData index 54b56ad..0c0554e 160000 --- a/Penumbra.GameData +++ b/Penumbra.GameData @@ -1 +1 @@ -Subproject commit 54b56ada57529221d3fc812193ffe65c424c1521 +Subproject commit 0c0554e7c482fac35110c3375e890540ee31abb3