TrinityCore
CreatureAIImpl.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#ifndef CREATUREAIIMPL_H
18#define CREATUREAIIMPL_H
19
20#include "Random.h"
21#include <type_traits>
22#include <functional>
23
24class WorldObject;
25enum Difficulty : uint8;
26
27template<typename First, typename Second, typename... Rest>
28inline First const& RAND(First const& first, Second const& second, Rest const&... rest)
29{
30 std::reference_wrapper<typename std::add_const<First>::type> const pack[] = { first, second, rest... };
31 return pack[urand(0, sizeof...(rest) + 1)].get();
32}
33
35{
42};
43
45{
49};
50
51#define AI_DEFAULT_COOLDOWN 5000
52
53// Spell targets used by SelectSpell
55{
56 SELECT_TARGET_DONTCARE = 0, // All target types allowed
57 SELECT_TARGET_SELF, // Only Self casting
58 SELECT_TARGET_SINGLE_ENEMY, // Only Single Enemy
59 SELECT_TARGET_AOE_ENEMY, // Only AoE Enemy
60 SELECT_TARGET_ANY_ENEMY, // AoE or Single Enemy
61 SELECT_TARGET_SINGLE_FRIEND, // Only Single Friend
62 SELECT_TARGET_AOE_FRIEND, // Only AoE Friend
63 SELECT_TARGET_ANY_FRIEND // AoE or Single Friend
64};
65
66// Spell Effects used by SelectSpell
68{
69 SELECT_EFFECT_DONTCARE = 0, // All spell effects allowed
70 SELECT_EFFECT_DAMAGE, // Spell does damage
71 SELECT_EFFECT_HEALING, // Spell does healing
72 SELECT_EFFECT_AURA // Spell applies an aura
73};
74
76{
83 float maxRange;
84
85 uint8 Targets; // set of enum SelectTarget
86 uint8 Effects; // set of enum SelectEffect
87};
88
90
91TC_GAME_API bool InstanceHasScript(WorldObject const* obj, char const* scriptName);
92
93template <class AI, class T>
94AI* GetInstanceAI(T* obj, char const* scriptName)
95{
96 if (InstanceHasScript(obj, scriptName))
97 return new AI(obj);
98
99 return nullptr;
100}
101
102#endif
AITarget
@ AITARGET_ALLY
@ AITARGET_BUFF
@ AITARGET_SELF
@ AITARGET_VICTIM
@ AITARGET_ENEMY
@ AITARGET_DEBUFF
SelectEffect
@ SELECT_EFFECT_DONTCARE
@ SELECT_EFFECT_AURA
@ SELECT_EFFECT_HEALING
@ SELECT_EFFECT_DAMAGE
TC_GAME_API bool InstanceHasScript(WorldObject const *obj, char const *scriptName)
#define AI_DEFAULT_COOLDOWN
First const & RAND(First const &first, Second const &second, Rest const &... rest)
AI * GetInstanceAI(T *obj, char const *scriptName)
SelectTargetType
@ SELECT_TARGET_ANY_FRIEND
@ SELECT_TARGET_AOE_FRIEND
@ SELECT_TARGET_ANY_ENEMY
@ SELECT_TARGET_SINGLE_FRIEND
@ SELECT_TARGET_SINGLE_ENEMY
@ SELECT_TARGET_DONTCARE
@ SELECT_TARGET_SELF
@ SELECT_TARGET_AOE_ENEMY
AISpellInfoType * GetAISpellInfo(uint32 spellId, Difficulty difficulty)
Definition: CreatureAI.cpp:40
AICondition
@ AICOND_COMBAT
@ AICOND_AGGRO
@ AICOND_DIE
Difficulty
Definition: DBCEnums.h:873
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition: Duration.h:29
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:42
Targets
Milliseconds realCooldown
AICondition condition
Milliseconds cooldown