[9033] Fixed percent mana regneration from spell 53228 and ranks buff.
[getmangos.git] / src / game / Unit.h
blob6699167594df7a20c011f9da49beb659a00da7d2
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef __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 flag 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 // high byte (3 from 0..3) of UNIT_FIELD_BYTES_2
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 // low byte ( 0 from 0..3 ) of UNIT_FIELD_BYTES_2
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 (1 from 0..3) of UNIT_FIELD_BYTES_2
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 (2 from 0..3) of UNIT_FIELD_BYTES_2
224 enum UnitRename
226 UNIT_RENAME_NOT_ALLOWED = 0x02,
227 UNIT_RENAME_ALLOWED = 0x03
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;
303 struct SpellImmune
305 uint32 type;
306 uint32 spellId;
309 typedef std::list<SpellImmune> SpellImmuneList;
311 enum UnitModifierType
313 BASE_VALUE = 0,
314 BASE_PCT = 1,
315 TOTAL_VALUE = 2,
316 TOTAL_PCT = 3,
317 MODIFIER_TYPE_END = 4
320 enum WeaponDamageRange
322 MINDAMAGE,
323 MAXDAMAGE
326 enum DamageTypeToSchool
328 RESISTANCE,
329 DAMAGE_DEALT,
330 DAMAGE_TAKEN
333 enum AuraRemoveMode
335 AURA_REMOVE_BY_DEFAULT,
336 AURA_REMOVE_BY_STACK, // at replace by similar aura
337 AURA_REMOVE_BY_CANCEL,
338 AURA_REMOVE_BY_DISPEL,
339 AURA_REMOVE_BY_DEATH,
340 AURA_REMOVE_BY_DELETE, // use for speedup and prevent unexpected effects at player logout/pet unsummon (must be used _only_ after save), delete.
343 enum UnitMods
345 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.
346 UNIT_MOD_STAT_AGILITY,
347 UNIT_MOD_STAT_STAMINA,
348 UNIT_MOD_STAT_INTELLECT,
349 UNIT_MOD_STAT_SPIRIT,
350 UNIT_MOD_HEALTH,
351 UNIT_MOD_MANA, // UNIT_MOD_MANA..UNIT_MOD_RUNIC_POWER must be in existed order, it's accessed by index values of Powers enum.
352 UNIT_MOD_RAGE,
353 UNIT_MOD_FOCUS,
354 UNIT_MOD_ENERGY,
355 UNIT_MOD_HAPPINESS,
356 UNIT_MOD_RUNE,
357 UNIT_MOD_RUNIC_POWER,
358 UNIT_MOD_ARMOR, // UNIT_MOD_ARMOR..UNIT_MOD_RESISTANCE_ARCANE must be in existed order, it's accessed by index values of SpellSchools enum.
359 UNIT_MOD_RESISTANCE_HOLY,
360 UNIT_MOD_RESISTANCE_FIRE,
361 UNIT_MOD_RESISTANCE_NATURE,
362 UNIT_MOD_RESISTANCE_FROST,
363 UNIT_MOD_RESISTANCE_SHADOW,
364 UNIT_MOD_RESISTANCE_ARCANE,
365 UNIT_MOD_ATTACK_POWER,
366 UNIT_MOD_ATTACK_POWER_RANGED,
367 UNIT_MOD_DAMAGE_MAINHAND,
368 UNIT_MOD_DAMAGE_OFFHAND,
369 UNIT_MOD_DAMAGE_RANGED,
370 UNIT_MOD_END,
371 // synonyms
372 UNIT_MOD_STAT_START = UNIT_MOD_STAT_STRENGTH,
373 UNIT_MOD_STAT_END = UNIT_MOD_STAT_SPIRIT + 1,
374 UNIT_MOD_RESISTANCE_START = UNIT_MOD_ARMOR,
375 UNIT_MOD_RESISTANCE_END = UNIT_MOD_RESISTANCE_ARCANE + 1,
376 UNIT_MOD_POWER_START = UNIT_MOD_MANA,
377 UNIT_MOD_POWER_END = UNIT_MOD_RUNIC_POWER + 1
380 enum BaseModGroup
382 CRIT_PERCENTAGE,
383 RANGED_CRIT_PERCENTAGE,
384 OFFHAND_CRIT_PERCENTAGE,
385 SHIELD_BLOCK_VALUE,
386 BASEMOD_END
389 enum BaseModType
391 FLAT_MOD,
392 PCT_MOD
395 #define MOD_END (PCT_MOD+1)
397 enum DeathState
399 ALIVE = 0,
400 JUST_DIED = 1,
401 CORPSE = 2,
402 DEAD = 3,
403 JUST_ALIVED = 4,
404 DEAD_FALLING= 5
407 enum UnitState
409 UNIT_STAT_DIED = 0x0001,
410 UNIT_STAT_MELEE_ATTACKING = 0x0002, // player is melee attacking someone
411 //UNIT_STAT_MELEE_ATTACK_BY = 0x0004, // player is melee attack by someone
412 UNIT_STAT_STUNNED = 0x0008,
413 UNIT_STAT_ROAMING = 0x0010,
414 UNIT_STAT_CHASE = 0x0020,
415 UNIT_STAT_SEARCHING = 0x0040,
416 UNIT_STAT_FLEEING = 0x0080,
417 UNIT_STAT_MOVING = (UNIT_STAT_ROAMING | UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING),
418 UNIT_STAT_IN_FLIGHT = 0x0100, // player is in flight mode
419 UNIT_STAT_FOLLOW = 0x0200,
420 UNIT_STAT_ROOT = 0x0400,
421 UNIT_STAT_CONFUSED = 0x0800,
422 UNIT_STAT_DISTRACTED = 0x1000,
423 UNIT_STAT_ISOLATED = 0x2000, // area auras do not affect other players
424 UNIT_STAT_ATTACK_PLAYER = 0x4000,
425 UNIT_STAT_ALL_STATE = 0xffff //(UNIT_STAT_STOPPED | UNIT_STAT_MOVING | UNIT_STAT_IN_COMBAT | UNIT_STAT_IN_FLIGHT)
428 enum UnitMoveType
430 MOVE_WALK = 0,
431 MOVE_RUN = 1,
432 MOVE_RUN_BACK = 2,
433 MOVE_SWIM = 3,
434 MOVE_SWIM_BACK = 4,
435 MOVE_TURN_RATE = 5,
436 MOVE_FLIGHT = 6,
437 MOVE_FLIGHT_BACK = 7,
438 MOVE_PITCH_RATE = 8
441 #define MAX_MOVE_TYPE 9
443 extern float baseMoveSpeed[MAX_MOVE_TYPE];
445 enum CombatRating
447 CR_WEAPON_SKILL = 0,
448 CR_DEFENSE_SKILL = 1,
449 CR_DODGE = 2,
450 CR_PARRY = 3,
451 CR_BLOCK = 4,
452 CR_HIT_MELEE = 5,
453 CR_HIT_RANGED = 6,
454 CR_HIT_SPELL = 7,
455 CR_CRIT_MELEE = 8,
456 CR_CRIT_RANGED = 9,
457 CR_CRIT_SPELL = 10,
458 CR_HIT_TAKEN_MELEE = 11,
459 CR_HIT_TAKEN_RANGED = 12,
460 CR_HIT_TAKEN_SPELL = 13,
461 CR_CRIT_TAKEN_MELEE = 14,
462 CR_CRIT_TAKEN_RANGED = 15,
463 CR_CRIT_TAKEN_SPELL = 16,
464 CR_HASTE_MELEE = 17,
465 CR_HASTE_RANGED = 18,
466 CR_HASTE_SPELL = 19,
467 CR_WEAPON_SKILL_MAINHAND = 20,
468 CR_WEAPON_SKILL_OFFHAND = 21,
469 CR_WEAPON_SKILL_RANGED = 22,
470 CR_EXPERTISE = 23,
471 CR_ARMOR_PENETRATION = 24
474 #define MAX_COMBAT_RATING 25
476 enum DamageEffectType
478 DIRECT_DAMAGE = 0, // used for normal weapon damage (not for class abilities or spells)
479 SPELL_DIRECT_DAMAGE = 1, // spell/class abilities damage
480 DOT = 2,
481 HEAL = 3,
482 NODAMAGE = 4, // used also in case when damage applied to health but not applied to spell channelInterruptFlags/etc
483 SELF_DAMAGE = 5
486 /// internal used flags for marking special auras - for example some dummy-auras
487 enum UnitAuraFlags
489 UNIT_AURAFLAG_ALIVE_INVISIBLE = 0x1, // aura which makes unit invisible for alive
492 enum UnitVisibility
494 VISIBILITY_OFF = 0, // absolute, not detectable, GM-like, can see all other
495 VISIBILITY_ON = 1,
496 VISIBILITY_GROUP_STEALTH = 2, // detect chance, seen and can see group members
497 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)
498 VISIBILITY_GROUP_NO_DETECT = 4, // state just at stealth apply for update Grid state. Don't remove, otherwise stealth spells will break
499 VISIBILITY_RESPAWN = 5 // special totally not detectable visibility for force delete object at respawn command
502 // Value masks for UNIT_FIELD_FLAGS
503 enum UnitFlags
505 UNIT_FLAG_UNK_0 = 0x00000001,
506 UNIT_FLAG_NON_ATTACKABLE = 0x00000002, // not attackable
507 UNIT_FLAG_DISABLE_MOVE = 0x00000004,
508 UNIT_FLAG_PVP_ATTACKABLE = 0x00000008, // allow apply pvp rules to attackable state in addition to faction dependent state
509 UNIT_FLAG_RENAME = 0x00000010,
510 UNIT_FLAG_PREPARATION = 0x00000020, // don't take reagents for spells with SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
511 UNIT_FLAG_UNK_6 = 0x00000040,
512 UNIT_FLAG_NOT_ATTACKABLE_1 = 0x00000080, // ?? (UNIT_FLAG_PVP_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1) is NON_PVP_ATTACKABLE
513 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.
514 UNIT_FLAG_UNK_9 = 0x00000200, // 3.0.3 - makes you unable to attack everything
515 UNIT_FLAG_LOOTING = 0x00000400, // loot animation
516 UNIT_FLAG_PET_IN_COMBAT = 0x00000800, // in combat?, 2.0.8
517 UNIT_FLAG_PVP = 0x00001000, // changed in 3.0.3
518 UNIT_FLAG_SILENCED = 0x00002000, // silenced, 2.1.1
519 UNIT_FLAG_UNK_14 = 0x00004000, // 2.0.8
520 UNIT_FLAG_UNK_15 = 0x00008000,
521 UNIT_FLAG_UNK_16 = 0x00010000, // removes attackable icon
522 UNIT_FLAG_PACIFIED = 0x00020000, // 3.0.3 ok
523 UNIT_FLAG_STUNNED = 0x00040000, // 3.0.3 ok
524 UNIT_FLAG_IN_COMBAT = 0x00080000,
525 UNIT_FLAG_TAXI_FLIGHT = 0x00100000, // disable casting at client side spell not allowed by taxi flight (mounted?), probably used with 0x4 flag
526 UNIT_FLAG_DISARMED = 0x00200000, // 3.0.3, disable melee spells casting..., "Required melee weapon" added to melee spells tooltip.
527 UNIT_FLAG_CONFUSED = 0x00400000,
528 UNIT_FLAG_FLEEING = 0x00800000,
529 UNIT_FLAG_PLAYER_CONTROLLED = 0x01000000, // used in spell Eyes of the Beast for pet... let attack by controlled creature
530 UNIT_FLAG_NOT_SELECTABLE = 0x02000000,
531 UNIT_FLAG_SKINNABLE = 0x04000000,
532 UNIT_FLAG_MOUNT = 0x08000000,
533 UNIT_FLAG_UNK_28 = 0x10000000,
534 UNIT_FLAG_UNK_29 = 0x20000000, // used in Feing Death spell
535 UNIT_FLAG_SHEATHE = 0x40000000,
536 UNIT_FLAG_UNK_31 = 0x80000000 // set skinnable icon and also changes color of portrait
539 // Value masks for UNIT_FIELD_FLAGS_2
540 enum UnitFlags2
542 UNIT_FLAG2_FEIGN_DEATH = 0x00000001,
543 UNIT_FLAG2_UNK1 = 0x00000002, // Hide unit model (show only player equip)
544 UNIT_FLAG2_COMPREHEND_LANG = 0x00000008,
545 UNIT_FLAG2_FORCE_MOVE = 0x00000040,
546 UNIT_FLAG2_REGENERATE_POWER = 0x00000800
549 /// Non Player Character flags
550 enum NPCFlags
552 UNIT_NPC_FLAG_NONE = 0x00000000,
553 UNIT_NPC_FLAG_GOSSIP = 0x00000001, // 100%
554 UNIT_NPC_FLAG_QUESTGIVER = 0x00000002, // guessed, probably ok
555 UNIT_NPC_FLAG_UNK1 = 0x00000004,
556 UNIT_NPC_FLAG_UNK2 = 0x00000008,
557 UNIT_NPC_FLAG_TRAINER = 0x00000010, // 100%
558 UNIT_NPC_FLAG_TRAINER_CLASS = 0x00000020, // 100%
559 UNIT_NPC_FLAG_TRAINER_PROFESSION = 0x00000040, // 100%
560 UNIT_NPC_FLAG_VENDOR = 0x00000080, // 100%
561 UNIT_NPC_FLAG_VENDOR_AMMO = 0x00000100, // 100%, general goods vendor
562 UNIT_NPC_FLAG_VENDOR_FOOD = 0x00000200, // 100%
563 UNIT_NPC_FLAG_VENDOR_POISON = 0x00000400, // guessed
564 UNIT_NPC_FLAG_VENDOR_REAGENT = 0x00000800, // 100%
565 UNIT_NPC_FLAG_REPAIR = 0x00001000, // 100%
566 UNIT_NPC_FLAG_FLIGHTMASTER = 0x00002000, // 100%
567 UNIT_NPC_FLAG_SPIRITHEALER = 0x00004000, // guessed
568 UNIT_NPC_FLAG_SPIRITGUIDE = 0x00008000, // guessed
569 UNIT_NPC_FLAG_INNKEEPER = 0x00010000, // 100%
570 UNIT_NPC_FLAG_BANKER = 0x00020000, // 100%
571 UNIT_NPC_FLAG_PETITIONER = 0x00040000, // 100% 0xC0000 = guild petitions, 0x40000 = arena team petitions
572 UNIT_NPC_FLAG_TABARDDESIGNER = 0x00080000, // 100%
573 UNIT_NPC_FLAG_BATTLEMASTER = 0x00100000, // 100%
574 UNIT_NPC_FLAG_AUCTIONEER = 0x00200000, // 100%
575 UNIT_NPC_FLAG_STABLEMASTER = 0x00400000, // 100%
576 UNIT_NPC_FLAG_GUILD_BANKER = 0x00800000, // cause client to send 997 opcode
577 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
578 UNIT_NPC_FLAG_GUARD = 0x10000000, // custom flag for guards
581 // used in SMSG_MONSTER_MOVE
582 enum MonsterMovementFlags
584 MONSTER_MOVE_NONE = 0x00000000,
585 MONSTER_MOVE_FORWARD = 0x00000001,
586 MONSTER_MOVE_BACKWARD = 0x00000002,
587 MONSTER_MOVE_STRAFE_LEFT = 0x00000004,
588 MONSTER_MOVE_STRAFE_RIGHT = 0x00000008,
589 MONSTER_MOVE_LEFT = 0x00000010, // turn
590 MONSTER_MOVE_RIGHT = 0x00000020, // turn
591 MONSTER_MOVE_PITCH_UP = 0x00000040,
592 MONSTER_MOVE_PITCH_DOWN = 0x00000080,
593 MONSTER_MOVE_TELEPORT = 0x00000100,
594 MONSTER_MOVE_TELEPORT2 = 0x00000200,
595 MONSTER_MOVE_LEVITATING = 0x00000400,
596 MONSTER_MOVE_UNK1 = 0x00000800, // float+uint32
597 MONSTER_MOVE_WALK = 0x00001000, // run2?
598 MONSTER_MOVE_SPLINE = 0x00002000, // spline n*(float x,y,z)
599 // 0x4000, 0x8000, 0x10000, 0x20000 run
600 MONSTER_MOVE_SPLINE2 = 0x00040000, // spline n*(float x,y,z)
601 MONSTER_MOVE_UNK2 = 0x00080000, // used for flying mobs
602 MONSTER_MOVE_UNK3 = 0x00100000, // used for flying mobs
603 MONSTER_MOVE_UNK4 = 0x00200000, // uint8+uint32
604 MONSTER_MOVE_UNK5 = 0x00400000, // run in place, then teleport to final point
605 MONSTER_MOVE_UNK6 = 0x00800000, // teleport
606 MONSTER_MOVE_UNK7 = 0x01000000, // run
607 MONSTER_MOVE_FLY = 0x02000000, // swimming/flying (depends on mob?)
608 MONSTER_MOVE_UNK9 = 0x04000000, // run
609 MONSTER_MOVE_UNK10 = 0x08000000, // run
610 MONSTER_MOVE_UNK11 = 0x10000000, // run
611 MONSTER_MOVE_UNK12 = 0x20000000, // run
612 MONSTER_MOVE_UNK13 = 0x40000000, // levitating
614 // masks
615 MONSTER_MOVE_SPLINE_FLY = 0x00003000, // fly by points
618 enum DiminishingLevels
620 DIMINISHING_LEVEL_1 = 0,
621 DIMINISHING_LEVEL_2 = 1,
622 DIMINISHING_LEVEL_3 = 2,
623 DIMINISHING_LEVEL_IMMUNE = 3
626 struct DiminishingReturn
628 DiminishingReturn(DiminishingGroup group, uint32 t, uint32 count)
629 : DRGroup(group), stack(0), hitTime(t), hitCount(count)
632 DiminishingGroup DRGroup:16;
633 uint16 stack:16;
634 uint32 hitTime;
635 uint32 hitCount;
638 enum MeleeHitOutcome
640 MELEE_HIT_EVADE, MELEE_HIT_MISS, MELEE_HIT_DODGE, MELEE_HIT_BLOCK, MELEE_HIT_PARRY,
641 MELEE_HIT_GLANCING, MELEE_HIT_CRIT, MELEE_HIT_CRUSHING, MELEE_HIT_NORMAL
644 struct CleanDamage
646 CleanDamage(uint32 _damage, WeaponAttackType _attackType, MeleeHitOutcome _hitOutCome) :
647 damage(_damage), attackType(_attackType), hitOutCome(_hitOutCome) {}
649 uint32 damage;
650 WeaponAttackType attackType;
651 MeleeHitOutcome hitOutCome;
654 // Struct for use in Unit::CalculateMeleeDamage
655 // Need create structure like in SMSG_ATTACKERSTATEUPDATE opcode
656 struct CalcDamageInfo
658 Unit *attacker; // Attacker
659 Unit *target; // Target for damage
660 SpellSchoolMask damageSchoolMask;
661 uint32 damage;
662 uint32 absorb;
663 uint32 resist;
664 uint32 blocked_amount;
665 uint32 HitInfo;
666 uint32 TargetState;
667 // Helper
668 WeaponAttackType attackType; //
669 uint32 procAttacker;
670 uint32 procVictim;
671 uint32 procEx;
672 uint32 cleanDamage; // Used only for rage calculation
673 MeleeHitOutcome hitOutCome; // TODO: remove this field (need use TargetState)
676 // Spell damage info structure based on structure sending in SMSG_SPELLNONMELEEDAMAGELOG opcode
677 struct SpellNonMeleeDamage{
678 SpellNonMeleeDamage(Unit *_attacker, Unit *_target, uint32 _SpellID, uint32 _schoolMask)
679 : target(_target), attacker(_attacker), SpellID(_SpellID), damage(0), overkill(0), schoolMask(_schoolMask),
680 absorb(0), resist(0), physicalLog(false), unused(false), blocked(0), HitInfo(0), cleanDamage(0)
683 Unit *target;
684 Unit *attacker;
685 uint32 SpellID;
686 uint32 damage;
687 uint32 overkill;
688 uint32 schoolMask;
689 uint32 absorb;
690 uint32 resist;
691 bool physicalLog;
692 bool unused;
693 uint32 blocked;
694 uint32 HitInfo;
695 // Used for help
696 uint32 cleanDamage;
699 struct SpellPeriodicAuraLogInfo
701 SpellPeriodicAuraLogInfo(Aura *_aura, uint32 _damage, uint32 _overDamage, uint32 _absorb, uint32 _resist, float _multiplier, bool _critical = false)
702 : aura(_aura), damage(_damage), overDamage(_overDamage), absorb(_absorb), resist(_resist), multiplier(_multiplier), critical(_critical) {}
704 Aura *aura;
705 uint32 damage;
706 uint32 overDamage; // overkill/overheal
707 uint32 absorb;
708 uint32 resist;
709 float multiplier;
710 bool critical;
713 uint32 createProcExtendMask(SpellNonMeleeDamage *damageInfo, SpellMissInfo missCondition);
715 #define MAX_DECLINED_NAME_CASES 5
717 struct DeclinedName
719 std::string name[MAX_DECLINED_NAME_CASES];
722 enum CurrentSpellTypes
724 CURRENT_MELEE_SPELL = 0,
725 CURRENT_GENERIC_SPELL = 1,
726 CURRENT_AUTOREPEAT_SPELL = 2,
727 CURRENT_CHANNELED_SPELL = 3
730 #define CURRENT_FIRST_NON_MELEE_SPELL 1
731 #define CURRENT_MAX_SPELL 4
734 enum ActiveStates
736 ACT_PASSIVE = 0x01, // 0x01 - passive
737 ACT_DISABLED = 0x81, // 0x80 - castable
738 ACT_ENABLED = 0xC1, // 0x40 | 0x80 - auto cast + castable
739 ACT_COMMAND = 0x07, // 0x01 | 0x02 | 0x04
740 ACT_REACTION = 0x06, // 0x02 | 0x04
741 ACT_DECIDE = 0x00 // custom
744 enum ReactStates
746 REACT_PASSIVE = 0,
747 REACT_DEFENSIVE = 1,
748 REACT_AGGRESSIVE = 2
751 enum CommandStates
753 COMMAND_STAY = 0,
754 COMMAND_FOLLOW = 1,
755 COMMAND_ATTACK = 2,
756 COMMAND_ABANDON = 3
759 #define UNIT_ACTION_BUTTON_ACTION(X) (uint32(X) & 0x00FFFFFF)
760 #define UNIT_ACTION_BUTTON_TYPE(X) ((uint32(X) & 0xFF000000) >> 24)
761 #define MAX_UNIT_ACTION_BUTTON_ACTION_VALUE (0x00FFFFFF+1)
762 #define MAKE_UNIT_ACTION_BUTTON(A,T) (uint32(A) | (uint32(T) << 24))
764 struct UnitActionBarEntry
766 UnitActionBarEntry() : packedData(uint32(ACT_DISABLED) << 24) {}
768 uint32 packedData;
770 // helper
771 ActiveStates GetType() const { return ActiveStates(UNIT_ACTION_BUTTON_TYPE(packedData)); }
772 uint32 GetAction() const { return UNIT_ACTION_BUTTON_ACTION(packedData); }
773 bool IsActionBarForSpell() const
775 ActiveStates Type = GetType();
776 return Type == ACT_DISABLED || Type == ACT_ENABLED || Type == ACT_PASSIVE;
779 void SetActionAndType(uint32 action, ActiveStates type)
781 packedData = MAKE_UNIT_ACTION_BUTTON(action,type);
784 void SetType(ActiveStates type)
786 packedData = MAKE_UNIT_ACTION_BUTTON(UNIT_ACTION_BUTTON_ACTION(packedData),type);
789 void SetAction(uint32 action)
791 packedData = (packedData & 0xFF000000) | UNIT_ACTION_BUTTON_ACTION(action);
795 typedef UnitActionBarEntry CharmSpellEntry;
797 enum ActionBarIndex
799 ACTION_BAR_INDEX_START = 0,
800 ACTION_BAR_INDEX_PET_SPELL_START = 3,
801 ACTION_BAR_INDEX_PET_SPELL_END = 7,
802 ACTION_BAR_INDEX_END = 10,
805 #define MAX_UNIT_ACTION_BAR_INDEX (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START)
807 struct CharmInfo
809 public:
810 explicit CharmInfo(Unit* unit);
811 uint32 GetPetNumber() const { return m_petnumber; }
812 void SetPetNumber(uint32 petnumber, bool statwindow);
814 void SetCommandState(CommandStates st) { m_CommandState = st; }
815 CommandStates GetCommandState() { return m_CommandState; }
816 bool HasCommandState(CommandStates state) { return (m_CommandState == state); }
817 void SetReactState(ReactStates st) { m_reactState = st; }
818 ReactStates GetReactState() { return m_reactState; }
819 bool HasReactState(ReactStates state) { return (m_reactState == state); }
821 void InitPossessCreateSpells();
822 void InitCharmCreateSpells();
823 void InitPetActionBar();
824 void InitEmptyActionBar();
826 //return true if successful
827 bool AddSpellToActionBar(uint32 spellid, ActiveStates newstate = ACT_DECIDE);
828 bool RemoveSpellFromActionBar(uint32 spell_id);
829 void LoadPetActionBar(const std::string& data);
830 void BuildActionBar(WorldPacket* data);
831 void SetSpellAutocast(uint32 spell_id, bool state);
832 void SetActionBar(uint8 index, uint32 spellOrAction,ActiveStates type)
834 PetActionBar[index].SetActionAndType(spellOrAction,type);
836 UnitActionBarEntry const* GetActionBarEntry(uint8 index) const { return &(PetActionBar[index]); }
838 void ToggleCreatureAutocast(uint32 spellid, bool apply);
840 CharmSpellEntry* GetCharmSpell(uint8 index) { return &(m_charmspells[index]); }
841 private:
843 Unit* m_unit;
844 UnitActionBarEntry PetActionBar[MAX_UNIT_ACTION_BAR_INDEX];
845 CharmSpellEntry m_charmspells[CREATURE_MAX_SPELLS];
846 CommandStates m_CommandState;
847 ReactStates m_reactState;
848 uint32 m_petnumber;
851 // for clearing special attacks
852 #define REACTIVE_TIMER_START 4000
854 enum ReactiveType
856 REACTIVE_DEFENSE = 0,
857 REACTIVE_HUNTER_PARRY = 1,
858 REACTIVE_OVERPOWER = 2
861 #define MAX_REACTIVE 3
862 #define MAX_TOTEM 4
864 typedef std::set<uint64> GuardianPetList;
866 // delay time next attack to prevent client attack animation problems
867 #define ATTACK_DISPLAY_DELAY 200
868 #define MAX_PLAYER_STEALTH_DETECT_RANGE 45.0f // max distance for detection targets by player
870 // Regeneration defines
871 #define REGEN_TIME_FULL 2000 // For this time difference is computed regen value
872 #define REGEN_TIME_PRECISE 500 // Used in Spell::CheckPower for precise regeneration in spell cast time
874 struct SpellProcEventEntry; // used only privately
876 class MANGOS_DLL_SPEC Unit : public WorldObject
878 public:
879 typedef std::set<Unit*> AttackerSet;
880 typedef std::pair<uint32, uint8> spellEffectPair;
881 typedef std::multimap< spellEffectPair, Aura*> AuraMap;
882 typedef std::list<Aura *> AuraList;
883 typedef std::list<DiminishingReturn> Diminishing;
884 typedef std::set<uint32> ComboPointHolderSet;
885 typedef std::map<uint8, uint32> VisibleAuraMap;
887 virtual ~Unit ( );
889 void AddToWorld();
890 void RemoveFromWorld();
892 void CleanupsBeforeDelete(); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units)
894 DiminishingLevels GetDiminishing(DiminishingGroup group);
895 void IncrDiminishing(DiminishingGroup group);
896 void ApplyDiminishingToDuration(DiminishingGroup group, int32 &duration,Unit* caster, DiminishingLevels Level, int32 limitduration);
897 void ApplyDiminishingAura(DiminishingGroup group, bool apply);
898 void ClearDiminishings() { m_Diminishing.clear(); }
900 virtual void Update( uint32 time );
902 void setAttackTimer(WeaponAttackType type, uint32 time) { m_attackTimer[type] = time; }
903 void resetAttackTimer(WeaponAttackType type = BASE_ATTACK);
904 uint32 getAttackTimer(WeaponAttackType type) const { return m_attackTimer[type]; }
905 bool isAttackReady(WeaponAttackType type = BASE_ATTACK) const { return m_attackTimer[type] == 0; }
906 bool haveOffhandWeapon() const;
907 bool canReachWithAttack(Unit *pVictim) const;
908 uint32 m_extraAttacks;
910 void _addAttacker(Unit *pAttacker) // must be called only from Unit::Attack(Unit*)
912 AttackerSet::const_iterator itr = m_attackers.find(pAttacker);
913 if(itr == m_attackers.end())
914 m_attackers.insert(pAttacker);
916 void _removeAttacker(Unit *pAttacker) // must be called only from Unit::AttackStop()
918 m_attackers.erase(pAttacker);
920 Unit * getAttackerForHelper() // If someone wants to help, who to give them
922 if (getVictim() != NULL)
923 return getVictim();
925 if (!m_attackers.empty())
926 return *(m_attackers.begin());
928 return NULL;
930 bool Attack(Unit *victim, bool meleeAttack);
931 void CastStop(uint32 except_spellid = 0);
932 bool AttackStop(bool targetSwitch = false);
933 void RemoveAllAttackers();
934 AttackerSet const& getAttackers() const { return m_attackers; }
935 bool isAttackingPlayer() const;
936 Unit* getVictim() const { return m_attacking; }
937 void CombatStop(bool includingCast = false);
938 void CombatStopWithPets(bool includingCast = false);
939 void StopAttackFaction(uint32 faction_id);
940 Unit* SelectNearbyTarget(Unit* except = NULL) const;
941 bool hasNegativeAuraWithInterruptFlag(uint32 flag);
942 void SendMeleeAttackStop(Unit* victim);
943 void SendMeleeAttackStart(Unit* pVictim);
945 void addUnitState(uint32 f) { m_state |= f; }
946 bool hasUnitState(const uint32 f) const { return (m_state & f); }
947 void clearUnitState(uint32 f) { m_state &= ~f; }
948 bool CanFreeMove() const
950 return !hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_FLEEING | UNIT_STAT_IN_FLIGHT |
951 UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DISTRACTED | UNIT_STAT_DIED ) && GetOwnerGUID()==0;
954 uint32 getLevel() const { return GetUInt32Value(UNIT_FIELD_LEVEL); }
955 virtual uint32 getLevelForTarget(Unit const* /*target*/) const { return getLevel(); }
956 void SetLevel(uint32 lvl);
957 uint8 getRace() const { return GetByteValue(UNIT_FIELD_BYTES_0, 0); }
958 uint32 getRaceMask() const { return 1 << (getRace()-1); }
959 uint8 getClass() const { return GetByteValue(UNIT_FIELD_BYTES_0, 1); }
960 uint32 getClassMask() const { return 1 << (getClass()-1); }
961 uint8 getGender() const { return GetByteValue(UNIT_FIELD_BYTES_0, 2); }
963 float GetStat(Stats stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0+stat)); }
964 void SetStat(Stats stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0+stat, val); }
965 uint32 GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL) ; }
966 void SetArmor(int32 val) { SetResistance(SPELL_SCHOOL_NORMAL, val); }
968 uint32 GetResistance(SpellSchools school) const { return GetUInt32Value(UNIT_FIELD_RESISTANCES+school); }
969 void SetResistance(SpellSchools school, int32 val) { SetStatInt32Value(UNIT_FIELD_RESISTANCES+school,val); }
971 uint32 GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH); }
972 uint32 GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH); }
973 void SetHealth( uint32 val);
974 void SetMaxHealth(uint32 val);
975 int32 ModifyHealth(int32 val);
977 Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, 3)); }
978 void setPowerType(Powers power);
979 uint32 GetPower( Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1 +power); }
980 uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1+power); }
981 void SetPower( Powers power, uint32 val);
982 void SetMaxPower(Powers power, uint32 val);
983 int32 ModifyPower(Powers power, int32 val);
984 void ApplyPowerMod(Powers power, uint32 val, bool apply);
985 void ApplyMaxPowerMod(Powers power, uint32 val, bool apply);
987 uint32 GetAttackTime(WeaponAttackType att) const { return (uint32)(GetFloatValue(UNIT_FIELD_BASEATTACKTIME+att)/m_modAttackSpeedPct[att]); }
988 void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val*m_modAttackSpeedPct[att]); }
989 void ApplyAttackTimePercentMod(WeaponAttackType att,float val, bool apply);
990 void ApplyCastTimePercentMod(float val, bool apply);
992 SheathState GetSheath() const { return SheathState(GetByteValue(UNIT_FIELD_BYTES_2, 0)); }
993 virtual void SetSheath( SheathState sheathed ) { SetByteValue(UNIT_FIELD_BYTES_2, 0, sheathed); }
995 // faction template id
996 uint32 getFaction() const { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE); }
997 void setFaction(uint32 faction) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, faction ); }
998 FactionTemplateEntry const* getFactionTemplateEntry() const;
999 bool IsHostileTo(Unit const* unit) const;
1000 bool IsHostileToPlayers() const;
1001 bool IsFriendlyTo(Unit const* unit) const;
1002 bool IsNeutralToAll() const;
1003 bool IsContestedGuard() const
1005 if(FactionTemplateEntry const* entry = getFactionTemplateEntry())
1006 return entry->IsContestedGuardFaction();
1008 return false;
1010 bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP); }
1011 void SetPvP(bool state);
1012 uint32 GetCreatureType() const;
1013 uint32 GetCreatureTypeMask() const
1015 uint32 creatureType = GetCreatureType();
1016 return (creatureType >= 1) ? (1 << (creatureType - 1)) : 0;
1019 uint8 getStandState() const { return GetByteValue(UNIT_FIELD_BYTES_1, 0); }
1020 bool IsSitState() const;
1021 bool IsStandState() const;
1022 void SetStandState(uint8 state);
1024 void SetStandFlags(uint8 flags) { SetByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1025 void RemoveStandFlags(uint8 flags) { RemoveByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1027 bool IsMounted() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); }
1028 uint32 GetMountID() const { return GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID); }
1029 void Mount(uint32 mount);
1030 void Unmount();
1032 uint16 GetMaxSkillValueForLevel(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1033 void DealDamageMods(Unit *pVictim, uint32 &damage, uint32* absorb);
1034 uint32 DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss);
1035 int32 DealHeal(Unit *pVictim, uint32 addhealth, SpellEntry const *spellProto, bool critical = false);
1037 void ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 procEx, uint32 amount, WeaponAttackType attType = BASE_ATTACK, SpellEntry const *procSpell = NULL);
1038 void ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage );
1040 void HandleEmoteCommand(uint32 anim_id);
1041 void AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType = BASE_ATTACK, bool extra = false );
1043 float MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const;
1045 void CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *damageInfo, WeaponAttackType attackType = BASE_ATTACK);
1046 void DealMeleeDamage(CalcDamageInfo *damageInfo, bool durabilityLoss);
1048 void CalculateSpellDamage(SpellNonMeleeDamage *damageInfo, int32 damage, SpellEntry const *spellInfo, WeaponAttackType attackType = BASE_ATTACK);
1049 void DealSpellDamage(SpellNonMeleeDamage *damageInfo, bool durabilityLoss);
1051 // player or player's pet resilience (-1%)
1052 float GetMeleeCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_MELEE); }
1053 float GetRangedCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_RANGED); }
1054 float GetSpellCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_SPELL); }
1056 // player or player's pet resilience (-1%)
1057 uint32 GetMeleeCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 2.2f, 33.0f, damage); }
1058 uint32 GetRangedCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_RANGED, 2.2f, 33.0f, damage); }
1059 uint32 GetSpellCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_SPELL, 2.2f, 33.0f, damage); }
1061 // player or player's pet resilience (-1%), cap 100%
1062 uint32 GetMeleeDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1063 uint32 GetRangedDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1064 uint32 GetSpellDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
1066 float MeleeSpellMissChance(Unit *pVictim, WeaponAttackType attType, int32 skillDiff, SpellEntry const *spell);
1067 SpellMissInfo MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1068 SpellMissInfo MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1069 SpellMissInfo SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool canReflect = false);
1071 float GetUnitDodgeChance() const;
1072 float GetUnitParryChance() const;
1073 float GetUnitBlockChance() const;
1074 float GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const;
1076 virtual uint32 GetShieldBlockValue() const =0;
1077 uint32 GetUnitMeleeSkill(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1078 uint32 GetDefenseSkillValue(Unit const* target = NULL) const;
1079 uint32 GetWeaponSkillValue(WeaponAttackType attType, Unit const* target = NULL) const;
1080 float GetWeaponProcChance() const;
1081 float GetPPMProcChance(uint32 WeaponSpeed, float PPM) const;
1083 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType) const;
1084 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance) const;
1086 bool isVendor() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR ); }
1087 bool isTrainer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER ); }
1088 bool isQuestGiver() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER ); }
1089 bool isGossip() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP ); }
1090 bool isTaxi() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_FLIGHTMASTER ); }
1091 bool isGuildMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PETITIONER ); }
1092 bool isBattleMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BATTLEMASTER ); }
1093 bool isBanker() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BANKER ); }
1094 bool isInnkeeper() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_INNKEEPER ); }
1095 bool isSpiritHealer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER ); }
1096 bool isSpiritGuide() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITGUIDE ); }
1097 bool isTabardDesigner()const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TABARDDESIGNER ); }
1098 bool isAuctioner() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER ); }
1099 bool isArmorer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_REPAIR ); }
1100 bool isServiceProvider() const
1102 return HasFlag( UNIT_NPC_FLAGS,
1103 UNIT_NPC_FLAG_VENDOR | UNIT_NPC_FLAG_TRAINER | UNIT_NPC_FLAG_FLIGHTMASTER |
1104 UNIT_NPC_FLAG_PETITIONER | UNIT_NPC_FLAG_BATTLEMASTER | UNIT_NPC_FLAG_BANKER |
1105 UNIT_NPC_FLAG_INNKEEPER | UNIT_NPC_FLAG_GUARD | UNIT_NPC_FLAG_SPIRITHEALER |
1106 UNIT_NPC_FLAG_SPIRITGUIDE | UNIT_NPC_FLAG_TABARDDESIGNER | UNIT_NPC_FLAG_AUCTIONEER );
1108 bool isSpiritService() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER | UNIT_NPC_FLAG_SPIRITGUIDE ); }
1110 //Need fix or use this
1111 bool isGuard() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GUARD); }
1113 bool isInFlight() const { return hasUnitState(UNIT_STAT_IN_FLIGHT); }
1115 bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); }
1116 void SetInCombatState(bool PvP, Unit* enemy = NULL);
1117 void SetInCombatWith(Unit* enemy);
1118 void ClearInCombat();
1119 uint32 GetCombatTimer() const { return m_CombatTimer; }
1121 bool HasAuraType(AuraType auraType) const;
1122 bool HasAura(uint32 spellId, uint32 effIndex) const
1124 return m_Auras.find(spellEffectPair(spellId, effIndex)) != m_Auras.end();
1126 bool HasAura(uint32 spellId) const;
1128 bool virtual HasSpell(uint32 /*spellID*/) const { return false; }
1130 bool HasStealthAura() const { return HasAuraType(SPELL_AURA_MOD_STEALTH); }
1131 bool HasInvisibilityAura() const { return HasAuraType(SPELL_AURA_MOD_INVISIBILITY); }
1132 bool isFeared() const { return HasAuraType(SPELL_AURA_MOD_FEAR); }
1133 bool isInRoots() const { return HasAuraType(SPELL_AURA_MOD_ROOT); }
1134 bool IsPolymorphed() const;
1136 bool isFrozen() const;
1138 void RemoveSpellbyDamageTaken(AuraType auraType, uint32 damage);
1140 bool isTargetableForAttack(bool inversAlive = false) const;
1141 virtual bool IsInWater() const;
1142 virtual bool IsUnderWater() const;
1143 bool isInAccessablePlaceFor(Creature const* c) const;
1145 void SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, uint32 OverHeal, bool critical = false);
1146 void SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage,Powers powertype);
1147 void EnergizeBySpell(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype);
1148 uint32 SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage);
1149 void CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1150 void CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1151 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);
1152 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);
1153 void CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1154 void CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1156 bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const;
1158 void DeMorph();
1160 void SendAttackStateUpdate(CalcDamageInfo *damageInfo);
1161 void SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount);
1162 void SendSpellNonMeleeDamageLog(SpellNonMeleeDamage *log);
1163 void SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID, uint32 Damage, SpellSchoolMask damageSchoolMask, uint32 AbsorbedDamage, uint32 Resist, bool PhysicalDamage, uint32 Blocked, bool CriticalHit = false);
1164 void SendPeriodicAuraLog(SpellPeriodicAuraLogInfo *pInfo);
1165 void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo);
1167 void NearTeleportTo(float x, float y, float z, float orientation, bool casting = false);
1169 void SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, MonsterMovementFlags flags, uint32 Time, Player* player = NULL);
1170 void SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, MonsterMovementFlags flags);
1172 void SendHighestThreatUpdate(HostileReference* pHostileReference);
1173 void SendThreatClear();
1174 void SendThreatRemove(HostileReference* pHostileReference);
1175 void SendThreatUpdate();
1177 void BuildHeartBeatMsg( WorldPacket *data ) const;
1179 virtual void MoveOutOfRange(Player &) { };
1181 bool isAlive() const { return (m_deathState == ALIVE); };
1182 bool isDead() const { return ( m_deathState == DEAD || m_deathState == CORPSE ); };
1183 DeathState getDeathState() { return m_deathState; };
1184 virtual void setDeathState(DeathState s); // overwrited in Creature/Player/Pet
1186 uint64 GetOwnerGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMONEDBY); }
1187 void SetOwnerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner); }
1188 uint64 GetCreatorGUID() const { return GetUInt64Value(UNIT_FIELD_CREATEDBY); }
1189 void SetCreatorGUID(uint64 creator) { SetUInt64Value(UNIT_FIELD_CREATEDBY, creator); }
1190 uint64 GetPetGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMON); }
1191 void SetPetGUID(uint64 pet) { SetUInt64Value(UNIT_FIELD_SUMMON, pet); }
1192 uint64 GetCharmerGUID() const { return GetUInt64Value(UNIT_FIELD_CHARMEDBY); }
1193 void SetCharmerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_CHARMEDBY, owner); }
1194 uint64 GetCharmGUID() const { return GetUInt64Value(UNIT_FIELD_CHARM); }
1195 void SetCharmGUID(uint64 charm) { SetUInt64Value(UNIT_FIELD_CHARM, charm); }
1196 uint64 GetTargetGUID() const { return GetUInt64Value(UNIT_FIELD_TARGET); }
1197 void SetTargetGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_TARGET, targetGuid); }
1198 uint64 GetChannelObjectGUID() const { return GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT); }
1199 void SetChannelObjectGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, targetGuid); }
1201 uint64 GetCharmerOrOwnerGUID() const { return GetCharmerGUID() ? GetCharmerGUID() : GetOwnerGUID(); }
1202 uint64 GetCharmerOrOwnerOrOwnGUID() const
1204 if(uint64 guid = GetCharmerOrOwnerGUID())
1205 return guid;
1206 return GetGUID();
1208 bool isCharmedOwnedByPlayerOrPlayer() const { return IS_PLAYER_GUID(GetCharmerOrOwnerOrOwnGUID()); }
1210 Player* GetSpellModOwner();
1212 Unit* GetOwner() const;
1213 Pet* GetPet() const;
1214 Unit* GetCharmer() const;
1215 Unit* GetCharm() const;
1216 void Uncharm();
1217 Unit* GetCharmerOrOwner() const { return GetCharmerGUID() ? GetCharmer() : GetOwner(); }
1218 Unit* GetCharmerOrOwnerOrSelf()
1220 if(Unit* u = GetCharmerOrOwner())
1221 return u;
1223 return this;
1225 Player* GetCharmerOrOwnerPlayerOrPlayerItself();
1226 float GetCombatDistance( const Unit* target ) const;
1228 void SetPet(Pet* pet);
1229 void SetCharm(Unit* pet);
1231 void AddGuardian(Pet* pet);
1232 void RemoveGuardian(Pet* pet);
1233 void RemoveGuardians();
1234 Pet* FindGuardianWithEntry(uint32 entry);
1236 bool isCharmed() const { return GetCharmerGUID() != 0; }
1238 CharmInfo* GetCharmInfo() { return m_charmInfo; }
1239 CharmInfo* InitCharmInfo(Unit* charm);
1241 Pet* CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id = 0);
1243 bool AddAura(Aura *aur);
1245 // removing specific aura stack
1246 void RemoveAura(Aura* aura, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1247 void RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1248 void RemoveAura(uint32 spellId, uint32 effindex, Aura* except = NULL);
1250 // removing specific aura stacks by diff reasons and selections
1251 void RemoveAurasDueToSpell(uint32 spellId, Aura* except = NULL);
1252 void RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId);
1253 void RemoveAurasByCasterSpell(uint32 spellId, uint64 casterGUID);
1254 void RemoveAurasByCasterSpell(uint32 spellId, uint32 effindex, uint64 casterGUID);
1255 void RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer);
1256 void RemoveAurasDueToSpellByCancel(uint32 spellId);
1258 // removing unknown aura stacks by diff reasons and selections
1259 void RemoveNotOwnSingleTargetAuras(uint32 newPhase = 0x0);
1260 void RemoveAurasAtMechanicImmunity(uint32 mechMask, uint32 exceptSpellId, bool non_positive = false);
1261 void RemoveSpellsCausingAura(AuraType auraType);
1262 void RemoveRankAurasDueToSpell(uint32 spellId);
1263 bool RemoveNoStackAurasDueToAura(Aura *Aur);
1264 void RemoveAurasWithInterruptFlags(uint32 flags);
1265 void RemoveAurasWithDispelType( DispelType type );
1266 void RemoveAllAuras(AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1267 void RemoveArenaAuras(bool onleave = false);
1268 void RemoveAllAurasOnDeath();
1270 // removing specific aura FROM stack
1271 void RemoveSingleAuraFromStack(uint32 spellId, uint32 effindex, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1272 void RemoveSingleAuraFromStack(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1274 // removing specific aura FROM stack by diff reasons and selections
1275 void RemoveSingleSpellAurasFromStack(uint32 spellId, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1276 void RemoveSingleSpellAurasByCasterSpell(uint32 spellId, uint64 casterGUID, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1277 void RemoveSingleAuraByCasterSpell(uint32 spellId, uint32 effindex, uint64 casterGUID, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1278 void RemoveSingleAuraDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler);
1280 void DelayAura(uint32 spellId, uint32 effindex, int32 delaytime);
1282 float GetResistanceBuffMods(SpellSchools school, bool positive) const { return GetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school ); }
1283 void SetResistanceBuffMods(SpellSchools school, bool positive, float val) { SetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school,val); }
1284 void ApplyResistanceBuffModsMod(SpellSchools school, bool positive, float val, bool apply) { ApplyModSignedFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1285 void ApplyResistanceBuffModsPercentMod(SpellSchools school, bool positive, float val, bool apply) { ApplyPercentModFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1286 void InitStatBuffMods()
1288 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_POSSTAT0+i, 0);
1289 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_NEGSTAT0+i, 0);
1291 void ApplyStatBuffMod(Stats stat, float val, bool apply) { ApplyModSignedFloatValue((val > 0 ? UNIT_FIELD_POSSTAT0+stat : UNIT_FIELD_NEGSTAT0+stat), val, apply); }
1292 void ApplyStatPercentBuffMod(Stats stat, float val, bool apply)
1294 ApplyPercentModFloatValue(UNIT_FIELD_POSSTAT0+stat, val, apply);
1295 ApplyPercentModFloatValue(UNIT_FIELD_NEGSTAT0+stat, val, apply);
1297 void SetCreateStat(Stats stat, float val) { m_createStats[stat] = val; }
1298 void SetCreateHealth(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_HEALTH, val); }
1299 uint32 GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH); }
1300 void SetCreateMana(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_MANA, val); }
1301 uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); }
1302 uint32 GetCreatePowers(Powers power) const;
1303 float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0+stat); }
1304 float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0+stat); }
1305 float GetCreateStat(Stats stat) const { return m_createStats[stat]; }
1307 void SetCurrentCastedSpell(Spell * pSpell);
1308 virtual void ProhibitSpellScholl(SpellSchoolMask /*idSchoolMask*/, uint32 /*unTimeMs*/ ) { }
1309 void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed = true);
1310 void FinishSpell(CurrentSpellTypes spellType, bool ok = true);
1312 // set withDelayed to true to account delayed spells as casted
1313 // delayed+channeled spells are always accounted as casted
1314 // we can skip channeled or delayed checks using flags
1315 bool IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled = false, bool skipAutorepeat = false) const;
1317 // set withDelayed to true to interrupt delayed spells too
1318 // delayed+channeled spells are always interrupted
1319 void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid = 0);
1321 Spell* GetCurrentSpell(CurrentSpellTypes spellType) const { return m_currentSpells[spellType]; }
1322 Spell* FindCurrentSpellBySpellId(uint32 spell_id) const;
1324 uint32 m_addDmgOnce;
1325 uint64 m_TotemSlot[MAX_TOTEM];
1326 uint64 m_ObjectSlot[4];
1327 uint32 m_detectInvisibilityMask;
1328 uint32 m_invisibilityMask;
1330 uint32 m_ShapeShiftFormSpellId;
1331 ShapeshiftForm m_form;
1332 bool IsInFeralForm() const { return m_form == FORM_CAT || m_form == FORM_BEAR || m_form == FORM_DIREBEAR; }
1334 float m_modMeleeHitChance;
1335 float m_modRangedHitChance;
1336 float m_modSpellHitChance;
1337 int32 m_baseSpellCritChance;
1339 float m_threatModifier[MAX_SPELL_SCHOOL];
1340 float m_modAttackSpeedPct[3];
1342 // Event handler
1343 EventProcessor m_Events;
1345 // stat system
1346 bool HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply);
1347 void SetModifierValue(UnitMods unitMod, UnitModifierType modifierType, float value) { m_auraModifiersGroup[unitMod][modifierType] = value; }
1348 float GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const;
1349 float GetTotalStatValue(Stats stat) const;
1350 float GetTotalAuraModValue(UnitMods unitMod) const;
1351 SpellSchools GetSpellSchoolByAuraGroup(UnitMods unitMod) const;
1352 Stats GetStatByAuraGroup(UnitMods unitMod) const;
1353 Powers GetPowerTypeByAuraGroup(UnitMods unitMod) const;
1354 bool CanModifyStats() const { return m_canModifyStats; }
1355 void SetCanModifyStats(bool modifyStats) { m_canModifyStats = modifyStats; }
1356 virtual bool UpdateStats(Stats stat) = 0;
1357 virtual bool UpdateAllStats() = 0;
1358 virtual void UpdateResistances(uint32 school) = 0;
1359 virtual void UpdateArmor() = 0;
1360 virtual void UpdateMaxHealth() = 0;
1361 virtual void UpdateMaxPower(Powers power) = 0;
1362 virtual void UpdateAttackPowerAndDamage(bool ranged = false) = 0;
1363 virtual void UpdateDamagePhysical(WeaponAttackType attType) = 0;
1364 float GetTotalAttackPowerValue(WeaponAttackType attType) const;
1365 float GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const;
1366 void SetBaseWeaponDamage(WeaponAttackType attType ,WeaponDamageRange damageRange, float value) { m_weaponDamage[attType][damageRange] = value; }
1368 void SetInFront(Unit const* target);
1369 void SetFacingToObject(WorldObject* pObject);
1371 // Visibility system
1372 UnitVisibility GetVisibility() const { return m_Visibility; }
1373 void SetVisibility(UnitVisibility x);
1375 // common function for visibility checks for player/creatures with detection code
1376 bool isVisibleForOrDetect(Unit const* u, WorldObject const* viewPoint, bool detect, bool inVisibleList = false, bool is3dDistance = true) const;
1377 bool canDetectInvisibilityOf(Unit const* u) const;
1378 void SetPhaseMask(uint32 newPhaseMask, bool update);// overwrite WorldObject::SetPhaseMask
1380 // virtual functions for all world objects types
1381 bool isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const;
1382 // function for low level grid visibility checks in player/creature cases
1383 virtual bool IsVisibleInGridForPlayer(Player* pl) const = 0;
1384 bool isInvisibleForAlive() const;
1386 AuraList & GetSingleCastAuras() { return m_scAuras; }
1387 AuraList const& GetSingleCastAuras() const { return m_scAuras; }
1388 SpellImmuneList m_spellImmune[MAX_SPELL_IMMUNITY];
1390 // Threat related methods
1391 bool CanHaveThreatList() const;
1392 void AddThreat(Unit* pVictim, float threat = 0.0f, bool crit = false, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NONE, SpellEntry const *threatSpell = NULL);
1393 float ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL);
1394 void DeleteThreatList();
1395 bool SelectHostileTarget();
1396 void TauntApply(Unit* pVictim);
1397 void TauntFadeOut(Unit *taunter);
1398 ThreatManager& getThreatManager() { return m_ThreatManager; }
1399 ThreatManager const& getThreatManager() const { return m_ThreatManager; }
1400 void addHatedBy(HostileReference* pHostileReference) { m_HostileRefManager.insertFirst(pHostileReference); };
1401 void removeHatedBy(HostileReference* /*pHostileReference*/ ) { /* nothing to do yet */ }
1402 HostileRefManager& getHostileRefManager() { return m_HostileRefManager; }
1404 uint32 GetVisibleAura(uint8 slot)
1406 VisibleAuraMap::const_iterator itr = m_visibleAuras.find(slot);
1407 if(itr != m_visibleAuras.end())
1408 return itr->second;
1409 return 0;
1411 void SetVisibleAura(uint8 slot, uint32 spellid)
1413 if(spellid == 0)
1414 m_visibleAuras.erase(slot);
1415 else
1416 m_visibleAuras[slot] = spellid;
1418 VisibleAuraMap const *GetVisibleAuras() { return &m_visibleAuras; }
1419 uint8 GetVisibleAurasCount() { return m_visibleAuras.size(); }
1421 Aura* GetAura(uint32 spellId, uint32 effindex);
1422 Aura* GetAura(AuraType type, uint32 family, uint64 familyFlag, uint32 familyFlag2 = 0, uint64 casterGUID = 0);
1424 AuraMap & GetAuras() { return m_Auras; }
1425 AuraMap const& GetAuras() const { return m_Auras; }
1426 AuraList const& GetAurasByType(AuraType type) const { return m_modAuras[type]; }
1427 void ApplyAuraProcTriggerDamage(Aura* aura, bool apply);
1429 int32 GetTotalAuraModifier(AuraType auratype) const;
1430 float GetTotalAuraMultiplier(AuraType auratype) const;
1431 int32 GetMaxPositiveAuraModifier(AuraType auratype) const;
1432 int32 GetMaxNegativeAuraModifier(AuraType auratype) const;
1434 int32 GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1435 float GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1436 int32 GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1437 int32 GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1439 int32 GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1440 float GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const;
1441 int32 GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1442 int32 GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1444 // misc have plain value but we check it fit to provided values mask (mask & (1 << (misc-1)))
1445 float GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype, uint32 mask) const;
1447 Aura* GetDummyAura(uint32 spell_id) const;
1449 uint32 m_AuraFlags;
1451 uint32 GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID); }
1452 void SetDisplayId(uint32 modelId);
1453 uint32 GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
1454 void SetNativeDisplayId(uint32 modelId) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, modelId); }
1455 void setTransForm(uint32 spellid) { m_transform = spellid;}
1456 uint32 getTransForm() const { return m_transform;}
1458 DynamicObject* GetDynObject(uint32 spellId, uint32 effIndex);
1459 DynamicObject* GetDynObject(uint32 spellId);
1460 void AddDynObject(DynamicObject* dynObj);
1461 void RemoveDynObject(uint32 spellid);
1462 void RemoveDynObjectWithGUID(uint64 guid) { m_dynObjGUIDs.remove(guid); }
1463 void RemoveAllDynObjects();
1465 GameObject* GetGameObject(uint32 spellId) const;
1466 void AddGameObject(GameObject* gameObj);
1467 void RemoveGameObject(GameObject* gameObj, bool del);
1468 void RemoveGameObject(uint32 spellid, bool del);
1469 void RemoveAllGameObjects();
1471 uint32 CalculateDamage(WeaponAttackType attType, bool normalized);
1472 float GetAPMultiplier(WeaponAttackType attType, bool normalized);
1473 void ModifyAuraState(AuraState flag, bool apply);
1474 bool HasAuraState(AuraState flag) const { return HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); }
1475 bool HasAuraStateForCaster(AuraState flag, uint64 caster) const;
1476 void UnsummonAllTotems();
1477 Unit* SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo = NULL);
1478 int32 SpellBaseDamageBonus(SpellSchoolMask schoolMask);
1479 int32 SpellBaseHealingBonus(SpellSchoolMask schoolMask);
1480 int32 SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1481 int32 SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1482 uint32 SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 damage, DamageEffectType damagetype, uint32 stack = 1);
1483 uint32 SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 healamount, DamageEffectType damagetype, uint32 stack = 1);
1484 bool isSpellBlocked(Unit *pVictim, SpellEntry const *spellProto, WeaponAttackType attackType = BASE_ATTACK);
1485 bool isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType = BASE_ATTACK);
1486 uint32 SpellCriticalDamageBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1487 uint32 SpellCriticalHealingBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1489 void SetLastManaUse()
1491 if (GetTypeId() == TYPEID_PLAYER && !IsUnderLastManaUseEffect())
1492 RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_REGENERATE_POWER);
1494 m_lastManaUseTimer = 5000;
1496 bool IsUnderLastManaUseEffect() const { return m_lastManaUseTimer; }
1498 uint32 GetRegenTimer() const { return m_regenTimer; }
1500 void SetContestedPvP(Player *attackedPlayer = NULL);
1502 uint32 MeleeDamageBonus(Unit *pVictim, uint32 damage, WeaponAttackType attType, SpellEntry const *spellProto = NULL, DamageEffectType damagetype = DIRECT_DAMAGE, uint32 stack =1);
1503 uint32 GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime );
1505 void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply);
1506 void ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply);
1507 virtual bool IsImmunedToSpell(SpellEntry const* spellInfo);
1508 // redefined in Creature
1509 bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask);
1510 virtual bool IsImmunedToSpellEffect(SpellEntry const* spellInfo, uint32 index) const;
1511 // redefined in Creature
1513 uint32 CalcArmorReducedDamage(Unit* pVictim, const uint32 damage);
1514 void CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist, bool canReflect = false);
1516 void UpdateSpeed(UnitMoveType mtype, bool forced);
1517 float GetSpeed( UnitMoveType mtype ) const;
1518 float GetSpeedRate( UnitMoveType mtype ) const { return m_speed_rate[mtype]; }
1519 void SetSpeed(UnitMoveType mtype, float rate, bool forced = false);
1521 void SetHover(bool on);
1522 bool isHover() const { return HasAuraType(SPELL_AURA_HOVER); }
1524 void KnockBackFrom(Unit* target, float horizintalSpeed, float verticalSpeed);
1526 void _RemoveAllAuraMods();
1527 void _ApplyAllAuraMods();
1529 int32 CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_index, int32 basePoints, Unit const* target);
1531 uint32 CalcNotIgnoreAbsorbDamage( uint32 damage, SpellSchoolMask damageSchoolMask, SpellEntry const* spellInfo = NULL);
1532 uint32 CalcNotIgnoreDamageRedunction( uint32 damage, SpellSchoolMask damageSchoolMask);
1533 int32 CalculateSpellDuration(SpellEntry const* spellProto, uint8 effect_index, Unit const* target);
1534 float CalculateLevelPenalty(SpellEntry const* spellProto) const;
1536 void addFollower(FollowerReference* pRef) { m_FollowingRefManager.insertFirst(pRef); }
1537 void removeFollower(FollowerReference* /*pRef*/ ) { /* nothing to do yet */ }
1538 static Unit* GetUnit(WorldObject& object, uint64 guid);
1540 MotionMaster* GetMotionMaster() { return &i_motionMaster; }
1542 bool IsStopped() const { return !(hasUnitState(UNIT_STAT_MOVING)); }
1543 void StopMoving();
1545 void SetFeared(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0, uint32 time = 0);
1546 void SetConfused(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);
1547 void SetFeignDeath(bool apply, uint64 const& casterGUID = 0, uint32 spellID = 0);
1549 void AddComboPointHolder(uint32 lowguid) { m_ComboPointHolders.insert(lowguid); }
1550 void RemoveComboPointHolder(uint32 lowguid) { m_ComboPointHolders.erase(lowguid); }
1551 void ClearComboPointHolders();
1553 ///----------Pet responses methods-----------------
1554 void SendPetCastFail(uint32 spellid, SpellCastResult msg);
1555 void SendPetActionFeedback (uint8 msg);
1556 void SendPetTalk (uint32 pettalk);
1557 void SendPetAIReaction(uint64 guid);
1558 ///----------End of Pet responses methods----------
1560 void propagateSpeedChange() { GetMotionMaster()->propagateSpeedChange(); }
1562 // reactive attacks
1563 void ClearAllReactives();
1564 void StartReactiveTimer( ReactiveType reactive ) { m_reactiveTimer[reactive] = REACTIVE_TIMER_START;}
1565 void UpdateReactives(uint32 p_time);
1567 // group updates
1568 void UpdateAuraForGroup(uint8 slot);
1570 // pet auras
1571 typedef std::set<PetAura const*> PetAuraSet;
1572 PetAuraSet m_petAuras;
1573 void AddPetAura(PetAura const* petSpell);
1574 void RemovePetAura(PetAura const* petSpell);
1576 protected:
1577 explicit Unit ();
1579 void _UpdateSpells(uint32 time);
1581 void _UpdateAutoRepeatSpell();
1582 bool m_AutoRepeatFirstCast;
1584 uint32 m_attackTimer[MAX_ATTACK];
1586 float m_createStats[MAX_STATS];
1588 AttackerSet m_attackers;
1589 Unit* m_attacking;
1591 DeathState m_deathState;
1593 AuraMap m_Auras;
1594 AuraMap::iterator m_AurasUpdateIterator; // != end() in Unit::m_Auras update and point to next element
1595 AuraList m_deletedAuras; // auras removed while in ApplyModifier and waiting deleted
1597 AuraList m_scAuras; // casted by unit single per-caster auras
1599 typedef std::list<uint64> DynObjectGUIDs;
1600 DynObjectGUIDs m_dynObjGUIDs;
1602 typedef std::list<GameObject*> GameObjectList;
1603 GameObjectList m_gameObj;
1604 bool m_isSorted;
1605 uint32 m_transform;
1607 AuraList m_modAuras[TOTAL_AURAS];
1608 float m_auraModifiersGroup[UNIT_MOD_END][MODIFIER_TYPE_END];
1609 float m_weaponDamage[MAX_ATTACK][2];
1610 bool m_canModifyStats;
1611 //std::list< spellEffectPair > AuraSpells[TOTAL_AURAS]; // TODO: use this if ok for mem
1612 VisibleAuraMap m_visibleAuras;
1614 float m_speed_rate[MAX_MOVE_TYPE];
1616 CharmInfo *m_charmInfo;
1618 virtual SpellSchoolMask GetMeleeDamageSchoolMask() const;
1620 MotionMaster i_motionMaster;
1622 uint32 m_reactiveTimer[MAX_REACTIVE];
1623 uint32 m_regenTimer;
1624 uint32 m_lastManaUseTimer;
1626 private:
1627 void CleanupDeletedAuars();
1629 bool IsTriggeredAtSpellProcEvent(Unit *pVictim, Aura* aura, SpellEntry const* procSpell, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, bool isVictim, bool active, SpellProcEventEntry const*& spellProcEvent );
1630 bool HandleDummyAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1631 bool HandleHasteAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1632 bool HandleSpellCritChanceAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1633 bool HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1634 bool HandleOverrideClassScriptAuraProc(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 cooldown);
1635 bool HandleMendingAuraProc(Aura* triggeredByAura);
1637 // player or player's pet
1638 float GetCombatRatingReduction(CombatRating cr) const;
1639 uint32 GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const;
1641 uint32 m_state; // Even derived shouldn't modify
1642 uint32 m_CombatTimer;
1644 Spell* m_currentSpells[CURRENT_MAX_SPELL];
1646 UnitVisibility m_Visibility;
1648 Diminishing m_Diminishing;
1649 // Manage all Units threatening us
1650 ThreatManager m_ThreatManager;
1651 // Manage all Units that are threatened by us
1652 HostileRefManager m_HostileRefManager;
1654 FollowerRefManager m_FollowingRefManager;
1656 ComboPointHolderSet m_ComboPointHolders;
1658 GuardianPetList m_guardianPets;
1660 #endif