fix(interaction): close selection lifecycle review gaps
Bind queued actions and pending inventory requests to exact live incarnations, separate optimistic placement from authoritative responses, and serialize retail-style inventory ownership across UI surfaces. Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
parent
d2bb5af453
commit
5acc3f01cf
23 changed files with 2635 additions and 168 deletions
|
|
@ -0,0 +1,106 @@
|
|||
using System.Numerics;
|
||||
using AcDream.App.Input;
|
||||
using AcDream.App.Interaction;
|
||||
using AcDream.Core.Physics;
|
||||
using AcDream.Core.Physics.Motion;
|
||||
using AcDream.Core.World;
|
||||
|
||||
namespace AcDream.App.Tests.Interaction;
|
||||
|
||||
public sealed class PlayerInteractionMovementSinkTests
|
||||
{
|
||||
private const uint Player = 0x5000_0001u;
|
||||
private const uint Target = 0x7000_0001u;
|
||||
private const uint Cell = 0x0101_0001u;
|
||||
|
||||
[Fact]
|
||||
public void MissingPlayerDoesNotArmTheIntent()
|
||||
{
|
||||
var sink = new PlayerInteractionMovementSink(() => null);
|
||||
bool armed = false;
|
||||
|
||||
Assert.False(sink.BeginApproach(Approach(closeRange: true), () => armed = true));
|
||||
Assert.False(armed);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, MovementType.TurnToObject)]
|
||||
[InlineData(false, MovementType.MoveToObject)]
|
||||
public void ProductionSinkCancelsThenArmsAndInstallsExactMovement(
|
||||
bool closeRange,
|
||||
MovementType expectedType)
|
||||
{
|
||||
var controller = new PlayerMovementController(new PhysicsEngine());
|
||||
controller.SetPosition(Vector3.Zero, Cell);
|
||||
bool nonAutonomousAtTargetInstall = false;
|
||||
int cancellations = 0;
|
||||
double targetQuantum = 0d;
|
||||
var moveTo = new MoveToManager(
|
||||
controller.Motion,
|
||||
stopCompletely: () => { },
|
||||
getPosition: () => controller.CellPosition,
|
||||
getHeading: () => MoveToMath.HeadingFromYaw(controller.Yaw),
|
||||
setHeading: (heading, _) => controller.Yaw = MoveToMath.YawFromHeading(heading),
|
||||
getOwnRadius: () => 0.4f,
|
||||
getOwnHeight: () => 1.8f,
|
||||
contact: () => true,
|
||||
isInterpolating: () => false,
|
||||
getVelocity: () => Vector3.Zero,
|
||||
getSelfId: () => Player,
|
||||
setTarget: (_, topLevelId, radius, quantum) =>
|
||||
{
|
||||
Assert.Equal(Target, topLevelId);
|
||||
Assert.Equal(0.5f, radius);
|
||||
targetQuantum = quantum;
|
||||
nonAutonomousAtTargetInstall =
|
||||
controller.Motion.PhysicsObj?.LastMoveWasAutonomous == false;
|
||||
},
|
||||
clearTarget: () => { },
|
||||
getTargetQuantum: () => targetQuantum,
|
||||
setTargetQuantum: quantum => targetQuantum = quantum);
|
||||
moveTo.MoveToCancelled = _ => cancellations++;
|
||||
controller.MoveTo = moveTo;
|
||||
|
||||
// Prove the sink's explicit cancel occurs before its arm callback.
|
||||
moveTo.MoveToPosition(
|
||||
new Position(Cell, new Vector3(2f, 0f, 0f), Quaternion.Identity),
|
||||
new MovementParameters { UseSpheres = false });
|
||||
bool armedAfterCancellation = false;
|
||||
var sink = new PlayerInteractionMovementSink(() => controller);
|
||||
|
||||
Assert.True(sink.BeginApproach(
|
||||
Approach(closeRange),
|
||||
() => armedAfterCancellation = cancellations == 1 && !moveTo.IsMovingTo()));
|
||||
|
||||
Assert.True(armedAfterCancellation);
|
||||
Assert.True(nonAutonomousAtTargetInstall);
|
||||
Assert.Equal(expectedType, moveTo.MovementTypeState);
|
||||
Assert.Equal(Target, moveTo.SoughtObjectId);
|
||||
Assert.Equal(Target, moveTo.TopLevelObjectId);
|
||||
Assert.Equal(closeRange ? 0f : 0.75f, moveTo.SoughtObjectRadius);
|
||||
Assert.Equal(closeRange ? 0f : 2.25f, moveTo.SoughtObjectHeight);
|
||||
Assert.Equal(0.6f, moveTo.Params.DistanceToObject);
|
||||
Assert.Equal(!closeRange, moveTo.Params.CanCharge);
|
||||
}
|
||||
|
||||
private static InteractionApproach Approach(bool closeRange)
|
||||
{
|
||||
var entity = new WorldEntity
|
||||
{
|
||||
Id = 101u,
|
||||
ServerGuid = Target,
|
||||
SourceGfxObjOrSetupId = 0x0200_0001u,
|
||||
Position = new Vector3(5f, 0f, 0f),
|
||||
Rotation = Quaternion.Identity,
|
||||
MeshRefs = [],
|
||||
};
|
||||
return new InteractionApproach(
|
||||
new WorldInteractionTarget(Target, entity.Id, entity),
|
||||
new PlayerInteractionPose(Cell, Vector3.Zero),
|
||||
UseRadius: 0.6f,
|
||||
IsCloseRange: closeRange,
|
||||
CanCharge: !closeRange,
|
||||
TargetRadius: 0.75f,
|
||||
TargetHeight: 2.25f);
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,8 @@ public sealed class SelectionInteractionControllerTests
|
|||
public bool Hostile { get; set; }
|
||||
public bool Useable { get; set; } = true;
|
||||
public bool Pickupable { get; set; } = true;
|
||||
public bool CaptureIdentity { get; set; } = true;
|
||||
public uint LocalEntityId { get; set; } = 101u;
|
||||
public ClosestCombatTarget? Closest { get; set; }
|
||||
public InteractionApproach? Approach { get; set; }
|
||||
public List<string> Events { get; } = new();
|
||||
|
|
@ -41,6 +43,11 @@ public sealed class SelectionInteractionControllerTests
|
|||
=> PickAtCursor(includeSelf);
|
||||
|
||||
public void BeginLightingPulse(uint serverGuid) => Events.Add("pulse");
|
||||
public bool TryCaptureIdentity(uint serverGuid, out uint localEntityId)
|
||||
{
|
||||
localEntityId = LocalEntityId;
|
||||
return CaptureIdentity;
|
||||
}
|
||||
public bool IsCurrent(uint serverGuid, uint localEntityId) => Current;
|
||||
public string Describe(uint serverGuid) => $"Target {serverGuid:X8}";
|
||||
public bool IsCreature(uint serverGuid) => Creature;
|
||||
|
|
@ -100,9 +107,15 @@ public sealed class SelectionInteractionControllerTests
|
|||
private sealed class Movement : IPlayerInteractionMovementSink
|
||||
{
|
||||
public List<InteractionApproach> Approaches { get; } = new();
|
||||
public bool BeginApproach(InteractionApproach approach)
|
||||
public bool Starts { get; set; } = true;
|
||||
public Action? AfterArm { get; set; }
|
||||
public bool BeginApproach(InteractionApproach approach, Action? armAfterCancel = null)
|
||||
{
|
||||
Approaches.Add(approach);
|
||||
if (!Starts)
|
||||
return false;
|
||||
armAfterCancel?.Invoke();
|
||||
AfterArm?.Invoke();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -116,6 +129,8 @@ public sealed class SelectionInteractionControllerTests
|
|||
public readonly ClientObjectTable Objects = new();
|
||||
public readonly List<string> Toasts = new();
|
||||
public readonly List<uint> Examines = new();
|
||||
public readonly List<PendingBackpackPlacement> PendingPlacements = new();
|
||||
public readonly List<PendingBackpackPlacement> CancelledPlacements = new();
|
||||
public readonly ItemInteractionController Items;
|
||||
public readonly SelectionInteractionController Controller;
|
||||
|
||||
|
|
@ -127,6 +142,12 @@ public sealed class SelectionInteractionControllerTests
|
|||
ObjectId = Player,
|
||||
Type = ItemType.Creature,
|
||||
});
|
||||
Objects.AddOrUpdate(new ClientObject
|
||||
{
|
||||
ObjectId = Target,
|
||||
Name = "Target",
|
||||
Type = ItemType.Misc,
|
||||
});
|
||||
Items = new ItemInteractionController(
|
||||
Objects,
|
||||
() => Player,
|
||||
|
|
@ -148,6 +169,8 @@ public sealed class SelectionInteractionControllerTests
|
|||
Transport,
|
||||
Movement,
|
||||
Toasts.Add);
|
||||
Items.PendingBackpackPlacementRequested += PendingPlacements.Add;
|
||||
Items.PendingBackpackPlacementCancelled += CancelledPlacements.Add;
|
||||
}
|
||||
|
||||
public void SetApproach(bool closeRange, uint localEntityId = 101u)
|
||||
|
|
@ -270,12 +293,14 @@ public sealed class SelectionInteractionControllerTests
|
|||
h.Selection.Select(Target, SelectionChangeSource.World);
|
||||
h.Controller.HandleInputAction(InputAction.SelectionPickUp);
|
||||
h.Controller.SendUse(Target);
|
||||
h.Items.InteractionState.EnterExamine();
|
||||
|
||||
h.Controller.ResetSession();
|
||||
h.Controller.DrainOutbound();
|
||||
h.Controller.OnNaturalMoveToComplete();
|
||||
|
||||
Assert.Null(h.Selection.SelectedObjectId);
|
||||
Assert.False(h.Items.IsAnyTargetModeActive);
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
Assert.Empty(h.Transport.Uses);
|
||||
}
|
||||
|
|
@ -305,6 +330,216 @@ public sealed class SelectionInteractionControllerTests
|
|||
Assert.Empty(h.Transport.Uses);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SynchronousNaturalCompletionObservesTheArmedCloseAction()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.SetApproach(closeRange: true);
|
||||
h.Movement.AfterArm = h.Controller.OnNaturalMoveToComplete;
|
||||
|
||||
h.Controller.SendUse(Target);
|
||||
h.Controller.OnNaturalMoveToComplete();
|
||||
|
||||
Assert.Equal(new[] { Target }, h.Transport.Uses);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SynchronousResetCannotResurrectTheCloseAction()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.SetApproach(closeRange: true);
|
||||
h.Movement.AfterArm = h.Controller.ResetSession;
|
||||
|
||||
h.Controller.SendUse(Target);
|
||||
h.Controller.OnNaturalMoveToComplete();
|
||||
|
||||
Assert.Empty(h.Transport.Uses);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CancelledClosePickupWithdrawsPresentationAndNeverFiresLater()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.SetApproach(closeRange: true);
|
||||
|
||||
Assert.True(h.Items.PlaceWorldItemInBackpack(Target));
|
||||
Assert.Single(h.PendingPlacements);
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
|
||||
h.Controller.OnMoveToCancelled(WeenieError.ActionCancelled);
|
||||
h.Controller.OnNaturalMoveToComplete();
|
||||
|
||||
Assert.Equal(new[] { Target }, h.CancelledPlacements.Select(p => p.ItemId));
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ErrorCompletionClearsCloseActionBeforeALaterSuccess()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.SetApproach(closeRange: true);
|
||||
h.Controller.SendUse(Target);
|
||||
|
||||
h.Controller.OnMoveToCancelled(WeenieError.NoObject);
|
||||
h.Controller.OnNaturalMoveToComplete();
|
||||
|
||||
Assert.Empty(h.Transport.Uses);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FailedClosePickupStartWithdrawsPresentation()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.SetApproach(closeRange: true);
|
||||
h.Movement.Starts = false;
|
||||
|
||||
Assert.True(h.Items.PlaceWorldItemInBackpack(Target));
|
||||
|
||||
Assert.Single(h.PendingPlacements);
|
||||
Assert.Equal(new[] { Target }, h.CancelledPlacements.Select(p => p.ItemId));
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void InvalidKeyboardPickupNeverPublishesAWaitingSlot(bool creature)
|
||||
{
|
||||
var h = new Harness();
|
||||
h.Query.Creature = creature;
|
||||
h.Query.Pickupable = false;
|
||||
h.Selection.Select(Target, SelectionChangeSource.World);
|
||||
|
||||
h.Controller.HandleInputAction(InputAction.SelectionPickUp);
|
||||
h.Controller.DrainOutbound();
|
||||
|
||||
Assert.Empty(h.PendingPlacements);
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(InputAction.SelectDblLeft)]
|
||||
[InlineData(InputAction.UseSelected)]
|
||||
[InlineData(InputAction.SelectionPickUp)]
|
||||
public void QueuedWorldActionCannotCrossAnIncarnationBoundary(InputAction action)
|
||||
{
|
||||
var h = new Harness();
|
||||
h.Query.Picked = Target;
|
||||
h.SetApproach(closeRange: false);
|
||||
h.Selection.Select(Target, SelectionChangeSource.World);
|
||||
|
||||
h.Controller.HandleInputAction(action);
|
||||
h.Query.Current = false;
|
||||
h.Controller.DrainOutbound();
|
||||
|
||||
Assert.Empty(h.Transport.Uses);
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
Assert.Empty(h.PendingPlacements);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DragReleasePulsesTheDropTargetWithoutChangingSelection()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.Query.Picked = Target;
|
||||
const uint item = 0x7000_0002u;
|
||||
h.Objects.AddOrUpdate(new ClientObject
|
||||
{
|
||||
ObjectId = item,
|
||||
Name = "Dragged",
|
||||
Type = ItemType.Misc,
|
||||
});
|
||||
var payload = new ItemDragPayload(
|
||||
item,
|
||||
ItemDragSource.Inventory,
|
||||
SourceSlot: 0,
|
||||
new UiItemSlot());
|
||||
|
||||
h.Controller.PlaceDraggedItem(payload, 10f, 20f);
|
||||
|
||||
Assert.Contains("pulse", h.Query.Events);
|
||||
Assert.Null(h.Selection.SelectedObjectId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RejectedTargetModeClickConsumesTheFollowingDoubleClick()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.Query.Picked = Target;
|
||||
h.Objects.Remove(Target);
|
||||
h.Items.InteractionState.EnterUse();
|
||||
|
||||
h.Controller.HandleInputAction(InputAction.SelectLeft);
|
||||
h.Controller.HandleInputAction(InputAction.SelectDblLeft);
|
||||
h.Controller.DrainOutbound();
|
||||
|
||||
Assert.Null(h.Selection.SelectedObjectId);
|
||||
Assert.Empty(h.Transport.Uses);
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TransportLossAtClosePickupCompletionWithdrawsPresentation()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.SetApproach(closeRange: true);
|
||||
Assert.True(h.Items.PlaceWorldItemInBackpack(Target));
|
||||
|
||||
h.Transport.IsInWorld = false;
|
||||
h.Controller.OnNaturalMoveToComplete();
|
||||
|
||||
Assert.Equal(new[] { Target }, h.CancelledPlacements.Select(p => p.ItemId));
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RepeatedPickupKeepsTheOriginalReservationAndDeferredAction()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.SetApproach(closeRange: true);
|
||||
Assert.True(h.Items.PlaceWorldItemInBackpack(Target));
|
||||
h.Selection.Select(Target, SelectionChangeSource.World);
|
||||
|
||||
h.Controller.HandleInputAction(InputAction.SelectionPickUp);
|
||||
h.Controller.DrainOutbound();
|
||||
|
||||
Assert.Single(h.PendingPlacements);
|
||||
Assert.Empty(h.CancelledPlacements);
|
||||
|
||||
h.Controller.OnNaturalMoveToComplete();
|
||||
Assert.Equal(new[] { (Target, Player, 0) }, h.Transport.Pickups);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithdrawnPickupReservationInvalidatesDeferredWireAction()
|
||||
{
|
||||
const uint replacement = 0x7000_0002u;
|
||||
var h = new Harness();
|
||||
h.SetApproach(closeRange: true);
|
||||
h.Objects.AddOrUpdate(new ClientObject
|
||||
{
|
||||
ObjectId = replacement,
|
||||
Name = "Replacement loot",
|
||||
Type = ItemType.Misc,
|
||||
});
|
||||
|
||||
Assert.True(h.Items.PlaceWorldItemInBackpack(Target));
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
PendingBackpackPlacement original = Assert.Single(h.PendingPlacements);
|
||||
h.Items.CancelPendingBackpackPlacement(Target, original.Token);
|
||||
Assert.True(h.Items.TryBeginPendingBackpackPlacement(
|
||||
replacement,
|
||||
Player,
|
||||
placement: 0,
|
||||
out _));
|
||||
|
||||
h.Controller.OnNaturalMoveToComplete();
|
||||
|
||||
Assert.Empty(h.Transport.Pickups);
|
||||
Assert.True(h.Items.TryGetPendingBackpackPlacement(replacement, out _));
|
||||
Assert.False(h.Items.TryGetPendingBackpackPlacement(Target, out _));
|
||||
}
|
||||
|
||||
private static WorldSession.EntitySpawn Spawn(uint guid, ushort instance)
|
||||
=> new(
|
||||
guid,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ public sealed class WorldSelectionQueryTests
|
|||
public RetailSelectionMesh? Resolve(uint gfxObjId) => mesh;
|
||||
}
|
||||
|
||||
private sealed record Animation(WorldEntity Entity, uint CurrentMotion)
|
||||
: ILiveEntityAnimationRuntime;
|
||||
|
||||
private sealed class Harness
|
||||
{
|
||||
public readonly ClientObjectTable Objects = new();
|
||||
|
|
@ -131,6 +134,41 @@ public sealed class WorldSelectionQueryTests
|
|||
Assert.Null(h.Query.PickAtCursor(includeSelf: false));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
public void PickRejectsPublishedPartAfterVisibilityLifetimeEnds(int transition)
|
||||
{
|
||||
var h = new Harness();
|
||||
WorldEntity target = h.Add(Target, new Vector3(0f, 0f, -5f), ItemType.Misc);
|
||||
h.Publish(target);
|
||||
Assert.Equal(Target, h.Query.PickAtCursor(includeSelf: false));
|
||||
|
||||
switch (transition)
|
||||
{
|
||||
case 0:
|
||||
Assert.True(h.Runtime.TryApplyState(
|
||||
new SetState.Parsed(
|
||||
Target,
|
||||
(uint)(PhysicsStateFlags.ReportCollisions | PhysicsStateFlags.Hidden),
|
||||
InstanceSequence: 1,
|
||||
StateSequence: 2),
|
||||
out _));
|
||||
break;
|
||||
case 1:
|
||||
Assert.True(h.Runtime.WithdrawLiveEntityProjection(Target));
|
||||
break;
|
||||
default:
|
||||
Assert.True(h.Runtime.UnregisterLiveEntity(
|
||||
new DeleteObject.Parsed(Target, 1),
|
||||
isLocalPlayer: false));
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.Null(h.Query.PickAtCursor(includeSelf: false));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClosestTargetIncludesOnlyVisibleLivingHostileMonsters()
|
||||
{
|
||||
|
|
@ -150,6 +188,43 @@ public sealed class WorldSelectionQueryTests
|
|||
new Vector3(1f, 0f, 0f),
|
||||
ItemType.Misc,
|
||||
SelectedObjectHealthPolicy.BfAttackable);
|
||||
h.Add(
|
||||
0x7000_0013u,
|
||||
new Vector3(3f, 0f, 0f),
|
||||
ItemType.Creature,
|
||||
SelectedObjectHealthPolicy.BfAttackable | SelectedObjectHealthPolicy.BfPlayer);
|
||||
WorldEntity pet = h.Add(
|
||||
0x7000_0014u,
|
||||
new Vector3(4f, 0f, 0f),
|
||||
ItemType.Creature,
|
||||
SelectedObjectHealthPolicy.BfAttackable);
|
||||
h.Objects.Get(pet.ServerGuid)!.PetOwnerId = Player;
|
||||
WorldEntity dead = h.Add(
|
||||
0x7000_0015u,
|
||||
new Vector3(5f, 0f, 0f),
|
||||
ItemType.Creature,
|
||||
SelectedObjectHealthPolicy.BfAttackable);
|
||||
h.Runtime.SetAnimationRuntime(
|
||||
dead.ServerGuid,
|
||||
new Animation(dead, MotionCommand.Dead));
|
||||
WorldEntity hidden = h.Add(
|
||||
0x7000_0016u,
|
||||
new Vector3(6f, 0f, 0f),
|
||||
ItemType.Creature,
|
||||
SelectedObjectHealthPolicy.BfAttackable);
|
||||
Assert.True(h.Runtime.TryApplyState(
|
||||
new SetState.Parsed(
|
||||
hidden.ServerGuid,
|
||||
(uint)(PhysicsStateFlags.ReportCollisions | PhysicsStateFlags.Hidden),
|
||||
InstanceSequence: 1,
|
||||
StateSequence: 2),
|
||||
out _));
|
||||
WorldEntity pending = h.Add(
|
||||
0x7000_0017u,
|
||||
new Vector3(7f, 0f, 0f),
|
||||
ItemType.Creature,
|
||||
SelectedObjectHealthPolicy.BfAttackable);
|
||||
Assert.True(h.Runtime.WithdrawLiveEntityProjection(pending.ServerGuid));
|
||||
|
||||
ClosestCombatTarget? closest = h.Query.FindClosestHostileMonster();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue