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

Revision 149, 61.6 kB (checked in by yumileroy, 17 years ago)

[svn] *Implement new player conditions CONDITION_NO_AURA, CONDITION_ACTIVE_EVENT
* Default behaviour of pets for creatures changed to REACT_DEFENSIVE
* Disallowed sending wrapped items as COD
* Prevent loading and saving single target auras for pet in same way as already implemented for player
* Correctly limit use some flask types to zones.
* Fixed extracting common.MPQ under *nix
* Many small xleanups and fixes.
** mangos merge rev.

TEST REV so be careful of creepy crawly bugs!

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