summaryrefslogtreecommitdiff
path: root/src/server/game/AI/CreatureAI.h
blob: e485ca73ce123dbeef720ce5d43f74fe6f16e3e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Copyright (C) 2016+     AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*/

#ifndef ACORE_CREATUREAI_H
#define ACORE_CREATUREAI_H

#include "Common.h"
#include "Creature.h"
#include "UnitAI.h"

class WorldObject;
class Unit;
class Creature;
class Player;
class SpellInfo;

#define TIME_INTERVAL_LOOK   5000
#define VISIBILITY_RANGE    10000

//Spell targets used by SelectSpell
enum SelectTargetType
{
    SELECT_TARGET_DONTCARE = 0,                             //All target types allowed

    SELECT_TARGET_SELF,                                     //Only Self casting

    SELECT_TARGET_SINGLE_ENEMY,                             //Only Single Enemy
    SELECT_TARGET_AOE_ENEMY,                                //Only AoE Enemy
    SELECT_TARGET_ANY_ENEMY,                                //AoE or Single Enemy

    SELECT_TARGET_SINGLE_FRIEND,                            //Only Single Friend
    SELECT_TARGET_AOE_FRIEND,                               //Only AoE Friend
    SELECT_TARGET_ANY_FRIEND,                               //AoE or Single Friend
};

//Spell Effects used by SelectSpell
enum SelectEffect
{
    SELECT_EFFECT_DONTCARE = 0,                             //All spell effects allowed
    SELECT_EFFECT_DAMAGE,                                   //Spell does damage
    SELECT_EFFECT_HEALING,                                  //Spell does healing
    SELECT_EFFECT_AURA,                                     //Spell applies an aura
};

enum SCEquip
{
    EQUIP_NO_CHANGE = -1,
    EQUIP_UNEQUIP   = 0
};

class CreatureAI : public UnitAI
{
protected:
    Creature* const me;

    bool UpdateVictim();
    bool UpdateVictimWithGaze();

    void SetGazeOn(Unit* target);

    Creature* DoSummon(uint32 entry, Position const& pos, uint32 despawnTime = 30000, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
    Creature* DoSummon(uint32 entry, WorldObject* obj, float radius = 5.0f, uint32 despawnTime = 30000, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);
    Creature* DoSummonFlyer(uint32 entry, WorldObject* obj, float flightZ, float radius = 5.0f, uint32 despawnTime = 30000, TempSummonType summonType = TEMPSUMMON_CORPSE_TIMED_DESPAWN);

public:
    void Talk(uint8 id, WorldObject const* whisperTarget = nullptr);
    explicit CreatureAI(Creature* creature) : UnitAI(creature), me(creature), m_MoveInLineOfSight_locked(false) {}

    ~CreatureAI() override {}

    void MoveCircleChecks();
    void MoveBackwardsChecks();

    /// == Reactions At =================================

    // Called if IsVisible(Unit* who) is true at each who move, reaction at visibility zone enter
    void MoveInLineOfSight_Safe(Unit* who);

    // Trigger Creature "Alert" state (creature can see stealthed unit)
    void TriggerAlert(Unit const* who) const;

    // Called in Creature::Update when deathstate = DEAD. Inherited classes may maniuplate the ability to respawn based on scripted events.
    virtual bool CanRespawn() { return true; }

    // Called for reaction at stopping attack at no attackers or targets
    virtual void EnterEvadeMode();

    // Called for reaction at enter to combat if not in combat yet (enemy can be nullptr)
    virtual void EnterCombat(Unit* /*victim*/) {}

    // Called when the creature is killed
    virtual void JustDied(Unit* /*killer*/) {}

    // Called when the creature kills a unit
    virtual void KilledUnit(Unit* /*victim*/) {}

    // Called when the creature summon successfully other creature
    virtual void JustSummoned(Creature* /*summon*/) {}
    virtual void IsSummonedBy(Unit* /*summoner*/) {}

    virtual void SummonedCreatureDespawn(Creature* /*summon*/) {}
    virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) {}
    virtual void SummonedCreatureDespawnAll() {}

    // Called when hit by a spell
    virtual void SpellHit(Unit* /*caster*/, SpellInfo const* /*spell*/) {}

    // Called when spell hits a target
    virtual void SpellHitTarget(Unit* /*target*/, SpellInfo const* /*spell*/) {}

    // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
    virtual void AttackedBy(Unit* /*attacker*/) {}
    virtual bool IsEscorted() { return false; }

    // Called when creature is spawned or respawned (for reseting variables)
    virtual void JustRespawned() { Reset(); }

    // Called at waypoint reached or point movement finished
    virtual void MovementInform(uint32 /*type*/, uint32 /*id*/) {}

    void OnCharmed(bool apply) override;

    // Called at reaching home after evade
    virtual void JustReachedHome() {}

    void DoZoneInCombat(Creature* creature = nullptr, float maxRangeToNearestTarget = 50.0f);

    // Called at text emote receive from player
    virtual void ReceiveEmote(Player* /*player*/, uint32 /*emoteId*/) {}

    // Called when owner takes damage
    virtual void OwnerAttackedBy(Unit* /*attacker*/) {}

    // Called when owner attacks something
    virtual void OwnerAttacked(Unit* /*target*/) {}

    /// == Triggered Actions Requested ==================

    // Called when creature attack expected (if creature can and no have current victim)
    // Note: for reaction at hostile action must be called AttackedBy function.
    //virtual void AttackStart(Unit*) {}

    // Called at World update tick
    //virtual void UpdateAI(uint32 /*diff*/) {}

    /// == State checks =================================

    // Is unit visible for MoveInLineOfSight
    //virtual bool IsVisible(Unit*) const { return false; }

    // called when the corpse of this creature gets removed
    virtual void CorpseRemoved(uint32& /*respawnDelay*/) {}

    // Called when victim entered water and creature can not enter water
    //virtual bool CanReachByRangeAttack(Unit*) { return false; }

    /// == Fields =======================================
    virtual void PassengerBoarded(Unit* /*passenger*/, int8 /*seatId*/, bool /*apply*/) {}

    virtual void OnSpellClick(Unit* /*clicker*/, bool& /*result*/) { }

    virtual bool CanSeeAlways(WorldObject const* /*obj*/) { return false; }

    virtual bool CanBeSeen(Player const* /*seer*/) { return true; }

protected:
    virtual void MoveInLineOfSight(Unit* /*who*/);

    bool _EnterEvadeMode();

private:
    bool m_MoveInLineOfSight_locked;
};

enum Permitions
{
    PERMIT_BASE_NO                 = -1,
    PERMIT_BASE_IDLE               = 1,
    PERMIT_BASE_REACTIVE           = 100,
    PERMIT_BASE_PROACTIVE          = 200,
    PERMIT_BASE_FACTION_SPECIFIC   = 400,
    PERMIT_BASE_SPECIAL            = 800
};

#endif