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

Revision 213, 63.2 kB (checked in by yumileroy, 17 years ago)

[svn] Fix some aura_interrupt_flag to correctly remove auras.
Add interrupt_flag_unattackable. Source: mangos forum. Adapted by F636y623.
Add function CombatStart?().

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