[7916] Fixed pet action bar setup.
[getmangos.git] / src / game / Unit.h
blobb54c96317d35c4909322b86574f62523cef7b9e6
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 "HostilRefManager.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
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,
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, 26 unused
113 SPELLMOD_MULTIPLE_VALUE = 27,
114 SPELLMOD_RESIST_DISPEL_CHANCE = 28
117 #define MAX_SPELLMOD 32
119 enum SpellFacingFlags
121 SPELL_FACING_FLAG_INFRONT = 0x0001
124 #define BASE_MINDAMAGE 1.0f
125 #define BASE_MAXDAMAGE 2.0f
126 #define BASE_ATTACK_TIME 2000
128 // byte value (UNIT_FIELD_BYTES_1,0)
129 enum UnitStandStateType
131 UNIT_STAND_STATE_STAND = 0,
132 UNIT_STAND_STATE_SIT = 1,
133 UNIT_STAND_STATE_SIT_CHAIR = 2,
134 UNIT_STAND_STATE_SLEEP = 3,
135 UNIT_STAND_STATE_SIT_LOW_CHAIR = 4,
136 UNIT_STAND_STATE_SIT_MEDIUM_CHAIR = 5,
137 UNIT_STAND_STATE_SIT_HIGH_CHAIR = 6,
138 UNIT_STAND_STATE_DEAD = 7,
139 UNIT_STAND_STATE_KNEEL = 8
142 // byte flag value (UNIT_FIELD_BYTES_1,2)
143 enum UnitStandFlags
145 UNIT_STAND_FLAGS_CREEP = 0x02,
146 UNIT_STAND_FLAGS_ALL = 0xFF
149 // byte flags value (UNIT_FIELD_BYTES_1,3)
150 enum UnitBytes1_Flags
152 UNIT_BYTE1_FLAG_ALWAYS_STAND = 0x01,
153 UNIT_BYTE1_FLAG_UNTRACKABLE = 0x04,
154 UNIT_BYTE1_FLAG_ALL = 0xFF
157 // high byte (3 from 0..3) of UNIT_FIELD_BYTES_2
158 enum ShapeshiftForm
160 FORM_NONE = 0x00,
161 FORM_CAT = 0x01,
162 FORM_TREE = 0x02,
163 FORM_TRAVEL = 0x03,
164 FORM_AQUA = 0x04,
165 FORM_BEAR = 0x05,
166 FORM_AMBIENT = 0x06,
167 FORM_GHOUL = 0x07,
168 FORM_DIREBEAR = 0x08,
169 FORM_CREATUREBEAR = 0x0E,
170 FORM_CREATURECAT = 0x0F,
171 FORM_GHOSTWOLF = 0x10,
172 FORM_BATTLESTANCE = 0x11,
173 FORM_DEFENSIVESTANCE = 0x12,
174 FORM_BERSERKERSTANCE = 0x13,
175 FORM_TEST = 0x14,
176 FORM_ZOMBIE = 0x15,
177 FORM_METAMORPHOSIS = 0x16,
178 FORM_FLIGHT_EPIC = 0x1B,
179 FORM_SHADOW = 0x1C,
180 FORM_FLIGHT = 0x1D,
181 FORM_STEALTH = 0x1E,
182 FORM_MOONKIN = 0x1F,
183 FORM_SPIRITOFREDEMPTION = 0x20
186 // low byte ( 0 from 0..3 ) of UNIT_FIELD_BYTES_2
187 enum SheathState
189 SHEATH_STATE_UNARMED = 0, // non prepared weapon
190 SHEATH_STATE_MELEE = 1, // prepared melee weapon
191 SHEATH_STATE_RANGED = 2 // prepared ranged weapon
194 #define MAX_SHEATH_STATE 3
196 // byte (1 from 0..3) of UNIT_FIELD_BYTES_2
197 enum UnitBytes2_Flags
199 UNIT_BYTE2_FLAG_PVP = 0x01,
200 UNIT_BYTE2_FLAG_UNK1 = 0x02,
201 UNIT_BYTE2_FLAG_FFA_PVP = 0x04,
202 UNIT_BYTE2_FLAG_SANCTUARY = 0x08,
203 UNIT_BYTE2_FLAG_UNK4 = 0x10,
204 UNIT_BYTE2_FLAG_UNK5 = 0x20,
205 UNIT_BYTE2_FLAG_UNK6 = 0x40,
206 UNIT_BYTE2_FLAG_UNK7 = 0x80
209 // byte (2 from 0..3) of UNIT_FIELD_BYTES_2
210 enum UnitRename
212 UNIT_RENAME_NOT_ALLOWED = 0x02,
213 UNIT_RENAME_ALLOWED = 0x03
216 #define CREATURE_MAX_SPELLS 4
218 enum Swing
220 NOSWING = 0,
221 SINGLEHANDEDSWING = 1,
222 TWOHANDEDSWING = 2
225 enum VictimState
227 VICTIMSTATE_UNKNOWN1 = 0,
228 VICTIMSTATE_NORMAL = 1,
229 VICTIMSTATE_DODGE = 2,
230 VICTIMSTATE_PARRY = 3,
231 VICTIMSTATE_INTERRUPT = 4,
232 VICTIMSTATE_BLOCKS = 5,
233 VICTIMSTATE_EVADES = 6,
234 VICTIMSTATE_IS_IMMUNE = 7,
235 VICTIMSTATE_DEFLECTS = 8
238 enum HitInfo
240 HITINFO_NORMALSWING = 0x00000000,
241 HITINFO_UNK1 = 0x00000001, // req correct packet structure
242 HITINFO_NORMALSWING2 = 0x00000002,
243 HITINFO_LEFTSWING = 0x00000004,
244 HITINFO_UNK2 = 0x00000008,
245 HITINFO_MISS = 0x00000010,
246 HITINFO_ABSORB = 0x00000020, // absorbed damage
247 HITINFO_ABSORB2 = 0x00000040, // absorbed damage
248 HITINFO_RESIST = 0x00000080, // resisted atleast some damage
249 HITINFO_RESIST2 = 0x00000100, // resisted atleast some damage
250 HITINFO_CRITICALHIT = 0x00000200, // critical hit
251 // 0x00000400
252 // 0x00000800
253 // 0x00001000
254 HITINFO_BLOCK = 0x00002000, // blocked damage
255 // 0x00004000
256 // 0x00008000
257 HITINFO_GLANCING = 0x00010000,
258 HITINFO_CRUSHING = 0x00020000,
259 HITINFO_NOACTION = 0x00040000, // guessed
260 // 0x00080000
261 // 0x00100000
262 HITINFO_SWINGNOHITSOUND = 0x00200000, // guessed
263 // 0x00400000
264 HITINFO_UNK3 = 0x00800000
267 //i would like to remove this: (it is defined in item.h
268 enum InventorySlot
270 NULL_BAG = 0,
271 NULL_SLOT = 255
274 struct FactionTemplateEntry;
275 struct Modifier;
276 struct SpellEntry;
277 struct SpellEntryExt;
279 class Aura;
280 class Creature;
281 class Spell;
282 class DynamicObject;
283 class GameObject;
284 class Item;
285 class Pet;
286 class Path;
287 class PetAura;
289 struct SpellImmune
291 uint32 type;
292 uint32 spellId;
295 typedef std::list<SpellImmune> SpellImmuneList;
297 enum UnitModifierType
299 BASE_VALUE = 0,
300 BASE_PCT = 1,
301 TOTAL_VALUE = 2,
302 TOTAL_PCT = 3,
303 MODIFIER_TYPE_END = 4
306 enum WeaponDamageRange
308 MINDAMAGE,
309 MAXDAMAGE
312 enum DamageTypeToSchool
314 RESISTANCE,
315 DAMAGE_DEALT,
316 DAMAGE_TAKEN
319 enum AuraRemoveMode
321 AURA_REMOVE_BY_DEFAULT,
322 AURA_REMOVE_BY_STACK, // at replace by similar aura
323 AURA_REMOVE_BY_CANCEL,
324 AURA_REMOVE_BY_DISPEL,
325 AURA_REMOVE_BY_DEATH
328 enum UnitMods
330 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.
331 UNIT_MOD_STAT_AGILITY,
332 UNIT_MOD_STAT_STAMINA,
333 UNIT_MOD_STAT_INTELLECT,
334 UNIT_MOD_STAT_SPIRIT,
335 UNIT_MOD_HEALTH,
336 UNIT_MOD_MANA, // UNIT_MOD_MANA..UNIT_MOD_RUNIC_POWER must be in existed order, it's accessed by index values of Powers enum.
337 UNIT_MOD_RAGE,
338 UNIT_MOD_FOCUS,
339 UNIT_MOD_ENERGY,
340 UNIT_MOD_HAPPINESS,
341 UNIT_MOD_RUNE,
342 UNIT_MOD_RUNIC_POWER,
343 UNIT_MOD_ARMOR, // UNIT_MOD_ARMOR..UNIT_MOD_RESISTANCE_ARCANE must be in existed order, it's accessed by index values of SpellSchools enum.
344 UNIT_MOD_RESISTANCE_HOLY,
345 UNIT_MOD_RESISTANCE_FIRE,
346 UNIT_MOD_RESISTANCE_NATURE,
347 UNIT_MOD_RESISTANCE_FROST,
348 UNIT_MOD_RESISTANCE_SHADOW,
349 UNIT_MOD_RESISTANCE_ARCANE,
350 UNIT_MOD_ATTACK_POWER,
351 UNIT_MOD_ATTACK_POWER_RANGED,
352 UNIT_MOD_DAMAGE_MAINHAND,
353 UNIT_MOD_DAMAGE_OFFHAND,
354 UNIT_MOD_DAMAGE_RANGED,
355 UNIT_MOD_END,
356 // synonyms
357 UNIT_MOD_STAT_START = UNIT_MOD_STAT_STRENGTH,
358 UNIT_MOD_STAT_END = UNIT_MOD_STAT_SPIRIT + 1,
359 UNIT_MOD_RESISTANCE_START = UNIT_MOD_ARMOR,
360 UNIT_MOD_RESISTANCE_END = UNIT_MOD_RESISTANCE_ARCANE + 1,
361 UNIT_MOD_POWER_START = UNIT_MOD_MANA,
362 UNIT_MOD_POWER_END = UNIT_MOD_RUNIC_POWER + 1
365 enum BaseModGroup
367 CRIT_PERCENTAGE,
368 RANGED_CRIT_PERCENTAGE,
369 OFFHAND_CRIT_PERCENTAGE,
370 SHIELD_BLOCK_VALUE,
371 BASEMOD_END
374 enum BaseModType
376 FLAT_MOD,
377 PCT_MOD
380 #define MOD_END (PCT_MOD+1)
382 enum DeathState
384 ALIVE = 0,
385 JUST_DIED = 1,
386 CORPSE = 2,
387 DEAD = 3,
388 JUST_ALIVED = 4,
389 DEAD_FALLING= 5
392 enum UnitState
394 UNIT_STAT_DIED = 0x0001,
395 UNIT_STAT_MELEE_ATTACKING = 0x0002, // player is melee attacking someone
396 //UNIT_STAT_MELEE_ATTACK_BY = 0x0004, // player is melee attack by someone
397 UNIT_STAT_STUNNED = 0x0008,
398 UNIT_STAT_ROAMING = 0x0010,
399 UNIT_STAT_CHASE = 0x0020,
400 UNIT_STAT_SEARCHING = 0x0040,
401 UNIT_STAT_FLEEING = 0x0080,
402 UNIT_STAT_MOVING = (UNIT_STAT_ROAMING | UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING),
403 UNIT_STAT_IN_FLIGHT = 0x0100, // player is in flight mode
404 UNIT_STAT_FOLLOW = 0x0200,
405 UNIT_STAT_ROOT = 0x0400,
406 UNIT_STAT_CONFUSED = 0x0800,
407 UNIT_STAT_DISTRACTED = 0x1000,
408 UNIT_STAT_ISOLATED = 0x2000, // area auras do not affect other players
409 UNIT_STAT_ATTACK_PLAYER = 0x4000,
410 UNIT_STAT_ALL_STATE = 0xffff //(UNIT_STAT_STOPPED | UNIT_STAT_MOVING | UNIT_STAT_IN_COMBAT | UNIT_STAT_IN_FLIGHT)
413 enum UnitMoveType
415 MOVE_WALK = 0,
416 MOVE_RUN = 1,
417 MOVE_RUN_BACK = 2,
418 MOVE_SWIM = 3,
419 MOVE_SWIM_BACK = 4,
420 MOVE_TURN_RATE = 5,
421 MOVE_FLIGHT = 6,
422 MOVE_FLIGHT_BACK = 7,
423 MOVE_PITCH_RATE = 8
426 #define MAX_MOVE_TYPE 9
428 extern float baseMoveSpeed[MAX_MOVE_TYPE];
430 enum WeaponAttackType
432 BASE_ATTACK = 0,
433 OFF_ATTACK = 1,
434 RANGED_ATTACK = 2
437 #define MAX_ATTACK 3
439 enum CombatRating
441 CR_WEAPON_SKILL = 0,
442 CR_DEFENSE_SKILL = 1,
443 CR_DODGE = 2,
444 CR_PARRY = 3,
445 CR_BLOCK = 4,
446 CR_HIT_MELEE = 5,
447 CR_HIT_RANGED = 6,
448 CR_HIT_SPELL = 7,
449 CR_CRIT_MELEE = 8,
450 CR_CRIT_RANGED = 9,
451 CR_CRIT_SPELL = 10,
452 CR_HIT_TAKEN_MELEE = 11,
453 CR_HIT_TAKEN_RANGED = 12,
454 CR_HIT_TAKEN_SPELL = 13,
455 CR_CRIT_TAKEN_MELEE = 14,
456 CR_CRIT_TAKEN_RANGED = 15,
457 CR_CRIT_TAKEN_SPELL = 16,
458 CR_HASTE_MELEE = 17,
459 CR_HASTE_RANGED = 18,
460 CR_HASTE_SPELL = 19,
461 CR_WEAPON_SKILL_MAINHAND = 20,
462 CR_WEAPON_SKILL_OFFHAND = 21,
463 CR_WEAPON_SKILL_RANGED = 22,
464 CR_EXPERTISE = 23,
465 CR_ARMOR_PENETRATION = 24
468 #define MAX_COMBAT_RATING 25
470 enum DamageEffectType
472 DIRECT_DAMAGE = 0, // used for normal weapon damage (not for class abilities or spells)
473 SPELL_DIRECT_DAMAGE = 1, // spell/class abilities damage
474 DOT = 2,
475 HEAL = 3,
476 NODAMAGE = 4, // used also in case when damage applied to health but not applied to spell channelInterruptFlags/etc
477 SELF_DAMAGE = 5
480 enum UnitVisibility
482 VISIBILITY_OFF = 0, // absolute, not detectable, GM-like, can see all other
483 VISIBILITY_ON = 1,
484 VISIBILITY_GROUP_STEALTH = 2, // detect chance, seen and can see group members
485 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)
486 VISIBILITY_GROUP_NO_DETECT = 4, // state just at stealth apply for update Grid state. Don't remove, otherwise stealth spells will break
487 VISIBILITY_RESPAWN = 5 // special totally not detectable visibility for force delete object at respawn command
490 // Value masks for UNIT_FIELD_FLAGS
491 enum UnitFlags
493 UNIT_FLAG_UNK_0 = 0x00000001,
494 UNIT_FLAG_NON_ATTACKABLE = 0x00000002, // not attackable
495 UNIT_FLAG_DISABLE_MOVE = 0x00000004,
496 UNIT_FLAG_PVP_ATTACKABLE = 0x00000008, // allow apply pvp rules to attackable state in addition to faction dependent state
497 UNIT_FLAG_RENAME = 0x00000010,
498 UNIT_FLAG_PREPARATION = 0x00000020, // don't take reagents for spells with SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
499 UNIT_FLAG_UNK_6 = 0x00000040,
500 UNIT_FLAG_NOT_ATTACKABLE_1 = 0x00000080, // ?? (UNIT_FLAG_PVP_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1) is NON_PVP_ATTACKABLE
501 UNIT_FLAG_UNK_8 = 0x00000100, // 2.0.8
502 UNIT_FLAG_UNK_9 = 0x00000200, // 3.0.3 - makes you unable to attack everything
503 UNIT_FLAG_LOOTING = 0x00000400, // loot animation
504 UNIT_FLAG_PET_IN_COMBAT = 0x00000800, // in combat?, 2.0.8
505 UNIT_FLAG_PVP = 0x00001000, // changed in 3.0.3
506 UNIT_FLAG_SILENCED = 0x00002000, // silenced, 2.1.1
507 UNIT_FLAG_UNK_14 = 0x00004000, // 2.0.8
508 UNIT_FLAG_UNK_15 = 0x00008000,
509 UNIT_FLAG_UNK_16 = 0x00010000,
510 UNIT_FLAG_PACIFIED = 0x00020000, // 3.0.3 ok
511 UNIT_FLAG_STUNNED = 0x00040000, // 3.0.3 ok
512 UNIT_FLAG_IN_COMBAT = 0x00080000,
513 UNIT_FLAG_TAXI_FLIGHT = 0x00100000, // disable casting at client side spell not allowed by taxi flight (mounted?), probably used with 0x4 flag
514 UNIT_FLAG_DISARMED = 0x00200000, // 3.0.3, disable melee spells casting..., "Required melee weapon" added to melee spells tooltip.
515 UNIT_FLAG_CONFUSED = 0x00400000,
516 UNIT_FLAG_FLEEING = 0x00800000,
517 UNIT_FLAG_UNK_24 = 0x01000000, // used in spell Eyes of the Beast for pet...
518 UNIT_FLAG_NOT_SELECTABLE = 0x02000000,
519 UNIT_FLAG_SKINNABLE = 0x04000000,
520 UNIT_FLAG_MOUNT = 0x08000000,
521 UNIT_FLAG_UNK_28 = 0x10000000,
522 UNIT_FLAG_UNK_29 = 0x20000000, // used in Feing Death spell
523 UNIT_FLAG_SHEATHE = 0x40000000,
524 UNIT_FLAG_UNK_31 = 0x80000000
527 // Value masks for UNIT_FIELD_FLAGS_2
528 enum UnitFlags2
530 UNIT_FLAG2_FEIGN_DEATH = 0x00000001,
531 UNIT_FLAG2_UNK1 = 0x00000002, // Hide unit model (show only player equip)
532 UNIT_FLAG2_COMPREHEND_LANG = 0x00000008,
533 UNIT_FLAG2_FORCE_MOVE = 0x00000040,
534 UNIT_FLAG2_REGENERATE_POWER = 0x00000800
537 /// Non Player Character flags
538 enum NPCFlags
540 UNIT_NPC_FLAG_NONE = 0x00000000,
541 UNIT_NPC_FLAG_GOSSIP = 0x00000001, // 100%
542 UNIT_NPC_FLAG_QUESTGIVER = 0x00000002, // guessed, probably ok
543 UNIT_NPC_FLAG_UNK1 = 0x00000004,
544 UNIT_NPC_FLAG_UNK2 = 0x00000008,
545 UNIT_NPC_FLAG_TRAINER = 0x00000010, // 100%
546 UNIT_NPC_FLAG_TRAINER_CLASS = 0x00000020, // 100%
547 UNIT_NPC_FLAG_TRAINER_PROFESSION = 0x00000040, // 100%
548 UNIT_NPC_FLAG_VENDOR = 0x00000080, // 100%
549 UNIT_NPC_FLAG_VENDOR_AMMO = 0x00000100, // 100%, general goods vendor
550 UNIT_NPC_FLAG_VENDOR_FOOD = 0x00000200, // 100%
551 UNIT_NPC_FLAG_VENDOR_POISON = 0x00000400, // guessed
552 UNIT_NPC_FLAG_VENDOR_REAGENT = 0x00000800, // 100%
553 UNIT_NPC_FLAG_REPAIR = 0x00001000, // 100%
554 UNIT_NPC_FLAG_FLIGHTMASTER = 0x00002000, // 100%
555 UNIT_NPC_FLAG_SPIRITHEALER = 0x00004000, // guessed
556 UNIT_NPC_FLAG_SPIRITGUIDE = 0x00008000, // guessed
557 UNIT_NPC_FLAG_INNKEEPER = 0x00010000, // 100%
558 UNIT_NPC_FLAG_BANKER = 0x00020000, // 100%
559 UNIT_NPC_FLAG_PETITIONER = 0x00040000, // 100% 0xC0000 = guild petitions, 0x40000 = arena team petitions
560 UNIT_NPC_FLAG_TABARDDESIGNER = 0x00080000, // 100%
561 UNIT_NPC_FLAG_BATTLEMASTER = 0x00100000, // 100%
562 UNIT_NPC_FLAG_AUCTIONEER = 0x00200000, // 100%
563 UNIT_NPC_FLAG_STABLEMASTER = 0x00400000, // 100%
564 UNIT_NPC_FLAG_GUILD_BANKER = 0x00800000, // cause client to send 997 opcode
565 UNIT_NPC_FLAG_SPELLCLICK = 0x01000000, // cause client to send 1015 opcode (spell click)
566 UNIT_NPC_FLAG_GUARD = 0x10000000, // custom flag for guards
569 enum MovementFlags
571 MOVEMENTFLAG_NONE = 0x00000000,
572 MOVEMENTFLAG_FORWARD = 0x00000001,
573 MOVEMENTFLAG_BACKWARD = 0x00000002,
574 MOVEMENTFLAG_STRAFE_LEFT = 0x00000004,
575 MOVEMENTFLAG_STRAFE_RIGHT = 0x00000008,
576 MOVEMENTFLAG_LEFT = 0x00000010,
577 MOVEMENTFLAG_RIGHT = 0x00000020,
578 MOVEMENTFLAG_PITCH_UP = 0x00000040,
579 MOVEMENTFLAG_PITCH_DOWN = 0x00000080,
580 MOVEMENTFLAG_WALK_MODE = 0x00000100, // Walking
581 MOVEMENTFLAG_ONTRANSPORT = 0x00000200, // Used for flying on some creatures
582 MOVEMENTFLAG_LEVITATING = 0x00000400,
583 MOVEMENTFLAG_FLY_UNK1 = 0x00000800,
584 MOVEMENTFLAG_JUMPING = 0x00001000,
585 MOVEMENTFLAG_UNK4 = 0x00002000,
586 MOVEMENTFLAG_FALLING = 0x00004000,
587 // 0x8000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000
588 MOVEMENTFLAG_SWIMMING = 0x00200000, // appears with fly flag also
589 MOVEMENTFLAG_FLY_UP = 0x00400000,
590 MOVEMENTFLAG_CAN_FLY = 0x00800000,
591 MOVEMENTFLAG_FLYING = 0x01000000,
592 MOVEMENTFLAG_FLYING2 = 0x02000000, // Actual flying mode
593 MOVEMENTFLAG_SPLINE = 0x04000000, // used for flight paths
594 MOVEMENTFLAG_SPLINE2 = 0x08000000, // used for flight paths
595 MOVEMENTFLAG_WATERWALKING = 0x10000000, // prevent unit from falling through water
596 MOVEMENTFLAG_SAFE_FALL = 0x20000000, // active rogue safe fall spell (passive)
597 MOVEMENTFLAG_UNK3 = 0x40000000
600 enum MonsterMovementFlags
602 MONSTER_MOVE_NONE = 0x00000000,
603 MONSTER_MOVE_FORWARD = 0x00000001,
604 MONSTER_MOVE_BACKWARD = 0x00000002,
605 MONSTER_MOVE_STRAFE_LEFT = 0x00000004,
606 MONSTER_MOVE_STRAFE_RIGHT = 0x00000008,
607 MONSTER_MOVE_LEFT = 0x00000010, // turn
608 MONSTER_MOVE_RIGHT = 0x00000020, // turn
609 MONSTER_MOVE_PITCH_UP = 0x00000040,
610 MONSTER_MOVE_PITCH_DOWN = 0x00000080,
611 MONSTER_MOVE_TELEPORT = 0x00000100,
612 MONSTER_MOVE_TELEPORT2 = 0x00000200,
613 MONSTER_MOVE_LEVITATING = 0x00000400,
614 MONSTER_MOVE_UNK1 = 0x00000800, // float+uint32
615 MONSTER_MOVE_WALK = 0x00001000, // run2?
616 MONSTER_MOVE_SPLINE = 0x00002000, // spline n*(float x,y,z)
617 // 0x4000, 0x8000, 0x10000, 0x20000 run
618 MONSTER_MOVE_SPLINE2 = 0x00040000, // spline n*(float x,y,z)
619 MONSTER_MOVE_UNK2 = 0x00080000, // used for flying mobs
620 MONSTER_MOVE_UNK3 = 0x00100000, // used for flying mobs
621 MONSTER_MOVE_UNK4 = 0x00200000, // uint8+uint32
622 MONSTER_MOVE_UNK5 = 0x00400000, // run in place, then teleport to final point
623 MONSTER_MOVE_UNK6 = 0x00800000, // teleport
624 MONSTER_MOVE_UNK7 = 0x01000000, // run
625 MONSTER_MOVE_FLY = 0x02000000, // swimming/flying (depends on mob?)
626 MONSTER_MOVE_UNK9 = 0x04000000, // run
627 MONSTER_MOVE_UNK10 = 0x08000000, // run
628 MONSTER_MOVE_UNK11 = 0x10000000, // run
629 MONSTER_MOVE_UNK12 = 0x20000000, // run
630 MONSTER_MOVE_UNK13 = 0x40000000, // levitating
632 // masks
633 MONSTER_MOVE_SPLINE_FLY = 0x00003000, // fly by points
636 enum DiminishingLevels
638 DIMINISHING_LEVEL_1 = 0,
639 DIMINISHING_LEVEL_2 = 1,
640 DIMINISHING_LEVEL_3 = 2,
641 DIMINISHING_LEVEL_IMMUNE = 3
644 struct DiminishingReturn
646 DiminishingReturn(DiminishingGroup group, uint32 t, uint32 count)
647 : DRGroup(group), stack(0), hitTime(t), hitCount(count)
650 DiminishingGroup DRGroup:16;
651 uint16 stack:16;
652 uint32 hitTime;
653 uint32 hitCount;
656 enum MeleeHitOutcome
658 MELEE_HIT_EVADE, MELEE_HIT_MISS, MELEE_HIT_DODGE, MELEE_HIT_BLOCK, MELEE_HIT_PARRY,
659 MELEE_HIT_GLANCING, MELEE_HIT_CRIT, MELEE_HIT_CRUSHING, MELEE_HIT_NORMAL
662 struct CleanDamage
664 CleanDamage(uint32 _damage, WeaponAttackType _attackType, MeleeHitOutcome _hitOutCome) :
665 damage(_damage), attackType(_attackType), hitOutCome(_hitOutCome) {}
667 uint32 damage;
668 WeaponAttackType attackType;
669 MeleeHitOutcome hitOutCome;
672 // Struct for use in Unit::CalculateMeleeDamage
673 // Need create structure like in SMSG_ATTACKERSTATEUPDATE opcode
674 struct CalcDamageInfo
676 Unit *attacker; // Attacker
677 Unit *target; // Target for damage
678 uint32 damageSchoolMask;
679 uint32 damage;
680 uint32 absorb;
681 uint32 resist;
682 uint32 blocked_amount;
683 uint32 HitInfo;
684 uint32 TargetState;
685 // Helper
686 WeaponAttackType attackType; //
687 uint32 procAttacker;
688 uint32 procVictim;
689 uint32 procEx;
690 uint32 cleanDamage; // Used only for rage calculation
691 MeleeHitOutcome hitOutCome; // TODO: remove this field (need use TargetState)
694 // Spell damage info structure based on structure sending in SMSG_SPELLNONMELEEDAMAGELOG opcode
695 struct SpellNonMeleeDamage{
696 SpellNonMeleeDamage(Unit *_attacker, Unit *_target, uint32 _SpellID, uint32 _schoolMask)
697 : target(_target), attacker(_attacker), SpellID(_SpellID), damage(0), overkill(0), schoolMask(_schoolMask),
698 absorb(0), resist(0), physicalLog(false), unused(false), blocked(0), HitInfo(0), cleanDamage(0)
701 Unit *target;
702 Unit *attacker;
703 uint32 SpellID;
704 uint32 damage;
705 uint32 overkill;
706 uint32 schoolMask;
707 uint32 absorb;
708 uint32 resist;
709 bool physicalLog;
710 bool unused;
711 uint32 blocked;
712 uint32 HitInfo;
713 // Used for help
714 uint32 cleanDamage;
717 struct SpellPeriodicAuraLogInfo
719 SpellPeriodicAuraLogInfo(Aura *_aura, uint32 _damage, uint32 _overDamage, uint32 _absorb, uint32 _resist, float _multiplier)
720 : aura(_aura), damage(_damage), overDamage(_overDamage), absorb(_absorb), resist(_resist), multiplier(_multiplier) {}
722 Aura *aura;
723 uint32 damage;
724 uint32 absorb;
725 uint32 resist;
726 uint32 overDamage; // overkill/overheal
727 float multiplier;
730 uint32 createProcExtendMask(SpellNonMeleeDamage *damageInfo, SpellMissInfo missCondition);
732 #define MAX_DECLINED_NAME_CASES 5
734 struct DeclinedName
736 std::string name[MAX_DECLINED_NAME_CASES];
739 enum CurrentSpellTypes
741 CURRENT_MELEE_SPELL = 0,
742 CURRENT_FIRST_NON_MELEE_SPELL = 1, // just counter
743 CURRENT_GENERIC_SPELL = 1,
744 CURRENT_AUTOREPEAT_SPELL = 2,
745 CURRENT_CHANNELED_SPELL = 3,
746 CURRENT_MAX_SPELL = 4 // just counter
749 enum ActiveStates
751 ACT_PASSIVE = 0x0100, // 0x0100 - passive
752 ACT_DISABLED = 0x8100, // 0x8000 - castable
753 ACT_ENABLED = 0xC100, // 0x4000 | 0x8000 - auto cast + castable
754 ACT_COMMAND = 0x0700, // 0x0100 | 0x0200 | 0x0400
755 ACT_REACTION = 0x0600, // 0x0200 | 0x0400
756 ACT_DECIDE = 0x0001 // what is it?
759 enum ReactStates
761 REACT_PASSIVE = 0,
762 REACT_DEFENSIVE = 1,
763 REACT_AGGRESSIVE = 2
766 enum CommandStates
768 COMMAND_STAY = 0,
769 COMMAND_FOLLOW = 1,
770 COMMAND_ATTACK = 2,
771 COMMAND_ABANDON = 3
774 struct UnitActionBarEntry
776 UnitActionBarEntry() : SpellOrAction(0), Type(ACT_DISABLED) {}
778 uint16 SpellOrAction;
779 uint16 Type;
781 // helper
782 bool IsActionBarForSpell() const
784 return Type == ACT_DISABLED || Type == ACT_ENABLED || Type == ACT_PASSIVE;
788 struct CharmSpellEntry
790 uint16 spellId;
791 uint16 active;
794 #define MAX_UNIT_ACTION_BAR_INDEX 10
796 struct CharmInfo
798 public:
799 explicit CharmInfo(Unit* unit);
800 uint32 GetPetNumber() const { return m_petnumber; }
801 void SetPetNumber(uint32 petnumber, bool statwindow);
803 void SetCommandState(CommandStates st) { m_CommandState = st; }
804 CommandStates GetCommandState() { return m_CommandState; }
805 bool HasCommandState(CommandStates state) { return (m_CommandState == state); }
806 void SetReactState(ReactStates st) { m_reactState = st; }
807 ReactStates GetReactState() { return m_reactState; }
808 bool HasReactState(ReactStates state) { return (m_reactState == state); }
810 void InitPossessCreateSpells();
811 void InitCharmCreateSpells();
812 void InitPetActionBar();
813 void InitEmptyActionBar();
815 //return true if successful
816 bool AddSpellToActionBar(uint32 spellid, ActiveStates newstate = ACT_DECIDE);
817 bool RemoveSpellFromActionBar(uint32 spell_id);
818 bool LoadActionBar(std::string data);
819 void BuildActionBar(WorldPacket* data);
820 void SetSpellAutocast(uint32 spell_id, bool state);
821 void SetActionBar(uint8 index, uint32 spellOrAction,ActiveStates type)
823 PetActionBar[index].Type = type;
824 PetActionBar[index].SpellOrAction = spellOrAction;
826 UnitActionBarEntry const* GetActionBarEntry(uint8 index) const { return &(PetActionBar[index]); }
828 void ToggleCreatureAutocast(uint32 spellid, bool apply);
830 CharmSpellEntry* GetCharmSpell(uint8 index) { return &(m_charmspells[index]); }
831 private:
833 Unit* m_unit;
834 UnitActionBarEntry PetActionBar[MAX_UNIT_ACTION_BAR_INDEX];
835 CharmSpellEntry m_charmspells[4];
836 CommandStates m_CommandState;
837 ReactStates m_reactState;
838 uint32 m_petnumber;
841 // for clearing special attacks
842 #define REACTIVE_TIMER_START 4000
844 enum ReactiveType
846 REACTIVE_DEFENSE = 0,
847 REACTIVE_HUNTER_PARRY = 1,
848 REACTIVE_OVERPOWER = 2
851 #define MAX_REACTIVE 3
852 #define MAX_TOTEM 4
854 // delay time next attack to prevent client attack animation problems
855 #define ATTACK_DISPLAY_DELAY 200
857 struct SpellProcEventEntry; // used only privately
859 class MANGOS_DLL_SPEC Unit : public WorldObject
861 public:
862 typedef std::set<Unit*> AttackerSet;
863 typedef std::pair<uint32, uint8> spellEffectPair;
864 typedef std::multimap< spellEffectPair, Aura*> AuraMap;
865 typedef std::list<Aura *> AuraList;
866 typedef std::list<DiminishingReturn> Diminishing;
867 typedef std::set<uint32> ComboPointHolderSet;
868 typedef std::map<uint8, uint32> VisibleAuraMap;
870 virtual ~Unit ( );
872 void AddToWorld();
873 void RemoveFromWorld();
875 void CleanupsBeforeDelete(); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units)
877 DiminishingLevels GetDiminishing(DiminishingGroup group);
878 void IncrDiminishing(DiminishingGroup group);
879 void ApplyDiminishingToDuration(DiminishingGroup group, int32 &duration,Unit* caster, DiminishingLevels Level);
880 void ApplyDiminishingAura(DiminishingGroup group, bool apply);
881 void ClearDiminishings() { m_Diminishing.clear(); }
883 virtual void Update( uint32 time );
885 void setAttackTimer(WeaponAttackType type, uint32 time) { m_attackTimer[type] = time; }
886 void resetAttackTimer(WeaponAttackType type = BASE_ATTACK);
887 uint32 getAttackTimer(WeaponAttackType type) const { return m_attackTimer[type]; }
888 bool isAttackReady(WeaponAttackType type = BASE_ATTACK) const { return m_attackTimer[type] == 0; }
889 bool haveOffhandWeapon() const;
890 bool canReachWithAttack(Unit *pVictim) const;
891 uint32 m_extraAttacks;
893 void _addAttacker(Unit *pAttacker) // must be called only from Unit::Attack(Unit*)
895 AttackerSet::const_iterator itr = m_attackers.find(pAttacker);
896 if(itr == m_attackers.end())
897 m_attackers.insert(pAttacker);
899 void _removeAttacker(Unit *pAttacker) // must be called only from Unit::AttackStop()
901 m_attackers.erase(pAttacker);
903 Unit * getAttackerForHelper() // If someone wants to help, who to give them
905 if (getVictim() != NULL)
906 return getVictim();
908 if (!m_attackers.empty())
909 return *(m_attackers.begin());
911 return NULL;
913 bool Attack(Unit *victim, bool meleeAttack);
914 void CastStop(uint32 except_spellid = 0);
915 bool AttackStop(bool targetSwitch = false);
916 void RemoveAllAttackers();
917 AttackerSet const& getAttackers() const { return m_attackers; }
918 bool isAttackingPlayer() const;
919 Unit* getVictim() const { return m_attacking; }
920 void CombatStop(bool includingCast = false);
921 void CombatStopWithPets(bool includingCast = false);
922 Unit* SelectNearbyTarget() const;
923 bool hasNegativeAuraWithInterruptFlag(uint32 flag);
925 void addUnitState(uint32 f) { m_state |= f; }
926 bool hasUnitState(const uint32 f) const { return (m_state & f); }
927 void clearUnitState(uint32 f) { m_state &= ~f; }
928 bool CanFreeMove() const
930 return !hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_FLEEING | UNIT_STAT_IN_FLIGHT |
931 UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DISTRACTED ) && GetOwnerGUID()==0;
934 uint32 getLevel() const { return GetUInt32Value(UNIT_FIELD_LEVEL); }
935 virtual uint32 getLevelForTarget(Unit const* /*target*/) const { return getLevel(); }
936 void SetLevel(uint32 lvl);
937 uint8 getRace() const { return GetByteValue(UNIT_FIELD_BYTES_0, 0); }
938 uint32 getRaceMask() const { return 1 << (getRace()-1); }
939 uint8 getClass() const { return GetByteValue(UNIT_FIELD_BYTES_0, 1); }
940 uint32 getClassMask() const { return 1 << (getClass()-1); }
941 uint8 getGender() const { return GetByteValue(UNIT_FIELD_BYTES_0, 2); }
943 float GetStat(Stats stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0+stat)); }
944 void SetStat(Stats stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0+stat, val); }
945 uint32 GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL) ; }
946 void SetArmor(int32 val) { SetResistance(SPELL_SCHOOL_NORMAL, val); }
948 uint32 GetResistance(SpellSchools school) const { return GetUInt32Value(UNIT_FIELD_RESISTANCES+school); }
949 void SetResistance(SpellSchools school, int32 val) { SetStatInt32Value(UNIT_FIELD_RESISTANCES+school,val); }
951 uint32 GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH); }
952 uint32 GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH); }
953 void SetHealth( uint32 val);
954 void SetMaxHealth(uint32 val);
955 int32 ModifyHealth(int32 val);
957 Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, 3)); }
958 void setPowerType(Powers power);
959 uint32 GetPower( Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1 +power); }
960 uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1+power); }
961 void SetPower( Powers power, uint32 val);
962 void SetMaxPower(Powers power, uint32 val);
963 int32 ModifyPower(Powers power, int32 val);
964 void ApplyPowerMod(Powers power, uint32 val, bool apply);
965 void ApplyMaxPowerMod(Powers power, uint32 val, bool apply);
967 uint32 GetAttackTime(WeaponAttackType att) const { return (uint32)(GetFloatValue(UNIT_FIELD_BASEATTACKTIME+att)/m_modAttackSpeedPct[att]); }
968 void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val*m_modAttackSpeedPct[att]); }
969 void ApplyAttackTimePercentMod(WeaponAttackType att,float val, bool apply);
970 void ApplyCastTimePercentMod(float val, bool apply);
972 SheathState GetSheath() const { return SheathState(GetByteValue(UNIT_FIELD_BYTES_2, 0)); }
973 virtual void SetSheath( SheathState sheathed ) { SetByteValue(UNIT_FIELD_BYTES_2, 0, sheathed); }
975 // faction template id
976 uint32 getFaction() const { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE); }
977 void setFaction(uint32 faction) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, faction ); }
978 FactionTemplateEntry const* getFactionTemplateEntry() const;
979 bool IsHostileTo(Unit const* unit) const;
980 bool IsHostileToPlayers() const;
981 bool IsFriendlyTo(Unit const* unit) const;
982 bool IsNeutralToAll() const;
983 bool IsContestedGuard() const
985 if(FactionTemplateEntry const* entry = getFactionTemplateEntry())
986 return entry->IsContestedGuardFaction();
988 return false;
990 bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP); }
991 void SetPvP(bool state);
992 uint32 GetCreatureType() const;
993 uint32 GetCreatureTypeMask() const
995 uint32 creatureType = GetCreatureType();
996 return (creatureType >= 1) ? (1 << (creatureType - 1)) : 0;
999 uint8 getStandState() const { return GetByteValue(UNIT_FIELD_BYTES_1, 0); }
1000 bool IsSitState() const;
1001 bool IsStandState() const;
1002 void SetStandState(uint8 state);
1004 void SetStandFlags(uint8 flags) { SetByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1005 void RemoveStandFlags(uint8 flags) { RemoveByteFlag(UNIT_FIELD_BYTES_1, 2,flags); }
1007 bool IsMounted() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); }
1008 uint32 GetMountID() const { return GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID); }
1009 void Mount(uint32 mount);
1010 void Unmount();
1012 uint16 GetMaxSkillValueForLevel(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1013 void DealDamageMods(Unit *pVictim, uint32 &damage, uint32* absorb);
1014 uint32 DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss);
1015 int32 DealHeal(Unit *pVictim, uint32 addhealth, SpellEntry const *spellProto, bool critical = false);
1017 void ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 procEx, uint32 amount, WeaponAttackType attType = BASE_ATTACK, SpellEntry const *procSpell = NULL);
1018 void ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage );
1020 void HandleEmoteCommand(uint32 anim_id);
1021 void AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType = BASE_ATTACK, bool extra = false );
1023 float MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const;
1025 void CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *damageInfo, WeaponAttackType attackType = BASE_ATTACK);
1026 void DealMeleeDamage(CalcDamageInfo *damageInfo, bool durabilityLoss);
1028 void CalculateSpellDamage(SpellNonMeleeDamage *damageInfo, int32 damage, SpellEntry const *spellInfo, WeaponAttackType attackType = BASE_ATTACK);
1029 void DealSpellDamage(SpellNonMeleeDamage *damageInfo, bool durabilityLoss);
1031 float MeleeSpellMissChance(Unit *pVictim, WeaponAttackType attType, int32 skillDiff, SpellEntry const *spell);
1032 SpellMissInfo MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1033 SpellMissInfo MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell);
1034 SpellMissInfo SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool canReflect = false);
1036 float GetUnitDodgeChance() const;
1037 float GetUnitParryChance() const;
1038 float GetUnitBlockChance() const;
1039 float GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const;
1041 virtual uint32 GetShieldBlockValue() const =0;
1042 uint32 GetUnitMeleeSkill(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
1043 uint32 GetDefenseSkillValue(Unit const* target = NULL) const;
1044 uint32 GetWeaponSkillValue(WeaponAttackType attType, Unit const* target = NULL) const;
1045 float GetWeaponProcChance() const;
1046 float GetPPMProcChance(uint32 WeaponSpeed, float PPM) const;
1048 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType) const;
1049 MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance) const;
1051 bool isVendor() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR ); }
1052 bool isTrainer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER ); }
1053 bool isQuestGiver() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER ); }
1054 bool isGossip() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP ); }
1055 bool isTaxi() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_FLIGHTMASTER ); }
1056 bool isGuildMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PETITIONER ); }
1057 bool isBattleMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BATTLEMASTER ); }
1058 bool isBanker() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BANKER ); }
1059 bool isInnkeeper() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_INNKEEPER ); }
1060 bool isSpiritHealer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER ); }
1061 bool isSpiritGuide() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITGUIDE ); }
1062 bool isTabardDesigner()const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TABARDDESIGNER ); }
1063 bool isAuctioner() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER ); }
1064 bool isArmorer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_REPAIR ); }
1065 bool isServiceProvider() const
1067 return HasFlag( UNIT_NPC_FLAGS,
1068 UNIT_NPC_FLAG_VENDOR | UNIT_NPC_FLAG_TRAINER | UNIT_NPC_FLAG_FLIGHTMASTER |
1069 UNIT_NPC_FLAG_PETITIONER | UNIT_NPC_FLAG_BATTLEMASTER | UNIT_NPC_FLAG_BANKER |
1070 UNIT_NPC_FLAG_INNKEEPER | UNIT_NPC_FLAG_GUARD | UNIT_NPC_FLAG_SPIRITHEALER |
1071 UNIT_NPC_FLAG_SPIRITGUIDE | UNIT_NPC_FLAG_TABARDDESIGNER | UNIT_NPC_FLAG_AUCTIONEER );
1073 bool isSpiritService() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER | UNIT_NPC_FLAG_SPIRITGUIDE ); }
1075 //Need fix or use this
1076 bool isGuard() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GUARD); }
1078 bool isInFlight() const { return hasUnitState(UNIT_STAT_IN_FLIGHT); }
1080 bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); }
1081 void SetInCombatState(bool PvP, Unit* enemy = NULL);
1082 void SetInCombatWith(Unit* enemy);
1083 void ClearInCombat();
1084 uint32 GetCombatTimer() const { return m_CombatTimer; }
1086 bool HasAuraType(AuraType auraType) const;
1087 bool HasAura(uint32 spellId, uint32 effIndex) const
1089 return m_Auras.find(spellEffectPair(spellId, effIndex)) != m_Auras.end();
1091 bool HasAura(uint32 spellId) const;
1093 bool virtual HasSpell(uint32 /*spellID*/) const { return false; }
1095 bool HasStealthAura() const { return HasAuraType(SPELL_AURA_MOD_STEALTH); }
1096 bool HasInvisibilityAura() const { return HasAuraType(SPELL_AURA_MOD_INVISIBILITY); }
1097 bool isFeared() const { return HasAuraType(SPELL_AURA_MOD_FEAR); }
1098 bool isInRoots() const { return HasAuraType(SPELL_AURA_MOD_ROOT); }
1099 bool IsPolymorphed() const;
1101 bool isFrozen() const;
1103 void RemoveSpellbyDamageTaken(AuraType auraType, uint32 damage);
1105 bool isTargetableForAttack() const;
1106 virtual bool IsInWater() const;
1107 virtual bool IsUnderWater() const;
1108 bool isInAccessablePlaceFor(Creature const* c) const;
1110 void SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, bool critical = false);
1111 void SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage,Powers powertype);
1112 uint32 SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage);
1113 void CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1114 void CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1115 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);
1116 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);
1117 void CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1118 void CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
1120 bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const;
1122 void DeMorph();
1124 void SendAttackStateUpdate(CalcDamageInfo *damageInfo);
1125 void SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount);
1126 void SendSpellNonMeleeDamageLog(SpellNonMeleeDamage *log);
1127 void SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID, uint32 Damage, SpellSchoolMask damageSchoolMask, uint32 AbsorbedDamage, uint32 Resist, bool PhysicalDamage, uint32 Blocked, bool CriticalHit = false);
1128 void SendPeriodicAuraLog(SpellPeriodicAuraLogInfo *pInfo);
1129 void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo);
1131 void NearTeleportTo(float x, float y, float z, float orientation, bool casting = false);
1133 void SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, uint32 MovementFlags, uint32 Time, Player* player = NULL);
1134 void SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, uint32 MovementFlags);
1135 void SendMonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime = 0, Player* player = NULL);
1136 void SendMonsterMoveWithSpeedToCurrentDestination(Player* player = NULL);
1138 virtual void MoveOutOfRange(Player &) { };
1140 bool isAlive() const { return (m_deathState == ALIVE); };
1141 bool isDead() const { return ( m_deathState == DEAD || m_deathState == CORPSE ); };
1142 DeathState getDeathState() { return m_deathState; };
1143 virtual void setDeathState(DeathState s); // overwrited in Creature/Player/Pet
1145 uint64 GetOwnerGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMONEDBY); }
1146 void SetOwnerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner); }
1147 uint64 GetCreatorGUID() const { return GetUInt64Value(UNIT_FIELD_CREATEDBY); }
1148 void SetCreatorGUID(uint64 creator) { SetUInt64Value(UNIT_FIELD_CREATEDBY, creator); }
1149 uint64 GetPetGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMON); }
1150 uint64 GetCharmerGUID() const { return GetUInt64Value(UNIT_FIELD_CHARMEDBY); }
1151 void SetCharmerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_CHARMEDBY, owner); }
1152 uint64 GetCharmGUID() const { return GetUInt64Value(UNIT_FIELD_CHARM); }
1154 uint64 GetCharmerOrOwnerGUID() const { return GetCharmerGUID() ? GetCharmerGUID() : GetOwnerGUID(); }
1155 uint64 GetCharmerOrOwnerOrOwnGUID() const
1157 if(uint64 guid = GetCharmerOrOwnerGUID())
1158 return guid;
1159 return GetGUID();
1161 bool isCharmedOwnedByPlayerOrPlayer() const { return IS_PLAYER_GUID(GetCharmerOrOwnerOrOwnGUID()); }
1163 Player* GetSpellModOwner();
1165 Unit* GetOwner() const;
1166 Pet* GetPet() const;
1167 Unit* GetCharmer() const;
1168 Unit* GetCharm() const;
1169 Unit* GetCharmerOrOwner() const { return GetCharmerGUID() ? GetCharmer() : GetOwner(); }
1170 Unit* GetCharmerOrOwnerOrSelf()
1172 if(Unit* u = GetCharmerOrOwner())
1173 return u;
1175 return this;
1177 Player* GetCharmerOrOwnerPlayerOrPlayerItself();
1178 float GetCombatDistance( const Unit* target ) const;
1180 void SetPet(Pet* pet);
1181 void SetCharm(Unit* pet);
1183 bool isCharmed() const { return GetCharmerGUID() != 0; }
1185 CharmInfo* GetCharmInfo() { return m_charmInfo; }
1186 CharmInfo* InitCharmInfo(Unit* charm);
1188 Pet* CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id = 0);
1190 bool AddAura(Aura *aur);
1192 void RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
1193 void RemoveAura(uint32 spellId, uint32 effindex, Aura* except = NULL);
1194 void RemoveSingleSpellAurasFromStack(uint32 spellId);
1195 void RemoveSingleAuraFromStack(uint32 spellId, uint32 effindex);
1196 void RemoveAurasDueToSpell(uint32 spellId, Aura* except = NULL);
1197 void RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId);
1198 void RemoveAurasByCasterSpell(uint32 spellId, uint64 casterGUID);
1199 void RemoveAurasDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler);
1200 void RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer);
1201 void RemoveAurasDueToSpellByCancel(uint32 spellId);
1202 void RemoveAurasAtChanneledTarget(SpellEntry const* spellInfo);
1203 void RemoveNotOwnSingleTargetAuras();
1205 void RemoveSpellsCausingAura(AuraType auraType);
1206 void RemoveRankAurasDueToSpell(uint32 spellId);
1207 bool RemoveNoStackAurasDueToAura(Aura *Aur);
1208 void RemoveAurasWithInterruptFlags(uint32 flags);
1209 void RemoveAurasWithDispelType( DispelType type );
1211 void RemoveAllAuras();
1212 void RemoveArenaAuras(bool onleave = false);
1213 void RemoveAllAurasOnDeath();
1214 void DelayAura(uint32 spellId, uint32 effindex, int32 delaytime);
1216 float GetResistanceBuffMods(SpellSchools school, bool positive) const { return GetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school ); }
1217 void SetResistanceBuffMods(SpellSchools school, bool positive, float val) { SetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school,val); }
1218 void ApplyResistanceBuffModsMod(SpellSchools school, bool positive, float val, bool apply) { ApplyModSignedFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1219 void ApplyResistanceBuffModsPercentMod(SpellSchools school, bool positive, float val, bool apply) { ApplyPercentModFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1220 void InitStatBuffMods()
1222 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_POSSTAT0+i, 0);
1223 for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_NEGSTAT0+i, 0);
1225 void ApplyStatBuffMod(Stats stat, float val, bool apply) { ApplyModSignedFloatValue((val > 0 ? UNIT_FIELD_POSSTAT0+stat : UNIT_FIELD_NEGSTAT0+stat), val, apply); }
1226 void ApplyStatPercentBuffMod(Stats stat, float val, bool apply)
1228 ApplyPercentModFloatValue(UNIT_FIELD_POSSTAT0+stat, val, apply);
1229 ApplyPercentModFloatValue(UNIT_FIELD_NEGSTAT0+stat, val, apply);
1231 void SetCreateStat(Stats stat, float val) { m_createStats[stat] = val; }
1232 void SetCreateHealth(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_HEALTH, val); }
1233 uint32 GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH); }
1234 void SetCreateMana(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_MANA, val); }
1235 uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); }
1236 uint32 GetCreatePowers(Powers power) const;
1237 float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0+stat); }
1238 float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0+stat); }
1239 float GetCreateStat(Stats stat) const { return m_createStats[stat]; }
1241 void SetCurrentCastedSpell(Spell * pSpell);
1242 virtual void ProhibitSpellScholl(SpellSchoolMask /*idSchoolMask*/, uint32 /*unTimeMs*/ ) { }
1243 void InterruptSpell(uint32 spellType, bool withDelayed = true);
1245 // set withDelayed to true to account delayed spells as casted
1246 // delayed+channeled spells are always accounted as casted
1247 // we can skip channeled or delayed checks using flags
1248 bool IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled = false, bool skipAutorepeat = false) const;
1250 // set withDelayed to true to interrupt delayed spells too
1251 // delayed+channeled spells are always interrupted
1252 void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid = 0);
1254 Spell* FindCurrentSpellBySpellId(uint32 spell_id) const;
1256 Spell* m_currentSpells[CURRENT_MAX_SPELL];
1258 uint32 m_addDmgOnce;
1259 uint64 m_TotemSlot[MAX_TOTEM];
1260 uint64 m_ObjectSlot[4];
1261 uint32 m_detectInvisibilityMask;
1262 uint32 m_invisibilityMask;
1264 uint32 m_ShapeShiftFormSpellId;
1265 ShapeshiftForm m_form;
1266 bool IsInFeralForm() const { return m_form == FORM_CAT || m_form == FORM_BEAR || m_form == FORM_DIREBEAR; }
1268 float m_modMeleeHitChance;
1269 float m_modRangedHitChance;
1270 float m_modSpellHitChance;
1271 int32 m_baseSpellCritChance;
1273 float m_threatModifier[MAX_SPELL_SCHOOL];
1274 float m_modAttackSpeedPct[3];
1276 // Event handler
1277 EventProcessor m_Events;
1279 // stat system
1280 bool HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply);
1281 void SetModifierValue(UnitMods unitMod, UnitModifierType modifierType, float value) { m_auraModifiersGroup[unitMod][modifierType] = value; }
1282 float GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const;
1283 float GetTotalStatValue(Stats stat) const;
1284 float GetTotalAuraModValue(UnitMods unitMod) const;
1285 SpellSchools GetSpellSchoolByAuraGroup(UnitMods unitMod) const;
1286 Stats GetStatByAuraGroup(UnitMods unitMod) const;
1287 Powers GetPowerTypeByAuraGroup(UnitMods unitMod) const;
1288 bool CanModifyStats() const { return m_canModifyStats; }
1289 void SetCanModifyStats(bool modifyStats) { m_canModifyStats = modifyStats; }
1290 virtual bool UpdateStats(Stats stat) = 0;
1291 virtual bool UpdateAllStats() = 0;
1292 virtual void UpdateResistances(uint32 school) = 0;
1293 virtual void UpdateArmor() = 0;
1294 virtual void UpdateMaxHealth() = 0;
1295 virtual void UpdateMaxPower(Powers power) = 0;
1296 virtual void UpdateAttackPowerAndDamage(bool ranged = false) = 0;
1297 virtual void UpdateDamagePhysical(WeaponAttackType attType) = 0;
1298 float GetTotalAttackPowerValue(WeaponAttackType attType) const;
1299 float GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const;
1300 void SetBaseWeaponDamage(WeaponAttackType attType ,WeaponDamageRange damageRange, float value) { m_weaponDamage[attType][damageRange] = value; }
1302 bool isInFrontInMap(Unit const* target,float distance, float arc = M_PI) const;
1303 void SetInFront(Unit const* target);
1304 bool isInBackInMap(Unit const* target, float distance, float arc = M_PI) const;
1306 // Visibility system
1307 UnitVisibility GetVisibility() const { return m_Visibility; }
1308 void SetVisibility(UnitVisibility x);
1310 // common function for visibility checks for player/creatures with detection code
1311 bool isVisibleForOrDetect(Unit const* u, bool detect, bool inVisibleList = false, bool is3dDistance = true) const;
1312 bool canDetectInvisibilityOf(Unit const* u) const;
1313 void SetPhaseMask(uint32 newPhaseMask, bool update);// overwrite WorldObject::SetPhaseMask
1315 // virtual functions for all world objects types
1316 bool isVisibleForInState(Player const* u, bool inVisibleList) const;
1317 // function for low level grid visibility checks in player/creature cases
1318 virtual bool IsVisibleInGridForPlayer(Player* pl) const = 0;
1320 AuraList & GetSingleCastAuras() { return m_scAuras; }
1321 AuraList const& GetSingleCastAuras() const { return m_scAuras; }
1322 SpellImmuneList m_spellImmune[MAX_SPELL_IMMUNITY];
1324 // Threat related methods
1325 bool CanHaveThreatList() const;
1326 void AddThreat(Unit* pVictim, float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellEntry const *threatSpell = NULL);
1327 float ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL);
1328 void DeleteThreatList();
1329 bool SelectHostilTarget();
1330 void TauntApply(Unit* pVictim);
1331 void TauntFadeOut(Unit *taunter);
1332 ThreatManager& getThreatManager() { return m_ThreatManager; }
1333 void addHatedBy(HostilReference* pHostilReference) { m_HostilRefManager.insertFirst(pHostilReference); };
1334 void removeHatedBy(HostilReference* /*pHostilReference*/ ) { /* nothing to do yet */ }
1335 HostilRefManager& getHostilRefManager() { return m_HostilRefManager; }
1337 uint32 GetVisibleAura(uint8 slot)
1339 VisibleAuraMap::const_iterator itr = m_visibleAuras.find(slot);
1340 if(itr != m_visibleAuras.end())
1341 return itr->second;
1342 return 0;
1344 void SetVisibleAura(uint8 slot, uint32 spellid)
1346 if(spellid == 0)
1347 m_visibleAuras.erase(slot);
1348 else
1349 m_visibleAuras[slot] = spellid;
1351 VisibleAuraMap const *GetVisibleAuras() { return &m_visibleAuras; }
1352 uint8 GetVisibleAurasCount() { return m_visibleAuras.size(); }
1354 Aura* GetAura(uint32 spellId, uint32 effindex);
1355 Aura* GetAura(AuraType type, uint32 family, uint64 familyFlag, uint32 familyFlag2 = 0, uint64 casterGUID = 0);
1357 AuraMap & GetAuras() { return m_Auras; }
1358 AuraMap const& GetAuras() const { return m_Auras; }
1359 AuraList const& GetAurasByType(AuraType type) const { return m_modAuras[type]; }
1360 void ApplyAuraProcTriggerDamage(Aura* aura, bool apply);
1362 int32 GetTotalAuraModifier(AuraType auratype) const;
1363 float GetTotalAuraMultiplier(AuraType auratype) const;
1364 int32 GetMaxPositiveAuraModifier(AuraType auratype) const;
1365 int32 GetMaxNegativeAuraModifier(AuraType auratype) const;
1367 int32 GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1368 float GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1369 int32 GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1370 int32 GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1372 int32 GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1373 float GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const;
1374 int32 GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1375 int32 GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1377 Aura* GetDummyAura(uint32 spell_id) const;
1379 uint32 GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID); }
1380 void SetDisplayId(uint32 modelId);
1381 uint32 GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
1382 void SetNativeDisplayId(uint32 modelId) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, modelId); }
1383 void setTransForm(uint32 spellid) { m_transform = spellid;}
1384 uint32 getTransForm() const { return m_transform;}
1386 DynamicObject* GetDynObject(uint32 spellId, uint32 effIndex);
1387 DynamicObject* GetDynObject(uint32 spellId);
1388 void AddDynObject(DynamicObject* dynObj);
1389 void RemoveDynObject(uint32 spellid);
1390 void RemoveDynObjectWithGUID(uint64 guid) { m_dynObjGUIDs.remove(guid); }
1391 void RemoveAllDynObjects();
1393 GameObject* GetGameObject(uint32 spellId) const;
1394 void AddGameObject(GameObject* gameObj);
1395 void RemoveGameObject(GameObject* gameObj, bool del);
1396 void RemoveGameObject(uint32 spellid, bool del);
1397 void RemoveAllGameObjects();
1399 uint32 CalculateDamage(WeaponAttackType attType, bool normalized);
1400 float GetAPMultiplier(WeaponAttackType attType, bool normalized);
1401 void ModifyAuraState(AuraState flag, bool apply);
1402 bool HasAuraState(AuraState flag) const { return HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); }
1403 void UnsummonAllTotems();
1404 Unit* SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo = NULL);
1405 int32 SpellBaseDamageBonus(SpellSchoolMask schoolMask);
1406 int32 SpellBaseHealingBonus(SpellSchoolMask schoolMask);
1407 int32 SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1408 int32 SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1409 uint32 SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 damage, DamageEffectType damagetype, uint32 stack = 1);
1410 uint32 SpellHealingBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 healamount, DamageEffectType damagetype, uint32 stack = 1);
1411 bool isSpellBlocked(Unit *pVictim, SpellEntry const *spellProto, WeaponAttackType attackType = BASE_ATTACK);
1412 bool isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType = BASE_ATTACK);
1413 uint32 SpellCriticalDamageBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1414 uint32 SpellCriticalHealingBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1416 void SetLastManaUse(uint32 spellCastTime) { m_lastManaUse = spellCastTime; }
1417 bool IsUnderLastManaUseEffect() const;
1419 void SetContestedPvP(Player *attackedPlayer = NULL);
1421 void MeleeDamageBonus(Unit *pVictim, uint32 *damage, WeaponAttackType attType, SpellEntry const *spellProto = NULL);
1422 uint32 GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime );
1424 void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply);
1425 void ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply);
1426 virtual bool IsImmunedToSpell(SpellEntry const* spellInfo);
1427 // redefined in Creature
1428 bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask);
1429 virtual bool IsImmunedToSpellEffect(SpellEntry const* spellInfo, uint32 index) const;
1430 // redefined in Creature
1432 uint32 CalcArmorReducedDamage(Unit* pVictim, const uint32 damage);
1433 void CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist);
1435 void UpdateSpeed(UnitMoveType mtype, bool forced);
1436 float GetSpeed( UnitMoveType mtype ) const;
1437 float GetSpeedRate( UnitMoveType mtype ) const { return m_speed_rate[mtype]; }
1438 void SetSpeed(UnitMoveType mtype, float rate, bool forced = false);
1440 void SetHover(bool on);
1441 bool isHover() const { return HasAuraType(SPELL_AURA_HOVER); }
1443 void _RemoveAllAuraMods();
1444 void _ApplyAllAuraMods();
1446 int32 CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_index, int32 basePoints, Unit const* target);
1447 int32 CalculateSpellDuration(SpellEntry const* spellProto, uint8 effect_index, Unit const* target);
1448 float CalculateLevelPenalty(SpellEntry const* spellProto) const;
1450 void addFollower(FollowerReference* pRef) { m_FollowingRefManager.insertFirst(pRef); }
1451 void removeFollower(FollowerReference* /*pRef*/ ) { /* nothing to do yet */ }
1452 static Unit* GetUnit(WorldObject& object, uint64 guid);
1454 MotionMaster* GetMotionMaster() { return &i_motionMaster; }
1456 bool IsStopped() const { return !(hasUnitState(UNIT_STAT_MOVING)); }
1457 void StopMoving();
1459 void AddUnitMovementFlag(uint32 f) { m_unit_movement_flags |= f; }
1460 void RemoveUnitMovementFlag(uint32 f)
1462 uint32 oldval = m_unit_movement_flags;
1463 m_unit_movement_flags = oldval & ~f;
1465 uint32 HasUnitMovementFlag(uint32 f) const { return m_unit_movement_flags & f; }
1466 uint32 GetUnitMovementFlags() const { return m_unit_movement_flags; }
1467 void SetUnitMovementFlags(uint32 f) { m_unit_movement_flags = f; }
1469 void SetFeared(bool apply, uint64 casterGUID = 0, uint32 spellID = 0, uint32 time = 0);
1470 void SetConfused(bool apply, uint64 casterGUID = 0, uint32 spellID = 0);
1472 void AddComboPointHolder(uint32 lowguid) { m_ComboPointHolders.insert(lowguid); }
1473 void RemoveComboPointHolder(uint32 lowguid) { m_ComboPointHolders.erase(lowguid); }
1474 void ClearComboPointHolders();
1476 ///----------Pet responses methods-----------------
1477 void SendPetCastFail(uint32 spellid, SpellCastResult msg);
1478 void SendPetActionFeedback (uint8 msg);
1479 void SendPetTalk (uint32 pettalk);
1480 void SendPetSpellCooldown (uint32 spellid, time_t cooltime);
1481 void SendPetClearCooldown (uint32 spellid);
1482 void SendPetAIReaction(uint64 guid);
1483 ///----------End of Pet responses methods----------
1485 void propagateSpeedChange() { GetMotionMaster()->propagateSpeedChange(); }
1487 // reactive attacks
1488 void ClearAllReactives();
1489 void StartReactiveTimer( ReactiveType reactive ) { m_reactiveTimer[reactive] = REACTIVE_TIMER_START;}
1490 void UpdateReactives(uint32 p_time);
1492 // group updates
1493 void UpdateAuraForGroup(uint8 slot);
1495 // pet auras
1496 typedef std::set<PetAura const*> PetAuraSet;
1497 PetAuraSet m_petAuras;
1498 void AddPetAura(PetAura const* petSpell);
1499 void RemovePetAura(PetAura const* petSpell);
1501 protected:
1502 explicit Unit ();
1504 void _UpdateSpells(uint32 time);
1506 void _UpdateAutoRepeatSpell();
1507 bool m_AutoRepeatFirstCast;
1509 uint32 m_attackTimer[MAX_ATTACK];
1511 float m_createStats[MAX_STATS];
1513 AttackerSet m_attackers;
1514 Unit* m_attacking;
1516 DeathState m_deathState;
1518 AuraMap m_Auras;
1520 std::list<Aura *> m_scAuras; // casted singlecast auras
1522 typedef std::list<uint64> DynObjectGUIDs;
1523 DynObjectGUIDs m_dynObjGUIDs;
1525 typedef std::list<GameObject*> GameObjectList;
1526 GameObjectList m_gameObj;
1527 bool m_isSorted;
1528 uint32 m_transform;
1529 uint32 m_removedAuras;
1531 AuraList m_modAuras[TOTAL_AURAS];
1532 float m_auraModifiersGroup[UNIT_MOD_END][MODIFIER_TYPE_END];
1533 float m_weaponDamage[MAX_ATTACK][2];
1534 bool m_canModifyStats;
1535 //std::list< spellEffectPair > AuraSpells[TOTAL_AURAS]; // TODO: use this if ok for mem
1536 VisibleAuraMap m_visibleAuras;
1538 float m_speed_rate[MAX_MOVE_TYPE];
1540 CharmInfo *m_charmInfo;
1542 virtual SpellSchoolMask GetMeleeDamageSchoolMask() const;
1544 MotionMaster i_motionMaster;
1545 uint32 m_unit_movement_flags;
1547 uint32 m_reactiveTimer[MAX_REACTIVE];
1548 uint32 m_regenTimer;
1550 private:
1551 void SendAttackStop(Unit* victim); // only from AttackStop(Unit*)
1552 void SendAttackStart(Unit* pVictim); // only from Unit::AttackStart(Unit*)
1554 bool IsTriggeredAtSpellProcEvent(Unit *pVictim, Aura* aura, SpellEntry const* procSpell, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, bool isVictim, bool active, SpellProcEventEntry const*& spellProcEvent );
1555 bool HandleDummyAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1556 bool HandleHasteAuraProc( Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1557 bool HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlag, uint32 procEx, uint32 cooldown);
1558 bool HandleOverrideClassScriptAuraProc(Unit *pVictim, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 cooldown);
1559 bool HandleMeandingAuraProc(Aura* triggeredByAura);
1561 uint32 m_state; // Even derived shouldn't modify
1562 uint32 m_CombatTimer;
1563 uint32 m_lastManaUse; // msecs
1565 UnitVisibility m_Visibility;
1567 Diminishing m_Diminishing;
1568 // Manage all Units threatening us
1569 ThreatManager m_ThreatManager;
1570 // Manage all Units that are threatened by us
1571 HostilRefManager m_HostilRefManager;
1573 FollowerRefManager m_FollowingRefManager;
1575 ComboPointHolderSet m_ComboPointHolders;
1577 #endif