fix(ui): port exact selected health policy

Replace the toolbar's PWD-bit approximation with retail ObjectIsAttackable composed with the exact player and pet short-circuits. Carry second-header PetOwner through CreateObject, session, and ClientObject state so self, pet, and Free-PK cases match retail while friendly NPCs and attackable non-creatures remain name-only.

Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-11 11:42:04 +02:00
parent 52a80dc531
commit 2644d1d527
18 changed files with 416 additions and 50 deletions

View file

@ -12568,39 +12568,17 @@ public sealed class GameWindow : IDisposable
return (LiveItemType(guid) & AcDream.Core.Items.ItemType.Creature) != 0;
}
// PublicWeenieDesc _bitfield flags (acclient.h:6431-6463) — same bitfield RadarBlipColors reads.
private const uint BfPlayer = 0x8u; // BF_PLAYER (acclient.h:6434)
private const uint BfAttackable = 0x10u; // BF_ATTACKABLE (acclient.h:6437)
/// <summary>
/// True if the selected-object strip should show a Health meter for <paramref name="guid"/>.
/// Approximates retail's <c>IsPlayer() || pet_owner || ClientCombatSystem::ObjectIsAttackable()</c>
/// gate (gmToolbarUI::HandleSelectionChanged :198754) using the server-provided PWD flags:
/// the <c>BF_ATTACKABLE</c> bit (monsters) or the <c>BF_PLAYER</c> bit (other players).
/// A friendly NPC (e.g. a vendor) has neither bit set → name-only, matching retail.
/// The full PK/faction logic of ObjectIsAttackable + the pet case are not ported (divergence AP-46).
/// Exact projection of retail's <c>IsPlayer() || pet_owner ||
/// ClientCombatSystem::ObjectIsAttackable()</c> gate from
/// <c>gmToolbarUI::HandleSelectionChanged @ 0x004BF380</c>.
/// </summary>
private bool IsHealthBarTarget(uint guid)
{
if (guid == _playerServerGuid)
return false;
if (!_entitiesByServerGuid.ContainsKey(guid))
return false;
uint pwd = _lastSpawnByGuid.TryGetValue(guid, out var spawn)
&& spawn.ObjectDescriptionFlags is { } odf ? odf : 0u;
// Another player → health bar (retail IsPlayer branch).
if ((pwd & BfPlayer) != 0)
return true;
// Attackable branch: retail ObjectIsAttackable requires the object to be a CREATURE
// first (InqType() & 0x10, acclient_2013_pseudo_c.txt:375406), THEN attackable. A Door
// carries the BF_ATTACKABLE bit but is ItemType Misc, so it is never a health-bar target —
// require the Creature flag here too (matches retail; excludes attackable doors/objects).
bool isCreature = (LiveItemType(guid) & AcDream.Core.Items.ItemType.Creature) != 0;
return isCreature && (pwd & BfAttackable) != 0;
}
=> AcDream.Core.Combat.SelectedObjectHealthPolicy.ShouldQueryHealth(
_playerServerGuid,
Objects.Get(_playerServerGuid),
Objects.Get(guid));
/// <summary>