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
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