aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorccrs <ccrs@users.noreply.github.com>2019-05-17 00:18:09 +0200
committerShauren <shauren.trinity@gmail.com>2021-12-05 18:40:05 +0100
commit86b4aa01bb31067e788b6ccffccd04a9901d779b (patch)
tree4ec3c56ec51927e079295afd0951bbe9f9d72b47
parentcb9a1c38f17e31c74855bc6e77d73c6c057b9f7f (diff)
Core/AI: PetAI method reordering
(cherry picked from commit acbfac7b1321f0b23f601df531af9958a369ea2f)
-rw-r--r--src/server/game/AI/CoreAI/PetAI.cpp143
-rw-r--r--src/server/game/AI/CoreAI/PetAI.h4
2 files changed, 74 insertions, 73 deletions
diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp
index 006fad0acf3..7c46ed4aa6c 100644
--- a/src/server/game/AI/CoreAI/PetAI.cpp
+++ b/src/server/game/AI/CoreAI/PetAI.cpp
@@ -48,38 +48,8 @@ PetAI::PetAI(Creature* creature, uint32 scriptId) : CreatureAI(creature, scriptI
{
if (!me->GetCharmInfo())
throw InvalidAIException("Creature doesn't have a valid charm info");
- UpdateAllies();
-}
-
-bool PetAI::NeedToStop()
-{
- // This is needed for charmed creatures, as once their target was reset other effects can trigger threat
- if (me->IsCharmed() && me->GetVictim() == me->GetCharmer())
- return true;
-
- // dont allow pets to follow targets far away from owner
- if (Unit* owner = me->GetCharmerOrOwner())
- if (owner->GetExactDist(me) >= (owner->GetVisibilityRange()-10.0f))
- return true;
-
- return !me->IsValidAttackTarget(me->GetVictim());
-}
-
-void PetAI::StopAttack()
-{
- if (!me->IsAlive())
- {
- me->GetMotionMaster()->Clear();
- me->GetMotionMaster()->MoveIdle();
- me->CombatStop();
- return;
- }
- me->AttackStop();
- me->InterruptNonMeleeSpells(false);
- me->GetCharmInfo()->SetIsCommandAttack(false);
- ClearCharmInfoFlags();
- HandleReturnMovement();
+ UpdateAllies();
}
void PetAI::UpdateAI(uint32 diff)
@@ -260,46 +230,6 @@ void PetAI::UpdateAI(uint32 diff)
}
-void PetAI::UpdateAllies()
-{
- _updateAlliesTimer = 10 * IN_MILLISECONDS; // update friendly targets every 10 seconds, lesser checks increase performance
-
- Unit* owner = me->GetCharmerOrOwner();
- if (!owner)
- return;
-
- Group* group = nullptr;
- if (Player* player = owner->ToPlayer())
- group = player->GetGroup();
-
- // only pet and owner/not in group->ok
- if (_allySet.size() == 2 && !group)
- return;
-
- // owner is in group; group members filled in already (no raid -> subgroupcount = whole count)
- if (group && !group->isRaidGroup() && _allySet.size() == (group->GetMembersCount() + 2))
- return;
-
- _allySet.clear();
- _allySet.insert(me->GetGUID());
- if (group) // add group
- {
- for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next())
- {
- Player* Target = itr->GetSource();
- if (!Target || !Target->IsInMap(owner) || !group->SameSubGroup(owner->ToPlayer(), Target))
- continue;
-
- if (Target->GetGUID() == owner->GetGUID())
- continue;
-
- _allySet.insert(Target->GetGUID());
- }
- }
- else // remove group
- _allySet.insert(owner->GetGUID());
-}
-
void PetAI::KilledUnit(Unit* victim)
{
// Called from Unit::Kill() in case where pet or owner kills something
@@ -624,6 +554,77 @@ void PetAI::ReceiveEmote(Player* player, uint32 emote)
}
}
+bool PetAI::NeedToStop()
+{
+ // This is needed for charmed creatures, as once their target was reset other effects can trigger threat
+ if (me->IsCharmed() && me->GetVictim() == me->GetCharmer())
+ return true;
+
+ // dont allow pets to follow targets far away from owner
+ if (Unit* owner = me->GetCharmerOrOwner())
+ if (owner->GetExactDist(me) >= (owner->GetVisibilityRange() - 10.0f))
+ return true;
+
+ return !me->IsValidAttackTarget(me->GetVictim());
+}
+
+void PetAI::StopAttack()
+{
+ if (!me->IsAlive())
+ {
+ me->GetMotionMaster()->Clear();
+ me->GetMotionMaster()->MoveIdle();
+ me->CombatStop();
+ return;
+ }
+
+ me->AttackStop();
+ me->InterruptNonMeleeSpells(false);
+ me->GetCharmInfo()->SetIsCommandAttack(false);
+ ClearCharmInfoFlags();
+ HandleReturnMovement();
+}
+
+void PetAI::UpdateAllies()
+{
+ _updateAlliesTimer = 10 * IN_MILLISECONDS; // update friendly targets every 10 seconds, lesser checks increase performance
+
+ Unit* owner = me->GetCharmerOrOwner();
+ if (!owner)
+ return;
+
+ Group* group = nullptr;
+ if (Player* player = owner->ToPlayer())
+ group = player->GetGroup();
+
+ // only pet and owner/not in group->ok
+ if (_allySet.size() == 2 && !group)
+ return;
+
+ // owner is in group; group members filled in already (no raid -> subgroupcount = whole count)
+ if (group && !group->isRaidGroup() && _allySet.size() == (group->GetMembersCount() + 2))
+ return;
+
+ _allySet.clear();
+ _allySet.insert(me->GetGUID());
+ if (group) // add group
+ {
+ for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next())
+ {
+ Player* Target = itr->GetSource();
+ if (!Target || !Target->IsInMap(owner) || !group->SameSubGroup(owner->ToPlayer(), Target))
+ continue;
+
+ if (Target->GetGUID() == owner->GetGUID())
+ continue;
+
+ _allySet.insert(Target->GetGUID());
+ }
+ }
+ else // remove group
+ _allySet.insert(owner->GetGUID());
+}
+
void PetAI::ClearCharmInfoFlags()
{
CharmInfo* ci = me->GetCharmInfo();
diff --git a/src/server/game/AI/CoreAI/PetAI.h b/src/server/game/AI/CoreAI/PetAI.h
index 4ce30b1f93f..4d083b2b90a 100644
--- a/src/server/game/AI/CoreAI/PetAI.h
+++ b/src/server/game/AI/CoreAI/PetAI.h
@@ -29,11 +29,11 @@ typedef std::vector<std::pair<Unit*, Spell*>> TargetSpellList;
class TC_GAME_API PetAI : public CreatureAI
{
public:
+ static int32 Permissible(Creature const* creature);
+
explicit PetAI(Creature* creature, uint32 scriptId = {});
void UpdateAI(uint32) override;
- static int32 Permissible(Creature const* creature);
-
void KilledUnit(Unit* /*victim*/) override;
// only start attacking if not attacking something else already
void AttackStart(Unit* target) override;