refactor(interaction): add selection interaction owner
Introduce a tested controller for selection mutations, target-mode interception, outbound ordering, Use/PickUp lifetime, and live-incarnation cleanup, plus narrow movement and WorldSession transport adapters.
This commit is contained in:
parent
e74f2ca99a
commit
fa8d5232cc
5 changed files with 754 additions and 1 deletions
62
src/AcDream.App/Interaction/SelectionInteractionTransport.cs
Normal file
62
src/AcDream.App/Interaction/SelectionInteractionTransport.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using AcDream.Core.Net;
|
||||
using AcDream.Core.Net.Messages;
|
||||
|
||||
namespace AcDream.App.Interaction;
|
||||
|
||||
internal interface ISelectionInteractionTransport
|
||||
{
|
||||
bool IsInWorld { get; }
|
||||
bool TrySendUse(uint serverGuid, out uint sequence);
|
||||
bool TrySendPickup(
|
||||
uint itemGuid,
|
||||
uint destinationContainerId,
|
||||
int placement,
|
||||
out uint sequence);
|
||||
}
|
||||
|
||||
internal sealed class WorldSessionSelectionInteractionTransport(
|
||||
Func<WorldSession?> session)
|
||||
: ISelectionInteractionTransport
|
||||
{
|
||||
private readonly Func<WorldSession?> _session = session
|
||||
?? throw new ArgumentNullException(nameof(session));
|
||||
|
||||
public bool IsInWorld =>
|
||||
_session()?.CurrentState == WorldSession.State.InWorld;
|
||||
|
||||
public bool TrySendUse(uint serverGuid, out uint sequence)
|
||||
{
|
||||
WorldSession? live = _session();
|
||||
if (live?.CurrentState != WorldSession.State.InWorld)
|
||||
{
|
||||
sequence = 0u;
|
||||
return false;
|
||||
}
|
||||
|
||||
sequence = live.NextGameActionSequence();
|
||||
live.SendGameAction(InteractRequests.BuildUse(sequence, serverGuid));
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TrySendPickup(
|
||||
uint itemGuid,
|
||||
uint destinationContainerId,
|
||||
int placement,
|
||||
out uint sequence)
|
||||
{
|
||||
WorldSession? live = _session();
|
||||
if (live?.CurrentState != WorldSession.State.InWorld)
|
||||
{
|
||||
sequence = 0u;
|
||||
return false;
|
||||
}
|
||||
|
||||
sequence = live.NextGameActionSequence();
|
||||
live.SendGameAction(InteractRequests.BuildPickUp(
|
||||
sequence,
|
||||
itemGuid,
|
||||
destinationContainerId,
|
||||
placement));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue