Fix some issues with Unlocked Mode and NPC stuff.

This commit is contained in:
Ottermandias 2023-07-23 13:34:46 +02:00
parent 4e2b719122
commit fa4f22f6f5
5 changed files with 13 additions and 16 deletions

View file

@ -18,7 +18,6 @@ public class AutoDesignApplier : IDisposable
{ {
private readonly Configuration _config; private readonly Configuration _config;
private readonly AutoDesignManager _manager; private readonly AutoDesignManager _manager;
private readonly CodeService _code;
private readonly StateManager _state; private readonly StateManager _state;
private readonly JobService _jobs; private readonly JobService _jobs;
private readonly ActorService _actors; private readonly ActorService _actors;
@ -28,13 +27,12 @@ public class AutoDesignApplier : IDisposable
private readonly AutomationChanged _event; private readonly AutomationChanged _event;
private readonly ObjectManager _objects; 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, CustomizationService customizations, ActorService actors, ItemUnlockManager itemUnlocks, CustomizeUnlockManager customizeUnlocks,
AutomationChanged @event, ObjectManager objects) AutomationChanged @event, ObjectManager objects)
{ {
_config = config; _config = config;
_manager = manager; _manager = manager;
_code = code;
_state = state; _state = state;
_jobs = jobs; _jobs = jobs;
_customizations = customizations; _customizations = customizations;
@ -243,7 +241,7 @@ public class AutoDesignApplier : IDisposable
if (equipFlags.HasFlag(flag)) if (equipFlags.HasFlag(flag))
{ {
var item = design.Item(slot); 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) if (!respectManual || state[slot, false] is not StateChanged.Source.Manual)
_state.ChangeItem(state, slot, item, source); _state.ChangeItem(state, slot, item, source);
@ -264,7 +262,7 @@ public class AutoDesignApplier : IDisposable
{ {
var item = design.Item(EquipSlot.MainHand); var item = design.Item(EquipSlot.MainHand);
if (state.ModelData.Item(EquipSlot.MainHand).Type == item.Type 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) if (!respectManual || state[EquipSlot.MainHand, false] is not StateChanged.Source.Manual)
_state.ChangeItem(state, EquipSlot.MainHand, item, source); _state.ChangeItem(state, EquipSlot.MainHand, item, source);
@ -276,7 +274,7 @@ public class AutoDesignApplier : IDisposable
{ {
var item = design.Item(EquipSlot.OffHand); var item = design.Item(EquipSlot.OffHand);
if (state.ModelData.Item(EquipSlot.OffHand).Type == item.Type 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) if (!respectManual || state[EquipSlot.OffHand, false] is not StateChanged.Source.Manual)
_state.ChangeItem(state, EquipSlot.OffHand, item, source); _state.ChangeItem(state, EquipSlot.OffHand, item, source);
@ -350,7 +348,7 @@ public class AutoDesignApplier : IDisposable
var value = design.Customize[index]; var value = design.Customize[index];
if (CustomizationService.IsCustomizationValid(set, face, index, value, out var data) 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) if (!respectManual || state[index] is not StateChanged.Source.Manual)
_state.ChangeCustomize(state, index, value, source); _state.ChangeCustomize(state, index, value, source);

View file

@ -191,7 +191,7 @@ public class SetPanel
continue; continue;
var item = design.Design!.DesignData.Item(slot); 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!"); sb.AppendLine($"{item.Name} in {slot.ToName()} slot is not unlocked. Consider obtaining it via gameplay means!");
} }

View file

@ -153,7 +153,7 @@ public class UnlockOverview
void DrawItem(EquipItem item) 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); var iconHandle = _textures.LoadIcon(item.IconId);
if (!iconHandle.HasValue) if (!iconHandle.HasValue)
return; return;

View file

@ -120,8 +120,7 @@ public sealed class CustomizationService : AsyncServiceWrapper<ICustomizationMan
/// <summary> Returns whether a customization value is valid for a given clan/gender set and face. </summary> /// <summary> Returns whether a customization value is valid for a given clan/gender set and face. </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool IsCustomizationValid(CustomizationSet set, CustomizeValue face, CustomizeIndex type, CustomizeValue value, public static bool IsCustomizationValid(CustomizationSet set, CustomizeValue face, CustomizeIndex type, CustomizeValue value, out CustomizeData? data)
[NotNullWhen(true)] out CustomizeData? data)
=> set.Validate(type, value, out data, face); => set.Validate(type, value, out data, face);
/// <summary> Returns whether a customization value is valid for a given clan, gender and face. </summary> /// <summary> Returns whether a customization value is valid for a given clan, gender and face. </summary>

View file

@ -201,7 +201,7 @@ public class ItemUnlockManager : ISavable, IDisposable
Save(); Save();
} }
public bool IsUnlocked(uint itemId, out DateTimeOffset time) public bool IsUnlocked(ulong itemId, out DateTimeOffset time)
{ {
// Pseudo items are always unlocked. // Pseudo items are always unlocked.
if (itemId >= _items.ItemSheet.RowCount) if (itemId >= _items.ItemSheet.RowCount)
@ -210,18 +210,18 @@ public class ItemUnlockManager : ISavable, IDisposable
return true; return true;
} }
if (_unlocked.TryGetValue(itemId, out var t)) if (_unlocked.TryGetValue((uint) itemId, out var t))
{ {
time = DateTimeOffset.FromUnixTimeMilliseconds(t); time = DateTimeOffset.FromUnixTimeMilliseconds(t);
return true; return true;
} }
if (IsGameUnlocked(itemId)) if (IsGameUnlocked((uint) itemId))
{ {
time = DateTimeOffset.UtcNow; 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(); Save();
} }