[9197] More propertly update walk mode for player pets.

* Use AddMonsterMoveFlag instead SetMonsterMoveFlags for set walk-mode
* Apply walk/run mode to all copntrolled units (except totems).
* Synchronize walk/run mode at pet creating/loading.
This commit is contained in:
VladimirMangos 2010-01-17 07:48:04 +03:00
parent b0809f63b2
commit 2e9bf5ad6a
6 changed files with 43 additions and 25 deletions

View file

@ -300,27 +300,7 @@ void WorldSession::HandleMovementOpcodes( WorldPacket & recv_data )
plMover->HandleFall(movementInfo);
if ((opcode == MSG_MOVE_SET_WALK_MODE || opcode == MSG_MOVE_SET_RUN_MODE) && plMover)
{
Pet* pPet = plMover->GetPet();
Pet* pMiniPet = plMover->GetMiniPet();
if (movementInfo.HasMovementFlag(MOVEMENTFLAG_WALK_MODE))
{
if (pPet && !pPet->isInCombat())
pPet->SetMonsterMoveFlags(MONSTER_MOVE_WALK);
if (pMiniPet)
pMiniPet->SetMonsterMoveFlags(MONSTER_MOVE_WALK);
}
else
{
if (pPet)
pPet->RemoveMonsterMoveFlag(MONSTER_MOVE_WALK);
if (pMiniPet)
pMiniPet->RemoveMonsterMoveFlag(MONSTER_MOVE_WALK);
}
}
plMover->UpdateWalkModeForPets(movementInfo.HasMovementFlag(MOVEMENTFLAG_WALK_MODE));
if (plMover && (movementInfo.HasMovementFlag(MOVEMENTFLAG_SWIMMING) != plMover->IsInWater()))
{

View file

@ -293,6 +293,8 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana);
}
UpdateWalkModeForPets(owner->HasMovementFlag(MOVEMENTFLAG_WALK_MODE));
AIM_Initialize();
map->Add((Creature*)this);

View file

@ -3548,6 +3548,9 @@ void Spell::EffectSummon(uint32 i)
spawnCreature->InitStatsForLevel(level, m_caster);
spawnCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
if (m_caster->GetTypeId() == TYPEID_PLAYER)
spawnCreature->UpdateWalkModeForPets(((Player*)m_caster)->HasMovementFlag(MOVEMENTFLAG_WALK_MODE));
spawnCreature->AIM_Initialize();
spawnCreature->InitPetCreateSpells();
@ -4415,6 +4418,9 @@ void Spell::EffectSummonPet(uint32 i)
NewSummon->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
NewSummon->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
if (m_caster->GetTypeId() == TYPEID_PLAYER)
NewSummon->UpdateWalkModeForPets(((Player*)m_caster)->HasMovementFlag(MOVEMENTFLAG_WALK_MODE));
NewSummon->GetCharmInfo()->SetPetNumber(pet_number, true);
// this enables pet details window (Shift+P)

View file

@ -3347,10 +3347,10 @@ void Unit::SetInFront(Unit const* target)
SetOrientation(GetAngle(target));
}
void Unit::SetFacingToObject(WorldObject* pObject)
void Unit::SetFacingTo(float ori)
{
// update orientation at server
SetOrientation(GetAngle(pObject));
SetOrientation(ori);
// and client
WorldPacket data;
@ -10394,6 +10394,34 @@ bool Unit::canDetectInvisibilityOf(Unit const* u) const
return false;
}
struct UpdateWalkModeForPetsHelper
{
explicit UpdateWalkModeForPetsHelper(bool _on) : on(_on) {}
void operator()(Unit* unit) const { unit->UpdateWalkModeForPets(on); }
bool on;
};
void Unit::UpdateWalkModeForPets(bool on)
{
if (GetTypeId() == TYPEID_PLAYER)
((Player*)this)->CallForAllControlledUnits(UpdateWalkModeForPetsHelper(on),false,true,true,true);
else
{
if (on)
{
if (((Creature*)this)->isPet() && hasUnitState(UNIT_STAT_FOLLOW))
((Creature*)this)->AddMonsterMoveFlag(MONSTER_MOVE_WALK);
}
else
{
if (((Creature*)this)->isPet())
((Creature*)this)->RemoveMonsterMoveFlag(MONSTER_MOVE_WALK);
}
CallForAllControlledUnits(UpdateWalkModeForPetsHelper(on),false,true,true);
}
}
void Unit::UpdateSpeed(UnitMoveType mtype, bool forced)
{
int32 main_speed_mod = 0;

View file

@ -1376,7 +1376,8 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
void SetBaseWeaponDamage(WeaponAttackType attType ,WeaponDamageRange damageRange, float value) { m_weaponDamage[attType][damageRange] = value; }
void SetInFront(Unit const* target);
void SetFacingToObject(WorldObject* pObject);
void SetFacingTo(float ori);
void SetFacingToObject(WorldObject* pObject) { SetFacingTo(GetAngle(pObject)); }
// Visibility system
UnitVisibility GetVisibility() const { return m_Visibility; }
@ -1523,6 +1524,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
uint32 CalcArmorReducedDamage(Unit* pVictim, const uint32 damage);
void CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist, bool canReflect = false);
void UpdateWalkModeForPets(bool on);
void UpdateSpeed(UnitMoveType mtype, bool forced);
float GetSpeed( UnitMoveType mtype ) const;
float GetSpeedRate( UnitMoveType mtype ) const { return m_speed_rate[mtype]; }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9196"
#define REVISION_NR "9197"
#endif // __REVISION_NR_H__