[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 else
m_updateAlliesTimer -= diff; m_updateAlliesTimer -= diff;
if (inCombat && i_pet.getVictim() == NULL) if (inCombat && !i_pet.getVictim())
_stopAttack(); _stopAttack();
// i_pet.getVictim() can't be used for check in case stop fighting, i_pet.getVictim() clear at Unit death etc. // 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() ) if( _needToStop() )
{ {

View file

@ -91,9 +91,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
break; break;
case COMMAND_ATTACK: //spellid=1792 //ATTACK case COMMAND_ATTACK: //spellid=1792 //ATTACK
{ {
// only place where pet can be player const uint64& selguid = _player->GetSelection();
pet->clearUnitState(UNIT_STAT_FOLLOW);
uint64 selguid = _player->GetSelection();
Unit *TargetUnit = ObjectAccessor::GetUnit(*_player, selguid); Unit *TargetUnit = ObjectAccessor::GetUnit(*_player, selguid);
if(!TargetUnit) if(!TargetUnit)
return; return;
@ -105,29 +103,33 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
if(!pet->IsWithinLOSInMap(TargetUnit)) if(!pet->IsWithinLOSInMap(TargetUnit))
return; return;
if(pet->getVictim()) // This is true if pet has no target or has target but targets differs.
pet->AttackStop(); if(pet->getVictim() != TargetUnit)
if(pet->GetTypeId() != TYPEID_PLAYER)
{ {
pet->GetMotionMaster()->Clear(); if (pet->getVictim())
if (((Creature*)pet)->AI()) pet->AttackStop();
((Creature*)pet)->AI()->AttackStart(TargetUnit);
//10% chance to play special pet attack talk, else growl if(pet->GetTypeId() != TYPEID_PLAYER)
if(((Creature*)pet)->isPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && urand(0, 100) < 10)
pet->SendPetTalk((uint32)PET_TALK_ATTACK);
else
{ {
// 90% chance for pet and 100% chance for charmed creature pet->GetMotionMaster()->Clear();
if (((Creature*)pet)->AI())
((Creature*)pet)->AI()->AttackStart(TargetUnit);
//10% chance to play special pet attack talk, else growl
if(((Creature*)pet)->isPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && urand(0, 100) < 10)
pet->SendPetTalk((uint32)PET_TALK_ATTACK);
else
{
// 90% chance for pet and 100% chance for charmed creature
pet->SendPetAIReaction(guid1);
}
}
else // charmed player
{
pet->Attack(TargetUnit,true);
pet->SendPetAIReaction(guid1); pet->SendPetAIReaction(guid1);
} }
} }
else // charmed player
{
pet->Attack(TargetUnit,true);
pet->SendPetAIReaction(guid1);
}
break; break;
} }
case COMMAND_ABANDON: // abandon (hunter pet) or dismiss (summoned pet) 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_PASSIVE: // 0x0100
case ACT_ENABLED: // 0xC100 spell case ACT_ENABLED: // 0xC100 spell
{ {
Unit* unit_target; Unit* unit_target = NULL;
if(guid2)
unit_target = ObjectAccessor::GetUnit(*_player,guid2);
else
unit_target = NULL;
if (((Creature*)pet)->GetGlobalCooldown() > 0) if (((Creature*)pet)->GetGlobalCooldown() > 0)
return; return;
if(guid2)
unit_target = ObjectAccessor::GetUnit(*_player,guid2);
// do not cast unknown spells // do not cast unknown spells
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid ); SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid );
if(!spellInfo) if(!spellInfo)
@ -194,7 +194,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
int16 result = spell->PetCanCast(unit_target); int16 result = spell->PetCanCast(unit_target);
//auto turn to target unless possessed //auto turn to target unless possessed
if(result == SPELL_FAILED_UNIT_NOT_INFRONT && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS)) if(result == SPELL_FAILED_UNIT_NOT_INFRONT && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS))
{ {
pet->SetInFront(unit_target); pet->SetInFront(unit_target);
@ -225,12 +225,15 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
if( unit_target && !GetPlayer()->IsFriendlyTo(unit_target) && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS)) 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()) if (pet->getVictim() != unit_target)
pet->AttackStop(); {
pet->GetMotionMaster()->Clear(); if (pet->getVictim())
if (((Creature*)pet)->AI()) pet->AttackStop();
((Creature*)pet)->AI()->AttackStart(unit_target); pet->GetMotionMaster()->Clear();
if (((Creature*)pet)->AI())
((Creature*)pet)->AI()->AttackStart(unit_target);
}
} }
spell->prepare(&(spell->m_targets)); spell->prepare(&(spell->m_targets));
@ -575,10 +578,10 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
if(!_player->GetPet() && !_player->GetCharm()) if(!_player->GetPet() && !_player->GetCharm())
return; return;
if(ObjectAccessor::FindPlayer(guid)) if (GUID_HIPART(guid) == HIGHGUID_PLAYER)
return; return;
Creature* pet=ObjectAccessor::GetCreatureOrPet(*_player,guid); Creature* pet = ObjectAccessor::GetCreatureOrPet(*_player,guid);
if(!pet || (pet != _player->GetPet() && pet!= _player->GetCharm())) if(!pet || (pet != _player->GetPet() && pet!= _player->GetCharm()))
{ {

View file

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