Merge pull request #8753 from MrSmite/Pet_SpeedFix

Fix pets lagging behind and despawning
This commit is contained in:
Subv committed 2013-01-03 17:04:50 -08:00
commit ef9f2aca0d
2 files changed
+26 -2

No files matched your search

+6
View File
@@ -251,6 +251,12 @@ void PetAI::UpdateAI(const uint32 diff)
for (TargetSpellList::const_iterator itr = targetSpellStore.begin(); itr != targetSpellStore.end(); ++itr)
delete itr->second;
}
// Update speed as needed to prevent dropping too far behind and despawning
me->UpdateSpeed(MOVE_RUN, true);
me->UpdateSpeed(MOVE_WALK, true);
me->UpdateSpeed(MOVE_FLIGHT, true);
}
void PetAI::UpdateAllies()
+20 -2
View File
@@ -12712,9 +12712,27 @@ void Unit::UpdateSpeed(UnitMoveType mtype, bool forced)
case MOVE_SWIM:
case MOVE_FLIGHT:
{
// Set creature speed rate from CreatureInfo
// Set creature speed rate
if (GetTypeId() == TYPEID_UNIT)
speed *= ToCreature()->GetCreatureTemplate()->speed_run; // at this point, MOVE_WALK is never reached
{
Unit* pOwner = GetCharmerOrOwner();
if (isPet() && !isInCombat() && pOwner) // Must check for owner or crash on "Tame Beast"
{
// For every yard over 5, increase speed by 0.01
// to help prevent pet from lagging behind and despawning
float dist = GetDistance(pOwner);
float base_rate = 1.00f; // base speed is 100% of owner speed
if (dist < 5)
dist = 5;
float mult = base_rate + ((dist - 5) * 0.01f);
speed *= pOwner->GetSpeedRate(mtype) * mult; // pets derive speed from owner when not in combat
}
else
speed *= ToCreature()->GetCreatureTemplate()->speed_run; // at this point, MOVE_WALK is never reached
}
// Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need
// TODO: possible affect only on MOVE_RUN