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"
36 #include "WorldPacket.h"
40 enum SpellInterruptFlags
42 SPELL_INTERRUPT_FLAG_MOVEMENT
= 0x01,
43 SPELL_INTERRUPT_FLAG_DAMAGE
= 0x02,
44 SPELL_INTERRUPT_FLAG_INTERRUPT
= 0x04,
45 SPELL_INTERRUPT_FLAG_AUTOATTACK
= 0x08,
46 SPELL_INTERRUPT_FLAG_ABORT_ON_DMG
= 0x10, // _complete_ interrupt on direct damage
47 //SPELL_INTERRUPT_UNK = 0x20 // unk, 564 of 727 spells having this spell start with "Glyph"
50 enum SpellChannelInterruptFlags
52 CHANNEL_FLAG_DAMAGE
= 0x0002,
53 CHANNEL_FLAG_MOVEMENT
= 0x0008,
54 CHANNEL_FLAG_TURNING
= 0x0010,
55 CHANNEL_FLAG_DAMAGE2
= 0x0080,
56 CHANNEL_FLAG_DELAY
= 0x4000
59 enum SpellAuraInterruptFlags
61 AURA_INTERRUPT_FLAG_UNK0
= 0x00000001, // 0 removed when getting hit by a negative spell?
62 AURA_INTERRUPT_FLAG_DAMAGE
= 0x00000002, // 1 removed by any damage
63 AURA_INTERRUPT_FLAG_UNK2
= 0x00000004, // 2
64 AURA_INTERRUPT_FLAG_MOVE
= 0x00000008, // 3 removed by any movement
65 AURA_INTERRUPT_FLAG_TURNING
= 0x00000010, // 4 removed by any turning
66 AURA_INTERRUPT_FLAG_ENTER_COMBAT
= 0x00000020, // 5 removed by entering combat
67 AURA_INTERRUPT_FLAG_NOT_MOUNTED
= 0x00000040, // 6 removed by unmounting
68 AURA_INTERRUPT_FLAG_NOT_ABOVEWATER
= 0x00000080, // 7 removed by entering water
69 AURA_INTERRUPT_FLAG_NOT_UNDERWATER
= 0x00000100, // 8 removed by leaving water
70 AURA_INTERRUPT_FLAG_NOT_SHEATHED
= 0x00000200, // 9 removed by unsheathing
71 AURA_INTERRUPT_FLAG_UNK10
= 0x00000400, // 10
72 AURA_INTERRUPT_FLAG_UNK11
= 0x00000800, // 11
73 AURA_INTERRUPT_FLAG_UNK12
= 0x00001000, // 12 removed by attack?
74 AURA_INTERRUPT_FLAG_UNK13
= 0x00002000, // 13
75 AURA_INTERRUPT_FLAG_UNK14
= 0x00004000, // 14
76 AURA_INTERRUPT_FLAG_UNK15
= 0x00008000, // 15 removed by casting a spell?
77 AURA_INTERRUPT_FLAG_UNK16
= 0x00010000, // 16
78 AURA_INTERRUPT_FLAG_MOUNTING
= 0x00020000, // 17 removed by mounting
79 AURA_INTERRUPT_FLAG_NOT_SEATED
= 0x00040000, // 18 removed by standing up (used by food and drink mostly and sleep/Fake Death like)
80 AURA_INTERRUPT_FLAG_CHANGE_MAP
= 0x00080000, // 19 leaving map/getting teleported
81 AURA_INTERRUPT_FLAG_IMMUNE_OR_LOST_SELECTION
= 0x00100000, // 20 removed by auras that make you invulnerable, or make other to loose selection on you
82 AURA_INTERRUPT_FLAG_UNK21
= 0x00200000, // 21
83 AURA_INTERRUPT_FLAG_UNK22
= 0x00400000, // 22
84 AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
= 0x00800000, // 23 removed by entering pvp combat
85 AURA_INTERRUPT_FLAG_DIRECT_DAMAGE
= 0x01000000 // 24 removed by any direct damage
91 SPELLMOD_DURATION
= 1,
97 SPELLMOD_CRITICAL_CHANCE
= 7,
98 SPELLMOD_ALL_EFFECTS
= 8,
99 SPELLMOD_NOT_LOSE_CASTING_TIME
= 9,
100 SPELLMOD_CASTING_TIME
= 10,
101 SPELLMOD_COOLDOWN
= 11,
102 SPELLMOD_EFFECT2
= 12,
103 // spellmod 13 unused
105 SPELLMOD_CRIT_DAMAGE_BONUS
= 15,
106 SPELLMOD_RESIST_MISS_CHANCE
= 16,
107 SPELLMOD_JUMP_TARGETS
= 17,
108 SPELLMOD_CHANCE_OF_SUCCESS
= 18, // Only used with SPELL_AURA_ADD_FLAT_MODIFIER and affects proc spells
109 SPELLMOD_ACTIVATION_TIME
= 19,
110 SPELLMOD_EFFECT_PAST_FIRST
= 20,
111 SPELLMOD_CASTING_TIME_OLD
= 21,
113 SPELLMOD_EFFECT3
= 23,
114 SPELLMOD_SPELL_BONUS_DAMAGE
= 24,
115 // spellmod 25 unused
116 SPELLMOD_FREQUENCY_OF_SUCCESS
= 26, // Only used with SPELL_AURA_ADD_PCT_MODIFIER and affects used on proc spells
117 SPELLMOD_MULTIPLE_VALUE
= 27,
118 SPELLMOD_RESIST_DISPEL_CHANCE
= 28
121 #define MAX_SPELLMOD 32
123 enum SpellFacingFlags
125 SPELL_FACING_FLAG_INFRONT
= 0x0001
128 #define BASE_MINDAMAGE 1.0f
129 #define BASE_MAXDAMAGE 2.0f
130 #define BASE_ATTACK_TIME 2000
132 // byte value (UNIT_FIELD_BYTES_1,0)
133 enum UnitStandStateType
135 UNIT_STAND_STATE_STAND
= 0,
136 UNIT_STAND_STATE_SIT
= 1,
137 UNIT_STAND_STATE_SIT_CHAIR
= 2,
138 UNIT_STAND_STATE_SLEEP
= 3,
139 UNIT_STAND_STATE_SIT_LOW_CHAIR
= 4,
140 UNIT_STAND_STATE_SIT_MEDIUM_CHAIR
= 5,
141 UNIT_STAND_STATE_SIT_HIGH_CHAIR
= 6,
142 UNIT_STAND_STATE_DEAD
= 7,
143 UNIT_STAND_STATE_KNEEL
= 8,
144 UNIT_STAND_STATE_SUBMERGED
= 9
147 // byte flags value (UNIT_FIELD_BYTES_1,2)
150 UNIT_STAND_FLAGS_UNK1
= 0x01,
151 UNIT_STAND_FLAGS_CREEP
= 0x02,
152 UNIT_STAND_FLAGS_UNK3
= 0x04,
153 UNIT_STAND_FLAGS_UNK4
= 0x08,
154 UNIT_STAND_FLAGS_UNK5
= 0x10,
155 UNIT_STAND_FLAGS_ALL
= 0xFF
158 // byte flags value (UNIT_FIELD_BYTES_1,3)
159 enum UnitBytes1_Flags
161 UNIT_BYTE1_FLAG_ALWAYS_STAND
= 0x01,
162 UNIT_BYTE1_FLAG_UNK_2
= 0x02, // Creature that can fly and are not on the ground appear to have this flag. If they are on the ground, flag is not present.
163 UNIT_BYTE1_FLAG_UNTRACKABLE
= 0x04,
164 UNIT_BYTE1_FLAG_ALL
= 0xFF
167 // byte value (UNIT_FIELD_BYTES_2,3)
178 FORM_DIREBEAR
= 0x08,
179 FORM_STEVES_GHOUL
= 0x09,
180 FORM_THARONJA_SKELETON
= 0x0A,
181 FORM_TEST_OF_STRENGTH
= 0x0B,
182 FORM_BLB_PLAYER
= 0x0C,
183 FORM_SHADOW_DANCE
= 0x0D,
184 FORM_CREATUREBEAR
= 0x0E,
185 FORM_CREATURECAT
= 0x0F,
186 FORM_GHOSTWOLF
= 0x10,
187 FORM_BATTLESTANCE
= 0x11,
188 FORM_DEFENSIVESTANCE
= 0x12,
189 FORM_BERSERKERSTANCE
= 0x13,
192 FORM_METAMORPHOSIS
= 0x16,
195 FORM_FLIGHT_EPIC
= 0x1B,
200 FORM_SPIRITOFREDEMPTION
= 0x20,
203 // byte value (UNIT_FIELD_BYTES_2,0)
206 SHEATH_STATE_UNARMED
= 0, // non prepared weapon
207 SHEATH_STATE_MELEE
= 1, // prepared melee weapon
208 SHEATH_STATE_RANGED
= 2 // prepared ranged weapon
211 #define MAX_SHEATH_STATE 3
213 // byte flags value (UNIT_FIELD_BYTES_2,1)
214 enum UnitPVPStateFlags
216 UNIT_BYTE2_FLAG_PVP
= 0x01,
217 UNIT_BYTE2_FLAG_UNK1
= 0x02,
218 UNIT_BYTE2_FLAG_FFA_PVP
= 0x04,
219 UNIT_BYTE2_FLAG_SANCTUARY
= 0x08,
220 UNIT_BYTE2_FLAG_UNK4
= 0x10,
221 UNIT_BYTE2_FLAG_UNK5
= 0x20,
222 UNIT_BYTE2_FLAG_UNK6
= 0x40,
223 UNIT_BYTE2_FLAG_UNK7
= 0x80
226 // byte flags value (UNIT_FIELD_BYTES_2,2)
229 UNIT_CAN_BE_RENAMED
= 0x01,
230 UNIT_CAN_BE_ABANDONED
= 0x02,
233 #define CREATURE_MAX_SPELLS 4
238 SINGLEHANDEDSWING
= 1,
244 VICTIMSTATE_UNKNOWN1
= 0,
245 VICTIMSTATE_NORMAL
= 1,
246 VICTIMSTATE_DODGE
= 2,
247 VICTIMSTATE_PARRY
= 3,
248 VICTIMSTATE_INTERRUPT
= 4,
249 VICTIMSTATE_BLOCKS
= 5,
250 VICTIMSTATE_EVADES
= 6,
251 VICTIMSTATE_IS_IMMUNE
= 7,
252 VICTIMSTATE_DEFLECTS
= 8
257 HITINFO_NORMALSWING
= 0x00000000,
258 HITINFO_UNK1
= 0x00000001, // req correct packet structure
259 HITINFO_NORMALSWING2
= 0x00000002,
260 HITINFO_LEFTSWING
= 0x00000004,
261 HITINFO_UNK2
= 0x00000008,
262 HITINFO_MISS
= 0x00000010,
263 HITINFO_ABSORB
= 0x00000020, // absorbed damage
264 HITINFO_ABSORB2
= 0x00000040, // absorbed damage
265 HITINFO_RESIST
= 0x00000080, // resisted atleast some damage
266 HITINFO_RESIST2
= 0x00000100, // resisted atleast some damage
267 HITINFO_CRITICALHIT
= 0x00000200, // critical hit
271 HITINFO_BLOCK
= 0x00002000, // blocked damage
274 HITINFO_GLANCING
= 0x00010000,
275 HITINFO_CRUSHING
= 0x00020000,
276 HITINFO_NOACTION
= 0x00040000, // guessed
279 HITINFO_SWINGNOHITSOUND
= 0x00200000, // guessed
281 HITINFO_UNK3
= 0x00800000
284 //i would like to remove this: (it is defined in item.h
291 struct FactionTemplateEntry
;
294 struct SpellEntryExt
;
312 typedef std::list
<SpellImmune
> SpellImmuneList
;
314 enum UnitModifierType
320 MODIFIER_TYPE_END
= 4
323 enum WeaponDamageRange
329 enum DamageTypeToSchool
338 AURA_REMOVE_BY_DEFAULT
,
339 AURA_REMOVE_BY_STACK
, // at replace by similar aura
340 AURA_REMOVE_BY_CANCEL
,
341 AURA_REMOVE_BY_DISPEL
,
342 AURA_REMOVE_BY_DEATH
,
343 AURA_REMOVE_BY_DELETE
, // use for speedup and prevent unexpected effects at player logout/pet unsummon (must be used _only_ after save), delete.
344 AURA_REMOVE_BY_SHIELD_BREAK
, // when absorb shield is removed by damage
345 AURA_REMOVE_BY_EXPIRE
, // at duration end
351 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.
352 UNIT_MOD_STAT_AGILITY
,
353 UNIT_MOD_STAT_STAMINA
,
354 UNIT_MOD_STAT_INTELLECT
,
355 UNIT_MOD_STAT_SPIRIT
,
357 UNIT_MOD_MANA
, // UNIT_MOD_MANA..UNIT_MOD_RUNIC_POWER must be in existed order, it's accessed by index values of Powers enum.
363 UNIT_MOD_RUNIC_POWER
,
364 UNIT_MOD_ARMOR
, // UNIT_MOD_ARMOR..UNIT_MOD_RESISTANCE_ARCANE must be in existed order, it's accessed by index values of SpellSchools enum.
365 UNIT_MOD_RESISTANCE_HOLY
,
366 UNIT_MOD_RESISTANCE_FIRE
,
367 UNIT_MOD_RESISTANCE_NATURE
,
368 UNIT_MOD_RESISTANCE_FROST
,
369 UNIT_MOD_RESISTANCE_SHADOW
,
370 UNIT_MOD_RESISTANCE_ARCANE
,
371 UNIT_MOD_ATTACK_POWER
,
372 UNIT_MOD_ATTACK_POWER_RANGED
,
373 UNIT_MOD_DAMAGE_MAINHAND
,
374 UNIT_MOD_DAMAGE_OFFHAND
,
375 UNIT_MOD_DAMAGE_RANGED
,
378 UNIT_MOD_STAT_START
= UNIT_MOD_STAT_STRENGTH
,
379 UNIT_MOD_STAT_END
= UNIT_MOD_STAT_SPIRIT
+ 1,
380 UNIT_MOD_RESISTANCE_START
= UNIT_MOD_ARMOR
,
381 UNIT_MOD_RESISTANCE_END
= UNIT_MOD_RESISTANCE_ARCANE
+ 1,
382 UNIT_MOD_POWER_START
= UNIT_MOD_MANA
,
383 UNIT_MOD_POWER_END
= UNIT_MOD_RUNIC_POWER
+ 1
389 RANGED_CRIT_PERCENTAGE
,
390 OFFHAND_CRIT_PERCENTAGE
,
401 #define MOD_END (PCT_MOD+1)
413 // internal state flags for some auras and movement generators, other.
416 // persistent state (applied by aura/etc until expire)
417 UNIT_STAT_MELEE_ATTACKING
= 0x00000001, // unit is melee attacking someone Unit::Attack
418 UNIT_STAT_ATTACK_PLAYER
= 0x00000002, // unit attack player or player's controlled unit and have contested pvpv timer setup, until timer expire, combat end and etc
419 UNIT_STAT_DIED
= 0x00000004, // Unit::SetFeignDeath
420 UNIT_STAT_STUNNED
= 0x00000008, // Aura::HandleAuraModStun
421 UNIT_STAT_ROOT
= 0x00000010, // Aura::HandleAuraModRoot
422 UNIT_STAT_ISOLATED
= 0x00000020, // area auras do not affect other players, Aura::HandleAuraModSchoolImmunity
423 UNIT_STAT_CONTROLED
= 0x00000040, // Aura::HandleAuraModPossess
425 // persistent movement generator state (all time while movement generator applied to unit (independent from top state of movegen)
426 UNIT_STAT_IN_FLIGHT
= 0x00000080, // player is in flight mode (in fact interrupted at far teleport until next map telport landing)
427 UNIT_STAT_DISTRACTED
= 0x00000100, // DistractedMovementGenerator active
429 // persistent movement generator state with non-persistent mirror states for stop support
430 // (can be removed temporary by stop command or another movement generator apply)
431 // not use _MOVE versions for generic movegen state, it can be removed temporary for unit stop and etc
432 UNIT_STAT_CONFUSED
= 0x00000200, // ConfusedMovementGenerator active/onstack
433 UNIT_STAT_CONFUSED_MOVE
= 0x00000400,
434 UNIT_STAT_ROAMING
= 0x00000800, // RandomMovementGenerator/PointMovementGenerator/WaypointMovementGenerator active (now always set)
435 UNIT_STAT_ROAMING_MOVE
= 0x00001000,
436 UNIT_STAT_CHASE
= 0x00002000, // ChaseMovementGenerator active
437 UNIT_STAT_CHASE_MOVE
= 0x00004000,
438 UNIT_STAT_FOLLOW
= 0x00008000, // FollowMovementGenerator active
439 UNIT_STAT_FOLLOW_MOVE
= 0x00010000,
440 UNIT_STAT_FLEEING
= 0x00020000, // FleeMovementGenerator/TimedFleeingMovementGenerator active/onstack
441 UNIT_STAT_FLEEING_MOVE
= 0x00040000,
443 // masks (only for check)
445 // can't move currently
446 UNIT_STAT_CAN_NOT_MOVE
= UNIT_STAT_ROOT
| UNIT_STAT_STUNNED
| UNIT_STAT_DIED
,
448 // stay by different reasons
449 UNIT_STAT_NOT_MOVE
= UNIT_STAT_ROOT
| UNIT_STAT_STUNNED
| UNIT_STAT_DIED
|
450 UNIT_STAT_DISTRACTED
,
452 // stay or scripted movement for effect( = in player case you can't move by client command)
453 UNIT_STAT_NO_FREE_MOVE
= UNIT_STAT_ROOT
| UNIT_STAT_STUNNED
| UNIT_STAT_DIED
|
454 UNIT_STAT_IN_FLIGHT
|
455 UNIT_STAT_CONFUSED
| UNIT_STAT_FLEEING
,
457 // not react at move in sight or other
458 UNIT_STAT_CAN_NOT_REACT
= UNIT_STAT_STUNNED
| UNIT_STAT_DIED
|
459 UNIT_STAT_CONFUSED
| UNIT_STAT_FLEEING
,
461 // AI disabled by some reason
462 UNIT_STAT_LOST_CONTROL
= UNIT_STAT_FLEEING
| UNIT_STAT_CONTROLED
,
464 // above 2 state cases
465 UNIT_STAT_CAN_NOT_REACT_OR_LOST_CONTROL
= UNIT_STAT_CAN_NOT_REACT
| UNIT_STAT_LOST_CONTROL
,
467 // masks (for check or reset)
469 // for real move using movegen check and stop (except unstoppable flight)
470 UNIT_STAT_MOVING
= UNIT_STAT_ROAMING_MOVE
| UNIT_STAT_CHASE_MOVE
| UNIT_STAT_FOLLOW_MOVE
| UNIT_STAT_FLEEING_MOVE
,
472 UNIT_STAT_ALL_STATE
= 0xFFFFFFFF
484 MOVE_FLIGHT_BACK
= 7,
488 #define MAX_MOVE_TYPE 9
490 extern float baseMoveSpeed
[MAX_MOVE_TYPE
];
495 CR_DEFENSE_SKILL
= 1,
505 CR_HIT_TAKEN_MELEE
= 11,
506 CR_HIT_TAKEN_RANGED
= 12,
507 CR_HIT_TAKEN_SPELL
= 13,
508 CR_CRIT_TAKEN_MELEE
= 14,
509 CR_CRIT_TAKEN_RANGED
= 15,
510 CR_CRIT_TAKEN_SPELL
= 16,
512 CR_HASTE_RANGED
= 18,
514 CR_WEAPON_SKILL_MAINHAND
= 20,
515 CR_WEAPON_SKILL_OFFHAND
= 21,
516 CR_WEAPON_SKILL_RANGED
= 22,
518 CR_ARMOR_PENETRATION
= 24
521 #define MAX_COMBAT_RATING 25
523 /// internal used flags for marking special auras - for example some dummy-auras
526 UNIT_AURAFLAG_ALIVE_INVISIBLE
= 0x1, // aura which makes unit invisible for alive
531 VISIBILITY_OFF
= 0, // absolute, not detectable, GM-like, can see all other
533 VISIBILITY_GROUP_STEALTH
= 2, // detect chance, seen and can see group members
534 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)
535 VISIBILITY_GROUP_NO_DETECT
= 4, // state just at stealth apply for update Grid state. Don't remove, otherwise stealth spells will break
536 VISIBILITY_RESPAWN
= 5 // special totally not detectable visibility for force delete object at respawn command
539 // Value masks for UNIT_FIELD_FLAGS
542 UNIT_FLAG_UNK_0
= 0x00000001,
543 UNIT_FLAG_NON_ATTACKABLE
= 0x00000002, // not attackable
544 UNIT_FLAG_DISABLE_MOVE
= 0x00000004,
545 UNIT_FLAG_PVP_ATTACKABLE
= 0x00000008, // allow apply pvp rules to attackable state in addition to faction dependent state
546 UNIT_FLAG_RENAME
= 0x00000010,
547 UNIT_FLAG_PREPARATION
= 0x00000020, // don't take reagents for spells with SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
548 UNIT_FLAG_UNK_6
= 0x00000040,
549 UNIT_FLAG_NOT_ATTACKABLE_1
= 0x00000080, // ?? (UNIT_FLAG_PVP_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1) is NON_PVP_ATTACKABLE
550 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 (flag probably removed for the attacked and it's party/group only)
551 UNIT_FLAG_PASSIVE
= 0x00000200, // makes you unable to attack everything. Almost identical to our "civilian"-term. Will ignore it's surroundings and not engage in combat unless "called upon" or engaged by another unit.
552 UNIT_FLAG_LOOTING
= 0x00000400, // loot animation
553 UNIT_FLAG_PET_IN_COMBAT
= 0x00000800, // in combat?, 2.0.8
554 UNIT_FLAG_PVP
= 0x00001000, // changed in 3.0.3
555 UNIT_FLAG_SILENCED
= 0x00002000, // silenced, 2.1.1
556 UNIT_FLAG_UNK_14
= 0x00004000, // 2.0.8
557 UNIT_FLAG_UNK_15
= 0x00008000,
558 UNIT_FLAG_UNK_16
= 0x00010000, // removes attackable icon
559 UNIT_FLAG_PACIFIED
= 0x00020000, // 3.0.3 ok
560 UNIT_FLAG_STUNNED
= 0x00040000, // 3.0.3 ok
561 UNIT_FLAG_IN_COMBAT
= 0x00080000,
562 UNIT_FLAG_TAXI_FLIGHT
= 0x00100000, // disable casting at client side spell not allowed by taxi flight (mounted?), probably used with 0x4 flag
563 UNIT_FLAG_DISARMED
= 0x00200000, // 3.0.3, disable melee spells casting..., "Required melee weapon" added to melee spells tooltip.
564 UNIT_FLAG_CONFUSED
= 0x00400000,
565 UNIT_FLAG_FLEEING
= 0x00800000,
566 UNIT_FLAG_PLAYER_CONTROLLED
= 0x01000000, // used in spell Eyes of the Beast for pet... let attack by controlled creature
567 UNIT_FLAG_NOT_SELECTABLE
= 0x02000000,
568 UNIT_FLAG_SKINNABLE
= 0x04000000,
569 UNIT_FLAG_MOUNT
= 0x08000000,
570 UNIT_FLAG_UNK_28
= 0x10000000,
571 UNIT_FLAG_UNK_29
= 0x20000000, // used in Feing Death spell
572 UNIT_FLAG_SHEATHE
= 0x40000000,
573 UNIT_FLAG_UNK_31
= 0x80000000 // set skinnable icon and also changes color of portrait
576 // Value masks for UNIT_FIELD_FLAGS_2
579 UNIT_FLAG2_FEIGN_DEATH
= 0x00000001,
580 UNIT_FLAG2_UNK1
= 0x00000002, // Hides unit model (show only player equip)
581 UNIT_FLAG2_COMPREHEND_LANG
= 0x00000008,
582 UNIT_FLAG2_FORCE_MOVE
= 0x00000040,
583 UNIT_FLAG2_DISARM
= 0x00000400, // disarm or something
584 UNIT_FLAG2_REGENERATE_POWER
= 0x00000800,
587 /// Non Player Character flags
590 UNIT_NPC_FLAG_NONE
= 0x00000000,
591 UNIT_NPC_FLAG_GOSSIP
= 0x00000001, // 100%
592 UNIT_NPC_FLAG_QUESTGIVER
= 0x00000002, // guessed, probably ok
593 UNIT_NPC_FLAG_UNK1
= 0x00000004,
594 UNIT_NPC_FLAG_UNK2
= 0x00000008,
595 UNIT_NPC_FLAG_TRAINER
= 0x00000010, // 100%
596 UNIT_NPC_FLAG_TRAINER_CLASS
= 0x00000020, // 100%
597 UNIT_NPC_FLAG_TRAINER_PROFESSION
= 0x00000040, // 100%
598 UNIT_NPC_FLAG_VENDOR
= 0x00000080, // 100%
599 UNIT_NPC_FLAG_VENDOR_AMMO
= 0x00000100, // 100%, general goods vendor
600 UNIT_NPC_FLAG_VENDOR_FOOD
= 0x00000200, // 100%
601 UNIT_NPC_FLAG_VENDOR_POISON
= 0x00000400, // guessed
602 UNIT_NPC_FLAG_VENDOR_REAGENT
= 0x00000800, // 100%
603 UNIT_NPC_FLAG_REPAIR
= 0x00001000, // 100%
604 UNIT_NPC_FLAG_FLIGHTMASTER
= 0x00002000, // 100%
605 UNIT_NPC_FLAG_SPIRITHEALER
= 0x00004000, // guessed
606 UNIT_NPC_FLAG_SPIRITGUIDE
= 0x00008000, // guessed
607 UNIT_NPC_FLAG_INNKEEPER
= 0x00010000, // 100%
608 UNIT_NPC_FLAG_BANKER
= 0x00020000, // 100%
609 UNIT_NPC_FLAG_PETITIONER
= 0x00040000, // 100% 0xC0000 = guild petitions, 0x40000 = arena team petitions
610 UNIT_NPC_FLAG_TABARDDESIGNER
= 0x00080000, // 100%
611 UNIT_NPC_FLAG_BATTLEMASTER
= 0x00100000, // 100%
612 UNIT_NPC_FLAG_AUCTIONEER
= 0x00200000, // 100%
613 UNIT_NPC_FLAG_STABLEMASTER
= 0x00400000, // 100%
614 UNIT_NPC_FLAG_GUILD_BANKER
= 0x00800000, // cause client to send 997 opcode
615 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
616 UNIT_NPC_FLAG_GUARD
= 0x10000000 // custom flag for guards
619 // used in most movement packets (send and received)
622 MOVEFLAG_NONE
= 0x00000000,
623 MOVEFLAG_FORWARD
= 0x00000001,
624 MOVEFLAG_BACKWARD
= 0x00000002,
625 MOVEFLAG_STRAFE_LEFT
= 0x00000004,
626 MOVEFLAG_STRAFE_RIGHT
= 0x00000008,
627 MOVEFLAG_TURN_LEFT
= 0x00000010,
628 MOVEFLAG_TURN_RIGHT
= 0x00000020,
629 MOVEFLAG_PITCH_UP
= 0x00000040,
630 MOVEFLAG_PITCH_DOWN
= 0x00000080,
631 MOVEFLAG_WALK_MODE
= 0x00000100, // Walking
632 MOVEFLAG_ONTRANSPORT
= 0x00000200,
633 MOVEFLAG_LEVITATING
= 0x00000400,
634 MOVEFLAG_ROOT
= 0x00000800,
635 MOVEFLAG_FALLING
= 0x00001000,
636 MOVEFLAG_FALLINGFAR
= 0x00002000,
637 MOVEFLAG_PENDINGSTOP
= 0x00004000,
638 MOVEFLAG_PENDINGSTRAFESTOP
= 0x00008000,
639 MOVEFLAG_PENDINGFORWARD
= 0x00010000,
640 MOVEFLAG_PENDINGBACKWARD
= 0x00020000,
641 MOVEFLAG_PENDINGSTRAFELEFT
= 0x00040000,
642 MOVEFLAG_PENDINGSTRAFERIGHT
= 0x00080000,
643 MOVEFLAG_PENDINGROOT
= 0x00100000,
644 MOVEFLAG_SWIMMING
= 0x00200000, // appears with fly flag also
645 MOVEFLAG_ASCENDING
= 0x00400000, // swim up also
646 MOVEFLAG_DESCENDING
= 0x00800000, // swim down also
647 MOVEFLAG_CAN_FLY
= 0x01000000, // can fly in 3.3?
648 MOVEFLAG_FLYING
= 0x02000000, // Actual flying mode
649 MOVEFLAG_SPLINE_ELEVATION
= 0x04000000, // used for flight paths
650 MOVEFLAG_SPLINE_ENABLED
= 0x08000000, // used for flight paths
651 MOVEFLAG_WATERWALKING
= 0x10000000, // prevent unit from falling through water
652 MOVEFLAG_SAFE_FALL
= 0x20000000, // active rogue safe fall spell (passive)
653 MOVEFLAG_HOVER
= 0x40000000
656 // flags that use in movement check for example at spell casting
657 MovementFlags
const movementFlagsMask
= MovementFlags(
658 MOVEFLAG_FORWARD
|MOVEFLAG_BACKWARD
|MOVEFLAG_STRAFE_LEFT
|MOVEFLAG_STRAFE_RIGHT
|
659 MOVEFLAG_PITCH_UP
|MOVEFLAG_PITCH_DOWN
|MOVEFLAG_ROOT
|
660 MOVEFLAG_FALLING
|MOVEFLAG_FALLINGFAR
|MOVEFLAG_ASCENDING
|
661 MOVEFLAG_FLYING
|MOVEFLAG_SPLINE_ELEVATION
664 MovementFlags
const movementOrTurningFlagsMask
= MovementFlags(
665 movementFlagsMask
| MOVEFLAG_TURN_LEFT
| MOVEFLAG_TURN_RIGHT
670 MOVEFLAG2_NONE
= 0x0000,
671 MOVEFLAG2_UNK1
= 0x0001,
672 MOVEFLAG2_UNK2
= 0x0002,
673 MOVEFLAG2_UNK3
= 0x0004,
674 MOVEFLAG2_FULLSPEEDTURNING
= 0x0008,
675 MOVEFLAG2_FULLSPEEDPITCHING
= 0x0010,
676 MOVEFLAG2_ALLOW_PITCHING
= 0x0020,
677 MOVEFLAG2_UNK4
= 0x0040,
678 MOVEFLAG2_UNK5
= 0x0080,
679 MOVEFLAG2_UNK6
= 0x0100,
680 MOVEFLAG2_UNK7
= 0x0200,
681 MOVEFLAG2_INTERP_MOVEMENT
= 0x0400,
682 MOVEFLAG2_INTERP_TURNING
= 0x0800,
683 MOVEFLAG2_INTERP_PITCHING
= 0x1000,
684 MOVEFLAG2_UNK8
= 0x2000,
685 MOVEFLAG2_UNK9
= 0x4000,
686 MOVEFLAG2_UNK10
= 0x8000,
687 MOVEFLAG2_INTERP_MASK
= MOVEFLAG2_INTERP_MOVEMENT
| MOVEFLAG2_INTERP_TURNING
| MOVEFLAG2_INTERP_PITCHING
692 SPLINEFLAG_NONE
= 0x00000000,
693 SPLINEFLAG_FORWARD
= 0x00000001,
694 SPLINEFLAG_BACKWARD
= 0x00000002,
695 SPLINEFLAG_STRAFE_LEFT
= 0x00000004,
696 SPLINEFLAG_STRAFE_RIGHT
= 0x00000008,
697 SPLINEFLAG_LEFT
= 0x00000010,
698 SPLINEFLAG_RIGHT
= 0x00000020,
699 SPLINEFLAG_PITCH_UP
= 0x00000040,
700 SPLINEFLAG_PITCH_DOWN
= 0x00000080,
701 SPLINEFLAG_DONE
= 0x00000100,
702 SPLINEFLAG_FALLING
= 0x00000200,
703 SPLINEFLAG_NO_SPLINE
= 0x00000400,
704 SPLINEFLAG_TRAJECTORY
= 0x00000800,
705 SPLINEFLAG_WALKMODE
= 0x00001000,
706 SPLINEFLAG_FLYING
= 0x00002000,
707 SPLINEFLAG_KNOCKBACK
= 0x00004000,
708 SPLINEFLAG_FINALPOINT
= 0x00008000,
709 SPLINEFLAG_FINALTARGET
= 0x00010000,
710 SPLINEFLAG_FINALFACING
= 0x00020000,
711 SPLINEFLAG_CATMULLROM
= 0x00040000,
712 SPLINEFLAG_UNKNOWN1
= 0x00080000,
713 SPLINEFLAG_UNKNOWN2
= 0x00100000,
714 SPLINEFLAG_UNKNOWN3
= 0x00200000,
715 SPLINEFLAG_UNKNOWN4
= 0x00400000,
716 SPLINEFLAG_UNKNOWN5
= 0x00800000,
717 SPLINEFLAG_UNKNOWN6
= 0x01000000,
718 SPLINEFLAG_UNKNOWN7
= 0x02000000,
719 SPLINEFLAG_UNKNOWN8
= 0x04000000,
720 SPLINEFLAG_UNKNOWN9
= 0x08000000,
721 SPLINEFLAG_UNKNOWN10
= 0x10000000,
722 SPLINEFLAG_UNKNOWN11
= 0x20000000,
723 SPLINEFLAG_UNKNOWN12
= 0x40000000
728 SPLINEMODE_LINEAR
= 0,
729 SPLINEMODE_CATMULLROM
= 1,
730 SPLINEMODE_BEZIER3
= 2
735 SPLINETYPE_NORMAL
= 0,
737 SPLINETYPE_FACINGSPOT
= 2,
738 SPLINETYPE_FACINGTARGET
= 3,
739 SPLINETYPE_FACINGANGLE
= 4
744 Position() : x(0.0f
), y(0.0f
), z(0.0f
), o(0.0f
) {}
751 MovementInfo() : moveFlags(MOVEFLAG_NONE
), moveFlags2(MOVEFLAG2_NONE
), time(0),
752 t_time(0), t_seat(-1), t_time2(0), s_pitch(0.0f
), fallTime(0), j_velocity(0.0f
), j_sinAngle(0.0f
),
753 j_cosAngle(0.0f
), j_xyspeed(0.0f
), u_unk1(0.0f
) {}
755 // Read/Write methods
756 void Read(ByteBuffer
&data
);
757 void Write(ByteBuffer
&data
) const;
759 // Movement flags manipulations
760 void AddMovementFlag(MovementFlags f
) { moveFlags
|= f
; }
761 void RemoveMovementFlag(MovementFlags f
) { moveFlags
&= ~f
; }
762 bool HasMovementFlag(MovementFlags f
) const { return moveFlags
& f
; }
763 MovementFlags
GetMovementFlags() const { return MovementFlags(moveFlags
); }
764 void SetMovementFlags(MovementFlags f
) { moveFlags
= f
; }
765 MovementFlags2
GetMovementFlags2() const { return MovementFlags2(moveFlags2
); }
767 // Position manipulations
768 Position
const *GetPos() const { return &pos
; }
769 void SetTransportData(ObjectGuid guid
, float x
, float y
, float z
, float o
, uint32 time
, int8 seat
)
779 void ClearTransportData()
781 t_guid
= ObjectGuid();
789 ObjectGuid
const& GetTransportGuid() const { return t_guid
; }
790 Position
const *GetTransportPos() const { return &t_pos
; }
791 int8
GetTransportSeat() const { return t_seat
; }
792 uint32
GetTransportTime() const { return t_time
; }
793 uint32
GetFallTime() const { return fallTime
; }
794 void ChangePosition(float x
, float y
, float z
, float o
) { pos
.x
= x
; pos
.y
= y
; pos
.z
= z
; pos
.o
= o
; }
795 void UpdateTime(uint32 _time
) { time
= _time
; }
799 uint32 moveFlags
; // see enum MovementFlags
800 uint16 moveFlags2
; // see enum MovementFlags2
809 // swimming and flying
814 float j_velocity
, j_sinAngle
, j_cosAngle
, j_xyspeed
;
819 inline ByteBuffer
& operator<< (ByteBuffer
& buf
, MovementInfo
const& mi
)
825 inline ByteBuffer
& operator>> (ByteBuffer
& buf
, MovementInfo
& mi
)
831 enum DiminishingLevels
833 DIMINISHING_LEVEL_1
= 0,
834 DIMINISHING_LEVEL_2
= 1,
835 DIMINISHING_LEVEL_3
= 2,
836 DIMINISHING_LEVEL_IMMUNE
= 3
839 struct DiminishingReturn
841 DiminishingReturn(DiminishingGroup group
, uint32 t
, uint32 count
)
842 : DRGroup(group
), stack(0), hitTime(t
), hitCount(count
)
845 DiminishingGroup DRGroup
:16;
851 // At least some values expected fixed and used in auras field, other custom
856 MELEE_HIT_DODGE
= 2, // used as misc in SPELL_AURA_IGNORE_COMBAT_RESULT
857 MELEE_HIT_BLOCK
= 3, // used as misc in SPELL_AURA_IGNORE_COMBAT_RESULT
858 MELEE_HIT_PARRY
= 4, // used as misc in SPELL_AURA_IGNORE_COMBAT_RESULT
859 MELEE_HIT_GLANCING
= 5,
861 MELEE_HIT_CRUSHING
= 7,
862 MELEE_HIT_NORMAL
= 8,
867 CleanDamage(uint32 _damage
, WeaponAttackType _attackType
, MeleeHitOutcome _hitOutCome
) :
868 damage(_damage
), attackType(_attackType
), hitOutCome(_hitOutCome
) {}
871 WeaponAttackType attackType
;
872 MeleeHitOutcome hitOutCome
;
875 // Struct for use in Unit::CalculateMeleeDamage
876 // Need create structure like in SMSG_ATTACKERSTATEUPDATE opcode
877 struct CalcDamageInfo
879 Unit
*attacker
; // Attacker
880 Unit
*target
; // Target for damage
881 SpellSchoolMask damageSchoolMask
;
885 uint32 blocked_amount
;
889 WeaponAttackType attackType
; //
893 uint32 cleanDamage
; // Used only for rage calculation
894 MeleeHitOutcome hitOutCome
; // TODO: remove this field (need use TargetState)
897 // Spell damage info structure based on structure sending in SMSG_SPELLNONMELEEDAMAGELOG opcode
898 struct SpellNonMeleeDamage
{
899 SpellNonMeleeDamage(Unit
*_attacker
, Unit
*_target
, uint32 _SpellID
, SpellSchoolMask _schoolMask
)
900 : target(_target
), attacker(_attacker
), SpellID(_SpellID
), damage(0), overkill(0), schoolMask(_schoolMask
),
901 absorb(0), resist(0), physicalLog(false), unused(false), blocked(0), HitInfo(0)
909 SpellSchoolMask schoolMask
;
918 struct SpellPeriodicAuraLogInfo
920 SpellPeriodicAuraLogInfo(Aura
*_aura
, uint32 _damage
, uint32 _overDamage
, uint32 _absorb
, uint32 _resist
, float _multiplier
, bool _critical
= false)
921 : aura(_aura
), damage(_damage
), overDamage(_overDamage
), absorb(_absorb
), resist(_resist
), multiplier(_multiplier
), critical(_critical
) {}
925 uint32 overDamage
; // overkill/overheal
932 uint32
createProcExtendMask(SpellNonMeleeDamage
*damageInfo
, SpellMissInfo missCondition
);
934 #define MAX_DECLINED_NAME_CASES 5
938 std::string name
[MAX_DECLINED_NAME_CASES
];
941 enum CurrentSpellTypes
943 CURRENT_MELEE_SPELL
= 0,
944 CURRENT_GENERIC_SPELL
= 1,
945 CURRENT_AUTOREPEAT_SPELL
= 2,
946 CURRENT_CHANNELED_SPELL
= 3
949 #define CURRENT_FIRST_NON_MELEE_SPELL 1
950 #define CURRENT_MAX_SPELL 4
955 ACT_PASSIVE
= 0x01, // 0x01 - passive
956 ACT_DISABLED
= 0x81, // 0x80 - castable
957 ACT_ENABLED
= 0xC1, // 0x40 | 0x80 - auto cast + castable
958 ACT_COMMAND
= 0x07, // 0x01 | 0x02 | 0x04
959 ACT_REACTION
= 0x06, // 0x02 | 0x04
960 ACT_DECIDE
= 0x00 // custom
978 #define UNIT_ACTION_BUTTON_ACTION(X) (uint32(X) & 0x00FFFFFF)
979 #define UNIT_ACTION_BUTTON_TYPE(X) ((uint32(X) & 0xFF000000) >> 24)
980 #define MAX_UNIT_ACTION_BUTTON_ACTION_VALUE (0x00FFFFFF+1)
981 #define MAKE_UNIT_ACTION_BUTTON(A,T) (uint32(A) | (uint32(T) << 24))
983 struct UnitActionBarEntry
985 UnitActionBarEntry() : packedData(uint32(ACT_DISABLED
) << 24) {}
990 ActiveStates
GetType() const { return ActiveStates(UNIT_ACTION_BUTTON_TYPE(packedData
)); }
991 uint32
GetAction() const { return UNIT_ACTION_BUTTON_ACTION(packedData
); }
992 bool IsActionBarForSpell() const
994 ActiveStates Type
= GetType();
995 return Type
== ACT_DISABLED
|| Type
== ACT_ENABLED
|| Type
== ACT_PASSIVE
;
998 void SetActionAndType(uint32 action
, ActiveStates type
)
1000 packedData
= MAKE_UNIT_ACTION_BUTTON(action
,type
);
1003 void SetType(ActiveStates type
)
1005 packedData
= MAKE_UNIT_ACTION_BUTTON(UNIT_ACTION_BUTTON_ACTION(packedData
),type
);
1008 void SetAction(uint32 action
)
1010 packedData
= (packedData
& 0xFF000000) | UNIT_ACTION_BUTTON_ACTION(action
);
1014 typedef UnitActionBarEntry CharmSpellEntry
;
1018 ACTION_BAR_INDEX_START
= 0,
1019 ACTION_BAR_INDEX_PET_SPELL_START
= 3,
1020 ACTION_BAR_INDEX_PET_SPELL_END
= 7,
1021 ACTION_BAR_INDEX_END
= 10,
1024 #define MAX_UNIT_ACTION_BAR_INDEX (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START)
1029 explicit CharmInfo(Unit
* unit
);
1030 uint32
GetPetNumber() const { return m_petnumber
; }
1031 void SetPetNumber(uint32 petnumber
, bool statwindow
);
1033 void SetCommandState(CommandStates st
) { m_CommandState
= st
; }
1034 CommandStates
GetCommandState() { return m_CommandState
; }
1035 bool HasCommandState(CommandStates state
) { return (m_CommandState
== state
); }
1036 void SetReactState(ReactStates st
) { m_reactState
= st
; }
1037 ReactStates
GetReactState() { return m_reactState
; }
1038 bool HasReactState(ReactStates state
) { return (m_reactState
== state
); }
1040 void InitPossessCreateSpells();
1041 void InitCharmCreateSpells();
1042 void InitPetActionBar();
1043 void InitEmptyActionBar();
1045 //return true if successful
1046 bool AddSpellToActionBar(uint32 spellid
, ActiveStates newstate
= ACT_DECIDE
);
1047 bool RemoveSpellFromActionBar(uint32 spell_id
);
1048 void LoadPetActionBar(const std::string
& data
);
1049 void BuildActionBar(WorldPacket
* data
);
1050 void SetSpellAutocast(uint32 spell_id
, bool state
);
1051 void SetActionBar(uint8 index
, uint32 spellOrAction
,ActiveStates type
)
1053 PetActionBar
[index
].SetActionAndType(spellOrAction
,type
);
1055 UnitActionBarEntry
const* GetActionBarEntry(uint8 index
) const { return &(PetActionBar
[index
]); }
1057 void ToggleCreatureAutocast(uint32 spellid
, bool apply
);
1059 CharmSpellEntry
* GetCharmSpell(uint8 index
) { return &(m_charmspells
[index
]); }
1063 UnitActionBarEntry PetActionBar
[MAX_UNIT_ACTION_BAR_INDEX
];
1064 CharmSpellEntry m_charmspells
[CREATURE_MAX_SPELLS
];
1065 CommandStates m_CommandState
;
1066 ReactStates m_reactState
;
1070 // for clearing special attacks
1071 #define REACTIVE_TIMER_START 4000
1075 REACTIVE_DEFENSE
= 0,
1076 REACTIVE_HUNTER_PARRY
= 1,
1077 REACTIVE_OVERPOWER
= 2
1080 #define MAX_REACTIVE 3
1082 typedef std::set
<uint64
> GuardianPetList
;
1084 // delay time next attack to prevent client attack animation problems
1085 #define ATTACK_DISPLAY_DELAY 200
1086 #define MAX_PLAYER_STEALTH_DETECT_RANGE 45.0f // max distance for detection targets by player
1087 #define MAX_CREATURE_ATTACK_RADIUS 45.0f // max distance for creature aggro (use with CONFIG_FLOAT_RATE_CREATURE_AGGRO)
1089 // Regeneration defines
1090 #define REGEN_TIME_FULL 2000 // For this time difference is computed regen value
1091 #define REGEN_TIME_PRECISE 500 // Used in Spell::CheckPower for precise regeneration in spell cast time
1093 struct SpellProcEventEntry
; // used only privately
1095 class MANGOS_DLL_SPEC Unit
: public WorldObject
1098 typedef std::set
<Unit
*> AttackerSet
;
1099 typedef std::pair
<uint32
, SpellEffectIndex
> spellEffectPair
;
1100 typedef std::multimap
< spellEffectPair
, Aura
*> AuraMap
;
1101 typedef std::list
<Aura
*> AuraList
;
1102 typedef std::list
<DiminishingReturn
> Diminishing
;
1103 typedef std::set
<uint32
> ComboPointHolderSet
;
1104 typedef std::map
<uint8
, uint32
> VisibleAuraMap
;
1109 void RemoveFromWorld();
1111 void CleanupsBeforeDelete(); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units)
1113 DiminishingLevels
GetDiminishing(DiminishingGroup group
);
1114 void IncrDiminishing(DiminishingGroup group
);
1115 void ApplyDiminishingToDuration(DiminishingGroup group
, int32
&duration
,Unit
* caster
, DiminishingLevels Level
, int32 limitduration
);
1116 void ApplyDiminishingAura(DiminishingGroup group
, bool apply
);
1117 void ClearDiminishings() { m_Diminishing
.clear(); }
1119 virtual void Update( uint32 time
);
1121 void setAttackTimer(WeaponAttackType type
, uint32 time
) { m_attackTimer
[type
] = time
; }
1122 void resetAttackTimer(WeaponAttackType type
= BASE_ATTACK
);
1123 uint32
getAttackTimer(WeaponAttackType type
) const { return m_attackTimer
[type
]; }
1124 bool isAttackReady(WeaponAttackType type
= BASE_ATTACK
) const { return m_attackTimer
[type
] == 0; }
1125 bool haveOffhandWeapon() const;
1126 bool canReachWithAttack(Unit
*pVictim
) const;
1127 uint32 m_extraAttacks
;
1129 void _addAttacker(Unit
*pAttacker
) // must be called only from Unit::Attack(Unit*)
1131 AttackerSet::const_iterator itr
= m_attackers
.find(pAttacker
);
1132 if(itr
== m_attackers
.end())
1133 m_attackers
.insert(pAttacker
);
1135 void _removeAttacker(Unit
*pAttacker
) // must be called only from Unit::AttackStop()
1137 m_attackers
.erase(pAttacker
);
1139 Unit
* getAttackerForHelper() // If someone wants to help, who to give them
1141 if (getVictim() != NULL
)
1144 if (!m_attackers
.empty())
1145 return *(m_attackers
.begin());
1149 bool Attack(Unit
*victim
, bool meleeAttack
);
1150 void CastStop(uint32 except_spellid
= 0);
1151 bool AttackStop(bool targetSwitch
= false);
1152 void RemoveAllAttackers();
1153 AttackerSet
const& getAttackers() const { return m_attackers
; }
1154 bool isAttackingPlayer() const;
1155 Unit
* getVictim() const { return m_attacking
; }
1156 void CombatStop(bool includingCast
= false);
1157 void CombatStopWithPets(bool includingCast
= false);
1158 void StopAttackFaction(uint32 faction_id
);
1159 Unit
* SelectRandomUnfriendlyTarget(Unit
* except
= NULL
, float radius
= ATTACK_DISTANCE
) const;
1160 Unit
* SelectRandomFriendlyTarget(Unit
* except
= NULL
, float radius
= ATTACK_DISTANCE
) const;
1161 bool hasNegativeAuraWithInterruptFlag(uint32 flag
);
1162 void SendMeleeAttackStop(Unit
* victim
);
1163 void SendMeleeAttackStart(Unit
* pVictim
);
1165 void addUnitState(uint32 f
) { m_state
|= f
; }
1166 bool hasUnitState(uint32 f
) const { return (m_state
& f
); }
1167 void clearUnitState(uint32 f
) { m_state
&= ~f
; }
1168 bool CanFreeMove() const
1170 return !hasUnitState(UNIT_STAT_NO_FREE_MOVE
) && GetOwnerGUID()==0;
1173 uint32
getLevel() const { return GetUInt32Value(UNIT_FIELD_LEVEL
); }
1174 virtual uint32
getLevelForTarget(Unit
const* /*target*/) const { return getLevel(); }
1175 void SetLevel(uint32 lvl
);
1176 uint8
getRace() const { return GetByteValue(UNIT_FIELD_BYTES_0
, 0); }
1177 uint32
getRaceMask() const { return 1 << (getRace()-1); }
1178 uint8
getClass() const { return GetByteValue(UNIT_FIELD_BYTES_0
, 1); }
1179 uint32
getClassMask() const { return 1 << (getClass()-1); }
1180 uint8
getGender() const { return GetByteValue(UNIT_FIELD_BYTES_0
, 2); }
1182 float GetStat(Stats stat
) const { return float(GetUInt32Value(UNIT_FIELD_STAT0
+stat
)); }
1183 void SetStat(Stats stat
, int32 val
) { SetStatInt32Value(UNIT_FIELD_STAT0
+stat
, val
); }
1184 uint32
GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL
) ; }
1185 void SetArmor(int32 val
) { SetResistance(SPELL_SCHOOL_NORMAL
, val
); }
1187 uint32
GetResistance(SpellSchools school
) const { return GetUInt32Value(UNIT_FIELD_RESISTANCES
+school
); }
1188 void SetResistance(SpellSchools school
, int32 val
) { SetStatInt32Value(UNIT_FIELD_RESISTANCES
+school
,val
); }
1190 uint32
GetHealth() const { return GetUInt32Value(UNIT_FIELD_HEALTH
); }
1191 uint32
GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH
); }
1192 float GetHealthPercent() const { return (GetHealth()*100.0f
) / GetMaxHealth(); }
1193 void SetHealth( uint32 val
);
1194 void SetMaxHealth(uint32 val
);
1195 void SetHealthPercent(float percent
);
1196 int32
ModifyHealth(int32 val
);
1198 Powers
getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0
, 3)); }
1199 void setPowerType(Powers power
);
1200 uint32
GetPower( Powers power
) const { return GetUInt32Value(UNIT_FIELD_POWER1
+power
); }
1201 uint32
GetMaxPower(Powers power
) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1
+power
); }
1202 void SetPower( Powers power
, uint32 val
);
1203 void SetMaxPower(Powers power
, uint32 val
);
1204 int32
ModifyPower(Powers power
, int32 val
);
1205 void ApplyPowerMod(Powers power
, uint32 val
, bool apply
);
1206 void ApplyMaxPowerMod(Powers power
, uint32 val
, bool apply
);
1208 uint32
GetAttackTime(WeaponAttackType att
) const { return (uint32
)(GetFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
)/m_modAttackSpeedPct
[att
]); }
1209 void SetAttackTime(WeaponAttackType att
, uint32 val
) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME
+att
,val
*m_modAttackSpeedPct
[att
]); }
1210 void ApplyAttackTimePercentMod(WeaponAttackType att
,float val
, bool apply
);
1211 void ApplyCastTimePercentMod(float val
, bool apply
);
1213 SheathState
GetSheath() const { return SheathState(GetByteValue(UNIT_FIELD_BYTES_2
, 0)); }
1214 virtual void SetSheath( SheathState sheathed
) { SetByteValue(UNIT_FIELD_BYTES_2
, 0, sheathed
); }
1216 // faction template id
1217 uint32
getFaction() const { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
); }
1218 void setFaction(uint32 faction
) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
, faction
); }
1219 FactionTemplateEntry
const* getFactionTemplateEntry() const;
1220 bool IsHostileTo(Unit
const* unit
) const;
1221 bool IsHostileToPlayers() const;
1222 bool IsFriendlyTo(Unit
const* unit
) const;
1223 bool IsNeutralToAll() const;
1224 bool IsContestedGuard() const
1226 if(FactionTemplateEntry
const* entry
= getFactionTemplateEntry())
1227 return entry
->IsContestedGuardFaction();
1231 bool IsPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
); }
1232 void SetPvP(bool state
);
1233 bool IsFFAPvP() const { return HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
); }
1234 void SetFFAPvP(bool state
);
1235 uint32
GetCreatureType() const;
1236 uint32
GetCreatureTypeMask() const
1238 uint32 creatureType
= GetCreatureType();
1239 return (creatureType
>= 1) ? (1 << (creatureType
- 1)) : 0;
1242 uint8
getStandState() const { return GetByteValue(UNIT_FIELD_BYTES_1
, 0); }
1243 bool IsSitState() const;
1244 bool IsStandState() const;
1245 void SetStandState(uint8 state
);
1247 void SetStandFlags(uint8 flags
) { SetByteFlag(UNIT_FIELD_BYTES_1
, 2,flags
); }
1248 void RemoveStandFlags(uint8 flags
) { RemoveByteFlag(UNIT_FIELD_BYTES_1
, 2,flags
); }
1250 bool IsMounted() const { return HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_MOUNT
); }
1251 uint32
GetMountID() const { return GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
); }
1252 void Mount(uint32 mount
, uint32 spellId
= 0);
1255 uint16
GetMaxSkillValueForLevel(Unit
const* target
= NULL
) const { return (target
? getLevelForTarget(target
) : getLevel()) * 5; }
1256 void DealDamageMods(Unit
*pVictim
, uint32
&damage
, uint32
* absorb
);
1257 uint32
DealDamage(Unit
*pVictim
, uint32 damage
, CleanDamage
const* cleanDamage
, DamageEffectType damagetype
, SpellSchoolMask damageSchoolMask
, SpellEntry
const *spellProto
, bool durabilityLoss
);
1258 int32
DealHeal(Unit
*pVictim
, uint32 addhealth
, SpellEntry
const *spellProto
, bool critical
= false);
1260 void ProcDamageAndSpell(Unit
*pVictim
, uint32 procAttacker
, uint32 procVictim
, uint32 procEx
, uint32 amount
, WeaponAttackType attType
= BASE_ATTACK
, SpellEntry
const *procSpell
= NULL
);
1261 void ProcDamageAndSpellFor( bool isVictim
, Unit
* pTarget
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, SpellEntry
const * procSpell
, uint32 damage
);
1263 void HandleEmote(uint32 anim_id
); // auto-select command/state
1264 void HandleEmoteCommand(uint32 anim_id
);
1265 void HandleEmoteState(uint32 anim_id
);
1266 void AttackerStateUpdate (Unit
*pVictim
, WeaponAttackType attType
= BASE_ATTACK
, bool extra
= false );
1268 float MeleeMissChanceCalc(const Unit
*pVictim
, WeaponAttackType attType
) const;
1270 void CalculateMeleeDamage(Unit
*pVictim
, uint32 damage
, CalcDamageInfo
*damageInfo
, WeaponAttackType attackType
= BASE_ATTACK
);
1271 void DealMeleeDamage(CalcDamageInfo
*damageInfo
, bool durabilityLoss
);
1273 void CalculateSpellDamage(SpellNonMeleeDamage
*damageInfo
, int32 damage
, SpellEntry
const *spellInfo
, WeaponAttackType attackType
= BASE_ATTACK
);
1274 void DealSpellDamage(SpellNonMeleeDamage
*damageInfo
, bool durabilityLoss
);
1276 // player or player's pet resilience (-1%)
1277 float GetMeleeCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_MELEE
); }
1278 float GetRangedCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_RANGED
); }
1279 float GetSpellCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_SPELL
); }
1281 // player or player's pet resilience (-1%)
1282 uint32
GetMeleeCritDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE
, 2.2f
, 33.0f
, damage
); }
1283 uint32
GetRangedCritDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_RANGED
, 2.2f
, 33.0f
, damage
); }
1284 uint32
GetSpellCritDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_SPELL
, 2.2f
, 33.0f
, damage
); }
1286 // player or player's pet resilience (-1%), cap 100%
1287 uint32
GetMeleeDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE
, 1.0f
, 100.0f
, damage
); }
1288 uint32
GetRangedDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE
, 1.0f
, 100.0f
, damage
); }
1289 uint32
GetSpellDamageReduction(uint32 damage
) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE
, 1.0f
, 100.0f
, damage
); }
1291 float MeleeSpellMissChance(Unit
*pVictim
, WeaponAttackType attType
, int32 skillDiff
, SpellEntry
const *spell
);
1292 SpellMissInfo
MeleeSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
);
1293 SpellMissInfo
MagicSpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
);
1294 SpellMissInfo
SpellHitResult(Unit
*pVictim
, SpellEntry
const *spell
, bool canReflect
= false);
1296 float GetUnitDodgeChance() const;
1297 float GetUnitParryChance() const;
1298 float GetUnitBlockChance() const;
1299 float GetUnitCriticalChance(WeaponAttackType attackType
, const Unit
*pVictim
) const;
1301 virtual uint32
GetShieldBlockValue() const =0;
1302 uint32
GetUnitMeleeSkill(Unit
const* target
= NULL
) const { return (target
? getLevelForTarget(target
) : getLevel()) * 5; }
1303 uint32
GetDefenseSkillValue(Unit
const* target
= NULL
) const;
1304 uint32
GetWeaponSkillValue(WeaponAttackType attType
, Unit
const* target
= NULL
) const;
1305 float GetWeaponProcChance() const;
1306 float GetPPMProcChance(uint32 WeaponSpeed
, float PPM
) const;
1308 MeleeHitOutcome
RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
) const;
1309 MeleeHitOutcome
RollMeleeOutcomeAgainst (const Unit
*pVictim
, WeaponAttackType attType
, int32 crit_chance
, int32 miss_chance
, int32 dodge_chance
, int32 parry_chance
, int32 block_chance
) const;
1311 bool isVendor() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_VENDOR
); }
1312 bool isTrainer() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_TRAINER
); }
1313 bool isQuestGiver() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_QUESTGIVER
); }
1314 bool isGossip() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_GOSSIP
); }
1315 bool isTaxi() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_FLIGHTMASTER
); }
1316 bool isGuildMaster() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_PETITIONER
); }
1317 bool isBattleMaster() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_BATTLEMASTER
); }
1318 bool isBanker() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_BANKER
); }
1319 bool isInnkeeper() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_INNKEEPER
); }
1320 bool isSpiritHealer() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPIRITHEALER
); }
1321 bool isSpiritGuide() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPIRITGUIDE
); }
1322 bool isTabardDesigner()const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_TABARDDESIGNER
); }
1323 bool isAuctioner() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_AUCTIONEER
); }
1324 bool isArmorer() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_REPAIR
); }
1325 bool isServiceProvider() const
1327 return HasFlag( UNIT_NPC_FLAGS
,
1328 UNIT_NPC_FLAG_VENDOR
| UNIT_NPC_FLAG_TRAINER
| UNIT_NPC_FLAG_FLIGHTMASTER
|
1329 UNIT_NPC_FLAG_PETITIONER
| UNIT_NPC_FLAG_BATTLEMASTER
| UNIT_NPC_FLAG_BANKER
|
1330 UNIT_NPC_FLAG_INNKEEPER
| UNIT_NPC_FLAG_GUARD
| UNIT_NPC_FLAG_SPIRITHEALER
|
1331 UNIT_NPC_FLAG_SPIRITGUIDE
| UNIT_NPC_FLAG_TABARDDESIGNER
| UNIT_NPC_FLAG_AUCTIONEER
);
1333 bool isSpiritService() const { return HasFlag( UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPIRITHEALER
| UNIT_NPC_FLAG_SPIRITGUIDE
); }
1335 //Need fix or use this
1336 bool isGuard() const { return HasFlag(UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_GUARD
); }
1338 bool isInFlight() const { return hasUnitState(UNIT_STAT_IN_FLIGHT
); }
1340 bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_IN_COMBAT
); }
1341 void SetInCombatState(bool PvP
, Unit
* enemy
= NULL
);
1342 void SetInCombatWith(Unit
* enemy
);
1343 void ClearInCombat();
1344 uint32
GetCombatTimer() const { return m_CombatTimer
; }
1346 bool HasAuraType(AuraType auraType
) const;
1347 bool HasAura(uint32 spellId
, SpellEffectIndex effIndex
) const
1349 return m_Auras
.find(spellEffectPair(spellId
, effIndex
)) != m_Auras
.end();
1351 bool HasAura(uint32 spellId
) const;
1353 bool virtual HasSpell(uint32
/*spellID*/) const { return false; }
1355 bool HasStealthAura() const { return HasAuraType(SPELL_AURA_MOD_STEALTH
); }
1356 bool HasInvisibilityAura() const { return HasAuraType(SPELL_AURA_MOD_INVISIBILITY
); }
1357 bool isFeared() const { return HasAuraType(SPELL_AURA_MOD_FEAR
); }
1358 bool isInRoots() const { return HasAuraType(SPELL_AURA_MOD_ROOT
); }
1359 bool IsPolymorphed() const;
1361 bool isFrozen() const;
1363 void RemoveSpellbyDamageTaken(AuraType auraType
, uint32 damage
);
1365 bool isTargetableForAttack(bool inversAlive
= false) const;
1366 bool isPassiveToHostile() { return HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PASSIVE
); }
1368 virtual bool IsInWater() const;
1369 virtual bool IsUnderWater() const;
1370 bool isInAccessablePlaceFor(Creature
const* c
) const;
1372 void SendHealSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, uint32 OverHeal
, bool critical
= false);
1373 void SendEnergizeSpellLog(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
,Powers powertype
);
1374 void EnergizeBySpell(Unit
*pVictim
, uint32 SpellID
, uint32 Damage
, Powers powertype
);
1375 uint32
SpellNonMeleeDamageLog(Unit
*pVictim
, uint32 spellID
, uint32 damage
);
1376 void CastSpell(Unit
* Victim
, uint32 spellId
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, ObjectGuid originalCaster
= ObjectGuid());
1377 void CastSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, ObjectGuid originalCaster
= ObjectGuid());
1378 void CastCustomSpell(Unit
* Victim
, uint32 spellId
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, ObjectGuid originalCaster
= ObjectGuid());
1379 void CastCustomSpell(Unit
* Victim
,SpellEntry
const *spellInfo
, int32
const* bp0
, int32
const* bp1
, int32
const* bp2
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, ObjectGuid originalCaster
= ObjectGuid());
1380 void CastSpell(float x
, float y
, float z
, uint32 spellId
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, ObjectGuid originalCaster
= ObjectGuid());
1381 void CastSpell(float x
, float y
, float z
, SpellEntry
const *spellInfo
, bool triggered
, Item
*castItem
= NULL
, Aura
* triggeredByAura
= NULL
, ObjectGuid originalCaster
= ObjectGuid());
1383 bool IsDamageToThreatSpell(SpellEntry
const * spellInfo
) const;
1387 void SendAttackStateUpdate(CalcDamageInfo
*damageInfo
);
1388 void SendAttackStateUpdate(uint32 HitInfo
, Unit
*target
, uint8 SwingType
, SpellSchoolMask damageSchoolMask
, uint32 Damage
, uint32 AbsorbDamage
, uint32 Resist
, VictimState TargetState
, uint32 BlockedAmount
);
1389 void SendSpellNonMeleeDamageLog(SpellNonMeleeDamage
*log
);
1390 void SendSpellNonMeleeDamageLog(Unit
*target
,uint32 SpellID
, uint32 Damage
, SpellSchoolMask damageSchoolMask
, uint32 AbsorbedDamage
, uint32 Resist
, bool PhysicalDamage
, uint32 Blocked
, bool CriticalHit
= false);
1391 void SendPeriodicAuraLog(SpellPeriodicAuraLogInfo
*pInfo
);
1392 void SendSpellMiss(Unit
*target
, uint32 spellID
, SpellMissInfo missInfo
);
1394 void NearTeleportTo(float x
, float y
, float z
, float orientation
, bool casting
= false);
1396 void MonsterMove(float x
, float y
, float z
, uint32 transitTime
);
1397 void MonsterMoveWithSpeed(float x
, float y
, float z
, uint32 transitTime
= 0);
1399 // recommend use MonsterMove/MonsterMoveWithSpeed for most case that correctly work with movegens
1400 // if used additional args in ... part then floats must explicitly casted to double
1401 void SendMonsterMove(float x
, float y
, float z
, SplineType type
, SplineFlags flags
, uint32 Time
, Player
* player
= NULL
, ...);
1402 void SendMonsterMoveWithSpeed(float x
, float y
, float z
, uint32 transitTime
= 0, Player
* player
= NULL
);
1404 template<typename PathElem
, typename PathNode
>
1405 void SendMonsterMoveByPath(Path
<PathElem
,PathNode
> const& path
, uint32 start
, uint32 end
, SplineFlags flags
);
1407 void SendHighestThreatUpdate(HostileReference
* pHostileReference
);
1408 void SendThreatClear();
1409 void SendThreatRemove(HostileReference
* pHostileReference
);
1410 void SendThreatUpdate();
1412 void BuildHeartBeatMsg( WorldPacket
*data
) const;
1414 virtual void MoveOutOfRange(Player
&) { };
1416 bool isAlive() const { return (m_deathState
== ALIVE
); };
1417 bool isDead() const { return ( m_deathState
== DEAD
|| m_deathState
== CORPSE
); };
1418 DeathState
getDeathState() { return m_deathState
; };
1419 virtual void setDeathState(DeathState s
); // overwritten in Creature/Player/Pet
1421 uint64
GetOwnerGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMONEDBY
); }
1422 void SetOwnerGUID(uint64 owner
) { SetUInt64Value(UNIT_FIELD_SUMMONEDBY
, owner
); }
1423 uint64
GetCreatorGUID() const { return GetUInt64Value(UNIT_FIELD_CREATEDBY
); }
1424 void SetCreatorGUID(uint64 creator
) { SetUInt64Value(UNIT_FIELD_CREATEDBY
, creator
); }
1425 uint64
GetPetGUID() const { return GetUInt64Value(UNIT_FIELD_SUMMON
); }
1426 void SetPetGUID(uint64 pet
) { SetUInt64Value(UNIT_FIELD_SUMMON
, pet
); }
1427 uint64
GetCharmerGUID() const { return GetUInt64Value(UNIT_FIELD_CHARMEDBY
); }
1428 void SetCharmerGUID(uint64 owner
) { SetUInt64Value(UNIT_FIELD_CHARMEDBY
, owner
); }
1429 uint64
GetCharmGUID() const { return GetUInt64Value(UNIT_FIELD_CHARM
); }
1430 void SetCharmGUID(uint64 charm
) { SetUInt64Value(UNIT_FIELD_CHARM
, charm
); }
1431 uint64
GetTargetGUID() const { return GetUInt64Value(UNIT_FIELD_TARGET
); }
1432 void SetTargetGUID(uint64 targetGuid
) { SetUInt64Value(UNIT_FIELD_TARGET
, targetGuid
); }
1433 uint64
GetChannelObjectGUID() const { return GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
); }
1434 void SetChannelObjectGUID(uint64 targetGuid
) { SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, targetGuid
); }
1436 uint64
GetCharmerOrOwnerGUID() const { return GetCharmerGUID() ? GetCharmerGUID() : GetOwnerGUID(); }
1437 uint64
GetCharmerOrOwnerOrOwnGUID() const
1439 if(uint64 guid
= GetCharmerOrOwnerGUID())
1443 bool isCharmedOwnedByPlayerOrPlayer() const { return IS_PLAYER_GUID(GetCharmerOrOwnerOrOwnGUID()); }
1445 Player
* GetSpellModOwner();
1447 Unit
* GetOwner() const;
1448 Pet
* GetPet() const;
1449 Unit
* GetCharmer() const;
1450 Unit
* GetCharm() const;
1452 Unit
* GetCharmerOrOwner() const { return GetCharmerGUID() ? GetCharmer() : GetOwner(); }
1453 Unit
* GetCharmerOrOwnerOrSelf()
1455 if(Unit
* u
= GetCharmerOrOwner())
1460 bool IsCharmerOrOwnerPlayerOrPlayerItself() const;
1461 Player
* GetCharmerOrOwnerPlayerOrPlayerItself();
1462 float GetCombatDistance( const Unit
* target
) const;
1464 void SetPet(Pet
* pet
);
1465 void SetCharm(Unit
* pet
);
1467 void AddGuardian(Pet
* pet
);
1468 void RemoveGuardian(Pet
* pet
);
1469 void RemoveGuardians();
1470 Pet
* FindGuardianWithEntry(uint32 entry
);
1472 bool isCharmed() const { return GetCharmerGUID() != 0; }
1474 CharmInfo
* GetCharmInfo() { return m_charmInfo
; }
1475 CharmInfo
* InitCharmInfo(Unit
* charm
);
1477 Pet
* CreateTamedPetFrom(Creature
* creatureTarget
,uint32 spell_id
= 0);
1479 uint64
const& GetTotemGUID(TotemSlot slot
) const { return m_TotemSlot
[slot
]; }
1480 Totem
* GetTotem(TotemSlot slot
) const;
1481 bool IsAllTotemSlotsUsed() const;
1483 void _AddTotem(TotemSlot slot
, Totem
* totem
); // only for call from Totem summon code
1484 void _RemoveTotem(Totem
* totem
); // only for call from Totem class
1486 template<typename Func
>
1487 void CallForAllControlledUnits(Func
const& func
, bool withTotems
, bool withGuardians
, bool withCharms
);
1488 template<typename Func
>
1489 bool CheckAllControlledUnits(Func
const& func
, bool withTotems
, bool withGuardians
, bool withCharms
) const;
1491 bool AddAura(Aura
*aur
);
1493 // removing specific aura stack
1494 void RemoveAura(Aura
* aura
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1495 void RemoveAura(AuraMap::iterator
&i
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1496 void RemoveAura(uint32 spellId
, SpellEffectIndex effindex
, Aura
* except
= NULL
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1498 // removing specific aura stacks by diff reasons and selections
1499 void RemoveAurasDueToSpell(uint32 spellId
, Aura
* except
= NULL
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1500 void RemoveAurasDueToItemSpell(Item
* castItem
,uint32 spellId
);
1501 void RemoveAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
);
1502 void RemoveAurasByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
);
1503 void RemoveAurasDueToSpellBySteal(uint32 spellId
, uint64 casterGUID
, Unit
*stealer
);
1504 void RemoveAurasDueToSpellByCancel(uint32 spellId
);
1506 // removing unknown aura stacks by diff reasons and selections
1507 void RemoveNotOwnSingleTargetAuras(uint32 newPhase
= 0x0);
1508 void RemoveAurasAtMechanicImmunity(uint32 mechMask
, uint32 exceptSpellId
, bool non_positive
= false);
1509 void RemoveSpellsCausingAura(AuraType auraType
);
1510 void RemoveRankAurasDueToSpell(uint32 spellId
);
1511 bool RemoveNoStackAurasDueToAura(Aura
*Aur
);
1512 void RemoveAurasWithInterruptFlags(uint32 flags
);
1513 void RemoveAurasWithDispelType( DispelType type
);
1514 void RemoveAllAuras(AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1515 void RemoveArenaAuras(bool onleave
= false);
1516 void RemoveAllAurasOnDeath();
1518 // removing specific aura FROM stack
1519 void RemoveSingleAuraFromStack(uint32 spellId
, SpellEffectIndex effindex
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1520 void RemoveSingleAuraFromStack(AuraMap::iterator
&i
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1522 // removing specific aura FROM stack by diff reasons and selections
1523 void RemoveSingleSpellAurasFromStack(uint32 spellId
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1524 void RemoveSingleSpellAurasByCasterSpell(uint32 spellId
, uint64 casterGUID
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1525 void RemoveSingleAuraByCasterSpell(uint32 spellId
, SpellEffectIndex effindex
, uint64 casterGUID
, AuraRemoveMode mode
= AURA_REMOVE_BY_DEFAULT
);
1526 void RemoveSingleAuraDueToSpellByDispel(uint32 spellId
, uint64 casterGUID
, Unit
*dispeler
);
1528 void DelayAura(uint32 spellId
, SpellEffectIndex effindex
, int32 delaytime
);
1530 float GetResistanceBuffMods(SpellSchools school
, bool positive
) const { return GetFloatValue(positive
? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+school
: UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+school
); }
1531 void SetResistanceBuffMods(SpellSchools school
, bool positive
, float val
) { SetFloatValue(positive
? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+school
: UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+school
,val
); }
1532 void ApplyResistanceBuffModsMod(SpellSchools school
, bool positive
, float val
, bool apply
) { ApplyModSignedFloatValue(positive
? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+school
: UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+school
, val
, apply
); }
1533 void ApplyResistanceBuffModsPercentMod(SpellSchools school
, bool positive
, float val
, bool apply
) { ApplyPercentModFloatValue(positive
? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+school
: UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+school
, val
, apply
); }
1534 void InitStatBuffMods()
1536 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
) SetFloatValue(UNIT_FIELD_POSSTAT0
+i
, 0);
1537 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
) SetFloatValue(UNIT_FIELD_NEGSTAT0
+i
, 0);
1539 void ApplyStatBuffMod(Stats stat
, float val
, bool apply
) { ApplyModSignedFloatValue((val
> 0 ? UNIT_FIELD_POSSTAT0
+stat
: UNIT_FIELD_NEGSTAT0
+stat
), val
, apply
); }
1540 void ApplyStatPercentBuffMod(Stats stat
, float val
, bool apply
)
1542 ApplyPercentModFloatValue(UNIT_FIELD_POSSTAT0
+stat
, val
, apply
);
1543 ApplyPercentModFloatValue(UNIT_FIELD_NEGSTAT0
+stat
, val
, apply
);
1545 void SetCreateStat(Stats stat
, float val
) { m_createStats
[stat
] = val
; }
1546 void SetCreateHealth(uint32 val
) { SetUInt32Value(UNIT_FIELD_BASE_HEALTH
, val
); }
1547 uint32
GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH
); }
1548 void SetCreateMana(uint32 val
) { SetUInt32Value(UNIT_FIELD_BASE_MANA
, val
); }
1549 uint32
GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA
); }
1550 uint32
GetCreatePowers(Powers power
) const;
1551 float GetPosStat(Stats stat
) const { return GetFloatValue(UNIT_FIELD_POSSTAT0
+stat
); }
1552 float GetNegStat(Stats stat
) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0
+stat
); }
1553 float GetCreateStat(Stats stat
) const { return m_createStats
[stat
]; }
1555 void SetCurrentCastedSpell(Spell
* pSpell
);
1556 virtual void ProhibitSpellSchool(SpellSchoolMask
/*idSchoolMask*/, uint32
/*unTimeMs*/ ) { }
1557 void InterruptSpell(CurrentSpellTypes spellType
, bool withDelayed
= true, bool sendAutoRepeatCancelToClient
= true);
1558 void FinishSpell(CurrentSpellTypes spellType
, bool ok
= true);
1560 // set withDelayed to true to account delayed spells as casted
1561 // delayed+channeled spells are always accounted as casted
1562 // we can skip channeled or delayed checks using flags
1563 bool IsNonMeleeSpellCasted(bool withDelayed
, bool skipChanneled
= false, bool skipAutorepeat
= false) const;
1565 // set withDelayed to true to interrupt delayed spells too
1566 // delayed+channeled spells are always interrupted
1567 void InterruptNonMeleeSpells(bool withDelayed
, uint32 spellid
= 0);
1569 Spell
* GetCurrentSpell(CurrentSpellTypes spellType
) const { return m_currentSpells
[spellType
]; }
1570 Spell
* FindCurrentSpellBySpellId(uint32 spell_id
) const;
1572 bool CheckAndIncreaseCastCounter();
1573 void DecreaseCastCounter() { if (m_castCounter
) --m_castCounter
; }
1575 uint32 m_addDmgOnce
;
1576 uint64 m_ObjectSlot
[4];
1577 uint32 m_detectInvisibilityMask
;
1578 uint32 m_invisibilityMask
;
1580 uint32 m_ShapeShiftFormSpellId
;
1581 ShapeshiftForm m_form
;
1582 bool IsInFeralForm() const { return m_form
== FORM_CAT
|| m_form
== FORM_BEAR
|| m_form
== FORM_DIREBEAR
; }
1584 float m_modMeleeHitChance
;
1585 float m_modRangedHitChance
;
1586 float m_modSpellHitChance
;
1587 int32 m_baseSpellCritChance
;
1589 float m_threatModifier
[MAX_SPELL_SCHOOL
];
1590 float m_modAttackSpeedPct
[3];
1593 EventProcessor m_Events
;
1596 bool HandleStatModifier(UnitMods unitMod
, UnitModifierType modifierType
, float amount
, bool apply
);
1597 void SetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
, float value
) { m_auraModifiersGroup
[unitMod
][modifierType
] = value
; }
1598 float GetModifierValue(UnitMods unitMod
, UnitModifierType modifierType
) const;
1599 float GetTotalStatValue(Stats stat
) const;
1600 float GetTotalAuraModValue(UnitMods unitMod
) const;
1601 SpellSchools
GetSpellSchoolByAuraGroup(UnitMods unitMod
) const;
1602 Stats
GetStatByAuraGroup(UnitMods unitMod
) const;
1603 Powers
GetPowerTypeByAuraGroup(UnitMods unitMod
) const;
1604 bool CanModifyStats() const { return m_canModifyStats
; }
1605 void SetCanModifyStats(bool modifyStats
) { m_canModifyStats
= modifyStats
; }
1606 virtual bool UpdateStats(Stats stat
) = 0;
1607 virtual bool UpdateAllStats() = 0;
1608 virtual void UpdateResistances(uint32 school
) = 0;
1609 virtual void UpdateArmor() = 0;
1610 virtual void UpdateMaxHealth() = 0;
1611 virtual void UpdateMaxPower(Powers power
) = 0;
1612 virtual void UpdateAttackPowerAndDamage(bool ranged
= false) = 0;
1613 virtual void UpdateDamagePhysical(WeaponAttackType attType
) = 0;
1614 float GetTotalAttackPowerValue(WeaponAttackType attType
) const;
1615 float GetWeaponDamageRange(WeaponAttackType attType
,WeaponDamageRange type
) const;
1616 void SetBaseWeaponDamage(WeaponAttackType attType
,WeaponDamageRange damageRange
, float value
) { m_weaponDamage
[attType
][damageRange
] = value
; }
1618 void SetInFront(Unit
const* target
);
1619 void SetFacingTo(float ori
);
1620 void SetFacingToObject(WorldObject
* pObject
);
1622 // Visibility system
1623 UnitVisibility
GetVisibility() const { return m_Visibility
; }
1624 void SetVisibility(UnitVisibility x
);
1626 // common function for visibility checks for player/creatures with detection code
1627 bool isVisibleForOrDetect(Unit
const* u
, WorldObject
const* viewPoint
, bool detect
, bool inVisibleList
= false, bool is3dDistance
= true) const;
1628 bool canDetectInvisibilityOf(Unit
const* u
) const;
1629 void SetPhaseMask(uint32 newPhaseMask
, bool update
);// overwrite WorldObject::SetPhaseMask
1631 // virtual functions for all world objects types
1632 bool isVisibleForInState(Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const;
1633 // function for low level grid visibility checks in player/creature cases
1634 virtual bool IsVisibleInGridForPlayer(Player
* pl
) const = 0;
1635 bool isInvisibleForAlive() const;
1637 AuraList
& GetSingleCastAuras() { return m_scAuras
; }
1638 AuraList
const& GetSingleCastAuras() const { return m_scAuras
; }
1639 SpellImmuneList m_spellImmune
[MAX_SPELL_IMMUNITY
];
1641 // Threat related methods
1642 bool CanHaveThreatList() const;
1643 void AddThreat(Unit
* pVictim
, float threat
= 0.0f
, bool crit
= false, SpellSchoolMask schoolMask
= SPELL_SCHOOL_MASK_NONE
, SpellEntry
const *threatSpell
= NULL
);
1644 float ApplyTotalThreatModifier(float threat
, SpellSchoolMask schoolMask
= SPELL_SCHOOL_MASK_NORMAL
);
1645 void DeleteThreatList();
1646 bool SelectHostileTarget();
1647 void TauntApply(Unit
* pVictim
);
1648 void TauntFadeOut(Unit
*taunter
);
1649 ThreatManager
& getThreatManager() { return m_ThreatManager
; }
1650 ThreatManager
const& getThreatManager() const { return m_ThreatManager
; }
1651 void addHatedBy(HostileReference
* pHostileReference
) { m_HostileRefManager
.insertFirst(pHostileReference
); };
1652 void removeHatedBy(HostileReference
* /*pHostileReference*/ ) { /* nothing to do yet */ }
1653 HostileRefManager
& getHostileRefManager() { return m_HostileRefManager
; }
1655 uint32
GetVisibleAura(uint8 slot
)
1657 VisibleAuraMap::const_iterator itr
= m_visibleAuras
.find(slot
);
1658 if(itr
!= m_visibleAuras
.end())
1662 void SetVisibleAura(uint8 slot
, uint32 spellid
)
1665 m_visibleAuras
.erase(slot
);
1667 m_visibleAuras
[slot
] = spellid
;
1669 VisibleAuraMap
const *GetVisibleAuras() { return &m_visibleAuras
; }
1670 uint8
GetVisibleAurasCount() { return m_visibleAuras
.size(); }
1672 Aura
* GetAura(uint32 spellId
, SpellEffectIndex effindex
);
1673 Aura
* GetAura(AuraType type
, uint32 family
, uint64 familyFlag
, uint32 familyFlag2
= 0, uint64 casterGUID
= 0);
1675 AuraMap
& GetAuras() { return m_Auras
; }
1676 AuraMap
const& GetAuras() const { return m_Auras
; }
1677 AuraList
const& GetAurasByType(AuraType type
) const { return m_modAuras
[type
]; }
1678 void ApplyAuraProcTriggerDamage(Aura
* aura
, bool apply
);
1680 int32
GetTotalAuraModifier(AuraType auratype
) const;
1681 float GetTotalAuraMultiplier(AuraType auratype
) const;
1682 int32
GetMaxPositiveAuraModifier(AuraType auratype
) const;
1683 int32
GetMaxNegativeAuraModifier(AuraType auratype
) const;
1685 int32
GetTotalAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const;
1686 float GetTotalAuraMultiplierByMiscMask(AuraType auratype
, uint32 misc_mask
) const;
1687 int32
GetMaxPositiveAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const;
1688 int32
GetMaxNegativeAuraModifierByMiscMask(AuraType auratype
, uint32 misc_mask
) const;
1690 int32
GetTotalAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const;
1691 float GetTotalAuraMultiplierByMiscValue(AuraType auratype
, int32 misc_value
) const;
1692 int32
GetMaxPositiveAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const;
1693 int32
GetMaxNegativeAuraModifierByMiscValue(AuraType auratype
, int32 misc_value
) const;
1695 // misc have plain value but we check it fit to provided values mask (mask & (1 << (misc-1)))
1696 float GetTotalAuraMultiplierByMiscValueForMask(AuraType auratype
, uint32 mask
) const;
1698 Aura
* GetDummyAura(uint32 spell_id
) const;
1702 uint32
GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID
); }
1703 void SetDisplayId(uint32 modelId
);
1704 uint32
GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID
); }
1705 void SetNativeDisplayId(uint32 modelId
) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID
, modelId
); }
1706 void setTransForm(uint32 spellid
) { m_transform
= spellid
;}
1707 uint32
getTransForm() const { return m_transform
;}
1709 DynamicObject
* GetDynObject(uint32 spellId
, SpellEffectIndex effIndex
);
1710 DynamicObject
* GetDynObject(uint32 spellId
);
1711 void AddDynObject(DynamicObject
* dynObj
);
1712 void RemoveDynObject(uint32 spellid
);
1713 void RemoveDynObjectWithGUID(uint64 guid
) { m_dynObjGUIDs
.remove(guid
); }
1714 void RemoveAllDynObjects();
1716 GameObject
* GetGameObject(uint32 spellId
) const;
1717 void AddGameObject(GameObject
* gameObj
);
1718 void RemoveGameObject(GameObject
* gameObj
, bool del
);
1719 void RemoveGameObject(uint32 spellid
, bool del
);
1720 void RemoveAllGameObjects();
1722 uint32
CalculateDamage(WeaponAttackType attType
, bool normalized
);
1723 float GetAPMultiplier(WeaponAttackType attType
, bool normalized
);
1724 void ModifyAuraState(AuraState flag
, bool apply
);
1725 bool HasAuraState(AuraState flag
) const { return HasFlag(UNIT_FIELD_AURASTATE
, 1<<(flag
-1)); }
1726 bool HasAuraStateForCaster(AuraState flag
, uint64 caster
) const;
1727 void UnsummonAllTotems();
1728 Unit
* SelectMagnetTarget(Unit
*victim
, SpellEntry
const *spellInfo
= NULL
);
1730 int32
SpellBonusWithCoeffs(SpellEntry
const *spellProto
, int32 total
, int32 benefit
, int32 ap_benefit
, DamageEffectType damagetype
, bool donePart
, float defCoeffMod
= 1.0f
);
1731 int32
SpellBaseDamageBonusDone(SpellSchoolMask schoolMask
);
1732 int32
SpellBaseDamageBonusTaken(SpellSchoolMask schoolMask
);
1733 uint32
SpellDamageBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
= 1);
1734 uint32
SpellDamageBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, uint32 pdamage
, DamageEffectType damagetype
, uint32 stack
= 1);
1735 int32
SpellBaseHealingBonusDone(SpellSchoolMask schoolMask
);
1736 int32
SpellBaseHealingBonusTaken(SpellSchoolMask schoolMask
);
1737 uint32
SpellHealingBonusDone(Unit
*pVictim
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
= 1);
1738 uint32
SpellHealingBonusTaken(Unit
*pCaster
, SpellEntry
const *spellProto
, int32 healamount
, DamageEffectType damagetype
, uint32 stack
= 1);
1739 uint32
MeleeDamageBonusDone(Unit
*pVictim
, uint32 damage
, WeaponAttackType attType
, SpellEntry
const *spellProto
= NULL
, DamageEffectType damagetype
= DIRECT_DAMAGE
, uint32 stack
= 1);
1740 uint32
MeleeDamageBonusTaken(Unit
*pCaster
, uint32 pdamage
,WeaponAttackType attType
, SpellEntry
const *spellProto
= NULL
, DamageEffectType damagetype
= DIRECT_DAMAGE
, uint32 stack
= 1);
1742 bool IsSpellBlocked(Unit
*pCaster
, SpellEntry
const *spellProto
, WeaponAttackType attackType
= BASE_ATTACK
);
1743 bool IsSpellCrit(Unit
*pVictim
, SpellEntry
const *spellProto
, SpellSchoolMask schoolMask
, WeaponAttackType attackType
= BASE_ATTACK
);
1744 uint32
SpellCriticalDamageBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
);
1745 uint32
SpellCriticalHealingBonus(SpellEntry
const *spellProto
, uint32 damage
, Unit
*pVictim
);
1747 void SetLastManaUse()
1749 if (GetTypeId() == TYPEID_PLAYER
&& !IsUnderLastManaUseEffect())
1750 RemoveFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_REGENERATE_POWER
);
1752 m_lastManaUseTimer
= 5000;
1754 bool IsUnderLastManaUseEffect() const { return m_lastManaUseTimer
; }
1756 uint32
GetRegenTimer() const { return m_regenTimer
; }
1758 void SetContestedPvP(Player
*attackedPlayer
= NULL
);
1760 void ApplySpellImmune(uint32 spellId
, uint32 op
, uint32 type
, bool apply
);
1761 void ApplySpellDispelImmunity(const SpellEntry
* spellProto
, DispelType type
, bool apply
);
1762 virtual bool IsImmunedToSpell(SpellEntry
const* spellInfo
);
1763 // redefined in Creature
1764 bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask
);
1765 virtual bool IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, SpellEffectIndex index
) const;
1766 // redefined in Creature
1768 uint32
CalcArmorReducedDamage(Unit
* pVictim
, const uint32 damage
);
1769 void CalculateAbsorbAndResist(Unit
*pCaster
, SpellSchoolMask schoolMask
, DamageEffectType damagetype
, const uint32 damage
, uint32
*absorb
, uint32
*resist
, bool canReflect
= false);
1770 void CalculateAbsorbResistBlock(Unit
*pCaster
, SpellNonMeleeDamage
*damageInfo
, SpellEntry
const* spellProto
, WeaponAttackType attType
= BASE_ATTACK
);
1772 void UpdateWalkMode(Unit
* source
, bool self
= true);
1773 void UpdateSpeed(UnitMoveType mtype
, bool forced
, float ratio
= 1.0f
);
1774 float GetSpeed( UnitMoveType mtype
) const;
1775 float GetSpeedRate( UnitMoveType mtype
) const { return m_speed_rate
[mtype
]; }
1776 void SetSpeedRate(UnitMoveType mtype
, float rate
, bool forced
= false);
1778 void SetHover(bool on
);
1779 bool isHover() const { return HasAuraType(SPELL_AURA_HOVER
); }
1781 void KnockBackFrom(Unit
* target
, float horizontalSpeed
, float verticalSpeed
);
1783 void _RemoveAllAuraMods();
1784 void _ApplyAllAuraMods();
1786 int32
CalculateSpellDamage(Unit
const* target
, SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, int32
const* basePoints
= NULL
);
1788 uint32
CalcNotIgnoreAbsorbDamage( uint32 damage
, SpellSchoolMask damageSchoolMask
, SpellEntry
const* spellInfo
= NULL
);
1789 uint32
CalcNotIgnoreDamageRedunction( uint32 damage
, SpellSchoolMask damageSchoolMask
);
1790 int32
CalculateSpellDuration(SpellEntry
const* spellProto
, SpellEffectIndex effect_index
, Unit
const* target
);
1791 float CalculateLevelPenalty(SpellEntry
const* spellProto
) const;
1793 void addFollower(FollowerReference
* pRef
) { m_FollowingRefManager
.insertFirst(pRef
); }
1794 void removeFollower(FollowerReference
* /*pRef*/ ) { /* nothing to do yet */ }
1795 static Unit
* GetUnit(WorldObject
const& object
, uint64 guid
);
1797 MotionMaster
* GetMotionMaster() { return &i_motionMaster
; }
1799 bool IsStopped() const { return !(hasUnitState(UNIT_STAT_MOVING
)); }
1802 void SetFeared(bool apply
, uint64
const& casterGUID
= 0, uint32 spellID
= 0, uint32 time
= 0);
1803 void SetConfused(bool apply
, uint64
const& casterGUID
= 0, uint32 spellID
= 0);
1804 void SetFeignDeath(bool apply
, uint64
const& casterGUID
= 0, uint32 spellID
= 0);
1806 void AddComboPointHolder(uint32 lowguid
) { m_ComboPointHolders
.insert(lowguid
); }
1807 void RemoveComboPointHolder(uint32 lowguid
) { m_ComboPointHolders
.erase(lowguid
); }
1808 void ClearComboPointHolders();
1810 ///----------Pet responses methods-----------------
1811 void SendPetCastFail(uint32 spellid
, SpellCastResult msg
);
1812 void SendPetActionFeedback (uint8 msg
);
1813 void SendPetTalk (uint32 pettalk
);
1814 void SendPetAIReaction(uint64 guid
);
1815 ///----------End of Pet responses methods----------
1817 void propagateSpeedChange() { GetMotionMaster()->propagateSpeedChange(); }
1820 void ClearAllReactives();
1821 void StartReactiveTimer( ReactiveType reactive
) { m_reactiveTimer
[reactive
] = REACTIVE_TIMER_START
;}
1822 void UpdateReactives(uint32 p_time
);
1825 void UpdateAuraForGroup(uint8 slot
);
1828 typedef std::set
<PetAura
const*> PetAuraSet
;
1829 PetAuraSet m_petAuras
;
1830 void AddPetAura(PetAura
const* petSpell
);
1831 void RemovePetAura(PetAura
const* petSpell
);
1834 MovementInfo m_movementInfo
;
1839 void _UpdateSpells(uint32 time
);
1840 void _UpdateAutoRepeatSpell();
1842 uint32 m_attackTimer
[MAX_ATTACK
];
1844 float m_createStats
[MAX_STATS
];
1846 AttackerSet m_attackers
;
1849 DeathState m_deathState
;
1852 AuraMap::iterator m_AurasUpdateIterator
; // != end() in Unit::m_Auras update and point to next element
1853 AuraList m_deletedAuras
; // auras removed while in ApplyModifier and waiting deleted
1855 AuraList m_scAuras
; // casted by unit single per-caster auras
1857 typedef std::list
<uint64
> DynObjectGUIDs
;
1858 DynObjectGUIDs m_dynObjGUIDs
;
1860 typedef std::list
<GameObject
*> GameObjectList
;
1861 GameObjectList m_gameObj
;
1865 AuraList m_modAuras
[TOTAL_AURAS
];
1866 float m_auraModifiersGroup
[UNIT_MOD_END
][MODIFIER_TYPE_END
];
1867 float m_weaponDamage
[MAX_ATTACK
][2];
1868 bool m_canModifyStats
;
1869 //std::list< spellEffectPair > AuraSpells[TOTAL_AURAS]; // TODO: use this if ok for mem
1870 VisibleAuraMap m_visibleAuras
;
1872 float m_speed_rate
[MAX_MOVE_TYPE
];
1874 CharmInfo
*m_charmInfo
;
1876 virtual SpellSchoolMask
GetMeleeDamageSchoolMask() const;
1878 MotionMaster i_motionMaster
;
1880 uint32 m_reactiveTimer
[MAX_REACTIVE
];
1881 uint32 m_regenTimer
;
1882 uint32 m_lastManaUseTimer
;
1885 void CleanupDeletedAuras();
1887 bool IsTriggeredAtSpellProcEvent(Unit
*pVictim
, Aura
* aura
, SpellEntry
const* procSpell
, uint32 procFlag
, uint32 procExtra
, WeaponAttackType attType
, bool isVictim
, bool active
, SpellProcEventEntry
const*& spellProcEvent
);
1888 bool HandleDummyAuraProc( Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
);
1889 bool HandleHasteAuraProc( Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
);
1890 bool HandleSpellCritChanceAuraProc( Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
);
1891 bool HandleProcTriggerSpell(Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 procFlag
, uint32 procEx
, uint32 cooldown
);
1892 bool HandleOverrideClassScriptAuraProc(Unit
*pVictim
, uint32 damage
, Aura
* triggredByAura
, SpellEntry
const *procSpell
, uint32 cooldown
);
1893 bool HandleMendingAuraProc(Aura
* triggeredByAura
);
1895 // player or player's pet
1896 float GetCombatRatingReduction(CombatRating cr
) const;
1897 uint32
GetCombatRatingDamageReduction(CombatRating cr
, float rate
, float cap
, uint32 damage
) const;
1899 Unit
* _GetTotem(TotemSlot slot
) const; // for templated function without include need
1901 uint32 m_state
; // Even derived shouldn't modify
1902 uint32 m_CombatTimer
;
1904 Spell
* m_currentSpells
[CURRENT_MAX_SPELL
];
1905 uint32 m_castCounter
; // count casts chain of triggered spells for prevent infinity cast crashes
1907 UnitVisibility m_Visibility
;
1909 Diminishing m_Diminishing
;
1910 // Manage all Units threatening us
1911 ThreatManager m_ThreatManager
;
1912 // Manage all Units that are threatened by us
1913 HostileRefManager m_HostileRefManager
;
1915 FollowerRefManager m_FollowingRefManager
;
1917 ComboPointHolderSet m_ComboPointHolders
;
1919 GuardianPetList m_guardianPets
;
1921 uint64 m_TotemSlot
[MAX_TOTEM_SLOT
];
1924 template<typename Func
>
1925 void Unit::CallForAllControlledUnits(Func
const& func
, bool withTotems
, bool withGuardians
, bool withCharms
)
1927 if(Pet
* pet
= GetPet())
1932 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
1933 if(Unit
* guardian
= Unit::GetUnit(*this,*itr
))
1939 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
1940 if (Unit
*totem
= _GetTotem(TotemSlot(i
)))
1945 if(Unit
* charm
= GetCharm())
1950 template<typename Func
>
1951 bool Unit::CheckAllControlledUnits(Func
const& func
, bool withTotems
, bool withGuardians
, bool withCharms
) const
1953 if (Pet
* pet
= GetPet())
1959 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
1960 if (Unit
* guardian
= Unit::GetUnit(*this,*itr
))
1968 for (int i
= 0; i
< MAX_TOTEM_SLOT
; ++i
)
1969 if (Unit
*totem
= _GetTotem(TotemSlot(i
)))
1975 if(Unit
* charm
= GetCharm())
1982 template<typename Elem
, typename Node
>
1983 inline void Unit::SendMonsterMoveByPath(Path
<Elem
,Node
> const& path
, uint32 start
, uint32 end
, SplineFlags flags
)
1985 uint32 traveltime
= uint32(path
.GetTotalLength(start
, end
) * 32);
1987 uint32 pathSize
= end
- start
;
1989 WorldPacket
data( SMSG_MONSTER_MOVE
, (GetPackGUID().size()+1+4+4+4+4+1+4+4+4+pathSize
*4*3) );
1990 data
<< GetPackGUID();
1992 data
<< GetPositionX();
1993 data
<< GetPositionY();
1994 data
<< GetPositionZ();
1995 data
<< uint32(getMSTime());
1996 data
<< uint8(SPLINETYPE_NORMAL
);
1997 data
<< uint32(flags
);
1998 data
<< uint32(traveltime
);
1999 data
<< uint32(pathSize
);
2001 for(uint32 i
= start
; i
< end
; ++i
)
2003 data
<< float(path
[i
].x
);
2004 data
<< float(path
[i
].y
);
2005 data
<< float(path
[i
].z
);
2008 SendMessageToSet(&data
, true);