[9529] Make Player::IsValidPos const
[getmangos.git] / src / game / Unit.h
blob545510b5fe1c01df34354ccdfeeebd1ddc04d315
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), 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 = o;
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
1053 typedef std::set<uint64> GuardianPetList;
1055 // delay time next attack to prevent client attack animation problems
1056 #define ATTACK_DISPLAY_DELAY 200
1057 #define MAX_PLAYER_STEALTH_DETECT_RANGE 45.0f // max distance for detection targets by player
1058 #define MAX_CREATURE_ATTACK_RADIUS 45.0f // max distance for creature aggro (use with CONFIG_FLOAT_RATE_CREATURE_AGGRO)
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, SpellEffectIndex> 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* SelectRandomUnfriendlyTarget(Unit* except = NULL, float radius = ATTACK_DISTANCE) const;
1131 Unit* SelectRandomFriendlyTarget(Unit* except = NULL, float radius = ATTACK_DISTANCE) const;
1132 bool hasNegativeAuraWithInterruptFlag(uint32 flag);
1133 void SendMeleeAttackStop(Unit* victim);
1134 void SendMeleeAttackStart(Unit* pVictim);
1136 void addUnitState(uint32 f) { m_state |= f; }
1137 bool hasUnitState(uint32 f) const { return (m_state & f); }
1138 void clearUnitState(uint32 f) { m_state &= ~f; }
1139 bool CanFreeMove() const
1141 return !hasUnitState(UNIT_STAT_NO_FREE_MOVE) && GetOwnerGUID()==0;
1144 uint32 getLevel() const { return GetUInt32Value(UNIT_FIELD_LEVEL); }
1145 virtual uint32 getLevelForTarget(Unit const* /*target*/) const { return getLevel(); }
1146 void SetLevel(uint32 lvl);
1147 uint8 getRace() const { return GetByteValue(UNIT_FIELD_BYTES_0, 0); }
1148 uint32 getRaceMask() const { return 1 << (getRace()-1); }
1149 uint8 getClass() const { return GetByteValue(UNIT_FIELD_BYTES_0, 1); }
1150 uint32 getClassMask() const { return 1 << (getClass()-1); }
1151 uint8 getGender() const { return GetByteValue(UNIT_FIELD_BYTES_0, 2); }
1153 float GetStat(Stats stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0+stat)); }
1154 void SetStat(Stats stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0+stat, val); }
1155 uint32 GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL) ; }
1156 void SetArmor(int32 val) { SetResistance(SPELL_SCHOOL_NORMAL, val); }
1158 uint32 GetResistance(SpellSchools school) const { return GetUInt32Value(UNIT_FIELD_RESISTANCES+school); }
1159 void SetResistance(SpellSchools school, int32 val) { SetStatInt32Value(UNIT_FIELD_RESISTANCES+school,val); }
1161 uint32 GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH); }
1162 uint32 GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH); }
1163 float GetHealthPercent() const { return (GetHealth()*100.0f) / GetMaxHealth(); }
1164 void SetHealth( uint32 val);
1165 void SetMaxHealth(uint32 val);
1166 void SetHealthPercent(float percent);
1167 int32 ModifyHealth(int32 val);
1169 Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, 3)); }
1170 void setPowerType(Powers power);
1171 uint32 GetPower( Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1 +power); }
1172 uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1+power); }
1173 void SetPower( Powers power, uint32 val);
1174 void SetMaxPower(Powers power, uint32 val);
1175 int32 ModifyPower(Powers power, int32 val);
1176 void ApplyPowerMod(Powers power, uint32 val, bool apply);
1177 void ApplyMaxPowerMod(Powers power, uint32 val, bool apply);
1179 uint32 GetAttackTime(WeaponAttackType att) const { return (uint32)(GetFloatValue(UNIT_FIELD_BASEATTACKTIME+att)/m_modAttackSpeedPct[att]); }
1180 void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val*m_modAttackSpeedPct[att]); }
1181 void ApplyAttackTimePercentMod(WeaponAttackType att,float val, bool apply);
1182 void ApplyCastTimePercentMod(float val, bool apply);
1184 SheathState GetSheath() const { return SheathState(GetByteValue(UNIT_FIELD_BYTES_2, 0)); }
1185 virtual void SetSheath( SheathState sheathed ) { SetByteValue(UNIT_FIELD_BYTES_2, 0, sheathed); }
1187 // faction template id
1188 uint32 getFaction() const { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE); }
1189 void setFaction(uint32 faction) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, faction ); }
1190 FactionTemplateEntry const* getFactionTemplateEntry() const;
1191 bool IsHostileTo(Unit const* unit) const;
1192 bool IsHostileToPlayers() const;
1193 bool IsFriendlyTo(Unit const* unit) const;
1194 bool IsNeutralToAll() const;
1195 bool IsContestedGuard() const
1197 if(FactionTemplateEntry const* entry = getFactionTemplateEntry())
1198 return entry->IsContestedGuardFaction();
1200 return false;
1202 bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP); }
1203 void SetPvP(bool state);
1204 bool IsFFAPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); }
1205 void SetFFAPvP(bool state);
1206 uint32 GetCreatureType() const;
1207 uint32 GetCreatureTypeMask() const
1209 uint32 creatureType = GetCreatureType();
1210 return (creatureType >= 1) ? (1 << (creatureType - 1)) : 0;
1213 uint8 getStandState() const { return GetByteValue(UNIT_FIELD_BYTES_1, 0); }
1214 bool IsSitState() const;
1215 bool IsStandState() const;
1216 void SetStandState(uint8 state);
1218 void SetStandFlags(uint8 flags) { SetByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1219 void RemoveStandFlags(uint8 flags) { RemoveByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1221 bool IsMounted() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); }
1222 uint32 GetMountID() const { return GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID); }
1223 void Mount(uint32 mount, uint32 spellId = 0);
1224 void Unmount();
1226 uint16 GetMaxSkillValueForLevel(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1227 void DealDamageMods(Unit *pVictim, uint32 &damage, uint32* absorb);
1228 uint32 DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss);
1229 int32 DealHeal(Unit *pVictim, uint32 addhealth, SpellEntry const *spellProto, bool critical = false);
1231 void ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 procEx, uint32 amount, WeaponAttackType attType = BASE_ATTACK, SpellEntry const *procSpell = NULL);
1232 void ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage );
1234 void HandleEmoteCommand(uint32 anim_id);
1235 void AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType = BASE_ATTACK, bool extra = false );
1237 float MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const;
1239 void CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *damageInfo, WeaponAttackType attackType = BASE_ATTACK);
1240 void DealMeleeDamage(CalcDamageInfo *damageInfo, bool durabilityLoss);
1242 void CalculateSpellDamage(SpellNonMeleeDamage *damageInfo, int32 damage, SpellEntry const *spellInfo, WeaponAttackType attackType = BASE_ATTACK);
1243 void DealSpellDamage(SpellNonMeleeDamage *damageInfo, bool durabilityLoss);
1245 // player or player's pet resilience (-1%)
1246 float GetMeleeCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_MELEE); }
1247 float GetRangedCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_RANGED); }
1248 float GetSpellCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_SPELL); }
1250 // player or player's pet resilience (-1%)
1251 uint32 GetMeleeCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 2.2f, 33.0f, damage); }
1252 uint32 GetRangedCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_RANGED, 2.2f, 33.0f, damage); }
1253 uint32 GetSpellCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_SPELL, 2.2f, 33.0f, damage); }
1255 // player or player's pet resilience (-1%), cap 100%
1256 uint32 GetMeleeDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1257 uint32 GetRangedDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1258 uint32 GetSpellDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1260 float MeleeSpellMissChance(Unit *pVictim, WeaponAttackType attType, int32 skillDiff, SpellEntry const *spell);
1261 SpellMissInfo MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1262 SpellMissInfo MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1263 SpellMissInfo SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool canReflect = false);
1265 float GetUnitDodgeChance() const;
1266 float GetUnitParryChance() const;
1267 float GetUnitBlockChance() const;
1268 float GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const;
1270 virtual uint32 GetShieldBlockValue() const =0;
1271 uint32 GetUnitMeleeSkill(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1272 uint32 GetDefenseSkillValue(Unit const* target = NULL) const;
1273 uint32 GetWeaponSkillValue(WeaponAttackType attType, Unit const* target = NULL) const;
1274 float GetWeaponProcChance() const;
1275 float GetPPMProcChance(uint32 WeaponSpeed, float PPM) const;
1277 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType) const;
1278 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance) const;
1280 bool isVendor() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR ); }
1281 bool isTrainer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER ); }
1282 bool isQuestGiver() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER ); }
1283 bool isGossip() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP ); }
1284 bool isTaxi() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_FLIGHTMASTER ); }
1285 bool isGuildMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PETITIONER ); }
1286 bool isBattleMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BATTLEMASTER ); }
1287 bool isBanker() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BANKER ); }
1288 bool isInnkeeper() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_INNKEEPER ); }
1289 bool isSpiritHealer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER ); }
1290 bool isSpiritGuide() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITGUIDE ); }
1291 bool isTabardDesigner()const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TABARDDESIGNER ); }
1292 bool isAuctioner() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER ); }
1293 bool isArmorer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_REPAIR ); }
1294 bool isServiceProvider() const
1296 return HasFlag( UNIT_NPC_FLAGS,
1297 UNIT_NPC_FLAG_VENDOR | UNIT_NPC_FLAG_TRAINER | UNIT_NPC_FLAG_FLIGHTMASTER |
1298 UNIT_NPC_FLAG_PETITIONER | UNIT_NPC_FLAG_BATTLEMASTER | UNIT_NPC_FLAG_BANKER |
1299 UNIT_NPC_FLAG_INNKEEPER | UNIT_NPC_FLAG_GUARD | UNIT_NPC_FLAG_SPIRITHEALER |
1300 UNIT_NPC_FLAG_SPIRITGUIDE | UNIT_NPC_FLAG_TABARDDESIGNER | UNIT_NPC_FLAG_AUCTIONEER );
1302 bool isSpiritService() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER | UNIT_NPC_FLAG_SPIRITGUIDE ); }
1304 //Need fix or use this
1305 bool isGuard() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GUARD); }
1307 bool isInFlight() const { return hasUnitState(UNIT_STAT_IN_FLIGHT); }
1309 bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); }
1310 void SetInCombatState(bool PvP, Unit* enemy = NULL);
1311 void SetInCombatWith(Unit* enemy);
1312 void ClearInCombat();
1313 uint32 GetCombatTimer() const { return m_CombatTimer; }
1315 bool HasAuraType(AuraType auraType) const;
1316 bool HasAura(uint32 spellId, SpellEffectIndex effIndex) const
1318 return m_Auras.find(spellEffectPair(spellId, effIndex)) != m_Auras.end();
1320 bool HasAura(uint32 spellId) const;
1322 bool virtual HasSpell(uint32 /*spellID*/) const { return false; }
1324 bool HasStealthAura() const { return HasAuraType(SPELL_AURA_MOD_STEALTH); }
1325 bool HasInvisibilityAura() const { return HasAuraType(SPELL_AURA_MOD_INVISIBILITY); }
1326 bool isFeared() const { return HasAuraType(SPELL_AURA_MOD_FEAR); }
1327 bool isInRoots() const { return HasAuraType(SPELL_AURA_MOD_ROOT); }
1328 bool IsPolymorphed() const;
1330 bool isFrozen() const;
1332 void RemoveSpellbyDamageTaken(AuraType auraType, uint32 damage);
1334 bool isTargetableForAttack(bool inversAlive = false) const;
1335 virtual bool IsInWater() const;
1336 virtual bool IsUnderWater() const;
1337 bool isInAccessablePlaceFor(Creature const* c) const;
1339 void SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, uint32 OverHeal, bool critical = false);
1340 void SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage,Powers powertype);
1341 void EnergizeBySpell(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype);
1342 uint32 SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage);
1343 void CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1344 void CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1345 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);
1346 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);
1347 void CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1348 void CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1350 bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const;
1352 void DeMorph();
1354 void SendAttackStateUpdate(CalcDamageInfo *damageInfo);
1355 void SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount);
1356 void SendSpellNonMeleeDamageLog(SpellNonMeleeDamage *log);
1357 void SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID, uint32 Damage, SpellSchoolMask damageSchoolMask, uint32 AbsorbedDamage, uint32 Resist, bool PhysicalDamage, uint32 Blocked, bool CriticalHit = false);
1358 void SendPeriodicAuraLog(SpellPeriodicAuraLogInfo *pInfo);
1359 void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo);
1361 void NearTeleportTo(float x, float y, float z, float orientation, bool casting = false);
1363 void MonsterMove(float x, float y, float z, uint32 transitTime);
1364 void MonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime = 0);
1366 // recommend use MonsterMove/MonsterMoveWithSpeed for most case that correctly work with movegens
1367 void SendMonsterMove(float x, float y, float z, SplineType type, SplineFlags flags, uint32 Time, Player* player = NULL);
1368 void SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, SplineFlags flags);
1369 void SendMonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime = 0, Player* player = NULL);
1371 void SendHighestThreatUpdate(HostileReference* pHostileReference);
1372 void SendThreatClear();
1373 void SendThreatRemove(HostileReference* pHostileReference);
1374 void SendThreatUpdate();
1376 void BuildHeartBeatMsg( WorldPacket *data ) const;
1378 virtual void MoveOutOfRange(Player &) { };
1380 bool isAlive() const { return (m_deathState == ALIVE); };
1381 bool isDead() const { return ( m_deathState == DEAD || m_deathState == CORPSE ); };
1382 DeathState getDeathState() { return m_deathState; };
1383 virtual void setDeathState(DeathState s); // overwritten in Creature/Player/Pet
1385 uint64 GetOwnerGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMONEDBY); }
1386 void SetOwnerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner); }
1387 uint64 GetCreatorGUID() const { return GetUInt64Value(UNIT_FIELD_CREATEDBY); }
1388 void SetCreatorGUID(uint64 creator) { SetUInt64Value(UNIT_FIELD_CREATEDBY, creator); }
1389 uint64 GetPetGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMON); }
1390 void SetPetGUID(uint64 pet) { SetUInt64Value(UNIT_FIELD_SUMMON, pet); }
1391 uint64 GetCharmerGUID() const { return GetUInt64Value(UNIT_FIELD_CHARMEDBY); }
1392 void SetCharmerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_CHARMEDBY, owner); }
1393 uint64 GetCharmGUID() const { return GetUInt64Value(UNIT_FIELD_CHARM); }
1394 void SetCharmGUID(uint64 charm) { SetUInt64Value(UNIT_FIELD_CHARM, charm); }
1395 uint64 GetTargetGUID() const { return GetUInt64Value(UNIT_FIELD_TARGET); }
1396 void SetTargetGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_TARGET, targetGuid); }
1397 uint64 GetChannelObjectGUID() const { return GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT); }
1398 void SetChannelObjectGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, targetGuid); }
1400 uint64 GetCharmerOrOwnerGUID() const { return GetCharmerGUID() ? GetCharmerGUID() : GetOwnerGUID(); }
1401 uint64 GetCharmerOrOwnerOrOwnGUID() const
1403 if(uint64 guid = GetCharmerOrOwnerGUID())
1404 return guid;
1405 return GetGUID();
1407 bool isCharmedOwnedByPlayerOrPlayer() const { return IS_PLAYER_GUID(GetCharmerOrOwnerOrOwnGUID()); }
1409 Player* GetSpellModOwner();
1411 Unit* GetOwner() const;
1412 Pet* GetPet() const;
1413 Unit* GetCharmer() const;
1414 Unit* GetCharm() const;
1415 void Uncharm();
1416 Unit* GetCharmerOrOwner() const { return GetCharmerGUID() ? GetCharmer() : GetOwner(); }
1417 Unit* GetCharmerOrOwnerOrSelf()
1419 if(Unit* u = GetCharmerOrOwner())
1420 return u;
1422 return this;
1424 bool IsCharmerOrOwnerPlayerOrPlayerItself() const;
1425 Player* GetCharmerOrOwnerPlayerOrPlayerItself();
1426 float GetCombatDistance( const Unit* target ) const;
1428 void SetPet(Pet* pet);
1429 void SetCharm(Unit* pet);
1431 void AddGuardian(Pet* pet);
1432 void RemoveGuardian(Pet* pet);
1433 void RemoveGuardians();
1434 Pet* FindGuardianWithEntry(uint32 entry);
1436 bool isCharmed() const { return GetCharmerGUID() != 0; }
1438 CharmInfo* GetCharmInfo() { return m_charmInfo; }
1439 CharmInfo* InitCharmInfo(Unit* charm);
1441 Pet* CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id = 0);
1443 uint64 const& GetTotemGUID(TotemSlot slot) const { return m_TotemSlot[slot]; }
1444 Totem* GetTotem(TotemSlot slot) const;
1445 bool IsAllTotemSlotsUsed() const;
1447 void _AddTotem(TotemSlot slot, Totem* totem); // only for call from Totem summon code
1448 void _RemoveTotem(Totem* totem); // only for call from Totem class
1450 template<typename Func>
1451 void CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms);
1452 template<typename Func>
1453 bool CheckAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms) const;
1455 bool AddAura(Aura *aur);
1457 // removing specific aura stack
1458 void RemoveAura(Aura* aura, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1459 void RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1460 void RemoveAura(uint32 spellId, SpellEffectIndex effindex, Aura* except = NULL);
1462 // removing specific aura stacks by diff reasons and selections
1463 void RemoveAurasDueToSpell(uint32 spellId, Aura* except = NULL);
1464 void RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId);
1465 void RemoveAurasByCasterSpell(uint32 spellId, uint64 casterGUID);
1466 void RemoveAurasByCasterSpell(uint32 spellId, SpellEffectIndex effindex, uint64 casterGUID);
1467 void RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer);
1468 void RemoveAurasDueToSpellByCancel(uint32 spellId);
1470 // removing unknown aura stacks by diff reasons and selections
1471 void RemoveNotOwnSingleTargetAuras(uint32 newPhase = 0x0);
1472 void RemoveAurasAtMechanicImmunity(uint32 mechMask, uint32 exceptSpellId, bool non_positive = false);
1473 void RemoveSpellsCausingAura(AuraType auraType);
1474 void RemoveRankAurasDueToSpell(uint32 spellId);
1475 bool RemoveNoStackAurasDueToAura(Aura *Aur);
1476 void RemoveAurasWithInterruptFlags(uint32 flags);
1477 void RemoveAurasWithDispelType( DispelType type );
1478 void RemoveAllAuras(AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1479 void RemoveArenaAuras(bool onleave = false);
1480 void RemoveAllAurasOnDeath();
1482 // removing specific aura FROM stack
1483 void RemoveSingleAuraFromStack(uint32 spellId, SpellEffectIndex effindex, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1484 void RemoveSingleAuraFromStack(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1486 // removing specific aura FROM stack by diff reasons and selections
1487 void RemoveSingleSpellAurasFromStack(uint32 spellId, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1488 void RemoveSingleSpellAurasByCasterSpell(uint32 spellId, uint64 casterGUID, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1489 void RemoveSingleAuraByCasterSpell(uint32 spellId, SpellEffectIndex effindex, uint64 casterGUID, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1490 void RemoveSingleAuraDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler);
1492 void DelayAura(uint32 spellId, SpellEffectIndex effindex, int32 delaytime);
1494 float GetResistanceBuffMods(SpellSchools school, bool positive) const { return GetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school ); }
1495 void SetResistanceBuffMods(SpellSchools school, bool positive, float val) { SetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school,val); }
1496 void ApplyResistanceBuffModsMod(SpellSchools school, bool positive, float val, bool apply) { ApplyModSignedFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1497 void ApplyResistanceBuffModsPercentMod(SpellSchools school, bool positive, float val, bool apply) { ApplyPercentModFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1498 void InitStatBuffMods()
1500 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_POSSTAT0+i, 0);
1501 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_NEGSTAT0+i, 0);
1503 void ApplyStatBuffMod(Stats stat, float val, bool apply) { ApplyModSignedFloatValue((val > 0 ? UNIT_FIELD_POSSTAT0+stat : UNIT_FIELD_NEGSTAT0+stat), val, apply); }
1504 void ApplyStatPercentBuffMod(Stats stat, float val, bool apply)
1506 ApplyPercentModFloatValue(UNIT_FIELD_POSSTAT0+stat, val, apply);
1507 ApplyPercentModFloatValue(UNIT_FIELD_NEGSTAT0+stat, val, apply);
1509 void SetCreateStat(Stats stat, float val) { m_createStats[stat] = val; }
1510 void SetCreateHealth(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_HEALTH, val); }
1511 uint32 GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH); }
1512 void SetCreateMana(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_MANA, val); }
1513 uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); }
1514 uint32 GetCreatePowers(Powers power) const;
1515 float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0+stat); }
1516 float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0+stat); }
1517 float GetCreateStat(Stats stat) const { return m_createStats[stat]; }
1519 void SetCurrentCastedSpell(Spell * pSpell);
1520 virtual void ProhibitSpellSchool(SpellSchoolMask /*idSchoolMask*/, uint32 /*unTimeMs*/ ) { }
1521 void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed = true, bool sendAutoRepeatCancelToClient = true);
1522 void FinishSpell(CurrentSpellTypes spellType, bool ok = true);
1524 // set withDelayed to true to account delayed spells as casted
1525 // delayed+channeled spells are always accounted as casted
1526 // we can skip channeled or delayed checks using flags
1527 bool IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled = false, bool skipAutorepeat = false) const;
1529 // set withDelayed to true to interrupt delayed spells too
1530 // delayed+channeled spells are always interrupted
1531 void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid = 0);
1533 Spell* GetCurrentSpell(CurrentSpellTypes spellType) const { return m_currentSpells[spellType]; }
1534 Spell* FindCurrentSpellBySpellId(uint32 spell_id) const;
1536 bool CheckAndIncreaseCastCounter();
1537 void DecreaseCastCounter() { if (m_castCounter) --m_castCounter; }
1539 uint32 m_addDmgOnce;
1540 uint64 m_ObjectSlot[4];
1541 uint32 m_detectInvisibilityMask;
1542 uint32 m_invisibilityMask;
1544 uint32 m_ShapeShiftFormSpellId;
1545 ShapeshiftForm m_form;
1546 bool IsInFeralForm() const { return m_form == FORM_CAT || m_form == FORM_BEAR || m_form == FORM_DIREBEAR; }
1548 float m_modMeleeHitChance;
1549 float m_modRangedHitChance;
1550 float m_modSpellHitChance;
1551 int32 m_baseSpellCritChance;
1553 float m_threatModifier[MAX_SPELL_SCHOOL];
1554 float m_modAttackSpeedPct[3];
1556 // Event handler
1557 EventProcessor m_Events;
1559 // stat system
1560 bool HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply);
1561 void SetModifierValue(UnitMods unitMod, UnitModifierType modifierType, float value) { m_auraModifiersGroup[unitMod][modifierType] = value; }
1562 float GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const;
1563 float GetTotalStatValue(Stats stat) const;
1564 float GetTotalAuraModValue(UnitMods unitMod) const;
1565 SpellSchools GetSpellSchoolByAuraGroup(UnitMods unitMod) const;
1566 Stats GetStatByAuraGroup(UnitMods unitMod) const;
1567 Powers GetPowerTypeByAuraGroup(UnitMods unitMod) const;
1568 bool CanModifyStats() const { return m_canModifyStats; }
1569 void SetCanModifyStats(bool modifyStats) { m_canModifyStats = modifyStats; }
1570 virtual bool UpdateStats(Stats stat) = 0;
1571 virtual bool UpdateAllStats() = 0;
1572 virtual void UpdateResistances(uint32 school) = 0;
1573 virtual void UpdateArmor() = 0;
1574 virtual void UpdateMaxHealth() = 0;
1575 virtual void UpdateMaxPower(Powers power) = 0;
1576 virtual void UpdateAttackPowerAndDamage(bool ranged = false) = 0;
1577 virtual void UpdateDamagePhysical(WeaponAttackType attType) = 0;
1578 float GetTotalAttackPowerValue(WeaponAttackType attType) const;
1579 float GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const;
1580 void SetBaseWeaponDamage(WeaponAttackType attType ,WeaponDamageRange damageRange, float value) { m_weaponDamage[attType][damageRange] = value; }
1582 void SetInFront(Unit const* target);
1583 void SetFacingTo(float ori);
1584 void SetFacingToObject(WorldObject* pObject);
1586 // Visibility system
1587 UnitVisibility GetVisibility() const { return m_Visibility; }
1588 void SetVisibility(UnitVisibility x);
1590 // common function for visibility checks for player/creatures with detection code
1591 bool isVisibleForOrDetect(Unit const* u, WorldObject const* viewPoint, bool detect, bool inVisibleList = false, bool is3dDistance = true) const;
1592 bool canDetectInvisibilityOf(Unit const* u) const;
1593 void SetPhaseMask(uint32 newPhaseMask, bool update);// overwrite WorldObject::SetPhaseMask
1595 // virtual functions for all world objects types
1596 bool isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const;
1597 // function for low level grid visibility checks in player/creature cases
1598 virtual bool IsVisibleInGridForPlayer(Player* pl) const = 0;
1599 bool isInvisibleForAlive() const;
1601 AuraList & GetSingleCastAuras() { return m_scAuras; }
1602 AuraList const& GetSingleCastAuras() const { return m_scAuras; }
1603 SpellImmuneList m_spellImmune[MAX_SPELL_IMMUNITY];
1605 // Threat related methods
1606 bool CanHaveThreatList() const;
1607 void AddThreat(Unit* pVictim, float threat = 0.0f, bool crit = false, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NONE, SpellEntry const *threatSpell = NULL);
1608 float ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL);
1609 void DeleteThreatList();
1610 bool SelectHostileTarget();
1611 void TauntApply(Unit* pVictim);
1612 void TauntFadeOut(Unit *taunter);
1613 ThreatManager& getThreatManager() { return m_ThreatManager; }
1614 ThreatManager const& getThreatManager() const { return m_ThreatManager; }
1615 void addHatedBy(HostileReference* pHostileReference) { m_HostileRefManager.insertFirst(pHostileReference); };
1616 void removeHatedBy(HostileReference* /*pHostileReference*/ ) { /* nothing to do yet */ }
1617 HostileRefManager& getHostileRefManager() { return m_HostileRefManager; }
1619 uint32 GetVisibleAura(uint8 slot)
1621 VisibleAuraMap::const_iterator itr = m_visibleAuras.find(slot);
1622 if(itr != m_visibleAuras.end())
1623 return itr->second;
1624 return 0;
1626 void SetVisibleAura(uint8 slot, uint32 spellid)
1628 if(spellid == 0)
1629 m_visibleAuras.erase(slot);
1630 else
1631 m_visibleAuras[slot] = spellid;
1633 VisibleAuraMap const *GetVisibleAuras() { return &m_visibleAuras; }
1634 uint8 GetVisibleAurasCount() { return m_visibleAuras.size(); }
1636 Aura* GetAura(uint32 spellId, SpellEffectIndex effindex);
1637 Aura* GetAura(AuraType type, uint32 family, uint64 familyFlag, uint32 familyFlag2 = 0, uint64 casterGUID = 0);
1639 AuraMap & GetAuras() { return m_Auras; }
1640 AuraMap const& GetAuras() const { return m_Auras; }
1641 AuraList const& GetAurasByType(AuraType type) const { return m_modAuras[type]; }
1642 void ApplyAuraProcTriggerDamage(Aura* aura, bool apply);
1644 int32 GetTotalAuraModifier(AuraType auratype) const;
1645 float GetTotalAuraMultiplier(AuraType auratype) const;
1646 int32 GetMaxPositiveAuraModifier(AuraType auratype) const;
1647 int32 GetMaxNegativeAuraModifier(AuraType auratype) const;
1649 int32 GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1650 float GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1651 int32 GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1652 int32 GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1654 int32 GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1655 float GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const;
1656 int32 GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1657 int32 GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1659 // misc have plain value but we check it fit to provided values mask (mask & (1 << (misc-1)))
1660 float GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype, uint32 mask) const;
1662 Aura* GetDummyAura(uint32 spell_id) const;
1664 uint32 m_AuraFlags;
1666 uint32 GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID); }
1667 void SetDisplayId(uint32 modelId);
1668 uint32 GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
1669 void SetNativeDisplayId(uint32 modelId) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, modelId); }
1670 void setTransForm(uint32 spellid) { m_transform = spellid;}
1671 uint32 getTransForm() const { return m_transform;}
1673 DynamicObject* GetDynObject(uint32 spellId, SpellEffectIndex effIndex);
1674 DynamicObject* GetDynObject(uint32 spellId);
1675 void AddDynObject(DynamicObject* dynObj);
1676 void RemoveDynObject(uint32 spellid);
1677 void RemoveDynObjectWithGUID(uint64 guid) { m_dynObjGUIDs.remove(guid); }
1678 void RemoveAllDynObjects();
1680 GameObject* GetGameObject(uint32 spellId) const;
1681 void AddGameObject(GameObject* gameObj);
1682 void RemoveGameObject(GameObject* gameObj, bool del);
1683 void RemoveGameObject(uint32 spellid, bool del);
1684 void RemoveAllGameObjects();
1686 uint32 CalculateDamage(WeaponAttackType attType, bool normalized);
1687 float GetAPMultiplier(WeaponAttackType attType, bool normalized);
1688 void ModifyAuraState(AuraState flag, bool apply);
1689 bool HasAuraState(AuraState flag) const { return HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); }
1690 bool HasAuraStateForCaster(AuraState flag, uint64 caster) const;
1691 void UnsummonAllTotems();
1692 Unit* SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo = NULL);
1693 int32 SpellBaseDamageBonus(SpellSchoolMask schoolMask);
1694 int32 SpellBaseHealingBonus(SpellSchoolMask schoolMask);
1695 int32 SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1696 int32 SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1697 uint32 SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 damage, DamageEffectType damagetype, uint32 stack = 1);
1698 int32 SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, int32 healamount, DamageEffectType damagetype, uint32 stack = 1);
1699 bool isSpellBlocked(Unit *pVictim, SpellEntry const *spellProto, WeaponAttackType attackType = BASE_ATTACK);
1700 bool isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType = BASE_ATTACK);
1701 uint32 SpellCriticalDamageBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1702 uint32 SpellCriticalHealingBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1704 void SetLastManaUse()
1706 if (GetTypeId() == TYPEID_PLAYER && !IsUnderLastManaUseEffect())
1707 RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_REGENERATE_POWER);
1709 m_lastManaUseTimer = 5000;
1711 bool IsUnderLastManaUseEffect() const { return m_lastManaUseTimer; }
1713 uint32 GetRegenTimer() const { return m_regenTimer; }
1715 void SetContestedPvP(Player *attackedPlayer = NULL);
1717 uint32 MeleeDamageBonus(Unit *pVictim, uint32 damage, WeaponAttackType attType, SpellEntry const *spellProto = NULL, DamageEffectType damagetype = DIRECT_DAMAGE, uint32 stack =1);
1718 uint32 GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime );
1720 void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply);
1721 void ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply);
1722 virtual bool IsImmunedToSpell(SpellEntry const* spellInfo);
1723 // redefined in Creature
1724 bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask);
1725 virtual bool IsImmunedToSpellEffect(SpellEntry const* spellInfo, SpellEffectIndex index) const;
1726 // redefined in Creature
1728 uint32 CalcArmorReducedDamage(Unit* pVictim, const uint32 damage);
1729 void CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist, bool canReflect = false);
1731 void UpdateWalkMode(Unit* source, bool self = true);
1732 void UpdateSpeed(UnitMoveType mtype, bool forced);
1733 float GetSpeed( UnitMoveType mtype ) const;
1734 float GetSpeedRate( UnitMoveType mtype ) const { return m_speed_rate[mtype]; }
1735 void SetSpeedRate(UnitMoveType mtype, float rate, bool forced = false);
1737 void SetHover(bool on);
1738 bool isHover() const { return HasAuraType(SPELL_AURA_HOVER); }
1740 void KnockBackFrom(Unit* target, float horizontalSpeed, float verticalSpeed);
1742 void _RemoveAllAuraMods();
1743 void _ApplyAllAuraMods();
1745 int32 CalculateSpellDamage(SpellEntry const* spellProto, SpellEffectIndex effect_index, int32 basePoints, Unit const* target);
1747 uint32 CalcNotIgnoreAbsorbDamage( uint32 damage, SpellSchoolMask damageSchoolMask, SpellEntry const* spellInfo = NULL);
1748 uint32 CalcNotIgnoreDamageRedunction( uint32 damage, SpellSchoolMask damageSchoolMask);
1749 int32 CalculateSpellDuration(SpellEntry const* spellProto, SpellEffectIndex effect_index, Unit const* target);
1750 float CalculateLevelPenalty(SpellEntry const* spellProto) const;
1752 void addFollower(FollowerReference* pRef) { m_FollowingRefManager.insertFirst(pRef); }
1753 void removeFollower(FollowerReference* /*pRef*/ ) { /* nothing to do yet */ }
1754 static Unit* GetUnit(WorldObject const& object, uint64 guid);
1756 MotionMaster* GetMotionMaster() { return &i_motionMaster; }
1758 bool IsStopped() const { return !(hasUnitState(UNIT_STAT_MOVING)); }
1759 void StopMoving();
1761 void SetFeared(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0, uint32 time = 0);
1762 void SetConfused(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);
1763 void SetFeignDeath(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);
1765 void AddComboPointHolder(uint32 lowguid) { m_ComboPointHolders.insert(lowguid); }
1766 void RemoveComboPointHolder(uint32 lowguid) { m_ComboPointHolders.erase(lowguid); }
1767 void ClearComboPointHolders();
1769 ///----------Pet responses methods-----------------
1770 void SendPetCastFail(uint32 spellid, SpellCastResult msg);
1771 void SendPetActionFeedback (uint8 msg);
1772 void SendPetTalk (uint32 pettalk);
1773 void SendPetAIReaction(uint64 guid);
1774 ///----------End of Pet responses methods----------
1776 void propagateSpeedChange() { GetMotionMaster()->propagateSpeedChange(); }
1778 // reactive attacks
1779 void ClearAllReactives();
1780 void StartReactiveTimer( ReactiveType reactive ) { m_reactiveTimer[reactive] = REACTIVE_TIMER_START;}
1781 void UpdateReactives(uint32 p_time);
1783 // group updates
1784 void UpdateAuraForGroup(uint8 slot);
1786 // pet auras
1787 typedef std::set<PetAura const*> PetAuraSet;
1788 PetAuraSet m_petAuras;
1789 void AddPetAura(PetAura const* petSpell);
1790 void RemovePetAura(PetAura const* petSpell);
1792 // Movement info
1793 MovementInfo m_movementInfo;
1795 protected:
1796 explicit Unit ();
1798 void _UpdateSpells(uint32 time);
1799 void _UpdateAutoRepeatSpell();
1801 uint32 m_attackTimer[MAX_ATTACK];
1803 float m_createStats[MAX_STATS];
1805 AttackerSet m_attackers;
1806 Unit* m_attacking;
1808 DeathState m_deathState;
1810 AuraMap m_Auras;
1811 AuraMap::iterator m_AurasUpdateIterator; // != end() in Unit::m_Auras update and point to next element
1812 AuraList m_deletedAuras; // auras removed while in ApplyModifier and waiting deleted
1814 AuraList m_scAuras; // casted by unit single per-caster auras
1816 typedef std::list<uint64> DynObjectGUIDs;
1817 DynObjectGUIDs m_dynObjGUIDs;
1819 typedef std::list<GameObject*> GameObjectList;
1820 GameObjectList m_gameObj;
1821 bool m_isSorted;
1822 uint32 m_transform;
1824 AuraList m_modAuras[TOTAL_AURAS];
1825 float m_auraModifiersGroup[UNIT_MOD_END][MODIFIER_TYPE_END];
1826 float m_weaponDamage[MAX_ATTACK][2];
1827 bool m_canModifyStats;
1828 //std::list< spellEffectPair > AuraSpells[TOTAL_AURAS]; // TODO: use this if ok for mem
1829 VisibleAuraMap m_visibleAuras;
1831 float m_speed_rate[MAX_MOVE_TYPE];
1833 CharmInfo *m_charmInfo;
1835 virtual SpellSchoolMask GetMeleeDamageSchoolMask() const;
1837 MotionMaster i_motionMaster;
1839 uint32 m_reactiveTimer[MAX_REACTIVE];
1840 uint32 m_regenTimer;
1841 uint32 m_lastManaUseTimer;
1843 uint64 m_InteractionObject;
1845 private:
1846 void CleanupDeletedAuras();
1848 bool IsTriggeredAtSpellProcEvent(Unit *pVictim, Aura* aura, SpellEntry const* procSpell, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, bool isVictim, bool active, SpellProcEventEntry const*& spellProcEvent );
1849 bool HandleDummyAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1850 bool HandleHasteAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1851 bool HandleSpellCritChanceAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1852 bool HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1853 bool HandleOverrideClassScriptAuraProc(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 cooldown);
1854 bool HandleMendingAuraProc(Aura* triggeredByAura);
1856 // player or player's pet
1857 float GetCombatRatingReduction(CombatRating cr) const;
1858 uint32 GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const;
1860 Unit* _GetTotem(TotemSlot slot) const; // for templated function without include need
1862 uint32 m_state; // Even derived shouldn't modify
1863 uint32 m_CombatTimer;
1865 Spell* m_currentSpells[CURRENT_MAX_SPELL];
1866 uint32 m_castCounter; // count casts chain of triggered spells for prevent infinity cast crashes
1868 UnitVisibility m_Visibility;
1870 Diminishing m_Diminishing;
1871 // Manage all Units threatening us
1872 ThreatManager m_ThreatManager;
1873 // Manage all Units that are threatened by us
1874 HostileRefManager m_HostileRefManager;
1876 FollowerRefManager m_FollowingRefManager;
1878 ComboPointHolderSet m_ComboPointHolders;
1880 GuardianPetList m_guardianPets;
1882 uint64 m_TotemSlot[MAX_TOTEM_SLOT];
1885 template<typename Func>
1886 void Unit::CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms)
1888 if(Pet* pet = GetPet())
1889 func(pet);
1891 if (withGuardians)
1893 for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
1894 if(Unit* guardian = Unit::GetUnit(*this,*itr))
1895 func(guardian);
1898 if (withTotems)
1900 for (int i = 0; i < MAX_TOTEM_SLOT; ++i)
1901 if (Unit *totem = _GetTotem(TotemSlot(i)))
1902 func(totem);
1905 if (withCharms)
1906 if(Unit* charm = GetCharm())
1907 func(charm);
1911 template<typename Func>
1912 bool Unit::CheckAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms) const
1914 if (Pet* pet = GetPet())
1915 if (func(pet))
1916 return true;
1918 if (withGuardians)
1920 for(GuardianPetList::const_iterator itr = m_guardianPets.begin(); itr != m_guardianPets.end(); ++itr)
1921 if (Unit* guardian = Unit::GetUnit(*this,*itr))
1922 if (func(guardian))
1923 return true;
1927 if (withTotems)
1929 for (int i = 0; i < MAX_TOTEM_SLOT; ++i)
1930 if (Unit *totem = _GetTotem(TotemSlot(i)))
1931 if (func(totem))
1932 return true;
1935 if (withCharms)
1936 if(Unit* charm = GetCharm())
1937 if (func(charm))
1938 return true;
1940 return false;
1942 #endif