Skip to content

fix(view): never show a living creature at 0 health - #4

Open
sorcerer-merlin wants to merge 1 commit into
firstoni-dev:mainfrom
sorcerer-merlin:fix/view-health-zero
Open

sorcerer-merlin wants to merge 1 commit into
firstoni-dev:mainfrom
sorcerer-merlin:fix/view-health-zero

Conversation

@sorcerer-merlin

Copy link
Copy Markdown

Problem

With the Z-14 per-viewer view enabled, a creature shown at a lower effective level than its real one can have
its health bar sent to the viewer as 0 while it is still alive.

ZoneScalingMgr::GetViewPool (src/ZoneScalingCombat.cpp) scales current health to the viewer's max and
truncates:

out.Health = uint32(uint64(creature->GetHealth()) * out.MaxHealth / realMax);

The 3.3.5a client treats UNIT_FIELD_HEALTH reaching 0 as the unit's death: it plays the death animation,
writes " dies." to the combat log and keeps showing the unit as a corpse. The server still has the
creature alive, so the client then shows a "corpse" that keeps attacking, talks, or slides along the ground
when it moves.

It hits whenever realHealth < realMax / shownMax, so only for viewers below the creature's real level, and
only at very low health. It's easiest to reproduce with any creature that a script holds at a low health floor
(e.g. SmartAI SET_INVINCIBILITY_HP_LEVEL for "beat them down" quest NPCs): a creature with 142 real max health
held at 1 HP, viewed at a level where its max shows as 84, is sent 1 × 84 / 142 = 0. Ordinary mobs show it
briefly as a "death" one hit early.

Fix

If the creature has any health left, the viewer sees at least 1:

if (!out.Health && creature->GetHealth())
    out.Health = 1;

The real health and every server-side calculation are unchanged; only the value sent to the viewer is affected.
Mana is left as is (0 mana doesn't mean anything to the client).

Testing

On a 3.3.5a server with Z-14 active: a level 1 character fought level 3 quest NPCs held at 1 HP by a SmartAI
invincibility floor. Before: the client showed them dead (UnitHealth 0, UnitIsDead true) while they kept
fighting. After: they show 1 HP, alive, and their scripted surrender plays normally. Regular kills are
unaffected (health really reaches 0 on death).

GetViewPool scales health to the viewer's effective level and rounds down, so a creature at 1 HP (142 real, 84 shown) was sent as 0. The client treats health 0 as death (OnDeath), so it played the death animation while the server kept the creature alive and fighting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant