root/trunk/src/game/Unit.h @ 141

Revision 141, 61.4 kB (checked in by yumileroy, 17 years ago)

[svn] Improve TargetedMovement? (TODO: let mob find "near angle" rather than "random angle").
Delete a repeated check in instance canenter().
Fix some spell targets.
Add some sunwell spell sql.
Fix Magtheridons earthquake. (TODO: need to find out why soul transfer has no effect when casted by mobs)
Let Brutallus dual wield. Enable burn (still no script effect).
Quick fix for shadowmoon valley illidan quest crash (wait for author's fix).

Original author: megamage
Date: 2008-10-31 21:42:00-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef __UNIT_H
22#define __UNIT_H
23
24#include "Common.h"
25#include "Object.h"
26#include "Opcodes.h"
27#include "Mthread.h"
28#include "SpellAuraDefines.h"
29#include "UpdateFields.h"
30#include "SharedDefines.h"
31#include "ThreatManager.h"
32#include "HostilRefManager.h"
33#include "FollowerReference.h"
34#include "FollowerRefManager.h"
35#include "Utilities/EventProcessor.h"
36#include "MotionMaster.h"
37#include "Database/DBCStructure.h"
38#include <list>
39
40enum SpellInterruptFlags
41{
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_TURNING      = 0x10              // not turning - maybe _complete_ interrupt on direct damage?
47};
48
49enum SpellChannelInterruptFlags
50{
51    CHANNEL_FLAG_DAMAGE      = 0x0002,
52    CHANNEL_FLAG_MOVEMENT    = 0x0008,
53    CHANNEL_FLAG_TURNING     = 0x0010,
54    CHANNEL_FLAG_DAMAGE2     = 0x0080,
55    CHANNEL_FLAG_DELAY       = 0x4000
56};
57
58enum SpellAuraInterruptFlags
59{
60    AURA_INTERRUPT_FLAG_UNK0                = 0x00000001,   // 0    removed when getting hit by a negative spell?
61    AURA_INTERRUPT_FLAG_DAMAGE              = 0x00000002,   // 1    removed by any damage
62    AURA_INTERRUPT_FLAG_UNK2                = 0x00000004,   // 2
63    AURA_INTERRUPT_FLAG_MOVE                = 0x00000008,   // 3    removed by any movement
64    AURA_INTERRUPT_FLAG_TURNING             = 0x00000010,   // 4    removed by any turning
65    AURA_INTERRUPT_FLAG_ENTER_COMBAT        = 0x00000020,   // 5    removed by entering combat
66    AURA_INTERRUPT_FLAG_NOT_MOUNTED         = 0x00000040,   // 6    removed by unmounting
67    AURA_INTERRUPT_FLAG_NOT_ABOVEWATER      = 0x00000080,   // 7    removed by entering water
68    AURA_INTERRUPT_FLAG_NOT_UNDERWATER      = 0x00000100,   // 8    removed by leaving water
69    AURA_INTERRUPT_FLAG_NOT_SHEATHED        = 0x00000200,   // 9    removed by unsheathing
70    AURA_INTERRUPT_FLAG_UNK10               = 0x00000400,   // 10
71    AURA_INTERRUPT_FLAG_UNK11               = 0x00000800,   // 11
72    AURA_INTERRUPT_FLAG_UNK12               = 0x00001000,   // 12   removed by attack?
73    AURA_INTERRUPT_FLAG_UNK13               = 0x00002000,   // 13
74    AURA_INTERRUPT_FLAG_UNK14               = 0x00004000,   // 14
75    AURA_INTERRUPT_FLAG_UNK15               = 0x00008000,   // 15   removed by casting a spell?
76    AURA_INTERRUPT_FLAG_UNK16               = 0x00010000,   // 16
77    AURA_INTERRUPT_FLAG_MOUNTING            = 0x00020000,   // 17   removed by mounting
78    AURA_INTERRUPT_FLAG_NOT_SEATED          = 0x00040000,   // 18   removed by standing up
79    AURA_INTERRUPT_FLAG_CHANGE_MAP          = 0x00080000,   // 19   leaving map/getting teleported
80    AURA_INTERRUPT_FLAG_UNK20               = 0x00100000,   // 20
81    AURA_INTERRUPT_FLAG_UNK21               = 0x00200000,   // 21
82    AURA_INTERRUPT_FLAG_UNK22               = 0x00400000,   // 22
83    AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT    = 0x00800000,   // 23   removed by entering pvp combat
84    AURA_INTERRUPT_FLAG_DIRECT_DAMAGE       = 0x01000000    // 24   removed by any direct damage
85};
86
87enum SpellModOp
88{
89    SPELLMOD_DAMAGE                 = 0,
90    SPELLMOD_DURATION               = 1,
91    SPELLMOD_THREAT                 = 2,
92    SPELLMOD_EFFECT1                = 3,
93    SPELLMOD_CHARGES                = 4,
94    SPELLMOD_RANGE                  = 5,
95    SPELLMOD_RADIUS                 = 6,
96    SPELLMOD_CRITICAL_CHANCE        = 7,
97    SPELLMOD_ALL_EFFECTS            = 8,
98    SPELLMOD_NOT_LOSE_CASTING_TIME  = 9,
99    SPELLMOD_CASTING_TIME           = 10,
100    SPELLMOD_COOLDOWN               = 11,
101    SPELLMOD_EFFECT2                = 12,
102    // spellmod 13 unused
103    SPELLMOD_COST                   = 14,
104    SPELLMOD_CRIT_DAMAGE_BONUS      = 15,
105    SPELLMOD_RESIST_MISS_CHANCE     = 16,
106    SPELLMOD_JUMP_TARGETS           = 17,
107    SPELLMOD_CHANCE_OF_SUCCESS      = 18,
108    SPELLMOD_ACTIVATION_TIME        = 19,
109    SPELLMOD_EFFECT_PAST_FIRST      = 20,
110    SPELLMOD_CASTING_TIME_OLD       = 21,
111    SPELLMOD_DOT                    = 22,
112    SPELLMOD_EFFECT3                = 23,
113    SPELLMOD_SPELL_BONUS_DAMAGE     = 24,
114    // spellmod 25, 26 unused
115    SPELLMOD_MULTIPLE_VALUE         = 27,
116    SPELLMOD_RESIST_DISPEL_CHANCE   = 28
117};
118
119#define MAX_SPELLMOD 32
120
121enum SpellFacingFlags
122{
123    SPELL_FACING_FLAG_INFRONT = 0x0001
124};
125
126#define BASE_MINDAMAGE 1.0f
127#define BASE_MAXDAMAGE 2.0f
128#define BASE_ATTACK_TIME 2000
129
130// high byte (3 from 0..3) of UNIT_FIELD_BYTES_2
131enum ShapeshiftForm
132{
133    FORM_NONE               = 0x00,
134    FORM_CAT                = 0x01,
135    FORM_TREE               = 0x02,
136    FORM_TRAVEL             = 0x03,
137    FORM_AQUA               = 0x04,
138    FORM_BEAR               = 0x05,
139    FORM_AMBIENT            = 0x06,
140    FORM_GHOUL              = 0x07,
141    FORM_DIREBEAR           = 0x08,
142    FORM_CREATUREBEAR       = 0x0E,
143    FORM_CREATURECAT        = 0x0F,
144    FORM_GHOSTWOLF          = 0x10,
145    FORM_BATTLESTANCE       = 0x11,
146    FORM_DEFENSIVESTANCE    = 0x12,
147    FORM_BERSERKERSTANCE    = 0x13,
148    FORM_TEST               = 0x14,
149    FORM_ZOMBIE             = 0x15,
150    FORM_FLIGHT_EPIC        = 0x1B,
151    FORM_SHADOW             = 0x1C,
152    FORM_FLIGHT             = 0x1D,
153    FORM_STEALTH            = 0x1E,
154    FORM_MOONKIN            = 0x1F,
155    FORM_SPIRITOFREDEMPTION = 0x20
156};
157
158// low byte ( 0 from 0..3 ) of UNIT_FIELD_BYTES_2
159enum SheathState
160{
161    SHEATH_STATE_UNARMED  = 0,                              // non prepared weapon
162    SHEATH_STATE_MELEE    = 1,                              // prepared melee weapon
163    SHEATH_STATE_RANGED   = 2                               // prepared ranged weapon
164};
165
166// byte (1 from 0..3) of UNIT_FIELD_BYTES_2
167enum UnitBytes2_Flags
168{
169    UNIT_BYTE2_FLAG_UNK0  = 0x01,
170    UNIT_BYTE2_FLAG_UNK1  = 0x02,
171    UNIT_BYTE2_FLAG_UNK2  = 0x04,
172    UNIT_BYTE2_FLAG_UNK3  = 0x08,
173    UNIT_BYTE2_FLAG_AURAS = 0x10,                           // show possitive auras as positive, and allow its dispel
174    UNIT_BYTE2_FLAG_UNK5  = 0x20,
175    UNIT_BYTE2_FLAG_UNK6  = 0x40,
176    UNIT_BYTE2_FLAG_UNK7  = 0x80
177};
178
179// byte (2 from 0..3) of UNIT_FIELD_BYTES_2
180enum UnitRename
181{
182    UNIT_RENAME_NOT_ALLOWED = 0x02,
183    UNIT_RENAME_ALLOWED     = 0x03
184};
185
186#define CREATURE_MAX_SPELLS     4
187
188enum Swing
189{
190    NOSWING                    = 0,
191    SINGLEHANDEDSWING          = 1,
192    TWOHANDEDSWING             = 2
193};
194
195enum VictimState
196{
197    VICTIMSTATE_UNKNOWN1       = 0,
198    VICTIMSTATE_NORMAL         = 1,
199    VICTIMSTATE_DODGE          = 2,
200    VICTIMSTATE_PARRY          = 3,
201    VICTIMSTATE_INTERRUPT      = 4,
202    VICTIMSTATE_BLOCKS         = 5,
203    VICTIMSTATE_EVADES         = 6,
204    VICTIMSTATE_IS_IMMUNE      = 7,
205    VICTIMSTATE_DEFLECTS       = 8
206};
207
208enum HitInfo
209{
210    HITINFO_NORMALSWING         = 0x00000000,
211    HITINFO_UNK1                = 0x00000001,               // req correct packet structure
212    HITINFO_NORMALSWING2        = 0x00000002,
213    HITINFO_LEFTSWING           = 0x00000004,
214    HITINFO_MISS                = 0x00000010,
215    HITINFO_ABSORB              = 0x00000020,               // plays absorb sound
216    HITINFO_RESIST              = 0x00000040,               // resisted atleast some damage
217    HITINFO_CRITICALHIT         = 0x00000080,
218    HITINFO_GLANCING            = 0x00004000,
219    HITINFO_CRUSHING            = 0x00008000,
220    HITINFO_NOACTION            = 0x00010000,
221    HITINFO_SWINGNOHITSOUND     = 0x00080000
222};
223
224//i would like to remove this: (it is defined in item.h
225enum InventorySlot
226{
227    NULL_BAG                   = 0,
228    NULL_SLOT                  = 255
229};
230
231struct FactionTemplateEntry;
232struct Modifier;
233struct SpellEntry;
234struct SpellEntryExt;
235
236class Aura;
237class Creature;
238class Spell;
239class DynamicObject;
240class GameObject;
241class Item;
242class Pet;
243class Path;
244class PetAura;
245
246struct SpellImmune
247{
248    uint32 type;
249    uint32 spellId;
250};
251
252typedef std::list<SpellImmune> SpellImmuneList;
253
254enum UnitModifierType
255{
256    BASE_VALUE = 0,
257    BASE_PCT = 1,
258    TOTAL_VALUE = 2,
259    TOTAL_PCT = 3,
260    MODIFIER_TYPE_END = 4
261};
262
263enum WeaponDamageRange
264{
265    MINDAMAGE,
266    MAXDAMAGE
267};
268
269enum DamageTypeToSchool
270{
271    RESISTANCE,
272    DAMAGE_DEALT,
273    DAMAGE_TAKEN
274};
275
276enum AuraRemoveMode
277{
278    AURA_REMOVE_BY_DEFAULT,
279    AURA_REMOVE_BY_STACK,                                   // at replace by semillar aura
280    AURA_REMOVE_BY_CANCEL,
281    AURA_REMOVE_BY_DISPEL,
282    AURA_REMOVE_BY_DEATH
283};
284
285enum UnitMods
286{
287    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.
288    UNIT_MOD_STAT_AGILITY,
289    UNIT_MOD_STAT_STAMINA,
290    UNIT_MOD_STAT_INTELLECT,
291    UNIT_MOD_STAT_SPIRIT,
292    UNIT_MOD_HEALTH,
293    UNIT_MOD_MANA,                                          // UNIT_MOD_MANA..UNIT_MOD_HAPPINESS must be in existed order, it's accessed by index values of Powers enum.
294    UNIT_MOD_RAGE,
295    UNIT_MOD_FOCUS,
296    UNIT_MOD_ENERGY,
297    UNIT_MOD_HAPPINESS,
298    UNIT_MOD_ARMOR,                                         // UNIT_MOD_ARMOR..UNIT_MOD_RESISTANCE_ARCANE must be in existed order, it's accessed by index values of SpellSchools enum.
299    UNIT_MOD_RESISTANCE_HOLY,
300    UNIT_MOD_RESISTANCE_FIRE,
301    UNIT_MOD_RESISTANCE_NATURE,
302    UNIT_MOD_RESISTANCE_FROST,
303    UNIT_MOD_RESISTANCE_SHADOW,
304    UNIT_MOD_RESISTANCE_ARCANE,
305    UNIT_MOD_ATTACK_POWER,
306    UNIT_MOD_ATTACK_POWER_RANGED,
307    UNIT_MOD_DAMAGE_MAINHAND,
308    UNIT_MOD_DAMAGE_OFFHAND,
309    UNIT_MOD_DAMAGE_RANGED,
310    UNIT_MOD_END,
311    // synonyms
312    UNIT_MOD_STAT_START = UNIT_MOD_STAT_STRENGTH,
313    UNIT_MOD_STAT_END = UNIT_MOD_STAT_SPIRIT + 1,
314    UNIT_MOD_RESISTANCE_START = UNIT_MOD_ARMOR,
315    UNIT_MOD_RESISTANCE_END = UNIT_MOD_RESISTANCE_ARCANE + 1,
316    UNIT_MOD_POWER_START = UNIT_MOD_MANA,
317    UNIT_MOD_POWER_END = UNIT_MOD_HAPPINESS + 1
318};
319
320enum BaseModGroup
321{
322    CRIT_PERCENTAGE,
323    RANGED_CRIT_PERCENTAGE,
324    OFFHAND_CRIT_PERCENTAGE,
325    SHIELD_BLOCK_VALUE,
326    BASEMOD_END
327};
328
329enum BaseModType
330{
331    FLAT_MOD,
332    PCT_MOD
333};
334
335#define MOD_END (PCT_MOD+1)
336
337enum DeathState
338{
339    ALIVE       = 0,
340    JUST_DIED   = 1,
341    CORPSE      = 2,
342    DEAD        = 3,
343    JUST_ALIVED = 4
344};
345
346enum UnitState
347{
348    UNIT_STAT_DIED            = 0x0001,
349    UNIT_STAT_MELEE_ATTACKING = 0x0002,                     // player is melee attacking someone
350    //UNIT_STAT_MELEE_ATTACK_BY = 0x0004,                     // player is melee attack by someone
351    UNIT_STAT_STUNNED         = 0x0008,
352    UNIT_STAT_ROAMING         = 0x0010,
353    UNIT_STAT_CHASE           = 0x0020,
354    UNIT_STAT_SEARCHING       = 0x0040,
355    UNIT_STAT_FLEEING         = 0x0080,
356    UNIT_STAT_MOVING          = (UNIT_STAT_ROAMING | UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING),
357    UNIT_STAT_IN_FLIGHT       = 0x0100,                     // player is in flight mode
358    UNIT_STAT_FOLLOW          = 0x0200,
359    UNIT_STAT_ROOT            = 0x0400,
360    UNIT_STAT_CONFUSED        = 0x0800,
361    UNIT_STAT_DISTRACTED      = 0x1000,
362    UNIT_STAT_ISOLATED        = 0x2000,                     // area auras do not affect other players
363    UNIT_STAT_ATTACK_PLAYER   = 0x4000,
364    UNIT_STAT_ALL_STATE       = 0xffff                      //(UNIT_STAT_STOPPED | UNIT_STAT_MOVING | UNIT_STAT_IN_COMBAT | UNIT_STAT_IN_FLIGHT)
365};
366
367enum UnitMoveType
368{
369    MOVE_WALK       = 0,
370    MOVE_RUN        = 1,
371    MOVE_WALKBACK   = 2,
372    MOVE_SWIM       = 3,
373    MOVE_SWIMBACK   = 4,
374    MOVE_TURN       = 5,
375    MOVE_FLY        = 6,
376    MOVE_FLYBACK    = 7
377};
378
379#define MAX_MOVE_TYPE 8
380
381extern float baseMoveSpeed[MAX_MOVE_TYPE];
382
383enum WeaponAttackType
384{
385    BASE_ATTACK   = 0,
386    OFF_ATTACK    = 1,
387    RANGED_ATTACK = 2
388};
389
390#define MAX_ATTACK  3
391
392enum CombatRating
393{
394    CR_WEAPON_SKILL             = 0,
395    CR_DEFENSE_SKILL            = 1,
396    CR_DODGE                    = 2,
397    CR_PARRY                    = 3,
398    CR_BLOCK                    = 4,
399    CR_HIT_MELEE                = 5,
400    CR_HIT_RANGED               = 6,
401    CR_HIT_SPELL                = 7,
402    CR_CRIT_MELEE               = 8,
403    CR_CRIT_RANGED              = 9,
404    CR_CRIT_SPELL               = 10,
405    CR_HIT_TAKEN_MELEE          = 11,
406    CR_HIT_TAKEN_RANGED         = 12,
407    CR_HIT_TAKEN_SPELL          = 13,
408    CR_CRIT_TAKEN_MELEE         = 14,
409    CR_CRIT_TAKEN_RANGED        = 15,
410    CR_CRIT_TAKEN_SPELL         = 16,
411    CR_HASTE_MELEE              = 17,
412    CR_HASTE_RANGED             = 18,
413    CR_HASTE_SPELL              = 19,
414    CR_WEAPON_SKILL_MAINHAND    = 20,
415    CR_WEAPON_SKILL_OFFHAND     = 21,
416    CR_WEAPON_SKILL_RANGED      = 22,
417    CR_EXPERTISE                = 23
418};
419
420#define MAX_COMBAT_RATING         24
421
422enum DamageEffectType
423{
424    DIRECT_DAMAGE           = 0,                            // used for normal weapon damage (not for class abilities or spells)
425    SPELL_DIRECT_DAMAGE     = 1,                            // spell/class abilities damage
426    DOT                     = 2,
427    HEAL                    = 3,
428    NODAMAGE                = 4,                            // used also in case when damage applied to health but not applied to spell channelInterruptFlags/etc
429    SELF_DAMAGE             = 5
430};
431
432enum UnitVisibility
433{
434    VISIBILITY_OFF                = 0,                      // absolute, not detectable, GM-like, can see all other
435    VISIBILITY_ON                 = 1,
436    VISIBILITY_GROUP_STEALTH      = 2,                      // detect chance, seen and can see group members
437    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)
438    VISIBILITY_GROUP_NO_DETECT    = 4,                      // state just at stealth apply for update Grid state. Don't remove, otherwise stealth spells will break
439    VISIBILITY_RESPAWN            = 5                       // special totally not detectable visibility for force delete object at respawn command
440};
441
442// Value masks for UNIT_FIELD_FLAGS
443enum UnitFlags
444{
445    UNIT_FLAG_UNKNOWN7         = 0x00000001,
446    UNIT_FLAG_NON_ATTACKABLE   = 0x00000002,                // not attackable
447    UNIT_FLAG_DISABLE_MOVE     = 0x00000004,
448    UNIT_FLAG_PVP_ATTACKABLE   = 0x00000008,                // allow apply pvp rules to attackable state in addition to faction dependent state
449    UNIT_FLAG_RENAME           = 0x00000010,
450    UNIT_FLAG_PREPARATION      = 0x00000020,                // don't take reagents for spells with SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
451    UNIT_FLAG_UNKNOWN9         = 0x00000040,
452    UNIT_FLAG_NOT_ATTACKABLE_1 = 0x00000080,                // ?? (UNIT_FLAG_PVP_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1) is NON_PVP_ATTACKABLE
453    UNIT_FLAG_UNKNOWN2         = 0x00000100,                // 2.0.8
454    UNIT_FLAG_UNKNOWN11        = 0x00000200,
455    UNIT_FLAG_LOOTING          = 0x00000400,                // loot animation
456    UNIT_FLAG_PET_IN_COMBAT    = 0x00000800,                // in combat?, 2.0.8
457    UNIT_FLAG_PVP              = 0x00001000,
458    UNIT_FLAG_SILENCED         = 0x00002000,                // silenced, 2.1.1
459    UNIT_FLAG_UNKNOWN4         = 0x00004000,                // 2.0.8
460    UNIT_FLAG_UNKNOWN13        = 0x00008000,
461    UNIT_FLAG_UNKNOWN14        = 0x00010000,
462    UNIT_FLAG_PACIFIED         = 0x00020000,
463    UNIT_FLAG_DISABLE_ROTATE   = 0x00040000,                // stunned, 2.1.1
464    UNIT_FLAG_IN_COMBAT        = 0x00080000,
465    UNIT_FLAG_TAXI_FLIGHT      = 0x00100000,                // disable casting at client side spell not allowed by taxi flight (mounted?), probably used with 0x4 flag
466    UNIT_FLAG_DISARMED         = 0x00200000,                // disable melee spells casting..., "Required melee weapon" added to melee spells tooltip.
467    UNIT_FLAG_CONFUSED         = 0x00400000,
468    UNIT_FLAG_FLEEING          = 0x00800000,
469    UNIT_FLAG_UNKNOWN5         = 0x01000000,                // used in spell Eyes of the Beast for pet...
470    UNIT_FLAG_NOT_SELECTABLE   = 0x02000000,
471    UNIT_FLAG_SKINNABLE        = 0x04000000,
472    UNIT_FLAG_MOUNT            = 0x08000000,
473    UNIT_FLAG_UNKNOWN17        = 0x10000000,
474    UNIT_FLAG_UNKNOWN6         = 0x20000000,                // used in Feing Death spell
475    UNIT_FLAG_SHEATHE          = 0x40000000
476};
477
478// Value masks for UNIT_FIELD_FLAGS_2
479enum UnitFlags2
480{
481    UNIT_FLAG2_FEIGN_DEATH    = 0x00000001,
482    UNIT_FLAG2_COMPREHEND_LANG= 0x00000008,
483    UNIT_FLAG2_FORCE_MOVE     = 0x00000040
484};
485
486/// Non Player Character flags
487enum NPCFlags
488{
489    UNIT_NPC_FLAG_NONE                  = 0x00000000,
490    UNIT_NPC_FLAG_GOSSIP                = 0x00000001,       // 100%
491    UNIT_NPC_FLAG_QUESTGIVER            = 0x00000002,       // guessed, probably ok
492    UNIT_NPC_FLAG_UNK1                  = 0x00000004,
493    UNIT_NPC_FLAG_UNK2                  = 0x00000008,
494    UNIT_NPC_FLAG_TRAINER               = 0x00000010,       // 100%
495    UNIT_NPC_FLAG_TRAINER_CLASS         = 0x00000020,       // 100%
496    UNIT_NPC_FLAG_TRAINER_PROFESSION    = 0x00000040,       // 100%
497    UNIT_NPC_FLAG_VENDOR                = 0x00000080,       // 100%
498    UNIT_NPC_FLAG_VENDOR_AMMO           = 0x00000100,       // 100%, general goods vendor
499    UNIT_NPC_FLAG_VENDOR_FOOD           = 0x00000200,       // 100%
500    UNIT_NPC_FLAG_VENDOR_POISON         = 0x00000400,       // guessed
501    UNIT_NPC_FLAG_VENDOR_REAGENT        = 0x00000800,       // 100%
502    UNIT_NPC_FLAG_REPAIR                = 0x00001000,       // 100%
503    UNIT_NPC_FLAG_FLIGHTMASTER          = 0x00002000,       // 100%
504    UNIT_NPC_FLAG_SPIRITHEALER          = 0x00004000,       // guessed
505    UNIT_NPC_FLAG_SPIRITGUIDE           = 0x00008000,       // guessed
506    UNIT_NPC_FLAG_INNKEEPER             = 0x00010000,       // 100%
507    UNIT_NPC_FLAG_BANKER                = 0x00020000,       // 100%
508    UNIT_NPC_FLAG_PETITIONER            = 0x00040000,       // 100% 0xC0000 = guild petitions, 0x40000 = arena team petitions
509    UNIT_NPC_FLAG_TABARDDESIGNER        = 0x00080000,       // 100%
510    UNIT_NPC_FLAG_BATTLEMASTER          = 0x00100000,       // 100%
511    UNIT_NPC_FLAG_AUCTIONEER            = 0x00200000,       // 100%
512    UNIT_NPC_FLAG_STABLEMASTER          = 0x00400000,       // 100%
513    UNIT_NPC_FLAG_GUILD_BANKER          = 0x00800000,       // cause client to send 997 opcode
514    UNIT_NPC_FLAG_UNK3                  = 0x01000000,       // cause client to send 1015 opcode
515    UNIT_NPC_FLAG_GUARD                 = 0x10000000,       // custom flag for guards
516    UNIT_NPC_FLAG_OUTDOORPVP            = 0x20000000,       // custom flag for outdoor pvp creatures
517};
518
519enum MovementFlags
520{
521    MOVEMENTFLAG_NONE           = 0x00000000,
522    MOVEMENTFLAG_FORWARD        = 0x00000001,
523    MOVEMENTFLAG_BACKWARD       = 0x00000002,
524    MOVEMENTFLAG_STRAFE_LEFT    = 0x00000004,
525    MOVEMENTFLAG_STRAFE_RIGHT   = 0x00000008,
526    MOVEMENTFLAG_LEFT           = 0x00000010,
527    MOVEMENTFLAG_RIGHT          = 0x00000020,
528    MOVEMENTFLAG_PITCH_UP       = 0x00000040,
529    MOVEMENTFLAG_PITCH_DOWN     = 0x00000080,
530    MOVEMENTFLAG_WALK_MODE      = 0x00000100,               // Walking
531    MOVEMENTFLAG_ONTRANSPORT    = 0x00000200,               // Used for flying on some creatures
532    MOVEMENTFLAG_LEVITATING     = 0x00000400,
533    MOVEMENTFLAG_FLY_UNK1       = 0x00000800,
534    MOVEMENTFLAG_JUMPING        = 0x00001000,
535    MOVEMENTFLAG_UNK4           = 0x00002000,
536    MOVEMENTFLAG_FALLING        = 0x00004000,
537    // 0x8000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000
538    MOVEMENTFLAG_SWIMMING       = 0x00200000,               // appears with fly flag also
539    MOVEMENTFLAG_FLY_UP         = 0x00400000,
540    MOVEMENTFLAG_CAN_FLY        = 0x00800000,
541    MOVEMENTFLAG_FLYING         = 0x01000000,
542    MOVEMENTFLAG_FLYING2        = 0x02000000,               // Actual flying mode
543    MOVEMENTFLAG_SPLINE         = 0x04000000,               // used for flight paths
544    MOVEMENTFLAG_SPLINE2        = 0x08000000,               // used for flight paths
545    MOVEMENTFLAG_WATERWALKING   = 0x10000000,               // prevent unit from falling through water
546    MOVEMENTFLAG_SAFE_FALL      = 0x20000000,               // active rogue safe fall spell (passive)
547    MOVEMENTFLAG_UNK3           = 0x40000000
548};
549
550enum DiminishingLevels
551{
552    DIMINISHING_LEVEL_1             = 0,
553    DIMINISHING_LEVEL_2             = 1,
554    DIMINISHING_LEVEL_3             = 2,
555    DIMINISHING_LEVEL_IMMUNE        = 3
556};
557
558struct DiminishingReturn
559{
560    DiminishingReturn(DiminishingGroup group, uint32 t, uint32 count) : DRGroup(group), hitTime(t), hitCount(count), stack(0) {}
561
562    DiminishingGroup        DRGroup:16;
563    uint16                  stack:16;
564    uint32                  hitTime;
565    uint32                  hitCount;
566};
567
568enum MeleeHitOutcome
569{
570    MELEE_HIT_EVADE, MELEE_HIT_MISS, MELEE_HIT_DODGE, MELEE_HIT_BLOCK, MELEE_HIT_PARRY,
571    MELEE_HIT_GLANCING, MELEE_HIT_CRIT, MELEE_HIT_CRUSHING, MELEE_HIT_NORMAL, MELEE_HIT_BLOCK_CRIT
572};
573struct CleanDamage
574{
575    CleanDamage(uint32 _damage, WeaponAttackType _attackType, MeleeHitOutcome _hitOutCome) :
576    damage(_damage), attackType(_attackType), hitOutCome(_hitOutCome) {}
577
578    uint32 damage;
579    WeaponAttackType attackType;
580    MeleeHitOutcome hitOutCome;
581};
582
583struct UnitActionBarEntry
584{
585    uint32 Type;
586    uint32 SpellOrAction;
587};
588
589#define MAX_DECLINED_NAME_CASES 5
590
591struct DeclinedName
592{
593    std::string name[MAX_DECLINED_NAME_CASES];
594};
595
596enum CurrentSpellTypes
597{
598    CURRENT_MELEE_SPELL = 0,
599    CURRENT_FIRST_NON_MELEE_SPELL = 1,                      // just counter
600    CURRENT_GENERIC_SPELL = 1,
601    CURRENT_AUTOREPEAT_SPELL = 2,
602    CURRENT_CHANNELED_SPELL = 3,
603    CURRENT_MAX_SPELL = 4                                   // just counter
604};
605
606enum ActiveStates
607{
608    ACT_ENABLED  = 0xC100,
609    ACT_DISABLED = 0x8100,
610    ACT_COMMAND  = 0x0700,
611    ACT_REACTION = 0x0600,
612    ACT_CAST     = 0x0100,
613    ACT_PASSIVE  = 0x0000,
614    ACT_DECIDE   = 0x0001
615};
616
617enum ReactStates
618{
619    REACT_PASSIVE    = 0,
620    REACT_DEFENSIVE  = 1,
621    REACT_AGGRESSIVE = 2
622};
623
624enum CommandStates
625{
626    COMMAND_STAY    = 0,
627    COMMAND_FOLLOW  = 1,
628    COMMAND_ATTACK  = 2,
629    COMMAND_ABANDON = 3
630};
631
632struct CharmSpellEntry
633{
634    uint16 spellId;
635    uint16 active;
636};
637
638struct CharmInfo
639{
640    public:
641        explicit CharmInfo(Unit* unit);
642        uint32 GetPetNumber() const { return m_petnumber; }
643        void SetPetNumber(uint32 petnumber, bool statwindow);
644
645        void SetCommandState(CommandStates st) { m_CommandState = st; }
646        CommandStates GetCommandState() { return m_CommandState; }
647        bool HasCommandState(CommandStates state) { return (m_CommandState == state); }
648        void SetReactState(ReactStates st) { m_ReactSate = st; }
649        ReactStates GetReactState() { return m_ReactSate; }
650        bool HasReactState(ReactStates state) { return (m_ReactSate == state); }
651
652        void InitPossessCreateSpells();
653        void InitCharmCreateSpells();
654        void InitPetActionBar();
655        void InitEmptyActionBar();
656                                                            //return true if successful
657        bool AddSpellToAB(uint32 oldid, uint32 newid, ActiveStates newstate = ACT_DECIDE);
658        void ToggleCreatureAutocast(uint32 spellid, bool apply);
659
660        UnitActionBarEntry* GetActionBarEntry(uint8 index) { return &(PetActionBar[index]); }
661        CharmSpellEntry* GetCharmSpell(uint8 index) { return &(m_charmspells[index]); }
662    private:
663        Unit* m_unit;
664        UnitActionBarEntry PetActionBar[10];
665        CharmSpellEntry m_charmspells[4];
666        CommandStates   m_CommandState;
667        ReactStates     m_ReactSate;
668        uint32          m_petnumber;
669};
670
671// for clearing special attacks
672#define REACTIVE_TIMER_START 4000
673
674enum ReactiveType
675{
676    REACTIVE_DEFENSE      = 1,
677    REACTIVE_HUNTER_PARRY = 2,
678    REACTIVE_CRIT         = 3,
679    REACTIVE_HUNTER_CRIT  = 4,
680    REACTIVE_OVERPOWER    = 5
681};
682
683#define MAX_REACTIVE 6
684#define MAX_TOTEM 4
685
686// delay time next attack to prevent client attack animation problems
687#define ATTACK_DISPLAY_DELAY 200
688
689class TRINITY_DLL_SPEC Unit : public WorldObject
690{
691    public:
692        typedef std::set<Unit*> AttackerSet;
693        typedef std::pair<uint32, uint8> spellEffectPair;
694        typedef std::multimap< spellEffectPair, Aura*> AuraMap;
695        typedef std::list<Aura *> AuraList;
696        typedef std::list<DiminishingReturn> Diminishing;
697        typedef std::set<AuraType> AuraTypeSet;
698        typedef std::set<uint32> ComboPointHolderSet;
699
700        virtual ~Unit ( );
701
702        void AddToWorld();
703        void RemoveFromWorld();
704
705        void CleanupsBeforeDelete();                        // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units)
706
707        DiminishingLevels GetDiminishing(DiminishingGroup  group);
708        void IncrDiminishing(DiminishingGroup group);
709        void ApplyDiminishingToDuration(DiminishingGroup  group, int32 &duration,Unit* caster, DiminishingLevels Level);
710        void ApplyDiminishingAura(DiminishingGroup  group, bool apply);
711        void ClearDiminishings() { m_Diminishing.clear(); }
712
713        virtual void Update( uint32 time );
714
715        void setAttackTimer(WeaponAttackType type, uint32 time) { m_attackTimer[type] = time; }
716        void resetAttackTimer(WeaponAttackType type = BASE_ATTACK);
717        uint32 getAttackTimer(WeaponAttackType type) const { return m_attackTimer[type]; }
718        bool isAttackReady(WeaponAttackType type = BASE_ATTACK) const { return m_attackTimer[type] == 0; }
719        bool haveOffhandWeapon() const;
720        bool CanDualWield() const { return m_canDualWield; }
721        void SetCanDualWield(bool value) { m_canDualWield = value; }
722        bool canReachWithAttack(Unit *pVictim) const;
723        bool IsWithinCombatDist(Unit *obj, float dist2compare) const;
724        void GetRandomContactPoint( const Unit* target, float &x, float &y, float &z, float distance2dMin, float distance2dMax ) const;
725        uint32 m_extraAttacks;
726        bool m_canDualWield;
727
728        void _addAttacker(Unit *pAttacker)                  // must be called only from Unit::Attack(Unit*)
729        {
730            AttackerSet::iterator itr = m_attackers.find(pAttacker);
731            if(itr == m_attackers.end())
732                m_attackers.insert(pAttacker);
733        }
734        void _removeAttacker(Unit *pAttacker)               // must be called only from Unit::AttackStop()
735        {
736            AttackerSet::iterator itr = m_attackers.find(pAttacker);
737            if(itr != m_attackers.end())
738                m_attackers.erase(itr);
739        }
740        Unit * getAttackerForHelper()                       // If someone wants to help, who to give them
741        {
742            if (getVictim() != NULL)
743                return getVictim();
744
745            if (!m_attackers.empty())
746                return *(m_attackers.begin());
747
748            return NULL;
749        }
750        bool Attack(Unit *victim, bool meleeAttack);
751        void CastStop(uint32 except_spellid = 0);
752        bool AttackStop();
753        void RemoveAllAttackers();
754        AttackerSet const& getAttackers() const { return m_attackers; }
755        bool isAttackingPlayer() const;
756        Unit* getVictim() const { return m_attacking; }
757        void CombatStop(bool cast = false);
758        void CombatStopWithPets(bool cast = false);
759        Unit* SelectNearbyTarget() const;
760
761        void addUnitState(uint32 f) { m_state |= f; }
762        bool hasUnitState(const uint32 f) const { return (m_state & f); }
763        void clearUnitState(uint32 f) { m_state &= ~f; }
764        bool CanFreeMove() const
765        {
766            return !hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_FLEEING | UNIT_STAT_IN_FLIGHT |
767                UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DISTRACTED ) && GetOwnerGUID()==0;
768        }
769
770        uint32 getLevel() const { return GetUInt32Value(UNIT_FIELD_LEVEL); }
771        virtual uint32 getLevelForTarget(Unit const* /*target*/) const { return getLevel(); }
772        void SetLevel(uint32 lvl);
773        uint8 getRace() const { return GetByteValue(UNIT_FIELD_BYTES_0, 0); }
774        uint32 getRaceMask() const { return 1 << (getRace()-1); }
775        uint8 getClass() const { return GetByteValue(UNIT_FIELD_BYTES_0, 1); }
776        uint32 getClassMask() const { return 1 << (getClass()-1); }
777        uint8 getGender() const { return GetByteValue(UNIT_FIELD_BYTES_0, 2); }
778
779        float GetStat(Stats stat) const { return float(GetUInt32Value(UNIT_FIELD_STAT0+stat)); }
780        void SetStat(Stats stat, int32 val) { SetStatInt32Value(UNIT_FIELD_STAT0+stat, val); }
781        uint32 GetArmor() const { return GetResistance(SPELL_SCHOOL_NORMAL) ; }
782        void SetArmor(int32 val) { SetResistance(SPELL_SCHOOL_NORMAL, val); }
783
784        uint32 GetResistance(SpellSchools school) const { return GetUInt32Value(UNIT_FIELD_RESISTANCES+school); }
785        void SetResistance(SpellSchools school, int32 val) { SetStatInt32Value(UNIT_FIELD_RESISTANCES+school,val); }
786
787        uint32 GetHealth()    const { return GetUInt32Value(UNIT_FIELD_HEALTH); }
788        uint32 GetMaxHealth() const { return GetUInt32Value(UNIT_FIELD_MAXHEALTH); }
789        void SetHealth(   uint32 val);
790        void SetMaxHealth(uint32 val);
791        int32 ModifyHealth(int32 val);
792
793        Powers getPowerType() const { return Powers(GetByteValue(UNIT_FIELD_BYTES_0, 3)); }
794        void setPowerType(Powers power);
795        uint32 GetPower(   Powers power) const { return GetUInt32Value(UNIT_FIELD_POWER1   +power); }
796        uint32 GetMaxPower(Powers power) const { return GetUInt32Value(UNIT_FIELD_MAXPOWER1+power); }
797        void SetPower(   Powers power, uint32 val);
798        void SetMaxPower(Powers power, uint32 val);
799        int32 ModifyPower(Powers power, int32 val);
800        void ApplyPowerMod(Powers power, uint32 val, bool apply);
801        void ApplyMaxPowerMod(Powers power, uint32 val, bool apply);
802
803        uint32 GetAttackTime(WeaponAttackType att) const { return (uint32)(GetFloatValue(UNIT_FIELD_BASEATTACKTIME+att)/m_modAttackSpeedPct[att]); }
804        void SetAttackTime(WeaponAttackType att, uint32 val) { SetFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val*m_modAttackSpeedPct[att]); }
805        void ApplyAttackTimePercentMod(WeaponAttackType att,float val, bool apply);
806        void ApplyCastTimePercentMod(float val, bool apply);
807
808        // faction template id
809        uint32 getFaction() const { return GetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE); }
810        void setFaction(uint32 faction) { SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, faction ); }
811        FactionTemplateEntry const* getFactionTemplateEntry() const;
812        bool IsHostileTo(Unit const* unit) const;
813        bool IsHostileToPlayers() const;
814        bool IsFriendlyTo(Unit const* unit) const;
815        bool IsNeutralToAll() const;
816        bool IsContestedGuard() const
817        {
818            if(FactionTemplateEntry const* entry = getFactionTemplateEntry())
819                return entry->IsContestedGuardFaction();
820
821            return false;
822        }
823        bool IsPvP() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP); }
824        void SetPvP(bool state) { if(state) SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP); else RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP); }
825        uint32 GetCreatureType() const;
826        uint32 GetCreatureTypeMask() const
827        {
828            uint32 creatureType = GetCreatureType();
829            return (creatureType >= 1) ? (1 << (creatureType - 1)) : 0;
830        }
831
832        uint8 getStandState() const { return GetByteValue(UNIT_FIELD_BYTES_1, 0); }
833        bool IsSitState() const;
834        bool IsStandState() const;
835        void SetStandState(uint8 state);
836
837        bool IsMounted() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); }
838        uint32 GetMountID() const { return GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID); }
839        void Mount(uint32 mount);
840        void Unmount();
841
842        uint16 GetMaxSkillValueForLevel(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
843        uint32 DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss);
844        void DealFlatDamage(Unit *pVictim, SpellEntry const *spellInfo, uint32 *damage, CleanDamage *cleanDamage, bool *crit = false, bool isTriggeredSpell = false);
845        void DoAttackDamage(Unit *pVictim, uint32 *damage, CleanDamage *cleanDamage, uint32 *blocked_amount, SpellSchoolMask damageSchoolMask, uint32 *hitInfo, VictimState *victimState, uint32 *absorbDamage, uint32 *resistDamage, WeaponAttackType attType, SpellEntry const *spellCasted = NULL, bool isTriggeredSpell = false);
846
847        void CastMeleeProcDamageAndSpell(Unit* pVictim, uint32 damage, SpellSchoolMask damageSchoolMask, WeaponAttackType attType, MeleeHitOutcome outcome, SpellEntry const *spellCasted = NULL, bool isTriggeredSpell = false);
848        void ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 damage = 0, SpellSchoolMask damageSchoolMask = SPELL_SCHOOL_MASK_NONE, SpellEntry const *procSpell = NULL, bool isTriggeredSpell = false, WeaponAttackType attType = BASE_ATTACK);
849        void HandleEmoteCommand(uint32 anim_id);
850        void AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType = BASE_ATTACK, bool extra = false );
851
852        float MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const;
853        SpellMissInfo MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell);
854        SpellMissInfo SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool canReflect = false);
855
856        float GetUnitDodgeChance()    const;
857        float GetUnitParryChance()    const;
858        float GetUnitBlockChance()    const;
859        float GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const;
860
861        virtual uint32 GetShieldBlockValue() const =0;
862        uint32 GetUnitMeleeSkill(Unit const* target = NULL) const { return (target ? getLevelForTarget(target) : getLevel()) * 5; }
863        uint32 GetDefenseSkillValue(Unit const* target = NULL) const;
864        uint32 GetWeaponSkillValue(WeaponAttackType attType, Unit const* target = NULL) const;
865        float GetWeaponProcChance() const;
866        float GetPPMProcChance(uint32 WeaponSpeed, float PPM) const;
867        MeleeHitOutcome RollPhysicalOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, SpellEntry const *spellInfo);
868        MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType) const;
869        MeleeHitOutcome RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance, bool SpellCasted ) const;
870
871        bool isVendor()       const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_VENDOR ); }
872        bool isTrainer()      const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TRAINER ); }
873        bool isQuestGiver()   const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_QUESTGIVER ); }
874        bool isGossip()       const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP ); }
875        bool isTaxi()         const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_FLIGHTMASTER ); }
876        bool isGuildMaster()  const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_PETITIONER ); }
877        bool isBattleMaster() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BATTLEMASTER ); }
878        bool isBanker()       const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_BANKER ); }
879        bool isInnkeeper()    const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_INNKEEPER ); }
880        bool isSpiritHealer() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER ); }
881        bool isSpiritGuide()  const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITGUIDE ); }
882        bool isTabardDesigner()const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_TABARDDESIGNER ); }
883        bool isAuctioner()    const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_AUCTIONEER ); }
884        bool isArmorer()      const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_REPAIR ); }
885        bool isServiceProvider() const
886        {
887            return HasFlag( UNIT_NPC_FLAGS,
888                UNIT_NPC_FLAG_VENDOR | UNIT_NPC_FLAG_TRAINER | UNIT_NPC_FLAG_FLIGHTMASTER |
889                UNIT_NPC_FLAG_PETITIONER | UNIT_NPC_FLAG_BATTLEMASTER | UNIT_NPC_FLAG_BANKER |
890                UNIT_NPC_FLAG_INNKEEPER | UNIT_NPC_FLAG_GUARD | UNIT_NPC_FLAG_SPIRITHEALER |
891                UNIT_NPC_FLAG_SPIRITGUIDE | UNIT_NPC_FLAG_TABARDDESIGNER | UNIT_NPC_FLAG_AUCTIONEER );
892        }
893        bool isSpiritService() const { return HasFlag( UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER | UNIT_NPC_FLAG_SPIRITGUIDE ); }
894
895        //Need fix or use this
896        bool isGuard() const  { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GUARD); }
897
898        bool isInFlight()  const { return hasUnitState(UNIT_STAT_IN_FLIGHT); }
899
900        bool isInCombat()  const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); }
901        void SetInCombatState(bool PvP);
902        void SetInCombatWith(Unit* enemy);
903        void ClearInCombat();
904        uint32 GetCombatTimer() const { return m_CombatTimer; }
905
906        bool HasAuraType(AuraType auraType) const;
907        bool HasAura(uint32 spellId, uint32 effIndex) const
908            { return m_Auras.find(spellEffectPair(spellId, effIndex)) != m_Auras.end(); }
909
910        bool virtual HasSpell(uint32 /*spellID*/) const { return false; }
911
912        bool HasStealthAura()      const { return HasAuraType(SPELL_AURA_MOD_STEALTH); }
913        bool HasInvisibilityAura() const { return HasAuraType(SPELL_AURA_MOD_INVISIBILITY); }
914        bool isFeared()  const { return HasAuraType(SPELL_AURA_MOD_FEAR); }
915        bool isInRoots() const { return HasAuraType(SPELL_AURA_MOD_ROOT); }
916        bool IsPolymorphed() const;
917
918        bool isFrozen() const;
919
920        bool isTargetableForAttack() const;
921        virtual bool IsInWater() const;
922        virtual bool IsUnderWater() const;
923        bool isInAccessablePlaceFor(Creature const* c) const;
924
925        void SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, bool critical = false);
926        void SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage,Powers powertype, bool critical = false);
927        uint32 SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage, bool isTriggeredSpell = false, bool useSpellDamage = true);
928        void CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
929        void CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem= NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
930        void CastCustomSpell(Unit* Victim, uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
931        void CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
932        void CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
933        void CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem = NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
934
935        bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const;
936
937        void DeMorph();
938
939        void SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount);
940        void SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID,uint32 Damage, SpellSchoolMask damageSchoolMask,uint32 AbsorbedDamage, uint32 Resist,bool PhysicalDamage, uint32 Blocked, bool CriticalHit = false);
941        void SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo);
942
943        void SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, uint32 MovementFlags, uint32 Time, Player* player = NULL);
944        void SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, uint32 MovementFlags);
945        void SendMonsterMoveWithSpeed(float x, float y, float z, uint32 MovementFlags, uint32 transitTime = 0, Player* player = NULL);
946        void SendMonsterMoveWithSpeedToCurrentDestination(Player* player = NULL);
947
948        virtual void MoveOutOfRange(Player &) {  };
949
950        bool isAlive() const { return (m_deathState == ALIVE); };
951        bool isDead() const { return ( m_deathState == DEAD || m_deathState == CORPSE ); };
952        DeathState getDeathState() { return m_deathState; };
953        virtual void setDeathState(DeathState s);           // overwrited in Creature/Player/Pet
954
955        uint64 const& GetOwnerGUID() const { return  GetUInt64Value(UNIT_FIELD_SUMMONEDBY); }
956        uint64 GetPetGUID() const { return  GetUInt64Value(UNIT_FIELD_SUMMON); }
957        uint64 GetCharmerGUID() const { return GetUInt64Value(UNIT_FIELD_CHARMEDBY); }
958        uint64 GetCharmGUID() const { return  GetUInt64Value(UNIT_FIELD_CHARM); }
959        void SetCharmerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_CHARMEDBY, owner); }
960
961        uint64 GetCharmerOrOwnerGUID() const { return GetCharmerGUID() ? GetCharmerGUID() : GetOwnerGUID(); }
962        uint64 GetCharmerOrOwnerOrOwnGUID() const
963        {
964            if(uint64 guid = GetCharmerOrOwnerGUID())
965                return guid;
966            return GetGUID();
967        }
968        bool isCharmedOwnedByPlayerOrPlayer() const { return IS_PLAYER_GUID(GetCharmerOrOwnerOrOwnGUID()); }
969
970        Player* GetSpellModOwner();
971
972        Unit* GetOwner() const;
973        Pet* GetPet() const;
974        Unit* GetCharmer() const;
975        Unit* GetCharm() const;
976        Unit* GetCharmerOrOwner() const { return GetCharmerGUID() ? GetCharmer() : GetOwner(); }
977        Unit* GetCharmerOrOwnerOrSelf()
978        {
979            if(Unit* u = GetCharmerOrOwner())
980                return u;
981
982            return this;
983        }
984        Player* GetCharmerOrOwnerPlayerOrPlayerItself();
985
986        void SetPet(Pet* pet);
987        void SetCharm(Unit* pet);
988        bool isCharmed() const { return GetCharmerGUID() != 0; }
989
990        CharmInfo* GetCharmInfo() { return m_charmInfo; }
991        CharmInfo* InitCharmInfo(Unit* charm);
992
993        bool AddAura(Aura *aur);
994
995        void RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode = AURA_REMOVE_BY_DEFAULT);
996        void RemoveAura(uint32 spellId, uint32 effindex, Aura* except = NULL);
997        void RemoveSingleAuraFromStack(uint32 spellId, uint32 effindex);
998        void RemoveAurasDueToSpell(uint32 spellId, Aura* except = NULL);
999        void RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId);
1000        void RemoveAurasDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler);
1001        void RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer);
1002        void RemoveAurasDueToSpellByCancel(uint32 spellId);
1003        void RemoveNotOwnSingleTargetAuras();
1004
1005        void RemoveSpellsCausingAura(AuraType auraType);
1006        void RemoveRankAurasDueToSpell(uint32 spellId);
1007        bool RemoveNoStackAurasDueToAura(Aura *Aur);
1008        void RemoveAurasWithInterruptFlags(uint32 flags);
1009        void RemoveAurasWithDispelType( DispelType type );
1010
1011        void RemoveAllAuras();
1012        void RemoveArenaAuras(bool onleave = false);
1013        void RemoveAllAurasOnDeath();
1014        void DelayAura(uint32 spellId, uint32 effindex, int32 delaytime);
1015
1016        float GetResistanceBuffMods(SpellSchools school, bool positive) const { return GetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school ); }
1017        void SetResistanceBuffMods(SpellSchools school, bool positive, float val) { SetFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school,val); }
1018        void ApplyResistanceBuffModsMod(SpellSchools school, bool positive, float val, bool apply) { ApplyModSignedFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1019        void ApplyResistanceBuffModsPercentMod(SpellSchools school, bool positive, float val, bool apply) { ApplyPercentModFloatValue(positive ? UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE+school : UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE+school, val, apply); }
1020        void InitStatBuffMods()
1021        {
1022            for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_POSSTAT0+i, 0);
1023            for(int i = STAT_STRENGTH; i < MAX_STATS; ++i) SetFloatValue(UNIT_FIELD_NEGSTAT0+i, 0);
1024        }
1025        void ApplyStatBuffMod(Stats stat, float val, bool apply) { ApplyModSignedFloatValue((val > 0 ? UNIT_FIELD_POSSTAT0+stat : UNIT_FIELD_NEGSTAT0+stat), val, apply); }
1026        void ApplyStatPercentBuffMod(Stats stat, float val, bool apply)
1027        {
1028            ApplyPercentModFloatValue(UNIT_FIELD_POSSTAT0+stat, val, apply);
1029            ApplyPercentModFloatValue(UNIT_FIELD_NEGSTAT0+stat, val, apply);
1030        }
1031        void SetCreateStat(Stats stat, float val) { m_createStats[stat] = val; }
1032        void SetCreateHealth(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_HEALTH, val); }
1033        uint32 GetCreateHealth() const { return GetUInt32Value(UNIT_FIELD_BASE_HEALTH); }
1034        void SetCreateMana(uint32 val) { SetUInt32Value(UNIT_FIELD_BASE_MANA, val); }
1035        uint32 GetCreateMana() const { return GetUInt32Value(UNIT_FIELD_BASE_MANA); }
1036        uint32 GetCreatePowers(Powers power) const;
1037        float GetPosStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_POSSTAT0+stat); }
1038        float GetNegStat(Stats stat) const { return GetFloatValue(UNIT_FIELD_NEGSTAT0+stat); }
1039        float GetCreateStat(Stats stat) const { return m_createStats[stat]; }
1040
1041        void SetCurrentCastedSpell(Spell * pSpell);
1042        virtual void ProhibitSpellScholl(SpellSchoolMask /*idSchoolMask*/, uint32 /*unTimeMs*/ ) { }
1043        void InterruptSpell(uint32 spellType, bool withDelayed = true);
1044
1045        // set withDelayed to true to account delayed spells as casted
1046        // delayed+channeled spells are always accounted as casted
1047        // we can skip channeled or delayed checks using flags
1048        bool IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled = false, bool skipAutorepeat = false) const;
1049
1050        // set withDelayed to true to interrupt delayed spells too
1051        // delayed+channeled spells are always interrupted
1052        void InterruptNonMeleeSpells(bool withDelayed, uint32 spellid = 0);
1053
1054        Spell* FindCurrentSpellBySpellId(uint32 spell_id) const;
1055
1056        Spell* m_currentSpells[CURRENT_MAX_SPELL];
1057
1058        uint32 m_addDmgOnce;
1059        uint64 m_TotemSlot[MAX_TOTEM];
1060        uint64 m_ObjectSlot[4];
1061        uint32 m_detectInvisibilityMask;
1062        uint32 m_invisibilityMask;
1063        uint32 m_ShapeShiftFormSpellId;
1064        ShapeshiftForm m_form;
1065        float m_modMeleeHitChance;
1066        float m_modRangedHitChance;
1067        float m_modSpellHitChance;
1068        int32 m_baseSpellCritChance;
1069
1070        float m_threatModifier[MAX_SPELL_SCHOOL];
1071        float m_modAttackSpeedPct[3];
1072
1073        // Event handler
1074        EventProcessor m_Events;
1075
1076        // stat system
1077        bool HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply);
1078        void SetModifierValue(UnitMods unitMod, UnitModifierType modifierType, float value) { m_auraModifiersGroup[unitMod][modifierType] = value; }
1079        float GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const;
1080        float GetTotalStatValue(Stats stat) const;
1081        float GetTotalAuraModValue(UnitMods unitMod) const;
1082        SpellSchools GetSpellSchoolByAuraGroup(UnitMods unitMod) const;
1083        Stats GetStatByAuraGroup(UnitMods unitMod) const;
1084        Powers GetPowerTypeByAuraGroup(UnitMods unitMod) const;
1085        bool CanModifyStats() const { return m_canModifyStats; }
1086        void SetCanModifyStats(bool modifyStats) { m_canModifyStats = modifyStats; }
1087        virtual bool UpdateStats(Stats stat) = 0;
1088        virtual bool UpdateAllStats() = 0;
1089        virtual void UpdateResistances(uint32 school) = 0;
1090        virtual void UpdateArmor() = 0;
1091        virtual void UpdateMaxHealth() = 0;
1092        virtual void UpdateMaxPower(Powers power) = 0;
1093        virtual void UpdateAttackPowerAndDamage(bool ranged = false) = 0;
1094        virtual void UpdateDamagePhysical(WeaponAttackType attType) = 0;
1095        float GetTotalAttackPowerValue(WeaponAttackType attType) const;
1096        float GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const;
1097        void SetBaseWeaponDamage(WeaponAttackType attType ,WeaponDamageRange damageRange, float value) { m_weaponDamage[attType][damageRange] = value; }
1098
1099        bool isInFront(Unit const* target,float distance, float arc = M_PI) const;
1100        void SetInFront(Unit const* target);
1101        bool isInBack(Unit const* target, float distance, float arc = M_PI) const;
1102        bool isInLine(Unit const* target, float distance) const;
1103
1104        // Visibility system
1105        UnitVisibility GetVisibility() const { return m_Visibility; }
1106        void SetVisibility(UnitVisibility x);
1107
1108        // common function for visibility checks for player/creatures with detection code
1109        bool isVisibleForOrDetect(Unit const* u, bool detect, bool inVisibleList = false) const;
1110        bool canDetectInvisibilityOf(Unit const* u) const;
1111
1112        // virtual functions for all world objects types
1113        bool isVisibleForInState(Player const* u, bool inVisibleList) const;
1114        // function for low level grid visibility checks in player/creature cases
1115        virtual bool IsVisibleInGridForPlayer(Player* pl) const = 0;
1116
1117        bool waterbreath;
1118        AuraList      & GetSingleCastAuras()       { return m_scAuras; }
1119        AuraList const& GetSingleCastAuras() const { return m_scAuras; }
1120        SpellImmuneList m_spellImmune[MAX_SPELL_IMMUNITY];
1121
1122        // Threat related methodes
1123        bool CanHaveThreatList() const;
1124        void AddThreat(Unit* pVictim, float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellEntry const *threatSpell = NULL);
1125        float ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL);
1126        void DeleteThreatList();
1127        bool SelectHostilTarget();
1128        void TauntApply(Unit* pVictim);
1129        void TauntFadeOut(Unit *taunter);
1130        ThreatManager& getThreatManager() { return m_ThreatManager; }
1131        void addHatedBy(HostilReference* pHostilReference) { m_HostilRefManager.insertFirst(pHostilReference); };
1132        void removeHatedBy(HostilReference* /*pHostilReference*/ ) { /* nothing to do yet */ }
1133        HostilRefManager& getHostilRefManager() { return m_HostilRefManager; }
1134
1135        Aura* GetAura(uint32 spellId, uint32 effindex);
1136        AuraMap      & GetAuras()       { return m_Auras; }
1137        AuraMap const& GetAuras() const { return m_Auras; }
1138        AuraList const& GetAurasByType(AuraType type) const { return m_modAuras[type]; }
1139        void ApplyAuraProcTriggerDamage(Aura* aura, bool apply);
1140
1141        int32 GetTotalAuraModifier(AuraType auratype) const;
1142        float GetTotalAuraMultiplier(AuraType auratype) const;
1143        int32 GetMaxPositiveAuraModifier(AuraType auratype) const;
1144        int32 GetMaxNegativeAuraModifier(AuraType auratype) const;
1145
1146        int32 GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1147        float GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1148        int32 GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1149        int32 GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const;
1150
1151        int32 GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1152        float GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const;
1153        int32 GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1154        int32 GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const;
1155
1156        Aura* GetDummyAura(uint32 spell_id) const;
1157
1158        uint32 GetDisplayId() { return GetUInt32Value(UNIT_FIELD_DISPLAYID); }
1159        void SetDisplayId(uint32 modelId);
1160        uint32 GetNativeDisplayId() { return GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID); }
1161        void SetNativeDisplayId(uint32 modelId) { SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, modelId); }
1162        void setTransForm(uint32 spellid) { m_transform = spellid;}
1163        uint32 getTransForm() const { return m_transform;}
1164        void AddDynObject(DynamicObject* dynObj);
1165        void RemoveDynObject(uint32 spellid);
1166        void RemoveDynObjectWithGUID(uint64 guid) { m_dynObjGUIDs.remove(guid); }
1167        void RemoveAllDynObjects();
1168        void AddGameObject(GameObject* gameObj);
1169        void RemoveGameObject(GameObject* gameObj, bool del);
1170        void RemoveGameObject(uint32 spellid, bool del);
1171        void RemoveAllGameObjects();
1172        DynamicObject *GetDynObject(uint32 spellId, uint32 effIndex);
1173        DynamicObject *GetDynObject(uint32 spellId);
1174        uint32 CalculateDamage(WeaponAttackType attType, bool normalized);
1175        float GetAPMultiplier(WeaponAttackType attType, bool normalized);
1176        void ModifyAuraState(AuraState flag, bool apply);
1177        bool HasAuraState(AuraState flag) const { return HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); }
1178        void UnsummonAllTotems();
1179        int32 SpellBaseDamageBonus(SpellSchoolMask schoolMask);
1180        int32 SpellBaseHealingBonus(SpellSchoolMask schoolMask);
1181        int32 SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1182        int32 SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim);
1183        uint32 SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 damage, DamageEffectType damagetype);
1184        uint32 SpellHealingBonus(SpellEntry const *spellProto, uint32 healamount, DamageEffectType damagetype, Unit *pVictim);
1185        bool   isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType);
1186        uint32 SpellCriticalBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim);
1187
1188        void SetLastManaUse(uint32 spellCastTime) { m_lastManaUse = spellCastTime; }
1189        bool IsUnderLastManaUseEffect() const;
1190
1191        void SetContestedPvP(Player *attackedPlayer = NULL);
1192
1193        void MeleeDamageBonus(Unit *pVictim, uint32 *damage, WeaponAttackType attType, SpellEntry const *spellProto = NULL);
1194        uint32 GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime );
1195
1196        void ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply);
1197        void ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply);
1198        virtual bool IsImmunedToSpell(SpellEntry const* spellInfo, bool useCharges = false);
1199                                                            // redefined in Creature
1200        bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask, bool useCharges = false);
1201        virtual bool IsImmunedToSpellEffect(uint32 effect, uint32 mechanic) const;
1202                                                            // redefined in Creature
1203
1204        uint32 CalcArmorReducedDamage(Unit* pVictim, const uint32 damage);
1205        void CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist);
1206
1207        void  UpdateSpeed(UnitMoveType mtype, bool forced);
1208        float GetSpeed( UnitMoveType mtype ) const;
1209        float GetSpeedRate( UnitMoveType mtype ) const { return m_speed_rate[mtype]; }
1210        void SetSpeed(UnitMoveType mtype, float rate, bool forced = false);
1211
1212        void SetHover(bool on);
1213        bool isHover() const { return HasAuraType(SPELL_AURA_HOVER); }
1214
1215        void _RemoveAllAuraMods();
1216        void _ApplyAllAuraMods();
1217
1218        int32 CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_index, int32 basePoints, Unit const* target);
1219        int32 CalculateSpellDuration(SpellEntry const* spellProto, uint8 effect_index, Unit const* target);
1220        float CalculateLevelPenalty(SpellEntry const* spellProto) const;
1221
1222        void addFollower(FollowerReference* pRef) { m_FollowingRefManager.insertFirst(pRef); }
1223        void removeFollower(FollowerReference* /*pRef*/ ) { /* nothing to do yet */ }
1224        static Unit* GetUnit(WorldObject& object, uint64 guid);
1225
1226        MotionMaster* GetMotionMaster() { return &i_motionMaster; }
1227
1228        bool IsStopped() const { return !(hasUnitState(UNIT_STAT_MOVING)); }
1229        void StopMoving();
1230
1231        void AddUnitMovementFlag(uint32 f) { m_unit_movement_flags |= f; }
1232        void RemoveUnitMovementFlag(uint32 f)
1233        {
1234            uint32 oldval = m_unit_movement_flags;
1235            m_unit_movement_flags = oldval & ~f;
1236        }
1237        uint32 HasUnitMovementFlag(uint32 f) const { return m_unit_movement_flags & f; }
1238        uint32 GetUnitMovementFlags() const { return m_unit_movement_flags; }
1239        void SetUnitMovementFlags(uint32 f) { m_unit_movement_flags = f; }
1240
1241        void SetFeared(bool apply, uint64 casterGUID = 0, uint32 spellID = 0);
1242        void SetConfused(bool apply, uint64 casterGUID = 0, uint32 spellID = 0);
1243
1244        void AddComboPointHolder(uint32 lowguid) { m_ComboPointHolders.insert(lowguid); }
1245        void RemoveComboPointHolder(uint32 lowguid) { m_ComboPointHolders.erase(lowguid); }
1246        void ClearComboPointHolders();
1247
1248        ///----------Pet responses methods-----------------
1249        void SendPetCastFail(uint32 spellid, uint8 msg);
1250        void SendPetActionFeedback (uint8 msg);
1251        void SendPetTalk (uint32 pettalk);
1252        void SendPetSpellCooldown (uint32 spellid, time_t cooltime);
1253        void SendPetClearCooldown (uint32 spellid);
1254        void SendPetAIReaction(uint64 guid);
1255        ///----------End of Pet responses methods----------
1256
1257        void propagateSpeedChange() { GetMotionMaster()->propagateSpeedChange(); }
1258
1259        // reactive attacks
1260        void ClearAllReactives();
1261        void StartReactiveTimer( ReactiveType reactive ) { m_reactiveTimer[reactive] = REACTIVE_TIMER_START;}
1262        void UpdateReactives(uint32 p_time);
1263
1264        // group updates
1265        void UpdateAuraForGroup(uint8 slot);
1266
1267        // pet auras
1268        typedef std::set<PetAura const*> PetAuraSet;
1269        PetAuraSet m_petAuras;
1270        void AddPetAura(PetAura const* petSpell);
1271        void RemovePetAura(PetAura const* petSpell);
1272
1273    protected:
1274        explicit Unit ();
1275
1276        void _UpdateSpells(uint32 time);
1277
1278        void _UpdateAutoRepeatSpell();
1279        bool m_AutoRepeatFirstCast;
1280
1281        uint32 m_attackTimer[MAX_ATTACK];
1282
1283        float m_createStats[MAX_STATS];
1284
1285        AttackerSet m_attackers;
1286        Unit* m_attacking;
1287
1288        DeathState m_deathState;
1289
1290        AuraMap m_Auras;
1291
1292        std::list<Aura *> m_scAuras;                        // casted singlecast auras
1293
1294        typedef std::list<uint64> DynObjectGUIDs;
1295        DynObjectGUIDs m_dynObjGUIDs;
1296
1297        std::list<GameObject*> m_gameObj;
1298        bool m_isSorted;
1299        uint32 m_transform;
1300        uint32 m_removedAuras;
1301
1302        AuraList m_modAuras[TOTAL_AURAS];
1303        float m_auraModifiersGroup[UNIT_MOD_END][MODIFIER_TYPE_END];
1304        float m_weaponDamage[MAX_ATTACK][2];
1305        bool m_canModifyStats;
1306        //std::list< spellEffectPair > AuraSpells[TOTAL_AURAS];  // TODO: use this if ok for mem
1307
1308        float m_speed_rate[MAX_MOVE_TYPE];
1309
1310        CharmInfo *m_charmInfo;
1311
1312        virtual SpellSchoolMask GetMeleeDamageSchoolMask() const;
1313
1314        MotionMaster i_motionMaster;
1315        uint32 m_unit_movement_flags;
1316
1317        uint32 m_reactiveTimer[MAX_REACTIVE];
1318
1319    private:
1320        void SendAttackStop(Unit* victim);                  // only from AttackStop(Unit*)
1321        void SendAttackStart(Unit* pVictim);                // only from Unit::AttackStart(Unit*)
1322
1323        void ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, AuraTypeSet const& procAuraTypes, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage, SpellSchoolMask damageSchoolMask );
1324        bool HandleDummyAuraProc(Unit *pVictim, SpellEntry const *spellProto, uint32 effIndex, uint32 damage, Aura* triggredByAura, SpellEntry const * procSpell, uint32 procFlag,uint32 cooldown);
1325        bool HandleProcTriggerSpell(Unit *pVictim,uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell, uint32 procFlags,WeaponAttackType attType,uint32 cooldown);
1326        bool HandleHasteAuraProc(Unit *pVictim, SpellEntry const *spellProto, uint32 effIndex, uint32 damage, Aura* triggredByAura, SpellEntry const * procSpell, uint32 procFlag,uint32 cooldown);
1327        bool HandleOverrideClassScriptAuraProc(Unit *pVictim, int32 scriptId, uint32 damage, Aura* triggredByAura, SpellEntry const *procSpell,uint32 cooldown);
1328        uint32 m_state;                                     // Even derived shouldn't modify
1329        uint32 m_CombatTimer;
1330        uint32 m_lastManaUse;                               // msecs
1331
1332        UnitVisibility m_Visibility;
1333
1334        Diminishing m_Diminishing;
1335        // Manage all Units threatening us
1336        ThreatManager m_ThreatManager;
1337        // Manage all Units that are threatened by us
1338        HostilRefManager m_HostilRefManager;
1339
1340        FollowerRefManager m_FollowingRefManager;
1341
1342        ComboPointHolderSet m_ComboPointHolders;
1343};
1344#endif
Note: See TracBrowser for help on using the browser.