Fix discrepancy between max hitpoints and actual hitpoints due to floats in JS.

Patch by: @Langbart
Fixes #6657

This was SVN commit r27425.
This commit is contained in:
Freagarach 2023-01-12 09:16:26 +00:00
parent a2efada174
commit 344e85e97f

View File

@ -465,7 +465,9 @@ Health.prototype.RecalculateValues = function()
let newMaxHitpoints = ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity);
if (oldMaxHitpoints != newMaxHitpoints)
{
let newHitpoints = this.hitpoints * newMaxHitpoints/oldMaxHitpoints;
// Don't recalculate hitpoints when full health due to float imprecision: #6657.
const newHitpoints = (this.hitpoints === oldMaxHitpoints) ? newMaxHitpoints :
this.hitpoints * newMaxHitpoints/oldMaxHitpoints;
this.maxHitpoints = newMaxHitpoints;
this.SetHitpoints(newHitpoints);
}