Skip to content

Commit

Permalink
PetHandler cleanup and hotfix
Browse files Browse the repository at this point in the history
Simplify and improve codeflow of PetHandler
and fix bug in pet stay
  • Loading branch information
Phatcat committed Jun 18, 2016
1 parent 1a6fda2 commit 9f64ca5
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions src/game/PetHandler.cpp
Expand Up @@ -86,18 +86,23 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)
switch (spellid)
{
case COMMAND_STAY: // flat=1792 // STAY
{
pet->StopMoving();
pet->AttackStop();
pet->GetMotionMaster()->Clear(false);
pet->GetMotionMaster()->MoveIdle();
((Pet*)pet)->SetStayPosition();
charmInfo->SetCommandState(COMMAND_STAY);
break;
}
case COMMAND_FOLLOW: // spellid=1792 // FOLLOW
{
((Pet*)pet)->ClearStayPosition();
pet->AttackStop();
pet->GetMotionMaster()->MoveFollow(_player, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
charmInfo->SetCommandState(COMMAND_FOLLOW);
break;
}
case COMMAND_ATTACK: // spellid=1792 // ATTACK
{
Unit* TargetUnit = _player->GetMap()->GetUnit(targetGuid);
Expand All @@ -107,44 +112,32 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)
// not let attack friendly units.
if (GetPlayer()->IsFriendlyTo(TargetUnit))
return;
// Not let attack through obstructions
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();
pet->AttackStop();

if (pet->hasUnitState(UNIT_STAT_CONTROLLED))
{
pet->Attack(TargetUnit, true);
pet->SendPetAIReaction();
}
else
{
pet->GetMotionMaster()->Clear(!((Pet*)pet)->IsStayPosSet());
pet->GetMotionMaster()->Clear();

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

// 10% chance to play special pet attack talk, else growl
if (((Creature*)pet)->IsPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && roll_chance_i(10))
pet->SendPetTalk((uint32)PET_TALK_ATTACK);
else
{
// 90% chance for pet and 100% chance for charmed creature
pet->SendPetAIReaction();
}
}
pet->SendPetAIReaction();
}
else
pet->Attack(TargetUnit, true);

break;
}
case COMMAND_ABANDON: // abandon (hunter pet) or dismiss (summoned pet)
{
Creature* petC = (Creature*)pet;
if (petC->IsPet())

{
Pet* p = (Pet*)petC;
if (p->getPetType() == HUNTER_PET)
Expand Down Expand Up @@ -173,10 +166,14 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)
switch (spellid)
{
case REACT_PASSIVE: // passive
{
}
case REACT_DEFENSIVE: // recovery
case REACT_AGGRESSIVE: // activete
{
charmInfo->SetReactState(ReactStates(spellid));
break;
}
}
break;
case ACT_DISABLED: // 0x81 spell (disabled), ignore
Expand All @@ -200,7 +197,9 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)

for (int i = 0; i < MAX_EFFECT_INDEX; ++i)
{
if (spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_INSTANT || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_CHANNELED)
if (spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA
|| spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_INSTANT
|| spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_CHANNELED)
return;
}

Expand Down Expand Up @@ -255,11 +254,21 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)
// 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->AttackStop();
pet->GetMotionMaster()->Clear();

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);
}
}

Expand Down

0 comments on commit 9f64ca5

Please sign in to comment.