[7128] Cleanup in PetHandler.cpp and little PetAI.cpp

Fixed: pet stop attacking when casts spell by command.

Signed-off-by: ApoC <apoc@nymfe.net>
This commit is contained in:
ApoC 2009-01-21 01:29:08 +01:00
parent 9e1b9e56fd
commit 03b7d1006a
3 changed files with 41 additions and 38 deletions

View file

@ -139,11 +139,11 @@ void PetAI::UpdateAI(const uint32 diff)
else
m_updateAlliesTimer -= diff;
if (inCombat && i_pet.getVictim() == NULL)
if (inCombat && !i_pet.getVictim())
_stopAttack();
// i_pet.getVictim() can't be used for check in case stop fighting, i_pet.getVictim() clear at Unit death etc.
if( i_pet.getVictim() != NULL )
if( i_pet.getVictim() )
{
if( _needToStop() )
{

View file

@ -91,9 +91,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
break;
case COMMAND_ATTACK: //spellid=1792 //ATTACK
{
// only place where pet can be player
pet->clearUnitState(UNIT_STAT_FOLLOW);
uint64 selguid = _player->GetSelection();
const uint64& selguid = _player->GetSelection();
Unit *TargetUnit = ObjectAccessor::GetUnit(*_player, selguid);
if(!TargetUnit)
return;
@ -105,6 +103,9 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
if(!pet->IsWithinLOSInMap(TargetUnit))
return;
// This is true if pet has no target or has target but targets differs.
if(pet->getVictim() != TargetUnit)
{
if (pet->getVictim())
pet->AttackStop();
@ -128,6 +129,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
pet->Attack(TargetUnit,true);
pet->SendPetAIReaction(guid1);
}
}
break;
}
case COMMAND_ABANDON: // abandon (hunter pet) or dismiss (summoned pet)
@ -161,15 +163,13 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
case ACT_PASSIVE: // 0x0100
case ACT_ENABLED: // 0xC100 spell
{
Unit* unit_target;
if(guid2)
unit_target = ObjectAccessor::GetUnit(*_player,guid2);
else
unit_target = NULL;
Unit* unit_target = NULL;
if (((Creature*)pet)->GetGlobalCooldown() > 0)
return;
if(guid2)
unit_target = ObjectAccessor::GetUnit(*_player,guid2);
// do not cast unknown spells
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid );
if(!spellInfo)
@ -225,13 +225,16 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
if( unit_target && !GetPlayer()->IsFriendlyTo(unit_target) && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS))
{
pet->clearUnitState(UNIT_STAT_FOLLOW);
// This is true if pet has no target or has target but targets differs.
if (pet->getVictim() != unit_target)
{
if (pet->getVictim())
pet->AttackStop();
pet->GetMotionMaster()->Clear();
if (((Creature*)pet)->AI())
((Creature*)pet)->AI()->AttackStart(unit_target);
}
}
spell->prepare(&(spell->m_targets));
}
@ -575,7 +578,7 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
if(!_player->GetPet() && !_player->GetCharm())
return;
if(ObjectAccessor::FindPlayer(guid))
if (GUID_HIPART(guid) == HIGHGUID_PLAYER)
return;
Creature* pet = ObjectAccessor::GetCreatureOrPet(*_player,guid);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "7127"
#define REVISION_NR "7128"
#endif // __REVISION_NR_H__