[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

@ -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,29 +103,33 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
if(!pet->IsWithinLOSInMap(TargetUnit))
return;
if(pet->getVictim())
pet->AttackStop();
if(pet->GetTypeId() != TYPEID_PLAYER)
// This is true if pet has no target or has target but targets differs.
if(pet->getVictim() != TargetUnit)
{
pet->GetMotionMaster()->Clear();
if (((Creature*)pet)->AI())
((Creature*)pet)->AI()->AttackStart(TargetUnit);
if (pet->getVictim())
pet->AttackStop();
//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
if(pet->GetTypeId() != TYPEID_PLAYER)
{
// 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);
}
}
else // charmed player
{
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)
@ -194,7 +194,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
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))
{
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))
{
pet->clearUnitState(UNIT_STAT_FOLLOW);
if(pet->getVictim())
pet->AttackStop();
pet->GetMotionMaster()->Clear();
if (((Creature*)pet)->AI())
((Creature*)pet)->AI()->AttackStart(unit_target);
// 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,10 +578,10 @@ 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);
Creature* pet = ObjectAccessor::GetCreatureOrPet(*_player,guid);
if(!pet || (pet != _player->GetPet() && pet!= _player->GetCharm()))
{