[10041] Use for spell 49145 and ranks for decrease SPELL_DIRECT_DAMAGE damage.
[getmangos.git] / src / game / CreatureEventAI.h
blob1b07922d2a98ddc9fa039bba557a7ed24c22ec33
1 /*
2 * Copyright (C) 2005-2010 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
22 #include "Common.h"
23 #include "Creature.h"
24 #include "CreatureAI.h"
25 #include "Unit.h"
27 class Player;
28 class WorldObject;
30 #define EVENT_UPDATE_TIME 500
31 #define MAX_ACTIONS 3
32 #define MAX_PHASE 32
34 enum EventAI_Type
36 EVENT_T_TIMER = 0, // InitialMin, InitialMax, RepeatMin, RepeatMax
37 EVENT_T_TIMER_OOC = 1, // InitialMin, InitialMax, RepeatMin, RepeatMax
38 EVENT_T_HP = 2, // HPMax%, HPMin%, RepeatMin, RepeatMax
39 EVENT_T_MANA = 3, // ManaMax%,ManaMin% RepeatMin, RepeatMax
40 EVENT_T_AGGRO = 4, // NONE
41 EVENT_T_KILL = 5, // RepeatMin, RepeatMax
42 EVENT_T_DEATH = 6, // NONE
43 EVENT_T_EVADE = 7, // NONE
44 EVENT_T_SPELLHIT = 8, // SpellID, School, RepeatMin, RepeatMax
45 EVENT_T_RANGE = 9, // MinDist, MaxDist, RepeatMin, RepeatMax
46 EVENT_T_OOC_LOS = 10, // NoHostile, MaxRnage, RepeatMin, RepeatMax
47 EVENT_T_SPAWNED = 11, // Condition, CondValue1
48 EVENT_T_TARGET_HP = 12, // HPMax%, HPMin%, RepeatMin, RepeatMax
49 EVENT_T_TARGET_CASTING = 13, // RepeatMin, RepeatMax
50 EVENT_T_FRIENDLY_HP = 14, // HPDeficit, Radius, RepeatMin, RepeatMax
51 EVENT_T_FRIENDLY_IS_CC = 15, // DispelType, Radius, RepeatMin, RepeatMax
52 EVENT_T_FRIENDLY_MISSING_BUFF = 16, // SpellId, Radius, RepeatMin, RepeatMax
53 EVENT_T_SUMMONED_UNIT = 17, // CreatureId, RepeatMin, RepeatMax
54 EVENT_T_TARGET_MANA = 18, // ManaMax%, ManaMin%, RepeatMin, RepeatMax
55 EVENT_T_QUEST_ACCEPT = 19, // QuestID
56 EVENT_T_QUEST_COMPLETE = 20, //
57 EVENT_T_REACHED_HOME = 21, // NONE
58 EVENT_T_RECEIVE_EMOTE = 22, // EmoteId, Condition, CondValue1, CondValue2
59 EVENT_T_BUFFED = 23, // Param1 = SpellID, Param2 = Number of Time STacked, Param3/4 Repeat Min/Max
60 EVENT_T_TARGET_BUFFED = 24, // Param1 = SpellID, Param2 = Number of Time STacked, Param3/4 Repeat Min/Max
61 EVENT_T_SUMMONED_JUST_DIED = 25, // CreatureId, RepeatMin, RepeatMax
62 EVENT_T_SUMMONED_JUST_DESPAWN = 26, // CreatureId, RepeatMin, RepeatMax
64 EVENT_T_END,
67 enum EventAI_ActionType
69 ACTION_T_NONE = 0, // No action
70 ACTION_T_TEXT = 1, // TextId1, optionally -TextId2, optionally -TextId3(if -TextId2 exist). If more than just -TextId1 is defined, randomize. Negative values.
71 ACTION_T_SET_FACTION = 2, // FactionId (or 0 for default)
72 ACTION_T_MORPH_TO_ENTRY_OR_MODEL = 3, // Creature_template entry(param1) OR ModelId (param2) (or 0 for both to demorph)
73 ACTION_T_SOUND = 4, // SoundId
74 ACTION_T_EMOTE = 5, // EmoteId
75 ACTION_T_RANDOM_SAY = 6, // UNUSED
76 ACTION_T_RANDOM_YELL = 7, // UNUSED
77 ACTION_T_RANDOM_TEXTEMOTE = 8, // UNUSED
78 ACTION_T_RANDOM_SOUND = 9, // SoundId1, SoundId2, SoundId3 (-1 in any field means no output if randomed that field)
79 ACTION_T_RANDOM_EMOTE = 10, // EmoteId1, EmoteId2, EmoteId3 (-1 in any field means no output if randomed that field)
80 ACTION_T_CAST = 11, // SpellId, Target, CastFlags
81 ACTION_T_SUMMON = 12, // CreatureID, Target, Duration in ms
82 ACTION_T_THREAT_SINGLE_PCT = 13, // Threat%, Target
83 ACTION_T_THREAT_ALL_PCT = 14, // Threat%
84 ACTION_T_QUEST_EVENT = 15, // QuestID, Target
85 ACTION_T_CAST_EVENT = 16, // QuestID, SpellId, Target - must be removed as hack?
86 ACTION_T_SET_UNIT_FIELD = 17, // Field_Number, Value, Target
87 ACTION_T_SET_UNIT_FLAG = 18, // Flags (may be more than one field OR'd together), Target
88 ACTION_T_REMOVE_UNIT_FLAG = 19, // Flags (may be more than one field OR'd together), Target
89 ACTION_T_AUTO_ATTACK = 20, // AllowAttackState (0 = stop attack, anything else means continue attacking)
90 ACTION_T_COMBAT_MOVEMENT = 21, // AllowCombatMovement (0 = stop combat based movement, anything else continue attacking)
91 ACTION_T_SET_PHASE = 22, // Phase
92 ACTION_T_INC_PHASE = 23, // Value (may be negative to decrement phase, should not be 0)
93 ACTION_T_EVADE = 24, // No Params
94 ACTION_T_FLEE_FOR_ASSIST = 25, // No Params
95 ACTION_T_QUEST_EVENT_ALL = 26, // QuestID
96 ACTION_T_CAST_EVENT_ALL = 27, // CreatureId, SpellId
97 ACTION_T_REMOVEAURASFROMSPELL = 28, // Target, Spellid
98 ACTION_T_RANGED_MOVEMENT = 29, // Distance, Angle
99 ACTION_T_RANDOM_PHASE = 30, // PhaseId1, PhaseId2, PhaseId3
100 ACTION_T_RANDOM_PHASE_RANGE = 31, // PhaseMin, PhaseMax
101 ACTION_T_SUMMON_ID = 32, // CreatureId, Target, SpawnId
102 ACTION_T_KILLED_MONSTER = 33, // CreatureId, Target
103 ACTION_T_SET_INST_DATA = 34, // Field, Data
104 ACTION_T_SET_INST_DATA64 = 35, // Field, Target
105 ACTION_T_UPDATE_TEMPLATE = 36, // Entry, Team
106 ACTION_T_DIE = 37, // No Params
107 ACTION_T_ZONE_COMBAT_PULSE = 38, // No Params
108 ACTION_T_CALL_FOR_HELP = 39, // Radius
109 ACTION_T_SET_SHEATH = 40, // Sheath (0-passive,1-melee,2-ranged)
110 ACTION_T_FORCE_DESPAWN = 41, // No Params
111 ACTION_T_SET_INVINCIBILITY_HP_LEVEL = 42, // MinHpValue, format(0-flat,1-percent from max health)
112 ACTION_T_END,
115 enum Target
117 //Self (m_creature)
118 TARGET_T_SELF = 0, //Self cast
120 //Hostile targets (if pet then returns pet owner)
121 TARGET_T_HOSTILE, //Our current target (ie: highest aggro)
122 TARGET_T_HOSTILE_SECOND_AGGRO, //Second highest aggro (generaly used for cleaves and some special attacks)
123 TARGET_T_HOSTILE_LAST_AGGRO, //Dead last on aggro (no idea what this could be used for)
124 TARGET_T_HOSTILE_RANDOM, //Just any random target on our threat list
125 TARGET_T_HOSTILE_RANDOM_NOT_TOP, //Any random target except top threat
127 //Invoker targets (if pet then returns pet owner)
128 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)
130 //Hostile targets (including pets)
131 TARGET_T_HOSTILE_WPET, //Current target (can be a pet)
132 TARGET_T_HOSTILE_WPET_SECOND_AGGRO, //Second highest aggro (generaly used for cleaves and some special attacks)
133 TARGET_T_HOSTILE_WPET_LAST_AGGRO, //Dead last on aggro (no idea what this could be used for)
134 TARGET_T_HOSTILE_WPET_RANDOM, //Just any random target on our threat list
135 TARGET_T_HOSTILE_WPET_RANDOM_NOT_TOP, //Any random target except top threat
137 TARGET_T_ACTION_INVOKER_WPET,
139 TARGET_T_END
142 enum EventFlags
144 EFLAG_REPEATABLE = 0x01, //Event repeats
145 EFLAG_DIFFICULTY_0 = 0x02, //Event only occurs in instance difficulty 0
146 EFLAG_DIFFICULTY_1 = 0x04, //Event only occurs in instance difficulty 1
147 EFLAG_DIFFICULTY_2 = 0x08, //Event only occurs in instance difficulty 2
148 EFLAG_DIFFICULTY_3 = 0x10, //Event only occurs in instance difficulty 3
149 EFLAG_RESERVED_5 = 0x20,
150 EFLAG_RESERVED_6 = 0x40,
151 EFLAG_DEBUG_ONLY = 0x80, //Event only occurs in debug build
153 EFLAG_DIFFICULTY_ALL = (EFLAG_DIFFICULTY_0|EFLAG_DIFFICULTY_1|EFLAG_DIFFICULTY_2|EFLAG_DIFFICULTY_3)
156 enum SpawnedEventMode
158 SPAWNED_EVENT_ALWAY = 0,
159 SPAWNED_EVENT_MAP = 1,
160 SPAWNED_EVENT_ZONE = 2
163 // String text additional data, used in (CreatureEventAI)
164 struct StringTextData
166 uint32 SoundId;
167 uint8 Type;
168 uint32 Language;
169 uint32 Emote;
171 // Text Maps
172 typedef UNORDERED_MAP<int32, StringTextData> CreatureEventAI_TextMap;
174 struct CreatureEventAI_Action
176 EventAI_ActionType type: 16;
177 union
179 // ACTION_T_TEXT = 1
180 struct
182 int32 TextId[3];
183 } text;
184 // ACTION_T_SET_FACTION = 2
185 struct
187 uint32 factionId; // faction or 0 for default)
188 } set_faction;
189 // ACTION_T_MORPH_TO_ENTRY_OR_MODEL = 3
190 struct
192 uint32 creatureId; // set one from fields (or 0 for both to demorph)
193 uint32 modelId;
194 } morph;
195 // ACTION_T_SOUND = 4
196 struct
198 uint32 soundId;
199 } sound;
200 // ACTION_T_EMOTE = 5
201 struct
203 uint32 emoteId;
204 } emote;
205 // ACTION_T_RANDOM_SOUND = 9
206 struct
208 int32 soundId1; // (-1 in any field means no output if randomed that field)
209 int32 soundId2;
210 int32 soundId3;
211 } random_sound;
212 // ACTION_T_RANDOM_EMOTE = 10
213 struct
215 int32 emoteId1; // (-1 in any field means no output if randomed that field)
216 int32 emoteId2;
217 int32 emoteId3;
218 } random_emote;
219 // ACTION_T_CAST = 11
220 struct
222 uint32 spellId;
223 uint32 target;
224 uint32 castFlags;
225 } cast;
226 // ACTION_T_SUMMON = 12
227 struct
229 uint32 creatureId;
230 uint32 target;
231 uint32 duration;
232 } summon;
233 // ACTION_T_THREAT_SINGLE_PCT = 13
234 struct
236 int32 percent;
237 uint32 target;
238 } threat_single_pct;
239 // ACTION_T_THREAT_ALL_PCT = 14
240 struct
242 int32 percent;
243 } threat_all_pct;
244 // ACTION_T_QUEST_EVENT = 15
245 struct
247 uint32 questId;
248 uint32 target;
249 } quest_event;
250 // ACTION_T_CAST_EVENT = 16
251 struct
253 uint32 creatureId;
254 uint32 spellId;
255 uint32 target;
256 } cast_event;
257 // ACTION_T_SET_UNIT_FIELD = 17
258 struct
260 uint32 field;
261 uint32 value;
262 uint32 target;
263 } set_unit_field;
264 // ACTION_T_SET_UNIT_FLAG = 18, // value provided mask bits that will be set
265 // ACTION_T_REMOVE_UNIT_FLAG = 19, // value provided mask bits that will be clear
266 struct
268 uint32 value;
269 uint32 target;
270 } unit_flag;
271 // ACTION_T_AUTO_ATTACK = 20
272 struct
274 uint32 state; // 0 = stop attack, anything else means continue attacking
275 } auto_attack;
276 // ACTION_T_COMBAT_MOVEMENT = 21
277 struct
279 uint32 state; // 0 = stop combat based movement, anything else continue attacking
280 uint32 melee; // if set: at stop send melee combat stop if in combat, use for terminate melee fighting state for switch to ranged
281 } combat_movement;
282 // ACTION_T_SET_PHASE = 22
283 struct
285 uint32 phase;
286 } set_phase;
287 // ACTION_T_INC_PHASE = 23
288 struct
290 int32 step;
291 } set_inc_phase;
292 // ACTION_T_QUEST_EVENT_ALL = 26
293 struct
295 uint32 questId;
296 } quest_event_all;
297 // ACTION_T_CAST_EVENT_ALL = 27
298 struct
300 uint32 creatureId;
301 uint32 spellId;
302 } cast_event_all;
303 // ACTION_T_REMOVEAURASFROMSPELL = 28
304 struct
306 uint32 target;
307 uint32 spellId;
308 } remove_aura;
309 // ACTION_T_RANGED_MOVEMENT = 29
310 struct
312 uint32 distance;
313 int32 angle;
314 } ranged_movement;
315 // ACTION_T_RANDOM_PHASE = 30
316 struct
318 uint32 phase1;
319 uint32 phase2;
320 uint32 phase3;
321 } random_phase;
322 // ACTION_T_RANDOM_PHASE_RANGE = 31
323 struct
325 uint32 phaseMin;
326 uint32 phaseMax;
327 } random_phase_range;
328 // ACTION_T_SUMMON_ID = 32
329 struct
331 uint32 creatureId;
332 uint32 target;
333 uint32 spawnId;
334 } summon_id;
335 // ACTION_T_KILLED_MONSTER = 33
336 struct
338 uint32 creatureId;
339 uint32 target;
340 } killed_monster;
341 // ACTION_T_SET_INST_DATA = 34
342 struct
344 uint32 field;
345 uint32 value;
346 } set_inst_data;
347 // ACTION_T_SET_INST_DATA64 = 35
348 struct
350 uint32 field;
351 uint32 target;
352 } set_inst_data64;
353 // ACTION_T_UPDATE_TEMPLATE = 36
354 struct
356 uint32 creatureId;
357 uint32 team;
358 } update_template;
359 // ACTION_T_CALL_FOR_HELP = 39
360 struct
362 uint32 radius;
363 } call_for_help;
364 // ACTION_T_SET_SHEATH = 40
365 struct
367 uint32 sheath;
368 } set_sheath;
369 // ACTION_T_FORCE_DESPAWN = 41
370 struct
372 uint32 msDelay;
373 } forced_despawn;
374 // ACTION_T_SET_INVINCIBILITY_HP_LEVEL = 42
375 struct
377 uint32 hp_level;
378 uint32 is_percent;
379 } invincibility_hp_level;
380 // RAW
381 struct
383 uint32 param1;
384 uint32 param2;
385 uint32 param3;
386 } raw;
390 struct CreatureEventAI_Event
392 uint32 event_id;
394 uint32 creature_id;
396 uint32 event_inverse_phase_mask;
398 EventAI_Type event_type : 16;
399 uint8 event_chance : 8;
400 uint8 event_flags : 8;
402 union
404 // EVENT_T_TIMER = 0
405 // EVENT_T_TIMER_OOC = 1
406 struct
408 uint32 initialMin;
409 uint32 initialMax;
410 uint32 repeatMin;
411 uint32 repeatMax;
412 } timer;
413 // EVENT_T_HP = 2
414 // EVENT_T_MANA = 3
415 // EVENT_T_TARGET_HP = 12
416 // EVENT_T_TARGET_MANA = 18
417 struct
419 uint32 percentMax;
420 uint32 percentMin;
421 uint32 repeatMin;
422 uint32 repeatMax;
423 } percent_range;
424 // EVENT_T_KILL = 5
425 struct
427 uint32 repeatMin;
428 uint32 repeatMax;
429 } kill;
430 // EVENT_T_SPELLHIT = 8
431 struct
433 uint32 spellId;
434 uint32 schoolMask; // -1 (==0xffffffff) is ok value for full mask, or must be more limited mask like (0 < 1) = 1 for normal/physical school
435 uint32 repeatMin;
436 uint32 repeatMax;
437 } spell_hit;
438 // EVENT_T_RANGE = 9
439 struct
441 uint32 minDist;
442 uint32 maxDist;
443 uint32 repeatMin;
444 uint32 repeatMax;
445 } range;
446 // EVENT_T_OOC_LOS = 10
447 struct
449 uint32 noHostile;
450 uint32 maxRange;
451 uint32 repeatMin;
452 uint32 repeatMax;
453 } ooc_los;
454 // EVENT_T_SPAWNED = 11
455 struct
457 uint32 condition;
458 uint32 conditionValue1;
459 } spawned;
460 // EVENT_T_TARGET_CASTING = 13
461 struct
463 uint32 repeatMin;
464 uint32 repeatMax;
465 } target_casting;
466 // EVENT_T_FRIENDLY_HP = 14
467 struct
469 uint32 hpDeficit;
470 uint32 radius;
471 uint32 repeatMin;
472 uint32 repeatMax;
473 } friendly_hp;
474 // EVENT_T_FRIENDLY_IS_CC = 15
475 struct
477 uint32 dispelType; // unused ?
478 uint32 radius;
479 uint32 repeatMin;
480 uint32 repeatMax;
481 } friendly_is_cc;
482 // EVENT_T_FRIENDLY_MISSING_BUFF = 16
483 struct
485 uint32 spellId;
486 uint32 radius;
487 uint32 repeatMin;
488 uint32 repeatMax;
489 } friendly_buff;
490 // EVENT_T_SUMMONED_UNIT = 17
491 //EVENT_T_SUMMONED_JUST_DIED = 25
492 //EVENT_T_SUMMONED_JUST_DESPAWN = 26
493 struct
495 uint32 creatureId;
496 uint32 repeatMin;
497 uint32 repeatMax;
498 } summoned;
499 // EVENT_T_QUEST_ACCEPT = 19
500 // EVENT_T_QUEST_COMPLETE = 20
501 struct
503 uint32 questId;
504 } quest;
505 // EVENT_T_RECEIVE_EMOTE = 22
506 struct
508 uint32 emoteId;
509 uint32 condition;
510 uint32 conditionValue1;
511 uint32 conditionValue2;
512 } receive_emote;
513 // EVENT_T_BUFFED = 23
514 // EVENT_T_TARGET_BUFFED = 24
515 struct
517 uint32 spellId;
518 uint32 amount;
519 uint32 repeatMin;
520 uint32 repeatMax;
521 } buffed;
523 // RAW
524 struct
526 uint32 param1;
527 uint32 param2;
528 uint32 param3;
529 uint32 param4;
530 } raw;
533 CreatureEventAI_Action action[MAX_ACTIONS];
535 //Event_Map
536 typedef std::vector<CreatureEventAI_Event> CreatureEventAI_Event_Vec;
537 typedef UNORDERED_MAP<uint32, CreatureEventAI_Event_Vec > CreatureEventAI_Event_Map;
539 struct CreatureEventAI_Summon
541 uint32 id;
543 float position_x;
544 float position_y;
545 float position_z;
546 float orientation;
547 uint32 SpawnTimeSecs;
550 //EventSummon_Map
551 typedef UNORDERED_MAP<uint32, CreatureEventAI_Summon> CreatureEventAI_Summon_Map;
553 struct CreatureEventAIHolder
555 CreatureEventAIHolder(CreatureEventAI_Event p) : Event(p), Time(0), Enabled(true){}
557 CreatureEventAI_Event Event;
558 uint32 Time;
559 bool Enabled;
561 // helper
562 bool UpdateRepeatTimer(Creature* creature, uint32 repeatMin, uint32 repeatMax);
565 class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI
568 public:
569 explicit CreatureEventAI(Creature *c);
570 ~CreatureEventAI()
572 CreatureEventAIList.clear();
574 void JustRespawned();
575 void Reset();
576 void JustReachedHome();
577 void EnterCombat(Unit *enemy);
578 void EnterEvadeMode();
579 void JustDied(Unit* killer);
580 void KilledUnit(Unit* victim);
581 void JustSummoned(Creature* pUnit);
582 void AttackStart(Unit *who);
583 void MoveInLineOfSight(Unit *who);
584 void SpellHit(Unit* pUnit, const SpellEntry* pSpell);
585 void DamageTaken(Unit* done_by, uint32& damage);
586 void UpdateAI(const uint32 diff);
587 bool IsVisible(Unit *) const;
588 void ReceiveEmote(Player* pPlayer, uint32 text_emote);
589 void SummonedCreatureJustDied(Creature* unit);
590 void SummonedCreatureDespawn(Creature* unit);
592 static int Permissible(const Creature *);
594 bool ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pActionInvoker = NULL);
595 void ProcessAction(CreatureEventAI_Action const& action, uint32 rnd, uint32 EventId, Unit* pActionInvoker);
596 inline uint32 GetRandActionParam(uint32 rnd, uint32 param1, uint32 param2, uint32 param3);
597 inline int32 GetRandActionParam(uint32 rnd, int32 param1, int32 param2, int32 param3);
598 inline Unit* GetTargetByType(uint32 Target, Unit* pActionInvoker);
600 void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target);
601 void DoMeleeAttackIfReady();
602 bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered);
604 bool SpawnedEventConditionsCheck(CreatureEventAI_Event const& event);
606 Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff);
607 void DoFindFriendlyMissingBuff(std::list<Creature*>& _list, float range, uint32 spellid);
608 void DoFindFriendlyCC(std::list<Creature*>& _list, float range);
610 //Holder for events (stores enabled, time, and eventid)
611 std::list<CreatureEventAIHolder> CreatureEventAIList;
612 uint32 EventUpdateTime; //Time between event updates
613 uint32 EventDiff; //Time between the last event call
614 bool bEmptyList;
616 //Variables used by Events themselves
617 uint8 Phase; // Current phase, max 32 phases
618 bool CombatMovementEnabled; // If we allow targeted movment gen (movement twoards top threat)
619 bool MeleeEnabled; // If we allow melee auto attack
620 float AttackDistance; // Distance to attack from
621 float AttackAngle; // Angle of attack
622 uint32 InvinceabilityHpLevel; // Minimal health level allowed at damage apply
624 #endif