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

Revision 203, 63.0 kB (checked in by yumileroy, 17 years ago)

[svn] Send AttackStart? package when update visibility.
Update DoMeleeAttackIfReady? to support dual wield.
Show player modelid2 instead id3 of triggers. This should fix the bug that gameobject::castspell summon a human model.
Remove the correct flag to make creature attackable. This should fix the bug that Illidan and Magtheridon are unattackable.
Add NullCreatureAI for trinityscript.
Fix channeler's soul transfer.
Some update of black temple scripts.

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