fix(combat): escape occupied login positions

Port retail's radius-aware placement ring so a relogging player is seated beside creatures occupying the saved location, and register the local body in the shared resolved-shadow pipeline. Route new forward movement and jump through AbortAutomaticAttack so repeat combat cancels immediately on movement.

Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-12 22:20:17 +02:00
parent e671b8a5c4
commit 00fe993f6f
11 changed files with 643 additions and 16 deletions

View file

@ -858,6 +858,9 @@ public sealed class GameWindow : IDisposable
private uint _playerServerGuid;
private uint? _playerMotionTableId; // server-sent MotionTable override for the player's character
private MovementTruthOutbound? _lastMovementTruthOutbound;
private (System.Numerics.Vector3 Position,
System.Numerics.Quaternion Orientation,
uint CellId)? _lastLocalPlayerShadow;
private readonly record struct MovementTruthOutbound(
string Kind,
@ -1988,6 +1991,7 @@ public sealed class GameWindow : IDisposable
Combat,
CanStartLiveCombatAttack,
SendLiveCombatAttack,
sendCancelAttack: () => _liveSession?.SendCancelAttack(),
isDualWield: () => _playerController?.Motion.InterpretedState.CurrentStyle
== AcDream.Core.Combat.CombatInputPlanner.DualWieldCombatStyle,
playerReadyForAttack: IsPlayerReadyForCombatAttack,
@ -3594,17 +3598,16 @@ public sealed class GameWindow : IDisposable
_lastSpawnByGuid[spawn.Guid] = spawn;
_equippedChildRenderer?.OnSpawn(spawn);
// Commit B 2026-04-29 — live-entity collision registration. The
// local player is the simulator (its PhysicsBody is the source of
// truth for our own movement); only remotes register as targets.
// Commit B 2026-04-29 — live-entity collision registration.
// The local player is the simulator (its PhysicsBody is the source of
// truth for our own movement), but retail still registers its resolved
// CPhysicsObj as a collision target for remote creatures. The player's
// own transition skips this entry by LocalEntityId / OBJECTINFO::object.
// Phantom-Setup entities (no CylSpheres / no Spheres / no Radius)
// are deliberately skipped — retail FUN's `FindObjCollisions`
// falls through to OK_TS for any object with no collision
// geometry (acclient_2013_pseudo_c.txt:276917,276987).
if (spawn.Guid != _playerServerGuid)
{
RegisterLiveEntityCollision(entity, setup, spawn, origin);
}
RegisterLiveEntityCollision(entity, setup, spawn, origin);
// Phase B.2: capture the server-sent MotionTableId for our own
// character so UpdatePlayerAnimation can pass it to GetIdleCycle.
@ -4162,6 +4165,36 @@ public sealed class GameWindow : IDisposable
}
}
private void SyncLocalPlayerShadow(
AcDream.Core.World.WorldEntity playerEntity,
uint cellId,
bool force = false)
{
if (!force
&& _lastLocalPlayerShadow is { } last
&& last.CellId == cellId
&& System.Numerics.Vector3.DistanceSquared(
last.Position, playerEntity.Position) <= 1e-4f
&& MathF.Abs(System.Numerics.Quaternion.Dot(
last.Orientation, playerEntity.Rotation)) >= 0.99999f)
{
return;
}
AcDream.App.Physics.ShadowPositionSynchronizer.Sync(
_physicsEngine.ShadowObjects,
playerEntity.Id,
playerEntity.Position,
playerEntity.Rotation,
cellId,
_liveCenterX,
_liveCenterY);
_lastLocalPlayerShadow = (
playerEntity.Position,
playerEntity.Rotation,
cellId);
}
/// <summary>
/// #175: the motion table's default-state pose (the closed pose for
/// doors) — the derivation lives in
@ -4504,6 +4537,8 @@ public sealed class GameWindow : IDisposable
_animatedEntities.Remove(existingEntity.Id);
_classificationCache.InvalidateEntity(existingEntity.Id);
_physicsEngine.ShadowObjects.Deregister(existingEntity.Id);
if (serverGuid == _playerServerGuid)
_lastLocalPlayerShadow = null;
// Dead-reckon state is keyed by SERVER guid (not local id) so we
// clear using the same guid the next spawn/update would use.
@ -8307,6 +8342,7 @@ public sealed class GameWindow : IDisposable
pe.ParentCellId = result.CellId;
pe.Rotation = System.Numerics.Quaternion.CreateFromAxisAngle(
System.Numerics.Vector3.UnitZ, _playerController.Yaw - MathF.PI / 2f);
SyncLocalPlayerShadow(pe, result.CellId);
// Move the player entity to its current landblock in GpuWorldState
// so it doesn't get frustum-culled when the player walks away from
@ -11713,6 +11749,12 @@ public sealed class GameWindow : IDisposable
return;
}
// ACCmdInterp::HandleNewForwardMovement (0x0058B1F0) aborts automatic
// combat before the movement command enters CommandInterpreter. This
// notification does not consume the input; the movement owner below
// still receives it normally.
_combatAttackController?.HandleMovementInput(action, activation);
// Retail attack actions consume their full transition stream: key-down
// starts the power build and key-up commits it. Handle them before the
// generic Press-only gate below.
@ -13278,6 +13320,33 @@ public sealed class GameWindow : IDisposable
var initResult = _physicsEngine.Resolve(
playerEntity.Position, pinitCellId,
System.Numerics.Vector3.Zero, 100f);
// Retail enter_world -> SetPosition(flags 0x11) runs
// CTransition::find_placement_pos after the initial cell/environment
// placement. That second phase is what seats a relogging character
// beside a monster that moved onto the saved logout position. The
// legacy Resolve above supplies the already-ported AdjustPosition +
// floor snap; this call supplies the missing object-aware ring search.
var (placementRadius, placementHeight) =
GetSetupCylinder(_playerServerGuid, playerEntity);
if (placementRadius < 0.05f)
{
placementRadius = 0.48f;
placementHeight = 1.835f;
}
var placementResult = _physicsEngine.ResolvePlacement(
initResult.Position,
initResult.CellId,
placementRadius,
placementHeight,
_playerController.StepUpHeight,
_playerController.StepDownHeight,
AcDream.Core.Physics.ObjectInfoState.IsPlayer
| AcDream.Core.Physics.ObjectInfoState.EdgeSlide,
playerEntity.Id);
if (placementResult.Ok)
initResult = placementResult;
_playerController.SetPosition(initResult.Position, initResult.CellId,
CellLocalForSeed(initResult.Position, initResult.CellId));
// #111 (2026-06-10): snap the ENTITY too — parity with the
@ -13288,6 +13357,7 @@ public sealed class GameWindow : IDisposable
// 2 m up against the window while physics stood on the floor).
playerEntity.SetPosition(initResult.Position);
playerEntity.ParentCellId = initResult.CellId;
SyncLocalPlayerShadow(playerEntity, initResult.CellId, force: true);
var q = playerEntity.Rotation;
float rawYaw = MathF.Atan2(