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:
parent
52a80dc531
commit
2644d1d527
18 changed files with 416 additions and 50 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -37,13 +37,6 @@ namespace AcDream.App.UI.Layout;
|
|||
/// "Drudge Slinker" reference shot).
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// <strong>Divergence — health-target gate approximation.</strong>
|
||||
/// Retail sends <c>Event_QueryHealth</c> for <c>IsPlayer() || pet_owner || ObjectIsAttackable()</c>
|
||||
/// (<c>:198754</c>). acdream uses <c>IsLiveCreatureTarget</c> (the <c>ItemType.Creature</c>
|
||||
/// flag) to gate the QueryHealth send. Visibility itself is health-data-driven (above), so
|
||||
/// the gate only affects whether we proactively query; recorded in the divergence register.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class SelectedObjectController : IRetainedPanelController
|
||||
{
|
||||
|
|
|
|||
|
|
@ -197,7 +197,9 @@ public static class CreateObject
|
|||
byte? CombatUse = null,
|
||||
// PublicWeenieDesc._plural_name, gated by WeenieHeader flag 0x1.
|
||||
// ACCWeenieObject::GetObjectName(NAME_APPROPRIATE) selects this for stacks.
|
||||
string? PluralName = null);
|
||||
string? PluralName = null,
|
||||
// PublicWeenieDesc._pet_owner, gated by second-header flag 0x8.
|
||||
uint? PetOwnerId = null);
|
||||
|
||||
/// <summary>
|
||||
/// The relevant subset of the server-sent <c>MovementData</c> /
|
||||
|
|
@ -760,6 +762,7 @@ public static class CreateObject
|
|||
uint iconUnderlayId = 0;
|
||||
uint uiEffects = 0;
|
||||
uint weenieFlags2 = 0;
|
||||
uint? petOwnerId = null;
|
||||
try
|
||||
{
|
||||
// BF_INCLUDES_SECOND_HEADER = 0x04000000 per acclient.h:6458
|
||||
|
|
@ -952,6 +955,28 @@ public static class CreateObject
|
|||
{
|
||||
iconUnderlayId = ReadPackedDwordOfKnownType(body, ref pos, IconTypePrefix);
|
||||
}
|
||||
// PublicWeenieDesc::UnPack @ 0x005AD7AC..0x005AD7F8 and ACE
|
||||
// SerializeCreateObject both place these fields after IconUnderlay.
|
||||
if ((weenieFlags & 0x80000000u) != 0) // MaterialType u32
|
||||
{
|
||||
if (body.Length - pos < 4) throw new FormatException("trunc MaterialType");
|
||||
pos += 4;
|
||||
}
|
||||
if ((weenieFlags2 & 0x00000002u) != 0) // CooldownId u32
|
||||
{
|
||||
if (body.Length - pos < 4) throw new FormatException("trunc CooldownId");
|
||||
pos += 4;
|
||||
}
|
||||
if ((weenieFlags2 & 0x00000004u) != 0) // CooldownDuration f64
|
||||
{
|
||||
if (body.Length - pos < 8) throw new FormatException("trunc CooldownDuration");
|
||||
pos += 8;
|
||||
}
|
||||
if ((weenieFlags2 & 0x00000008u) != 0) // PetOwner u32
|
||||
{
|
||||
if (body.Length - pos < 4) throw new FormatException("trunc PetOwner");
|
||||
petOwnerId = ReadU32(body, ref pos);
|
||||
}
|
||||
}
|
||||
catch { /* truncated weenie tail — keep whatever we got. */ }
|
||||
|
||||
|
|
@ -974,7 +999,8 @@ public static class CreateObject
|
|||
Workmanship: wWorkmanship,
|
||||
RadarBlipColor: radarBlipColor, RadarBehavior: radarBehavior,
|
||||
CombatUse: combatUse,
|
||||
PluralName: pluralName);
|
||||
PluralName: pluralName,
|
||||
PetOwnerId: petOwnerId);
|
||||
|
||||
// Local helper: if we ran out of fields past PhysicsData, still
|
||||
// return the useful prefix (guid/position/setup/animParts/textures/palettes/scale/motion).
|
||||
|
|
|
|||
|
|
@ -88,5 +88,6 @@ public static class ObjectTableWiring
|
|||
RadarBehavior: s.RadarBehavior,
|
||||
PublicWeenieBitfield: s.ObjectDescriptionFlags,
|
||||
CombatUse: s.CombatUse,
|
||||
PluralName: s.PluralName);
|
||||
PluralName: s.PluralName,
|
||||
PetOwnerId: s.PetOwnerId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,8 @@ public sealed class WorldSession : IDisposable
|
|||
byte? RadarBlipColor = null,
|
||||
byte? RadarBehavior = null,
|
||||
byte? CombatUse = null,
|
||||
string? PluralName = null);
|
||||
string? PluralName = null,
|
||||
uint? PetOwnerId = null);
|
||||
|
||||
/// <summary>
|
||||
/// Projects the wire-level CreateObject result into the stable session
|
||||
|
|
@ -177,7 +178,8 @@ public sealed class WorldSession : IDisposable
|
|||
RadarBlipColor: parsed.RadarBlipColor,
|
||||
RadarBehavior: parsed.RadarBehavior,
|
||||
CombatUse: parsed.CombatUse,
|
||||
PluralName: parsed.PluralName);
|
||||
PluralName: parsed.PluralName,
|
||||
PetOwnerId: parsed.PetOwnerId);
|
||||
|
||||
/// <summary>Fires when the session finishes parsing a CreateObject.</summary>
|
||||
public event Action<EntitySpawn>? EntitySpawned;
|
||||
|
|
|
|||
79
src/AcDream.Core/Combat/SelectedObjectHealthPolicy.cs
Normal file
79
src/AcDream.Core/Combat/SelectedObjectHealthPolicy.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
using AcDream.Core.Items;
|
||||
|
||||
namespace AcDream.Core.Combat;
|
||||
|
||||
/// <summary>
|
||||
/// Retail selected-object health-query eligibility.
|
||||
/// Ports <c>gmToolbarUI::HandleSelectionChanged @ 0x004BF380</c> and
|
||||
/// <c>ClientCombatSystem::ObjectIsAttackable @ 0x0056A600</c>.
|
||||
/// </summary>
|
||||
public static class SelectedObjectHealthPolicy
|
||||
{
|
||||
public const uint BfPlayer = 0x00000008u;
|
||||
public const uint BfAttackable = 0x00000010u;
|
||||
public const uint BfPlayerKiller = 0x00000020u;
|
||||
public const uint BfFreePkStatus = 0x00200000u;
|
||||
public const uint BfPkLiteStatus = 0x02000000u;
|
||||
|
||||
/// <summary>
|
||||
/// Exact toolbar composition: every player, every pet, otherwise retail's
|
||||
/// reusable combat attackability predicate. Stacked objects take the separate
|
||||
/// split-control branch before this policy is called.
|
||||
/// </summary>
|
||||
public static bool ShouldQueryHealth(
|
||||
uint playerId,
|
||||
ClientObject? player,
|
||||
ClientObject? selected)
|
||||
{
|
||||
if (selected is null)
|
||||
return false;
|
||||
|
||||
uint flags = selected.PublicWeenieBitfield ?? 0u;
|
||||
return (flags & BfPlayer) != 0
|
||||
|| selected.PetOwnerId != 0
|
||||
|| ObjectIsAttackable(playerId, player, selected.ObjectId, selected);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Line-for-line branch port of
|
||||
/// <c>ClientCombatSystem::ObjectIsAttackable @ 0x0056A600</c>.
|
||||
/// </summary>
|
||||
public static bool ObjectIsAttackable(
|
||||
uint playerId,
|
||||
ClientObject? player,
|
||||
uint targetId,
|
||||
ClientObject? target)
|
||||
{
|
||||
if (targetId == 0 || targetId == playerId)
|
||||
return true;
|
||||
|
||||
if (target is null || (target.Type & ItemType.Creature) == 0)
|
||||
return false;
|
||||
|
||||
uint targetFlags = target.PublicWeenieBitfield ?? 0u;
|
||||
if ((targetFlags & BfFreePkStatus) != 0)
|
||||
return true;
|
||||
|
||||
if (player is null)
|
||||
return false;
|
||||
|
||||
uint playerFlags = player.PublicWeenieBitfield ?? 0u;
|
||||
if ((playerFlags & BfFreePkStatus) != 0)
|
||||
return true;
|
||||
|
||||
if ((targetFlags & BfPlayer) != 0)
|
||||
{
|
||||
if ((targetFlags & BfPlayerKiller) != 0
|
||||
&& (playerFlags & BfPlayerKiller) != 0)
|
||||
return true;
|
||||
|
||||
return (targetFlags & BfPkLiteStatus) != 0
|
||||
&& (playerFlags & BfPkLiteStatus) != 0;
|
||||
}
|
||||
|
||||
if (target.PetOwnerId != 0)
|
||||
return false;
|
||||
|
||||
return (targetFlags & BfAttackable) != 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -182,6 +182,11 @@ public sealed class ClientObject
|
|||
public uint? TargetType { get; set; } // ITEM_TYPE mask for targeted-use compatibility
|
||||
/// <summary>Retail <c>PublicWeenieDesc._bitfield</c>; null until CreateObject supplies it.</summary>
|
||||
public uint? PublicWeenieBitfield { get; set; }
|
||||
/// <summary>
|
||||
/// Retail <c>PublicWeenieDesc._pet_owner</c>; zero means this creature is not a pet.
|
||||
/// CreateObject second-header flag <c>PWD2_Packed_PetOwner (0x8)</c> supplies it.
|
||||
/// </summary>
|
||||
public uint PetOwnerId { get; set; }
|
||||
/// <summary>Retail <c>PublicWeenieDesc._combatUse</c>; null when its header flag was absent.</summary>
|
||||
public byte? CombatUse { get; set; }
|
||||
/// <summary>Client-side trade state used by ItemHolder legality gates.</summary>
|
||||
|
|
@ -249,7 +254,8 @@ public readonly record struct WeenieData(
|
|||
byte? RadarBehavior = null,
|
||||
uint? PublicWeenieBitfield = null,
|
||||
byte? CombatUse = null,
|
||||
string? PluralName = null);
|
||||
string? PluralName = null,
|
||||
uint? PetOwnerId = null);
|
||||
|
||||
/// <summary>
|
||||
/// Retail ITEM_USEABLE helpers (acclient.h:6478, ItemUses::* at 0x004fccd0).
|
||||
|
|
|
|||
|
|
@ -388,6 +388,7 @@ public sealed class ClientObjectTable
|
|||
if (d.Useability is { } use) obj.Useability = use;
|
||||
if (d.TargetType is { } targetType) obj.TargetType = targetType;
|
||||
if (d.PublicWeenieBitfield is { } bitfield) obj.PublicWeenieBitfield = bitfield;
|
||||
if (d.PetOwnerId is { } petOwnerId) obj.PetOwnerId = petOwnerId;
|
||||
if (d.CombatUse is { } combatUse) obj.CombatUse = combatUse;
|
||||
if (d.RadarBlipColor is { } radarBlipColor) obj.RadarBlipColor = radarBlipColor;
|
||||
if (d.RadarBehavior is { } radarBehavior) obj.RadarBehavior = radarBehavior;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue