fix(Core/Unit): Reduce mobs speed when low on health (#7932)

This commit is contained in:
patou01
2021-11-04 14:43:24 +01:00
committed by GitHub
parent da42426783
commit ea2c880fc8
3 changed files with 24 additions and 9 deletions

View File

@@ -1805,7 +1805,6 @@ void Creature::setDeathState(DeathState s, bool despawn)
if (HasSearchedAssistance())
{
SetNoSearchAssistance(false);
UpdateSpeed(MOVE_RUN, false);
}
//Dismiss group if is leader

View File

@@ -9773,7 +9773,6 @@ bool Unit::AttackStop()
if (creature->HasSearchedAssistance())
{
creature->SetNoSearchAssistance(false);
UpdateSpeed(MOVE_RUN, false);
}
}
@@ -13496,11 +13495,23 @@ void Unit::UpdateSpeed(UnitMoveType mtype, bool forced)
break;
}
// for creature case, we check explicit if mob searched for assistance
if (GetTypeId() == TYPEID_UNIT)
int32 slowFromHealth = 0;
Creature* creature = ToCreature();
// ignore pets, player owned vehicles, and mobs immune to snare
if (creature
&& !IsPet()
&& !(IsControlledByPlayer() && IsVehicle())
&& !(creature->HasMechanicTemplateImmunity(MECHANIC_SNARE))
&& !(creature->IsDungeonBoss()))
{
if (ToCreature()->HasSearchedAssistance())
speed *= 0.66f; // best guessed value, so this will be 33% reduction. Based off initial speed, mob can then "run", "walk fast" or "walk".
// 1.6% for each % under 30.
// use min(0, health-30) so that we don't boost mobs above 30.
slowFromHealth = (int32) std::min(0.0f, (1.66f * (GetHealthPct() - 30.0f)));
}
if (slowFromHealth)
{
AddPct(speed, slowFromHealth);
}
// Apply strongest slow aura mod to speed
@@ -14566,8 +14577,16 @@ void Unit::SetHealth(uint32 val)
val = maxHealth;
}
float prevHealthPct = GetHealthPct();
SetUInt32Value(UNIT_FIELD_HEALTH, val);
// mobs that are now or were below 30% need to update their speed
if (GetTypeId() == TYPEID_UNIT && (prevHealthPct < 30.0 || HealthBelowPct(30)))
{
UpdateSpeed(MOVE_RUN, false);
}
// group update
if (GetTypeId() == TYPEID_PLAYER)
{

View File

@@ -115,9 +115,6 @@ namespace Movement
moveFlagsForSpeed &= ~MOVEMENTFLAG_WALKING;
args.velocity = unit->GetSpeed(SelectSpeedType(moveFlagsForSpeed));
if (Creature* creature = unit->ToCreature())
if (creature->HasSearchedAssistance())
args.velocity *= 0.66f;
}
// limit the speed in the same way the client does