2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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"
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
88 SPELLMOD_DURATION
= 1,
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
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,
110 SPELLMOD_EFFECT3
= 23,
111 SPELLMOD_SPELL_BONUS_DAMAGE
= 24,
112 // spellmod 25 unused
113 SPELLMOD_FREQUENCY_OF_SUCCESS
= 26, // Only used with SPELL_AURA_ADD_PCT_MODIFIER and affects used on proc spells
114 SPELLMOD_MULTIPLE_VALUE
= 27,
115 SPELLMOD_RESIST_DISPEL_CHANCE
= 28
118 #define MAX_SPELLMOD 32
120 enum SpellFacingFlags
122 SPELL_FACING_FLAG_INFRONT
= 0x0001
125 #define BASE_MINDAMAGE 1.0f
126 #define BASE_MAXDAMAGE 2.0f
127 #define BASE_ATTACK_TIME 2000
129 // byte value (UNIT_FIELD_BYTES_1,0)
130 enum UnitStandStateType
132 UNIT_STAND_STATE_STAND
= 0,
133 UNIT_STAND_STATE_SIT
= 1,
134 UNIT_STAND_STATE_SIT_CHAIR
= 2,
135 UNIT_STAND_STATE_SLEEP
= 3,
136 UNIT_STAND_STATE_SIT_LOW_CHAIR
= 4,
137 UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
= 5,
138 UNIT_STAND_STATE_SIT_HIGH_CHAIR
= 6,
139 UNIT_STAND_STATE_DEAD
= 7,
140 UNIT_STAND_STATE_KNEEL
= 8,
141 UNIT_STAND_STATE_SUBMERGED
= 9
144 // byte flags value (UNIT_FIELD_BYTES_1,2)
147 UNIT_STAND_FLAGS_UNK1
= 0x01,
148 UNIT_STAND_FLAGS_CREEP
= 0x02,
149 UNIT_STAND_FLAGS_UNK3
= 0x04,
150 UNIT_STAND_FLAGS_UNK4
= 0x08,
151 UNIT_STAND_FLAGS_UNK5
= 0x10,
152 UNIT_STAND_FLAGS_ALL
= 0xFF
155 // byte flags value (UNIT_FIELD_BYTES_1,3)
156 enum UnitBytes1_Flags
158 UNIT_BYTE1_FLAG_ALWAYS_STAND
= 0x01,
159 UNIT_BYTE1_FLAG_UNK_2
= 0x02,
160 UNIT_BYTE1_FLAG_UNTRACKABLE
= 0x04,
161 UNIT_BYTE1_FLAG_ALL
= 0xFF
164 // byte value (UNIT_FIELD_BYTES_2,3)
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,
189 FORM_METAMORPHOSIS
= 0x16,
192 FORM_FLIGHT_EPIC
= 0x1B,
197 FORM_SPIRITOFREDEMPTION
= 0x20,
200 // byte value (UNIT_FIELD_BYTES_2,0)
203 SHEATH_STATE_UNARMED
= 0, // non prepared weapon
204 SHEATH_STATE_MELEE
= 1, // prepared melee weapon
205 SHEATH_STATE_RANGED
= 2 // prepared ranged weapon
208 #define MAX_SHEATH_STATE 3
210 // byte flags value (UNIT_FIELD_BYTES_2,1)
211 enum UnitPVPStateFlags
213 UNIT_BYTE2_FLAG_PVP
= 0x01,
214 UNIT_BYTE2_FLAG_UNK1
= 0x02,
215 UNIT_BYTE2_FLAG_FFA_PVP
= 0x04,
216 UNIT_BYTE2_FLAG_SANCTUARY
= 0x08,
217 UNIT_BYTE2_FLAG_UNK4
= 0x10,
218 UNIT_BYTE2_FLAG_UNK5
= 0x20,
219 UNIT_BYTE2_FLAG_UNK6
= 0x40,
220 UNIT_BYTE2_FLAG_UNK7
= 0x80
223 // byte flags value (UNIT_FIELD_BYTES_2,2)
226 UNIT_CAN_BE_RENAMED
= 0x01,
227 UNIT_CAN_BE_ABANDONED
= 0x02,
230 #define CREATURE_MAX_SPELLS 4
235 SINGLEHANDEDSWING
= 1,
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
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
268 HITINFO_BLOCK
= 0x00002000, // blocked damage
271 HITINFO_GLANCING
= 0x00010000,
272 HITINFO_CRUSHING
= 0x00020000,
273 HITINFO_NOACTION
= 0x00040000, // guessed
276 HITINFO_SWINGNOHITSOUND
= 0x00200000, // guessed
278 HITINFO_UNK3
= 0x00800000
281 //i would like to remove this: (it is defined in item.h
288 struct FactionTemplateEntry
;
291 struct SpellEntryExt
;
310 typedef std::list
<SpellImmune
> SpellImmuneList
;
312 enum UnitModifierType
318 MODIFIER_TYPE_END
= 4
321 enum WeaponDamageRange
327 enum DamageTypeToSchool
336 AURA_REMOVE_BY_DEFAULT
,
337 AURA_REMOVE_BY_STACK
, // at replace by similar aura
338 AURA_REMOVE_BY_CANCEL
,
339 AURA_REMOVE_BY_DISPEL
,
340 AURA_REMOVE_BY_DEATH
,
341 AURA_REMOVE_BY_DELETE
, // use for speedup and prevent unexpected effects at player logout/pet unsummon (must be used _only_ after save), delete.
346 UNIT_MOD_STAT_STRENGTH
, // UNIT_MOD_STAT_STRENGTH..UNIT_MOD_STAT_SPIRIT must be in existed order, it's accessed by index values of Stats enum.
347 UNIT_MOD_STAT_AGILITY
,
348 UNIT_MOD_STAT_STAMINA
,
349 UNIT_MOD_STAT_INTELLECT
,
350 UNIT_MOD_STAT_SPIRIT
,
352 UNIT_MOD_MANA
, // UNIT_MOD_MANA..UNIT_MOD_RUNIC_POWER must be in existed order, it's accessed by index values of Powers enum.
358 UNIT_MOD_RUNIC_POWER
,
359 UNIT_MOD_ARMOR
, // UNIT_MOD_ARMOR..UNIT_MOD_RESISTANCE_ARCANE must be in existed order, it's accessed by index values of SpellSchools enum.
360 UNIT_MOD_RESISTANCE_HOLY
,
361 UNIT_MOD_RESISTANCE_FIRE
,
362 UNIT_MOD_RESISTANCE_NATURE
,
363 UNIT_MOD_RESISTANCE_FROST
,
364 UNIT_MOD_RESISTANCE_SHADOW
,
365 UNIT_MOD_RESISTANCE_ARCANE
,
366 UNIT_MOD_ATTACK_POWER
,
367 UNIT_MOD_ATTACK_POWER_RANGED
,
368 UNIT_MOD_DAMAGE_MAINHAND
,
369 UNIT_MOD_DAMAGE_OFFHAND
,
370 UNIT_MOD_DAMAGE_RANGED
,
373 UNIT_MOD_STAT_START
= UNIT_MOD_STAT_STRENGTH
,
374 UNIT_MOD_STAT_END
= UNIT_MOD_STAT_SPIRIT
+ 1,
375 UNIT_MOD_RESISTANCE_START
= UNIT_MOD_ARMOR
,
376 UNIT_MOD_RESISTANCE_END
= UNIT_MOD_RESISTANCE_ARCANE
+ 1,
377 UNIT_MOD_POWER_START
= UNIT_MOD_MANA
,
378 UNIT_MOD_POWER_END
= UNIT_MOD_RUNIC_POWER
+ 1
384 RANGED_CRIT_PERCENTAGE
,
385 OFFHAND_CRIT_PERCENTAGE
,
396 #define MOD_END (PCT_MOD+1)
410 UNIT_STAT_DIED
= 0x0001,
411 UNIT_STAT_MELEE_ATTACKING
= 0x0002, // player is melee attacking someone
412 //UNIT_STAT_MELEE_ATTACK_BY = 0x0004, // player is melee attack by someone
413 UNIT_STAT_STUNNED
= 0x0008,
414 UNIT_STAT_ROAMING
= 0x0010,
415 UNIT_STAT_CHASE
= 0x0020,
416 //UNIT_STAT_SEARCHING = 0x0040,
417 UNIT_STAT_FLEEING
= 0x0080,
418 UNIT_STAT_MOVING
= (UNIT_STAT_ROAMING
| UNIT_STAT_CHASE
| UNIT_STAT_FLEEING
),
419 UNIT_STAT_IN_FLIGHT
= 0x0100, // player is in flight mode
420 UNIT_STAT_FOLLOW
= 0x0200,
421 UNIT_STAT_ROOT
= 0x0400,
422 UNIT_STAT_CONFUSED
= 0x0800,
423 UNIT_STAT_DISTRACTED
= 0x1000,
424 UNIT_STAT_ISOLATED
= 0x2000, // area auras do not affect other players
425 UNIT_STAT_ATTACK_PLAYER
= 0x4000,
426 UNIT_STAT_ALL_STATE
= 0xffff //(UNIT_STAT_STOPPED | UNIT_STAT_MOVING | UNIT_STAT_IN_COMBAT | UNIT_STAT_IN_FLIGHT)
438 MOVE_FLIGHT_BACK
= 7,
442 #define MAX_MOVE_TYPE 9
444 extern float baseMoveSpeed
[MAX_MOVE_TYPE
];
449 CR_DEFENSE_SKILL
= 1,
459 CR_HIT_TAKEN_MELEE
= 11,
460 CR_HIT_TAKEN_RANGED
= 12,
461 CR_HIT_TAKEN_SPELL
= 13,
462 CR_CRIT_TAKEN_MELEE
= 14,
463 CR_CRIT_TAKEN_RANGED
= 15,
464 CR_CRIT_TAKEN_SPELL
= 16,
466 CR_HASTE_RANGED
= 18,
468 CR_WEAPON_SKILL_MAINHAND
= 20,
469 CR_WEAPON_SKILL_OFFHAND
= 21,
470 CR_WEAPON_SKILL_RANGED
= 22,
472 CR_ARMOR_PENETRATION
= 24
475 #define MAX_COMBAT_RATING 25
477 enum DamageEffectType
479 DIRECT_DAMAGE
= 0, // used for normal weapon damage (not for class abilities or spells)
480 SPELL_DIRECT_DAMAGE
= 1, // spell/class abilities damage
483 NODAMAGE
= 4, // used also in case when damage applied to health but not applied to spell channelInterruptFlags/etc
487 /// internal used flags for marking special auras - for example some dummy-auras
490 UNIT_AURAFLAG_ALIVE_INVISIBLE
= 0x1, // aura which makes unit invisible for alive
495 VISIBILITY_OFF
= 0, // absolute, not detectable, GM-like, can see all other
497 VISIBILITY_GROUP_STEALTH
= 2, // detect chance, seen and can see group members
498 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)
499 VISIBILITY_GROUP_NO_DETECT
= 4, // state just at stealth apply for update Grid state. Don't remove, otherwise stealth spells will break
500 VISIBILITY_RESPAWN
= 5 // special totally not detectable visibility for force delete object at respawn command
503 // Value masks for UNIT_FIELD_FLAGS
506 UNIT_FLAG_UNK_0
= 0x00000001,
507 UNIT_FLAG_NON_ATTACKABLE
= 0x00000002, // not attackable
508 UNIT_FLAG_DISABLE_MOVE
= 0x00000004,
509 UNIT_FLAG_PVP_ATTACKABLE
= 0x00000008, // allow apply pvp rules to attackable state in addition to faction dependent state
510 UNIT_FLAG_RENAME
= 0x00000010,
511 UNIT_FLAG_PREPARATION
= 0x00000020, // don't take reagents for spells with SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
512 UNIT_FLAG_UNK_6
= 0x00000040,
513 UNIT_FLAG_NOT_ATTACKABLE_1
= 0x00000080, // ?? (UNIT_FLAG_PVP_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1) is NON_PVP_ATTACKABLE
514 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.
515 UNIT_FLAG_UNK_9
= 0x00000200, // 3.0.3 - makes you unable to attack everything
516 UNIT_FLAG_LOOTING
= 0x00000400, // loot animation
517 UNIT_FLAG_PET_IN_COMBAT
= 0x00000800, // in combat?, 2.0.8
518 UNIT_FLAG_PVP
= 0x00001000, // changed in 3.0.3
519 UNIT_FLAG_SILENCED
= 0x00002000, // silenced, 2.1.1
520 UNIT_FLAG_UNK_14
= 0x00004000, // 2.0.8
521 UNIT_FLAG_UNK_15
= 0x00008000,
522 UNIT_FLAG_UNK_16
= 0x00010000, // removes attackable icon
523 UNIT_FLAG_PACIFIED
= 0x00020000, // 3.0.3 ok
524 UNIT_FLAG_STUNNED
= 0x00040000, // 3.0.3 ok
525 UNIT_FLAG_IN_COMBAT
= 0x00080000,
526 UNIT_FLAG_TAXI_FLIGHT
= 0x00100000, // disable casting at client side spell not allowed by taxi flight (mounted?), probably used with 0x4 flag
527 UNIT_FLAG_DISARMED
= 0x00200000, // 3.0.3, disable melee spells casting..., "Required melee weapon" added to melee spells tooltip.
528 UNIT_FLAG_CONFUSED
= 0x00400000,
529 UNIT_FLAG_FLEEING
= 0x00800000,
530 UNIT_FLAG_PLAYER_CONTROLLED
= 0x01000000, // used in spell Eyes of the Beast for pet... let attack by controlled creature
531 UNIT_FLAG_NOT_SELECTABLE
= 0x02000000,
532 UNIT_FLAG_SKINNABLE
= 0x04000000,
533 UNIT_FLAG_MOUNT
= 0x08000000,
534 UNIT_FLAG_UNK_28
= 0x10000000,
535 UNIT_FLAG_UNK_29
= 0x20000000, // used in Feing Death spell
536 UNIT_FLAG_SHEATHE
= 0x40000000,
537 UNIT_FLAG_UNK_31
= 0x80000000 // set skinnable icon and also changes color of portrait
540 // Value masks for UNIT_FIELD_FLAGS_2
543 UNIT_FLAG2_FEIGN_DEATH
= 0x00000001,
544 UNIT_FLAG2_UNK1
= 0x00000002, // Hide unit model (show only player equip)
545 UNIT_FLAG2_COMPREHEND_LANG
= 0x00000008,
546 UNIT_FLAG2_FORCE_MOVE
= 0x00000040,
547 UNIT_FLAG2_REGENERATE_POWER
= 0x00000800
550 /// Non Player Character flags
553 UNIT_NPC_FLAG_NONE
= 0x00000000,
554 UNIT_NPC_FLAG_GOSSIP
= 0x00000001, // 100%
555 UNIT_NPC_FLAG_QUESTGIVER
= 0x00000002, // guessed, probably ok
556 UNIT_NPC_FLAG_UNK1
= 0x00000004,
557 UNIT_NPC_FLAG_UNK2
= 0x00000008,
558 UNIT_NPC_FLAG_TRAINER
= 0x00000010, // 100%
559 UNIT_NPC_FLAG_TRAINER_CLASS
= 0x00000020, // 100%
560 UNIT_NPC_FLAG_TRAINER_PROFESSION
= 0x00000040, // 100%
561 UNIT_NPC_FLAG_VENDOR
= 0x00000080, // 100%
562 UNIT_NPC_FLAG_VENDOR_AMMO
= 0x00000100, // 100%, general goods vendor
563 UNIT_NPC_FLAG_VENDOR_FOOD
= 0x00000200, // 100%
564 UNIT_NPC_FLAG_VENDOR_POISON
= 0x00000400, // guessed
565 UNIT_NPC_FLAG_VENDOR_REAGENT
= 0x00000800, // 100%
566 UNIT_NPC_FLAG_REPAIR
= 0x00001000, // 100%
567 UNIT_NPC_FLAG_FLIGHTMASTER
= 0x00002000, // 100%
568 UNIT_NPC_FLAG_SPIRITHEALER
= 0x00004000, // guessed
569 UNIT_NPC_FLAG_SPIRITGUIDE
= 0x00008000, // guessed
570 UNIT_NPC_FLAG_INNKEEPER
= 0x00010000, // 100%
571 UNIT_NPC_FLAG_BANKER
= 0x00020000, // 100%
572 UNIT_NPC_FLAG_PETITIONER
= 0x00040000, // 100% 0xC0000 = guild petitions, 0x40000 = arena team petitions
573 UNIT_NPC_FLAG_TABARDDESIGNER
= 0x00080000, // 100%
574 UNIT_NPC_FLAG_BATTLEMASTER
= 0x00100000, // 100%
575 UNIT_NPC_FLAG_AUCTIONEER
= 0x00200000, // 100%
576 UNIT_NPC_FLAG_STABLEMASTER
= 0x00400000, // 100%
577 UNIT_NPC_FLAG_GUILD_BANKER
= 0x00800000, // cause client to send 997 opcode
578 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
579 UNIT_NPC_FLAG_GUARD
= 0x10000000, // custom flag for guards
582 // used in SMSG_MONSTER_MOVE
583 enum MonsterMovementFlags
585 MONSTER_MOVE_NONE
= 0x00000000,
586 MONSTER_MOVE_FORWARD
= 0x00000001,
587 MONSTER_MOVE_BACKWARD
= 0x00000002,
588 MONSTER_MOVE_STRAFE_LEFT
= 0x00000004,
589 MONSTER_MOVE_STRAFE_RIGHT
= 0x00000008,
590 MONSTER_MOVE_LEFT
= 0x00000010, // turn
591 MONSTER_MOVE_RIGHT
= 0x00000020, // turn
592 MONSTER_MOVE_PITCH_UP
= 0x00000040,
593 MONSTER_MOVE_PITCH_DOWN
= 0x00000080,
594 MONSTER_MOVE_TELEPORT
= 0x00000100,
595 MONSTER_MOVE_TELEPORT2
= 0x00000200,
596 MONSTER_MOVE_LEVITATING
= 0x00000400,
597 MONSTER_MOVE_UNK1
= 0x00000800, // float+uint32
598 MONSTER_MOVE_WALK
= 0x00001000, // run2?
599 MONSTER_MOVE_SPLINE
= 0x00002000, // spline n*(float x,y,z)
600 // 0x4000, 0x8000, 0x10000, 0x20000 run
601 MONSTER_MOVE_SPLINE2
= 0x00040000, // spline n*(float x,y,z)
602 MONSTER_MOVE_UNK2
= 0x00080000, // used for flying mobs
603 MONSTER_MOVE_UNK3
= 0x00100000, // used for flying mobs
604 MONSTER_MOVE_UNK4
= 0x00200000, // uint8+uint32
605 MONSTER_MOVE_UNK5
= 0x00400000, // run in place, then teleport to final point
606 MONSTER_MOVE_UNK6
= 0x00800000, // teleport
607 MONSTER_MOVE_UNK7
= 0x01000000, // run
608 MONSTER_MOVE_FLY
= 0x02000000, // swimming/flying (depends on mob?)
609 MONSTER_MOVE_UNK9
= 0x04000000, // run
610 MONSTER_MOVE_UNK10
= 0x08000000, // run
611 MONSTER_MOVE_UNK11
= 0x10000000, // run
612 MONSTER_MOVE_UNK12
= 0x20000000, // run
613 MONSTER_MOVE_UNK13
= 0x40000000, // levitating
616 MONSTER_MOVE_SPLINE_FLY
= 0x00003000, // fly by points
619 enum DiminishingLevels
621 DIMINISHING_LEVEL_1
= 0,
622 DIMINISHING_LEVEL_2
= 1,
623 DIMINISHING_LEVEL_3
= 2,
624 DIMINISHING_LEVEL_IMMUNE
= 3
627 struct DiminishingReturn
629 DiminishingReturn(DiminishingGroup group
, uint32 t
, uint32 count
)
630 : DRGroup(group
), stack(0), hitTime(t
), hitCount(count
)
633 DiminishingGroup DRGroup
:16;
641 MELEE_HIT_EVADE
, MELEE_HIT_MISS
, MELEE_HIT_DODGE
, MELEE_HIT_BLOCK
, MELEE_HIT_PARRY
,
642 MELEE_HIT_GLANCING
, MELEE_HIT_CRIT
, MELEE_HIT_CRUSHING
, MELEE_HIT_NORMAL
647 CleanDamage(uint32 _damage
, WeaponAttackType _attackType
, MeleeHitOutcome _hitOutCome
) :
648 damage(_damage
), attackType(_attackType
), hitOutCome(_hitOutCome
) {}
651 WeaponAttackType attackType
;
652 MeleeHitOutcome hitOutCome
;
655 // Struct for use in Unit::CalculateMeleeDamage
656 // Need create structure like in SMSG_ATTACKERSTATEUPDATE opcode
657 struct CalcDamageInfo
659 Unit
*attacker
; // Attacker
660 Unit
*target
; // Target for damage
661 SpellSchoolMask damageSchoolMask
;
665 uint32 blocked_amount
;
669 WeaponAttackType attackType
; //
673 uint32 cleanDamage
; // Used only for rage calculation
674 MeleeHitOutcome hitOutCome
; // TODO: remove this field (need use TargetState)
677 // Spell damage info structure based on structure sending in SMSG_SPELLNONMELEEDAMAGELOG opcode
678 struct SpellNonMeleeDamage
{
679 SpellNonMeleeDamage(Unit
*_attacker
, Unit
*_target
, uint32 _SpellID
, uint32 _schoolMask
)
680 : target(_target
), attacker(_attacker
), SpellID(_SpellID
), damage(0), overkill(0), schoolMask(_schoolMask
),
681 absorb(0), resist(0), physicalLog(false), unused(false), blocked(0), HitInfo(0), cleanDamage(0)
700 struct SpellPeriodicAuraLogInfo
702 SpellPeriodicAuraLogInfo(Aura
*_aura
, uint32 _damage
, uint32 _overDamage
, uint32 _absorb
, uint32 _resist
, float _multiplier
, bool _critical
= false)
703 : aura(_aura
), damage(_damage
), overDamage(_overDamage
), absorb(_absorb
), resist(_resist
), multiplier(_multiplier
), critical(_critical
) {}
707 uint32 overDamage
; // overkill/overheal
714 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
);
716 #define MAX_DECLINED_NAME_CASES 5
720 std::string name
[MAX_DECLINED_NAME_CASES
];
723 enum CurrentSpellTypes
725 CURRENT_MELEE_SPELL
= 0,
726 CURRENT_GENERIC_SPELL
= 1,
727 CURRENT_AUTOREPEAT_SPELL
= 2,
728 CURRENT_CHANNELED_SPELL
= 3
731 #define CURRENT_FIRST_NON_MELEE_SPELL 1
732 #define CURRENT_MAX_SPELL 4
737 ACT_PASSIVE
= 0x01, // 0x01 - passive
738 ACT_DISABLED
= 0x81, // 0x80 - castable
739 ACT_ENABLED
= 0xC1, // 0x40 | 0x80 - auto cast + castable
740 ACT_COMMAND
= 0x07, // 0x01 | 0x02 | 0x04
741 ACT_REACTION
= 0x06, // 0x02 | 0x04
742 ACT_DECIDE
= 0x00 // custom
760 #define UNIT_ACTION_BUTTON_ACTION(X) (uint32(X) & 0x00FFFFFF)
761 #define UNIT_ACTION_BUTTON_TYPE(X) ((uint32(X) & 0xFF000000) >> 24)
762 #define MAX_UNIT_ACTION_BUTTON_ACTION_VALUE (0x00FFFFFF+1)
763 #define MAKE_UNIT_ACTION_BUTTON(A,T) (uint32(A) | (uint32(T) << 24))
765 struct UnitActionBarEntry
767 UnitActionBarEntry() : packedData(uint32(ACT_DISABLED
) << 24) {}
772 ActiveStates
GetType() const { return ActiveStates(UNIT_ACTION_BUTTON_TYPE(packedData
)); }
773 uint32
GetAction() const { return UNIT_ACTION_BUTTON_ACTION(packedData
); }
774 bool IsActionBarForSpell() const
776 ActiveStates Type
= GetType();
777 return Type
== ACT_DISABLED
|| Type
== ACT_ENABLED
|| Type
== ACT_PASSIVE
;
780 void SetActionAndType(uint32 action
, ActiveStates type
)
782 packedData
= MAKE_UNIT_ACTION_BUTTON(action
,type
);
785 void SetType(ActiveStates type
)
787 packedData
= MAKE_UNIT_ACTION_BUTTON(UNIT_ACTION_BUTTON_ACTION(packedData
),type
);
790 void SetAction(uint32 action
)
792 packedData
= (packedData
& 0xFF000000) | UNIT_ACTION_BUTTON_ACTION(action
);
796 typedef UnitActionBarEntry CharmSpellEntry
;
800 ACTION_BAR_INDEX_START
= 0,
801 ACTION_BAR_INDEX_PET_SPELL_START
= 3,
802 ACTION_BAR_INDEX_PET_SPELL_END
= 7,
803 ACTION_BAR_INDEX_END
= 10,
806 #define MAX_UNIT_ACTION_BAR_INDEX (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START)
811 explicit CharmInfo(Unit
* unit
);
812 uint32
GetPetNumber() const { return m_petnumber
; }
813 void SetPetNumber(uint32 petnumber
, bool statwindow
);
815 void SetCommandState(CommandStates st
) { m_CommandState
= st
; }
816 CommandStates
GetCommandState() { return m_CommandState
; }
817 bool HasCommandState(CommandStates state
) { return (m_CommandState
== state
); }
818 void SetReactState(ReactStates st
) { m_reactState
= st
; }
819 ReactStates
GetReactState() { return m_reactState
; }
820 bool HasReactState(ReactStates state
) { return (m_reactState
== state
); }
822 void InitPossessCreateSpells();
823 void InitCharmCreateSpells();
824 void InitPetActionBar();
825 void InitEmptyActionBar();
827 //return true if successful
828 bool AddSpellToActionBar(uint32 spellid
, ActiveStates newstate
= ACT_DECIDE
);
829 bool RemoveSpellFromActionBar(uint32 spell_id
);
830 void LoadPetActionBar(const std::string
& data
);
831 void BuildActionBar(WorldPacket
* data
);
832 void SetSpellAutocast(uint32 spell_id
, bool state
);
833 void SetActionBar(uint8 index
, uint32 spellOrAction
,ActiveStates type
)
835 PetActionBar
[index
].SetActionAndType(spellOrAction
,type
);
837 UnitActionBarEntry
const* GetActionBarEntry(uint8 index
) const { return &(PetActionBar
[index
]); }
839 void ToggleCreatureAutocast(uint32 spellid
, bool apply
);
841 CharmSpellEntry
* GetCharmSpell(uint8 index
) { return &(m_charmspells
[index
]); }
845 UnitActionBarEntry PetActionBar
[MAX_UNIT_ACTION_BAR_INDEX
];
846 CharmSpellEntry m_charmspells
[CREATURE_MAX_SPELLS
];
847 CommandStates m_CommandState
;
848 ReactStates m_reactState
;
852 // for clearing special attacks
853 #define REACTIVE_TIMER_START 4000
857 REACTIVE_DEFENSE
= 0,
858 REACTIVE_HUNTER_PARRY
= 1,
859 REACTIVE_OVERPOWER
= 2
862 #define MAX_REACTIVE 3
865 typedef std::set
<uint64
> GuardianPetList
;
867 // delay time next attack to prevent client attack animation problems
868 #define ATTACK_DISPLAY_DELAY 200
869 #define MAX_PLAYER_STEALTH_DETECT_RANGE 45.0f // max distance for detection targets by player
871 // Regeneration defines
872 #define REGEN_TIME_FULL 2000 // For this time difference is computed regen value
873 #define REGEN_TIME_PRECISE 500 // Used in Spell::CheckPower for precise regeneration in spell cast time
875 struct SpellProcEventEntry
; // used only privately
877 class MANGOS_DLL_SPEC Unit
: public WorldObject
880 typedef std::set
<Unit
*> AttackerSet
;
881 typedef std::pair
<uint32
, uint8
> spellEffectPair
;
882 typedef std::multimap
< spellEffectPair
, Aura
*> AuraMap
;
883 typedef std::list
<Aura
*> AuraList
;
884 typedef std::list
<DiminishingReturn
> Diminishing
;
885 typedef std::set
<uint32
> ComboPointHolderSet
;
886 typedef std::map
<uint8
, uint32
> VisibleAuraMap
;
891 void RemoveFromWorld();
893 void CleanupsBeforeDelete(); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units)
895 DiminishingLevels
GetDiminishing(DiminishingGroup group
);
896 void IncrDiminishing(DiminishingGroup group
);
897 void ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
, DiminishingLevels Level
, int32 limitduration
);
898 void ApplyDiminishingAura(DiminishingGroup group
, bool apply
);
899 void ClearDiminishings() { m_Diminishing
.clear(); }
901 virtual void Update( uint32 time
);
903 void setAttackTimer(WeaponAttackType type
, uint32 time
) { m_attackTimer
[type
] = time
; }
904 void resetAttackTimer(WeaponAttackType type
= BASE_ATTACK
);
905 uint32
getAttackTimer(WeaponAttackType type
) const { return m_attackTimer
[type
]; }
906 bool isAttackReady(WeaponAttackType type
= BASE_ATTACK
) const { return m_attackTimer
[type
] == 0; }
907 bool haveOffhandWeapon() const;
908 bool canReachWithAttack(Unit
*pVictim
) const;
909 uint32 m_extraAttacks
;
911 void _addAttacker(Unit
*pAttacker
) // must be called only from Unit::Attack(Unit*)
913 AttackerSet::const_iterator itr
= m_attackers
.find(pAttacker
);
914 if(itr
== m_attackers
.end())
915 m_attackers
.insert(pAttacker
);
917 void _removeAttacker(Unit
*pAttacker
) // must be called only from Unit::AttackStop()
919 m_attackers
.erase(pAttacker
);
921 Unit
* getAttackerForHelper() // If someone wants to help, who to give them
923 if (getVictim() != NULL
)
926 if (!m_attackers
.empty())
927 return *(m_attackers
.begin());
931 bool Attack(Unit
*victim
, bool meleeAttack
);
932 void CastStop(uint32 except_spellid
= 0);
933 bool AttackStop(bool targetSwitch
= false);
934 void RemoveAllAttackers();
935 AttackerSet
const& getAttackers() const { return m_attackers
; }
936 bool isAttackingPlayer() const;
937 Unit
* getVictim() const { return m_attacking
; }
938 void CombatStop(bool includingCast
= false);
939 void CombatStopWithPets(bool includingCast
= false);
940 void StopAttackFaction(uint32 faction_id
);
941 Unit
* SelectNearbyTarget(Unit
* except
= NULL
) const;
942 bool hasNegativeAuraWithInterruptFlag(uint32 flag
);
943 void SendMeleeAttackStop(Unit
* victim
);
944 void SendMeleeAttackStart(Unit
* pVictim
);
946 void addUnitState(uint32 f
) { m_state
|= f
; }
947 bool hasUnitState(const uint32 f
) const { return (m_state
& f
); }
948 void clearUnitState(uint32 f
) { m_state
&= ~f
; }
949 bool CanFreeMove() const
951 return !hasUnitState(UNIT_STAT_CONFUSED
| UNIT_STAT_FLEEING
| UNIT_STAT_IN_FLIGHT
|
952 UNIT_STAT_ROOT
| UNIT_STAT_STUNNED
| UNIT_STAT_DISTRACTED
| UNIT_STAT_DIED
) && GetOwnerGUID()==0;
955 uint32
getLevel() const { return GetUInt32Value(UNIT_FIELD_LEVEL
); }
956 virtual uint32
getLevelForTarget(Unit
const* /*target*/) const { return getLevel(); }
957 void SetLevel(uint32 lvl
);
958 uint8
getRace() const { return GetByteValue(UNIT_FIELD_BYTES_0
, 0); }
959 uint32
getRaceMask() const { return 1 << (getRace()-1); }
960 uint8
getClass() const { return GetByteValue(UNIT_FIELD_BYTES_0
, 1); }
961 uint32
getClassMask() const { return 1 << (getClass()-1); }
962 uint8
getGender() const { return GetByteValue(UNIT_FIELD_BYTES_0
, 2); }
964 float GetStat(Stats stat
) const { return float(GetUInt32Value(UNIT_FIELD_STAT0
+stat
)); }
965 void SetStat(Stats stat
, int32 val
) { SetStatInt32Value(UNIT_FIELD_STAT0
+stat
, val
); }
966 uint32
GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL
) ; }
967 void SetArmor(int32 val
) { SetResistance(SPELL_SCHOOL_NORMAL
, val
); }
969 uint32
GetResistance(SpellSchools school
) const { return GetUInt32Value(UNIT_FIELD_RESISTANCES
+school
); }
970 void SetResistance(SpellSchools school
, int32 val
) { SetStatInt32Value(UNIT_FIELD_RESISTANCES
+school
,val
); }
972 uint32
GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH
); }
973 uint32
GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH
); }
974 void SetHealth( uint32 val
);
975 void SetMaxHealth(uint32 val
);
976 int32
ModifyHealth(int32 val
);
978 Powers
getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0
, 3)); }
979 void setPowerType(Powers power
);
980 uint32
GetPower( Powers power
) const { return GetUInt32Value(UNIT_FIELD_POWER1
+power
); }
981 uint32
GetMaxPower(Powers power
) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1
+power
); }
982 void SetPower( Powers power
, uint32 val
);
983 void SetMaxPower(Powers power
, uint32 val
);
984 int32
ModifyPower(Powers power
, int32 val
);
985 void ApplyPowerMod(Powers power
, uint32 val
, bool apply
);
986 void ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
);
988 uint32
GetAttackTime(WeaponAttackType att
) const { return (uint32
)(GetFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
)/m_modAttackSpeedPct
[att
]); }
989 void SetAttackTime(WeaponAttackType att
, uint32 val
) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
*m_modAttackSpeedPct
[att
]); }
990 void ApplyAttackTimePercentMod(WeaponAttackType att
,float val
, bool apply
);
991 void ApplyCastTimePercentMod(float val
, bool apply
);
993 SheathState
GetSheath() const { return SheathState(GetByteValue(UNIT_FIELD_BYTES_2
, 0)); }
994 virtual void SetSheath( SheathState sheathed
) { SetByteValue(UNIT_FIELD_BYTES_2
, 0, sheathed
); }
996 // faction template id
997 uint32
getFaction() const { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
); }
998 void setFaction(uint32 faction
) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
, faction
); }
999 FactionTemplateEntry
const* getFactionTemplateEntry() const;
1000 bool IsHostileTo(Unit
const* unit
) const;
1001 bool IsHostileToPlayers() const;
1002 bool IsFriendlyTo(Unit
const* unit
) const;
1003 bool IsNeutralToAll() const;
1004 bool IsContestedGuard() const
1006 if(FactionTemplateEntry
const* entry
= getFactionTemplateEntry())
1007 return entry
->IsContestedGuardFaction();
1011 bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
); }
1012 void SetPvP(bool state
);
1013 bool IsFFAPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
); }
1014 void SetFFAPvP(bool state
);
1015 uint32
GetCreatureType() const;
1016 uint32
GetCreatureTypeMask() const
1018 uint32 creatureType
= GetCreatureType();
1019 return (creatureType
>= 1) ? (1 << (creatureType
- 1)) : 0;
1022 uint8
getStandState() const { return GetByteValue(UNIT_FIELD_BYTES_1
, 0); }
1023 bool IsSitState() const;
1024 bool IsStandState() const;
1025 void SetStandState(uint8 state
);
1027 void SetStandFlags(uint8 flags
) { SetByteFlag(UNIT_FIELD_BYTES_1
, 2,flags
); }
1028 void RemoveStandFlags(uint8 flags
) { RemoveByteFlag(UNIT_FIELD_BYTES_1
, 2,flags
); }
1030 bool IsMounted() const { return HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
); }
1031 uint32
GetMountID() const { return GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
); }
1032 void Mount(uint32 mount
, uint32 spellId
= 0);
1035 uint16
GetMaxSkillValueForLevel(Unit
const* target
= NULL
) const { return (target
? getLevelForTarget(target
) : getLevel()) * 5; }
1036 void DealDamageMods(Unit
*pVictim
, uint32
&damage
, uint32
* absorb
);
1037 uint32
DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
);
1038 int32
DealHeal(Unit
*pVictim
, uint32 addhealth
, SpellEntry
const *spellProto
, bool critical
= false);
1040 void ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procEx
, uint32 amount
, WeaponAttackType attType
= BASE_ATTACK
, SpellEntry
const *procSpell
= NULL
);
1041 void ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
);
1043 void HandleEmoteCommand(uint32 anim_id
);
1044 void AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
= BASE_ATTACK
, bool extra
= false );
1046 float MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const;
1048 void CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
= BASE_ATTACK
);
1049 void DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
);
1051 void CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
= BASE_ATTACK
);
1052 void DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
);
1054 // player or player's pet resilience (-1%)
1055 float GetMeleeCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_MELEE
); }
1056 float GetRangedCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_RANGED
); }
1057 float GetSpellCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_SPELL
); }
1059 // player or player's pet resilience (-1%)
1060 uint32
GetMeleeCritDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE
, 2.2f
, 33.0f
, damage
); }
1061 uint32
GetRangedCritDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_RANGED
, 2.2f
, 33.0f
, damage
); }
1062 uint32
GetSpellCritDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_SPELL
, 2.2f
, 33.0f
, damage
); }
1064 // player or player's pet resilience (-1%), cap 100%
1065 uint32
GetMeleeDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE
, 1.0f
, 100.0f
, damage
); }
1066 uint32
GetRangedDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE
, 1.0f
, 100.0f
, damage
); }
1067 uint32
GetSpellDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE
, 1.0f
, 100.0f
, damage
); }
1069 float MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
);
1070 SpellMissInfo
MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
);
1071 SpellMissInfo
MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
);
1072 SpellMissInfo
SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool canReflect
= false);
1074 float GetUnitDodgeChance() const;
1075 float GetUnitParryChance() const;
1076 float GetUnitBlockChance() const;
1077 float GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const;
1079 virtual uint32
GetShieldBlockValue() const =0;
1080 uint32
GetUnitMeleeSkill(Unit
const* target
= NULL
) const { return (target
? getLevelForTarget(target
) : getLevel()) * 5; }
1081 uint32
GetDefenseSkillValue(Unit
const* target
= NULL
) const;
1082 uint32
GetWeaponSkillValue(WeaponAttackType attType
, Unit
const* target
= NULL
) const;
1083 float GetWeaponProcChance() const;
1084 float GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const;
1086 MeleeHitOutcome
RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
) const;
1087 MeleeHitOutcome
RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const;
1089 bool isVendor() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_VENDOR
); }
1090 bool isTrainer() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_TRAINER
); }
1091 bool isQuestGiver() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_QUESTGIVER
); }
1092 bool isGossip() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_GOSSIP
); }
1093 bool isTaxi() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_FLIGHTMASTER
); }
1094 bool isGuildMaster() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_PETITIONER
); }
1095 bool isBattleMaster() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_BATTLEMASTER
); }
1096 bool isBanker() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_BANKER
); }
1097 bool isInnkeeper() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_INNKEEPER
); }
1098 bool isSpiritHealer() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPIRITHEALER
); }
1099 bool isSpiritGuide() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPIRITGUIDE
); }
1100 bool isTabardDesigner()const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_TABARDDESIGNER
); }
1101 bool isAuctioner() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_AUCTIONEER
); }
1102 bool isArmorer() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_REPAIR
); }
1103 bool isServiceProvider() const
1105 return HasFlag( UNIT_NPC_FLAGS
,
1106 UNIT_NPC_FLAG_VENDOR
| UNIT_NPC_FLAG_TRAINER
| UNIT_NPC_FLAG_FLIGHTMASTER
|
1107 UNIT_NPC_FLAG_PETITIONER
| UNIT_NPC_FLAG_BATTLEMASTER
| UNIT_NPC_FLAG_BANKER
|
1108 UNIT_NPC_FLAG_INNKEEPER
| UNIT_NPC_FLAG_GUARD
| UNIT_NPC_FLAG_SPIRITHEALER
|
1109 UNIT_NPC_FLAG_SPIRITGUIDE
| UNIT_NPC_FLAG_TABARDDESIGNER
| UNIT_NPC_FLAG_AUCTIONEER
);
1111 bool isSpiritService() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPIRITHEALER
| UNIT_NPC_FLAG_SPIRITGUIDE
); }
1113 //Need fix or use this
1114 bool isGuard() const { return HasFlag(UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_GUARD
); }
1116 bool isInFlight() const { return hasUnitState(UNIT_STAT_IN_FLIGHT
); }
1118 bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
); }
1119 void SetInCombatState(bool PvP
, Unit
* enemy
= NULL
);
1120 void SetInCombatWith(Unit
* enemy
);
1121 void ClearInCombat();
1122 uint32
GetCombatTimer() const { return m_CombatTimer
; }
1124 bool HasAuraType(AuraType auraType
) const;
1125 bool HasAura(uint32 spellId
, uint32 effIndex
) const
1127 return m_Auras
.find(spellEffectPair(spellId
, effIndex
)) != m_Auras
.end();
1129 bool HasAura(uint32 spellId
) const;
1131 bool virtual HasSpell(uint32
/*spellID*/) const { return false; }
1133 bool HasStealthAura() const { return HasAuraType(SPELL_AURA_MOD_STEALTH
); }
1134 bool HasInvisibilityAura() const { return HasAuraType(SPELL_AURA_MOD_INVISIBILITY
); }
1135 bool isFeared() const { return HasAuraType(SPELL_AURA_MOD_FEAR
); }
1136 bool isInRoots() const { return HasAuraType(SPELL_AURA_MOD_ROOT
); }
1137 bool IsPolymorphed() const;
1139 bool isFrozen() const;
1141 void RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
);
1143 bool isTargetableForAttack(bool inversAlive
= false) const;
1144 virtual bool IsInWater() const;
1145 virtual bool IsUnderWater() const;
1146 bool isInAccessablePlaceFor(Creature
const* c
) const;
1148 void SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, uint32 OverHeal
, bool critical
= false);
1149 void SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
,Powers powertype
);
1150 void EnergizeBySpell(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
);
1151 uint32
SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
);
1152 void CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, uint64 originalCaster
= 0);
1153 void CastSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, uint64 originalCaster
= 0);
1154 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);
1155 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);
1156 void CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, uint64 originalCaster
= 0);
1157 void CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, uint64 originalCaster
= 0);
1159 bool IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const;
1163 void SendAttackStateUpdate(CalcDamageInfo
*damageInfo
);
1164 void SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8 SwingType
, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
);
1165 void SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
);
1166 void SendSpellNonMeleeDamageLog(Unit
*target
,uint32 SpellID
, uint32 Damage
, SpellSchoolMask damageSchoolMask
, uint32 AbsorbedDamage
, uint32 Resist
, bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
= false);
1167 void SendPeriodicAuraLog(SpellPeriodicAuraLogInfo
*pInfo
);
1168 void SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
);
1170 void NearTeleportTo(float x
, float y
, float z
, float orientation
, bool casting
= false);
1172 void SendMonsterMove(float NewPosX
, float NewPosY
, float NewPosZ
, uint8 type
, MonsterMovementFlags flags
, uint32 Time
, Player
* player
= NULL
);
1173 void SendMonsterMoveByPath(Path
const& path
, uint32 start
, uint32 end
, MonsterMovementFlags flags
);
1175 void SendHighestThreatUpdate(HostileReference
* pHostileReference
);
1176 void SendThreatClear();
1177 void SendThreatRemove(HostileReference
* pHostileReference
);
1178 void SendThreatUpdate();
1180 void BuildHeartBeatMsg( WorldPacket
*data
) const;
1182 virtual void MoveOutOfRange(Player
&) { };
1184 bool isAlive() const { return (m_deathState
== ALIVE
); };
1185 bool isDead() const { return ( m_deathState
== DEAD
|| m_deathState
== CORPSE
); };
1186 DeathState
getDeathState() { return m_deathState
; };
1187 virtual void setDeathState(DeathState s
); // overwrited in Creature/Player/Pet
1189 uint64
GetOwnerGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMONEDBY
); }
1190 void SetOwnerGUID(uint64 owner
) { SetUInt64Value(UNIT_FIELD_SUMMONEDBY
, owner
); }
1191 uint64
GetCreatorGUID() const { return GetUInt64Value(UNIT_FIELD_CREATEDBY
); }
1192 void SetCreatorGUID(uint64 creator
) { SetUInt64Value(UNIT_FIELD_CREATEDBY
, creator
); }
1193 uint64
GetPetGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMON
); }
1194 void SetPetGUID(uint64 pet
) { SetUInt64Value(UNIT_FIELD_SUMMON
, pet
); }
1195 uint64
GetCharmerGUID() const { return GetUInt64Value(UNIT_FIELD_CHARMEDBY
); }
1196 void SetCharmerGUID(uint64 owner
) { SetUInt64Value(UNIT_FIELD_CHARMEDBY
, owner
); }
1197 uint64
GetCharmGUID() const { return GetUInt64Value(UNIT_FIELD_CHARM
); }
1198 void SetCharmGUID(uint64 charm
) { SetUInt64Value(UNIT_FIELD_CHARM
, charm
); }
1199 uint64
GetTargetGUID() const { return GetUInt64Value(UNIT_FIELD_TARGET
); }
1200 void SetTargetGUID(uint64 targetGuid
) { SetUInt64Value(UNIT_FIELD_TARGET
, targetGuid
); }
1201 uint64
GetChannelObjectGUID() const { return GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
); }
1202 void SetChannelObjectGUID(uint64 targetGuid
) { SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, targetGuid
); }
1204 uint64
GetCharmerOrOwnerGUID() const { return GetCharmerGUID() ? GetCharmerGUID() : GetOwnerGUID(); }
1205 uint64
GetCharmerOrOwnerOrOwnGUID() const
1207 if(uint64 guid
= GetCharmerOrOwnerGUID())
1211 bool isCharmedOwnedByPlayerOrPlayer() const { return IS_PLAYER_GUID(GetCharmerOrOwnerOrOwnGUID()); }
1213 Player
* GetSpellModOwner();
1215 Unit
* GetOwner() const;
1216 Pet
* GetPet() const;
1217 Unit
* GetCharmer() const;
1218 Unit
* GetCharm() const;
1220 Unit
* GetCharmerOrOwner() const { return GetCharmerGUID() ? GetCharmer() : GetOwner(); }
1221 Unit
* GetCharmerOrOwnerOrSelf()
1223 if(Unit
* u
= GetCharmerOrOwner())
1228 Player
* GetCharmerOrOwnerPlayerOrPlayerItself();
1229 float GetCombatDistance( const Unit
* target
) const;
1231 void SetPet(Pet
* pet
);
1232 void SetCharm(Unit
* pet
);
1234 void AddGuardian(Pet
* pet
);
1235 void RemoveGuardian(Pet
* pet
);
1236 void RemoveGuardians();
1237 Pet
* FindGuardianWithEntry(uint32 entry
);
1239 bool isCharmed() const { return GetCharmerGUID() != 0; }
1241 CharmInfo
* GetCharmInfo() { return m_charmInfo
; }
1242 CharmInfo
* InitCharmInfo(Unit
* charm
);
1244 Pet
* CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
= 0);
1246 Totem
* GetTotem(uint8 slot
) const;
1248 template<typename Func
>
1249 void CallForAllControlledUnits(Func
const& func
, bool withTotems
, bool withGuardians
, bool withCharms
);
1250 template<typename Func
>
1251 bool CheckAllControlledUnits(Func
const& func
, bool withTotems
, bool withGuardians
, bool withCharms
) const;
1253 bool AddAura(Aura
*aur
);
1255 // removing specific aura stack
1256 void RemoveAura(Aura
* aura
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1257 void RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1258 void RemoveAura(uint32 spellId
, uint32 effindex
, Aura
* except
= NULL
);
1260 // removing specific aura stacks by diff reasons and selections
1261 void RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
= NULL
);
1262 void RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
);
1263 void RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
);
1264 void RemoveAurasByCasterSpell(uint32 spellId
, uint32 effindex
, uint64 casterGUID
);
1265 void RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
);
1266 void RemoveAurasDueToSpellByCancel(uint32 spellId
);
1268 // removing unknown aura stacks by diff reasons and selections
1269 void RemoveNotOwnSingleTargetAuras(uint32 newPhase
= 0x0);
1270 void RemoveAurasAtMechanicImmunity(uint32 mechMask
, uint32 exceptSpellId
, bool non_positive
= false);
1271 void RemoveSpellsCausingAura(AuraType auraType
);
1272 void RemoveRankAurasDueToSpell(uint32 spellId
);
1273 bool RemoveNoStackAurasDueToAura(Aura
*Aur
);
1274 void RemoveAurasWithInterruptFlags(uint32 flags
);
1275 void RemoveAurasWithDispelType( DispelType type
);
1276 void RemoveAllAuras(AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1277 void RemoveArenaAuras(bool onleave
= false);
1278 void RemoveAllAurasOnDeath();
1280 // removing specific aura FROM stack
1281 void RemoveSingleAuraFromStack(uint32 spellId
, uint32 effindex
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1282 void RemoveSingleAuraFromStack(AuraMap::iterator
&i
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1284 // removing specific aura FROM stack by diff reasons and selections
1285 void RemoveSingleSpellAurasFromStack(uint32 spellId
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1286 void RemoveSingleSpellAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1287 void RemoveSingleAuraByCasterSpell(uint32 spellId
, uint32 effindex
, uint64 casterGUID
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1288 void RemoveSingleAuraDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
);
1290 void DelayAura(uint32 spellId
, uint32 effindex
, int32 delaytime
);
1292 float GetResistanceBuffMods(SpellSchools school
, bool positive
) const { return GetFloatValue(positive
? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+school
: UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+school
); }
1293 void SetResistanceBuffMods(SpellSchools school
, bool positive
, float val
) { SetFloatValue(positive
? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+school
: UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+school
,val
); }
1294 void ApplyResistanceBuffModsMod(SpellSchools school
, bool positive
, float val
, bool apply
) { ApplyModSignedFloatValue(positive
? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+school
: UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+school
, val
, apply
); }
1295 void ApplyResistanceBuffModsPercentMod(SpellSchools school
, bool positive
, float val
, bool apply
) { ApplyPercentModFloatValue(positive
? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+school
: UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+school
, val
, apply
); }
1296 void InitStatBuffMods()
1298 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
) SetFloatValue(UNIT_FIELD_POSSTAT0
+i
, 0);
1299 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
) SetFloatValue(UNIT_FIELD_NEGSTAT0
+i
, 0);
1301 void ApplyStatBuffMod(Stats stat
, float val
, bool apply
) { ApplyModSignedFloatValue((val
> 0 ? UNIT_FIELD_POSSTAT0
+stat
: UNIT_FIELD_NEGSTAT0
+stat
), val
, apply
); }
1302 void ApplyStatPercentBuffMod(Stats stat
, float val
, bool apply
)
1304 ApplyPercentModFloatValue(UNIT_FIELD_POSSTAT0
+stat
, val
, apply
);
1305 ApplyPercentModFloatValue(UNIT_FIELD_NEGSTAT0
+stat
, val
, apply
);
1307 void SetCreateStat(Stats stat
, float val
) { m_createStats
[stat
] = val
; }
1308 void SetCreateHealth(uint32 val
) { SetUInt32Value(UNIT_FIELD_BASE_HEALTH
, val
); }
1309 uint32
GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH
); }
1310 void SetCreateMana(uint32 val
) { SetUInt32Value(UNIT_FIELD_BASE_MANA
, val
); }
1311 uint32
GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA
); }
1312 uint32
GetCreatePowers(Powers power
) const;
1313 float GetPosStat(Stats stat
) const { return GetFloatValue(UNIT_FIELD_POSSTAT0
+stat
); }
1314 float GetNegStat(Stats stat
) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0
+stat
); }
1315 float GetCreateStat(Stats stat
) const { return m_createStats
[stat
]; }
1317 void SetCurrentCastedSpell(Spell
* pSpell
);
1318 virtual void ProhibitSpellScholl(SpellSchoolMask
/*idSchoolMask*/, uint32
/*unTimeMs*/ ) { }
1319 void InterruptSpell(CurrentSpellTypes spellType
, bool withDelayed
= true);
1320 void FinishSpell(CurrentSpellTypes spellType
, bool ok
= true);
1322 // set withDelayed to true to account delayed spells as casted
1323 // delayed+channeled spells are always accounted as casted
1324 // we can skip channeled or delayed checks using flags
1325 bool IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
= false, bool skipAutorepeat
= false) const;
1327 // set withDelayed to true to interrupt delayed spells too
1328 // delayed+channeled spells are always interrupted
1329 void InterruptNonMeleeSpells(bool withDelayed
, uint32 spellid
= 0);
1331 Spell
* GetCurrentSpell(CurrentSpellTypes spellType
) const { return m_currentSpells
[spellType
]; }
1332 Spell
* FindCurrentSpellBySpellId(uint32 spell_id
) const;
1334 uint32 m_addDmgOnce
;
1335 uint64 m_TotemSlot
[MAX_TOTEM
];
1336 uint64 m_ObjectSlot
[4];
1337 uint32 m_detectInvisibilityMask
;
1338 uint32 m_invisibilityMask
;
1340 uint32 m_ShapeShiftFormSpellId
;
1341 ShapeshiftForm m_form
;
1342 bool IsInFeralForm() const { return m_form
== FORM_CAT
|| m_form
== FORM_BEAR
|| m_form
== FORM_DIREBEAR
; }
1344 float m_modMeleeHitChance
;
1345 float m_modRangedHitChance
;
1346 float m_modSpellHitChance
;
1347 int32 m_baseSpellCritChance
;
1349 float m_threatModifier
[MAX_SPELL_SCHOOL
];
1350 float m_modAttackSpeedPct
[3];
1353 EventProcessor m_Events
;
1356 bool HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
);
1357 void SetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
, float value
) { m_auraModifiersGroup
[unitMod
][modifierType
] = value
; }
1358 float GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const;
1359 float GetTotalStatValue(Stats stat
) const;
1360 float GetTotalAuraModValue(UnitMods unitMod
) const;
1361 SpellSchools
GetSpellSchoolByAuraGroup(UnitMods unitMod
) const;
1362 Stats
GetStatByAuraGroup(UnitMods unitMod
) const;
1363 Powers
GetPowerTypeByAuraGroup(UnitMods unitMod
) const;
1364 bool CanModifyStats() const { return m_canModifyStats
; }
1365 void SetCanModifyStats(bool modifyStats
) { m_canModifyStats
= modifyStats
; }
1366 virtual bool UpdateStats(Stats stat
) = 0;
1367 virtual bool UpdateAllStats() = 0;
1368 virtual void UpdateResistances(uint32 school
) = 0;
1369 virtual void UpdateArmor() = 0;
1370 virtual void UpdateMaxHealth() = 0;
1371 virtual void UpdateMaxPower(Powers power
) = 0;
1372 virtual void UpdateAttackPowerAndDamage(bool ranged
= false) = 0;
1373 virtual void UpdateDamagePhysical(WeaponAttackType attType
) = 0;
1374 float GetTotalAttackPowerValue(WeaponAttackType attType
) const;
1375 float GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const;
1376 void SetBaseWeaponDamage(WeaponAttackType attType
,WeaponDamageRange damageRange
, float value
) { m_weaponDamage
[attType
][damageRange
] = value
; }
1378 void SetInFront(Unit
const* target
);
1379 void SetFacingTo(float ori
);
1380 void SetFacingToObject(WorldObject
* pObject
) { SetFacingTo(GetAngle(pObject
)); }
1382 // Visibility system
1383 UnitVisibility
GetVisibility() const { return m_Visibility
; }
1384 void SetVisibility(UnitVisibility x
);
1386 // common function for visibility checks for player/creatures with detection code
1387 bool isVisibleForOrDetect(Unit
const* u
, WorldObject
const* viewPoint
, bool detect
, bool inVisibleList
= false, bool is3dDistance
= true) const;
1388 bool canDetectInvisibilityOf(Unit
const* u
) const;
1389 void SetPhaseMask(uint32 newPhaseMask
, bool update
);// overwrite WorldObject::SetPhaseMask
1391 // virtual functions for all world objects types
1392 bool isVisibleForInState(Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const;
1393 // function for low level grid visibility checks in player/creature cases
1394 virtual bool IsVisibleInGridForPlayer(Player
* pl
) const = 0;
1395 bool isInvisibleForAlive() const;
1397 AuraList
& GetSingleCastAuras() { return m_scAuras
; }
1398 AuraList
const& GetSingleCastAuras() const { return m_scAuras
; }
1399 SpellImmuneList m_spellImmune
[MAX_SPELL_IMMUNITY
];
1401 // Threat related methods
1402 bool CanHaveThreatList() const;
1403 void AddThreat(Unit
* pVictim
, float threat
= 0.0f
, bool crit
= false, SpellSchoolMask schoolMask
= SPELL_SCHOOL_MASK_NONE
, SpellEntry
const *threatSpell
= NULL
);
1404 float ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
= SPELL_SCHOOL_MASK_NORMAL
);
1405 void DeleteThreatList();
1406 bool SelectHostileTarget();
1407 void TauntApply(Unit
* pVictim
);
1408 void TauntFadeOut(Unit
*taunter
);
1409 ThreatManager
& getThreatManager() { return m_ThreatManager
; }
1410 ThreatManager
const& getThreatManager() const { return m_ThreatManager
; }
1411 void addHatedBy(HostileReference
* pHostileReference
) { m_HostileRefManager
.insertFirst(pHostileReference
); };
1412 void removeHatedBy(HostileReference
* /*pHostileReference*/ ) { /* nothing to do yet */ }
1413 HostileRefManager
& getHostileRefManager() { return m_HostileRefManager
; }
1415 uint32
GetVisibleAura(uint8 slot
)
1417 VisibleAuraMap::const_iterator itr
= m_visibleAuras
.find(slot
);
1418 if(itr
!= m_visibleAuras
.end())
1422 void SetVisibleAura(uint8 slot
, uint32 spellid
)
1425 m_visibleAuras
.erase(slot
);
1427 m_visibleAuras
[slot
] = spellid
;
1429 VisibleAuraMap
const *GetVisibleAuras() { return &m_visibleAuras
; }
1430 uint8
GetVisibleAurasCount() { return m_visibleAuras
.size(); }
1432 Aura
* GetAura(uint32 spellId
, uint32 effindex
);
1433 Aura
* GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
= 0, uint64 casterGUID
= 0);
1435 AuraMap
& GetAuras() { return m_Auras
; }
1436 AuraMap
const& GetAuras() const { return m_Auras
; }
1437 AuraList
const& GetAurasByType(AuraType type
) const { return m_modAuras
[type
]; }
1438 void ApplyAuraProcTriggerDamage(Aura
* aura
, bool apply
);
1440 int32
GetTotalAuraModifier(AuraType auratype
) const;
1441 float GetTotalAuraMultiplier(AuraType auratype
) const;
1442 int32
GetMaxPositiveAuraModifier(AuraType auratype
) const;
1443 int32
GetMaxNegativeAuraModifier(AuraType auratype
) const;
1445 int32
GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const;
1446 float GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const;
1447 int32
GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const;
1448 int32
GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const;
1450 int32
GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const;
1451 float GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const;
1452 int32
GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const;
1453 int32
GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const;
1455 // misc have plain value but we check it fit to provided values mask (mask & (1 << (misc-1)))
1456 float GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype
, uint32 mask
) const;
1458 Aura
* GetDummyAura(uint32 spell_id
) const;
1462 uint32
GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID
); }
1463 void SetDisplayId(uint32 modelId
);
1464 uint32
GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID
); }
1465 void SetNativeDisplayId(uint32 modelId
) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID
, modelId
); }
1466 void setTransForm(uint32 spellid
) { m_transform
= spellid
;}
1467 uint32
getTransForm() const { return m_transform
;}
1469 DynamicObject
* GetDynObject(uint32 spellId
, uint32 effIndex
);
1470 DynamicObject
* GetDynObject(uint32 spellId
);
1471 void AddDynObject(DynamicObject
* dynObj
);
1472 void RemoveDynObject(uint32 spellid
);
1473 void RemoveDynObjectWithGUID(uint64 guid
) { m_dynObjGUIDs
.remove(guid
); }
1474 void RemoveAllDynObjects();
1476 GameObject
* GetGameObject(uint32 spellId
) const;
1477 void AddGameObject(GameObject
* gameObj
);
1478 void RemoveGameObject(GameObject
* gameObj
, bool del
);
1479 void RemoveGameObject(uint32 spellid
, bool del
);
1480 void RemoveAllGameObjects();
1482 uint32
CalculateDamage(WeaponAttackType attType
, bool normalized
);
1483 float GetAPMultiplier(WeaponAttackType attType
, bool normalized
);
1484 void ModifyAuraState(AuraState flag
, bool apply
);
1485 bool HasAuraState(AuraState flag
) const { return HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)); }
1486 bool HasAuraStateForCaster(AuraState flag
, uint64 caster
) const;
1487 void UnsummonAllTotems();
1488 Unit
* SelectMagnetTarget(Unit
*victim
, SpellEntry
const *spellInfo
= NULL
);
1489 int32
SpellBaseDamageBonus(SpellSchoolMask schoolMask
);
1490 int32
SpellBaseHealingBonus(SpellSchoolMask schoolMask
);
1491 int32
SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
);
1492 int32
SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask
, Unit
*pVictim
);
1493 uint32
SpellDamageBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 damage
, DamageEffectType damagetype
, uint32 stack
= 1);
1494 uint32
SpellHealingBonus(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 healamount
, DamageEffectType damagetype
, uint32 stack
= 1);
1495 bool isSpellBlocked(Unit
*pVictim
, SpellEntry
const *spellProto
, WeaponAttackType attackType
= BASE_ATTACK
);
1496 bool isSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
= BASE_ATTACK
);
1497 uint32
SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
);
1498 uint32
SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
);
1500 void SetLastManaUse()
1502 if (GetTypeId() == TYPEID_PLAYER
&& !IsUnderLastManaUseEffect())
1503 RemoveFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_REGENERATE_POWER
);
1505 m_lastManaUseTimer
= 5000;
1507 bool IsUnderLastManaUseEffect() const { return m_lastManaUseTimer
; }
1509 uint32
GetRegenTimer() const { return m_regenTimer
; }
1511 void SetContestedPvP(Player
*attackedPlayer
= NULL
);
1513 uint32
MeleeDamageBonus(Unit
*pVictim
, uint32 damage
, WeaponAttackType attType
, SpellEntry
const *spellProto
= NULL
, DamageEffectType damagetype
= DIRECT_DAMAGE
, uint32 stack
=1);
1514 uint32
GetCastingTimeForBonus( SpellEntry
const *spellProto
, DamageEffectType damagetype
, uint32 CastingTime
);
1516 void ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
);
1517 void ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
);
1518 virtual bool IsImmunedToSpell(SpellEntry
const* spellInfo
);
1519 // redefined in Creature
1520 bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask
);
1521 virtual bool IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, uint32 index
) const;
1522 // redefined in Creature
1524 uint32
CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
);
1525 void CalcAbsorbResist(Unit
*pVictim
, SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
, bool canReflect
= false);
1527 void UpdateWalkModeForPets(bool on
);
1528 void UpdateSpeed(UnitMoveType mtype
, bool forced
);
1529 float GetSpeed( UnitMoveType mtype
) const;
1530 float GetSpeedRate( UnitMoveType mtype
) const { return m_speed_rate
[mtype
]; }
1531 void SetSpeed(UnitMoveType mtype
, float rate
, bool forced
= false);
1533 void SetHover(bool on
);
1534 bool isHover() const { return HasAuraType(SPELL_AURA_HOVER
); }
1536 void KnockBackFrom(Unit
* target
, float horizintalSpeed
, float verticalSpeed
);
1538 void _RemoveAllAuraMods();
1539 void _ApplyAllAuraMods();
1541 int32
CalculateSpellDamage(SpellEntry
const* spellProto
, uint8 effect_index
, int32 basePoints
, Unit
const* target
);
1543 uint32
CalcNotIgnoreAbsorbDamage( uint32 damage
, SpellSchoolMask damageSchoolMask
, SpellEntry
const* spellInfo
= NULL
);
1544 uint32
CalcNotIgnoreDamageRedunction( uint32 damage
, SpellSchoolMask damageSchoolMask
);
1545 int32
CalculateSpellDuration(SpellEntry
const* spellProto
, uint8 effect_index
, Unit
const* target
);
1546 float CalculateLevelPenalty(SpellEntry
const* spellProto
) const;
1548 void addFollower(FollowerReference
* pRef
) { m_FollowingRefManager
.insertFirst(pRef
); }
1549 void removeFollower(FollowerReference
* /*pRef*/ ) { /* nothing to do yet */ }
1550 static Unit
* GetUnit(WorldObject
const& object
, uint64 guid
);
1552 MotionMaster
* GetMotionMaster() { return &i_motionMaster
; }
1554 bool IsStopped() const { return !(hasUnitState(UNIT_STAT_MOVING
)); }
1557 void SetFeared(bool apply
, uint64
const& casterGUID
= 0, uint32 spellID
= 0, uint32 time
= 0);
1558 void SetConfused(bool apply
, uint64
const& casterGUID
= 0, uint32 spellID
= 0);
1559 void SetFeignDeath(bool apply
, uint64
const& casterGUID
= 0, uint32 spellID
= 0);
1561 void AddComboPointHolder(uint32 lowguid
) { m_ComboPointHolders
.insert(lowguid
); }
1562 void RemoveComboPointHolder(uint32 lowguid
) { m_ComboPointHolders
.erase(lowguid
); }
1563 void ClearComboPointHolders();
1565 ///----------Pet responses methods-----------------
1566 void SendPetCastFail(uint32 spellid
, SpellCastResult msg
);
1567 void SendPetActionFeedback (uint8 msg
);
1568 void SendPetTalk (uint32 pettalk
);
1569 void SendPetAIReaction(uint64 guid
);
1570 ///----------End of Pet responses methods----------
1572 void propagateSpeedChange() { GetMotionMaster()->propagateSpeedChange(); }
1575 void ClearAllReactives();
1576 void StartReactiveTimer( ReactiveType reactive
) { m_reactiveTimer
[reactive
] = REACTIVE_TIMER_START
;}
1577 void UpdateReactives(uint32 p_time
);
1580 void UpdateAuraForGroup(uint8 slot
);
1583 typedef std::set
<PetAura
const*> PetAuraSet
;
1584 PetAuraSet m_petAuras
;
1585 void AddPetAura(PetAura
const* petSpell
);
1586 void RemovePetAura(PetAura
const* petSpell
);
1591 void _UpdateSpells(uint32 time
);
1593 void _UpdateAutoRepeatSpell();
1594 bool m_AutoRepeatFirstCast
;
1596 uint32 m_attackTimer
[MAX_ATTACK
];
1598 float m_createStats
[MAX_STATS
];
1600 AttackerSet m_attackers
;
1603 DeathState m_deathState
;
1606 AuraMap::iterator m_AurasUpdateIterator
; // != end() in Unit::m_Auras update and point to next element
1607 AuraList m_deletedAuras
; // auras removed while in ApplyModifier and waiting deleted
1609 AuraList m_scAuras
; // casted by unit single per-caster auras
1611 typedef std::list
<uint64
> DynObjectGUIDs
;
1612 DynObjectGUIDs m_dynObjGUIDs
;
1614 typedef std::list
<GameObject
*> GameObjectList
;
1615 GameObjectList m_gameObj
;
1619 AuraList m_modAuras
[TOTAL_AURAS
];
1620 float m_auraModifiersGroup
[UNIT_MOD_END
][MODIFIER_TYPE_END
];
1621 float m_weaponDamage
[MAX_ATTACK
][2];
1622 bool m_canModifyStats
;
1623 //std::list< spellEffectPair > AuraSpells[TOTAL_AURAS]; // TODO: use this if ok for mem
1624 VisibleAuraMap m_visibleAuras
;
1626 float m_speed_rate
[MAX_MOVE_TYPE
];
1628 CharmInfo
*m_charmInfo
;
1630 virtual SpellSchoolMask
GetMeleeDamageSchoolMask() const;
1632 MotionMaster i_motionMaster
;
1634 uint32 m_reactiveTimer
[MAX_REACTIVE
];
1635 uint32 m_regenTimer
;
1636 uint32 m_lastManaUseTimer
;
1639 void CleanupDeletedAuras();
1641 bool IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
);
1642 bool HandleDummyAuraProc( Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
);
1643 bool HandleHasteAuraProc( Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
);
1644 bool HandleSpellCritChanceAuraProc( Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
);
1645 bool HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
);
1646 bool HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
);
1647 bool HandleMendingAuraProc(Aura
* triggeredByAura
);
1649 // player or player's pet
1650 float GetCombatRatingReduction(CombatRating cr
) const;
1651 uint32
GetCombatRatingDamageReduction(CombatRating cr
, float rate
, float cap
, uint32 damage
) const;
1653 Unit
* _GetTotem(uint8 slot
) const; // for templated function without include need
1655 uint32 m_state
; // Even derived shouldn't modify
1656 uint32 m_CombatTimer
;
1658 Spell
* m_currentSpells
[CURRENT_MAX_SPELL
];
1660 UnitVisibility m_Visibility
;
1662 Diminishing m_Diminishing
;
1663 // Manage all Units threatening us
1664 ThreatManager m_ThreatManager
;
1665 // Manage all Units that are threatened by us
1666 HostileRefManager m_HostileRefManager
;
1668 FollowerRefManager m_FollowingRefManager
;
1670 ComboPointHolderSet m_ComboPointHolders
;
1672 GuardianPetList m_guardianPets
;
1675 template<typename Func
>
1676 void Unit::CallForAllControlledUnits(Func
const& func
, bool withTotems
, bool withGuardians
, bool withCharms
)
1678 if(Pet
* pet
= GetPet())
1683 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
1684 if(Unit
* guardian
= Unit::GetUnit(*this,*itr
))
1690 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
1691 if (Unit
*totem
= _GetTotem(i
))
1696 if(Unit
* charm
= GetCharm())
1701 template<typename Func
>
1702 bool Unit::CheckAllControlledUnits(Func
const& func
, bool withTotems
, bool withGuardians
, bool withCharms
) const
1704 if (Pet
* pet
= GetPet())
1710 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
1711 if (Unit
* guardian
= Unit::GetUnit(*this,*itr
))
1719 for (int8 i
= 0; i
< MAX_TOTEM
; ++i
)
1720 if (Unit
*totem
= _GetTotem(i
))
1726 if(Unit
* charm
= GetCharm())