refactor(net): own session wiring subscriptions
This commit is contained in:
parent
88fe1db37b
commit
7d452aa6a2
8 changed files with 577 additions and 61 deletions
|
|
@ -12,13 +12,15 @@ public static class CombatStateWiring
|
|||
{
|
||||
public const uint CombatModePropertyId = 40u;
|
||||
|
||||
public static void Wire(WorldSession session, CombatState combat)
|
||||
public static IDisposable Wire(WorldSession session, CombatState combat)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(session);
|
||||
ArgumentNullException.ThrowIfNull(combat);
|
||||
|
||||
session.PlayerIntPropertyUpdated += update =>
|
||||
Action<WorldSession.PlayerIntPropertyUpdate> handler = update =>
|
||||
ApplyPlayerIntProperty(combat, update.Property, update.Value);
|
||||
session.PlayerIntPropertyUpdated += handler;
|
||||
return new EventSubscription(session, handler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -44,4 +46,15 @@ public static class CombatStateWiring
|
|||
combat.SetCombatMode(mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
private sealed class EventSubscription(
|
||||
WorldSession session,
|
||||
Action<WorldSession.PlayerIntPropertyUpdate> handler) : IDisposable
|
||||
{
|
||||
private Action? _unsubscribe =
|
||||
() => session.PlayerIntPropertyUpdated -= handler;
|
||||
|
||||
public void Dispose() =>
|
||||
Interlocked.Exchange(ref _unsubscribe, null)?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue