From fa4f22f6f597f09f3d81df66771b2661ba5706f3 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 23 Jul 2023 13:34:46 +0200 Subject: [PATCH] Fix some issues with Unlocked Mode and NPC stuff. --- Glamourer/Automation/AutoDesignApplier.cs | 12 +++++------- Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs | 2 +- Glamourer/Gui/Tabs/UnlocksTab/UnlockOverview.cs | 2 +- Glamourer/Services/CustomizationService.cs | 3 +-- Glamourer/Unlocks/ItemUnlockManager.cs | 10 +++++----- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Glamourer/Automation/AutoDesignApplier.cs b/Glamourer/Automation/AutoDesignApplier.cs index 2a494bc..02e7887 100644 --- a/Glamourer/Automation/AutoDesignApplier.cs +++ b/Glamourer/Automation/AutoDesignApplier.cs @@ -18,7 +18,6 @@ public class AutoDesignApplier : IDisposable { private readonly Configuration _config; private readonly AutoDesignManager _manager; - private readonly CodeService _code; private readonly StateManager _state; private readonly JobService _jobs; private readonly ActorService _actors; @@ -28,13 +27,12 @@ public class AutoDesignApplier : IDisposable private readonly AutomationChanged _event; private readonly ObjectManager _objects; - public AutoDesignApplier(Configuration config, AutoDesignManager manager, CodeService code, StateManager state, JobService jobs, + public AutoDesignApplier(Configuration config, AutoDesignManager manager, StateManager state, JobService jobs, CustomizationService customizations, ActorService actors, ItemUnlockManager itemUnlocks, CustomizeUnlockManager customizeUnlocks, AutomationChanged @event, ObjectManager objects) { _config = config; _manager = manager; - _code = code; _state = state; _jobs = jobs; _customizations = customizations; @@ -243,7 +241,7 @@ public class AutoDesignApplier : IDisposable if (equipFlags.HasFlag(flag)) { var item = design.Item(slot); - if (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _)) + if (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.Id, out _)) { if (!respectManual || state[slot, false] is not StateChanged.Source.Manual) _state.ChangeItem(state, slot, item, source); @@ -264,7 +262,7 @@ public class AutoDesignApplier : IDisposable { var item = design.Item(EquipSlot.MainHand); if (state.ModelData.Item(EquipSlot.MainHand).Type == item.Type - && (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _))) + && (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.Id, out _))) { if (!respectManual || state[EquipSlot.MainHand, false] is not StateChanged.Source.Manual) _state.ChangeItem(state, EquipSlot.MainHand, item, source); @@ -276,7 +274,7 @@ public class AutoDesignApplier : IDisposable { var item = design.Item(EquipSlot.OffHand); if (state.ModelData.Item(EquipSlot.OffHand).Type == item.Type - && (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.ItemId, out _))) + && (!_config.UnlockedItemMode || _itemUnlocks.IsUnlocked(item.Id, out _))) { if (!respectManual || state[EquipSlot.OffHand, false] is not StateChanged.Source.Manual) _state.ChangeItem(state, EquipSlot.OffHand, item, source); @@ -350,7 +348,7 @@ public class AutoDesignApplier : IDisposable var value = design.Customize[index]; if (CustomizationService.IsCustomizationValid(set, face, index, value, out var data) - && (!_config.UnlockedItemMode || _customizeUnlocks.IsUnlocked(data.Value, out _))) + && (data.HasValue && (!_config.UnlockedItemMode || _customizeUnlocks.IsUnlocked(data.Value, out _)))) { if (!respectManual || state[index] is not StateChanged.Source.Manual) _state.ChangeCustomize(state, index, value, source); diff --git a/Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs b/Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs index 3c8b73f..60d37e2 100644 --- a/Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs +++ b/Glamourer/Gui/Tabs/AutomationTab/SetPanel.cs @@ -191,7 +191,7 @@ public class SetPanel continue; var item = design.Design!.DesignData.Item(slot); - if (!_itemUnlocks.IsUnlocked(item.ItemId, out _)) + if (!_itemUnlocks.IsUnlocked(item.Id, out _)) sb.AppendLine($"{item.Name} in {slot.ToName()} slot is not unlocked. Consider obtaining it via gameplay means!"); } diff --git a/Glamourer/Gui/Tabs/UnlocksTab/UnlockOverview.cs b/Glamourer/Gui/Tabs/UnlocksTab/UnlockOverview.cs index 4a51af8..06ebe9b 100644 --- a/Glamourer/Gui/Tabs/UnlocksTab/UnlockOverview.cs +++ b/Glamourer/Gui/Tabs/UnlocksTab/UnlockOverview.cs @@ -153,7 +153,7 @@ public class UnlockOverview void DrawItem(EquipItem item) { - var unlocked = _itemUnlocks.IsUnlocked(item.ItemId, out var time); + var unlocked = _itemUnlocks.IsUnlocked(item.Id, out var time); var iconHandle = _textures.LoadIcon(item.IconId); if (!iconHandle.HasValue) return; diff --git a/Glamourer/Services/CustomizationService.cs b/Glamourer/Services/CustomizationService.cs index fcfc2f8..cfabef3 100644 --- a/Glamourer/Services/CustomizationService.cs +++ b/Glamourer/Services/CustomizationService.cs @@ -120,8 +120,7 @@ public sealed class CustomizationService : AsyncServiceWrapper Returns whether a customization value is valid for a given clan/gender set and face. [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - public static bool IsCustomizationValid(CustomizationSet set, CustomizeValue face, CustomizeIndex type, CustomizeValue value, - [NotNullWhen(true)] out CustomizeData? data) + public static bool IsCustomizationValid(CustomizationSet set, CustomizeValue face, CustomizeIndex type, CustomizeValue value, out CustomizeData? data) => set.Validate(type, value, out data, face); /// Returns whether a customization value is valid for a given clan, gender and face. diff --git a/Glamourer/Unlocks/ItemUnlockManager.cs b/Glamourer/Unlocks/ItemUnlockManager.cs index 6e2bed1..8eee4a4 100644 --- a/Glamourer/Unlocks/ItemUnlockManager.cs +++ b/Glamourer/Unlocks/ItemUnlockManager.cs @@ -201,7 +201,7 @@ public class ItemUnlockManager : ISavable, IDisposable Save(); } - public bool IsUnlocked(uint itemId, out DateTimeOffset time) + public bool IsUnlocked(ulong itemId, out DateTimeOffset time) { // Pseudo items are always unlocked. if (itemId >= _items.ItemSheet.RowCount) @@ -210,18 +210,18 @@ public class ItemUnlockManager : ISavable, IDisposable return true; } - if (_unlocked.TryGetValue(itemId, out var t)) + if (_unlocked.TryGetValue((uint) itemId, out var t)) { time = DateTimeOffset.FromUnixTimeMilliseconds(t); return true; } - if (IsGameUnlocked(itemId)) + if (IsGameUnlocked((uint) itemId)) { time = DateTimeOffset.UtcNow; - if (_unlocked.TryAdd(itemId, time.ToUnixTimeMilliseconds())) + if (_unlocked.TryAdd((uint) itemId, time.ToUnixTimeMilliseconds())) { - _event.Invoke(ObjectUnlocked.Type.Item, itemId, time); + _event.Invoke(ObjectUnlocked.Type.Item, (uint) itemId, time); Save(); }