[9581] Fixed apply damage reduction to melee/ranged damage.
[getmangos.git] / src / game / Unit.h
blob23acdb589d043ff628d40f74b694ff796e58a2d2
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 (in fact interrupted at far teleport until next map telport landing)
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),
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 // Read/Write methods
753 void Read(ByteBuffer &data);
754 void Write(ByteBuffer &data) const;
756 // Movement flags manipulations
757 void AddMovementFlag(MovementFlags f) { moveFlags |= f; }
758 void RemoveMovementFlag(MovementFlags f) { moveFlags &= ~f; }
759 bool HasMovementFlag(MovementFlags f) const { return moveFlags & f; }
760 MovementFlags GetMovementFlags() const { return MovementFlags(moveFlags); }
761 void SetMovementFlags(MovementFlags f) { moveFlags = f; }
762 MovementFlags2 GetMovementFlags2() const { return MovementFlags2(moveFlags2); }
764 // Position manipulations
765 Position const *GetPos() const { return &pos; }
766 void SetTransportData(uint64 guid, float x, float y, float z, float o, uint32 time, int8 seat)
768 t_guid = guid;
769 t_pos.x = x;
770 t_pos.y = y;
771 t_pos.z = z;
772 t_pos.o = o;
773 t_time = time;
774 t_seat = seat;
776 uint64 GetTransportGuid() const { return t_guid.GetRawValue(); }
777 Position const *GetTransportPos() const { return &t_pos; }
778 int8 GetTransportSeat() const { return t_seat; }
779 uint32 GetTransportTime() const { return t_time; }
780 uint32 GetFallTime() const { return fallTime; }
781 void ChangePosition(float x, float y, float z, float o) { pos.x = x; pos.y = y; pos.z = z; pos.o = o; }
782 void UpdateTime(uint32 _time) { time = _time; }
784 private:
785 // common
786 uint32 moveFlags; // see enum MovementFlags
787 uint16 moveFlags2; // see enum MovementFlags2
788 uint32 time;
789 Position pos;
790 // transport
791 ObjectGuid t_guid;
792 Position t_pos;
793 uint32 t_time;
794 int8 t_seat;
795 uint32 t_time2;
796 // swimming and flying
797 float s_pitch;
798 // last fall time
799 uint32 fallTime;
800 // jumping
801 float j_velocity, j_sinAngle, j_cosAngle, j_xyspeed;
802 // spline
803 float u_unk1;
806 inline ByteBuffer& operator<< (ByteBuffer& buf, MovementInfo const& mi)
808 mi.Write(buf);
809 return buf;
812 inline ByteBuffer& operator>> (ByteBuffer& buf, MovementInfo& mi)
814 mi.Read(buf);
815 return buf;
818 enum DiminishingLevels
820 DIMINISHING_LEVEL_1 = 0,
821 DIMINISHING_LEVEL_2 = 1,
822 DIMINISHING_LEVEL_3 = 2,
823 DIMINISHING_LEVEL_IMMUNE = 3
826 struct DiminishingReturn
828 DiminishingReturn(DiminishingGroup group, uint32 t, uint32 count)
829 : DRGroup(group), stack(0), hitTime(t), hitCount(count)
832 DiminishingGroup DRGroup:16;
833 uint16 stack:16;
834 uint32 hitTime;
835 uint32 hitCount;
838 enum MeleeHitOutcome
840 MELEE_HIT_EVADE, MELEE_HIT_MISS, MELEE_HIT_DODGE, MELEE_HIT_BLOCK, MELEE_HIT_PARRY,
841 MELEE_HIT_GLANCING, MELEE_HIT_CRIT, MELEE_HIT_CRUSHING, MELEE_HIT_NORMAL
844 struct CleanDamage
846 CleanDamage(uint32 _damage, WeaponAttackType _attackType, MeleeHitOutcome _hitOutCome) :
847 damage(_damage), attackType(_attackType), hitOutCome(_hitOutCome) {}
849 uint32 damage;
850 WeaponAttackType attackType;
851 MeleeHitOutcome hitOutCome;
854 // Struct for use in Unit::CalculateMeleeDamage
855 // Need create structure like in SMSG_ATTACKERSTATEUPDATE opcode
856 struct CalcDamageInfo
858 Unit *attacker; // Attacker
859 Unit *target; // Target for damage
860 SpellSchoolMask damageSchoolMask;
861 uint32 damage;
862 uint32 absorb;
863 uint32 resist;
864 uint32 blocked_amount;
865 uint32 HitInfo;
866 uint32 TargetState;
867 // Helper
868 WeaponAttackType attackType; //
869 uint32 procAttacker;
870 uint32 procVictim;
871 uint32 procEx;
872 uint32 cleanDamage; // Used only for rage calculation
873 MeleeHitOutcome hitOutCome; // TODO: remove this field (need use TargetState)
876 // Spell damage info structure based on structure sending in SMSG_SPELLNONMELEEDAMAGELOG opcode
877 struct SpellNonMeleeDamage{
878 SpellNonMeleeDamage(Unit *_attacker, Unit *_target, uint32 _SpellID, uint32 _schoolMask)
879 : target(_target), attacker(_attacker), SpellID(_SpellID), damage(0), overkill(0), schoolMask(_schoolMask),
880 absorb(0), resist(0), physicalLog(false), unused(false), blocked(0), HitInfo(0), cleanDamage(0)
883 Unit *target;
884 Unit *attacker;
885 uint32 SpellID;
886 uint32 damage;
887 uint32 overkill;
888 uint32 schoolMask;
889 uint32 absorb;
890 uint32 resist;
891 bool physicalLog;
892 bool unused;
893 uint32 blocked;
894 uint32 HitInfo;
895 // Used for help
896 uint32 cleanDamage;
899 struct SpellPeriodicAuraLogInfo
901 SpellPeriodicAuraLogInfo(Aura *_aura, uint32 _damage, uint32 _overDamage, uint32 _absorb, uint32 _resist, float _multiplier, bool _critical = false)
902 : aura(_aura), damage(_damage), overDamage(_overDamage), absorb(_absorb), resist(_resist), multiplier(_multiplier), critical(_critical) {}
904 Aura *aura;
905 uint32 damage;
906 uint32 overDamage; // overkill/overheal
907 uint32 absorb;
908 uint32 resist;
909 float multiplier;
910 bool critical;
913 uint32 createProcExtendMask(SpellNonMeleeDamage *damageInfo, SpellMissInfo missCondition);
915 #define MAX_DECLINED_NAME_CASES 5
917 struct DeclinedName
919 std::string name[MAX_DECLINED_NAME_CASES];
922 enum CurrentSpellTypes
924 CURRENT_MELEE_SPELL = 0,
925 CURRENT_GENERIC_SPELL = 1,
926 CURRENT_AUTOREPEAT_SPELL = 2,
927 CURRENT_CHANNELED_SPELL = 3
930 #define CURRENT_FIRST_NON_MELEE_SPELL 1
931 #define CURRENT_MAX_SPELL 4
934 enum ActiveStates
936 ACT_PASSIVE = 0x01, // 0x01 - passive
937 ACT_DISABLED = 0x81, // 0x80 - castable
938 ACT_ENABLED = 0xC1, // 0x40 | 0x80 - auto cast + castable
939 ACT_COMMAND = 0x07, // 0x01 | 0x02 | 0x04
940 ACT_REACTION = 0x06, // 0x02 | 0x04
941 ACT_DECIDE = 0x00 // custom
944 enum ReactStates
946 REACT_PASSIVE = 0,
947 REACT_DEFENSIVE = 1,
948 REACT_AGGRESSIVE = 2
951 enum CommandStates
953 COMMAND_STAY = 0,
954 COMMAND_FOLLOW = 1,
955 COMMAND_ATTACK = 2,
956 COMMAND_ABANDON = 3
959 #define UNIT_ACTION_BUTTON_ACTION(X) (uint32(X) & 0x00FFFFFF)
960 #define UNIT_ACTION_BUTTON_TYPE(X) ((uint32(X) & 0xFF000000) >> 24)
961 #define MAX_UNIT_ACTION_BUTTON_ACTION_VALUE (0x00FFFFFF+1)
962 #define MAKE_UNIT_ACTION_BUTTON(A,T) (uint32(A) | (uint32(T) << 24))
964 struct UnitActionBarEntry
966 UnitActionBarEntry() : packedData(uint32(ACT_DISABLED) << 24) {}
968 uint32 packedData;
970 // helper
971 ActiveStates GetType() const { return ActiveStates(UNIT_ACTION_BUTTON_TYPE(packedData)); }
972 uint32 GetAction() const { return UNIT_ACTION_BUTTON_ACTION(packedData); }
973 bool IsActionBarForSpell() const
975 ActiveStates Type = GetType();
976 return Type == ACT_DISABLED || Type == ACT_ENABLED || Type == ACT_PASSIVE;
979 void SetActionAndType(uint32 action, ActiveStates type)
981 packedData = MAKE_UNIT_ACTION_BUTTON(action,type);
984 void SetType(ActiveStates type)
986 packedData = MAKE_UNIT_ACTION_BUTTON(UNIT_ACTION_BUTTON_ACTION(packedData),type);
989 void SetAction(uint32 action)
991 packedData = (packedData & 0xFF000000) | UNIT_ACTION_BUTTON_ACTION(action);
995 typedef UnitActionBarEntry CharmSpellEntry;
997 enum ActionBarIndex
999 ACTION_BAR_INDEX_START = 0,
1000 ACTION_BAR_INDEX_PET_SPELL_START = 3,
1001 ACTION_BAR_INDEX_PET_SPELL_END = 7,
1002 ACTION_BAR_INDEX_END = 10,
1005 #define MAX_UNIT_ACTION_BAR_INDEX (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START)
1007 struct CharmInfo
1009 public:
1010 explicit CharmInfo(Unit* unit);
1011 uint32 GetPetNumber() const { return m_petnumber; }
1012 void SetPetNumber(uint32 petnumber, bool statwindow);
1014 void SetCommandState(CommandStates st) { m_CommandState = st; }
1015 CommandStates GetCommandState() { return m_CommandState; }
1016 bool HasCommandState(CommandStates state) { return (m_CommandState == state); }
1017 void SetReactState(ReactStates st) { m_reactState = st; }
1018 ReactStates GetReactState() { return m_reactState; }
1019 bool HasReactState(ReactStates state) { return (m_reactState == state); }
1021 void InitPossessCreateSpells();
1022 void InitCharmCreateSpells();
1023 void InitPetActionBar();
1024 void InitEmptyActionBar();
1026 //return true if successful
1027 bool AddSpellToActionBar(uint32 spellid, ActiveStates newstate = ACT_DECIDE);
1028 bool RemoveSpellFromActionBar(uint32 spell_id);
1029 void LoadPetActionBar(const std::string& data);
1030 void BuildActionBar(WorldPacket* data);
1031 void SetSpellAutocast(uint32 spell_id, bool state);
1032 void SetActionBar(uint8 index, uint32 spellOrAction,ActiveStates type)
1034 PetActionBar[index].SetActionAndType(spellOrAction,type);
1036 UnitActionBarEntry const* GetActionBarEntry(uint8 index) const { return &(PetActionBar[index]); }
1038 void ToggleCreatureAutocast(uint32 spellid, bool apply);
1040 CharmSpellEntry* GetCharmSpell(uint8 index) { return &(m_charmspells[index]); }
1041 private:
1043 Unit* m_unit;
1044 UnitActionBarEntry PetActionBar[MAX_UNIT_ACTION_BAR_INDEX];
1045 CharmSpellEntry m_charmspells[CREATURE_MAX_SPELLS];
1046 CommandStates m_CommandState;
1047 ReactStates m_reactState;
1048 uint32 m_petnumber;
1051 // for clearing special attacks
1052 #define REACTIVE_TIMER_START 4000
1054 enum ReactiveType
1056 REACTIVE_DEFENSE = 0,
1057 REACTIVE_HUNTER_PARRY = 1,
1058 REACTIVE_OVERPOWER = 2
1061 #define MAX_REACTIVE 3
1063 typedef std::set<uint64> GuardianPetList;
1065 // delay time next attack to prevent client attack animation problems
1066 #define ATTACK_DISPLAY_DELAY 200
1067 #define MAX_PLAYER_STEALTH_DETECT_RANGE 45.0f // max distance for detection targets by player
1068 #define MAX_CREATURE_ATTACK_RADIUS 45.0f // max distance for creature aggro (use with CONFIG_FLOAT_RATE_CREATURE_AGGRO)
1070 // Regeneration defines
1071 #define REGEN_TIME_FULL 2000 // For this time difference is computed regen value
1072 #define REGEN_TIME_PRECISE 500 // Used in Spell::CheckPower for precise regeneration in spell cast time
1074 struct SpellProcEventEntry; // used only privately
1076 class MANGOS_DLL_SPEC Unit : public WorldObject
1078 public:
1079 typedef std::set<Unit*> AttackerSet;
1080 typedef std::pair<uint32, SpellEffectIndex> spellEffectPair;
1081 typedef std::multimap< spellEffectPair, Aura*> AuraMap;
1082 typedef std::list<Aura *> AuraList;
1083 typedef std::list<DiminishingReturn> Diminishing;
1084 typedef std::set<uint32> ComboPointHolderSet;
1085 typedef std::map<uint8, uint32> VisibleAuraMap;
1087 virtual ~Unit ( );
1089 void AddToWorld();
1090 void RemoveFromWorld();
1092 void CleanupsBeforeDelete(); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units)
1094 DiminishingLevels GetDiminishing(DiminishingGroup group);
1095 void IncrDiminishing(DiminishingGroup group);
1096 void ApplyDiminishingToDuration(DiminishingGroup group, int32 &duration,Unit* caster, DiminishingLevels Level, int32 limitduration);
1097 void ApplyDiminishingAura(DiminishingGroup group, bool apply);
1098 void ClearDiminishings() { m_Diminishing.clear(); }
1100 virtual void Update( uint32 time );
1102 void setAttackTimer(WeaponAttackType type, uint32 time) { m_attackTimer[type] = time; }
1103 void resetAttackTimer(WeaponAttackType type = BASE_ATTACK);
1104 uint32 getAttackTimer(WeaponAttackType type) const { return m_attackTimer[type]; }
1105 bool isAttackReady(WeaponAttackType type = BASE_ATTACK) const { return m_attackTimer[type] == 0; }
1106 bool haveOffhandWeapon() const;
1107 bool canReachWithAttack(Unit *pVictim) const;
1108 uint32 m_extraAttacks;
1110 void _addAttacker(Unit *pAttacker) // must be called only from Unit::Attack(Unit*)
1112 AttackerSet::const_iterator itr = m_attackers.find(pAttacker);
1113 if(itr == m_attackers.end())
1114 m_attackers.insert(pAttacker);
1116 void _removeAttacker(Unit *pAttacker) // must be called only from Unit::AttackStop()
1118 m_attackers.erase(pAttacker);
1120 Unit * getAttackerForHelper() // If someone wants to help, who to give them
1122 if (getVictim() != NULL)
1123 return getVictim();
1125 if (!m_attackers.empty())
1126 return *(m_attackers.begin());
1128 return NULL;
1130 bool Attack(Unit *victim, bool meleeAttack);
1131 void CastStop(uint32 except_spellid = 0);
1132 bool AttackStop(bool targetSwitch = false);
1133 void RemoveAllAttackers();
1134 AttackerSet const& getAttackers() const { return m_attackers; }
1135 bool isAttackingPlayer() const;
1136 Unit* getVictim() const { return m_attacking; }
1137 void CombatStop(bool includingCast = false);
1138 void CombatStopWithPets(bool includingCast = false);
1139 void StopAttackFaction(uint32 faction_id);
1140 Unit* SelectRandomUnfriendlyTarget(Unit* except = NULL, float radius = ATTACK_DISTANCE) const;
1141 Unit* SelectRandomFriendlyTarget(Unit* except = NULL, float radius = ATTACK_DISTANCE) const;
1142 bool hasNegativeAuraWithInterruptFlag(uint32 flag);
1143 void SendMeleeAttackStop(Unit* victim);
1144 void SendMeleeAttackStart(Unit* pVictim);
1146 void addUnitState(uint32 f) { m_state |= f; }
1147 bool hasUnitState(uint32 f) const { return (m_state & f); }
1148 void clearUnitState(uint32 f) { m_state &= ~f; }
1149 bool CanFreeMove() const
1151 return !hasUnitState(UNIT_STAT_NO_FREE_MOVE) && GetOwnerGUID()==0;
1154 uint32 getLevel() const { return GetUInt32Value(UNIT_FIELD_LEVEL); }
1155 virtual uint32 getLevelForTarget(Unit const* /*target*/) const { return getLevel(); }
1156 void SetLevel(uint32 lvl);
1157 uint8 getRace() const { return GetByteValue(UNIT_FIELD_BYTES_0, 0); }
1158 uint32 getRaceMask() const { return 1 << (getRace()-1); }
1159 uint8 getClass() const { return GetByteValue(UNIT_FIELD_BYTES_0, 1); }
1160 uint32 getClassMask() const { return 1 << (getClass()-1); }
1161 uint8 getGender() const { return GetByteValue(UNIT_FIELD_BYTES_0, 2); }
1163 float GetStat(Stats stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0+stat)); }
1164 void SetStat(Stats stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0+stat, val); }
1165 uint32 GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL) ; }
1166 void SetArmor(int32 val) { SetResistance(SPELL_SCHOOL_NORMAL, val); }
1168 uint32 GetResistance(SpellSchools school) const { return GetUInt32Value(UNIT_FIELD_RESISTANCES+school); }
1169 void SetResistance(SpellSchools school, int32 val) { SetStatInt32Value(UNIT_FIELD_RESISTANCES+school,val); }
1171 uint32 GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH); }
1172 uint32 GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH); }
1173 float GetHealthPercent() const { return (GetHealth()*100.0f) / GetMaxHealth(); }
1174 void SetHealth( uint32 val);
1175 void SetMaxHealth(uint32 val);
1176 void SetHealthPercent(float percent);
1177 int32 ModifyHealth(int32 val);
1179 Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, 3)); }
1180 void setPowerType(Powers power);
1181 uint32 GetPower( Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1 +power); }
1182 uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1+power); }
1183 void SetPower( Powers power, uint32 val);
1184 void SetMaxPower(Powers power, uint32 val);
1185 int32 ModifyPower(Powers power, int32 val);
1186 void ApplyPowerMod(Powers power, uint32 val, bool apply);
1187 void ApplyMaxPowerMod(Powers power, uint32 val, bool apply);
1189 uint32 GetAttackTime(WeaponAttackType att) const { return (uint32)(GetFloatValue(UNIT_FIELD_BASEATTACKTIME+att)/m_modAttackSpeedPct[att]); }
1190 void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val*m_modAttackSpeedPct[att]); }
1191 void ApplyAttackTimePercentMod(WeaponAttackType att,float val, bool apply);
1192 void ApplyCastTimePercentMod(float val, bool apply);
1194 SheathState GetSheath() const { return SheathState(GetByteValue(UNIT_FIELD_BYTES_2, 0)); }
1195 virtual void SetSheath( SheathState sheathed ) { SetByteValue(UNIT_FIELD_BYTES_2, 0, sheathed); }
1197 // faction template id
1198 uint32 getFaction() const { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE); }
1199 void setFaction(uint32 faction) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, faction ); }
1200 FactionTemplateEntry const* getFactionTemplateEntry() const;
1201 bool IsHostileTo(Unit const* unit) const;
1202 bool IsHostileToPlayers() const;
1203 bool IsFriendlyTo(Unit const* unit) const;
1204 bool IsNeutralToAll() const;
1205 bool IsContestedGuard() const
1207 if(FactionTemplateEntry const* entry = getFactionTemplateEntry())
1208 return entry->IsContestedGuardFaction();
1210 return false;
1212 bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP); }
1213 void SetPvP(bool state);
1214 bool IsFFAPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); }
1215 void SetFFAPvP(bool state);
1216 uint32 GetCreatureType() const;
1217 uint32 GetCreatureTypeMask() const
1219 uint32 creatureType = GetCreatureType();
1220 return (creatureType >= 1) ? (1 << (creatureType - 1)) : 0;
1223 uint8 getStandState() const { return GetByteValue(UNIT_FIELD_BYTES_1, 0); }
1224 bool IsSitState() const;
1225 bool IsStandState() const;
1226 void SetStandState(uint8 state);
1228 void SetStandFlags(uint8 flags) { SetByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1229 void RemoveStandFlags(uint8 flags) { RemoveByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1231 bool IsMounted() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); }
1232 uint32 GetMountID() const { return GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID); }
1233 void Mount(uint32 mount, uint32 spellId = 0);
1234 void Unmount();
1236 uint16 GetMaxSkillValueForLevel(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1237 void DealDamageMods(Unit *pVictim, uint32 &damage, uint32* absorb);
1238 uint32 DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss);
1239 int32 DealHeal(Unit *pVictim, uint32 addhealth, SpellEntry const *spellProto, bool critical = false);
1241 void ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 procEx, uint32 amount, WeaponAttackType attType = BASE_ATTACK, SpellEntry const *procSpell = NULL);
1242 void ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage );
1244 void HandleEmoteCommand(uint32 anim_id);
1245 void AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType = BASE_ATTACK, bool extra = false );
1247 float MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const;
1249 void CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *damageInfo, WeaponAttackType attackType = BASE_ATTACK);
1250 void DealMeleeDamage(CalcDamageInfo *damageInfo, bool durabilityLoss);
1252 void CalculateSpellDamage(SpellNonMeleeDamage *damageInfo, int32 damage, SpellEntry const *spellInfo, WeaponAttackType attackType = BASE_ATTACK);
1253 void DealSpellDamage(SpellNonMeleeDamage *damageInfo, bool durabilityLoss);
1255 // player or player's pet resilience (-1%)
1256 float GetMeleeCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_MELEE); }
1257 float GetRangedCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_RANGED); }
1258 float GetSpellCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_SPELL); }
1260 // player or player's pet resilience (-1%)
1261 uint32 GetMeleeCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 2.2f, 33.0f, damage); }
1262 uint32 GetRangedCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_RANGED, 2.2f, 33.0f, damage); }
1263 uint32 GetSpellCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_SPELL, 2.2f, 33.0f, damage); }
1265 // player or player's pet resilience (-1%), cap 100%
1266 uint32 GetMeleeDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1267 uint32 GetRangedDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1268 uint32 GetSpellDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1270 float MeleeSpellMissChance(Unit *pVictim, WeaponAttackType attType, int32 skillDiff, SpellEntry const *spell);
1271 SpellMissInfo MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1272 SpellMissInfo MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1273 SpellMissInfo SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool canReflect = false);
1275 float GetUnitDodgeChance() const;
1276 float GetUnitParryChance() const;
1277 float GetUnitBlockChance() const;
1278 float GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const;
1280 virtual uint32 GetShieldBlockValue() const =0;
1281 uint32 GetUnitMeleeSkill(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1282 uint32 GetDefenseSkillValue(Unit const* target = NULL) const;
1283 uint32 GetWeaponSkillValue(WeaponAttackType attType, Unit const* target = NULL) const;
1284 float GetWeaponProcChance() const;
1285 float GetPPMProcChance(uint32 WeaponSpeed, float PPM) const;
1287 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType) const;
1288 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance) const;
1290 bool isVendor() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR ); }
1291 bool isTrainer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER ); }
1292 bool isQuestGiver() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER ); }
1293 bool isGossip() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP ); }
1294 bool isTaxi() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_FLIGHTMASTER ); }
1295 bool isGuildMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PETITIONER ); }
1296 bool isBattleMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BATTLEMASTER ); }
1297 bool isBanker() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BANKER ); }
1298 bool isInnkeeper() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_INNKEEPER ); }
1299 bool isSpiritHealer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER ); }
1300 bool isSpiritGuide() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITGUIDE ); }
1301 bool isTabardDesigner()const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TABARDDESIGNER ); }
1302 bool isAuctioner() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER ); }
1303 bool isArmorer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_REPAIR ); }
1304 bool isServiceProvider() const
1306 return HasFlag( UNIT_NPC_FLAGS,
1307 UNIT_NPC_FLAG_VENDOR | UNIT_NPC_FLAG_TRAINER | UNIT_NPC_FLAG_FLIGHTMASTER |
1308 UNIT_NPC_FLAG_PETITIONER | UNIT_NPC_FLAG_BATTLEMASTER | UNIT_NPC_FLAG_BANKER |
1309 UNIT_NPC_FLAG_INNKEEPER | UNIT_NPC_FLAG_GUARD | UNIT_NPC_FLAG_SPIRITHEALER |
1310 UNIT_NPC_FLAG_SPIRITGUIDE | UNIT_NPC_FLAG_TABARDDESIGNER | UNIT_NPC_FLAG_AUCTIONEER );
1312 bool isSpiritService() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER | UNIT_NPC_FLAG_SPIRITGUIDE ); }
1314 //Need fix or use this
1315 bool isGuard() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GUARD); }
1317 bool isInFlight() const { return hasUnitState(UNIT_STAT_IN_FLIGHT); }
1319 bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); }
1320 void SetInCombatState(bool PvP, Unit* enemy = NULL);
1321 void SetInCombatWith(Unit* enemy);
1322 void ClearInCombat();
1323 uint32 GetCombatTimer() const { return m_CombatTimer; }
1325 bool HasAuraType(AuraType auraType) const;
1326 bool HasAura(uint32 spellId, SpellEffectIndex effIndex) const
1328 return m_Auras.find(spellEffectPair(spellId, effIndex)) != m_Auras.end();
1330 bool HasAura(uint32 spellId) const;
1332 bool virtual HasSpell(uint32 /*spellID*/) const { return false; }
1334 bool HasStealthAura() const { return HasAuraType(SPELL_AURA_MOD_STEALTH); }
1335 bool HasInvisibilityAura() const { return HasAuraType(SPELL_AURA_MOD_INVISIBILITY); }
1336 bool isFeared() const { return HasAuraType(SPELL_AURA_MOD_FEAR); }
1337 bool isInRoots() const { return HasAuraType(SPELL_AURA_MOD_ROOT); }
1338 bool IsPolymorphed() const;
1340 bool isFrozen() const;
1342 void RemoveSpellbyDamageTaken(AuraType auraType, uint32 damage);
1344 bool isTargetableForAttack(bool inversAlive = false) const;
1345 virtual bool IsInWater() const;
1346 virtual bool IsUnderWater() const;
1347 bool isInAccessablePlaceFor(Creature const* c) const;
1349 void SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, uint32 OverHeal, bool critical = false);
1350 void SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage,Powers powertype);
1351 void EnergizeBySpell(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype);
1352 uint32 SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage);
1353 void CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1354 void CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1355 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);
1356 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);
1357 void CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1358 void CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1360 bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const;
1362 void DeMorph();
1364 void SendAttackStateUpdate(CalcDamageInfo *damageInfo);
1365 void SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount);
1366 void SendSpellNonMeleeDamageLog(SpellNonMeleeDamage *log);
1367 void SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID, uint32 Damage, SpellSchoolMask damageSchoolMask, uint32 AbsorbedDamage, uint32 Resist, bool PhysicalDamage, uint32 Blocked, bool CriticalHit = false);
1368 void SendPeriodicAuraLog(SpellPeriodicAuraLogInfo *pInfo);
1369 void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo);
1371 void NearTeleportTo(float x, float y, float z, float orientation, bool casting = false);
1373 void MonsterMove(float x, float y, float z, uint32 transitTime);
1374 void MonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime = 0);
1376 // recommend use MonsterMove/MonsterMoveWithSpeed for most case that correctly work with movegens
1377 void SendMonsterMove(float x, float y, float z, SplineType type, SplineFlags flags, uint32 Time, Player* player = NULL);
1378 void SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, SplineFlags flags);
1379 void SendMonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime = 0, Player* player = NULL);
1381 void SendHighestThreatUpdate(HostileReference* pHostileReference);
1382 void SendThreatClear();
1383 void SendThreatRemove(HostileReference* pHostileReference);
1384 void SendThreatUpdate();
1386 void BuildHeartBeatMsg( WorldPacket *data ) const;
1388 virtual void MoveOutOfRange(Player &) { };
1390 bool isAlive() const { return (m_deathState == ALIVE); };
1391 bool isDead() const { return ( m_deathState == DEAD || m_deathState == CORPSE ); };
1392 DeathState getDeathState() { return m_deathState; };
1393 virtual void setDeathState(DeathState s); // overwritten in Creature/Player/Pet
1395 uint64 GetOwnerGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMONEDBY); }
1396 void SetOwnerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner); }
1397 uint64 GetCreatorGUID() const { return GetUInt64Value(UNIT_FIELD_CREATEDBY); }
1398 void SetCreatorGUID(uint64 creator) { SetUInt64Value(UNIT_FIELD_CREATEDBY, creator); }
1399 uint64 GetPetGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMON); }
1400 void SetPetGUID(uint64 pet) { SetUInt64Value(UNIT_FIELD_SUMMON, pet); }
1401 uint64 GetCharmerGUID() const { return GetUInt64Value(UNIT_FIELD_CHARMEDBY); }
1402 void SetCharmerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_CHARMEDBY, owner); }
1403 uint64 GetCharmGUID() const { return GetUInt64Value(UNIT_FIELD_CHARM); }
1404 void SetCharmGUID(uint64 charm) { SetUInt64Value(UNIT_FIELD_CHARM, charm); }
1405 uint64 GetTargetGUID() const { return GetUInt64Value(UNIT_FIELD_TARGET); }
1406 void SetTargetGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_TARGET, targetGuid); }
1407 uint64 GetChannelObjectGUID() const { return GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT); }
1408 void SetChannelObjectGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, targetGuid); }
1410 uint64 GetCharmerOrOwnerGUID() const { return GetCharmerGUID() ? GetCharmerGUID() : GetOwnerGUID(); }
1411 uint64 GetCharmerOrOwnerOrOwnGUID() const
1413 if(uint64 guid = GetCharmerOrOwnerGUID())
1414 return guid;
1415 return GetGUID();
1417 bool isCharmedOwnedByPlayerOrPlayer() const { return IS_PLAYER_GUID(GetCharmerOrOwnerOrOwnGUID()); }
1419 Player* GetSpellModOwner();
1421 Unit* GetOwner() const;
1422 Pet* GetPet() const;
1423 Unit* GetCharmer() const;
1424 Unit* GetCharm() const;
1425 void Uncharm();
1426 Unit* GetCharmerOrOwner() const { return GetCharmerGUID() ? GetCharmer() : GetOwner(); }
1427 Unit* GetCharmerOrOwnerOrSelf()
1429 if(Unit* u = GetCharmerOrOwner())
1430 return u;
1432 return this;
1434 bool IsCharmerOrOwnerPlayerOrPlayerItself() const;
1435 Player* GetCharmerOrOwnerPlayerOrPlayerItself();
1436 float GetCombatDistance( const Unit* target ) const;
1438 void SetPet(Pet* pet);
1439 void SetCharm(Unit* pet);
1441 void AddGuardian(Pet* pet);
1442 void RemoveGuardian(Pet* pet);
1443 void RemoveGuardians();
1444 Pet* FindGuardianWithEntry(uint32 entry);
1446 bool isCharmed() const { return GetCharmerGUID() != 0; }
1448 CharmInfo* GetCharmInfo() { return m_charmInfo; }
1449 CharmInfo* InitCharmInfo(Unit* charm);
1451 Pet* CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id = 0);
1453 uint64 const& GetTotemGUID(TotemSlot slot) const { return m_TotemSlot[slot]; }
1454 Totem* GetTotem(TotemSlot slot) const;
1455 bool IsAllTotemSlotsUsed() const;
1457 void _AddTotem(TotemSlot slot, Totem* totem); // only for call from Totem summon code
1458 void _RemoveTotem(Totem* totem); // only for call from Totem class
1460 template<typename Func>
1461 void CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms);
1462 template<typename Func>
1463 bool CheckAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms) const;
1465 bool AddAura(Aura *aur);
1467 // removing specific aura stack
1468 void RemoveAura(Aura* aura, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1469 void RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1470 void RemoveAura(uint32 spellId, SpellEffectIndex effindex, Aura* except = NULL);
1472 // removing specific aura stacks by diff reasons and selections
1473 void RemoveAurasDueToSpell(uint32 spellId, Aura* except = NULL);
1474 void RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId);
1475 void RemoveAurasByCasterSpell(uint32 spellId, uint64 casterGUID);
1476 void RemoveAurasByCasterSpell(uint32 spellId, SpellEffectIndex effindex, uint64 casterGUID);
1477 void RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer);
1478 void RemoveAurasDueToSpellByCancel(uint32 spellId);
1480 // removing unknown aura stacks by diff reasons and selections
1481 void RemoveNotOwnSingleTargetAuras(uint32 newPhase = 0x0);
1482 void RemoveAurasAtMechanicImmunity(uint32 mechMask, uint32 exceptSpellId, bool non_positive = false);
1483 void RemoveSpellsCausingAura(AuraType auraType);
1484 void RemoveRankAurasDueToSpell(uint32 spellId);
1485 bool RemoveNoStackAurasDueToAura(Aura *Aur);
1486 void RemoveAurasWithInterruptFlags(uint32 flags);
1487 void RemoveAurasWithDispelType( DispelType type );
1488 void RemoveAllAuras(AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1489 void RemoveArenaAuras(bool onleave = false);
1490 void RemoveAllAurasOnDeath();
1492 // removing specific aura FROM stack
1493 void RemoveSingleAuraFromStack(uint32 spellId, SpellEffectIndex effindex, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1494 void RemoveSingleAuraFromStack(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1496 // removing specific aura FROM stack by diff reasons and selections
1497 void RemoveSingleSpellAurasFromStack(uint32 spellId, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1498 void RemoveSingleSpellAurasByCasterSpell(uint32 spellId, uint64 casterGUID, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1499 void RemoveSingleAuraByCasterSpell(uint32 spellId, SpellEffectIndex effindex, uint64 casterGUID, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1500 void RemoveSingleAuraDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler);
1502 void DelayAura(uint32 spellId, SpellEffectIndex effindex, int32 delaytime);
1504 float GetResistanceBuffMods(SpellSchools school, bool positive) const { return GetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school ); }
1505 void SetResistanceBuffMods(SpellSchools school, bool positive, float val) { SetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school,val); }
1506 void ApplyResistanceBuffModsMod(SpellSchools school, bool positive, float val, bool apply) { ApplyModSignedFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1507 void ApplyResistanceBuffModsPercentMod(SpellSchools school, bool positive, float val, bool apply) { ApplyPercentModFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1508 void InitStatBuffMods()
1510 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_POSSTAT0+i, 0);
1511 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_NEGSTAT0+i, 0);
1513 void ApplyStatBuffMod(Stats stat, float val, bool apply) { ApplyModSignedFloatValue((val > 0 ? UNIT_FIELD_POSSTAT0+stat : UNIT_FIELD_NEGSTAT0+stat), val, apply); }
1514 void ApplyStatPercentBuffMod(Stats stat, float val, bool apply)
1516 ApplyPercentModFloatValue(UNIT_FIELD_POSSTAT0+stat, val, apply);
1517 ApplyPercentModFloatValue(UNIT_FIELD_NEGSTAT0+stat, val, apply);
1519 void SetCreateStat(Stats stat, float val) { m_createStats[stat] = val; }
1520 void SetCreateHealth(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_HEALTH, val); }
1521 uint32 GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH); }
1522 void SetCreateMana(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_MANA, val); }
1523 uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); }
1524 uint32 GetCreatePowers(Powers power) const;
1525 float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0+stat); }
1526 float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0+stat); }
1527 float GetCreateStat(Stats stat) const { return m_createStats[stat]; }
1529 void SetCurrentCastedSpell(Spell * pSpell);
1530 virtual void ProhibitSpellSchool(SpellSchoolMask /*idSchoolMask*/, uint32 /*unTimeMs*/ ) { }
1531 void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed = true, bool sendAutoRepeatCancelToClient = true);
1532 void FinishSpell(CurrentSpellTypes spellType, bool ok = true);
1534 // set withDelayed to true to account delayed spells as casted
1535 // delayed+channeled spells are always accounted as casted
1536 // we can skip channeled or delayed checks using flags
1537 bool IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled = false, bool skipAutorepeat = false) const;
1539 // set withDelayed to true to interrupt delayed spells too
1540 // delayed+channeled spells are always interrupted
1541 void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid = 0);
1543 Spell* GetCurrentSpell(CurrentSpellTypes spellType) const { return m_currentSpells[spellType]; }
1544 Spell* FindCurrentSpellBySpellId(uint32 spell_id) const;
1546 bool CheckAndIncreaseCastCounter();
1547 void DecreaseCastCounter() { if (m_castCounter) --m_castCounter; }
1549 uint32 m_addDmgOnce;
1550 uint64 m_ObjectSlot[4];
1551 uint32 m_detectInvisibilityMask;
1552 uint32 m_invisibilityMask;
1554 uint32 m_ShapeShiftFormSpellId;
1555 ShapeshiftForm m_form;
1556 bool IsInFeralForm() const { return m_form == FORM_CAT || m_form == FORM_BEAR || m_form == FORM_DIREBEAR; }
1558 float m_modMeleeHitChance;
1559 float m_modRangedHitChance;
1560 float m_modSpellHitChance;
1561 int32 m_baseSpellCritChance;
1563 float m_threatModifier[MAX_SPELL_SCHOOL];
1564 float m_modAttackSpeedPct[3];
1566 // Event handler
1567 EventProcessor m_Events;
1569 // stat system
1570 bool HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply);
1571 void SetModifierValue(UnitMods unitMod, UnitModifierType modifierType, float value) { m_auraModifiersGroup[unitMod][modifierType] = value; }
1572 float GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const;
1573 float GetTotalStatValue(Stats stat) const;
1574 float GetTotalAuraModValue(UnitMods unitMod) const;
1575 SpellSchools GetSpellSchoolByAuraGroup(UnitMods unitMod) const;
1576 Stats GetStatByAuraGroup(UnitMods unitMod) const;
1577 Powers GetPowerTypeByAuraGroup(UnitMods unitMod) const;
1578 bool CanModifyStats() const { return m_canModifyStats; }
1579 void SetCanModifyStats(bool modifyStats) { m_canModifyStats = modifyStats; }
1580 virtual bool UpdateStats(Stats stat) = 0;
1581 virtual bool UpdateAllStats() = 0;
1582 virtual void UpdateResistances(uint32 school) = 0;
1583 virtual void UpdateArmor() = 0;
1584 virtual void UpdateMaxHealth() = 0;
1585 virtual void UpdateMaxPower(Powers power) = 0;
1586 virtual void UpdateAttackPowerAndDamage(bool ranged = false) = 0;
1587 virtual void UpdateDamagePhysical(WeaponAttackType attType) = 0;
1588 float GetTotalAttackPowerValue(WeaponAttackType attType) const;
1589 float GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const;
1590 void SetBaseWeaponDamage(WeaponAttackType attType ,WeaponDamageRange damageRange, float value) { m_weaponDamage[attType][damageRange] = value; }
1592 void SetInFront(Unit const* target);
1593 void SetFacingTo(float ori);
1594 void SetFacingToObject(WorldObject* pObject);
1596 // Visibility system
1597 UnitVisibility GetVisibility() const { return m_Visibility; }
1598 void SetVisibility(UnitVisibility x);
1600 // common function for visibility checks for player/creatures with detection code
1601 bool isVisibleForOrDetect(Unit const* u, WorldObject const* viewPoint, bool detect, bool inVisibleList = false, bool is3dDistance = true) const;
1602 bool canDetectInvisibilityOf(Unit const* u) const;
1603 void SetPhaseMask(uint32 newPhaseMask, bool update);// overwrite WorldObject::SetPhaseMask
1605 // virtual functions for all world objects types
1606 bool isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const;
1607 // function for low level grid visibility checks in player/creature cases
1608 virtual bool IsVisibleInGridForPlayer(Player* pl) const = 0;
1609 bool isInvisibleForAlive() const;
1611 AuraList & GetSingleCastAuras() { return m_scAuras; }
1612 AuraList const& GetSingleCastAuras() const { return m_scAuras; }
1613 SpellImmuneList m_spellImmune[MAX_SPELL_IMMUNITY];
1615 // Threat related methods
1616 bool CanHaveThreatList() const;
1617 void AddThreat(Unit* pVictim, float threat = 0.0f, bool crit = false, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NONE, SpellEntry const *threatSpell = NULL);
1618 float ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL);
1619 void DeleteThreatList();
1620 bool SelectHostileTarget();
1621 void TauntApply(Unit* pVictim);
1622 void TauntFadeOut(Unit *taunter);
1623 ThreatManager& getThreatManager() { return m_ThreatManager; }
1624 ThreatManager const& getThreatManager() const { return m_ThreatManager; }
1625 void addHatedBy(HostileReference* pHostileReference) { m_HostileRefManager.insertFirst(pHostileReference); };
1626 void removeHatedBy(HostileReference* /*pHostileReference*/ ) { /* nothing to do yet */ }
1627 HostileRefManager& getHostileRefManager() { return m_HostileRefManager; }
1629 uint32 GetVisibleAura(uint8 slot)
1631 VisibleAuraMap::const_iterator itr = m_visibleAuras.find(slot);
1632 if(itr != m_visibleAuras.end())
1633 return itr->second;
1634 return 0;
1636 void SetVisibleAura(uint8 slot, uint32 spellid)
1638 if(spellid == 0)
1639 m_visibleAuras.erase(slot);
1640 else
1641 m_visibleAuras[slot] = spellid;
1643 VisibleAuraMap const *GetVisibleAuras() { return &m_visibleAuras; }
1644 uint8 GetVisibleAurasCount() { return m_visibleAuras.size(); }
1646 Aura* GetAura(uint32 spellId, SpellEffectIndex effindex);
1647 Aura* GetAura(AuraType type, uint32 family, uint64 familyFlag, uint32 familyFlag2 = 0, uint64 casterGUID = 0);
1649 AuraMap & GetAuras() { return m_Auras; }
1650 AuraMap const& GetAuras() const { return m_Auras; }
1651 AuraList const& GetAurasByType(AuraType type) const { return m_modAuras[type]; }
1652 void ApplyAuraProcTriggerDamage(Aura* aura, bool apply);
1654 int32 GetTotalAuraModifier(AuraType auratype) const;
1655 float GetTotalAuraMultiplier(AuraType auratype) const;
1656 int32 GetMaxPositiveAuraModifier(AuraType auratype) const;
1657 int32 GetMaxNegativeAuraModifier(AuraType auratype) const;
1659 int32 GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1660 float GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1661 int32 GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1662 int32 GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1664 int32 GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1665 float GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const;
1666 int32 GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1667 int32 GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1669 // misc have plain value but we check it fit to provided values mask (mask & (1 << (misc-1)))
1670 float GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype, uint32 mask) const;
1672 Aura* GetDummyAura(uint32 spell_id) const;
1674 uint32 m_AuraFlags;
1676 uint32 GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID); }
1677 void SetDisplayId(uint32 modelId);
1678 uint32 GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
1679 void SetNativeDisplayId(uint32 modelId) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, modelId); }
1680 void setTransForm(uint32 spellid) { m_transform = spellid;}
1681 uint32 getTransForm() const { return m_transform;}
1683 DynamicObject* GetDynObject(uint32 spellId, SpellEffectIndex effIndex);
1684 DynamicObject* GetDynObject(uint32 spellId);
1685 void AddDynObject(DynamicObject* dynObj);
1686 void RemoveDynObject(uint32 spellid);
1687 void RemoveDynObjectWithGUID(uint64 guid) { m_dynObjGUIDs.remove(guid); }
1688 void RemoveAllDynObjects();
1690 GameObject* GetGameObject(uint32 spellId) const;
1691 void AddGameObject(GameObject* gameObj);
1692 void RemoveGameObject(GameObject* gameObj, bool del);
1693 void RemoveGameObject(uint32 spellid, bool del);
1694 void RemoveAllGameObjects();
1696 uint32 CalculateDamage(WeaponAttackType attType, bool normalized);
1697 float GetAPMultiplier(WeaponAttackType attType, bool normalized);
1698 void ModifyAuraState(AuraState flag, bool apply);
1699 bool HasAuraState(AuraState flag) const { return HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); }
1700 bool HasAuraStateForCaster(AuraState flag, uint64 caster) const;
1701 void UnsummonAllTotems();
1702 Unit* SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo = NULL);
1703 int32 SpellBaseDamageBonus(SpellSchoolMask schoolMask);
1704 int32 SpellBaseHealingBonus(SpellSchoolMask schoolMask);
1705 int32 SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1706 int32 SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1707 uint32 SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 damage, DamageEffectType damagetype, uint32 stack = 1);
1708 int32 SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, int32 healamount, DamageEffectType damagetype, uint32 stack = 1);
1709 bool isSpellBlocked(Unit *pVictim, SpellEntry const *spellProto, WeaponAttackType attackType = BASE_ATTACK);
1710 bool isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType = BASE_ATTACK);
1711 uint32 SpellCriticalDamageBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1712 uint32 SpellCriticalHealingBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1714 void SetLastManaUse()
1716 if (GetTypeId() == TYPEID_PLAYER && !IsUnderLastManaUseEffect())
1717 RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_REGENERATE_POWER);
1719 m_lastManaUseTimer = 5000;
1721 bool IsUnderLastManaUseEffect() const { return m_lastManaUseTimer; }
1723 uint32 GetRegenTimer() const { return m_regenTimer; }
1725 void SetContestedPvP(Player *attackedPlayer = NULL);
1727 uint32 MeleeDamageBonus(Unit *pVictim, uint32 damage, WeaponAttackType attType, SpellEntry const *spellProto = NULL, DamageEffectType damagetype = DIRECT_DAMAGE, uint32 stack =1);
1728 uint32 GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime );
1730 void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply);
1731 void ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply);
1732 virtual bool IsImmunedToSpell(SpellEntry const* spellInfo);
1733 // redefined in Creature
1734 bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask);
1735 virtual bool IsImmunedToSpellEffect(SpellEntry const* spellInfo, SpellEffectIndex index) const;
1736 // redefined in Creature
1738 uint32 CalcArmorReducedDamage(Unit* pVictim, const uint32 damage);
1739 void CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist, bool canReflect = false);
1741 void UpdateWalkMode(Unit* source, bool self = true);
1742 void UpdateSpeed(UnitMoveType mtype, bool forced);
1743 float GetSpeed( UnitMoveType mtype ) const;
1744 float GetSpeedRate( UnitMoveType mtype ) const { return m_speed_rate[mtype]; }
1745 void SetSpeedRate(UnitMoveType mtype, float rate, bool forced = false);
1747 void SetHover(bool on);
1748 bool isHover() const { return HasAuraType(SPELL_AURA_HOVER); }
1750 void KnockBackFrom(Unit* target, float horizontalSpeed, float verticalSpeed);
1752 void _RemoveAllAuraMods();
1753 void _ApplyAllAuraMods();
1755 int32 CalculateSpellDamage(SpellEntry const* spellProto, SpellEffectIndex effect_index, int32 basePoints, Unit const* target);
1757 uint32 CalcNotIgnoreAbsorbDamage( uint32 damage, SpellSchoolMask damageSchoolMask, SpellEntry const* spellInfo = NULL);
1758 uint32 CalcNotIgnoreDamageRedunction( uint32 damage, SpellSchoolMask damageSchoolMask);
1759 int32 CalculateSpellDuration(SpellEntry const* spellProto, SpellEffectIndex effect_index, Unit const* target);
1760 float CalculateLevelPenalty(SpellEntry const* spellProto) const;
1762 void addFollower(FollowerReference* pRef) { m_FollowingRefManager.insertFirst(pRef); }
1763 void removeFollower(FollowerReference* /*pRef*/ ) { /* nothing to do yet */ }
1764 static Unit* GetUnit(WorldObject const& object, uint64 guid);
1766 MotionMaster* GetMotionMaster() { return &i_motionMaster; }
1768 bool IsStopped() const { return !(hasUnitState(UNIT_STAT_MOVING)); }
1769 void StopMoving();
1771 void SetFeared(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0, uint32 time = 0);
1772 void SetConfused(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);
1773 void SetFeignDeath(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);
1775 void AddComboPointHolder(uint32 lowguid) { m_ComboPointHolders.insert(lowguid); }
1776 void RemoveComboPointHolder(uint32 lowguid) { m_ComboPointHolders.erase(lowguid); }
1777 void ClearComboPointHolders();
1779 ///----------Pet responses methods-----------------
1780 void SendPetCastFail(uint32 spellid, SpellCastResult msg);
1781 void SendPetActionFeedback (uint8 msg);
1782 void SendPetTalk (uint32 pettalk);
1783 void SendPetAIReaction(uint64 guid);
1784 ///----------End of Pet responses methods----------
1786 void propagateSpeedChange() { GetMotionMaster()->propagateSpeedChange(); }
1788 // reactive attacks
1789 void ClearAllReactives();
1790 void StartReactiveTimer( ReactiveType reactive ) { m_reactiveTimer[reactive] = REACTIVE_TIMER_START;}
1791 void UpdateReactives(uint32 p_time);
1793 // group updates
1794 void UpdateAuraForGroup(uint8 slot);
1796 // pet auras
1797 typedef std::set<PetAura const*> PetAuraSet;
1798 PetAuraSet m_petAuras;
1799 void AddPetAura(PetAura const* petSpell);
1800 void RemovePetAura(PetAura const* petSpell);
1802 // Movement info
1803 MovementInfo m_movementInfo;
1805 protected:
1806 explicit Unit ();
1808 void _UpdateSpells(uint32 time);
1809 void _UpdateAutoRepeatSpell();
1811 uint32 m_attackTimer[MAX_ATTACK];
1813 float m_createStats[MAX_STATS];
1815 AttackerSet m_attackers;
1816 Unit* m_attacking;
1818 DeathState m_deathState;
1820 AuraMap m_Auras;
1821 AuraMap::iterator m_AurasUpdateIterator; // != end() in Unit::m_Auras update and point to next element
1822 AuraList m_deletedAuras; // auras removed while in ApplyModifier and waiting deleted
1824 AuraList m_scAuras; // casted by unit single per-caster auras
1826 typedef std::list<uint64> DynObjectGUIDs;
1827 DynObjectGUIDs m_dynObjGUIDs;
1829 typedef std::list<GameObject*> GameObjectList;
1830 GameObjectList m_gameObj;
1831 bool m_isSorted;
1832 uint32 m_transform;
1834 AuraList m_modAuras[TOTAL_AURAS];
1835 float m_auraModifiersGroup[UNIT_MOD_END][MODIFIER_TYPE_END];
1836 float m_weaponDamage[MAX_ATTACK][2];
1837 bool m_canModifyStats;
1838 //std::list< spellEffectPair > AuraSpells[TOTAL_AURAS]; // TODO: use this if ok for mem
1839 VisibleAuraMap m_visibleAuras;
1841 float m_speed_rate[MAX_MOVE_TYPE];
1843 CharmInfo *m_charmInfo;
1845 virtual SpellSchoolMask GetMeleeDamageSchoolMask() const;
1847 MotionMaster i_motionMaster;
1849 uint32 m_reactiveTimer[MAX_REACTIVE];
1850 uint32 m_regenTimer;
1851 uint32 m_lastManaUseTimer;
1853 uint64 m_InteractionObject;
1855 private:
1856 void CleanupDeletedAuras();
1858 bool IsTriggeredAtSpellProcEvent(Unit *pVictim, Aura* aura, SpellEntry const* procSpell, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, bool isVictim, bool active, SpellProcEventEntry const*& spellProcEvent );
1859 bool HandleDummyAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1860 bool HandleHasteAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1861 bool HandleSpellCritChanceAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1862 bool HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1863 bool HandleOverrideClassScriptAuraProc(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 cooldown);
1864 bool HandleMendingAuraProc(Aura* triggeredByAura);
1866 // player or player's pet
1867 float GetCombatRatingReduction(CombatRating cr) const;
1868 uint32 GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const;
1870 Unit* _GetTotem(TotemSlot slot) const; // for templated function without include need
1872 uint32 m_state; // Even derived shouldn't modify
1873 uint32 m_CombatTimer;
1875 Spell* m_currentSpells[CURRENT_MAX_SPELL];
1876 uint32 m_castCounter; // count casts chain of triggered spells for prevent infinity cast crashes
1878 UnitVisibility m_Visibility;
1880 Diminishing m_Diminishing;
1881 // Manage all Units threatening us
1882 ThreatManager m_ThreatManager;
1883 // Manage all Units that are threatened by us
1884 HostileRefManager m_HostileRefManager;
1886 FollowerRefManager m_FollowingRefManager;
1888 ComboPointHolderSet m_ComboPointHolders;
1890 GuardianPetList m_guardianPets;
1892 uint64 m_TotemSlot[MAX_TOTEM_SLOT];
1895 template<typename Func>
1896 void Unit::CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms)
1898 if(Pet* pet = GetPet())
1899 func(pet);
1901 if (withGuardians)
1903 for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
1904 if(Unit* guardian = Unit::GetUnit(*this,*itr))
1905 func(guardian);
1908 if (withTotems)
1910 for (int i = 0; i < MAX_TOTEM_SLOT; ++i)
1911 if (Unit *totem = _GetTotem(TotemSlot(i)))
1912 func(totem);
1915 if (withCharms)
1916 if(Unit* charm = GetCharm())
1917 func(charm);
1921 template<typename Func>
1922 bool Unit::CheckAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms) const
1924 if (Pet* pet = GetPet())
1925 if (func(pet))
1926 return true;
1928 if (withGuardians)
1930 for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
1931 if (Unit* guardian = Unit::GetUnit(*this,*itr))
1932 if (func(guardian))
1933 return true;
1937 if (withTotems)
1939 for (int i = 0; i < MAX_TOTEM_SLOT; ++i)
1940 if (Unit *totem = _GetTotem(TotemSlot(i)))
1941 if (func(totem))
1942 return true;
1945 if (withCharms)
1946 if(Unit* charm = GetCharm())
1947 if (func(charm))
1948 return true;
1950 return false;
1952 #endif