[8449] Deprecate healing/damage item mods and merge internal data in to spell power.
[getmangos.git] / src / game / CreatureEventAI.h
blob603d889742d90cf65875bf7d10a435521e7c2eae
1 /*
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
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
62 EVENT_T_END,
65 enum EventAI_ActionType
67 ACTION_T_NONE = 0, // No action
68 ACTION_T_TEXT = 1, // TextId1, optionally -TextId2, optionally -TextId3(if -TextId2 exist). If more than just -TextId1 is defined, randomize. Negative values.
69 ACTION_T_SET_FACTION = 2, // FactionId (or 0 for default)
70 ACTION_T_MORPH_TO_ENTRY_OR_MODEL = 3, // Creature_template entry(param1) OR ModelId (param2) (or 0 for both to demorph)
71 ACTION_T_SOUND = 4, // SoundId
72 ACTION_T_EMOTE = 5, // EmoteId
73 ACTION_T_RANDOM_SAY = 6, // UNUSED
74 ACTION_T_RANDOM_YELL = 7, // UNUSED
75 ACTION_T_RANDOM_TEXTEMOTE = 8, // UNUSED
76 ACTION_T_RANDOM_SOUND = 9, // SoundId1, SoundId2, SoundId3 (-1 in any field means no output if randomed that field)
77 ACTION_T_RANDOM_EMOTE = 10, // EmoteId1, EmoteId2, EmoteId3 (-1 in any field means no output if randomed that field)
78 ACTION_T_CAST = 11, // SpellId, Target, CastFlags
79 ACTION_T_SUMMON = 12, // CreatureID, Target, Duration in ms
80 ACTION_T_THREAT_SINGLE_PCT = 13, // Threat%, Target
81 ACTION_T_THREAT_ALL_PCT = 14, // Threat%
82 ACTION_T_QUEST_EVENT = 15, // QuestID, Target
83 ACTION_T_CAST_EVENT = 16, // QuestID, SpellId, Target - must be removed as hack?
84 ACTION_T_SET_UNIT_FIELD = 17, // Field_Number, Value, Target
85 ACTION_T_SET_UNIT_FLAG = 18, // Flags (may be more than one field OR'd together), Target
86 ACTION_T_REMOVE_UNIT_FLAG = 19, // Flags (may be more than one field OR'd together), Target
87 ACTION_T_AUTO_ATTACK = 20, // AllowAttackState (0 = stop attack, anything else means continue attacking)
88 ACTION_T_COMBAT_MOVEMENT = 21, // AllowCombatMovement (0 = stop combat based movement, anything else continue attacking)
89 ACTION_T_SET_PHASE = 22, // Phase
90 ACTION_T_INC_PHASE = 23, // Value (may be negative to decrement phase, should not be 0)
91 ACTION_T_EVADE = 24, // No Params
92 ACTION_T_FLEE_FOR_ASSIST = 25, // No Params
93 ACTION_T_QUEST_EVENT_ALL = 26, // QuestID
94 ACTION_T_CAST_EVENT_ALL = 27, // CreatureId, SpellId
95 ACTION_T_REMOVEAURASFROMSPELL = 28, // Target, Spellid
96 ACTION_T_RANGED_MOVEMENT = 29, // Distance, Angle
97 ACTION_T_RANDOM_PHASE = 30, // PhaseId1, PhaseId2, PhaseId3
98 ACTION_T_RANDOM_PHASE_RANGE = 31, // PhaseMin, PhaseMax
99 ACTION_T_SUMMON_ID = 32, // CreatureId, Target, SpawnId
100 ACTION_T_KILLED_MONSTER = 33, // CreatureId, Target
101 ACTION_T_SET_INST_DATA = 34, // Field, Data
102 ACTION_T_SET_INST_DATA64 = 35, // Field, Target
103 ACTION_T_UPDATE_TEMPLATE = 36, // Entry, Team
104 ACTION_T_DIE = 37, // No Params
105 ACTION_T_ZONE_COMBAT_PULSE = 38, // No Params
106 ACTION_T_CALL_FOR_HELP = 39, // Radius
107 ACTION_T_SET_SHEATH = 40, // Sheath (0-passive,1-melee,2-ranged)
108 ACTION_T_FORCE_DESPAWN = 41, // No Params
109 ACTION_T_SET_INVINCIBILITY_HP_LEVEL = 42, // MinHpValue, format(0-flat,1-percent from max health)
110 ACTION_T_END,
113 enum Target
115 //Self (m_creature)
116 TARGET_T_SELF = 0, //Self cast
118 //Hostile targets (if pet then returns pet owner)
119 TARGET_T_HOSTILE, //Our current target (ie: highest aggro)
120 TARGET_T_HOSTILE_SECOND_AGGRO, //Second highest aggro (generaly used for cleaves and some special attacks)
121 TARGET_T_HOSTILE_LAST_AGGRO, //Dead last on aggro (no idea what this could be used for)
122 TARGET_T_HOSTILE_RANDOM, //Just any random target on our threat list
123 TARGET_T_HOSTILE_RANDOM_NOT_TOP, //Any random target except top threat
125 //Invoker targets (if pet then returns pet owner)
126 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)
128 //Hostile targets (including pets)
129 TARGET_T_HOSTILE_WPET, //Current target (can be a pet)
130 TARGET_T_HOSTILE_WPET_SECOND_AGGRO, //Second highest aggro (generaly used for cleaves and some special attacks)
131 TARGET_T_HOSTILE_WPET_LAST_AGGRO, //Dead last on aggro (no idea what this could be used for)
132 TARGET_T_HOSTILE_WPET_RANDOM, //Just any random target on our threat list
133 TARGET_T_HOSTILE_WPET_RANDOM_NOT_TOP, //Any random target except top threat
135 TARGET_T_ACTION_INVOKER_WPET,
137 TARGET_T_END
140 enum CastFlags
142 CAST_INTURRUPT_PREVIOUS = 0x01, //Interrupt any spell casting
143 CAST_TRIGGERED = 0x02, //Triggered (this makes spell cost zero mana and have no cast time)
144 CAST_FORCE_CAST = 0x04, //Forces cast even if creature is out of mana or out of range
145 CAST_NO_MELEE_IF_OOM = 0x08, //Prevents creature from entering melee if out of mana or out of range
146 CAST_FORCE_TARGET_SELF = 0x10, //Forces the target to cast this spell on itself
147 CAST_AURA_NOT_PRESENT = 0x20, //Only casts the spell if the target does not have an aura from the spell
150 enum EventFlags
152 EFLAG_REPEATABLE = 0x01, //Event repeats
153 EFLAG_NORMAL = 0x02, //Event only occurs in Normal instance difficulty
154 EFLAG_HEROIC = 0x04, //Event only occurs in Heroic instance difficulty
155 EFLAG_RESERVED_3 = 0x08,
156 EFLAG_RESERVED_4 = 0x10,
157 EFLAG_RESERVED_5 = 0x20,
158 EFLAG_RESERVED_6 = 0x40,
159 EFLAG_DEBUG_ONLY = 0x80, //Event only occurs in debug build
162 enum SpawnedEventMode
164 SPAWNED_EVENT_ALWAY = 0,
165 SPAWNED_EVENT_MAP = 1,
166 SPAWNED_EVENT_ZONE = 2
169 // String text additional data, used in (CreatureEventAI)
170 struct StringTextData
172 uint32 SoundId;
173 uint8 Type;
174 uint32 Language;
175 uint32 Emote;
177 // Text Maps
178 typedef UNORDERED_MAP<int32, StringTextData> CreatureEventAI_TextMap;
180 struct CreatureEventAI_Action
182 EventAI_ActionType type: 16;
183 union
185 // ACTION_T_TEXT = 1
186 struct
188 int32 TextId1;
189 int32 TextId2;
190 int32 TextId3;
191 } text;
192 // ACTION_T_SET_FACTION = 2
193 struct
195 uint32 factionId; // faction or 0 for default)
196 } set_faction;
197 // ACTION_T_MORPH_TO_ENTRY_OR_MODEL = 3
198 struct
200 uint32 creatureId; // set one from fields (or 0 for both to demorph)
201 uint32 modelId;
202 } morph;
203 // ACTION_T_SOUND = 4
204 struct
206 uint32 soundId;
207 } sound;
208 // ACTION_T_EMOTE = 5
209 struct
211 uint32 emoteId;
212 } emote;
213 // ACTION_T_RANDOM_SOUND = 9
214 struct
216 int32 soundId1; // (-1 in any field means no output if randomed that field)
217 int32 soundId2;
218 int32 soundId3;
219 } random_sound;
220 // ACTION_T_RANDOM_EMOTE = 10
221 struct
223 int32 emoteId1; // (-1 in any field means no output if randomed that field)
224 int32 emoteId2;
225 int32 emoteId3;
226 } random_emote;
227 // ACTION_T_CAST = 11
228 struct
230 uint32 spellId;
231 uint32 target;
232 uint32 castFlags;
233 } cast;
234 // ACTION_T_SUMMON = 12
235 struct
237 uint32 creatureId;
238 uint32 target;
239 uint32 duration;
240 } summon;
241 // ACTION_T_THREAT_SINGLE_PCT = 13
242 struct
244 int32 percent;
245 uint32 target;
246 } threat_single_pct;
247 // ACTION_T_THREAT_ALL_PCT = 14
248 struct
250 int32 percent;
251 } threat_all_pct;
252 // ACTION_T_QUEST_EVENT = 15
253 struct
255 uint32 questId;
256 uint32 target;
257 } quest_event;
258 // ACTION_T_CAST_EVENT = 16
259 struct
261 uint32 creatureId;
262 uint32 spellId;
263 uint32 target;
264 } cast_event;
265 // ACTION_T_SET_UNIT_FIELD = 17
266 struct
268 uint32 field;
269 uint32 value;
270 uint32 target;
271 } set_unit_field;
272 // ACTION_T_SET_UNIT_FLAG = 18, // value provided mask bits that will be set
273 // ACTION_T_REMOVE_UNIT_FLAG = 19, // value provided mask bits that will be clear
274 struct
276 uint32 value;
277 uint32 target;
278 } unit_flag;
279 // ACTION_T_AUTO_ATTACK = 20
280 struct
282 uint32 state; // 0 = stop attack, anything else means continue attacking
283 } auto_attack;
284 // ACTION_T_COMBAT_MOVEMENT = 21
285 struct
287 uint32 state; // 0 = stop combat based movement, anything else continue attacking
288 uint32 melee; // if set: at stop send melee combat stop if in combat, use for terminate melee fighting state for switch to ranged
289 } combat_movement;
290 // ACTION_T_SET_PHASE = 22
291 struct
293 uint32 phase;
294 } set_phase;
295 // ACTION_T_INC_PHASE = 23
296 struct
298 int32 step;
299 } set_inc_phase;
300 // ACTION_T_QUEST_EVENT_ALL = 26
301 struct
303 uint32 questId;
304 } quest_event_all;
305 // ACTION_T_CAST_EVENT_ALL = 27
306 struct
308 uint32 creatureId;
309 uint32 spellId;
310 } cast_event_all;
311 // ACTION_T_REMOVEAURASFROMSPELL = 28
312 struct
314 uint32 target;
315 uint32 spellId;
316 } remove_aura;
317 // ACTION_T_RANGED_MOVEMENT = 29
318 struct
320 uint32 distance;
321 int32 angle;
322 } ranged_movement;
323 // ACTION_T_RANDOM_PHASE = 30
324 struct
326 uint32 phase1;
327 uint32 phase2;
328 uint32 phase3;
329 } random_phase;
330 // ACTION_T_RANDOM_PHASE_RANGE = 31
331 struct
333 uint32 phaseMin;
334 uint32 phaseMax;
335 } random_phase_range;
336 // ACTION_T_SUMMON_ID = 32
337 struct
339 uint32 creatureId;
340 uint32 target;
341 uint32 spawnId;
342 } summon_id;
343 // ACTION_T_KILLED_MONSTER = 33
344 struct
346 uint32 creatureId;
347 uint32 target;
348 } killed_monster;
349 // ACTION_T_SET_INST_DATA = 34
350 struct
352 uint32 field;
353 uint32 value;
354 } set_inst_data;
355 // ACTION_T_SET_INST_DATA64 = 35
356 struct
358 uint32 field;
359 uint32 target;
360 } set_inst_data64;
361 // ACTION_T_UPDATE_TEMPLATE = 36
362 struct
364 uint32 creatureId;
365 uint32 team;
366 } update_template;
367 // ACTION_T_CALL_FOR_HELP = 39
368 struct
370 uint32 radius;
371 } call_for_help;
372 // ACTION_T_SET_SHEATH = 40
373 struct
375 uint32 sheath;
376 } set_sheath;
377 // ACTION_T_SET_INVINCIBILITY_HP_LEVEL = 42
378 struct
380 uint32 hp_level;
381 uint32 is_percent;
382 } invincibility_hp_level;
383 // RAW
384 struct
386 uint32 param1;
387 uint32 param2;
388 uint32 param3;
389 } raw;
393 struct CreatureEventAI_Event
395 uint32 event_id;
397 uint32 creature_id;
399 uint32 event_inverse_phase_mask;
401 EventAI_Type event_type : 16;
402 uint8 event_chance : 8;
403 uint8 event_flags : 8;
405 union
407 // EVENT_T_TIMER = 0
408 // EVENT_T_TIMER_OOC = 1
409 struct
411 uint32 initialMin;
412 uint32 initialMax;
413 uint32 repeatMin;
414 uint32 repeatMax;
415 } timer;
416 // EVENT_T_HP = 2
417 // EVENT_T_MANA = 3
418 // EVENT_T_TARGET_HP = 12
419 // EVENT_T_TARGET_MANA = 18
420 struct
422 uint32 percentMax;
423 uint32 percentMin;
424 uint32 repeatMin;
425 uint32 repeatMax;
426 } percent_range;
427 // EVENT_T_KILL = 5
428 struct
430 uint32 repeatMin;
431 uint32 repeatMax;
432 } kill;
433 // EVENT_T_SPELLHIT = 8
434 struct
436 uint32 spellId;
437 uint32 schoolMask; // -1 (==0xffffffff) is ok value for full mask, or must be more limited mask like (0 < 1) = 1 for normal/physical school
438 uint32 repeatMin;
439 uint32 repeatMax;
440 } spell_hit;
441 // EVENT_T_RANGE = 9
442 struct
444 uint32 minDist;
445 uint32 maxDist;
446 uint32 repeatMin;
447 uint32 repeatMax;
448 } range;
449 // EVENT_T_OOC_LOS = 10
450 struct
452 uint32 noHostile;
453 uint32 maxRange;
454 uint32 repeatMin;
455 uint32 repeatMax;
456 } ooc_los;
457 // EVENT_T_SPAWNED = 11
458 struct
460 uint32 condition;
461 uint32 conditionValue1;
462 } spawned;
463 // EVENT_T_TARGET_CASTING = 13
464 struct
466 uint32 repeatMin;
467 uint32 repeatMax;
468 } target_casting;
469 // EVENT_T_FRIENDLY_HP = 14
470 struct
472 uint32 hpDeficit;
473 uint32 radius;
474 uint32 repeatMin;
475 uint32 repeatMax;
476 } friendly_hp;
477 // EVENT_T_FRIENDLY_IS_CC = 15
478 struct
480 uint32 dispelType; // unused ?
481 uint32 radius;
482 uint32 repeatMin;
483 uint32 repeatMax;
484 } friendly_is_cc;
485 // EVENT_T_FRIENDLY_MISSING_BUFF = 16
486 struct
488 uint32 spellId;
489 uint32 radius;
490 uint32 repeatMin;
491 uint32 repeatMax;
492 } friendly_buff;
493 // EVENT_T_SUMMONED_UNIT = 17
494 struct
496 uint32 creatureId;
497 uint32 repeatMin;
498 uint32 repeatMax;
499 } summon_unit;
500 // EVENT_T_QUEST_ACCEPT = 19
501 // EVENT_T_QUEST_COMPLETE = 20
502 struct
504 uint32 questId;
505 } quest;
506 // EVENT_T_RECEIVE_EMOTE = 22
507 struct
509 uint32 emoteId;
510 uint32 condition;
511 uint32 conditionValue1;
512 uint32 conditionValue2;
513 } receive_emote;
514 // EVENT_T_BUFFED = 23
515 // EVENT_T_TARGET_BUFFED = 24
516 struct
518 uint32 spellId;
519 uint32 amount;
520 uint32 repeatMin;
521 uint32 repeatMax;
522 } buffed;
524 // RAW
525 struct
527 uint32 param1;
528 uint32 param2;
529 uint32 param3;
530 uint32 param4;
531 } raw;
534 CreatureEventAI_Action action[MAX_ACTIONS];
536 //Event_Map
537 typedef UNORDERED_MAP<uint32, std::vector<CreatureEventAI_Event> > 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 static int Permissible(const Creature *);
591 bool ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pActionInvoker = NULL);
592 void ProcessAction(CreatureEventAI_Action const& action, uint32 rnd, uint32 EventId, Unit* pActionInvoker);
593 inline uint32 GetRandActionParam(uint32 rnd, uint32 param1, uint32 param2, uint32 param3);
594 inline int32 GetRandActionParam(uint32 rnd, int32 param1, int32 param2, int32 param3);
595 inline Unit* GetTargetByType(uint32 Target, Unit* pActionInvoker);
596 inline Unit* SelectUnit(AttackingTarget target, uint32 position);
598 void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target);
599 void DoMeleeAttackIfReady();
600 bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered);
602 bool SpawnedEventConditionsCheck(CreatureEventAI_Event const& event);
604 Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff);
605 void DoFindFriendlyMissingBuff(std::list<Creature*>& _list, float range, uint32 spellid);
606 void DoFindFriendlyCC(std::list<Creature*>& _list, float range);
608 //Holder for events (stores enabled, time, and eventid)
609 std::list<CreatureEventAIHolder> CreatureEventAIList;
610 uint32 EventUpdateTime; //Time between event updates
611 uint32 EventDiff; //Time between the last event call
612 bool bEmptyList;
614 //Variables used by Events themselves
615 uint8 Phase; // Current phase, max 32 phases
616 bool CombatMovementEnabled; // If we allow targeted movment gen (movement twoards top threat)
617 bool MeleeEnabled; // If we allow melee auto attack
618 float AttackDistance; // Distance to attack from
619 float AttackAngle; // Angle of attack
620 uint32 InvinceabilityHpLevel; // Minimal health level allowed at damage apply
622 #endif