aboutsummaryrefslogtreecommitdiff
path: root/src/server/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game')
-rw-r--r--src/server/game/AI/PlayerAI/PlayerAI.cpp36
-rw-r--r--src/server/game/AI/PlayerAI/PlayerAI.h25
2 files changed, 43 insertions, 18 deletions
diff --git a/src/server/game/AI/PlayerAI/PlayerAI.cpp b/src/server/game/AI/PlayerAI/PlayerAI.cpp
index 2a660fc31d7..d670df82528 100644
--- a/src/server/game/AI/PlayerAI/PlayerAI.cpp
+++ b/src/server/game/AI/PlayerAI/PlayerAI.cpp
@@ -16,6 +16,10 @@
*/
#include "PlayerAI.h"
+#include "Creature.h"
+#include "ObjectAccessor.h"
+#include "Player.h"
+#include "Spell.h"
#include "SpellAuras.h"
#include "SpellAuraEffects.h"
@@ -383,6 +387,25 @@ enum Spells
SPELL_LIFEBLOOM = 48451
};
+PlayerAI::PlayerAI(Player* player) : UnitAI(player), me(player),
+ _selfSpec(player->GetUInt32Value(PLAYER_FIELD_CURRENT_SPEC_ID)),
+ _isSelfHealer(PlayerAI::IsPlayerHealer(player)),
+ _isSelfRangedAttacker(PlayerAI::IsPlayerRangedAttacker(player))
+{
+}
+
+Creature* PlayerAI::GetCharmer() const
+{
+ if (me->GetCharmerGUID().IsCreature())
+ return ObjectAccessor::GetCreature(*me, me->GetCharmerGUID());
+ return nullptr;
+}
+
+uint16 PlayerAI::GetSpec(Player const* who /*= nullptr*/) const
+{
+ return (!who || who == me) ? _selfSpec : who->GetUInt32Value(PLAYER_FIELD_CURRENT_SPEC_ID);
+}
+
bool PlayerAI::IsPlayerHealer(Player const* who)
{
if (!who)
@@ -543,6 +566,13 @@ PlayerAI::TargetedSpell PlayerAI::SelectSpellCast(PossibleSpellVector& spells)
return selected;
}
+void PlayerAI::DoCastAtTarget(TargetedSpell spell)
+{
+ SpellCastTargets targets;
+ targets.SetUnitTarget(spell.second);
+ spell.first->prepare(&targets);
+}
+
void PlayerAI::DoRangedAttackIfReady()
{
if (me->HasUnitState(UNIT_STATE_CASTING))
@@ -614,6 +644,11 @@ void PlayerAI::CancelAllShapeshifts()
me->RemoveOwnedAura(aura, AURA_REMOVE_BY_CANCEL);
}
+Unit* PlayerAI::SelectAttackTarget() const
+{
+ return me->GetCharmer() ? me->GetCharmer()->GetVictim() : nullptr;
+}
+
struct UncontrolledTargetSelectPredicate : public std::unary_function<Unit*, bool>
{
bool operator()(Unit const* target) const
@@ -621,6 +656,7 @@ struct UncontrolledTargetSelectPredicate : public std::unary_function<Unit*, boo
return !target->HasBreakableByDamageCrowdControlAura();
}
};
+
Unit* SimpleCharmedPlayerAI::SelectAttackTarget() const
{
if (Unit* charmer = me->GetCharmer())
diff --git a/src/server/game/AI/PlayerAI/PlayerAI.h b/src/server/game/AI/PlayerAI/PlayerAI.h
index 78c8c3c27b5..a89e262a10d 100644
--- a/src/server/game/AI/PlayerAI/PlayerAI.h
+++ b/src/server/game/AI/PlayerAI/PlayerAI.h
@@ -19,25 +19,19 @@
#define TRINITY_PLAYERAI_H
#include "UnitAI.h"
-#include "Player.h"
-#include "Spell.h"
-#include "Creature.h"
+
+class Spell;
class TC_GAME_API PlayerAI : public UnitAI
{
public:
- explicit PlayerAI(Player* player) : UnitAI(player), me(player), _selfSpec(player->GetUInt32Value(PLAYER_FIELD_CURRENT_SPEC_ID)), _isSelfHealer(PlayerAI::IsPlayerHealer(player)), _isSelfRangedAttacker(PlayerAI::IsPlayerRangedAttacker(player)) { }
+ explicit PlayerAI(Player* player);
void OnCharmed(bool /*apply*/) override { } // charm AI application for players is handled by Unit::SetCharmedBy / Unit::RemoveCharmedBy
- Creature* GetCharmer() const
- {
- if (me->GetCharmerGUID().IsCreature())
- return ObjectAccessor::GetCreature(*me, me->GetCharmerGUID());
- return nullptr;
- }
+ Creature* GetCharmer() const;
// helper functions to determine player info
- uint16 GetSpec(Player const* who = nullptr) const { return (!who || who == me) ? _selfSpec : who->GetUInt32Value(PLAYER_FIELD_CURRENT_SPEC_ID); }
+ uint16 GetSpec(Player const* who = nullptr) const;
static bool IsPlayerHealer(Player const* who);
bool IsHealer(Player const* who = nullptr) const { return (!who || who == me) ? _isSelfHealer : IsPlayerHealer(who); }
static bool IsPlayerRangedAttacker(Player const* who);
@@ -81,14 +75,9 @@ class TC_GAME_API PlayerAI : public UnitAI
This invalidates the vector, and empties it to prevent accidental misuse. */
TargetedSpell SelectSpellCast(PossibleSpellVector& spells);
/* Helper method - casts the included spell at the included target */
- inline void DoCastAtTarget(TargetedSpell spell)
- {
- SpellCastTargets targets;
- targets.SetUnitTarget(spell.second);
- spell.first->prepare(&targets);
- }
+ void DoCastAtTarget(TargetedSpell spell);
- virtual Unit* SelectAttackTarget() const { return me->GetCharmer() ? me->GetCharmer()->GetVictim() : nullptr; }
+ virtual Unit* SelectAttackTarget() const;
void DoRangedAttackIfReady();
void DoAutoAttackIfReady();