refactor(net): converge live session state reset

This commit is contained in:
Erik 2026-07-21 12:00:48 +02:00
parent 78a9223b65
commit 4f31a5085f
35 changed files with 1460 additions and 83 deletions

View file

@ -1009,7 +1009,14 @@ public sealed class ItemInteractionController : IDisposable
};
private void OnInteractionModeChanged(InteractionModeTransition _)
=> StateChanged?.Invoke();
{
List<Exception> failures = [];
DispatchAll(StateChanged, failures);
if (failures.Count != 0)
throw new AggregateException(
"One or more item-interaction observers failed.",
failures);
}
private void OnInventoryObjectMoved(ClientObjectMove move)
{
@ -1124,17 +1131,50 @@ public sealed class ItemInteractionController : IDisposable
/// </summary>
public void ResetSession()
{
CancelPendingBackpackPlacement();
bool busyChanged = _busyCount != 0 || _pendingInventoryRequest is not null;
bool modeChanged = IsAnyTargetModeActive;
PendingBackpackPlacement? pendingPlacement = _pendingBackpackPlacement;
_pendingBackpackPlacement = null;
_busyCount = 0;
_pendingInventoryRequest = null;
_lastUseMs = long.MinValue / 2;
_consumedPrimaryClickTarget = 0u;
_consumedPrimaryClickMs = long.MinValue / 2;
_interactionState.Clear();
if (busyChanged && !modeChanged)
StateChanged?.Invoke();
List<Exception> failures = [];
try { _interactionState.ResetSession(); }
catch (Exception error) { failures.Add(error); }
if (pendingPlacement is { } pending)
DispatchAll(PendingBackpackPlacementCancelled, pending, failures);
if (failures.Count != 0)
throw new AggregateException(
"One or more item-interaction reset observers failed.",
failures);
}
private static void DispatchAll(Action? listeners, List<Exception> failures)
{
if (listeners is null)
return;
foreach (Action listener in listeners.GetInvocationList())
{
try { listener(); }
catch (Exception error) { failures.Add(error); }
}
}
private static void DispatchAll<T>(
Action<T>? listeners,
T value,
List<Exception> failures)
{
if (listeners is null)
return;
foreach (Action<T> listener in listeners.GetInvocationList())
{
try { listener(value); }
catch (Exception error) { failures.Add(error); }
}
}
private bool ConsumeUseThrottle()