Skip to content

Commit

Permalink
Pet adjustments
Browse files Browse the repository at this point in the history
The first parameter for SetInCombatsate was a PvP bool and so setting it
to true was wrong, it should be depending on the target.

Also with attackstop we do want to interrupt spell casting (which is the
second bool)

Only players and player pets use PetAI and PetHandler,
so anything related to creature pets can be pulled out
  • Loading branch information
Phatcat committed Aug 24, 2016
1 parent 0897af9 commit 23d23ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 40 deletions.
19 changes: 8 additions & 11 deletions src/game/PetAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void PetAI::MoveInLineOfSight(Unit* u)
AttackStart(u);

if (Unit* owner = m_creature->GetOwner())
owner->SetInCombatState(true, u);
owner->SetInCombatState((u->GetTypeId() == TYPEID_PLAYER), u);
}
}

Expand Down Expand Up @@ -99,7 +99,7 @@ void PetAI::UpdateAI(const uint32 diff)
Unit* owner = m_creature->GetCharmerOrOwner();
Unit* victim = nullptr;

if (((Pet*)m_creature)->isControlled())
if (!((Pet*)m_creature)->isControlled())
m_creature->SelectHostileTarget();

// Creature pets and guardians will always look in threat list for victim
Expand All @@ -115,7 +115,7 @@ void PetAI::UpdateAI(const uint32 diff)

if (inCombat && !victim)
{
m_creature->AttackStop(true, false);
m_creature->AttackStop(true, true);
inCombat = false;
}

Expand Down Expand Up @@ -218,9 +218,9 @@ void PetAI::UpdateAI(const uint32 diff)

Spell* spell = new Spell(m_creature, spellInfo, false);

if (inCombat && !m_creature->hasUnitState(UNIT_STAT_FOLLOW) && spell->CanAutoCast(m_creature->getVictim()))
if (inCombat && !m_creature->hasUnitState(UNIT_STAT_FOLLOW) && spell->CanAutoCast(victim))
{
targetSpellStore.push_back(TargetSpellList::value_type(m_creature->getVictim(), spell));
targetSpellStore.push_back(TargetSpellList::value_type(victim, spell));
continue;
}
else
Expand Down Expand Up @@ -278,13 +278,11 @@ void PetAI::UpdateAI(const uint32 diff)
for (TargetSpellList::const_iterator itr = targetSpellStore.begin(); itr != targetSpellStore.end(); ++itr)
delete itr->second;
}
else if (m_creature->hasUnitState(UNIT_STAT_FOLLOW_MOVE))
m_creature->InterruptNonMeleeSpells(false);

if (((Pet*)m_creature)->isControlled())
// Guardians will always look in threat list for victim
if (!((Pet*)m_creature)->isControlled())
m_creature->SelectHostileTarget();

// Creature pets and guardians will always look in threat list for victim
if (!(m_creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE)
|| (m_creature->IsPet() && ((Pet*)m_creature)->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)))
victim = m_creature->getVictim();
Expand All @@ -293,8 +291,7 @@ void PetAI::UpdateAI(const uint32 diff)
{
// i_pet.getVictim() can't be used for check in case stop fighting, i_pet.getVictim() clear at Unit death etc.
// This is needed for charmed creatures, as once their target was reset other effects can trigger threat
if ((m_creature->isCharmed() && victim == m_creature->GetCharmer())
|| !victim->isTargetableForAttack())
if ((m_creature->isCharmed() && victim == m_creature->GetCharmer()) || !victim->isTargetableForAttack())
{
DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "PetAI (guid = %u) is stopping attack.", m_creature->GetGUIDLow());
m_creature->CombatStop();
Expand Down
33 changes: 4 additions & 29 deletions src/game/PetHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)
if (!pet->isAlive())
return;

if (pet->GetTypeId() == TYPEID_PLAYER && pet->GetCharmer()->GetTypeId() == TYPEID_PLAYER)
if (pet->GetTypeId() == TYPEID_PLAYER)
{
// controller player cannot use controlled player's spells
if (flag != (ACT_COMMAND || ACT_REACTION))
// controller player can only do melee attack
if (!(flag == ACT_COMMAND && spellid == COMMAND_ATTACK))
return;
}
else if (((Creature*)pet)->IsPet())
Expand Down Expand Up @@ -116,7 +116,7 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)

if (targetUnit && targetUnit != pet && targetUnit->isTargetableForAttack() && targetUnit->isInAccessablePlaceFor((Creature*)pet))
{
_player->SetInCombatState(true, targetUnit);
_player->SetInCombatState((targetUnit->GetTypeId() == TYPEID_PLAYER), targetUnit);

// This is true if pet has no target or has target but targets differs.
if (pet->getVictim() != targetUnit)
Expand Down Expand Up @@ -272,31 +272,6 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)

unit_target = spell->m_targets.getUnitTarget();

if (unit_target && !GetPlayer()->IsFriendlyTo(unit_target) && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS))
{
// This is true if pet has no target or has target but targets differs.
if (pet->getVictim() != unit_target)
{
pet->AttackStop();
pet->GetMotionMaster()->Clear();

_player->SetInCombatState(true, unit_target);

if (((Creature*)pet)->AI())
{
((Creature*)pet)->AI()->AttackStart(unit_target);
// 10% chance to play special warlock pet attack talk, else growl
if (((Creature*)pet)->IsPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != unit_target && roll_chance_i(10))
pet->SendPetTalk((uint32)PET_TALK_ATTACK);

pet->SendPetAIReaction();
}

else
pet->Attack(unit_target, true);
}
}

((Pet*)pet)->SetSpellOpener();
spell->SpellStart(&(spell->m_targets));
}
Expand Down

0 comments on commit 23d23ec

Please sign in to comment.