fix(combat): #298 — admit player targets to melee/missile attack and the camera
Selecting a PKLite player and attacking did nothing: with auto-target on it retargeted to the nearest monster, with auto-target off it logged "combat: attack ignored; no creature target found". Spells on the same target worked, which was the clue. Root cause: CombatTargetPolicy.IsHostileMonster:31-33 rejects any candidate carrying BfPlayer BEFORE reaching ObjectIsAttackable, so the both-PKLite pool match at SelectedObjectHealthPolicy.cs:70-71 was unreachable for players. Melee and missile targeting never supported player targets at all — the gate is named IsHostileMonster and does exactly what it says. Nobody could hit it until69ba9486made PK Lite reachable. Retail uses ONE predicate for monsters and players, with no player exclusion: ClientCombatSystem::ExecuteAttack @0x0056BB70 gates unconditionally on ObjectIsAttackable @0x0056A600 (creature type, Free-PK short-circuit on either side, then IsPlayer -> bothPK || bothPKLite, else BF_ATTACKABLE with pets excluded). acdream already ported that predicate verbatim; it was simply unreachable. The fix SPLITS the two concerns rather than relaxing the shared predicate: explicit-target admission routes through ObjectIsAttackable, while auto-target ACQUISITION keeps the monster-only gate. That is required by register row IA-19 — explicit product direction that Auto Target must never select NPCs, players or pets. IA-19 is not overridden here; its own justification promises "manual player-selection commands remain available", and that promise was never implemented, so this makes the row true. Review confirmed no path lets auto-acquisition select a player: every automatic Select is fed by a FindClosest* filtered through IsHostileMonster. Review also found a second site with the same bug, which the first pass froze in place on my instruction: retail gates combat-camera tracking on the SAME predicate as the attack. ClientCombatSystem::UpdateTargetTracking @0x0056A950 reads GetAttackTarget() then gates CameraSet::TrackTarget on ObjectIsAttackable. Ours used the monster-only gate, so with ViewCombatTarget on by default the attack would land while the camera refused to track the opponent — user-visible in exactly the duel this fix enables. GetCombatCameraTargetPoint now uses the wide predicate. IA-19 does not reach the camera: it performs no acquisition, only presentation on an already-chosen target. The first pass had added a source comment asserting IA-19 covered it; that comment and the matching text in docs/ISSUES.md are corrected, since a wrong citation is how a real divergence becomes invisible. Depends on9b1e6fc6(#297): the both-PKLite arm needs the LOCAL player's own bit to be live. Review confirmed both admission sites read ClientObjectTable on every call, so this is not inert in production. Newly reachable and now pinned: ObjectIsAttackable's pet-exclusion arm, which CombatTargetPolicy rejected before it could ever run. Follow-ups filed: #304 (SelectionInteractionController.GetSelectedOrClosestCombatTarget has no production caller — one of the two widened call sites is dead code), #305 (HeadlessGameplayOperations has the identical pre-existing bug, so the graphical/headless hosts now diverge). Gates: complete Release solution 10,904 passed / 4 skipped / 0 failed (baseline 10,900). Adversarial + retail-conformance review PASS after one FAIL round; the predicate was re-verified branch-for-branch against 0x0056A600 since it goes live here for the first time. Camera fix discrimination-verified by revert. Connected acceptance NOT run — needs a live two-client PKLite session. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
9b1e6fc637
commit
bc0077a55f
11 changed files with 410 additions and 25 deletions
|
|
@ -32,6 +32,142 @@ public sealed class CombatAttackTargetSourceTests
|
|||
harness.Targets.GetSelectedOrClosestCombatTarget(autoTarget: false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #298: explicit selection of a compatible-PK player is a valid attack
|
||||
/// target. Retail <c>ObjectIsAttackable @ 0x0056A600</c> admits a player
|
||||
/// target when both sides carry the same PKLite status, and this is
|
||||
/// reachable ONLY through explicit selection — never automatic
|
||||
/// acquisition (register row IA-19).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ExplicitSelectedPkLitePlayerIsAcceptedWithoutAutoTarget()
|
||||
{
|
||||
var harness = new Harness();
|
||||
harness.SetLocalPlayerPvpFlags(SelectedObjectHealthPolicy.BfPkLiteStatus);
|
||||
const uint target = 0x7000_0002u;
|
||||
harness.Add(
|
||||
target,
|
||||
new Vector3(2f, 0f, 0f),
|
||||
attackable: false,
|
||||
isPlayer: true,
|
||||
extraFlags: SelectedObjectHealthPolicy.BfPkLiteStatus);
|
||||
harness.Selection.Select(target, SelectionChangeSource.Keyboard);
|
||||
|
||||
Assert.Equal(
|
||||
target,
|
||||
harness.Targets.GetSelectedOrClosestCombatTarget(autoTarget: false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #298: explicit selection of a player whose PK pool does not match
|
||||
/// (neither side is PKLite/PK/Free) is still refused — the fix widens
|
||||
/// admission to compatible-PK players, it does not admit every player.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ExplicitSelectedNonPkPlayerIsRefused()
|
||||
{
|
||||
var harness = new Harness();
|
||||
const uint target = 0x7000_0003u;
|
||||
harness.Add(
|
||||
target,
|
||||
new Vector3(2f, 0f, 0f),
|
||||
attackable: false,
|
||||
isPlayer: true);
|
||||
harness.Selection.Select(target, SelectionChangeSource.Keyboard);
|
||||
|
||||
Assert.Null(
|
||||
harness.Targets.GetSelectedOrClosestCombatTarget(autoTarget: false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #298 follow-up: explicit selection no longer short-circuits on
|
||||
/// <c>PetOwnerId != 0</c> the way <c>CombatTargetPolicy.IsHostileMonster</c>
|
||||
/// does (`:33`) — it now reaches <c>ObjectIsAttackable</c>'s OWN pet arm
|
||||
/// (retail `else if (esi->pwd._pet_owner == 0)` @ 0x0056a683) for the
|
||||
/// first time. That arm still refuses an attackable, owned pet, so the
|
||||
/// end behavior is unchanged; this pins reachability through the new
|
||||
/// path, not just the Core predicate (see
|
||||
/// <c>SelectedObjectHealthPolicyTests.ObjectIsAttackable_AttackablePetIsRejected</c>).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ExplicitSelectedAttackablePetIsRefused()
|
||||
{
|
||||
var harness = new Harness();
|
||||
const uint pet = 0x7000_0007u;
|
||||
harness.Add(
|
||||
pet,
|
||||
new Vector3(2f, 0f, 0f),
|
||||
attackable: true,
|
||||
petOwnerId: Player);
|
||||
harness.Selection.Select(pet, SelectionChangeSource.Keyboard);
|
||||
|
||||
Assert.Null(
|
||||
harness.Targets.GetSelectedOrClosestCombatTarget(autoTarget: false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mutation guard for <see cref="CombatAttackTargetSource.FindClosestHostileMonster"/>:
|
||||
/// with nothing explicitly selected, auto-acquisition must still filter
|
||||
/// the nearer compatible-PK player out and pick the farther monster. This
|
||||
/// does NOT exercise the explicit-selection branch (nothing is selected),
|
||||
/// so it does not by itself prove the #298 split kept
|
||||
/// <see cref="CombatTargetPolicy.IsHostileMonster"/> narrow — it proves
|
||||
/// nobody swapped <c>FindClosestHostileMonster</c>'s gate for the wider
|
||||
/// predicate. See <see cref="AutoTargetNeverAcquiresAPlayerWhenNoMonsterIsInRange"/>
|
||||
/// for the case that actually forces the narrow policy to reject the
|
||||
/// only candidate.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void AutoTargetNeverAcquiresAPlayerOverAMonster()
|
||||
{
|
||||
var harness = new Harness();
|
||||
harness.SetLocalPlayerPvpFlags(SelectedObjectHealthPolicy.BfPkLiteStatus);
|
||||
const uint monster = 0x7000_0004u;
|
||||
const uint pkLitePlayer = 0x7000_0005u;
|
||||
harness.Add(monster, new Vector3(8f, 0f, 0f), attackable: true);
|
||||
harness.Add(
|
||||
pkLitePlayer,
|
||||
new Vector3(1f, 0f, 0f),
|
||||
attackable: false,
|
||||
isPlayer: true,
|
||||
extraFlags: SelectedObjectHealthPolicy.BfPkLiteStatus);
|
||||
|
||||
uint? selected = harness.Targets.GetSelectedOrClosestCombatTarget(
|
||||
autoTarget: true);
|
||||
|
||||
Assert.Equal(monster, selected);
|
||||
Assert.Equal(monster, harness.Selection.SelectedObjectId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The actual IA-19 invariant: with nothing selected and NO monster in
|
||||
/// range at all, a nearby compatible-PK player must still be rejected by
|
||||
/// automatic acquisition — <c>FindClosestHostileMonster</c> filters
|
||||
/// through the narrow <see cref="CombatTargetPolicy.IsHostileMonster"/>,
|
||||
/// finds no candidate, and the stale selection is cleared, exactly as
|
||||
/// retail's IA-19 divergence documents (auto-target never acquires a
|
||||
/// player even though retail's own <c>AutoTarget</c> would).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void AutoTargetNeverAcquiresAPlayerWhenNoMonsterIsInRange()
|
||||
{
|
||||
var harness = new Harness();
|
||||
harness.SetLocalPlayerPvpFlags(SelectedObjectHealthPolicy.BfPkLiteStatus);
|
||||
const uint pkLitePlayer = 0x7000_0006u;
|
||||
harness.Add(
|
||||
pkLitePlayer,
|
||||
new Vector3(1f, 0f, 0f),
|
||||
attackable: false,
|
||||
isPlayer: true,
|
||||
extraFlags: SelectedObjectHealthPolicy.BfPkLiteStatus);
|
||||
|
||||
uint? selected = harness.Targets.GetSelectedOrClosestCombatTarget(
|
||||
autoTarget: true);
|
||||
|
||||
Assert.Null(selected);
|
||||
Assert.Null(harness.Selection.SelectedObjectId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AutoTargetUsesNearestEligibleLiveHostile()
|
||||
{
|
||||
|
|
@ -107,11 +243,22 @@ public sealed class CombatAttackTargetSourceTests
|
|||
Add(Player, Vector3.Zero, attackable: false, isPlayer: true);
|
||||
}
|
||||
|
||||
public void SetLocalPlayerPvpFlags(uint extraFlags) =>
|
||||
Objects.AddOrUpdate(new ClientObject
|
||||
{
|
||||
ObjectId = Player,
|
||||
Name = $"Object {Player:X8}",
|
||||
Type = ItemType.Creature,
|
||||
PublicWeenieBitfield = SelectedObjectHealthPolicy.BfPlayer | extraFlags,
|
||||
});
|
||||
|
||||
public WorldEntity Add(
|
||||
uint guid,
|
||||
Vector3 position,
|
||||
bool attackable,
|
||||
bool isPlayer = false)
|
||||
bool isPlayer = false,
|
||||
uint extraFlags = 0u,
|
||||
uint petOwnerId = 0u)
|
||||
{
|
||||
Runtime.RegisterLiveEntity(Spawn(guid));
|
||||
WorldEntity entity = Runtime.MaterializeLiveEntity(
|
||||
|
|
@ -130,12 +277,14 @@ public sealed class CombatAttackTargetSourceTests
|
|||
uint flags = attackable ? SelectedObjectHealthPolicy.BfAttackable : 0u;
|
||||
if (isPlayer)
|
||||
flags |= SelectedObjectHealthPolicy.BfPlayer;
|
||||
flags |= extraFlags;
|
||||
Objects.AddOrUpdate(new ClientObject
|
||||
{
|
||||
ObjectId = guid,
|
||||
Name = $"Object {guid:X8}",
|
||||
Type = ItemType.Creature,
|
||||
PublicWeenieBitfield = flags,
|
||||
PetOwnerId = petOwnerId,
|
||||
});
|
||||
return entity;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public sealed class CombatCameraTargetSourceTests
|
|||
public string Describe(uint serverGuid) => string.Empty;
|
||||
public bool IsCreature(uint serverGuid) => false;
|
||||
public bool IsHostileMonster(uint serverGuid) => false;
|
||||
public bool IsAttackableTarget(uint serverGuid) => false;
|
||||
public ClosestCombatTarget? FindClosestHostileMonster() => null;
|
||||
public bool IsUseable(uint serverGuid) => false;
|
||||
public bool IsPickupable(uint serverGuid) => false;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ public sealed class SelectionInteractionControllerTests
|
|||
public bool Current { get; set; } = true;
|
||||
public bool Creature { get; set; }
|
||||
public bool Hostile { get; set; }
|
||||
public bool Attackable { get; set; }
|
||||
public bool Useable { get; set; } = true;
|
||||
public bool Pickupable { get; set; } = true;
|
||||
public bool WieldedByPlayer { get; set; }
|
||||
|
|
@ -66,6 +67,7 @@ public sealed class SelectionInteractionControllerTests
|
|||
public string Describe(uint serverGuid) => $"Target {serverGuid:X8}";
|
||||
public bool IsCreature(uint serverGuid) => Creature;
|
||||
public bool IsHostileMonster(uint serverGuid) => Hostile;
|
||||
public bool IsAttackableTarget(uint serverGuid) => Attackable;
|
||||
public ClosestCombatTarget? FindClosestHostileMonster() => Closest;
|
||||
public bool IsUseable(uint serverGuid) => Useable;
|
||||
public bool IsPickupable(uint serverGuid) => Pickupable;
|
||||
|
|
@ -1040,6 +1042,44 @@ public sealed class SelectionInteractionControllerTests
|
|||
Assert.False(h.Items.TryGetPendingBackpackPlacement(Target, out _));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #298: explicit-target admission routes through the wider
|
||||
/// <c>IsAttackableTarget</c> query (retail <c>ObjectIsAttackable</c>,
|
||||
/// which admits a compatible-PK player), not the narrower
|
||||
/// <c>IsHostileMonster</c> that auto-acquisition uses.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetSelectedOrClosestCombatTargetAcceptsExplicitAttackableEvenWhenNotHostileMonster()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.Query.Attackable = true;
|
||||
h.Query.Hostile = false;
|
||||
h.Selection.Select(Target, SelectionChangeSource.Keyboard);
|
||||
|
||||
Assert.Equal(
|
||||
Target,
|
||||
h.Controller.GetSelectedOrClosestCombatTarget(autoTarget: false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #298 / IA-19 guard: when the explicit selection is not an admitted
|
||||
/// attack target, auto-acquisition falls back to the narrower
|
||||
/// <c>FindClosestHostileMonster</c> query unchanged.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GetSelectedOrClosestCombatTargetFallsBackToAutoAcquisitionWhenExplicitTargetIsNotAttackable()
|
||||
{
|
||||
var h = new Harness();
|
||||
const uint monster = 0x7000_0099u;
|
||||
h.Query.Attackable = false;
|
||||
h.Query.Closest = new ClosestCombatTarget(monster, DistanceSquared: 4f);
|
||||
h.Selection.Select(Target, SelectionChangeSource.Keyboard);
|
||||
|
||||
Assert.Equal(
|
||||
monster,
|
||||
h.Controller.GetSelectedOrClosestCombatTarget(autoTarget: true));
|
||||
}
|
||||
|
||||
private static WorldSession.EntitySpawn Spawn(uint guid, ushort instance)
|
||||
=> new(
|
||||
guid,
|
||||
|
|
|
|||
|
|
@ -299,6 +299,44 @@ public sealed class WorldSelectionQueryTests
|
|||
Assert.Equal(64f, closest?.DistanceSquared);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #298 follow-up: retail <c>ClientCombatSystem::UpdateTargetTracking
|
||||
/// @ 0x0056A950</c> (pc:375691-375696) gates <c>CameraSet::TrackTarget</c>
|
||||
/// on <c>ObjectIsAttackable @ 0x0056A600</c> — the SAME wide predicate as
|
||||
/// <c>ExecuteAttack</c>, not the narrower monster-only
|
||||
/// <c>IsHostileMonster</c>. A compatible-PK player under explicit
|
||||
/// selection is a valid camera target; a non-PK player is not.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void CombatCameraTracksACompatiblePkPlayerButNotAnIncompatibleOne()
|
||||
{
|
||||
var h = new Harness();
|
||||
h.Objects.AddOrUpdate(new ClientObject
|
||||
{
|
||||
ObjectId = Player,
|
||||
Name = $"Object {Player:X8}",
|
||||
Type = ItemType.Creature,
|
||||
PublicWeenieBitfield = SelectedObjectHealthPolicy.BfPlayer
|
||||
| SelectedObjectHealthPolicy.BfPkLiteStatus,
|
||||
});
|
||||
const uint pkLiteOpponent = 0x7000_0050u;
|
||||
const uint nonPkPlayer = 0x7000_0051u;
|
||||
h.Add(
|
||||
pkLiteOpponent,
|
||||
new Vector3(2f, 0f, 0f),
|
||||
ItemType.Creature,
|
||||
SelectedObjectHealthPolicy.BfPlayer
|
||||
| SelectedObjectHealthPolicy.BfPkLiteStatus);
|
||||
h.Add(
|
||||
nonPkPlayer,
|
||||
new Vector3(3f, 0f, 0f),
|
||||
ItemType.Creature,
|
||||
SelectedObjectHealthPolicy.BfPlayer);
|
||||
|
||||
Assert.NotNull(h.Query.GetCombatCameraTargetPoint(pkLiteOpponent));
|
||||
Assert.Null(h.Query.GetCombatCameraTargetPoint(nonPkPlayer));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.59f, true)]
|
||||
[InlineData(0.61f, false)]
|
||||
|
|
|
|||
|
|
@ -1181,6 +1181,7 @@ public sealed class CurrentGameRuntimeAdapterTests
|
|||
public string Describe(uint serverGuid) => "Runtime target";
|
||||
public bool IsCreature(uint serverGuid) => serverGuid == target;
|
||||
public bool IsHostileMonster(uint serverGuid) => serverGuid == target;
|
||||
public bool IsAttackableTarget(uint serverGuid) => serverGuid == target;
|
||||
public ClosestCombatTarget? FindClosestHostileMonster() =>
|
||||
new(target, DistanceSquared: 4f);
|
||||
public bool IsUseable(uint serverGuid) => serverGuid == target;
|
||||
|
|
|
|||
|
|
@ -93,4 +93,27 @@ public sealed class SelectedObjectHealthPolicyTests
|
|||
Assert.False(SelectedObjectHealthPolicy.ObjectIsAttackable(
|
||||
PlayerId, null, creature.ObjectId, creature));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #298 follow-up: this arm (retail <c>else if (esi->pwd._pet_owner ==
|
||||
/// 0)</c> @ 0x0056a683 — falling through to <c>eax = 0; return 0</c> when
|
||||
/// it does NOT hold) only became reachable from the App layer once
|
||||
/// explicit-target admission started calling <c>ObjectIsAttackable</c>
|
||||
/// directly; <c>CombatTargetPolicy.IsHostileMonster</c> rejects pets
|
||||
/// earlier and never reaches it. Pin it here at the source predicate: an
|
||||
/// attackable, owned pet is refused even though its
|
||||
/// <c>BfAttackable</c> bit is set.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ObjectIsAttackable_AttackablePetIsRejected()
|
||||
{
|
||||
var player = Obj(PlayerId, flags: SelectedObjectHealthPolicy.BfPlayer);
|
||||
var pet = Obj(
|
||||
0x50000041u,
|
||||
flags: SelectedObjectHealthPolicy.BfAttackable,
|
||||
petOwner: PlayerId);
|
||||
|
||||
Assert.False(SelectedObjectHealthPolicy.ObjectIsAttackable(
|
||||
PlayerId, player, pet.ObjectId, pet));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue