TrinityCore
PetAI.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_PETAI_H
19#define TRINITY_PETAI_H
20
21#include "CreatureAI.h"
22#include "Timer.h"
23
24class Creature;
25class Spell;
26
27typedef std::vector<std::pair<Unit*, Spell*>> TargetSpellList;
28
30{
31 public:
32 static int32 Permissible(Creature const* creature);
33
34 explicit PetAI(Creature* creature, uint32 scriptId = {});
35
36 void UpdateAI(uint32) override;
37 void KilledUnit(Unit* /*victim*/) override;
38 // only start attacking if not attacking something else already
39 void AttackStart(Unit* target) override;
40 // always start attacking if possible
41 void _AttackStart(Unit* target);
42 void MovementInform(uint32 type, uint32 id) override;
43 void OwnerAttackedBy(Unit* attacker) override;
44 void OwnerAttacked(Unit* target) override;
45 void DamageTaken(Unit* attacker, uint32& /*damage*/, DamageEffectType /*damageType*/, SpellInfo const* /*spellInfo = nullptr*/) override { AttackStart(attacker); }
46 void ReceiveEmote(Player* player, uint32 textEmote) override;
47 void JustEnteredCombat(Unit* who) override { EngagementStart(who); }
48 void JustExitedCombat() override { EngagementOver(); }
49 void OnCharmed(bool isNew) override;
50
51 // The following aren't used by the PetAI but need to be defined to override
52 // default CreatureAI functions which interfere with the PetAI
53
54 void MoveInLineOfSight(Unit* /*who*/) override { } // CreatureAI interferes with returning pets
55 void MoveInLineOfSight_Safe(Unit* /*who*/) { } // CreatureAI interferes with returning pets
56 void JustAppeared() override { } // we will control following manually
57 void EnterEvadeMode(EvadeReason /*why*/) override { } // For fleeing, pets don't use this type of Evade mechanic
58
59 private:
60 bool NeedToStop();
61 void StopAttack();
62 void UpdateAllies();
63 Unit* SelectNextTarget(bool allowAutoSelect) const;
64 void HandleReturnMovement();
65 void DoAttack(Unit* target, bool chase);
66 bool CanAttack(Unit* target);
67 // Quick access to set all flags to FALSE
68 void ClearCharmInfoFlags();
69
73};
74
75#endif
#define TC_GAME_API
Definition: Define.h:123
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
std::set< ObjectGuid > GuidSet
Definition: ObjectGuid.h:393
std::vector< std::pair< Unit *, Spell * > > TargetSpellList
Definition: PetAI.h:27
EvadeReason
Definition: UnitAICommon.h:30
DamageEffectType
Definition: UnitDefines.h:131
virtual void OwnerAttacked(Unit *target)
Definition: CreatureAI.h:171
virtual void MovementInform(uint32, uint32)
Definition: CreatureAI.h:154
virtual void OwnerAttackedBy(Unit *attacker)
Definition: CreatureAI.h:168
virtual void KilledUnit(Unit *)
Definition: CreatureAI.h:108
virtual void ReceiveEmote(Player *, uint32)
Definition: CreatureAI.h:165
void OnCharmed(bool isNew) override
Definition: CreatureAI.cpp:62
void AttackStart(Unit *victim) override
== Triggered Actions Requested ==================
Definition: CreatureAI.cpp:328
void EngagementStart(Unit *who)
Definition: CreatureAI.cpp:275
void EngagementOver()
Definition: CreatureAI.cpp:287
Definition: PetAI.h:30
uint32 _updateAlliesTimer
Definition: PetAI.h:72
void EnterEvadeMode(EvadeReason) override
Definition: PetAI.h:57
void MoveInLineOfSight(Unit *) override
Definition: PetAI.h:54
TimeTracker _tracker
Definition: PetAI.h:70
void JustExitedCombat() override
Definition: PetAI.h:48
void JustAppeared() override
Definition: PetAI.h:56
void JustEnteredCombat(Unit *who) override
Definition: PetAI.h:47
GuidSet _allySet
Definition: PetAI.h:71
void DamageTaken(Unit *attacker, uint32 &, DamageEffectType, SpellInfo const *) override
Definition: PetAI.h:45
void MoveInLineOfSight_Safe(Unit *)
Definition: PetAI.h:55
Definition: Spell.h:255
virtual void UpdateAI(uint32 diff)=0
Definition: Unit.h:627