2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_CREATURE_EAI_H
20 #define MANGOS_CREATURE_EAI_H
24 #include "CreatureAI.h"
30 #define EVENT_UPDATE_TIME 500
31 #define SPELL_RUN_AWAY 8225
33 #define TEXT_SOURCE_RANGE -1000000 //the amount of entries each text source has available
37 EVENT_T_TIMER
= 0, // InitialMin, InitialMax, RepeatMin, RepeatMax
38 EVENT_T_TIMER_OOC
= 1, // InitialMin, InitialMax, RepeatMin, RepeatMax
39 EVENT_T_HP
= 2, // HPMax%, HPMin%, RepeatMin, RepeatMax
40 EVENT_T_MANA
= 3, // ManaMax%,ManaMin% RepeatMin, RepeatMax
41 EVENT_T_AGGRO
= 4, // NONE
42 EVENT_T_KILL
= 5, // RepeatMin, RepeatMax
43 EVENT_T_DEATH
= 6, // NONE
44 EVENT_T_EVADE
= 7, // NONE
45 EVENT_T_SPELLHIT
= 8, // SpellID, School, RepeatMin, RepeatMax
46 EVENT_T_RANGE
= 9, // MinDist, MaxDist, RepeatMin, RepeatMax
47 EVENT_T_OOC_LOS
= 10, // NoHostile, NoFriendly, RepeatMin, RepeatMax
48 EVENT_T_SPAWNED
= 11, // NONE
49 EVENT_T_TARGET_HP
= 12, // HPMax%, HPMin%, RepeatMin, RepeatMax
50 EVENT_T_TARGET_CASTING
= 13, // RepeatMin, RepeatMax
51 EVENT_T_FRIENDLY_HP
= 14, // HPDeficit, Radius, RepeatMin, RepeatMax
52 EVENT_T_FRIENDLY_IS_CC
= 15, // DispelType, Radius, RepeatMin, RepeatMax
53 EVENT_T_FRIENDLY_MISSING_BUFF
= 16, // SpellId, Radius, RepeatMin, RepeatMax
54 EVENT_T_SUMMONED_UNIT
= 17, // CreatureId, RepeatMin, RepeatMax
55 EVENT_T_TARGET_MANA
= 18, // ManaMax%, ManaMin%, RepeatMin, RepeatMax
56 EVENT_T_QUEST_ACCEPT
= 19, // QuestID
57 EVENT_T_QUEST_COMPLETE
= 20, //
58 EVENT_T_REACHED_HOME
= 21, // NONE
59 EVENT_T_RECEIVE_EMOTE
= 22, // EmoteId, Condition, CondValue1, CondValue2
64 enum EventAI_ActionType
66 ACTION_T_NONE
= 0, //*No action
67 ACTION_T_TEXT
= 1, //*-TextId1, optionally -TextId2, optionally -TextId3(if -TextId2 exist). If more than just -TextId1 is defined, randomize. Negative values.
68 ACTION_T_SET_FACTION
= 2, //*FactionId (or 0 for default)
69 ACTION_T_MORPH_TO_ENTRY_OR_MODEL
= 3, //*Creature_template entry(param1) OR ModelId (param2) (or 0 for both to demorph)
70 ACTION_T_SOUND
= 4, //*SoundId
71 ACTION_T_EMOTE
= 5, //*EmoteId
72 ACTION_T_RANDOM_SAY
= 6, //*UNUSED
73 ACTION_T_RANDOM_YELL
= 7, //*UNUSED
74 ACTION_T_RANDOM_TEXTEMOTE
= 8, //*UNUSED
75 ACTION_T_RANDOM_SOUND
= 9, //SoundId1, SoundId2, SoundId3 (-1 in any field means no output if randomed that field)
76 ACTION_T_RANDOM_EMOTE
= 10, //*EmoteId1, EmoteId2, EmoteId3 (-1 in any field means no output if randomed that field)
77 ACTION_T_CAST
= 11, //*SpellId, Target, CastFlags
78 ACTION_T_SUMMON
= 12, //*CreatureID, Target, Duration in ms
79 ACTION_T_THREAT_SINGLE_PCT
= 13, //*Threat%, Target
80 ACTION_T_THREAT_ALL_PCT
= 14, //Threat%
81 ACTION_T_QUEST_EVENT
= 15, //*QuestID, Target
82 ACTION_T_CASTCREATUREGO
= 16, //*QuestID, SpellId, Target
83 ACTION_T_SET_UNIT_FIELD
= 17, //*Field_Number, Value, Target
84 ACTION_T_SET_UNIT_FLAG
= 18, //*Flags (may be more than one field OR'd together), Target
85 ACTION_T_REMOVE_UNIT_FLAG
= 19, //*Flags (may be more than one field OR'd together), Target
86 ACTION_T_AUTO_ATTACK
= 20, //AllowAttackState (0 = stop attack, anything else means continue attacking)
87 ACTION_T_COMBAT_MOVEMENT
= 21, //AllowCombatMovement (0 = stop combat based movement, anything else continue attacking)
88 ACTION_T_SET_PHASE
= 22, //*Phase
89 ACTION_T_INC_PHASE
= 23, //*Value (may be negative to decrement phase, should not be 0)
90 ACTION_T_EVADE
= 24, //No Params
91 ACTION_T_FLEE
= 25, //No Params
92 ACTION_T_QUEST_EVENT_ALL
= 26, //*QuestID
93 ACTION_T_CASTCREATUREGO_ALL
= 27, //*QuestId, SpellId
94 ACTION_T_REMOVEAURASFROMSPELL
= 28, //*Target, Spellid
95 ACTION_T_RANGED_MOVEMENT
= 29, //Distance, Angle
96 ACTION_T_RANDOM_PHASE
= 30, //PhaseId1, PhaseId2, PhaseId3
97 ACTION_T_RANDOM_PHASE_RANGE
= 31, //PhaseMin, PhaseMax
98 ACTION_T_SUMMON_ID
= 32, //*CreatureId, Target, SpawnId
99 ACTION_T_KILLED_MONSTER
= 33, //*CreatureId, Target
100 ACTION_T_SET_INST_DATA
= 34, //*Field, Data
101 ACTION_T_SET_INST_DATA64
= 35, //*Field, Target
102 ACTION_T_UPDATE_TEMPLATE
= 36, //*Entry, Team
103 ACTION_T_DIE
= 37, //No Params
104 ACTION_T_ZONE_COMBAT_PULSE
= 38, //No Params
112 TARGET_T_SELF
= 0, //Self cast
114 //Hostile targets (if pet then returns pet owner)
115 TARGET_T_HOSTILE
, //Our current target (ie: highest aggro)
116 TARGET_T_HOSTILE_SECOND_AGGRO
, //Second highest aggro (generaly used for cleaves and some special attacks)
117 TARGET_T_HOSTILE_LAST_AGGRO
, //Dead last on aggro (no idea what this could be used for)
118 TARGET_T_HOSTILE_RANDOM
, //Just any random target on our threat list
119 TARGET_T_HOSTILE_RANDOM_NOT_TOP
, //Any random target except top threat
121 //Invoker targets (if pet then returns pet owner)
122 TARGET_T_ACTION_INVOKER
, //Unit who caused this Event to occur (only works for EVENT_T_AGGRO, EVENT_T_KILL, EVENT_T_DEATH, EVENT_T_SPELLHIT, EVENT_T_OOC_LOS, EVENT_T_FRIENDLY_HP, EVENT_T_FRIENDLY_IS_CC, EVENT_T_FRIENDLY_MISSING_BUFF)
124 //Hostile targets (including pets)
125 TARGET_T_HOSTILE_WPET
, //Current target (can be a pet)
126 TARGET_T_HOSTILE_WPET_SECOND_AGGRO
, //Second highest aggro (generaly used for cleaves and some special attacks)
127 TARGET_T_HOSTILE_WPET_LAST_AGGRO
, //Dead last on aggro (no idea what this could be used for)
128 TARGET_T_HOSTILE_WPET_RANDOM
, //Just any random target on our threat list
129 TARGET_T_HOSTILE_WPET_RANDOM_NOT_TOP
, //Any random target except top threat
131 TARGET_T_ACTION_INVOKER_WPET
,
138 CAST_INTURRUPT_PREVIOUS
= 0x01, //Interrupt any spell casting
139 CAST_TRIGGERED
= 0x02, //Triggered (this makes spell cost zero mana and have no cast time)
140 CAST_FORCE_CAST
= 0x04, //Forces cast even if creature is out of mana or out of range
141 CAST_NO_MELEE_IF_OOM
= 0x08, //Prevents creature from entering melee if out of mana or out of range
142 CAST_FORCE_TARGET_SELF
= 0x10, //Forces the target to cast this spell on itself
143 CAST_AURA_NOT_PRESENT
= 0x20, //Only casts the spell if the target does not have an aura from the spell
148 EFLAG_REPEATABLE
= 0x01, //Event repeats
149 EFLAG_NORMAL
= 0x02, //Event only occurs in Normal instance difficulty
150 EFLAG_HEROIC
= 0x04, //Event only occurs in Heroic instance difficulty
151 EFLAG_RESERVED_3
= 0x08,
152 EFLAG_RESERVED_4
= 0x10,
153 EFLAG_RESERVED_5
= 0x20,
154 EFLAG_RESERVED_6
= 0x40,
155 EFLAG_DEBUG_ONLY
= 0x80, //Event only occurs in debug build
158 // String text additional data, used in (CreatureEventAI)
159 struct StringTextData
167 typedef UNORDERED_MAP
<int32
, StringTextData
> CreatureEventAI_TextMap
;
169 struct CreatureEventAI_Event
175 uint32 event_inverse_phase_mask
;
177 EventAI_Type event_type
: 16;
178 uint8 event_chance
: 8;
179 uint8 event_flags
: 8;
184 int32 event_param1_s
;
189 int32 event_param2_s
;
194 int32 event_param3_s
;
199 int32 event_param4_s
;
204 EventAI_ActionType type
: 16;
220 }action
[MAX_ACTIONS
];
223 typedef UNORDERED_MAP
<uint32
, std::vector
<CreatureEventAI_Event
> > CreatureEventAI_Event_Map
;
225 struct CreatureEventAI_Summon
233 uint32 SpawnTimeSecs
;
237 typedef UNORDERED_MAP
<uint32
, CreatureEventAI_Summon
> CreatureEventAI_Summon_Map
;
239 struct CreatureEventAIHolder
241 CreatureEventAIHolder(CreatureEventAI_Event p
) : Event(p
), Time(0), Enabled(true){}
243 CreatureEventAI_Event Event
;
248 class MANGOS_DLL_SPEC CreatureEventAI
: public CreatureAI
252 explicit CreatureEventAI(Creature
*c
);
255 CreatureEventAIList
.clear();
257 void JustRespawned();
259 void JustReachedHome();
260 void EnterEvadeMode();
261 void JustDied(Unit
* killer
);
262 void KilledUnit(Unit
* victim
);
263 void JustSummoned(Creature
* pUnit
);
264 void Aggro(Unit
*who
);
265 void AttackStart(Unit
*who
);
266 void MoveInLineOfSight(Unit
*who
);
267 void SpellHit(Unit
* pUnit
, const SpellEntry
* pSpell
);
268 void UpdateAI(const uint32 diff
);
269 bool IsVisible(Unit
*) const;
270 void ReceiveEmote(Player
* pPlayer
, uint32 text_emote
);
271 static int Permissible(const Creature
*);
273 bool ProcessEvent(CreatureEventAIHolder
& pHolder
, Unit
* pActionInvoker
= NULL
);
274 void ProcessAction(uint16 type
, uint32 param1
, uint32 param2
, uint32 param3
, uint32 rnd
, uint32 EventId
, Unit
* pActionInvoker
);
275 inline uint32
GetRandActionParam(uint32 rnd
, uint32 param1
, uint32 param2
, uint32 param3
);
276 inline Unit
* GetTargetByType(uint32 Target
, Unit
* pActionInvoker
);
277 inline Unit
* SelectUnit(AttackingTarget target
, uint32 position
);
279 void DoScriptText(int32 textEntry
, WorldObject
* pSource
, Unit
* target
);
280 void DoZoneInCombat(Unit
* pUnit
);
281 void DoMeleeAttackIfReady();
282 bool CanCast(Unit
* Target
, SpellEntry
const *Spell
, bool Triggered
);
284 Unit
* DoSelectLowestHpFriendly(float range
, uint32 MinHPDiff
);
285 void DoFindFriendlyMissingBuff(std::list
<Creature
*>& _list
, float range
, uint32 spellid
);
286 void DoFindFriendlyCC(std::list
<Creature
*>& _list
, float range
);
288 //Holder for events (stores enabled, time, and eventid)
289 std::list
<CreatureEventAIHolder
> CreatureEventAIList
;
290 uint32 EventUpdateTime
; //Time between event updates
291 uint32 EventDiff
; //Time between the last event call
294 //Variables used by Events themselves
295 uint8 Phase
; //Current phase, max 32 phases
296 bool CombatMovementEnabled
; //If we allow targeted movment gen (movement twoards top threat)
297 bool MeleeEnabled
; //If we allow melee auto attack
298 uint32 AttackDistance
; //Distance to attack from
299 float AttackAngle
; //Angle of attack