fix(Core/Spells): Fixed work of sobering spells and other improvements for drunk system (#18390)

* fix(Core/Spells): Fix sobering spells and possible uint8 overflow/underflow in SPELL_EFFECT_INEBRIATE handler.

* fix(Core/Spells): Improvements for SPELL_AURA_MOD_FAKE_INEBRIATE handling
This commit is contained in:
Mykhailo Redko
2024-03-20 06:45:01 +02:00
committed by GitHub
parent 21c1c5de11
commit 33f951d742
4 changed files with 50 additions and 60 deletions

View File

@@ -4474,17 +4474,25 @@ void Spell::EffectInebriate(SpellEffIndex /*effIndex*/)
}
uint8 currentDrunk = player->GetDrunkValue();
uint8 drunkMod = damage;
if (currentDrunk + drunkMod > 100)
{
int32 drunkMod = damage;
if (drunkMod == 0)
return;
// drunkMod may contain values that are guaranteed to cause uint8 overflow/underflow (examples: 29690, 46874)
// In addition, we would not want currentDrunk to become more than 100.
// So before adding the values, let's check that everything is fine.
if (drunkMod > 0 && drunkMod > static_cast<int32>(100 - currentDrunk))
currentDrunk = 100;
if (rand_chance() < 25.0f)
player->CastSpell(player, 67468, false); // Drunken Vomit
}
else if (drunkMod < 0 && drunkMod < static_cast<int32>(0 - currentDrunk))
currentDrunk = 0;
else
currentDrunk += drunkMod;
currentDrunk += drunkMod; // Due to previous checks we can be sure that currentDrunk will not go beyond [0-100] range.
player->SetDrunkValue(currentDrunk, m_CastItem ? m_CastItem->GetEntry() : 0);
if (currentDrunk == 100 && roll_chance_i(25))
player->CastSpell(player, 67468, false); // Drunken Vomit
}
void Spell::EffectFeedPet(SpellEffIndex effIndex)