Core/Players: fixed health initialization for players after levelups and fixed adding/reducing health based on the player's current health percentage

This commit is contained in:
Ovahlord committed 2026-06-11 12:43:17 +02:00
1 parent a43db2bf4a
commit 981e70a5a1
2 files changed
+12 -13

No files matched your search

+9 -12
View File
@@ -2246,13 +2246,13 @@ void Player::GiveLevel(uint8 level)
UpdateSkillsForLevel();
SetCreateHealth(basehp);
SetCreateMana(basemana);
// save base values (bonuses already included in stored stats)
for (StatType stat : AllStats)
GetStats().SetBaseStatValue(stat, info.stats[AsUnderlyingType(stat)]);
SetCreateHealth(basehp);
SetCreateMana(basemana);
InitTalentForLevel();
InitTaxiNodesForLevel();
InitGlyphsForLevel();
@@ -2376,15 +2376,13 @@ void Player::InitStatsForLevel(bool reapplyMods)
// reset size before reapply auras
SetObjectScale(1.0f);
SetCreateHealth(basehp);
SetCreateMana(basemana);
// save base values (bonuses already included in stored stats
for (StatType stat : AllStats)
GetStats().SetBaseStatValue(stat, info.stats[AsUnderlyingType(stat)]);
SetCreateHealth(basehp);
//set create powers
SetCreateMana(basemana);
//reset rating fields values
for (uint16 index = PLAYER_FIELD_COMBAT_RATING_1; index < PLAYER_FIELD_COMBAT_RATING_1 + MAX_COMBAT_RATING; ++index)
SetUInt32Value(index, 0);
@@ -2470,8 +2468,6 @@ void Player::InitStatsForLevel(bool reapplyMods)
for (uint8 i = POWER_MANA; i < MAX_POWERS; ++i)
SetMaxPower(PowerType(i), GetCreatePowerValue(PowerType(i)));
SetMaxHealth(basehp); // stamina bonus will applied later
// cleanup mounted state (it will set correctly at aura loading if player saved at mount.
SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, 0);
@@ -17085,6 +17081,9 @@ bool Player::LoadFromDB(ObjectGuid guid, CharacterDatabaseQueryHolder const& hol
SetGuidValue(PLAYER_DUEL_ARBITER, ObjectGuid::Empty);
SetUInt32Value(PLAYER_DUEL_TEAM, 0);
RegisterPowerTypes();
UpdateDisplayPower();
// reset stats before loading any modifiers
InitStatsForLevel();
InitGlyphsForLevel();
@@ -17116,8 +17115,6 @@ bool Player::LoadFromDB(ObjectGuid guid, CharacterDatabaseQueryHolder const& hol
//mails are loaded only when needed ;-) - when player in game click on mailbox.
//_LoadMail();
RegisterPowerTypes();
UpdateDisplayPower();
_LoadTalents(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_TALENTS));
_LoadSpells(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_SPELLS));
+3 -1
View File
@@ -351,7 +351,9 @@ void Player::UpdateMaxHealth()
value += GetFlatModifierValue(unitMod, TOTAL_VALUE) + GetHealthBonusFromStamina();
value *= GetPctModifierValue(unitMod, TOTAL_PCT);
SetMaxHealth((uint32)value);
float healthPct = GetHealthPct();
SetMaxHealth(static_cast<uint32>(value));
SetHealth(std::max<uint32>(1, CalculatePct(GetMaxHealth(), healthPct)));
}
uint32 Player::GetPowerIndex(PowerType power) const