[9362] Make specs work at least for action bars
[getmangos.git] / src / game / Unit.h
blobd2d38767b98468a19b06166c2ff5685617335738
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 __UNIT_H
20 #define __UNIT_H
22 #include "Common.h"
23 #include "Object.h"
24 #include "Opcodes.h"
25 #include "SpellAuraDefines.h"
26 #include "UpdateFields.h"
27 #include "SharedDefines.h"
28 #include "ThreatManager.h"
29 #include "HostileRefManager.h"
30 #include "FollowerReference.h"
31 #include "FollowerRefManager.h"
32 #include "Utilities/EventProcessor.h"
33 #include "MotionMaster.h"
34 #include "DBCStructure.h"
35 #include <list>
37 enum SpellInterruptFlags
39 SPELL_INTERRUPT_FLAG_MOVEMENT = 0x01,
40 SPELL_INTERRUPT_FLAG_DAMAGE = 0x02,
41 SPELL_INTERRUPT_FLAG_INTERRUPT = 0x04,
42 SPELL_INTERRUPT_FLAG_AUTOATTACK = 0x08,
43 SPELL_INTERRUPT_FLAG_ABORT_ON_DMG = 0x10, // _complete_ interrupt on direct damage
44 //SPELL_INTERRUPT_UNK = 0x20 // unk, 564 of 727 spells having this spell start with "Glyph"
47 enum SpellChannelInterruptFlags
49 CHANNEL_FLAG_DAMAGE = 0x0002,
50 CHANNEL_FLAG_MOVEMENT = 0x0008,
51 CHANNEL_FLAG_TURNING = 0x0010,
52 CHANNEL_FLAG_DAMAGE2 = 0x0080,
53 CHANNEL_FLAG_DELAY = 0x4000
56 enum SpellAuraInterruptFlags
58 AURA_INTERRUPT_FLAG_UNK0 = 0x00000001, // 0 removed when getting hit by a negative spell?
59 AURA_INTERRUPT_FLAG_DAMAGE = 0x00000002, // 1 removed by any damage
60 AURA_INTERRUPT_FLAG_UNK2 = 0x00000004, // 2
61 AURA_INTERRUPT_FLAG_MOVE = 0x00000008, // 3 removed by any movement
62 AURA_INTERRUPT_FLAG_TURNING = 0x00000010, // 4 removed by any turning
63 AURA_INTERRUPT_FLAG_ENTER_COMBAT = 0x00000020, // 5 removed by entering combat
64 AURA_INTERRUPT_FLAG_NOT_MOUNTED = 0x00000040, // 6 removed by unmounting
65 AURA_INTERRUPT_FLAG_NOT_ABOVEWATER = 0x00000080, // 7 removed by entering water
66 AURA_INTERRUPT_FLAG_NOT_UNDERWATER = 0x00000100, // 8 removed by leaving water
67 AURA_INTERRUPT_FLAG_NOT_SHEATHED = 0x00000200, // 9 removed by unsheathing
68 AURA_INTERRUPT_FLAG_UNK10 = 0x00000400, // 10
69 AURA_INTERRUPT_FLAG_UNK11 = 0x00000800, // 11
70 AURA_INTERRUPT_FLAG_UNK12 = 0x00001000, // 12 removed by attack?
71 AURA_INTERRUPT_FLAG_UNK13 = 0x00002000, // 13
72 AURA_INTERRUPT_FLAG_UNK14 = 0x00004000, // 14
73 AURA_INTERRUPT_FLAG_UNK15 = 0x00008000, // 15 removed by casting a spell?
74 AURA_INTERRUPT_FLAG_UNK16 = 0x00010000, // 16
75 AURA_INTERRUPT_FLAG_MOUNTING = 0x00020000, // 17 removed by mounting
76 AURA_INTERRUPT_FLAG_NOT_SEATED = 0x00040000, // 18 removed by standing up (used by food and drink mostly and sleep/Fake Death like)
77 AURA_INTERRUPT_FLAG_CHANGE_MAP = 0x00080000, // 19 leaving map/getting teleported
78 AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION = 0x00100000, // 20 removed by auras that make you invulnerable, or make other to loose selection on you
79 AURA_INTERRUPT_FLAG_UNK21 = 0x00200000, // 21
80 AURA_INTERRUPT_FLAG_UNK22 = 0x00400000, // 22
81 AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT = 0x00800000, // 23 removed by entering pvp combat
82 AURA_INTERRUPT_FLAG_DIRECT_DAMAGE = 0x01000000 // 24 removed by any direct damage
85 enum SpellModOp
87 SPELLMOD_DAMAGE = 0,
88 SPELLMOD_DURATION = 1,
89 SPELLMOD_THREAT = 2,
90 SPELLMOD_EFFECT1 = 3,
91 SPELLMOD_CHARGES = 4,
92 SPELLMOD_RANGE = 5,
93 SPELLMOD_RADIUS = 6,
94 SPELLMOD_CRITICAL_CHANCE = 7,
95 SPELLMOD_ALL_EFFECTS = 8,
96 SPELLMOD_NOT_LOSE_CASTING_TIME = 9,
97 SPELLMOD_CASTING_TIME = 10,
98 SPELLMOD_COOLDOWN = 11,
99 SPELLMOD_EFFECT2 = 12,
100 // spellmod 13 unused
101 SPELLMOD_COST = 14,
102 SPELLMOD_CRIT_DAMAGE_BONUS = 15,
103 SPELLMOD_RESIST_MISS_CHANCE = 16,
104 SPELLMOD_JUMP_TARGETS = 17,
105 SPELLMOD_CHANCE_OF_SUCCESS = 18, // Only used with SPELL_AURA_ADD_FLAT_MODIFIER and affects proc spells
106 SPELLMOD_ACTIVATION_TIME = 19,
107 SPELLMOD_EFFECT_PAST_FIRST = 20,
108 SPELLMOD_CASTING_TIME_OLD = 21,
109 SPELLMOD_DOT = 22,
110 SPELLMOD_EFFECT3 = 23,
111 SPELLMOD_SPELL_BONUS_DAMAGE = 24,
112 // spellmod 25 unused
113 SPELLMOD_FREQUENCY_OF_SUCCESS = 26, // Only used with SPELL_AURA_ADD_PCT_MODIFIER and affects used on proc spells
114 SPELLMOD_MULTIPLE_VALUE = 27,
115 SPELLMOD_RESIST_DISPEL_CHANCE = 28
118 #define MAX_SPELLMOD 32
120 enum SpellFacingFlags
122 SPELL_FACING_FLAG_INFRONT = 0x0001
125 #define BASE_MINDAMAGE 1.0f
126 #define BASE_MAXDAMAGE 2.0f
127 #define BASE_ATTACK_TIME 2000
129 // byte value (UNIT_FIELD_BYTES_1,0)
130 enum UnitStandStateType
132 UNIT_STAND_STATE_STAND = 0,
133 UNIT_STAND_STATE_SIT = 1,
134 UNIT_STAND_STATE_SIT_CHAIR = 2,
135 UNIT_STAND_STATE_SLEEP = 3,
136 UNIT_STAND_STATE_SIT_LOW_CHAIR = 4,
137 UNIT_STAND_STATE_SIT_MEDIUM_CHAIR = 5,
138 UNIT_STAND_STATE_SIT_HIGH_CHAIR = 6,
139 UNIT_STAND_STATE_DEAD = 7,
140 UNIT_STAND_STATE_KNEEL = 8,
141 UNIT_STAND_STATE_SUBMERGED = 9
144 // byte flags value (UNIT_FIELD_BYTES_1,2)
145 enum UnitStandFlags
147 UNIT_STAND_FLAGS_UNK1 = 0x01,
148 UNIT_STAND_FLAGS_CREEP = 0x02,
149 UNIT_STAND_FLAGS_UNK3 = 0x04,
150 UNIT_STAND_FLAGS_UNK4 = 0x08,
151 UNIT_STAND_FLAGS_UNK5 = 0x10,
152 UNIT_STAND_FLAGS_ALL = 0xFF
155 // byte flags value (UNIT_FIELD_BYTES_1,3)
156 enum UnitBytes1_Flags
158 UNIT_BYTE1_FLAG_ALWAYS_STAND = 0x01,
159 UNIT_BYTE1_FLAG_UNK_2 = 0x02,
160 UNIT_BYTE1_FLAG_UNTRACKABLE = 0x04,
161 UNIT_BYTE1_FLAG_ALL = 0xFF
164 // byte value (UNIT_FIELD_BYTES_2,3)
165 enum ShapeshiftForm
167 FORM_NONE = 0x00,
168 FORM_CAT = 0x01,
169 FORM_TREE = 0x02,
170 FORM_TRAVEL = 0x03,
171 FORM_AQUA = 0x04,
172 FORM_BEAR = 0x05,
173 FORM_AMBIENT = 0x06,
174 FORM_GHOUL = 0x07,
175 FORM_DIREBEAR = 0x08,
176 FORM_STEVES_GHOUL = 0x09,
177 FORM_THARONJA_SKELETON = 0x0A,
178 FORM_TEST_OF_STRENGTH = 0x0B,
179 FORM_BLB_PLAYER = 0x0C,
180 FORM_SHADOW_DANCE = 0x0D,
181 FORM_CREATUREBEAR = 0x0E,
182 FORM_CREATURECAT = 0x0F,
183 FORM_GHOSTWOLF = 0x10,
184 FORM_BATTLESTANCE = 0x11,
185 FORM_DEFENSIVESTANCE = 0x12,
186 FORM_BERSERKERSTANCE = 0x13,
187 FORM_TEST = 0x14,
188 FORM_ZOMBIE = 0x15,
189 FORM_METAMORPHOSIS = 0x16,
190 FORM_UNDEAD = 0x19,
191 FORM_FRENZY = 0x1A,
192 FORM_FLIGHT_EPIC = 0x1B,
193 FORM_SHADOW = 0x1C,
194 FORM_FLIGHT = 0x1D,
195 FORM_STEALTH = 0x1E,
196 FORM_MOONKIN = 0x1F,
197 FORM_SPIRITOFREDEMPTION = 0x20,
200 // byte value (UNIT_FIELD_BYTES_2,0)
201 enum SheathState
203 SHEATH_STATE_UNARMED = 0, // non prepared weapon
204 SHEATH_STATE_MELEE = 1, // prepared melee weapon
205 SHEATH_STATE_RANGED = 2 // prepared ranged weapon
208 #define MAX_SHEATH_STATE 3
210 // byte flags value (UNIT_FIELD_BYTES_2,1)
211 enum UnitPVPStateFlags
213 UNIT_BYTE2_FLAG_PVP = 0x01,
214 UNIT_BYTE2_FLAG_UNK1 = 0x02,
215 UNIT_BYTE2_FLAG_FFA_PVP = 0x04,
216 UNIT_BYTE2_FLAG_SANCTUARY = 0x08,
217 UNIT_BYTE2_FLAG_UNK4 = 0x10,
218 UNIT_BYTE2_FLAG_UNK5 = 0x20,
219 UNIT_BYTE2_FLAG_UNK6 = 0x40,
220 UNIT_BYTE2_FLAG_UNK7 = 0x80
223 // byte flags value (UNIT_FIELD_BYTES_2,2)
224 enum UnitRename
226 UNIT_CAN_BE_RENAMED = 0x01,
227 UNIT_CAN_BE_ABANDONED = 0x02,
230 #define CREATURE_MAX_SPELLS 4
232 enum Swing
234 NOSWING = 0,
235 SINGLEHANDEDSWING = 1,
236 TWOHANDEDSWING = 2
239 enum VictimState
241 VICTIMSTATE_UNKNOWN1 = 0,
242 VICTIMSTATE_NORMAL = 1,
243 VICTIMSTATE_DODGE = 2,
244 VICTIMSTATE_PARRY = 3,
245 VICTIMSTATE_INTERRUPT = 4,
246 VICTIMSTATE_BLOCKS = 5,
247 VICTIMSTATE_EVADES = 6,
248 VICTIMSTATE_IS_IMMUNE = 7,
249 VICTIMSTATE_DEFLECTS = 8
252 enum HitInfo
254 HITINFO_NORMALSWING = 0x00000000,
255 HITINFO_UNK1 = 0x00000001, // req correct packet structure
256 HITINFO_NORMALSWING2 = 0x00000002,
257 HITINFO_LEFTSWING = 0x00000004,
258 HITINFO_UNK2 = 0x00000008,
259 HITINFO_MISS = 0x00000010,
260 HITINFO_ABSORB = 0x00000020, // absorbed damage
261 HITINFO_ABSORB2 = 0x00000040, // absorbed damage
262 HITINFO_RESIST = 0x00000080, // resisted atleast some damage
263 HITINFO_RESIST2 = 0x00000100, // resisted atleast some damage
264 HITINFO_CRITICALHIT = 0x00000200, // critical hit
265 // 0x00000400
266 // 0x00000800
267 // 0x00001000
268 HITINFO_BLOCK = 0x00002000, // blocked damage
269 // 0x00004000
270 // 0x00008000
271 HITINFO_GLANCING = 0x00010000,
272 HITINFO_CRUSHING = 0x00020000,
273 HITINFO_NOACTION = 0x00040000, // guessed
274 // 0x00080000
275 // 0x00100000
276 HITINFO_SWINGNOHITSOUND = 0x00200000, // guessed
277 // 0x00400000
278 HITINFO_UNK3 = 0x00800000
281 //i would like to remove this: (it is defined in item.h
282 enum InventorySlot
284 NULL_BAG = 0,
285 NULL_SLOT = 255
288 struct FactionTemplateEntry;
289 struct Modifier;
290 struct SpellEntry;
291 struct SpellEntryExt;
293 class Aura;
294 class Creature;
295 class Spell;
296 class DynamicObject;
297 class GameObject;
298 class Item;
299 class Pet;
300 class Path;
301 class PetAura;
302 class Totem;
304 struct SpellImmune
306 uint32 type;
307 uint32 spellId;
310 typedef std::list<SpellImmune> SpellImmuneList;
312 enum UnitModifierType
314 BASE_VALUE = 0,
315 BASE_PCT = 1,
316 TOTAL_VALUE = 2,
317 TOTAL_PCT = 3,
318 MODIFIER_TYPE_END = 4
321 enum WeaponDamageRange
323 MINDAMAGE,
324 MAXDAMAGE
327 enum DamageTypeToSchool
329 RESISTANCE,
330 DAMAGE_DEALT,
331 DAMAGE_TAKEN
334 enum AuraRemoveMode
336 AURA_REMOVE_BY_DEFAULT,
337 AURA_REMOVE_BY_STACK, // at replace by similar aura
338 AURA_REMOVE_BY_CANCEL,
339 AURA_REMOVE_BY_DISPEL,
340 AURA_REMOVE_BY_DEATH,
341 AURA_REMOVE_BY_DELETE, // use for speedup and prevent unexpected effects at player logout/pet unsummon (must be used _only_ after save), delete.
344 enum UnitMods
346 UNIT_MOD_STAT_STRENGTH, // UNIT_MOD_STAT_STRENGTH..UNIT_MOD_STAT_SPIRIT must be in existed order, it's accessed by index values of Stats enum.
347 UNIT_MOD_STAT_AGILITY,
348 UNIT_MOD_STAT_STAMINA,
349 UNIT_MOD_STAT_INTELLECT,
350 UNIT_MOD_STAT_SPIRIT,
351 UNIT_MOD_HEALTH,
352 UNIT_MOD_MANA, // UNIT_MOD_MANA..UNIT_MOD_RUNIC_POWER must be in existed order, it's accessed by index values of Powers enum.
353 UNIT_MOD_RAGE,
354 UNIT_MOD_FOCUS,
355 UNIT_MOD_ENERGY,
356 UNIT_MOD_HAPPINESS,
357 UNIT_MOD_RUNE,
358 UNIT_MOD_RUNIC_POWER,
359 UNIT_MOD_ARMOR, // UNIT_MOD_ARMOR..UNIT_MOD_RESISTANCE_ARCANE must be in existed order, it's accessed by index values of SpellSchools enum.
360 UNIT_MOD_RESISTANCE_HOLY,
361 UNIT_MOD_RESISTANCE_FIRE,
362 UNIT_MOD_RESISTANCE_NATURE,
363 UNIT_MOD_RESISTANCE_FROST,
364 UNIT_MOD_RESISTANCE_SHADOW,
365 UNIT_MOD_RESISTANCE_ARCANE,
366 UNIT_MOD_ATTACK_POWER,
367 UNIT_MOD_ATTACK_POWER_RANGED,
368 UNIT_MOD_DAMAGE_MAINHAND,
369 UNIT_MOD_DAMAGE_OFFHAND,
370 UNIT_MOD_DAMAGE_RANGED,
371 UNIT_MOD_END,
372 // synonyms
373 UNIT_MOD_STAT_START = UNIT_MOD_STAT_STRENGTH,
374 UNIT_MOD_STAT_END = UNIT_MOD_STAT_SPIRIT + 1,
375 UNIT_MOD_RESISTANCE_START = UNIT_MOD_ARMOR,
376 UNIT_MOD_RESISTANCE_END = UNIT_MOD_RESISTANCE_ARCANE + 1,
377 UNIT_MOD_POWER_START = UNIT_MOD_MANA,
378 UNIT_MOD_POWER_END = UNIT_MOD_RUNIC_POWER + 1
381 enum BaseModGroup
383 CRIT_PERCENTAGE,
384 RANGED_CRIT_PERCENTAGE,
385 OFFHAND_CRIT_PERCENTAGE,
386 SHIELD_BLOCK_VALUE,
387 BASEMOD_END
390 enum BaseModType
392 FLAT_MOD,
393 PCT_MOD
396 #define MOD_END (PCT_MOD+1)
398 enum DeathState
400 ALIVE = 0,
401 JUST_DIED = 1,
402 CORPSE = 2,
403 DEAD = 3,
404 JUST_ALIVED = 4,
405 DEAD_FALLING= 5
408 // internal state flags for some auras and movement generators, other.
409 enum UnitState
411 // persistent state (applied by aura/etc until expire)
412 UNIT_STAT_MELEE_ATTACKING = 0x00000001, // unit is melee attacking someone Unit::Attack
413 UNIT_STAT_ATTACK_PLAYER = 0x00000002, // unit attack player or player's controlled unit and have contested pvpv timer setup, until timer expire, combat end and etc
414 UNIT_STAT_DIED = 0x00000004, // Unit::SetFeignDeath
415 UNIT_STAT_STUNNED = 0x00000008, // Aura::HandleAuraModStun
416 UNIT_STAT_ROOT = 0x00000010, // Aura::HandleAuraModRoot
417 UNIT_STAT_ISOLATED = 0x00000020, // area auras do not affect other players, Aura::HandleAuraModSchoolImmunity
419 // persistent movement generator state (all time while movement generator applied to unit (independent from top state of movegen)
420 UNIT_STAT_IN_FLIGHT = 0x00000040, // player is in flight mode
421 UNIT_STAT_DISTRACTED = 0x00000080, // DistractedMovementGenerator active
423 // persistent movement generator state with non-persistent mirror states for stop support
424 // (can be removed temporary by stop command or another movement generator apply)
425 // not use _MOVE versions for generic movegen state, it can be removed temporary for unit stop and etc
426 UNIT_STAT_CONFUSED = 0x00000100, // ConfusedMovementGenerator active/onstack
427 UNIT_STAT_CONFUSED_MOVE = 0x00000200,
428 UNIT_STAT_ROAMING = 0x00000400, // RandomMovementGenerator/PointMovementGenerator/WaypointMovementGenerator active (now always set)
429 UNIT_STAT_ROAMING_MOVE = 0x00000800,
430 UNIT_STAT_CHASE = 0x00001000, // ChaseMovementGenerator active
431 UNIT_STAT_CHASE_MOVE = 0x00002000,
432 UNIT_STAT_FOLLOW = 0x00004000, // FollowMovementGenerator active
433 UNIT_STAT_FOLLOW_MOVE = 0x00008000,
434 UNIT_STAT_FLEEING = 0x00010000, // FleeMovementGenerator/TimedFleeingMovementGenerator active/onstack
435 UNIT_STAT_FLEEING_MOVE = 0x00020000,
437 // masks (only for check)
439 // can't move currently
440 UNIT_STAT_CAN_NOT_MOVE = UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DIED,
442 // stay by different reasons
443 UNIT_STAT_NOT_MOVE = UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DIED |
444 UNIT_STAT_DISTRACTED,
446 // stay or scripted movement for effect( = in player case you can't move by client command)
447 UNIT_STAT_NO_FREE_MOVE = UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DIED |
448 UNIT_STAT_IN_FLIGHT |
449 UNIT_STAT_CONFUSED | UNIT_STAT_FLEEING,
451 // not react at move in sight or other
452 UNIT_STAT_CAN_NOT_REACT = UNIT_STAT_STUNNED | UNIT_STAT_DIED |
453 UNIT_STAT_CONFUSED | UNIT_STAT_FLEEING,
455 // masks (for check or reset)
457 // for real move using movegen check and stop (except unstoppable flight)
458 UNIT_STAT_MOVING = UNIT_STAT_ROAMING_MOVE | UNIT_STAT_CHASE_MOVE | UNIT_STAT_FOLLOW_MOVE | UNIT_STAT_FLEEING_MOVE,
460 UNIT_STAT_ALL_STATE = 0xFFFFFFFF
463 enum UnitMoveType
465 MOVE_WALK = 0,
466 MOVE_RUN = 1,
467 MOVE_RUN_BACK = 2,
468 MOVE_SWIM = 3,
469 MOVE_SWIM_BACK = 4,
470 MOVE_TURN_RATE = 5,
471 MOVE_FLIGHT = 6,
472 MOVE_FLIGHT_BACK = 7,
473 MOVE_PITCH_RATE = 8
476 #define MAX_MOVE_TYPE 9
478 extern float baseMoveSpeed[MAX_MOVE_TYPE];
480 enum CombatRating
482 CR_WEAPON_SKILL = 0,
483 CR_DEFENSE_SKILL = 1,
484 CR_DODGE = 2,
485 CR_PARRY = 3,
486 CR_BLOCK = 4,
487 CR_HIT_MELEE = 5,
488 CR_HIT_RANGED = 6,
489 CR_HIT_SPELL = 7,
490 CR_CRIT_MELEE = 8,
491 CR_CRIT_RANGED = 9,
492 CR_CRIT_SPELL = 10,
493 CR_HIT_TAKEN_MELEE = 11,
494 CR_HIT_TAKEN_RANGED = 12,
495 CR_HIT_TAKEN_SPELL = 13,
496 CR_CRIT_TAKEN_MELEE = 14,
497 CR_CRIT_TAKEN_RANGED = 15,
498 CR_CRIT_TAKEN_SPELL = 16,
499 CR_HASTE_MELEE = 17,
500 CR_HASTE_RANGED = 18,
501 CR_HASTE_SPELL = 19,
502 CR_WEAPON_SKILL_MAINHAND = 20,
503 CR_WEAPON_SKILL_OFFHAND = 21,
504 CR_WEAPON_SKILL_RANGED = 22,
505 CR_EXPERTISE = 23,
506 CR_ARMOR_PENETRATION = 24
509 #define MAX_COMBAT_RATING 25
511 enum DamageEffectType
513 DIRECT_DAMAGE = 0, // used for normal weapon damage (not for class abilities or spells)
514 SPELL_DIRECT_DAMAGE = 1, // spell/class abilities damage
515 DOT = 2,
516 HEAL = 3,
517 NODAMAGE = 4, // used also in case when damage applied to health but not applied to spell channelInterruptFlags/etc
518 SELF_DAMAGE = 5
521 /// internal used flags for marking special auras - for example some dummy-auras
522 enum UnitAuraFlags
524 UNIT_AURAFLAG_ALIVE_INVISIBLE = 0x1, // aura which makes unit invisible for alive
527 enum UnitVisibility
529 VISIBILITY_OFF = 0, // absolute, not detectable, GM-like, can see all other
530 VISIBILITY_ON = 1,
531 VISIBILITY_GROUP_STEALTH = 2, // detect chance, seen and can see group members
532 VISIBILITY_GROUP_INVISIBILITY = 3, // invisibility, can see and can be seen only another invisible unit or invisible detection unit, set only if not stealthed, and in checks not used (mask used instead)
533 VISIBILITY_GROUP_NO_DETECT = 4, // state just at stealth apply for update Grid state. Don't remove, otherwise stealth spells will break
534 VISIBILITY_RESPAWN = 5 // special totally not detectable visibility for force delete object at respawn command
537 // Value masks for UNIT_FIELD_FLAGS
538 enum UnitFlags
540 UNIT_FLAG_UNK_0 = 0x00000001,
541 UNIT_FLAG_NON_ATTACKABLE = 0x00000002, // not attackable
542 UNIT_FLAG_DISABLE_MOVE = 0x00000004,
543 UNIT_FLAG_PVP_ATTACKABLE = 0x00000008, // allow apply pvp rules to attackable state in addition to faction dependent state
544 UNIT_FLAG_RENAME = 0x00000010,
545 UNIT_FLAG_PREPARATION = 0x00000020, // don't take reagents for spells with SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
546 UNIT_FLAG_UNK_6 = 0x00000040,
547 UNIT_FLAG_NOT_ATTACKABLE_1 = 0x00000080, // ?? (UNIT_FLAG_PVP_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1) is NON_PVP_ATTACKABLE
548 UNIT_FLAG_OOC_NOT_ATTACKABLE = 0x00000100, // 2.0.8 - (OOC Out Of Combat) Can not be attacked when not in combat. Removed if unit for some reason enter combat.
549 UNIT_FLAG_UNK_9 = 0x00000200, // 3.0.3 - makes you unable to attack everything
550 UNIT_FLAG_LOOTING = 0x00000400, // loot animation
551 UNIT_FLAG_PET_IN_COMBAT = 0x00000800, // in combat?, 2.0.8
552 UNIT_FLAG_PVP = 0x00001000, // changed in 3.0.3
553 UNIT_FLAG_SILENCED = 0x00002000, // silenced, 2.1.1
554 UNIT_FLAG_UNK_14 = 0x00004000, // 2.0.8
555 UNIT_FLAG_UNK_15 = 0x00008000,
556 UNIT_FLAG_UNK_16 = 0x00010000, // removes attackable icon
557 UNIT_FLAG_PACIFIED = 0x00020000, // 3.0.3 ok
558 UNIT_FLAG_STUNNED = 0x00040000, // 3.0.3 ok
559 UNIT_FLAG_IN_COMBAT = 0x00080000,
560 UNIT_FLAG_TAXI_FLIGHT = 0x00100000, // disable casting at client side spell not allowed by taxi flight (mounted?), probably used with 0x4 flag
561 UNIT_FLAG_DISARMED = 0x00200000, // 3.0.3, disable melee spells casting..., "Required melee weapon" added to melee spells tooltip.
562 UNIT_FLAG_CONFUSED = 0x00400000,
563 UNIT_FLAG_FLEEING = 0x00800000,
564 UNIT_FLAG_PLAYER_CONTROLLED = 0x01000000, // used in spell Eyes of the Beast for pet... let attack by controlled creature
565 UNIT_FLAG_NOT_SELECTABLE = 0x02000000,
566 UNIT_FLAG_SKINNABLE = 0x04000000,
567 UNIT_FLAG_MOUNT = 0x08000000,
568 UNIT_FLAG_UNK_28 = 0x10000000,
569 UNIT_FLAG_UNK_29 = 0x20000000, // used in Feing Death spell
570 UNIT_FLAG_SHEATHE = 0x40000000,
571 UNIT_FLAG_UNK_31 = 0x80000000 // set skinnable icon and also changes color of portrait
574 // Value masks for UNIT_FIELD_FLAGS_2
575 enum UnitFlags2
577 UNIT_FLAG2_FEIGN_DEATH = 0x00000001,
578 UNIT_FLAG2_UNK1 = 0x00000002, // Hide unit model (show only player equip)
579 UNIT_FLAG2_COMPREHEND_LANG = 0x00000008,
580 UNIT_FLAG2_FORCE_MOVE = 0x00000040,
581 UNIT_FLAG2_REGENERATE_POWER = 0x00000800
584 /// Non Player Character flags
585 enum NPCFlags
587 UNIT_NPC_FLAG_NONE = 0x00000000,
588 UNIT_NPC_FLAG_GOSSIP = 0x00000001, // 100%
589 UNIT_NPC_FLAG_QUESTGIVER = 0x00000002, // guessed, probably ok
590 UNIT_NPC_FLAG_UNK1 = 0x00000004,
591 UNIT_NPC_FLAG_UNK2 = 0x00000008,
592 UNIT_NPC_FLAG_TRAINER = 0x00000010, // 100%
593 UNIT_NPC_FLAG_TRAINER_CLASS = 0x00000020, // 100%
594 UNIT_NPC_FLAG_TRAINER_PROFESSION = 0x00000040, // 100%
595 UNIT_NPC_FLAG_VENDOR = 0x00000080, // 100%
596 UNIT_NPC_FLAG_VENDOR_AMMO = 0x00000100, // 100%, general goods vendor
597 UNIT_NPC_FLAG_VENDOR_FOOD = 0x00000200, // 100%
598 UNIT_NPC_FLAG_VENDOR_POISON = 0x00000400, // guessed
599 UNIT_NPC_FLAG_VENDOR_REAGENT = 0x00000800, // 100%
600 UNIT_NPC_FLAG_REPAIR = 0x00001000, // 100%
601 UNIT_NPC_FLAG_FLIGHTMASTER = 0x00002000, // 100%
602 UNIT_NPC_FLAG_SPIRITHEALER = 0x00004000, // guessed
603 UNIT_NPC_FLAG_SPIRITGUIDE = 0x00008000, // guessed
604 UNIT_NPC_FLAG_INNKEEPER = 0x00010000, // 100%
605 UNIT_NPC_FLAG_BANKER = 0x00020000, // 100%
606 UNIT_NPC_FLAG_PETITIONER = 0x00040000, // 100% 0xC0000 = guild petitions, 0x40000 = arena team petitions
607 UNIT_NPC_FLAG_TABARDDESIGNER = 0x00080000, // 100%
608 UNIT_NPC_FLAG_BATTLEMASTER = 0x00100000, // 100%
609 UNIT_NPC_FLAG_AUCTIONEER = 0x00200000, // 100%
610 UNIT_NPC_FLAG_STABLEMASTER = 0x00400000, // 100%
611 UNIT_NPC_FLAG_GUILD_BANKER = 0x00800000, // cause client to send 997 opcode
612 UNIT_NPC_FLAG_SPELLCLICK = 0x01000000, // cause client to send 1015 opcode (spell click), dynamic, set at loading and don't must be set in DB
613 UNIT_NPC_FLAG_GUARD = 0x10000000 // custom flag for guards
616 // used in most movement packets (send and received)
617 enum MovementFlags
619 MOVEFLAG_NONE = 0x00000000,
620 MOVEFLAG_FORWARD = 0x00000001,
621 MOVEFLAG_BACKWARD = 0x00000002,
622 MOVEFLAG_STRAFE_LEFT = 0x00000004,
623 MOVEFLAG_STRAFE_RIGHT = 0x00000008,
624 MOVEFLAG_TURN_LEFT = 0x00000010,
625 MOVEFLAG_TURN_RIGHT = 0x00000020,
626 MOVEFLAG_PITCH_UP = 0x00000040,
627 MOVEFLAG_PITCH_DOWN = 0x00000080,
628 MOVEFLAG_WALK_MODE = 0x00000100, // Walking
629 MOVEFLAG_ONTRANSPORT = 0x00000200,
630 MOVEFLAG_LEVITATING = 0x00000400,
631 MOVEFLAG_ROOT = 0x00000800,
632 MOVEFLAG_FALLING = 0x00001000,
633 MOVEFLAG_FALLINGFAR = 0x00002000,
634 MOVEFLAG_PENDINGSTOP = 0x00004000,
635 MOVEFLAG_PENDINGSTRAFESTOP = 0x00008000,
636 MOVEFLAG_PENDINGFORWARD = 0x00010000,
637 MOVEFLAG_PENDINGBACKWARD = 0x00020000,
638 MOVEFLAG_PENDINGSTRAFELEFT = 0x00040000,
639 MOVEFLAG_PENDINGSTRAFERIGHT = 0x00080000,
640 MOVEFLAG_PENDINGROOT = 0x00100000,
641 MOVEFLAG_SWIMMING = 0x00200000, // appears with fly flag also
642 MOVEFLAG_ASCENDING = 0x00400000, // swim up also
643 MOVEFLAG_DESCENDING = 0x00800000, // swim down also
644 MOVEFLAG_CAN_FLY = 0x01000000, // can fly in 3.3?
645 MOVEFLAG_FLYING = 0x02000000, // Actual flying mode
646 MOVEFLAG_SPLINE_ELEVATION = 0x04000000, // used for flight paths
647 MOVEFLAG_SPLINE_ENABLED = 0x08000000, // used for flight paths
648 MOVEFLAG_WATERWALKING = 0x10000000, // prevent unit from falling through water
649 MOVEFLAG_SAFE_FALL = 0x20000000, // active rogue safe fall spell (passive)
650 MOVEFLAG_HOVER = 0x40000000
653 // flags that use in movement check for example at spell casting
654 MovementFlags const movementFlagsMask = MovementFlags(
655 MOVEFLAG_FORWARD |MOVEFLAG_BACKWARD |MOVEFLAG_STRAFE_LEFT |MOVEFLAG_STRAFE_RIGHT|
656 MOVEFLAG_PITCH_UP|MOVEFLAG_PITCH_DOWN|MOVEFLAG_ROOT |
657 MOVEFLAG_FALLING |MOVEFLAG_FALLINGFAR|MOVEFLAG_ASCENDING |
658 MOVEFLAG_FLYING |MOVEFLAG_SPLINE_ELEVATION
661 MovementFlags const movementOrTurningFlagsMask = MovementFlags(
662 movementFlagsMask | MOVEFLAG_TURN_LEFT | MOVEFLAG_TURN_RIGHT
665 enum MovementFlags2
667 MOVEFLAG2_NONE = 0x0000,
668 MOVEFLAG2_UNK1 = 0x0001,
669 MOVEFLAG2_UNK2 = 0x0002,
670 MOVEFLAG2_UNK3 = 0x0004,
671 MOVEFLAG2_FULLSPEEDTURNING = 0x0008,
672 MOVEFLAG2_FULLSPEEDPITCHING = 0x0010,
673 MOVEFLAG2_ALLOW_PITCHING = 0x0020,
674 MOVEFLAG2_UNK4 = 0x0040,
675 MOVEFLAG2_UNK5 = 0x0080,
676 MOVEFLAG2_UNK6 = 0x0100,
677 MOVEFLAG2_UNK7 = 0x0200,
678 MOVEFLAG2_INTERP_MOVEMENT = 0x0400,
679 MOVEFLAG2_INTERP_TURNING = 0x0800,
680 MOVEFLAG2_INTERP_PITCHING = 0x1000,
681 MOVEFLAG2_UNK8 = 0x2000,
682 MOVEFLAG2_UNK9 = 0x4000,
683 MOVEFLAG2_UNK10 = 0x8000,
684 MOVEFLAG2_INTERP_MASK = MOVEFLAG2_INTERP_MOVEMENT | MOVEFLAG2_INTERP_TURNING | MOVEFLAG2_INTERP_PITCHING
687 enum SplineFlags
689 SPLINEFLAG_NONE = 0x00000000,
690 SPLINEFLAG_FORWARD = 0x00000001,
691 SPLINEFLAG_BACKWARD = 0x00000002,
692 SPLINEFLAG_STRAFE_LEFT = 0x00000004,
693 SPLINEFLAG_STRAFE_RIGHT = 0x00000008,
694 SPLINEFLAG_LEFT = 0x00000010,
695 SPLINEFLAG_RIGHT = 0x00000020,
696 SPLINEFLAG_PITCH_UP = 0x00000040,
697 SPLINEFLAG_PITCH_DOWN = 0x00000080,
698 SPLINEFLAG_DONE = 0x00000100,
699 SPLINEFLAG_FALLING = 0x00000200,
700 SPLINEFLAG_NO_SPLINE = 0x00000400,
701 SPLINEFLAG_TRAJECTORY = 0x00000800,
702 SPLINEFLAG_WALKMODE = 0x00001000,
703 SPLINEFLAG_FLYING = 0x00002000,
704 SPLINEFLAG_KNOCKBACK = 0x00004000,
705 SPLINEFLAG_FINALPOINT = 0x00008000,
706 SPLINEFLAG_FINALTARGET = 0x00010000,
707 SPLINEFLAG_FINALFACING = 0x00020000,
708 SPLINEFLAG_CATMULLROM = 0x00040000,
709 SPLINEFLAG_UNKNOWN1 = 0x00080000,
710 SPLINEFLAG_UNKNOWN2 = 0x00100000,
711 SPLINEFLAG_UNKNOWN3 = 0x00200000,
712 SPLINEFLAG_UNKNOWN4 = 0x00400000,
713 SPLINEFLAG_UNKNOWN5 = 0x00800000,
714 SPLINEFLAG_UNKNOWN6 = 0x01000000,
715 SPLINEFLAG_UNKNOWN7 = 0x02000000,
716 SPLINEFLAG_UNKNOWN8 = 0x04000000,
717 SPLINEFLAG_UNKNOWN9 = 0x08000000,
718 SPLINEFLAG_UNKNOWN10 = 0x10000000,
719 SPLINEFLAG_UNKNOWN11 = 0x20000000,
720 SPLINEFLAG_UNKNOWN12 = 0x40000000
723 enum SplineMode
725 SPLINEMODE_LINEAR = 0,
726 SPLINEMODE_CATMULLROM = 1,
727 SPLINEMODE_BEZIER3 = 2
730 enum SplineType
732 SPLINETYPE_NORMAL = 0,
733 SPLINETYPE_STOP = 1,
734 SPLINETYPE_FACINGSPOT = 2,
735 SPLINETYPE_FACINGTARGET = 3,
736 SPLINETYPE_FACINGANGLE = 4
739 struct Position
741 Position() : x(0.0f), y(0.0f), z(0.0f), o(0.0f) {}
742 float x, y, z, o;
745 class MovementInfo
747 public:
748 MovementInfo() : moveFlags(MOVEFLAG_NONE), moveFlags2(MOVEFLAG2_NONE), time(0), t_guid(0),
749 t_time(0), t_seat(-1), t_time2(0), s_pitch(0.0f), fallTime(0), j_velocity(0.0f), j_sinAngle(0.0f),
750 j_cosAngle(0.0f), j_xyspeed(0.0f), u_unk1(0.0f) {}
752 MovementInfo(WorldPacket &data);
754 // Read/Write methods
755 void Read(ByteBuffer &data);
756 void Write(ByteBuffer &data);
758 // Movement flags manipulations
759 void AddMovementFlag(MovementFlags f) { moveFlags |= f; }
760 void RemoveMovementFlag(MovementFlags f) { moveFlags &= ~f; }
761 bool HasMovementFlag(MovementFlags f) const { return moveFlags & f; }
762 MovementFlags GetMovementFlags() const { return MovementFlags(moveFlags); }
763 void SetMovementFlags(MovementFlags f) { moveFlags = f; }
764 MovementFlags2 GetMovementFlags2() const { return MovementFlags2(moveFlags2); }
766 // Position manipulations
767 Position const *GetPos() const { return &pos; }
768 void SetTransportData(uint64 guid, float x, float y, float z, float o, uint32 time, int8 seat)
770 t_guid = guid;
771 t_pos.x = x;
772 t_pos.y = y;
773 t_pos.z = z;
774 t_pos.o = z;
775 t_time = time;
776 t_seat = seat;
778 uint64 GetTransportGuid() const { return t_guid; }
779 Position const *GetTransportPos() const { return &t_pos; }
780 int8 GetTransportSeat() const { return t_seat; }
781 uint32 GetTransportTime() const { return t_time; }
782 uint32 GetFallTime() const { return fallTime; }
783 void ChangePosition(float x, float y, float z, float o) { pos.x = x; pos.y = y; pos.z = z; pos.o = o; }
784 void UpdateTime(uint32 _time) { time = _time; }
786 private:
787 // common
788 uint32 moveFlags; // see enum MovementFlags
789 uint16 moveFlags2; // see enum MovementFlags2
790 uint32 time;
791 Position pos;
792 // transport
793 uint64 t_guid;
794 Position t_pos;
795 uint32 t_time;
796 int8 t_seat;
797 uint32 t_time2;
798 // swimming and flying
799 float s_pitch;
800 // last fall time
801 uint32 fallTime;
802 // jumping
803 float j_velocity, j_sinAngle, j_cosAngle, j_xyspeed;
804 // spline
805 float u_unk1;
808 enum DiminishingLevels
810 DIMINISHING_LEVEL_1 = 0,
811 DIMINISHING_LEVEL_2 = 1,
812 DIMINISHING_LEVEL_3 = 2,
813 DIMINISHING_LEVEL_IMMUNE = 3
816 struct DiminishingReturn
818 DiminishingReturn(DiminishingGroup group, uint32 t, uint32 count)
819 : DRGroup(group), stack(0), hitTime(t), hitCount(count)
822 DiminishingGroup DRGroup:16;
823 uint16 stack:16;
824 uint32 hitTime;
825 uint32 hitCount;
828 enum MeleeHitOutcome
830 MELEE_HIT_EVADE, MELEE_HIT_MISS, MELEE_HIT_DODGE, MELEE_HIT_BLOCK, MELEE_HIT_PARRY,
831 MELEE_HIT_GLANCING, MELEE_HIT_CRIT, MELEE_HIT_CRUSHING, MELEE_HIT_NORMAL
834 struct CleanDamage
836 CleanDamage(uint32 _damage, WeaponAttackType _attackType, MeleeHitOutcome _hitOutCome) :
837 damage(_damage), attackType(_attackType), hitOutCome(_hitOutCome) {}
839 uint32 damage;
840 WeaponAttackType attackType;
841 MeleeHitOutcome hitOutCome;
844 // Struct for use in Unit::CalculateMeleeDamage
845 // Need create structure like in SMSG_ATTACKERSTATEUPDATE opcode
846 struct CalcDamageInfo
848 Unit *attacker; // Attacker
849 Unit *target; // Target for damage
850 SpellSchoolMask damageSchoolMask;
851 uint32 damage;
852 uint32 absorb;
853 uint32 resist;
854 uint32 blocked_amount;
855 uint32 HitInfo;
856 uint32 TargetState;
857 // Helper
858 WeaponAttackType attackType; //
859 uint32 procAttacker;
860 uint32 procVictim;
861 uint32 procEx;
862 uint32 cleanDamage; // Used only for rage calculation
863 MeleeHitOutcome hitOutCome; // TODO: remove this field (need use TargetState)
866 // Spell damage info structure based on structure sending in SMSG_SPELLNONMELEEDAMAGELOG opcode
867 struct SpellNonMeleeDamage{
868 SpellNonMeleeDamage(Unit *_attacker, Unit *_target, uint32 _SpellID, uint32 _schoolMask)
869 : target(_target), attacker(_attacker), SpellID(_SpellID), damage(0), overkill(0), schoolMask(_schoolMask),
870 absorb(0), resist(0), physicalLog(false), unused(false), blocked(0), HitInfo(0), cleanDamage(0)
873 Unit *target;
874 Unit *attacker;
875 uint32 SpellID;
876 uint32 damage;
877 uint32 overkill;
878 uint32 schoolMask;
879 uint32 absorb;
880 uint32 resist;
881 bool physicalLog;
882 bool unused;
883 uint32 blocked;
884 uint32 HitInfo;
885 // Used for help
886 uint32 cleanDamage;
889 struct SpellPeriodicAuraLogInfo
891 SpellPeriodicAuraLogInfo(Aura *_aura, uint32 _damage, uint32 _overDamage, uint32 _absorb, uint32 _resist, float _multiplier, bool _critical = false)
892 : aura(_aura), damage(_damage), overDamage(_overDamage), absorb(_absorb), resist(_resist), multiplier(_multiplier), critical(_critical) {}
894 Aura *aura;
895 uint32 damage;
896 uint32 overDamage; // overkill/overheal
897 uint32 absorb;
898 uint32 resist;
899 float multiplier;
900 bool critical;
903 uint32 createProcExtendMask(SpellNonMeleeDamage *damageInfo, SpellMissInfo missCondition);
905 #define MAX_DECLINED_NAME_CASES 5
907 struct DeclinedName
909 std::string name[MAX_DECLINED_NAME_CASES];
912 enum CurrentSpellTypes
914 CURRENT_MELEE_SPELL = 0,
915 CURRENT_GENERIC_SPELL = 1,
916 CURRENT_AUTOREPEAT_SPELL = 2,
917 CURRENT_CHANNELED_SPELL = 3
920 #define CURRENT_FIRST_NON_MELEE_SPELL 1
921 #define CURRENT_MAX_SPELL 4
924 enum ActiveStates
926 ACT_PASSIVE = 0x01, // 0x01 - passive
927 ACT_DISABLED = 0x81, // 0x80 - castable
928 ACT_ENABLED = 0xC1, // 0x40 | 0x80 - auto cast + castable
929 ACT_COMMAND = 0x07, // 0x01 | 0x02 | 0x04
930 ACT_REACTION = 0x06, // 0x02 | 0x04
931 ACT_DECIDE = 0x00 // custom
934 enum ReactStates
936 REACT_PASSIVE = 0,
937 REACT_DEFENSIVE = 1,
938 REACT_AGGRESSIVE = 2
941 enum CommandStates
943 COMMAND_STAY = 0,
944 COMMAND_FOLLOW = 1,
945 COMMAND_ATTACK = 2,
946 COMMAND_ABANDON = 3
949 #define UNIT_ACTION_BUTTON_ACTION(X) (uint32(X) & 0x00FFFFFF)
950 #define UNIT_ACTION_BUTTON_TYPE(X) ((uint32(X) & 0xFF000000) >> 24)
951 #define MAX_UNIT_ACTION_BUTTON_ACTION_VALUE (0x00FFFFFF+1)
952 #define MAKE_UNIT_ACTION_BUTTON(A,T) (uint32(A) | (uint32(T) << 24))
954 struct UnitActionBarEntry
956 UnitActionBarEntry() : packedData(uint32(ACT_DISABLED) << 24) {}
958 uint32 packedData;
960 // helper
961 ActiveStates GetType() const { return ActiveStates(UNIT_ACTION_BUTTON_TYPE(packedData)); }
962 uint32 GetAction() const { return UNIT_ACTION_BUTTON_ACTION(packedData); }
963 bool IsActionBarForSpell() const
965 ActiveStates Type = GetType();
966 return Type == ACT_DISABLED || Type == ACT_ENABLED || Type == ACT_PASSIVE;
969 void SetActionAndType(uint32 action, ActiveStates type)
971 packedData = MAKE_UNIT_ACTION_BUTTON(action,type);
974 void SetType(ActiveStates type)
976 packedData = MAKE_UNIT_ACTION_BUTTON(UNIT_ACTION_BUTTON_ACTION(packedData),type);
979 void SetAction(uint32 action)
981 packedData = (packedData & 0xFF000000) | UNIT_ACTION_BUTTON_ACTION(action);
985 typedef UnitActionBarEntry CharmSpellEntry;
987 enum ActionBarIndex
989 ACTION_BAR_INDEX_START = 0,
990 ACTION_BAR_INDEX_PET_SPELL_START = 3,
991 ACTION_BAR_INDEX_PET_SPELL_END = 7,
992 ACTION_BAR_INDEX_END = 10,
995 #define MAX_UNIT_ACTION_BAR_INDEX (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START)
997 struct CharmInfo
999 public:
1000 explicit CharmInfo(Unit* unit);
1001 uint32 GetPetNumber() const { return m_petnumber; }
1002 void SetPetNumber(uint32 petnumber, bool statwindow);
1004 void SetCommandState(CommandStates st) { m_CommandState = st; }
1005 CommandStates GetCommandState() { return m_CommandState; }
1006 bool HasCommandState(CommandStates state) { return (m_CommandState == state); }
1007 void SetReactState(ReactStates st) { m_reactState = st; }
1008 ReactStates GetReactState() { return m_reactState; }
1009 bool HasReactState(ReactStates state) { return (m_reactState == state); }
1011 void InitPossessCreateSpells();
1012 void InitCharmCreateSpells();
1013 void InitPetActionBar();
1014 void InitEmptyActionBar();
1016 //return true if successful
1017 bool AddSpellToActionBar(uint32 spellid, ActiveStates newstate = ACT_DECIDE);
1018 bool RemoveSpellFromActionBar(uint32 spell_id);
1019 void LoadPetActionBar(const std::string& data);
1020 void BuildActionBar(WorldPacket* data);
1021 void SetSpellAutocast(uint32 spell_id, bool state);
1022 void SetActionBar(uint8 index, uint32 spellOrAction,ActiveStates type)
1024 PetActionBar[index].SetActionAndType(spellOrAction,type);
1026 UnitActionBarEntry const* GetActionBarEntry(uint8 index) const { return &(PetActionBar[index]); }
1028 void ToggleCreatureAutocast(uint32 spellid, bool apply);
1030 CharmSpellEntry* GetCharmSpell(uint8 index) { return &(m_charmspells[index]); }
1031 private:
1033 Unit* m_unit;
1034 UnitActionBarEntry PetActionBar[MAX_UNIT_ACTION_BAR_INDEX];
1035 CharmSpellEntry m_charmspells[CREATURE_MAX_SPELLS];
1036 CommandStates m_CommandState;
1037 ReactStates m_reactState;
1038 uint32 m_petnumber;
1041 // for clearing special attacks
1042 #define REACTIVE_TIMER_START 4000
1044 enum ReactiveType
1046 REACTIVE_DEFENSE = 0,
1047 REACTIVE_HUNTER_PARRY = 1,
1048 REACTIVE_OVERPOWER = 2
1051 #define MAX_REACTIVE 3
1052 #define MAX_TOTEM 4
1054 typedef std::set<uint64> GuardianPetList;
1056 // delay time next attack to prevent client attack animation problems
1057 #define ATTACK_DISPLAY_DELAY 200
1058 #define MAX_PLAYER_STEALTH_DETECT_RANGE 45.0f // max distance for detection targets by player
1060 // Regeneration defines
1061 #define REGEN_TIME_FULL 2000 // For this time difference is computed regen value
1062 #define REGEN_TIME_PRECISE 500 // Used in Spell::CheckPower for precise regeneration in spell cast time
1064 struct SpellProcEventEntry; // used only privately
1066 class MANGOS_DLL_SPEC Unit : public WorldObject
1068 public:
1069 typedef std::set<Unit*> AttackerSet;
1070 typedef std::pair<uint32, uint8> spellEffectPair;
1071 typedef std::multimap< spellEffectPair, Aura*> AuraMap;
1072 typedef std::list<Aura *> AuraList;
1073 typedef std::list<DiminishingReturn> Diminishing;
1074 typedef std::set<uint32> ComboPointHolderSet;
1075 typedef std::map<uint8, uint32> VisibleAuraMap;
1077 virtual ~Unit ( );
1079 void AddToWorld();
1080 void RemoveFromWorld();
1082 void CleanupsBeforeDelete(); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units)
1084 DiminishingLevels GetDiminishing(DiminishingGroup group);
1085 void IncrDiminishing(DiminishingGroup group);
1086 void ApplyDiminishingToDuration(DiminishingGroup group, int32 &duration,Unit* caster, DiminishingLevels Level, int32 limitduration);
1087 void ApplyDiminishingAura(DiminishingGroup group, bool apply);
1088 void ClearDiminishings() { m_Diminishing.clear(); }
1090 virtual void Update( uint32 time );
1092 void setAttackTimer(WeaponAttackType type, uint32 time) { m_attackTimer[type] = time; }
1093 void resetAttackTimer(WeaponAttackType type = BASE_ATTACK);
1094 uint32 getAttackTimer(WeaponAttackType type) const { return m_attackTimer[type]; }
1095 bool isAttackReady(WeaponAttackType type = BASE_ATTACK) const { return m_attackTimer[type] == 0; }
1096 bool haveOffhandWeapon() const;
1097 bool canReachWithAttack(Unit *pVictim) const;
1098 uint32 m_extraAttacks;
1100 void _addAttacker(Unit *pAttacker) // must be called only from Unit::Attack(Unit*)
1102 AttackerSet::const_iterator itr = m_attackers.find(pAttacker);
1103 if(itr == m_attackers.end())
1104 m_attackers.insert(pAttacker);
1106 void _removeAttacker(Unit *pAttacker) // must be called only from Unit::AttackStop()
1108 m_attackers.erase(pAttacker);
1110 Unit * getAttackerForHelper() // If someone wants to help, who to give them
1112 if (getVictim() != NULL)
1113 return getVictim();
1115 if (!m_attackers.empty())
1116 return *(m_attackers.begin());
1118 return NULL;
1120 bool Attack(Unit *victim, bool meleeAttack);
1121 void CastStop(uint32 except_spellid = 0);
1122 bool AttackStop(bool targetSwitch = false);
1123 void RemoveAllAttackers();
1124 AttackerSet const& getAttackers() const { return m_attackers; }
1125 bool isAttackingPlayer() const;
1126 Unit* getVictim() const { return m_attacking; }
1127 void CombatStop(bool includingCast = false);
1128 void CombatStopWithPets(bool includingCast = false);
1129 void StopAttackFaction(uint32 faction_id);
1130 Unit* SelectNearbyTarget(Unit* except = NULL) const;
1131 bool hasNegativeAuraWithInterruptFlag(uint32 flag);
1132 void SendMeleeAttackStop(Unit* victim);
1133 void SendMeleeAttackStart(Unit* pVictim);
1135 void addUnitState(uint32 f) { m_state |= f; }
1136 bool hasUnitState(uint32 f) const { return (m_state & f); }
1137 void clearUnitState(uint32 f) { m_state &= ~f; }
1138 bool CanFreeMove() const
1140 return !hasUnitState(UNIT_STAT_NO_FREE_MOVE) && GetOwnerGUID()==0;
1143 uint32 getLevel() const { return GetUInt32Value(UNIT_FIELD_LEVEL); }
1144 virtual uint32 getLevelForTarget(Unit const* /*target*/) const { return getLevel(); }
1145 void SetLevel(uint32 lvl);
1146 uint8 getRace() const { return GetByteValue(UNIT_FIELD_BYTES_0, 0); }
1147 uint32 getRaceMask() const { return 1 << (getRace()-1); }
1148 uint8 getClass() const { return GetByteValue(UNIT_FIELD_BYTES_0, 1); }
1149 uint32 getClassMask() const { return 1 << (getClass()-1); }
1150 uint8 getGender() const { return GetByteValue(UNIT_FIELD_BYTES_0, 2); }
1152 float GetStat(Stats stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0+stat)); }
1153 void SetStat(Stats stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0+stat, val); }
1154 uint32 GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL) ; }
1155 void SetArmor(int32 val) { SetResistance(SPELL_SCHOOL_NORMAL, val); }
1157 uint32 GetResistance(SpellSchools school) const { return GetUInt32Value(UNIT_FIELD_RESISTANCES+school); }
1158 void SetResistance(SpellSchools school, int32 val) { SetStatInt32Value(UNIT_FIELD_RESISTANCES+school,val); }
1160 uint32 GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH); }
1161 uint32 GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH); }
1162 void SetHealth( uint32 val);
1163 void SetMaxHealth(uint32 val);
1164 int32 ModifyHealth(int32 val);
1166 Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, 3)); }
1167 void setPowerType(Powers power);
1168 uint32 GetPower( Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1 +power); }
1169 uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1+power); }
1170 void SetPower( Powers power, uint32 val);
1171 void SetMaxPower(Powers power, uint32 val);
1172 int32 ModifyPower(Powers power, int32 val);
1173 void ApplyPowerMod(Powers power, uint32 val, bool apply);
1174 void ApplyMaxPowerMod(Powers power, uint32 val, bool apply);
1176 uint32 GetAttackTime(WeaponAttackType att) const { return (uint32)(GetFloatValue(UNIT_FIELD_BASEATTACKTIME+att)/m_modAttackSpeedPct[att]); }
1177 void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val*m_modAttackSpeedPct[att]); }
1178 void ApplyAttackTimePercentMod(WeaponAttackType att,float val, bool apply);
1179 void ApplyCastTimePercentMod(float val, bool apply);
1181 SheathState GetSheath() const { return SheathState(GetByteValue(UNIT_FIELD_BYTES_2, 0)); }
1182 virtual void SetSheath( SheathState sheathed ) { SetByteValue(UNIT_FIELD_BYTES_2, 0, sheathed); }
1184 // faction template id
1185 uint32 getFaction() const { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE); }
1186 void setFaction(uint32 faction) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, faction ); }
1187 FactionTemplateEntry const* getFactionTemplateEntry() const;
1188 bool IsHostileTo(Unit const* unit) const;
1189 bool IsHostileToPlayers() const;
1190 bool IsFriendlyTo(Unit const* unit) const;
1191 bool IsNeutralToAll() const;
1192 bool IsContestedGuard() const
1194 if(FactionTemplateEntry const* entry = getFactionTemplateEntry())
1195 return entry->IsContestedGuardFaction();
1197 return false;
1199 bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP); }
1200 void SetPvP(bool state);
1201 bool IsFFAPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); }
1202 void SetFFAPvP(bool state);
1203 uint32 GetCreatureType() const;
1204 uint32 GetCreatureTypeMask() const
1206 uint32 creatureType = GetCreatureType();
1207 return (creatureType >= 1) ? (1 << (creatureType - 1)) : 0;
1210 uint8 getStandState() const { return GetByteValue(UNIT_FIELD_BYTES_1, 0); }
1211 bool IsSitState() const;
1212 bool IsStandState() const;
1213 void SetStandState(uint8 state);
1215 void SetStandFlags(uint8 flags) { SetByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1216 void RemoveStandFlags(uint8 flags) { RemoveByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1218 bool IsMounted() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); }
1219 uint32 GetMountID() const { return GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID); }
1220 void Mount(uint32 mount, uint32 spellId = 0);
1221 void Unmount();
1223 uint16 GetMaxSkillValueForLevel(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1224 void DealDamageMods(Unit *pVictim, uint32 &damage, uint32* absorb);
1225 uint32 DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss);
1226 int32 DealHeal(Unit *pVictim, uint32 addhealth, SpellEntry const *spellProto, bool critical = false);
1228 void ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 procEx, uint32 amount, WeaponAttackType attType = BASE_ATTACK, SpellEntry const *procSpell = NULL);
1229 void ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage );
1231 void HandleEmoteCommand(uint32 anim_id);
1232 void AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType = BASE_ATTACK, bool extra = false );
1234 float MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const;
1236 void CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *damageInfo, WeaponAttackType attackType = BASE_ATTACK);
1237 void DealMeleeDamage(CalcDamageInfo *damageInfo, bool durabilityLoss);
1239 void CalculateSpellDamage(SpellNonMeleeDamage *damageInfo, int32 damage, SpellEntry const *spellInfo, WeaponAttackType attackType = BASE_ATTACK);
1240 void DealSpellDamage(SpellNonMeleeDamage *damageInfo, bool durabilityLoss);
1242 // player or player's pet resilience (-1%)
1243 float GetMeleeCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_MELEE); }
1244 float GetRangedCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_RANGED); }
1245 float GetSpellCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_SPELL); }
1247 // player or player's pet resilience (-1%)
1248 uint32 GetMeleeCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 2.2f, 33.0f, damage); }
1249 uint32 GetRangedCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_RANGED, 2.2f, 33.0f, damage); }
1250 uint32 GetSpellCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_SPELL, 2.2f, 33.0f, damage); }
1252 // player or player's pet resilience (-1%), cap 100%
1253 uint32 GetMeleeDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1254 uint32 GetRangedDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1255 uint32 GetSpellDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1257 float MeleeSpellMissChance(Unit *pVictim, WeaponAttackType attType, int32 skillDiff, SpellEntry const *spell);
1258 SpellMissInfo MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1259 SpellMissInfo MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1260 SpellMissInfo SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool canReflect = false);
1262 float GetUnitDodgeChance() const;
1263 float GetUnitParryChance() const;
1264 float GetUnitBlockChance() const;
1265 float GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const;
1267 virtual uint32 GetShieldBlockValue() const =0;
1268 uint32 GetUnitMeleeSkill(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1269 uint32 GetDefenseSkillValue(Unit const* target = NULL) const;
1270 uint32 GetWeaponSkillValue(WeaponAttackType attType, Unit const* target = NULL) const;
1271 float GetWeaponProcChance() const;
1272 float GetPPMProcChance(uint32 WeaponSpeed, float PPM) const;
1274 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType) const;
1275 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance) const;
1277 bool isVendor() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR ); }
1278 bool isTrainer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER ); }
1279 bool isQuestGiver() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER ); }
1280 bool isGossip() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP ); }
1281 bool isTaxi() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_FLIGHTMASTER ); }
1282 bool isGuildMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PETITIONER ); }
1283 bool isBattleMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BATTLEMASTER ); }
1284 bool isBanker() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BANKER ); }
1285 bool isInnkeeper() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_INNKEEPER ); }
1286 bool isSpiritHealer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER ); }
1287 bool isSpiritGuide() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITGUIDE ); }
1288 bool isTabardDesigner()const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TABARDDESIGNER ); }
1289 bool isAuctioner() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER ); }
1290 bool isArmorer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_REPAIR ); }
1291 bool isServiceProvider() const
1293 return HasFlag( UNIT_NPC_FLAGS,
1294 UNIT_NPC_FLAG_VENDOR | UNIT_NPC_FLAG_TRAINER | UNIT_NPC_FLAG_FLIGHTMASTER |
1295 UNIT_NPC_FLAG_PETITIONER | UNIT_NPC_FLAG_BATTLEMASTER | UNIT_NPC_FLAG_BANKER |
1296 UNIT_NPC_FLAG_INNKEEPER | UNIT_NPC_FLAG_GUARD | UNIT_NPC_FLAG_SPIRITHEALER |
1297 UNIT_NPC_FLAG_SPIRITGUIDE | UNIT_NPC_FLAG_TABARDDESIGNER | UNIT_NPC_FLAG_AUCTIONEER );
1299 bool isSpiritService() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER | UNIT_NPC_FLAG_SPIRITGUIDE ); }
1301 //Need fix or use this
1302 bool isGuard() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GUARD); }
1304 bool isInFlight() const { return hasUnitState(UNIT_STAT_IN_FLIGHT); }
1306 bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); }
1307 void SetInCombatState(bool PvP, Unit* enemy = NULL);
1308 void SetInCombatWith(Unit* enemy);
1309 void ClearInCombat();
1310 uint32 GetCombatTimer() const { return m_CombatTimer; }
1312 bool HasAuraType(AuraType auraType) const;
1313 bool HasAura(uint32 spellId, uint32 effIndex) const
1315 return m_Auras.find(spellEffectPair(spellId, effIndex)) != m_Auras.end();
1317 bool HasAura(uint32 spellId) const;
1319 bool virtual HasSpell(uint32 /*spellID*/) const { return false; }
1321 bool HasStealthAura() const { return HasAuraType(SPELL_AURA_MOD_STEALTH); }
1322 bool HasInvisibilityAura() const { return HasAuraType(SPELL_AURA_MOD_INVISIBILITY); }
1323 bool isFeared() const { return HasAuraType(SPELL_AURA_MOD_FEAR); }
1324 bool isInRoots() const { return HasAuraType(SPELL_AURA_MOD_ROOT); }
1325 bool IsPolymorphed() const;
1327 bool isFrozen() const;
1329 void RemoveSpellbyDamageTaken(AuraType auraType, uint32 damage);
1331 bool isTargetableForAttack(bool inversAlive = false) const;
1332 virtual bool IsInWater() const;
1333 virtual bool IsUnderWater() const;
1334 bool isInAccessablePlaceFor(Creature const* c) const;
1336 void SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, uint32 OverHeal, bool critical = false);
1337 void SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage,Powers powertype);
1338 void EnergizeBySpell(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype);
1339 uint32 SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage);
1340 void CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1341 void CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1342 void CastCustomSpell(Unit* Victim, uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1343 void CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1344 void CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1345 void CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1347 bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const;
1349 void DeMorph();
1351 void SendAttackStateUpdate(CalcDamageInfo *damageInfo);
1352 void SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount);
1353 void SendSpellNonMeleeDamageLog(SpellNonMeleeDamage *log);
1354 void SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID, uint32 Damage, SpellSchoolMask damageSchoolMask, uint32 AbsorbedDamage, uint32 Resist, bool PhysicalDamage, uint32 Blocked, bool CriticalHit = false);
1355 void SendPeriodicAuraLog(SpellPeriodicAuraLogInfo *pInfo);
1356 void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo);
1358 void NearTeleportTo(float x, float y, float z, float orientation, bool casting = false);
1360 void SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, SplineFlags flags, uint32 Time, Player* player = NULL);
1361 void SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, SplineFlags flags);
1363 void SendHighestThreatUpdate(HostileReference* pHostileReference);
1364 void SendThreatClear();
1365 void SendThreatRemove(HostileReference* pHostileReference);
1366 void SendThreatUpdate();
1368 void BuildHeartBeatMsg( WorldPacket *data ) const;
1370 virtual void MoveOutOfRange(Player &) { };
1372 bool isAlive() const { return (m_deathState == ALIVE); };
1373 bool isDead() const { return ( m_deathState == DEAD || m_deathState == CORPSE ); };
1374 DeathState getDeathState() { return m_deathState; };
1375 virtual void setDeathState(DeathState s); // overwritten in Creature/Player/Pet
1377 uint64 GetOwnerGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMONEDBY); }
1378 void SetOwnerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner); }
1379 uint64 GetCreatorGUID() const { return GetUInt64Value(UNIT_FIELD_CREATEDBY); }
1380 void SetCreatorGUID(uint64 creator) { SetUInt64Value(UNIT_FIELD_CREATEDBY, creator); }
1381 uint64 GetPetGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMON); }
1382 void SetPetGUID(uint64 pet) { SetUInt64Value(UNIT_FIELD_SUMMON, pet); }
1383 uint64 GetCharmerGUID() const { return GetUInt64Value(UNIT_FIELD_CHARMEDBY); }
1384 void SetCharmerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_CHARMEDBY, owner); }
1385 uint64 GetCharmGUID() const { return GetUInt64Value(UNIT_FIELD_CHARM); }
1386 void SetCharmGUID(uint64 charm) { SetUInt64Value(UNIT_FIELD_CHARM, charm); }
1387 uint64 GetTargetGUID() const { return GetUInt64Value(UNIT_FIELD_TARGET); }
1388 void SetTargetGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_TARGET, targetGuid); }
1389 uint64 GetChannelObjectGUID() const { return GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT); }
1390 void SetChannelObjectGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, targetGuid); }
1392 uint64 GetCharmerOrOwnerGUID() const { return GetCharmerGUID() ? GetCharmerGUID() : GetOwnerGUID(); }
1393 uint64 GetCharmerOrOwnerOrOwnGUID() const
1395 if(uint64 guid = GetCharmerOrOwnerGUID())
1396 return guid;
1397 return GetGUID();
1399 bool isCharmedOwnedByPlayerOrPlayer() const { return IS_PLAYER_GUID(GetCharmerOrOwnerOrOwnGUID()); }
1401 Player* GetSpellModOwner();
1403 Unit* GetOwner() const;
1404 Pet* GetPet() const;
1405 Unit* GetCharmer() const;
1406 Unit* GetCharm() const;
1407 void Uncharm();
1408 Unit* GetCharmerOrOwner() const { return GetCharmerGUID() ? GetCharmer() : GetOwner(); }
1409 Unit* GetCharmerOrOwnerOrSelf()
1411 if(Unit* u = GetCharmerOrOwner())
1412 return u;
1414 return this;
1416 bool IsCharmerOrOwnerPlayerOrPlayerItself() const;
1417 Player* GetCharmerOrOwnerPlayerOrPlayerItself();
1418 float GetCombatDistance( const Unit* target ) const;
1420 void SetPet(Pet* pet);
1421 void SetCharm(Unit* pet);
1423 void AddGuardian(Pet* pet);
1424 void RemoveGuardian(Pet* pet);
1425 void RemoveGuardians();
1426 Pet* FindGuardianWithEntry(uint32 entry);
1428 bool isCharmed() const { return GetCharmerGUID() != 0; }
1430 CharmInfo* GetCharmInfo() { return m_charmInfo; }
1431 CharmInfo* InitCharmInfo(Unit* charm);
1433 Pet* CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id = 0);
1435 Totem* GetTotem(uint8 slot) const;
1437 template<typename Func>
1438 void CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms);
1439 template<typename Func>
1440 bool CheckAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms) const;
1442 bool AddAura(Aura *aur);
1444 // removing specific aura stack
1445 void RemoveAura(Aura* aura, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1446 void RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1447 void RemoveAura(uint32 spellId, uint32 effindex, Aura* except = NULL);
1449 // removing specific aura stacks by diff reasons and selections
1450 void RemoveAurasDueToSpell(uint32 spellId, Aura* except = NULL);
1451 void RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId);
1452 void RemoveAurasByCasterSpell(uint32 spellId, uint64 casterGUID);
1453 void RemoveAurasByCasterSpell(uint32 spellId, uint32 effindex, uint64 casterGUID);
1454 void RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer);
1455 void RemoveAurasDueToSpellByCancel(uint32 spellId);
1457 // removing unknown aura stacks by diff reasons and selections
1458 void RemoveNotOwnSingleTargetAuras(uint32 newPhase = 0x0);
1459 void RemoveAurasAtMechanicImmunity(uint32 mechMask, uint32 exceptSpellId, bool non_positive = false);
1460 void RemoveSpellsCausingAura(AuraType auraType);
1461 void RemoveRankAurasDueToSpell(uint32 spellId);
1462 bool RemoveNoStackAurasDueToAura(Aura *Aur);
1463 void RemoveAurasWithInterruptFlags(uint32 flags);
1464 void RemoveAurasWithDispelType( DispelType type );
1465 void RemoveAllAuras(AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1466 void RemoveArenaAuras(bool onleave = false);
1467 void RemoveAllAurasOnDeath();
1469 // removing specific aura FROM stack
1470 void RemoveSingleAuraFromStack(uint32 spellId, uint32 effindex, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1471 void RemoveSingleAuraFromStack(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1473 // removing specific aura FROM stack by diff reasons and selections
1474 void RemoveSingleSpellAurasFromStack(uint32 spellId, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1475 void RemoveSingleSpellAurasByCasterSpell(uint32 spellId, uint64 casterGUID, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1476 void RemoveSingleAuraByCasterSpell(uint32 spellId, uint32 effindex, uint64 casterGUID, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1477 void RemoveSingleAuraDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler);
1479 void DelayAura(uint32 spellId, uint32 effindex, int32 delaytime);
1481 float GetResistanceBuffMods(SpellSchools school, bool positive) const { return GetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school ); }
1482 void SetResistanceBuffMods(SpellSchools school, bool positive, float val) { SetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school,val); }
1483 void ApplyResistanceBuffModsMod(SpellSchools school, bool positive, float val, bool apply) { ApplyModSignedFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1484 void ApplyResistanceBuffModsPercentMod(SpellSchools school, bool positive, float val, bool apply) { ApplyPercentModFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1485 void InitStatBuffMods()
1487 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_POSSTAT0+i, 0);
1488 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_NEGSTAT0+i, 0);
1490 void ApplyStatBuffMod(Stats stat, float val, bool apply) { ApplyModSignedFloatValue((val > 0 ? UNIT_FIELD_POSSTAT0+stat : UNIT_FIELD_NEGSTAT0+stat), val, apply); }
1491 void ApplyStatPercentBuffMod(Stats stat, float val, bool apply)
1493 ApplyPercentModFloatValue(UNIT_FIELD_POSSTAT0+stat, val, apply);
1494 ApplyPercentModFloatValue(UNIT_FIELD_NEGSTAT0+stat, val, apply);
1496 void SetCreateStat(Stats stat, float val) { m_createStats[stat] = val; }
1497 void SetCreateHealth(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_HEALTH, val); }
1498 uint32 GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH); }
1499 void SetCreateMana(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_MANA, val); }
1500 uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); }
1501 uint32 GetCreatePowers(Powers power) const;
1502 float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0+stat); }
1503 float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0+stat); }
1504 float GetCreateStat(Stats stat) const { return m_createStats[stat]; }
1506 void SetCurrentCastedSpell(Spell * pSpell);
1507 virtual void ProhibitSpellSchool(SpellSchoolMask /*idSchoolMask*/, uint32 /*unTimeMs*/ ) { }
1508 void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed = true);
1509 void FinishSpell(CurrentSpellTypes spellType, bool ok = true);
1511 // set withDelayed to true to account delayed spells as casted
1512 // delayed+channeled spells are always accounted as casted
1513 // we can skip channeled or delayed checks using flags
1514 bool IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled = false, bool skipAutorepeat = false) const;
1516 // set withDelayed to true to interrupt delayed spells too
1517 // delayed+channeled spells are always interrupted
1518 void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid = 0);
1520 Spell* GetCurrentSpell(CurrentSpellTypes spellType) const { return m_currentSpells[spellType]; }
1521 Spell* FindCurrentSpellBySpellId(uint32 spell_id) const;
1523 uint32 m_addDmgOnce;
1524 uint64 m_TotemSlot[MAX_TOTEM];
1525 uint64 m_ObjectSlot[4];
1526 uint32 m_detectInvisibilityMask;
1527 uint32 m_invisibilityMask;
1529 uint32 m_ShapeShiftFormSpellId;
1530 ShapeshiftForm m_form;
1531 bool IsInFeralForm() const { return m_form == FORM_CAT || m_form == FORM_BEAR || m_form == FORM_DIREBEAR; }
1533 float m_modMeleeHitChance;
1534 float m_modRangedHitChance;
1535 float m_modSpellHitChance;
1536 int32 m_baseSpellCritChance;
1538 float m_threatModifier[MAX_SPELL_SCHOOL];
1539 float m_modAttackSpeedPct[3];
1541 // Event handler
1542 EventProcessor m_Events;
1544 // stat system
1545 bool HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply);
1546 void SetModifierValue(UnitMods unitMod, UnitModifierType modifierType, float value) { m_auraModifiersGroup[unitMod][modifierType] = value; }
1547 float GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const;
1548 float GetTotalStatValue(Stats stat) const;
1549 float GetTotalAuraModValue(UnitMods unitMod) const;
1550 SpellSchools GetSpellSchoolByAuraGroup(UnitMods unitMod) const;
1551 Stats GetStatByAuraGroup(UnitMods unitMod) const;
1552 Powers GetPowerTypeByAuraGroup(UnitMods unitMod) const;
1553 bool CanModifyStats() const { return m_canModifyStats; }
1554 void SetCanModifyStats(bool modifyStats) { m_canModifyStats = modifyStats; }
1555 virtual bool UpdateStats(Stats stat) = 0;
1556 virtual bool UpdateAllStats() = 0;
1557 virtual void UpdateResistances(uint32 school) = 0;
1558 virtual void UpdateArmor() = 0;
1559 virtual void UpdateMaxHealth() = 0;
1560 virtual void UpdateMaxPower(Powers power) = 0;
1561 virtual void UpdateAttackPowerAndDamage(bool ranged = false) = 0;
1562 virtual void UpdateDamagePhysical(WeaponAttackType attType) = 0;
1563 float GetTotalAttackPowerValue(WeaponAttackType attType) const;
1564 float GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const;
1565 void SetBaseWeaponDamage(WeaponAttackType attType ,WeaponDamageRange damageRange, float value) { m_weaponDamage[attType][damageRange] = value; }
1567 void SetInFront(Unit const* target);
1568 void SetFacingTo(float ori);
1569 void SetFacingToObject(WorldObject* pObject) { SetFacingTo(GetAngle(pObject)); }
1571 // Visibility system
1572 UnitVisibility GetVisibility() const { return m_Visibility; }
1573 void SetVisibility(UnitVisibility x);
1575 // common function for visibility checks for player/creatures with detection code
1576 bool isVisibleForOrDetect(Unit const* u, WorldObject const* viewPoint, bool detect, bool inVisibleList = false, bool is3dDistance = true) const;
1577 bool canDetectInvisibilityOf(Unit const* u) const;
1578 void SetPhaseMask(uint32 newPhaseMask, bool update);// overwrite WorldObject::SetPhaseMask
1580 // virtual functions for all world objects types
1581 bool isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const;
1582 // function for low level grid visibility checks in player/creature cases
1583 virtual bool IsVisibleInGridForPlayer(Player* pl) const = 0;
1584 bool isInvisibleForAlive() const;
1586 AuraList & GetSingleCastAuras() { return m_scAuras; }
1587 AuraList const& GetSingleCastAuras() const { return m_scAuras; }
1588 SpellImmuneList m_spellImmune[MAX_SPELL_IMMUNITY];
1590 // Threat related methods
1591 bool CanHaveThreatList() const;
1592 void AddThreat(Unit* pVictim, float threat = 0.0f, bool crit = false, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NONE, SpellEntry const *threatSpell = NULL);
1593 float ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL);
1594 void DeleteThreatList();
1595 bool SelectHostileTarget();
1596 void TauntApply(Unit* pVictim);
1597 void TauntFadeOut(Unit *taunter);
1598 ThreatManager& getThreatManager() { return m_ThreatManager; }
1599 ThreatManager const& getThreatManager() const { return m_ThreatManager; }
1600 void addHatedBy(HostileReference* pHostileReference) { m_HostileRefManager.insertFirst(pHostileReference); };
1601 void removeHatedBy(HostileReference* /*pHostileReference*/ ) { /* nothing to do yet */ }
1602 HostileRefManager& getHostileRefManager() { return m_HostileRefManager; }
1604 uint32 GetVisibleAura(uint8 slot)
1606 VisibleAuraMap::const_iterator itr = m_visibleAuras.find(slot);
1607 if(itr != m_visibleAuras.end())
1608 return itr->second;
1609 return 0;
1611 void SetVisibleAura(uint8 slot, uint32 spellid)
1613 if(spellid == 0)
1614 m_visibleAuras.erase(slot);
1615 else
1616 m_visibleAuras[slot] = spellid;
1618 VisibleAuraMap const *GetVisibleAuras() { return &m_visibleAuras; }
1619 uint8 GetVisibleAurasCount() { return m_visibleAuras.size(); }
1621 Aura* GetAura(uint32 spellId, uint32 effindex);
1622 Aura* GetAura(AuraType type, uint32 family, uint64 familyFlag, uint32 familyFlag2 = 0, uint64 casterGUID = 0);
1624 AuraMap & GetAuras() { return m_Auras; }
1625 AuraMap const& GetAuras() const { return m_Auras; }
1626 AuraList const& GetAurasByType(AuraType type) const { return m_modAuras[type]; }
1627 void ApplyAuraProcTriggerDamage(Aura* aura, bool apply);
1629 int32 GetTotalAuraModifier(AuraType auratype) const;
1630 float GetTotalAuraMultiplier(AuraType auratype) const;
1631 int32 GetMaxPositiveAuraModifier(AuraType auratype) const;
1632 int32 GetMaxNegativeAuraModifier(AuraType auratype) const;
1634 int32 GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1635 float GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1636 int32 GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1637 int32 GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1639 int32 GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1640 float GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const;
1641 int32 GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1642 int32 GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1644 // misc have plain value but we check it fit to provided values mask (mask & (1 << (misc-1)))
1645 float GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype, uint32 mask) const;
1647 Aura* GetDummyAura(uint32 spell_id) const;
1649 uint32 m_AuraFlags;
1651 uint32 GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID); }
1652 void SetDisplayId(uint32 modelId);
1653 uint32 GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
1654 void SetNativeDisplayId(uint32 modelId) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, modelId); }
1655 void setTransForm(uint32 spellid) { m_transform = spellid;}
1656 uint32 getTransForm() const { return m_transform;}
1658 DynamicObject* GetDynObject(uint32 spellId, uint32 effIndex);
1659 DynamicObject* GetDynObject(uint32 spellId);
1660 void AddDynObject(DynamicObject* dynObj);
1661 void RemoveDynObject(uint32 spellid);
1662 void RemoveDynObjectWithGUID(uint64 guid) { m_dynObjGUIDs.remove(guid); }
1663 void RemoveAllDynObjects();
1665 GameObject* GetGameObject(uint32 spellId) const;
1666 void AddGameObject(GameObject* gameObj);
1667 void RemoveGameObject(GameObject* gameObj, bool del);
1668 void RemoveGameObject(uint32 spellid, bool del);
1669 void RemoveAllGameObjects();
1671 uint32 CalculateDamage(WeaponAttackType attType, bool normalized);
1672 float GetAPMultiplier(WeaponAttackType attType, bool normalized);
1673 void ModifyAuraState(AuraState flag, bool apply);
1674 bool HasAuraState(AuraState flag) const { return HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); }
1675 bool HasAuraStateForCaster(AuraState flag, uint64 caster) const;
1676 void UnsummonAllTotems();
1677 Unit* SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo = NULL);
1678 int32 SpellBaseDamageBonus(SpellSchoolMask schoolMask);
1679 int32 SpellBaseHealingBonus(SpellSchoolMask schoolMask);
1680 int32 SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1681 int32 SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1682 uint32 SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 damage, DamageEffectType damagetype, uint32 stack = 1);
1683 uint32 SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 healamount, DamageEffectType damagetype, uint32 stack = 1);
1684 bool isSpellBlocked(Unit *pVictim, SpellEntry const *spellProto, WeaponAttackType attackType = BASE_ATTACK);
1685 bool isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType = BASE_ATTACK);
1686 uint32 SpellCriticalDamageBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1687 uint32 SpellCriticalHealingBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1689 void SetLastManaUse()
1691 if (GetTypeId() == TYPEID_PLAYER && !IsUnderLastManaUseEffect())
1692 RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_REGENERATE_POWER);
1694 m_lastManaUseTimer = 5000;
1696 bool IsUnderLastManaUseEffect() const { return m_lastManaUseTimer; }
1698 uint32 GetRegenTimer() const { return m_regenTimer; }
1700 void SetContestedPvP(Player *attackedPlayer = NULL);
1702 uint32 MeleeDamageBonus(Unit *pVictim, uint32 damage, WeaponAttackType attType, SpellEntry const *spellProto = NULL, DamageEffectType damagetype = DIRECT_DAMAGE, uint32 stack =1);
1703 uint32 GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime );
1705 void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply);
1706 void ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply);
1707 virtual bool IsImmunedToSpell(SpellEntry const* spellInfo);
1708 // redefined in Creature
1709 bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask);
1710 virtual bool IsImmunedToSpellEffect(SpellEntry const* spellInfo, uint32 index) const;
1711 // redefined in Creature
1713 uint32 CalcArmorReducedDamage(Unit* pVictim, const uint32 damage);
1714 void CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist, bool canReflect = false);
1716 void UpdateWalkMode(Unit* source, bool self = true);
1717 void UpdateSpeed(UnitMoveType mtype, bool forced);
1718 float GetSpeed( UnitMoveType mtype ) const;
1719 float GetSpeedRate( UnitMoveType mtype ) const { return m_speed_rate[mtype]; }
1720 void SetSpeedRate(UnitMoveType mtype, float rate, bool forced = false);
1722 void SetHover(bool on);
1723 bool isHover() const { return HasAuraType(SPELL_AURA_HOVER); }
1725 void KnockBackFrom(Unit* target, float horizintalSpeed, float verticalSpeed);
1727 void _RemoveAllAuraMods();
1728 void _ApplyAllAuraMods();
1730 int32 CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_index, int32 basePoints, Unit const* target);
1732 uint32 CalcNotIgnoreAbsorbDamage( uint32 damage, SpellSchoolMask damageSchoolMask, SpellEntry const* spellInfo = NULL);
1733 uint32 CalcNotIgnoreDamageRedunction( uint32 damage, SpellSchoolMask damageSchoolMask);
1734 int32 CalculateSpellDuration(SpellEntry const* spellProto, uint8 effect_index, Unit const* target);
1735 float CalculateLevelPenalty(SpellEntry const* spellProto) const;
1737 void addFollower(FollowerReference* pRef) { m_FollowingRefManager.insertFirst(pRef); }
1738 void removeFollower(FollowerReference* /*pRef*/ ) { /* nothing to do yet */ }
1739 static Unit* GetUnit(WorldObject const& object, uint64 guid);
1741 MotionMaster* GetMotionMaster() { return &i_motionMaster; }
1743 bool IsStopped() const { return !(hasUnitState(UNIT_STAT_MOVING)); }
1744 void StopMoving();
1746 void SetFeared(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0, uint32 time = 0);
1747 void SetConfused(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);
1748 void SetFeignDeath(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);
1750 void AddComboPointHolder(uint32 lowguid) { m_ComboPointHolders.insert(lowguid); }
1751 void RemoveComboPointHolder(uint32 lowguid) { m_ComboPointHolders.erase(lowguid); }
1752 void ClearComboPointHolders();
1754 ///----------Pet responses methods-----------------
1755 void SendPetCastFail(uint32 spellid, SpellCastResult msg);
1756 void SendPetActionFeedback (uint8 msg);
1757 void SendPetTalk (uint32 pettalk);
1758 void SendPetAIReaction(uint64 guid);
1759 ///----------End of Pet responses methods----------
1761 void propagateSpeedChange() { GetMotionMaster()->propagateSpeedChange(); }
1763 // reactive attacks
1764 void ClearAllReactives();
1765 void StartReactiveTimer( ReactiveType reactive ) { m_reactiveTimer[reactive] = REACTIVE_TIMER_START;}
1766 void UpdateReactives(uint32 p_time);
1768 // group updates
1769 void UpdateAuraForGroup(uint8 slot);
1771 // pet auras
1772 typedef std::set<PetAura const*> PetAuraSet;
1773 PetAuraSet m_petAuras;
1774 void AddPetAura(PetAura const* petSpell);
1775 void RemovePetAura(PetAura const* petSpell);
1777 // Movement info
1778 MovementInfo m_movementInfo;
1780 protected:
1781 explicit Unit ();
1783 void _UpdateSpells(uint32 time);
1785 void _UpdateAutoRepeatSpell();
1786 bool m_AutoRepeatFirstCast;
1788 uint32 m_attackTimer[MAX_ATTACK];
1790 float m_createStats[MAX_STATS];
1792 AttackerSet m_attackers;
1793 Unit* m_attacking;
1795 DeathState m_deathState;
1797 AuraMap m_Auras;
1798 AuraMap::iterator m_AurasUpdateIterator; // != end() in Unit::m_Auras update and point to next element
1799 AuraList m_deletedAuras; // auras removed while in ApplyModifier and waiting deleted
1801 AuraList m_scAuras; // casted by unit single per-caster auras
1803 typedef std::list<uint64> DynObjectGUIDs;
1804 DynObjectGUIDs m_dynObjGUIDs;
1806 typedef std::list<GameObject*> GameObjectList;
1807 GameObjectList m_gameObj;
1808 bool m_isSorted;
1809 uint32 m_transform;
1811 AuraList m_modAuras[TOTAL_AURAS];
1812 float m_auraModifiersGroup[UNIT_MOD_END][MODIFIER_TYPE_END];
1813 float m_weaponDamage[MAX_ATTACK][2];
1814 bool m_canModifyStats;
1815 //std::list< spellEffectPair > AuraSpells[TOTAL_AURAS]; // TODO: use this if ok for mem
1816 VisibleAuraMap m_visibleAuras;
1818 float m_speed_rate[MAX_MOVE_TYPE];
1820 CharmInfo *m_charmInfo;
1822 virtual SpellSchoolMask GetMeleeDamageSchoolMask() const;
1824 MotionMaster i_motionMaster;
1826 uint32 m_reactiveTimer[MAX_REACTIVE];
1827 uint32 m_regenTimer;
1828 uint32 m_lastManaUseTimer;
1830 private:
1831 void CleanupDeletedAuras();
1833 bool IsTriggeredAtSpellProcEvent(Unit *pVictim, Aura* aura, SpellEntry const* procSpell, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, bool isVictim, bool active, SpellProcEventEntry const*& spellProcEvent );
1834 bool HandleDummyAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1835 bool HandleHasteAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1836 bool HandleSpellCritChanceAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1837 bool HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1838 bool HandleOverrideClassScriptAuraProc(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 cooldown);
1839 bool HandleMendingAuraProc(Aura* triggeredByAura);
1841 // player or player's pet
1842 float GetCombatRatingReduction(CombatRating cr) const;
1843 uint32 GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const;
1845 Unit* _GetTotem(uint8 slot) const; // for templated function without include need
1847 uint32 m_state; // Even derived shouldn't modify
1848 uint32 m_CombatTimer;
1850 Spell* m_currentSpells[CURRENT_MAX_SPELL];
1852 UnitVisibility m_Visibility;
1854 Diminishing m_Diminishing;
1855 // Manage all Units threatening us
1856 ThreatManager m_ThreatManager;
1857 // Manage all Units that are threatened by us
1858 HostileRefManager m_HostileRefManager;
1860 FollowerRefManager m_FollowingRefManager;
1862 ComboPointHolderSet m_ComboPointHolders;
1864 GuardianPetList m_guardianPets;
1867 template<typename Func>
1868 void Unit::CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms)
1870 if(Pet* pet = GetPet())
1871 func(pet);
1873 if (withGuardians)
1875 for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
1876 if(Unit* guardian = Unit::GetUnit(*this,*itr))
1877 func(guardian);
1880 if (withTotems)
1882 for (int8 i = 0; i < MAX_TOTEM; ++i)
1883 if (Unit *totem = _GetTotem(i))
1884 func(totem);
1887 if (withCharms)
1888 if(Unit* charm = GetCharm())
1889 func(charm);
1893 template<typename Func>
1894 bool Unit::CheckAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms) const
1896 if (Pet* pet = GetPet())
1897 if (func(pet))
1898 return true;
1900 if (withGuardians)
1902 for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
1903 if (Unit* guardian = Unit::GetUnit(*this,*itr))
1904 if (func(guardian))
1905 return true;
1909 if (withTotems)
1911 for (int8 i = 0; i < MAX_TOTEM; ++i)
1912 if (Unit *totem = _GetTotem(i))
1913 if (func(totem))
1914 return true;
1917 if (withCharms)
1918 if(Unit* charm = GetCharm())
1919 if (func(charm))
1920 return true;
1922 return false;
1924 #endif