root/trunk/src/game/Player.h @ 34

Revision 34, 97.2 kB (checked in by yumileroy, 17 years ago)

[svn] * Removing useless data accidentally committed.
* Applying ImpConfig? patch.
* Note: QUEUE_FOR_GM currently disabled as it's not compatible with the ACE patch. Anyone care to rewrite it?
* Note2: This is untested - I may have done some mistakes here and there. Will try to compile now.

Original author: XTZGZoReX
Date: 2008-10-10 13:37:21-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 */
18
19#ifndef _PLAYER_H
20#define _PLAYER_H
21
22#include "Common.h"
23#include "ItemPrototype.h"
24#include "Unit.h"
25#include "Item.h"
26
27#include "Database/DatabaseEnv.h"
28#include "NPCHandler.h"
29#include "QuestDef.h"
30#include "Group.h"
31#include "Bag.h"
32#include "WorldSession.h"
33#include "Pet.h"
34#include "Util.h"                                           // for Tokens typedef
35
36#include<string>
37#include<vector>
38
39struct Mail;
40class Channel;
41class DynamicObject;
42class Creature;
43class Pet;
44class PlayerMenu;
45class Transport;
46class UpdateMask;
47class PlayerSocial;
48
49typedef std::deque<Mail*> PlayerMails;
50
51#define PLAYER_MAX_SKILLS       127
52#define PLAYER_MAX_DAILY_QUESTS 25
53
54// Note: SPELLMOD_* values is aura types in fact
55enum SpellModType
56{
57    SPELLMOD_FLAT         = 107,                            // SPELL_AURA_ADD_FLAT_MODIFIER
58    SPELLMOD_PCT          = 108                             // SPELL_AURA_ADD_PCT_MODIFIER
59};
60
61enum PlayerSpellState
62{
63    PLAYERSPELL_UNCHANGED = 0,
64    PLAYERSPELL_CHANGED   = 1,
65    PLAYERSPELL_NEW       = 2,
66    PLAYERSPELL_REMOVED   = 3
67};
68
69struct PlayerSpell
70{
71    uint16 slotId          : 16;
72    PlayerSpellState state : 8;
73    bool active            : 1;
74    bool disabled          : 1;
75};
76
77#define SPELL_WITHOUT_SLOT_ID uint16(-1)
78
79struct SpellModifier
80{
81    SpellModOp   op   : 8;
82    SpellModType type : 8;
83    int16 charges     : 16;
84    int32 value;
85    uint64 mask;
86    uint32 spellId;
87    uint32 effectId;
88    Spell const* lastAffected;
89};
90
91typedef HM_NAMESPACE::hash_map<uint16, PlayerSpell*> PlayerSpellMap;
92typedef std::list<SpellModifier*> SpellModList;
93
94struct SpellCooldown
95{
96    time_t end;
97    uint16 itemid;
98};
99
100typedef std::map<uint32, SpellCooldown> SpellCooldowns;
101
102enum TrainerSpellState
103{
104    TRAINER_SPELL_GREEN = 0,
105    TRAINER_SPELL_RED   = 1,
106    TRAINER_SPELL_GRAY  = 2
107};
108
109enum ActionButtonUpdateState
110{
111    ACTIONBUTTON_UNCHANGED = 0,
112    ACTIONBUTTON_CHANGED   = 1,
113    ACTIONBUTTON_NEW       = 2,
114    ACTIONBUTTON_DELETED   = 3
115};
116
117struct ActionButton
118{
119    ActionButton() : action(0), type(0), misc(0), uState( ACTIONBUTTON_NEW ) {}
120    ActionButton(uint16 _action, uint8 _type, uint8 _misc) : action(_action), type(_type), misc(_misc), uState( ACTIONBUTTON_NEW ) {}
121
122    uint16 action;
123    uint8 type;
124    uint8 misc;
125    ActionButtonUpdateState uState;
126};
127
128enum ActionButtonType
129{
130    ACTION_BUTTON_SPELL = 0,
131    ACTION_BUTTON_MACRO = 64,
132    ACTION_BUTTON_CMACRO= 65,
133    ACTION_BUTTON_ITEM  = 128
134};
135
136#define  MAX_ACTION_BUTTONS 132                             //checked in 2.3.0
137
138typedef std::map<uint8,ActionButton> ActionButtonList;
139
140typedef std::pair<uint16, uint8> CreateSpellPair;
141
142struct PlayerCreateInfoItem
143{
144    PlayerCreateInfoItem(uint32 id, uint32 amount) : item_id(id), item_amount(amount) {}
145
146    uint32 item_id;
147    uint32 item_amount;
148};
149
150typedef std::list<PlayerCreateInfoItem> PlayerCreateInfoItems;
151
152struct PlayerClassLevelInfo
153{
154    PlayerClassLevelInfo() : basehealth(0), basemana(0) {}
155    uint16 basehealth;
156    uint16 basemana;
157};
158
159struct PlayerClassInfo
160{
161    PlayerClassInfo() : levelInfo(NULL) { }
162
163    PlayerClassLevelInfo* levelInfo;                        //[level-1] 0..MaxPlayerLevel-1
164};
165
166struct PlayerLevelInfo
167{
168    PlayerLevelInfo() { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
169
170    uint8 stats[MAX_STATS];
171};
172
173struct PlayerInfo
174{
175                                                            // existence checked by displayId != 0             // existence checked by displayId != 0
176    PlayerInfo() : displayId_m(0),displayId_f(0),levelInfo(NULL)
177    {
178    }
179
180    uint32 mapId;
181    uint32 zoneId;
182    float positionX;
183    float positionY;
184    float positionZ;
185    uint16 displayId_m;
186    uint16 displayId_f;
187    PlayerCreateInfoItems item;
188    std::list<CreateSpellPair> spell;
189    std::list<uint16> action[4];
190
191    PlayerLevelInfo* levelInfo;                             //[level-1] 0..MaxPlayerLevel-1
192};
193
194struct PvPInfo
195{
196    PvPInfo() : inHostileArea(false), endTimer(0) {}
197
198    bool inHostileArea;
199    time_t endTimer;
200};
201
202struct DuelInfo
203{
204    DuelInfo() : initiator(NULL), opponent(NULL), startTimer(0), startTime(0), outOfBound(0) {}
205
206    Player *initiator;
207    Player *opponent;
208    time_t startTimer;
209    time_t startTime;
210    time_t outOfBound;
211};
212
213struct Areas
214{
215    uint32 areaID;
216    uint32 areaFlag;
217    float x1;
218    float x2;
219    float y1;
220    float y2;
221};
222
223enum FactionFlags
224{
225    FACTION_FLAG_VISIBLE            = 0x01,                 // makes visible in client (set or can be set at interaction with target of this faction)
226    FACTION_FLAG_AT_WAR             = 0x02,                 // enable AtWar-button in client. player controlled (except opposition team always war state), Flag only set on initial creation
227    FACTION_FLAG_HIDDEN             = 0x04,                 // hidden faction from reputation pane in client (player can gain reputation, but this update not sent to client)
228    FACTION_FLAG_INVISIBLE_FORCED   = 0x08,                 // always overwrite FACTION_FLAG_VISIBLE and hide faction in rep.list, used for hide opposite team factions
229    FACTION_FLAG_PEACE_FORCED       = 0x10,                 // always overwrite FACTION_FLAG_AT_WAR, used for prevent war with own team factions
230    FACTION_FLAG_INACTIVE           = 0x20,                 // player controlled, state stored in characters.data ( CMSG_SET_FACTION_INACTIVE )
231    FACTION_FLAG_RIVAL              = 0x40                  // flag for the two competing outland factions
232};
233
234typedef uint32 RepListID;
235struct FactionState
236{
237    uint32 ID;
238    RepListID ReputationListID;
239    uint32 Flags;
240    int32  Standing;
241    bool Changed;
242};
243
244typedef std::map<RepListID,FactionState> FactionStateList;
245
246typedef std::map<uint32,ReputationRank> ForcedReactions;
247
248typedef std::set<uint64> GuardianPetList;
249
250struct EnchantDuration
251{
252    EnchantDuration() : item(NULL), slot(MAX_ENCHANTMENT_SLOT), leftduration(0) {};
253    EnchantDuration(Item * _item, EnchantmentSlot _slot, uint32 _leftduration) : item(_item), slot(_slot), leftduration(_leftduration) { assert(item); };
254
255    Item * item;
256    EnchantmentSlot slot;
257    uint32 leftduration;
258};
259
260typedef std::list<EnchantDuration> EnchantDurationList;
261typedef std::list<Item*> ItemDurationList;
262
263struct LookingForGroupSlot
264{
265    LookingForGroupSlot() : entry(0), type(0) {}
266    bool Empty() const { return !entry && !type; }
267    void Clear() { entry = 0; type = 0; }
268    void Set(uint32 _entry, uint32 _type ) { entry = _entry; type = _type; }
269    bool Is(uint32 _entry, uint32 _type) const { return entry==_entry && type==_type; }
270    bool canAutoJoin() const { return entry && (type == 1 || type == 5); }
271
272    uint32 entry;
273    uint32 type;
274};
275
276#define MAX_LOOKING_FOR_GROUP_SLOT 3
277
278struct LookingForGroup
279{
280    LookingForGroup() {}
281    bool HaveInSlot(LookingForGroupSlot const& slot) const { return HaveInSlot(slot.entry,slot.type); }
282    bool HaveInSlot(uint32 _entry, uint32 _type) const
283    {
284        for(int i = 0; i < MAX_LOOKING_FOR_GROUP_SLOT; ++i)
285            if(slots[i].Is(_entry,_type))
286                return true;
287        return false;
288    }
289
290    bool canAutoJoin() const
291    {
292        for(int i = 0; i < MAX_LOOKING_FOR_GROUP_SLOT; ++i)
293            if(slots[i].canAutoJoin())
294                return true;
295        return false;
296    }
297
298    bool Empty() const
299    {
300        for(int i = 0; i < MAX_LOOKING_FOR_GROUP_SLOT; ++i)
301            if(!slots[i].Empty())
302                return false;
303        return more.Empty();
304    }
305
306    LookingForGroupSlot slots[MAX_LOOKING_FOR_GROUP_SLOT];
307    LookingForGroupSlot more;
308    std::string comment;
309};
310
311enum PlayerMovementType
312{
313    MOVE_ROOT       = 1,
314    MOVE_UNROOT     = 2,
315    MOVE_WATER_WALK = 3,
316    MOVE_LAND_WALK  = 4
317};
318
319enum DrunkenState
320{
321    DRUNKEN_SOBER   = 0,
322    DRUNKEN_TIPSY   = 1,
323    DRUNKEN_DRUNK   = 2,
324    DRUNKEN_SMASHED = 3
325};
326
327enum PlayerStateType
328{
329    /*
330        PLAYER_STATE_DANCE
331        PLAYER_STATE_SLEEP
332        PLAYER_STATE_SIT
333        PLAYER_STATE_STAND
334        PLAYER_STATE_READYUNARMED
335        PLAYER_STATE_WORK
336        PLAYER_STATE_POINT(DNR)
337        PLAYER_STATE_NONE // not used or just no state, just standing there?
338        PLAYER_STATE_STUN
339        PLAYER_STATE_DEAD
340        PLAYER_STATE_KNEEL
341        PLAYER_STATE_USESTANDING
342        PLAYER_STATE_STUN_NOSHEATHE
343        PLAYER_STATE_USESTANDING_NOSHEATHE
344        PLAYER_STATE_WORK_NOSHEATHE
345        PLAYER_STATE_SPELLPRECAST
346        PLAYER_STATE_READYRIFLE
347        PLAYER_STATE_WORK_NOSHEATHE_MINING
348        PLAYER_STATE_WORK_NOSHEATHE_CHOPWOOD
349        PLAYER_STATE_AT_EASE
350        PLAYER_STATE_READY1H
351        PLAYER_STATE_SPELLKNEELSTART
352        PLAYER_STATE_SUBMERGED
353    */
354
355    PLAYER_STATE_NONE              = 0,
356    PLAYER_STATE_SIT               = 1,
357    PLAYER_STATE_SIT_CHAIR         = 2,
358    PLAYER_STATE_SLEEP             = 3,
359    PLAYER_STATE_SIT_LOW_CHAIR     = 4,
360    PLAYER_STATE_SIT_MEDIUM_CHAIR  = 5,
361    PLAYER_STATE_SIT_HIGH_CHAIR    = 6,
362    PLAYER_STATE_DEAD              = 7,
363    PLAYER_STATE_KNEEL             = 8,
364
365    PLAYER_STATE_FORM_ALL          = 0x00FF0000,
366
367    PLAYER_STATE_FLAG_ALWAYS_STAND = 0x01,                  // byte 4
368    PLAYER_STATE_FLAG_CREEP        = 0x02000000,
369    PLAYER_STATE_FLAG_UNTRACKABLE  = 0x04000000,
370    PLAYER_STATE_FLAG_ALL          = 0xFF000000,
371};
372
373enum PlayerFlags
374{
375    PLAYER_FLAGS_GROUP_LEADER   = 0x00000001,
376    PLAYER_FLAGS_AFK            = 0x00000002,
377    PLAYER_FLAGS_DND            = 0x00000004,
378    PLAYER_FLAGS_GM             = 0x00000008,
379    PLAYER_FLAGS_GHOST          = 0x00000010,
380    PLAYER_FLAGS_RESTING        = 0x00000020,
381    PLAYER_FLAGS_FFA_PVP        = 0x00000080,
382    PLAYER_FLAGS_CONTESTED_PVP  = 0x00000100,               // Player has been involved in a PvP combat and will be attacked by contested guards
383    PLAYER_FLAGS_IN_PVP         = 0x00000200,
384    PLAYER_FLAGS_HIDE_HELM      = 0x00000400,
385    PLAYER_FLAGS_HIDE_CLOAK     = 0x00000800,
386    PLAYER_FLAGS_UNK1           = 0x00001000,               // played long time
387    PLAYER_FLAGS_UNK2           = 0x00002000,               // played too long time
388    PLAYER_FLAGS_UNK3           = 0x00008000,               // strange visual effect (2.0.1), looks like PLAYER_FLAGS_GHOST flag
389    PLAYER_FLAGS_SANCTUARY      = 0x00010000,               // player entered sanctuary
390    PLAYER_FLAGS_UNK4           = 0x00020000,               // taxi benchmark mode (on/off) (2.0.1)
391    PLAYER_UNK                  = 0x00040000,               // 2.0.8...
392};
393
394// used for PLAYER__FIELD_KNOWN_TITLES field (uint64), (1<<bit_index) without (-1)
395// can't use enum for uint64 values
396#define PLAYER_TITLE_DISABLED              0x0000000000000000LL
397#define PLAYER_TITLE_NONE                  0x0000000000000001LL
398#define PLAYER_TITLE_PRIVATE               0x0000000000000002LL // 1
399#define PLAYER_TITLE_CORPORAL              0x0000000000000004LL // 2
400#define PLAYER_TITLE_SERGEANT_A            0x0000000000000008LL // 3
401#define PLAYER_TITLE_MASTER_SERGEANT       0x0000000000000010LL // 4
402#define PLAYER_TITLE_SERGEANT_MAJOR        0x0000000000000020LL // 5
403#define PLAYER_TITLE_KNIGHT                0x0000000000000040LL // 6
404#define PLAYER_TITLE_KNIGHT_LIEUTENANT     0x0000000000000080LL // 7
405#define PLAYER_TITLE_KNIGHT_CAPTAIN        0x0000000000000100LL // 8
406#define PLAYER_TITLE_KNIGHT_CHAMPION       0x0000000000000200LL // 9
407#define PLAYER_TITLE_LIEUTENANT_COMMANDER  0x0000000000000400LL // 10
408#define PLAYER_TITLE_COMMANDER             0x0000000000000800LL // 11
409#define PLAYER_TITLE_MARSHAL               0x0000000000001000LL // 12
410#define PLAYER_TITLE_FIELD_MARSHAL         0x0000000000002000LL // 13
411#define PLAYER_TITLE_GRAND_MARSHAL         0x0000000000004000LL // 14
412#define PLAYER_TITLE_SCOUT                 0x0000000000008000LL // 15
413#define PLAYER_TITLE_GRUNT                 0x0000000000010000LL // 16
414#define PLAYER_TITLE_SERGEANT_H            0x0000000000020000LL // 17
415#define PLAYER_TITLE_SENIOR_SERGEANT       0x0000000000040000LL // 18
416#define PLAYER_TITLE_FIRST_SERGEANT        0x0000000000080000LL // 19
417#define PLAYER_TITLE_STONE_GUARD           0x0000000000100000LL // 20
418#define PLAYER_TITLE_BLOOD_GUARD           0x0000000000200000LL // 21
419#define PLAYER_TITLE_LEGIONNAIRE           0x0000000000400000LL // 22
420#define PLAYER_TITLE_CENTURION             0x0000000000800000LL // 23
421#define PLAYER_TITLE_CHAMPION              0x0000000001000000LL // 24
422#define PLAYER_TITLE_LIEUTENANT_GENERAL    0x0000000002000000LL // 25
423#define PLAYER_TITLE_GENERAL               0x0000000004000000LL // 26
424#define PLAYER_TITLE_WARLORD               0x0000000008000000LL // 27
425#define PLAYER_TITLE_HIGH_WARLORD          0x0000000010000000LL // 28
426#define PLAYER_TITLE_GLADIATOR             0x0000000020000000LL // 29
427#define PLAYER_TITLE_DUELIST               0x0000000040000000LL // 30
428#define PLAYER_TITLE_RIVAL                 0x0000000080000000LL // 31
429#define PLAYER_TITLE_CHALLENGER            0x0000000100000000LL // 32
430#define PLAYER_TITLE_SCARAB_LORD           0x0000000200000000LL // 33
431#define PLAYER_TITLE_CONQUEROR             0x0000000400000000LL // 34
432#define PLAYER_TITLE_JUSTICAR              0x0000000800000000LL // 35
433#define PLAYER_TITLE_CHAMPION_OF_THE_NAARU 0x0000001000000000LL // 36
434#define PLAYER_TITLE_MERCILESS_GLADIATOR   0x0000002000000000LL // 37
435#define PLAYER_TITLE_OF_THE_SHATTERED_SUN  0x0000004000000000LL // 38
436#define PLAYER_TITLE_HAND_OF_ADAL          0x0000008000000000LL // 39
437#define PLAYER_TITLE_VENGEFUL_GLADIATOR    0x0000010000000000LL // 40
438
439// used in PLAYER_FIELD_BYTES values
440enum PlayerFieldByteFlags
441{
442    PLAYER_FIELD_BYTE_TRACK_STEALTHED   = 0x00000002,
443    PLAYER_FIELD_BYTE_RELEASE_TIMER     = 0x00000008,       // Display time till auto release spirit
444    PLAYER_FIELD_BYTE_NO_RELEASE_WINDOW = 0x00000010        // Display no "release spirit" window at all
445};
446
447// used in PLAYER_FIELD_BYTES2 values
448enum PlayerFieldByte2Flags
449{
450    PLAYER_FIELD_BYTE2_NONE              = 0x0000,
451    PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW = 0x4000
452};
453
454enum ActivateTaxiReplies
455{
456    ERR_TAXIOK                      = 0,
457    ERR_TAXIUNSPECIFIEDSERVERERROR  = 1,
458    ERR_TAXINOSUCHPATH              = 2,
459    ERR_TAXINOTENOUGHMONEY          = 3,
460    ERR_TAXITOOFARAWAY              = 4,
461    ERR_TAXINOVENDORNEARBY          = 5,
462    ERR_TAXINOTVISITED              = 6,
463    ERR_TAXIPLAYERBUSY              = 7,
464    ERR_TAXIPLAYERALREADYMOUNTED    = 8,
465    ERR_TAXIPLAYERSHAPESHIFTED      = 9,
466    ERR_TAXIPLAYERMOVING            = 10,
467    ERR_TAXISAMENODE                = 11,
468    ERR_TAXINOTSTANDING             = 12
469};
470
471enum LootType
472{
473    LOOT_CORPSE                 = 1,
474    LOOT_SKINNING               = 2,
475    LOOT_FISHING                = 3,
476    LOOT_PICKPOCKETING          = 4,                        // unsupported by client, sending LOOT_SKINNING instead
477    LOOT_DISENCHANTING          = 5,                        // unsupported by client, sending LOOT_SKINNING instead
478    LOOT_PROSPECTING            = 6,                        // unsupported by client, sending LOOT_SKINNING instead
479    LOOT_INSIGNIA               = 7,                        // unsupported by client, sending LOOT_SKINNING instead
480    LOOT_FISHINGHOLE            = 8                         // unsupported by client, sending LOOT_FISHING instead
481};
482
483enum MirrorTimerType
484{
485    FATIGUE_TIMER      = 0,
486    BREATH_TIMER       = 1,
487    FIRE_TIMER         = 2
488};
489
490// 2^n values
491enum PlayerExtraFlags
492{
493    // gm abilities
494    PLAYER_EXTRA_GM_ON              = 0x0001,
495    PLAYER_EXTRA_GM_ACCEPT_TICKETS  = 0x0002,
496    PLAYER_EXTRA_ACCEPT_WHISPERS    = 0x0004,
497    PLAYER_EXTRA_TAXICHEAT          = 0x0008,
498    PLAYER_EXTRA_GM_INVISIBLE       = 0x0010,
499    PLAYER_EXTRA_GM_CHAT            = 0x0020,               // Show GM badge in chat messages
500
501    // other states
502    PLAYER_EXTRA_PVP_DEATH          = 0x0100                // store PvP death status until corpse creating.
503};
504
505// 2^n values
506enum AtLoginFlags
507{
508    AT_LOGIN_NONE          = 0,
509    AT_LOGIN_RENAME        = 1,
510    AT_LOGIN_RESET_SPELLS  = 2,
511    AT_LOGIN_RESET_TALENTS = 4
512};
513
514typedef std::map<uint32, QuestStatusData> QuestStatusMap;
515
516enum QuestSlotOffsets
517{
518    QUEST_ID_OFFSET = 0,
519    QUEST_STATE_OFFSET = 1,
520    QUEST_COUNTS_OFFSET = 2,
521    QUEST_TIME_OFFSET = 3
522};
523
524#define MAX_QUEST_OFFSET 4
525
526enum QuestSlotStateMask
527{
528    QUEST_STATE_NONE     = 0x0000,
529    QUEST_STATE_COMPLETE = 0x0001,
530    QUEST_STATE_FAIL     = 0x0002
531};
532
533class Quest;
534class Spell;
535class Item;
536class WorldSession;
537
538enum PlayerSlots
539{
540    // first slot for item stored (in any way in player m_items data)
541    PLAYER_SLOT_START           = 0,
542    // last+1 slot for item stored (in any way in player m_items data)
543    PLAYER_SLOT_END             = 118,
544    PLAYER_SLOTS_COUNT          = (PLAYER_SLOT_END - PLAYER_SLOT_START)
545};
546
547enum EquipmentSlots
548{
549    EQUIPMENT_SLOT_START        = 0,
550    EQUIPMENT_SLOT_HEAD         = 0,
551    EQUIPMENT_SLOT_NECK         = 1,
552    EQUIPMENT_SLOT_SHOULDERS    = 2,
553    EQUIPMENT_SLOT_BODY         = 3,
554    EQUIPMENT_SLOT_CHEST        = 4,
555    EQUIPMENT_SLOT_WAIST        = 5,
556    EQUIPMENT_SLOT_LEGS         = 6,
557    EQUIPMENT_SLOT_FEET         = 7,
558    EQUIPMENT_SLOT_WRISTS       = 8,
559    EQUIPMENT_SLOT_HANDS        = 9,
560    EQUIPMENT_SLOT_FINGER1      = 10,
561    EQUIPMENT_SLOT_FINGER2      = 11,
562    EQUIPMENT_SLOT_TRINKET1     = 12,
563    EQUIPMENT_SLOT_TRINKET2     = 13,
564    EQUIPMENT_SLOT_BACK         = 14,
565    EQUIPMENT_SLOT_MAINHAND     = 15,
566    EQUIPMENT_SLOT_OFFHAND      = 16,
567    EQUIPMENT_SLOT_RANGED       = 17,
568    EQUIPMENT_SLOT_TABARD       = 18,
569    EQUIPMENT_SLOT_END          = 19
570};
571
572enum InventorySlots
573{
574    INVENTORY_SLOT_BAG_0        = 255,
575    INVENTORY_SLOT_BAG_START    = 19,
576    INVENTORY_SLOT_BAG_1        = 19,
577    INVENTORY_SLOT_BAG_2        = 20,
578    INVENTORY_SLOT_BAG_3        = 21,
579    INVENTORY_SLOT_BAG_4        = 22,
580    INVENTORY_SLOT_BAG_END      = 23,
581
582    INVENTORY_SLOT_ITEM_START   = 23,
583    INVENTORY_SLOT_ITEM_1       = 23,
584    INVENTORY_SLOT_ITEM_2       = 24,
585    INVENTORY_SLOT_ITEM_3       = 25,
586    INVENTORY_SLOT_ITEM_4       = 26,
587    INVENTORY_SLOT_ITEM_5       = 27,
588    INVENTORY_SLOT_ITEM_6       = 28,
589    INVENTORY_SLOT_ITEM_7       = 29,
590    INVENTORY_SLOT_ITEM_8       = 30,
591    INVENTORY_SLOT_ITEM_9       = 31,
592    INVENTORY_SLOT_ITEM_10      = 32,
593    INVENTORY_SLOT_ITEM_11      = 33,
594    INVENTORY_SLOT_ITEM_12      = 34,
595    INVENTORY_SLOT_ITEM_13      = 35,
596    INVENTORY_SLOT_ITEM_14      = 36,
597    INVENTORY_SLOT_ITEM_15      = 37,
598    INVENTORY_SLOT_ITEM_16      = 38,
599    INVENTORY_SLOT_ITEM_END     = 39
600};
601
602enum BankSlots
603{
604    BANK_SLOT_ITEM_START        = 39,
605    BANK_SLOT_ITEM_1            = 39,
606    BANK_SLOT_ITEM_2            = 40,
607    BANK_SLOT_ITEM_3            = 41,
608    BANK_SLOT_ITEM_4            = 42,
609    BANK_SLOT_ITEM_5            = 43,
610    BANK_SLOT_ITEM_6            = 44,
611    BANK_SLOT_ITEM_7            = 45,
612    BANK_SLOT_ITEM_8            = 46,
613    BANK_SLOT_ITEM_9            = 47,
614    BANK_SLOT_ITEM_10           = 48,
615    BANK_SLOT_ITEM_11           = 49,
616    BANK_SLOT_ITEM_12           = 50,
617    BANK_SLOT_ITEM_13           = 51,
618    BANK_SLOT_ITEM_14           = 52,
619    BANK_SLOT_ITEM_15           = 53,
620    BANK_SLOT_ITEM_16           = 54,
621    BANK_SLOT_ITEM_17           = 55,
622    BANK_SLOT_ITEM_18           = 56,
623    BANK_SLOT_ITEM_19           = 57,
624    BANK_SLOT_ITEM_20           = 58,
625    BANK_SLOT_ITEM_21           = 59,
626    BANK_SLOT_ITEM_22           = 60,
627    BANK_SLOT_ITEM_23           = 61,
628    BANK_SLOT_ITEM_24           = 62,
629    BANK_SLOT_ITEM_25           = 63,
630    BANK_SLOT_ITEM_26           = 64,
631    BANK_SLOT_ITEM_27           = 65,
632    BANK_SLOT_ITEM_28           = 66,
633    BANK_SLOT_ITEM_END          = 67,
634
635    BANK_SLOT_BAG_START         = 67,
636    BANK_SLOT_BAG_1             = 67,
637    BANK_SLOT_BAG_2             = 68,
638    BANK_SLOT_BAG_3             = 69,
639    BANK_SLOT_BAG_4             = 70,
640    BANK_SLOT_BAG_5             = 71,
641    BANK_SLOT_BAG_6             = 72,
642    BANK_SLOT_BAG_7             = 73,
643    BANK_SLOT_BAG_END           = 74
644};
645
646enum BuyBackSlots
647{
648    // stored in m_buybackitems
649    BUYBACK_SLOT_START          = 74,
650    BUYBACK_SLOT_1              = 74,
651    BUYBACK_SLOT_2              = 75,
652    BUYBACK_SLOT_3              = 76,
653    BUYBACK_SLOT_4              = 77,
654    BUYBACK_SLOT_5              = 78,
655    BUYBACK_SLOT_6              = 79,
656    BUYBACK_SLOT_7              = 80,
657    BUYBACK_SLOT_8              = 81,
658    BUYBACK_SLOT_9              = 82,
659    BUYBACK_SLOT_10             = 83,
660    BUYBACK_SLOT_11             = 84,
661    BUYBACK_SLOT_12             = 85,
662    BUYBACK_SLOT_END            = 86
663};
664
665enum KeyRingSlots
666{
667    KEYRING_SLOT_START          = 86,
668    KEYRING_SLOT_END            = 118
669};
670
671struct ItemPosCount
672{
673    ItemPosCount(uint16 _pos, uint8 _count) : pos(_pos), count(_count) {}
674    bool isContainedIn(std::vector<ItemPosCount> const& vec) const;
675    uint16 pos;
676    uint8 count;
677};
678typedef std::vector<ItemPosCount> ItemPosCountVec;
679
680enum SwitchWeapon
681{
682    DEFAULT_SWITCH_WEAPON       = 1500,                     //cooldown in ms
683    ROGUE_SWITCH_WEAPON         = 1000
684};
685
686enum TradeSlots
687{
688    TRADE_SLOT_COUNT            = 7,
689    TRADE_SLOT_TRADED_COUNT     = 6,
690    TRADE_SLOT_NONTRADED        = 6
691};
692
693enum TransferAbortReason
694{
695    TRANSFER_ABORT_MAX_PLAYERS          = 0x0001,           // Transfer Aborted: instance is full
696    TRANSFER_ABORT_NOT_FOUND            = 0x0002,           // Transfer Aborted: instance not found
697    TRANSFER_ABORT_TOO_MANY_INSTANCES   = 0x0003,           // You have entered too many instances recently.
698    TRANSFER_ABORT_ZONE_IN_COMBAT       = 0x0005,           // Unable to zone in while an encounter is in progress.
699    TRANSFER_ABORT_INSUF_EXPAN_LVL1     = 0x0106,           // You must have TBC expansion installed to access this area.
700    TRANSFER_ABORT_DIFFICULTY1          = 0x0007,           // Normal difficulty mode is not available for %s.
701    TRANSFER_ABORT_DIFFICULTY2          = 0x0107,           // Heroic difficulty mode is not available for %s.
702    TRANSFER_ABORT_DIFFICULTY3          = 0x0207            // Epic difficulty mode is not available for %s.
703};
704
705enum InstanceResetWarningType
706{
707    RAID_INSTANCE_WARNING_HOURS     = 1,                    // WARNING! %s is scheduled to reset in %d hour(s).
708    RAID_INSTANCE_WARNING_MIN       = 2,                    // WARNING! %s is scheduled to reset in %d minute(s)!
709    RAID_INSTANCE_WARNING_MIN_SOON  = 3,                    // WARNING! %s is scheduled to reset in %d minute(s). Please exit the zone or you will be returned to your bind location!
710    RAID_INSTANCE_WELCOME           = 4                     // Welcome to %s. This raid instance is scheduled to reset in %s.
711};
712
713struct MovementInfo
714{
715    // common
716    //uint32  flags;
717    uint8   unk1;
718    uint32  time;
719    float   x, y, z, o;
720    // transport
721    uint64  t_guid;
722    float   t_x, t_y, t_z, t_o;
723    uint32  t_time;
724    // swimming and unk
725    float   s_pitch;
726    // last fall time
727    uint32  fallTime;
728    // jumping
729    float   j_unk, j_sinAngle, j_cosAngle, j_xyspeed;
730    // spline
731    float   u_unk1;
732
733    MovementInfo()
734    {
735        //flags =
736        time = t_time = fallTime = 0;
737        unk1 = 0;
738        x = y = z = o = t_x = t_y = t_z = t_o = s_pitch = j_unk = j_sinAngle = j_cosAngle = j_xyspeed = u_unk1 = 0.0f;
739        t_guid = 0;
740    }
741
742    /*void SetMovementFlags(uint32 _flags)
743    {
744        flags = _flags;
745    }*/
746};
747
748// flags that use in movement check for example at spell casting
749MovementFlags const movementFlagsMask = MovementFlags(
750    MOVEMENTFLAG_FORWARD |MOVEMENTFLAG_BACKWARD  |MOVEMENTFLAG_STRAFE_LEFT|MOVEMENTFLAG_STRAFE_RIGHT|
751    MOVEMENTFLAG_PITCH_UP|MOVEMENTFLAG_PITCH_DOWN|MOVEMENTFLAG_FLY_UNK1    |
752    MOVEMENTFLAG_JUMPING |MOVEMENTFLAG_FALLING   |MOVEMENTFLAG_FLY_UP      |
753    MOVEMENTFLAG_FLYING  |MOVEMENTFLAG_SPLINE
754);
755
756MovementFlags const movementOrTurningFlagsMask = MovementFlags(
757    movementFlagsMask | MOVEMENTFLAG_LEFT | MOVEMENTFLAG_RIGHT
758);
759class InstanceSave;
760
761enum RestType
762{
763    REST_TYPE_NO        = 0,
764    REST_TYPE_IN_TAVERN = 1,
765    REST_TYPE_IN_CITY   = 2
766};
767
768enum DuelCompleteType
769{
770    DUEL_INTERUPTED = 0,
771    DUEL_WON        = 1,
772    DUEL_FLED       = 2
773};
774
775enum TeleportToOptions
776{
777    TELE_TO_GM_MODE             = 0x01,
778    TELE_TO_NOT_LEAVE_TRANSPORT = 0x02,
779    TELE_TO_NOT_LEAVE_COMBAT    = 0x04,
780    TELE_TO_NOT_UNSUMMON_PET    = 0x08,
781    TELE_TO_SPELL               = 0x10,
782};
783
784/// Type of environmental damages
785enum EnviromentalDamage
786{
787    DAMAGE_EXHAUSTED = 0,
788    DAMAGE_DROWNING  = 1,
789    DAMAGE_FALL      = 2,
790    DAMAGE_LAVA      = 3,
791    DAMAGE_SLIME     = 4,
792    DAMAGE_FIRE      = 5,
793    DAMAGE_FALL_TO_VOID = 6                                 // custom case for fall without durability loss
794};
795
796// used at player loading query list preparing, and later result selection
797enum PlayerLoginQueryIndex
798{
799    PLAYER_LOGIN_QUERY_LOADFROM                 = 0,
800    PLAYER_LOGIN_QUERY_LOADGROUP                = 1,
801    PLAYER_LOGIN_QUERY_LOADBOUNDINSTANCES       = 2,
802    PLAYER_LOGIN_QUERY_LOADAURAS                = 3,
803    PLAYER_LOGIN_QUERY_LOADSPELLS               = 4,
804    PLAYER_LOGIN_QUERY_LOADQUESTSTATUS          = 5,
805    PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS     = 6,
806    PLAYER_LOGIN_QUERY_LOADTUTORIALS            = 7,        // common for all characters for some account at specific realm
807    PLAYER_LOGIN_QUERY_LOADREPUTATION           = 8,
808    PLAYER_LOGIN_QUERY_LOADINVENTORY            = 9,
809    PLAYER_LOGIN_QUERY_LOADACTIONS              = 10,
810    PLAYER_LOGIN_QUERY_LOADMAILCOUNT            = 11,
811    PLAYER_LOGIN_QUERY_LOADMAILDATE             = 12,
812    PLAYER_LOGIN_QUERY_LOADSOCIALLIST           = 13,
813    PLAYER_LOGIN_QUERY_LOADHOMEBIND             = 14,
814    PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS       = 15,
815    PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES        = 16,
816    PLAYER_LOGIN_QUERY_LOADGUILD                = 17,
817};
818
819#define MAX_PLAYER_LOGIN_QUERY                    18
820
821// Player summoning auto-decline time (in secs)
822#define MAX_PLAYER_SUMMON_DELAY                   (2*MINUTE)
823#define MAX_MONEY_AMOUNT                       (0x7FFFFFFF-1)
824
825struct InstancePlayerBind
826{
827    InstanceSave *save;
828    bool perm;
829    /* permanent PlayerInstanceBinds are created in Raid/Heroic instances for players
830       that aren't already permanently bound when they are inside when a boss is killed
831       or when they enter an instance that the group leader is permanently bound to. */
832    InstancePlayerBind() : save(NULL), perm(false) {}
833};
834
835class MANGOS_DLL_SPEC PlayerTaxi
836{
837    public:
838        PlayerTaxi();
839        ~PlayerTaxi() {}
840        // Nodes
841        void InitTaxiNodesForLevel(uint32 race, uint32 level);
842        void LoadTaxiMask(const char* data);
843        void SaveTaxiMask(const char* data);
844
845        uint32 GetTaximask( uint8 index ) const { return m_taximask[index]; }
846        bool IsTaximaskNodeKnown(uint32 nodeidx) const
847        {
848            uint8  field   = uint8((nodeidx - 1) / 32);
849            uint32 submask = 1<<((nodeidx-1)%32);
850            return (m_taximask[field] & submask) == submask;
851        }
852        bool SetTaximaskNode(uint32 nodeidx)
853        {
854            uint8  field   = uint8((nodeidx - 1) / 32);
855            uint32 submask = 1<<((nodeidx-1)%32);
856            if ((m_taximask[field] & submask) != submask )
857            {
858                m_taximask[field] |= submask;
859                return true;
860            }
861            else
862                return false;
863        }
864        void AppendTaximaskTo(ByteBuffer& data,bool all);
865
866        // Destinations
867        bool LoadTaxiDestinationsFromString(std::string values);
868        std::string SaveTaxiDestinationsToString();
869
870        void ClearTaxiDestinations() { m_TaxiDestinations.clear(); }
871        void AddTaxiDestination(uint32 dest) { m_TaxiDestinations.push_back(dest); }
872        uint32 GetTaxiSource() const { return m_TaxiDestinations.empty() ? 0 : m_TaxiDestinations.front(); }
873        uint32 GetTaxiDestination() const { return m_TaxiDestinations.size() < 2 ? 0 : m_TaxiDestinations[1]; }
874        uint32 GetCurrentTaxiPath() const;
875        uint32 NextTaxiDestination()
876        {
877            m_TaxiDestinations.pop_front();
878            return GetTaxiDestination();
879        }
880        bool empty() const { return m_TaxiDestinations.empty(); }
881    private:
882        TaxiMask m_taximask;
883        std::deque<uint32> m_TaxiDestinations;
884};
885
886class MANGOS_DLL_SPEC Player : public Unit
887{
888    friend class WorldSession;
889    friend void Item::AddToUpdateQueueOf(Player *player);
890    friend void Item::RemoveFromUpdateQueueOf(Player *player);
891    public:
892        explicit Player (WorldSession *session);
893        ~Player ( );
894
895        void CleanupsBeforeDelete();
896
897        static UpdateMask updateVisualBits;
898        static void InitVisibleBits();
899
900        void AddToWorld();
901        void RemoveFromWorld();
902
903        bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options = 0);
904
905        bool TeleportTo(WorldLocation const &loc, uint32 options = 0)
906        {
907            return TeleportTo(loc.mapid, loc.x, loc.y, loc.z, options);
908        }
909
910        void SetSummonPoint(uint32 mapid, float x, float y, float z)
911        {
912            m_summon_expire = time(NULL) + MAX_PLAYER_SUMMON_DELAY;
913            m_summon_mapid = mapid;
914            m_summon_x = x;
915            m_summon_y = y;
916            m_summon_z = z;
917        }
918        void SummonIfPossible(bool agree);
919
920        bool Create( uint32 guidlow, std::string name, uint8 race, uint8 class_, uint8 gender, uint8 skin, uint8 face, uint8 hairStyle, uint8 hairColor, uint8 facialHair, uint8 outfitId );
921
922        void Update( uint32 time );
923
924        void BuildEnumData( QueryResult * result,  WorldPacket * p_data );
925
926        void SetInWater(bool apply);
927
928        bool IsInWater() const { return m_isInWater; }
929        bool IsUnderWater() const;
930
931        void SendInitialPacketsBeforeAddToMap();
932        void SendInitialPacketsAfterAddToMap();
933        void SendTransferAborted(uint32 mapid, uint16 reason);
934        void SendInstanceResetWarning(uint32 mapid, uint32 time);
935
936        bool CanInteractWithNPCs(bool alive = true) const;
937
938        bool ToggleAFK();
939        bool ToggleDND();
940        bool isAFK() const { return HasFlag(PLAYER_FLAGS,PLAYER_FLAGS_AFK); };
941        bool isDND() const { return HasFlag(PLAYER_FLAGS,PLAYER_FLAGS_DND); };
942        uint8 chatTag() const;
943        std::string afkMsg;
944        std::string dndMsg;
945
946        PlayerSocial *GetSocial() { return m_social; }
947
948        PlayerTaxi m_taxi;
949        void InitTaxiNodesForLevel() { m_taxi.InitTaxiNodesForLevel(getRace(),getLevel()); }
950        bool ActivateTaxiPathTo(std::vector<uint32> const& nodes, uint32 mount_id = 0 , Creature* npc = NULL);
951                                                            // mount_id can be used in scripting calls
952        bool isAcceptTickets() const { return GetSession()->GetSecurity() >= SEC_GAMEMASTER && (m_ExtraFlags & PLAYER_EXTRA_GM_ACCEPT_TICKETS); }
953        void SetAcceptTicket(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_GM_ACCEPT_TICKETS; else m_ExtraFlags &= ~PLAYER_EXTRA_GM_ACCEPT_TICKETS; }
954        bool isAcceptWhispers() const { return m_ExtraFlags & PLAYER_EXTRA_ACCEPT_WHISPERS; }
955        void SetAcceptWhispers(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_ACCEPT_WHISPERS; else m_ExtraFlags &= ~PLAYER_EXTRA_ACCEPT_WHISPERS; }
956        bool isGameMaster() const { return m_ExtraFlags & PLAYER_EXTRA_GM_ON; }
957        void SetGameMaster(bool on);
958        bool isGMChat() const { return GetSession()->GetSecurity() >= SEC_MODERATOR && (m_ExtraFlags & PLAYER_EXTRA_GM_CHAT); }
959        void SetGMChat(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_GM_CHAT; else m_ExtraFlags &= ~PLAYER_EXTRA_GM_CHAT; }
960        bool isTaxiCheater() const { return m_ExtraFlags & PLAYER_EXTRA_TAXICHEAT; }
961        void SetTaxiCheater(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_TAXICHEAT; else m_ExtraFlags &= ~PLAYER_EXTRA_TAXICHEAT; }
962        bool isGMVisible() const { return !(m_ExtraFlags & PLAYER_EXTRA_GM_INVISIBLE); }
963        void SetGMVisible(bool on);
964        void SetPvPDeath(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_PVP_DEATH; else m_ExtraFlags &= ~PLAYER_EXTRA_PVP_DEATH; }
965
966        void GiveXP(uint32 xp, Unit* victim);
967        void GiveLevel(uint32 level);
968        void InitStatsForLevel(bool reapplyMods = false);
969
970        // Played Time Stuff
971        time_t m_logintime;
972        time_t m_Last_tick;
973        uint32 m_Played_time[2];
974        uint32 GetTotalPlayedTime() { return m_Played_time[0]; };
975        uint32 GetLevelPlayedTime() { return m_Played_time[1]; };
976
977        void setDeathState(DeathState s);                   // overwrite Unit::setDeathState
978
979        void InnEnter (int time,uint32 mapid, float x,float y,float z)
980        {
981            inn_pos_mapid = mapid;
982            inn_pos_x = x;
983            inn_pos_y = y;
984            inn_pos_z = z;
985            time_inn_enter = time;
986        };
987
988        float GetRestBonus() const { return m_rest_bonus; };
989        void SetRestBonus(float rest_bonus_new);
990
991        RestType GetRestType() const { return rest_type; };
992        void SetRestType(RestType n_r_type) { rest_type = n_r_type; };
993
994        uint32 GetInnPosMapId() const { return inn_pos_mapid; };
995        float GetInnPosX() const { return inn_pos_x; };
996        float GetInnPosY() const { return inn_pos_y; };
997        float GetInnPosZ() const { return inn_pos_z; };
998
999        int GetTimeInnEnter() const { return time_inn_enter; };
1000        void UpdateInnerTime (int time) { time_inn_enter = time; };
1001
1002        void RemovePet(Pet* pet, PetSaveMode mode, bool returnreagent = false);
1003        void RemoveMiniPet();
1004        Pet* GetMiniPet();
1005        void SetMiniPet(Pet* pet) { m_miniPet = pet->GetGUID(); }
1006        void RemoveGuardians();
1007        bool HasGuardianWithEntry(uint32 entry);
1008        void AddGuardian(Pet* pet) { m_guardianPets.insert(pet->GetGUID()); }
1009        GuardianPetList const& GetGuardians() const { return m_guardianPets; }
1010        void Uncharm();
1011
1012        void Say(std::string text, const uint32 language);
1013        void Yell(std::string text, const uint32 language);
1014        void TextEmote(std::string text);
1015        void Whisper(std::string text, const uint32 language,uint64 receiver);
1016        void BuildPlayerChat(WorldPacket *data, uint8 msgtype, std::string text, uint32 language) const;
1017
1018        /*********************************************************/
1019        /***                    STORAGE SYSTEM                 ***/
1020        /*********************************************************/
1021
1022        void SetVirtualItemSlot( uint8 i, Item* item);
1023        void SetSheath( uint32 sheathed );
1024        uint8 FindEquipSlot( ItemPrototype const* proto, uint32 slot, bool swap ) const;
1025        uint32 GetItemCount( uint32 item, bool inBankAlso = false, Item* skipItem = NULL ) const;
1026        Item* GetItemByGuid( uint64 guid ) const;
1027        Item* GetItemByPos( uint16 pos ) const;
1028        Item* GetItemByPos( uint8 bag, uint8 slot ) const;
1029        Item* GetWeaponForAttack(WeaponAttackType attackType, bool useable = false) const;
1030        Item* GetShield(bool useable = false) const;
1031        static uint32 GetAttackBySlot( uint8 slot );        // MAX_ATTACK if not weapon slot
1032        std::vector<Item *> &GetItemUpdateQueue() { return m_itemUpdateQueue; }
1033        static bool IsInventoryPos( uint16 pos ) { return IsInventoryPos(pos >> 8,pos & 255); }
1034        static bool IsInventoryPos( uint8 bag, uint8 slot );
1035        static bool IsEquipmentPos( uint16 pos ) { return IsEquipmentPos(pos >> 8,pos & 255); }
1036        static bool IsEquipmentPos( uint8 bag, uint8 slot );
1037        static bool IsBagPos( uint16 pos );
1038        static bool IsBankPos( uint16 pos ) { return IsBankPos(pos >> 8,pos & 255); }
1039        static bool IsBankPos( uint8 bag, uint8 slot );
1040        bool HasBankBagSlot( uint8 slot ) const;
1041        bool HasItemCount( uint32 item, uint32 count, bool inBankAlso = false ) const;
1042        bool HasItemFitToSpellReqirements(SpellEntry const* spellInfo, Item const* ignoreItem = NULL);
1043        Item* GetItemOrItemWithGemEquipped( uint32 item ) const;
1044        uint8 CanTakeMoreSimilarItems(Item* pItem) const { return _CanTakeMoreSimilarItems(pItem->GetEntry(),pItem->GetCount(),pItem); }
1045        uint8 CanTakeMoreSimilarItems(uint32 entry, uint32 count) const { return _CanTakeMoreSimilarItems(entry,count,NULL); }
1046        uint8 CanStoreNewItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 item, uint32 count, uint32* no_space_count = NULL ) const
1047        {
1048            return _CanStoreItem(bag, slot, dest, item, count, NULL, false, no_space_count );
1049        }
1050        uint8 CanStoreItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, Item *pItem, bool swap = false ) const
1051        {
1052            if(!pItem)
1053                return EQUIP_ERR_ITEM_NOT_FOUND;
1054            uint32 count = pItem->GetCount();
1055            return _CanStoreItem( bag, slot, dest, pItem->GetEntry(), count, pItem, swap, NULL );
1056
1057        }
1058        uint8 CanStoreItems( Item **pItem,int count) const;
1059        uint8 CanEquipNewItem( uint8 slot, uint16 &dest, uint32 item, uint32 count, bool swap ) const;
1060        uint8 CanEquipItem( uint8 slot, uint16 &dest, Item *pItem, bool swap, bool not_loading = true ) const;
1061        uint8 CanUnequipItems( uint32 item, uint32 count ) const;
1062        uint8 CanUnequipItem( uint16 src, bool swap ) const;
1063        uint8 CanBankItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, Item *pItem, bool swap, bool not_loading = true ) const;
1064        uint8 CanUseItem( Item *pItem, bool not_loading = true ) const;
1065        bool HasItemTotemCategory( uint32 TotemCategory ) const;
1066        bool CanUseItem( ItemPrototype const *pItem );
1067        uint8 CanUseAmmo( uint32 item ) const;
1068        Item* StoreNewItem( ItemPosCountVec const& pos, uint32 item, bool update,int32 randomPropertyId = 0 );
1069        Item* StoreItem( ItemPosCountVec const& pos, Item *pItem, bool update );
1070        Item* EquipNewItem( uint16 pos, uint32 item, uint32 count, bool update );
1071        Item* EquipItem( uint16 pos, Item *pItem, bool update );
1072        void AutoUnequipOffhandIfNeed();
1073
1074        uint8 _CanTakeMoreSimilarItems(uint32 entry, uint32 count, Item* pItem, uint32* no_space_count = NULL) const;
1075        uint8 _CanStoreItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 entry, uint32 count, Item *pItem = NULL, bool swap = false, uint32* no_space_count = NULL ) const;
1076
1077        void ApplyEquipCooldown( Item * pItem );
1078        void SetAmmo( uint32 item );
1079        void RemoveAmmo();
1080        float GetAmmoDPS() const { return m_ammoDPS; }
1081        bool CheckAmmoCompatibility(const ItemPrototype *ammo_proto) const;
1082        void QuickEquipItem( uint16 pos, Item *pItem);
1083        void VisualizeItem( uint8 slot, Item *pItem);
1084        void SetVisibleItemSlot(uint8 slot, Item *pItem);
1085        Item* BankItem( ItemPosCountVec const& dest, Item *pItem, bool update )
1086        {
1087            return StoreItem( dest, pItem, update);
1088        }
1089        Item* BankItem( uint16 pos, Item *pItem, bool update );
1090        void RemoveItem( uint8 bag, uint8 slot, bool update );
1091        void MoveItemFromInventory(uint8 bag, uint8 slot, bool update);
1092                                                            // in trade, auction, guild bank, mail....
1093        void MoveItemToInventory(ItemPosCountVec const& dest, Item* pItem, bool update, bool in_characterInventoryDB = false);
1094                                                            // in trade, guild bank, mail....
1095        void RemoveItemDependentAurasAndCasts( Item * pItem );
1096        void DestroyItem( uint8 bag, uint8 slot, bool update );
1097        void DestroyItemCount( uint32 item, uint32 count, bool update, bool unequip_check = false);
1098        void DestroyItemCount( Item* item, uint32& count, bool update );
1099        void DestroyConjuredItems( bool update );
1100        void DestroyZoneLimitedItem( bool update, uint32 new_zone );
1101        void SplitItem( uint16 src, uint16 dst, uint32 count );
1102        void SwapItem( uint16 src, uint16 dst );
1103        void AddItemToBuyBackSlot( Item *pItem );
1104        Item* GetItemFromBuyBackSlot( uint32 slot );
1105        void RemoveItemFromBuyBackSlot( uint32 slot, bool del );
1106        uint32 GetMaxKeyringSize() const { return KEYRING_SLOT_END-KEYRING_SLOT_START; }
1107        void SendEquipError( uint8 msg, Item* pItem, Item *pItem2 );
1108        void SendBuyError( uint8 msg, Creature* pCreature, uint32 item, uint32 param );
1109        void SendSellError( uint8 msg, Creature* pCreature, uint64 guid, uint32 param );
1110        void AddWeaponProficiency(uint32 newflag) { m_WeaponProficiency |= newflag; }
1111        void AddArmorProficiency(uint32 newflag) { m_ArmorProficiency |= newflag; }
1112        uint32 GetWeaponProficiency() const { return m_WeaponProficiency; }
1113        uint32 GetArmorProficiency() const { return m_ArmorProficiency; }
1114        bool IsInFeralForm() const { return m_form == FORM_CAT || m_form == FORM_BEAR || m_form == FORM_DIREBEAR; }
1115        bool IsUseEquipedWeapon( bool mainhand ) const
1116        {
1117            // disarm applied only to mainhand weapon
1118            return !IsInFeralForm() && (!mainhand || !HasFlag(UNIT_FIELD_FLAGS,UNIT_FLAG_DISARMED) );
1119        }
1120        void SendNewItem( Item *item, uint32 count, bool received, bool created, bool broadcast = false );
1121        bool BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint64 bagguid, uint8 slot);
1122
1123        float GetReputationPriceDiscount( Creature const* pCreature ) const;
1124        Player* GetTrader() const { return pTrader; }
1125        void ClearTrade();
1126        void TradeCancel(bool sendback);
1127        uint16 GetItemPosByTradeSlot(uint32 slot) const { return tradeItems[slot]; }
1128
1129        void UpdateEnchantTime(uint32 time);
1130        void UpdateItemDuration(uint32 time, bool realtimeonly=false);
1131        void AddEnchantmentDurations(Item *item);
1132        void RemoveEnchantmentDurations(Item *item);
1133        void RemoveAllEnchantments(EnchantmentSlot slot);
1134        void AddEnchantmentDuration(Item *item,EnchantmentSlot slot,uint32 duration);
1135        void ApplyEnchantment(Item *item,EnchantmentSlot slot,bool apply, bool apply_dur = true, bool ignore_condition = false);
1136        void ApplyEnchantment(Item *item,bool apply);
1137        void SendEnchantmentDurations();
1138        void AddItemDurations(Item *item);
1139        void RemoveItemDurations(Item *item);
1140        void SendItemDurations();
1141        void LoadCorpse();
1142        void LoadPet();
1143
1144        uint32 m_stableSlots;
1145
1146        /*********************************************************/
1147        /***                    QUEST SYSTEM                   ***/
1148        /*********************************************************/
1149
1150        void PrepareQuestMenu( uint64 guid );
1151        void SendPreparedQuest( uint64 guid );
1152        bool IsActiveQuest( uint32 quest_id ) const;
1153        Quest const *GetNextQuest( uint64 guid, Quest const *pQuest );
1154        bool CanSeeStartQuest( Quest const *pQuest );
1155        bool CanTakeQuest( Quest const *pQuest, bool msg );
1156        bool CanAddQuest( Quest const *pQuest, bool msg );
1157        bool CanCompleteQuest( uint32 quest_id );
1158        bool CanCompleteRepeatableQuest(Quest const *pQuest);
1159        bool CanRewardQuest( Quest const *pQuest, bool msg );
1160        bool CanRewardQuest( Quest const *pQuest, uint32 reward, bool msg );
1161        void AddQuest( Quest const *pQuest, Object *questGiver );
1162        void CompleteQuest( uint32 quest_id );
1163        void IncompleteQuest( uint32 quest_id );
1164        void RewardQuest( Quest const *pQuest, uint32 reward, Object* questGiver, bool announce = true );
1165        void FailQuest( uint32 quest_id );
1166        void FailTimedQuest( uint32 quest_id );
1167        bool SatisfyQuestSkillOrClass( Quest const* qInfo, bool msg );
1168        bool SatisfyQuestLevel( Quest const* qInfo, bool msg );
1169        bool SatisfyQuestLog( bool msg );
1170        bool SatisfyQuestPreviousQuest( Quest const* qInfo, bool msg );
1171        bool SatisfyQuestRace( Quest const* qInfo, bool msg );
1172        bool SatisfyQuestReputation( Quest const* qInfo, bool msg );
1173        bool SatisfyQuestStatus( Quest const* qInfo, bool msg );
1174        bool SatisfyQuestTimed( Quest const* qInfo, bool msg );
1175        bool SatisfyQuestExclusiveGroup( Quest const* qInfo, bool msg );
1176        bool SatisfyQuestNextChain( Quest const* qInfo, bool msg );
1177        bool SatisfyQuestPrevChain( Quest const* qInfo, bool msg );
1178        bool SatisfyQuestDay( Quest const* qInfo, bool msg );
1179        bool GiveQuestSourceItem( Quest const *pQuest );
1180        bool TakeQuestSourceItem( uint32 quest_id, bool msg );
1181        bool GetQuestRewardStatus( uint32 quest_id ) const;
1182        QuestStatus GetQuestStatus( uint32 quest_id ) const;
1183        void SetQuestStatus( uint32 quest_id, QuestStatus status );
1184
1185        void SetDailyQuestStatus( uint32 quest_id );
1186        void ResetDailyQuestStatus();
1187
1188        uint16 FindQuestSlot( uint32 quest_id ) const;
1189        uint32 GetQuestSlotQuestId(uint16 slot) const { return GetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_ID_OFFSET); }
1190        uint32 GetQuestSlotState(uint16 slot)   const { return GetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_STATE_OFFSET); }
1191        uint32 GetQuestSlotCounters(uint16 slot)const { return GetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_COUNTS_OFFSET); }
1192        uint8 GetQuestSlotCounter(uint16 slot,uint8 counter) const { return GetByteValue(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_COUNTS_OFFSET,counter); }
1193        uint32 GetQuestSlotTime(uint16 slot)    const { return GetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_TIME_OFFSET); }
1194        void SetQuestSlot(uint16 slot,uint32 quest_id, uint32 timer = 0)
1195        {
1196            SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_ID_OFFSET,quest_id);
1197            SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_STATE_OFFSET,0);
1198            SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_COUNTS_OFFSET,0);
1199            SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_TIME_OFFSET,timer);
1200        }
1201        void SetQuestSlotCounter(uint16 slot,uint8 counter,uint8 count) { SetByteValue(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_COUNTS_OFFSET,counter,count); }
1202        void SetQuestSlotState(uint16 slot,uint32 state) { SetFlag(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_STATE_OFFSET,state); }
1203        void RemoveQuestSlotState(uint16 slot,uint32 state) { RemoveFlag(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_STATE_OFFSET,state); }
1204        void SetQuestSlotTimer(uint16 slot,uint32 timer) { SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_TIME_OFFSET,timer); }
1205        void SwapQuestSlot(uint16 slot1,uint16 slot2)
1206        {
1207            for (int i = 0; i < MAX_QUEST_OFFSET ; ++i )
1208            {
1209                uint32 temp1 = GetUInt32Value(PLAYER_QUEST_LOG_1_1 + MAX_QUEST_OFFSET *slot1 + i);
1210                uint32 temp2 = GetUInt32Value(PLAYER_QUEST_LOG_1_1 + MAX_QUEST_OFFSET *slot2 + i);
1211
1212                SetUInt32Value(PLAYER_QUEST_LOG_1_1 + MAX_QUEST_OFFSET *slot1 + i, temp2);
1213                SetUInt32Value(PLAYER_QUEST_LOG_1_1 + MAX_QUEST_OFFSET *slot2 + i, temp1);
1214            }
1215        }
1216        uint32 GetReqKillOrCastCurrentCount(uint32 quest_id, int32 entry);
1217        void AdjustQuestReqItemCount( Quest const* pQuest );
1218        void AreaExploredOrEventHappens( uint32 questId );
1219        void GroupEventHappens( uint32 questId, WorldObject const* pEventObject );
1220        void ItemAddedQuestCheck( uint32 entry, uint32 count );
1221        void ItemRemovedQuestCheck( uint32 entry, uint32 count );
1222        void KilledMonster( uint32 entry, uint64 guid );
1223        void CastedCreatureOrGO( uint32 entry, uint64 guid, uint32 spell_id );
1224        void TalkedToCreature( uint32 entry, uint64 guid );
1225        void MoneyChanged( uint32 value );
1226        bool HasQuestForItem( uint32 itemid ) const;
1227        bool HasQuestForGO(int32 GOId);
1228        void UpdateForQuestsGO();
1229        bool CanShareQuest(uint32 quest_id) const;
1230
1231        void SendQuestComplete( uint32 quest_id );
1232        void SendQuestReward( Quest const *pQuest, uint32 XP, Object* questGiver );
1233        void SendQuestFailed( uint32 quest_id );
1234        void SendQuestTimerFailed( uint32 quest_id );
1235        void SendCanTakeQuestResponse( uint32 msg );
1236        void SendPushToPartyResponse( Player *pPlayer, uint32 msg );
1237        void SendQuestUpdateAddItem( Quest const* pQuest, uint32 item_idx, uint32 count );
1238        void SendQuestUpdateAddCreatureOrGo( Quest const* pQuest, uint64 guid, uint32 creatureOrGO_idx, uint32 old_count, uint32 add_count );
1239
1240        uint64 GetDivider() { return m_divider; };
1241        void SetDivider( uint64 guid ) { m_divider = guid; };
1242
1243        uint32 GetInGameTime() { return m_ingametime; };
1244
1245        void SetInGameTime( uint32 time ) { m_ingametime = time; };
1246
1247        void AddTimedQuest( uint32 quest_id ) { m_timedquests.insert(quest_id); }
1248
1249        /*********************************************************/
1250        /***                   LOAD SYSTEM                     ***/
1251        /*********************************************************/
1252
1253        bool LoadFromDB(uint32 guid, SqlQueryHolder *holder);
1254        bool MinimalLoadFromDB(QueryResult *result, uint32 guid);
1255        static bool   LoadValuesArrayFromDB(Tokens& data,uint64 guid);
1256        static uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index);
1257        static float  GetFloatValueFromArray(Tokens const& data, uint16 index);
1258        static uint32 GetUInt32ValueFromDB(uint16 index, uint64 guid);
1259        static float  GetFloatValueFromDB(uint16 index, uint64 guid);
1260        static uint32 GetZoneIdFromDB(uint64 guid);
1261        static bool   LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float& o, bool& in_flight, uint64 guid);
1262
1263        /*********************************************************/
1264        /***                   SAVE SYSTEM                     ***/
1265        /*********************************************************/
1266
1267        void SaveToDB();
1268        void SaveInventoryAndGoldToDB();                    // fast save function for item/money cheating preventing
1269        void SaveGoldToDB() { SetUInt32ValueInDB(PLAYER_FIELD_COINAGE,GetMoney(),GetGUID()); }
1270        static bool SaveValuesArrayInDB(Tokens const& data,uint64 guid);
1271        static void SetUInt32ValueInArray(Tokens& data,uint16 index, uint32 value);
1272        static void SetFloatValueInArray(Tokens& data,uint16 index, float value);
1273        static void SetUInt32ValueInDB(uint16 index, uint32 value, uint64 guid);
1274        static void SetFloatValueInDB(uint16 index, float value, uint64 guid);
1275        static void SavePositionInDB(uint32 mapid, float x,float y,float z,float o,uint32 zone,uint64 guid);
1276
1277        bool m_mailsLoaded;
1278        bool m_mailsUpdated;
1279
1280        void SetBindPoint(uint64 guid);
1281        void SendTalentWipeConfirm(uint64 guid);
1282        void RewardRage( uint32 damage, uint32 weaponSpeedHitFactor, bool attacker );
1283        void SendPetSkillWipeConfirm();
1284        void CalcRage( uint32 damage,bool attacker );
1285        void RegenerateAll();
1286        void Regenerate(Powers power);
1287        void RegenerateHealth();
1288        void setRegenTimer(uint32 time) {m_regenTimer = time;}
1289        void setWeaponChangeTimer(uint32 time) {m_weaponChangeTimer = time;}
1290
1291        uint32 GetMoney() { return GetUInt32Value (PLAYER_FIELD_COINAGE); }
1292        void ModifyMoney( int32 d )
1293        {
1294            if(d < 0)
1295                SetMoney (GetMoney() > uint32(-d) ? GetMoney() + d : 0);
1296            else
1297                SetMoney (GetMoney() < MAX_MONEY_AMOUNT - d ? GetMoney() + d : MAX_MONEY_AMOUNT);
1298
1299            // "At Gold Limit"
1300            if(GetMoney() >= MAX_MONEY_AMOUNT)
1301                SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD,NULL,NULL);
1302        }
1303        void SetMoney( uint32 value )
1304        {
1305            SetUInt32Value (PLAYER_FIELD_COINAGE, value);
1306            MoneyChanged( value );
1307        }
1308
1309        uint32 GetTutorialInt(uint32 intId )
1310        {
1311            ASSERT( (intId < 8) );
1312            return m_Tutorials[intId];
1313        }
1314
1315        void SetTutorialInt(uint32 intId, uint32 value)
1316        {
1317            ASSERT( (intId < 8) );
1318            if(m_Tutorials[intId]!=value)
1319            {
1320                m_Tutorials[intId] = value;
1321                m_TutorialsChanged = true;
1322            }
1323        }
1324
1325        QuestStatusMap& getQuestStatusMap() { return mQuestStatus; };
1326
1327        const uint64& GetSelection( ) const { return m_curSelection; }
1328        void SetSelection(const uint64 &guid) { m_curSelection = guid; SetUInt64Value(UNIT_FIELD_TARGET, guid); }
1329
1330        uint8 GetComboPoints() { return m_comboPoints; }
1331        uint64 GetComboTarget() { return m_comboTarget; }
1332
1333        void AddComboPoints(Unit* target, int8 count);
1334        void ClearComboPoints();
1335        void SendComboPoints();
1336
1337        void SendMailResult(uint32 mailId, uint32 mailAction, uint32 mailError, uint32 equipError = 0, uint32 item_guid = 0, uint32 item_count = 0);
1338        void SendNewMail();
1339        void UpdateNextMailTimeAndUnreads();
1340        void AddNewMailDeliverTime(time_t deliver_time);
1341        bool IsMailsLoaded() const { return m_mailsLoaded; }
1342
1343        //void SetMail(Mail *m);
1344        void RemoveMail(uint32 id);
1345
1346        void AddMail(Mail* mail) { m_mail.push_front(mail);}// for call from WorldSession::SendMailTo
1347        uint32 GetMailSize() { return m_mail.size();};
1348        Mail* GetMail(uint32 id);
1349
1350        PlayerMails::iterator GetmailBegin() { return m_mail.begin();};
1351        PlayerMails::iterator GetmailEnd() { return m_mail.end();};
1352
1353        /*********************************************************/
1354        /*** MAILED ITEMS SYSTEM ***/
1355        /*********************************************************/
1356
1357        uint8 unReadMails;
1358        time_t m_nextMailDelivereTime;
1359
1360        typedef HM_NAMESPACE::hash_map<uint32, Item*> ItemMap;
1361
1362        ItemMap mMitems;                                    //template defined in objectmgr.cpp
1363
1364        Item* GetMItem(uint32 id)
1365        {
1366            ItemMap::const_iterator itr = mMitems.find(id);
1367            if (itr != mMitems.end())
1368                return itr->second;
1369
1370            return NULL;
1371        }
1372
1373        void AddMItem(Item* it)
1374        {
1375            ASSERT( it );
1376            //assert deleted, because items can be added before loading
1377            mMitems[it->GetGUIDLow()] = it;
1378        }
1379
1380        bool RemoveMItem(uint32 id)
1381        {
1382            ItemMap::iterator i = mMitems.find(id);
1383            if (i == mMitems.end())
1384                return false;
1385
1386            mMitems.erase(i);
1387            return true;
1388        }
1389
1390        void PetSpellInitialize();
1391        void CharmSpellInitialize();
1392        void PossessSpellInitialize();
1393        bool HasSpell(uint32 spell) const;
1394        TrainerSpellState GetTrainerSpellState(TrainerSpell const* trainer_spell) const;
1395        bool IsSpellFitByClassAndRace( uint32 spell_id ) const;
1396
1397        void SendProficiency(uint8 pr1, uint32 pr2);
1398        void SendInitialSpells();
1399        bool addSpell(uint32 spell_id, bool active, bool learning = true, bool loading = false, uint16 slot_id=SPELL_WITHOUT_SLOT_ID, bool disabled = false);
1400        void learnSpell(uint32 spell_id);
1401        void removeSpell(uint32 spell_id, bool disabled = false);
1402        void resetSpells();
1403        void learnDefaultSpells(bool loading = false);
1404        void learnQuestRewardedSpells();
1405        void learnQuestRewardedSpells(Quest const* quest);
1406
1407        uint32 GetFreeTalentPoints() const { return GetUInt32Value(PLAYER_CHARACTER_POINTS1); }
1408        void SetFreeTalentPoints(uint32 points) { SetUInt32Value(PLAYER_CHARACTER_POINTS1,points); }
1409        bool resetTalents(bool no_cost = false);
1410        uint32 resetTalentsCost() const;
1411        void InitTalentForLevel();
1412
1413        uint32 GetFreePrimaryProffesionPoints() const { return GetUInt32Value(PLAYER_CHARACTER_POINTS2); }
1414        void SetFreePrimaryProffesions(uint16 profs) { SetUInt32Value(PLAYER_CHARACTER_POINTS2,profs); }
1415        void InitPrimaryProffesions();
1416
1417        PlayerSpellMap const& GetSpellMap() const { return m_spells; }
1418        PlayerSpellMap      & GetSpellMap()       { return m_spells; }
1419
1420        void AddSpellMod(SpellModifier* mod, bool apply);
1421        int32 GetTotalFlatMods(uint32 spellId, SpellModOp op);
1422        int32 GetTotalPctMods(uint32 spellId, SpellModOp op);
1423        bool IsAffectedBySpellmod(SpellEntry const *spellInfo, SpellModifier *mod, Spell const* spell = NULL);
1424        template <class T> T ApplySpellMod(uint32 spellId, SpellModOp op, T &basevalue, Spell const* spell = NULL);
1425        void RemoveSpellMods(Spell const* spell);
1426
1427        bool HasSpellCooldown(uint32 spell_id) const
1428        {
1429            SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id);
1430            return itr != m_spellCooldowns.end() && itr->second.end > time(NULL);
1431        }
1432        uint32 GetSpellCooldownDelay(uint32 spell_id) const
1433        {
1434            SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id);
1435            time_t t = time(NULL);
1436            return itr != m_spellCooldowns.end() && itr->second.end > t ? itr->second.end - t : 0;
1437        }
1438        void AddSpellCooldown(uint32 spell_id, uint32 itemid, time_t end_time);
1439        void SendCooldownEvent(SpellEntry const *spellInfo);
1440        void ProhibitSpellScholl(SpellSchoolMask idSchoolMask, uint32 unTimeMs );
1441        void RemoveSpellCooldown(uint32 spell_id) { m_spellCooldowns.erase(spell_id); }
1442        void RemoveArenaSpellCooldowns();
1443        void RemoveAllSpellCooldown();
1444        void _LoadSpellCooldowns(QueryResult *result);
1445        void _SaveSpellCooldowns();
1446
1447        void setResurrectRequestData(uint64 guid, uint32 mapId, float X, float Y, float Z, uint32 health, uint32 mana)
1448        {
1449            m_resurrectGUID = guid;
1450            m_resurrectMap = mapId;
1451            m_resurrectX = X;
1452            m_resurrectY = Y;
1453            m_resurrectZ = Z;
1454            m_resurrectHealth = health;
1455            m_resurrectMana = mana;
1456        };
1457        void clearResurrectRequestData() { setResurrectRequestData(0,0,0.0f,0.0f,0.0f,0,0); }
1458        bool isRessurectRequestedBy(uint64 guid) const { return m_resurrectGUID == guid; }
1459        bool isRessurectRequested() const { return m_resurrectGUID != 0; }
1460        void ResurectUsingRequestData();
1461
1462        int getCinematic()
1463        {
1464            return m_cinematic;
1465        }
1466        void setCinematic(int cine)
1467        {
1468            m_cinematic = cine;
1469        }
1470
1471        void addActionButton(uint8 button, uint16 action, uint8 type, uint8 misc);
1472        void removeActionButton(uint8 button);
1473        void SendInitialActionButtons();
1474
1475        PvPInfo pvpInfo;
1476        void UpdatePvP(bool state, bool ovrride=false);
1477        void UpdateZone(uint32 newZone);
1478        void UpdateArea(uint32 newArea);
1479
1480        void UpdateZoneDependentAuras( uint32 zone_id );    // zones
1481        void UpdateAreaDependentAuras( uint32 area_id );    // subzones
1482
1483        void UpdateAfkReport(time_t currTime);
1484        void UpdatePvPFlag(time_t currTime);
1485        void UpdateContestedPvP(uint32 currTime);
1486        void SetContestedPvPTimer(uint32 newTime) {m_contestedPvPTimer = newTime;}
1487        void ResetContestedPvP()
1488        {
1489            clearUnitState(UNIT_STAT_ATTACK_PLAYER);
1490            RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP);
1491            m_contestedPvPTimer = 0;
1492        }
1493
1494        /** todo: -maybe move UpdateDuelFlag+DuelComplete to independent DuelHandler.. **/
1495        DuelInfo *duel;
1496        void UpdateDuelFlag(time_t currTime);
1497        void CheckDuelDistance(time_t currTime);
1498        void DuelComplete(DuelCompleteType type);
1499
1500        bool IsGroupVisibleFor(Player* p) const;
1501        bool IsInSameGroupWith(Player const* p) const;
1502        bool IsInSameRaidWith(Player const* p) const { return p==this || (GetGroup() != NULL && GetGroup() == p->GetGroup()); }
1503        void UninviteFromGroup();
1504        static void RemoveFromGroup(Group* group, uint64 guid);
1505        void RemoveFromGroup() { RemoveFromGroup(GetGroup(),GetGUID()); }
1506        void SendUpdateToOutOfRangeGroupMembers();
1507
1508        void SetInGuild(uint32 GuildId) { SetUInt32Value(PLAYER_GUILDID, GuildId); Player::SetUInt32ValueInDB(PLAYER_GUILDID, GuildId, this->GetGUID()); }
1509        void SetRank(uint32 rankId){ SetUInt32Value(PLAYER_GUILDRANK, rankId); Player::SetUInt32ValueInDB(PLAYER_GUILDRANK, rankId, this->GetGUID()); }
1510        void SetGuildIdInvited(uint32 GuildId) { m_GuildIdInvited = GuildId; }
1511        uint32 GetGuildId() { return GetUInt32Value(PLAYER_GUILDID);  }
1512        static uint32 GetGuildIdFromDB(uint64 guid);
1513        uint32 GetRank(){ return GetUInt32Value(PLAYER_GUILDRANK); }
1514        static uint32 GetRankFromDB(uint64 guid);
1515        int GetGuildIdInvited() { return m_GuildIdInvited; }
1516        static void RemovePetitionsAndSigns(uint64 guid, uint32 type);
1517
1518        // Arena Team
1519        void SetInArenaTeam(uint32 ArenaTeamId, uint8 slot)
1520        {
1521            SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * 6), ArenaTeamId);
1522            SetUInt32ValueInDB(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * 6), ArenaTeamId, this->GetGUID());
1523        }
1524        uint32 GetArenaTeamId(uint8 slot) { return GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * 6)); }
1525        static uint32 GetArenaTeamIdFromDB(uint64 guid, uint8 slot);
1526        void SetArenaTeamIdInvited(uint32 ArenaTeamId) { m_ArenaTeamIdInvited = ArenaTeamId; }
1527        uint32 GetArenaTeamIdInvited() { return m_ArenaTeamIdInvited; }
1528
1529        void SetDifficulty(uint32 dungeon_difficulty) { m_dungeonDifficulty = dungeon_difficulty; }
1530        uint8 GetDifficulty() { return m_dungeonDifficulty; }
1531
1532        bool UpdateSkill(uint32 skill_id, uint32 step);
1533        bool UpdateSkillPro(uint16 SkillId, int32 Chance, uint32 step);
1534
1535        bool UpdateCraftSkill(uint32 spellid);
1536        bool UpdateGatherSkill(uint32 SkillId, uint32 SkillValue, uint32 RedLevel, uint32 Multiplicator = 1);
1537        bool UpdateFishingSkill();
1538
1539        uint32 GetBaseDefenseSkillValue() const { return GetBaseSkillValue(SKILL_DEFENSE); }
1540        uint32 GetBaseWeaponSkillValue(WeaponAttackType attType) const;
1541
1542        uint32 GetSpellByProto(ItemPrototype *proto);
1543
1544        float GetHealthBonusFromStamina();
1545        float GetManaBonusFromIntellect();
1546
1547        bool UpdateStats(Stats stat);
1548        bool UpdateAllStats();
1549        void UpdateResistances(uint32 school);
1550        void UpdateArmor();
1551        void UpdateMaxHealth();
1552        void UpdateMaxPower(Powers power);
1553        void UpdateAttackPowerAndDamage(bool ranged = false);
1554        void UpdateShieldBlockValue();
1555        void UpdateDamagePhysical(WeaponAttackType attType);
1556        void UpdateSpellDamageAndHealingBonus();
1557
1558        void CalculateMinMaxDamage(WeaponAttackType attType, bool normalized, float& min_damage, float& max_damage);
1559
1560        void UpdateDefenseBonusesMod();
1561        void ApplyRatingMod(CombatRating cr, int32 value, bool apply);
1562        float GetMeleeCritFromAgility();
1563        float GetDodgeFromAgility();
1564        float GetSpellCritFromIntellect();
1565        float OCTRegenHPPerSpirit();
1566        float OCTRegenMPPerSpirit();
1567        float GetRatingCoefficient(CombatRating cr) const;
1568        float GetRatingBonusValue(CombatRating cr) const;
1569        uint32 GetMeleeCritDamageReduction(uint32 damage) const;
1570        uint32 GetRangedCritDamageReduction(uint32 damage) const;
1571        uint32 GetSpellCritDamageReduction(uint32 damage) const;
1572        uint32 GetDotDamageReduction(uint32 damage) const;
1573
1574        float GetExpertiseDodgeOrParryReduction(WeaponAttackType attType) const;
1575        void UpdateBlockPercentage();
1576        void UpdateCritPercentage(WeaponAttackType attType);
1577        void UpdateAllCritPercentages();
1578        void UpdateParryPercentage();
1579        void UpdateDodgePercentage();
1580        void UpdateAllSpellCritChances();
1581        void UpdateSpellCritChance(uint32 school);
1582        void UpdateExpertise(WeaponAttackType attType);
1583        void UpdateManaRegen();
1584
1585        const uint64& GetLootGUID() const { return m_lootGuid; }
1586        void SetLootGUID(const uint64 &guid) { m_lootGuid = guid; }
1587
1588        void RemovedInsignia(Player* looterPlr);
1589
1590        WorldSession* GetSession() const { return m_session; }
1591        void SetSession(WorldSession *s) { m_session = s; }
1592
1593        void BuildCreateUpdateBlockForPlayer( UpdateData *data, Player *target ) const;
1594        void DestroyForPlayer( Player *target ) const;
1595        void SendDelayResponse(const uint32);
1596        void SendLogXPGain(uint32 GivenXP,Unit* victim,uint32 RestXP);
1597
1598        //notifiers
1599        void SendAttackSwingCantAttack();
1600        void SendAttackSwingCancelAttack();
1601        void SendAttackSwingDeadTarget();
1602        void SendAttackSwingNotStanding();
1603        void SendAttackSwingNotInRange();
1604        void SendAttackSwingBadFacingAttack();
1605        void SendAutoRepeatCancel();
1606        void SendExplorationExperience(uint32 Area, uint32 Experience);
1607
1608        void SendDungeonDifficulty(bool IsInGroup);
1609        void ResetInstances(uint8 method);
1610        void SendResetInstanceSuccess(uint32 MapId);
1611        void SendResetInstanceFailed(uint32 reason, uint32 MapId);
1612        void SendResetFailedNotify(uint32 mapid);
1613
1614        bool SetPosition(float x, float y, float z, float orientation, bool teleport = false);
1615        void UpdateUnderwaterState( Map * m, float x, float y, float z );
1616
1617        void SendMessageToSet(WorldPacket *data, bool self);// overwrite Object::SendMessageToSet
1618        void SendMessageToSetInRange(WorldPacket *data, float fist, bool self);
1619                                                            // overwrite Object::SendMessageToSetInRange
1620        void SendMessageToSetInRange(WorldPacket *data, float dist, bool self, bool own_team_only);
1621
1622        static void DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmChars = true);
1623
1624        Corpse *GetCorpse() const;
1625        void SpawnCorpseBones();
1626        void CreateCorpse();
1627        void KillPlayer();
1628        uint32 GetResurrectionSpellId();
1629        void ResurrectPlayer(float restore_percent, bool updateToWorld = true, bool applySickness = false);
1630        void BuildPlayerRepop();
1631        void RepopAtGraveyard();
1632
1633        void DurabilityLossAll(double percent, bool inventory);
1634        void DurabilityLoss(Item* item, double percent);
1635        void DurabilityPointsLossAll(int32 points, bool inventory);
1636        void DurabilityPointsLoss(Item* item, int32 points);
1637        void DurabilityPointLossForEquipSlot(EquipmentSlots slot);
1638        uint32 DurabilityRepairAll(bool cost, float discountMod, bool guildBank);
1639        uint32 DurabilityRepair(uint16 pos, bool cost, float discountMod, bool guildBank);
1640
1641        void StopMirrorTimers()
1642        {
1643            StopMirrorTimer(FATIGUE_TIMER);
1644            StopMirrorTimer(BREATH_TIMER);
1645            StopMirrorTimer(FIRE_TIMER);
1646        }
1647
1648        void SetMovement(PlayerMovementType pType);
1649
1650        void JoinedChannel(Channel *c);
1651        void LeftChannel(Channel *c);
1652        void CleanupChannels();
1653        void UpdateLocalChannels( uint32 newZone );
1654        void LeaveLFGChannel();
1655
1656        void UpdateDefense();
1657        void UpdateWeaponSkill (WeaponAttackType attType);
1658        void UpdateCombatSkills(Unit *pVictim, WeaponAttackType attType, MeleeHitOutcome outcome, bool defence);
1659
1660        void SetSkill(uint32 id, uint16 currVal, uint16 maxVal);
1661        uint16 GetMaxSkillValue(uint32 skill) const;        // max + perm. bonus
1662        uint16 GetPureMaxSkillValue(uint32 skill) const;    // max
1663        uint16 GetSkillValue(uint32 skill) const;           // skill value + perm. bonus + temp bonus
1664        uint16 GetBaseSkillValue(uint32 skill) const;       // skill value + perm. bonus
1665        uint16 GetPureSkillValue(uint32 skill) const;       // skill value
1666        int16 GetSkillTempBonusValue(uint32 skill) const;
1667        bool HasSkill(uint32 skill) const;
1668        void learnSkillRewardedSpells( uint32 id );
1669        void learnSkillRewardedSpells();
1670
1671        void SetDontMove(bool dontMove);
1672        bool GetDontMove() const { return m_dontMove; }
1673
1674        void CheckExploreSystem(void);
1675
1676        static uint32 TeamForRace(uint8 race);
1677        uint32 GetTeam() const { return m_team; }
1678        static uint32 getFactionForRace(uint8 race);
1679        void setFactionForRace(uint8 race);
1680
1681        bool IsAtGroupRewardDistance(WorldObject const* pRewardSource) const;
1682        bool RewardPlayerAndGroupAtKill(Unit* pVictim);
1683
1684        FactionStateList m_factions;
1685        ForcedReactions m_forcedReactions;
1686        uint32 GetDefaultReputationFlags(const FactionEntry *factionEntry) const;
1687        int32 GetBaseReputation(const FactionEntry *factionEntry) const;
1688        int32 GetReputation(uint32 faction_id) const;
1689        int32 GetReputation(const FactionEntry *factionEntry) const;
1690        ReputationRank GetReputationRank(uint32 faction) const;
1691        ReputationRank GetReputationRank(const FactionEntry *factionEntry) const;
1692        ReputationRank GetBaseReputationRank(const FactionEntry *factionEntry) const;
1693        ReputationRank ReputationToRank(int32 standing) const;
1694        const static int32 ReputationRank_Length[MAX_REPUTATION_RANK];
1695        const static int32 Reputation_Cap    =  42999;
1696        const static int32 Reputation_Bottom = -42000;
1697        bool ModifyFactionReputation(uint32 FactionTemplateId, int32 DeltaReputation);
1698        bool ModifyFactionReputation(FactionEntry const* factionEntry, int32 standing);
1699        bool ModifyOneFactionReputation(FactionEntry const* factionEntry, int32 standing);
1700        bool SetFactionReputation(uint32 FactionTemplateId, int32 standing);
1701        bool SetFactionReputation(FactionEntry const* factionEntry, int32 standing);
1702        bool SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing);
1703        int32 CalculateReputationGain(uint32 creatureOrQuestLevel, int32 rep, bool for_quest);
1704        void RewardReputation(Unit *pVictim, float rate);
1705        void RewardReputation(Quest const *pQuest);
1706        void SetInitialFactions();
1707        void UpdateReputation() const;
1708        void SendFactionState(FactionState const* faction) const;
1709        void SendInitialReputations();
1710        FactionState const* GetFactionState( FactionEntry const* factionEntry) const;
1711        void SetFactionAtWar(FactionState* faction, bool atWar);
1712        void SetFactionInactive(FactionState* faction, bool inactive);
1713        void SetFactionVisible(FactionState* faction);
1714        void SetFactionVisibleForFactionTemplateId(uint32 FactionTemplateId);
1715        void SetFactionVisibleForFactionId(uint32 FactionId);
1716        void UpdateMaxSkills();
1717        void UpdateSkillsToMaxSkillsForLevel();             // for .levelup
1718        void ModifySkillBonus(uint32 skillid,int32 val, bool talent);
1719
1720        /*********************************************************/
1721        /***                  PVP SYSTEM                       ***/
1722        /*********************************************************/
1723        void UpdateArenaFields();
1724        void UpdateHonorFields();
1725        bool RewardHonor(Unit *pVictim, uint32 groupsize, float honor = -1, bool pvptoken = false);
1726        uint32 GetHonorPoints() { return GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY); }
1727        uint32 GetArenaPoints() { return GetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY); }
1728        void ModifyHonorPoints( int32 value );
1729        void ModifyArenaPoints( int32 value );
1730        uint32 GetMaxPersonalArenaRatingRequirement();
1731
1732        //End of PvP System
1733
1734        void SetDrunkValue(uint16 newDrunkValue, uint32 itemid=0);
1735        uint16 GetDrunkValue() const { return m_drunk; }
1736        static DrunkenState GetDrunkenstateByValue(uint16 value);
1737
1738        uint32 GetDeathTimer() const { return m_deathTimer; }
1739        uint32 GetCorpseReclaimDelay(bool pvp) const;
1740        void UpdateCorpseReclaimDelay();
1741        void SendCorpseReclaimDelay(bool load = false);
1742
1743        uint32 GetShieldBlockValue() const;                 // overwrite Unit version (virtual)
1744        bool CanParry() const { return m_canParry; }
1745        void SetCanParry(bool value);
1746        bool CanBlock() const { return m_canBlock; }
1747        void SetCanBlock(bool value);
1748        bool CanDualWield() const { return m_canDualWield; }
1749        void SetCanDualWield(bool value) { m_canDualWield = value; }
1750
1751        void SetRegularAttackTime();
1752        void SetBaseModValue(BaseModGroup modGroup, BaseModType modType, float value) { m_auraBaseMod[modGroup][modType] = value; }
1753        void HandleBaseModValue(BaseModGroup modGroup, BaseModType modType, float amount, bool apply, bool affectStats = true);
1754        float GetBaseModValue(BaseModGroup modGroup, BaseModType modType) const;
1755        float GetTotalBaseModValue(BaseModGroup modGroup) const;
1756        float GetTotalPercentageModValue(BaseModGroup modGroup) const { return m_auraBaseMod[modGroup][FLAT_MOD] + m_auraBaseMod[modGroup][PCT_MOD]; }
1757        void _ApplyAllStatBonuses();
1758        void _RemoveAllStatBonuses();
1759
1760        void _ApplyWeaponDependentAuraMods(Item *item,WeaponAttackType attackType,bool apply);
1761        void _ApplyWeaponDependentAuraCritMod(Item *item, WeaponAttackType attackType, Aura* aura, bool apply);
1762        void _ApplyWeaponDependentAuraDamageMod(Item *item, WeaponAttackType attackType, Aura* aura, bool apply);
1763
1764        void _ApplyItemMods(Item *item,uint8 slot,bool apply);
1765        void _RemoveAllItemMods();
1766        void _ApplyAllItemMods();
1767        void _ApplyItemBonuses(ItemPrototype const *proto,uint8 slot,bool apply);
1768        void _ApplyAmmoBonuses();
1769        bool EnchantmentFitsRequirements(uint32 enchantmentcondition, int8 slot);
1770        void ToggleMetaGemsActive(uint8 exceptslot, bool apply);
1771        void CorrectMetaGemEnchants(uint8 slot, bool apply);
1772        void InitDataForForm(bool reapplyMods = false);
1773
1774        void ApplyItemEquipSpell(Item *item, bool apply, bool form_change = false);
1775        void ApplyEquipSpell(SpellEntry const* spellInfo, Item* item, bool apply, bool form_change = false);
1776        void UpdateEquipSpellsAtFormChange();
1777        void CastItemCombatSpell(Item *item,Unit* Target, WeaponAttackType attType);
1778
1779        void SendInitWorldStates();
1780        void SendUpdateWorldState(uint32 Field, uint32 Value);
1781        void SendDirectMessage(WorldPacket *data);
1782
1783        void SendAuraDurationsForTarget(Unit* target);
1784
1785        PlayerMenu* PlayerTalkClass;
1786        std::vector<ItemSetEffect *> ItemSetEff;
1787
1788        void SendLoot(uint64 guid, LootType loot_type);
1789        void SendLootRelease( uint64 guid );
1790        void SendNotifyLootItemRemoved(uint8 lootSlot);
1791        void SendNotifyLootMoneyRemoved();
1792
1793        /*********************************************************/
1794        /***               BATTLEGROUND SYSTEM                 ***/
1795        /*********************************************************/
1796
1797        bool InBattleGround() const { return m_bgBattleGroundID != 0; }
1798        uint32 GetBattleGroundId() const    { return m_bgBattleGroundID; }
1799        BattleGround* GetBattleGround() const;
1800        bool InArena() const;
1801
1802        static uint32 GetMinLevelForBattleGroundQueueId(uint32 queue_id);
1803        static uint32 GetMaxLevelForBattleGroundQueueId(uint32 queue_id);
1804        uint32 GetBattleGroundQueueIdFromLevel() const;
1805
1806        bool InBattleGroundQueue() const         
1807            {   
1808                for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)   
1809                if (m_bgBattleGroundQueueID[i].bgQueueType != 0)         
1810                        return true;     
1811                return false;   
1812            }
1813
1814        uint32 GetBattleGroundQueueId(uint32 index) const { return m_bgBattleGroundQueueID[index].bgQueueType; }
1815        uint32 GetBattleGroundQueueIndex(uint32 bgQueueType) const
1816        {
1817            for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1818                if (m_bgBattleGroundQueueID[i].bgQueueType == bgQueueType)
1819                    return i;
1820            return PLAYER_MAX_BATTLEGROUND_QUEUES;
1821        }
1822        bool IsInvitedForBattleGroundQueueType(uint32 bgQueueType) const
1823        {
1824            for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1825                if (m_bgBattleGroundQueueID[i].bgQueueType == bgQueueType)
1826                    return m_bgBattleGroundQueueID[i].invitedToInstance != 0;
1827            return PLAYER_MAX_BATTLEGROUND_QUEUES;
1828        }
1829        bool InBattleGroundQueueForBattleGroundQueueType(uint32 bgQueueType) const
1830        {
1831            return GetBattleGroundQueueIndex(bgQueueType) < PLAYER_MAX_BATTLEGROUND_QUEUES;
1832        }
1833
1834        void SetBattleGroundId(uint32 val)  { m_bgBattleGroundID = val; }
1835        uint32 AddBattleGroundQueueId(uint32 val)
1836        {
1837            for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1838            {
1839                if (m_bgBattleGroundQueueID[i].bgQueueType == 0 || m_bgBattleGroundQueueID[i].bgQueueType == val)
1840                {
1841                    m_bgBattleGroundQueueID[i].bgQueueType = val;
1842                    m_bgBattleGroundQueueID[i].invitedToInstance = 0;
1843                    return i;
1844                }
1845            }
1846            return PLAYER_MAX_BATTLEGROUND_QUEUES;
1847        }
1848        bool HasFreeBattleGroundQueueId()
1849        {
1850            for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1851                if (m_bgBattleGroundQueueID[i].bgQueueType == 0)
1852                    return true;
1853            return false;
1854        }
1855        void RemoveBattleGroundQueueId(uint32 val)
1856        {
1857            for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1858            {
1859                if (m_bgBattleGroundQueueID[i].bgQueueType == val)
1860                {
1861                    m_bgBattleGroundQueueID[i].bgQueueType = 0;
1862                    m_bgBattleGroundQueueID[i].invitedToInstance = 0;
1863                    return;
1864                }
1865            }
1866        }
1867        void SetInviteForBattleGroundQueueType(uint32 bgQueueType, uint32 instanceId)
1868        {
1869            for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1870                if (m_bgBattleGroundQueueID[i].bgQueueType == bgQueueType)
1871                    m_bgBattleGroundQueueID[i].invitedToInstance = instanceId;
1872        }
1873        bool IsInvitedForBattleGroundInstance(uint32 instanceId) const
1874        {
1875            for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1876                if (m_bgBattleGroundQueueID[i].invitedToInstance == instanceId)
1877                    return true;
1878            return false;
1879        }
1880        uint32 GetBattleGroundEntryPointMap() const { return m_bgEntryPointMap; }
1881        float GetBattleGroundEntryPointX() const { return m_bgEntryPointX; }
1882        float GetBattleGroundEntryPointY() const { return m_bgEntryPointY; }
1883        float GetBattleGroundEntryPointZ() const { return m_bgEntryPointZ; }
1884        float GetBattleGroundEntryPointO() const { return m_bgEntryPointO; }
1885        void SetBattleGroundEntryPoint(uint32 Map, float PosX, float PosY, float PosZ, float PosO )
1886        {
1887            m_bgEntryPointMap = Map;
1888            m_bgEntryPointX = PosX;
1889            m_bgEntryPointY = PosY;
1890            m_bgEntryPointZ = PosZ;
1891            m_bgEntryPointO = PosO;
1892        }
1893
1894        void SetBGTeam(uint32 team) { m_bgTeam = team; }
1895        uint32 GetBGTeam() const { return m_bgTeam ? m_bgTeam : GetTeam(); }
1896
1897        void LeaveBattleground(bool teleportToEntryPoint = true);
1898        bool CanJoinToBattleground() const;
1899        bool CanReportAfkDueToLimit();
1900        void ReportedAfkBy(Player* reporter);
1901        void ClearAfkReports() { m_bgAfkReporter.clear(); }
1902
1903        bool GetBGAccessByLevel(uint32 bgTypeId) const;
1904        bool isAllowUseBattleGroundObject();
1905
1906        /*********************************************************/
1907        /***                    REST SYSTEM                    ***/
1908        /*********************************************************/
1909
1910        bool isRested() const { return GetRestTime() >= 10000; }
1911        uint32 GetXPRestBonus(uint32 xp);
1912        uint32 GetRestTime() const { return m_restTime;};
1913        void SetRestTime(uint32 v) { m_restTime = v;};
1914
1915        /*********************************************************/
1916        /***              ENVIROMENTAL SYSTEM                  ***/
1917        /*********************************************************/
1918
1919        void EnvironmentalDamage(uint64 guid, EnviromentalDamage type, uint32 damage);
1920
1921        /*********************************************************/
1922        /***               FLOOD FILTER SYSTEM                 ***/
1923        /*********************************************************/
1924
1925        void UpdateSpeakTime();
1926        bool CanSpeak() const;
1927        void ChangeSpeakTime(int utime);
1928
1929        /*********************************************************/
1930        /***                 VARIOUS SYSTEMS                   ***/
1931        /*********************************************************/
1932        MovementInfo m_movementInfo;
1933        bool isMoving() const { return HasUnitMovementFlag(movementFlagsMask); }
1934        bool isMovingOrTurning() const { return HasUnitMovementFlag(movementOrTurningFlagsMask); }
1935
1936        bool CanFly() const { return HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY); }
1937        bool IsFlying() const { return HasUnitMovementFlag(MOVEMENTFLAG_FLYING); }
1938
1939        void HandleDrowning();
1940
1941        void SetClientControl(Unit* target, uint8 allowMove);
1942
1943        // Transports
1944        Transport * GetTransport() const { return m_transport; }
1945        void SetTransport(Transport * t) { m_transport = t; }
1946
1947        float GetTransOffsetX() const { return m_movementInfo.t_x; }
1948        float GetTransOffsetY() const { return m_movementInfo.t_y; }
1949        float GetTransOffsetZ() const { return m_movementInfo.t_z; }
1950        float GetTransOffsetO() const { return m_movementInfo.t_o; }
1951        uint32 GetTransTime() const { return m_movementInfo.t_time; }
1952
1953        uint32 GetSaveTimer() const { return m_nextSave; }
1954        void   SetSaveTimer(uint32 timer) { m_nextSave = timer; }
1955
1956        // Recall position
1957        uint32 m_recallMap;
1958        float  m_recallX;
1959        float  m_recallY;
1960        float  m_recallZ;
1961        float  m_recallO;
1962        void   SaveRecallPosition();
1963
1964        // Homebind coordinates
1965        uint32 m_homebindMapId;
1966        uint16 m_homebindZoneId;
1967        float m_homebindX;
1968        float m_homebindY;
1969        float m_homebindZ;
1970
1971        // currently visible objects at player client
1972        typedef std::set<uint64> ClientGUIDs;
1973        ClientGUIDs m_clientGUIDs;
1974
1975        bool HaveAtClient(WorldObject const* u) { return u==this || m_clientGUIDs.find(u->GetGUID())!=m_clientGUIDs.end(); }
1976
1977        bool IsVisibleInGridForPlayer(Player* pl) const;
1978        bool IsVisibleGloballyFor(Player* pl) const;
1979
1980        void UpdateVisibilityOf(WorldObject* target);
1981
1982        template<class T>
1983            void UpdateVisibilityOf(T* target, UpdateData& data, UpdateDataMapType& data_updates, std::set<WorldObject*>& visibleNow);
1984
1985        // Stealth detection system
1986        uint32 m_DetectInvTimer;
1987        void HandleStealthedUnitsDetection();
1988
1989        uint8 m_forced_speed_changes[MAX_MOVE_TYPE];
1990
1991        bool HasAtLoginFlag(AtLoginFlags f) const { return m_atLoginFlags & f; }
1992        void SetAtLoginFlag(AtLoginFlags f) { m_atLoginFlags |= f; }
1993
1994        LookingForGroup m_lookingForGroup;
1995
1996        // Temporarily removed pet cache
1997        uint32 GetTemporaryUnsummonedPetNumber() const { return m_temporaryUnsummonedPetNumber; }
1998        void SetTemporaryUnsummonedPetNumber(uint32 petnumber) { m_temporaryUnsummonedPetNumber = petnumber; }
1999        uint32 GetOldPetSpell() const { return m_oldpetspell; }
2000        void SetOldPetSpell(uint32 petspell) { m_oldpetspell = petspell; }
2001
2002        /*********************************************************/
2003        /***                 INSTANCE SYSTEM                   ***/
2004        /*********************************************************/
2005
2006        typedef HM_NAMESPACE::hash_map< uint32 /*mapId*/, InstancePlayerBind > BoundInstancesMap;
2007
2008        void UpdateHomebindTime(uint32 time);
2009
2010        uint32 m_HomebindTimer;
2011        bool m_InstanceValid;
2012        // permanent binds and solo binds by difficulty
2013        BoundInstancesMap m_boundInstances[TOTAL_DIFFICULTIES];
2014        InstancePlayerBind* GetBoundInstance(uint32 mapid, uint8 difficulty);
2015        BoundInstancesMap& GetBoundInstances(uint8 difficulty) { return m_boundInstances[difficulty]; }
2016        void UnbindInstance(uint32 mapid, uint8 difficulty, bool unload = false);
2017        void UnbindInstance(BoundInstancesMap::iterator &itr, uint8 difficulty, bool unload = false);
2018        InstancePlayerBind* BindToInstance(InstanceSave *save, bool permanent, bool load = false);
2019        void SendRaidInfo();
2020        void SendSavedInstances();
2021        static void ConvertInstancesToGroup(Player *player, Group *group = NULL, uint64 player_guid = 0);
2022
2023        /*********************************************************/
2024        /***                   GROUP SYSTEM                    ***/
2025        /*********************************************************/
2026
2027        Group * GetGroupInvite() { return m_groupInvite; }
2028        void SetGroupInvite(Group *group) { m_groupInvite = group; }
2029        Group * GetGroup() { return m_group.getTarget(); }
2030        const Group * GetGroup() const { return (const Group*)m_group.getTarget(); }
2031        GroupReference& GetGroupRef() { return m_group; }
2032        void SetGroup(Group *group, int8 subgroup = -1);
2033        uint8 GetSubGroup() const { return m_group.getSubGroup(); }
2034        uint32 GetGroupUpdateFlag() { return m_groupUpdateMask; }
2035        void SetGroupUpdateFlag(uint32 flag) { m_groupUpdateMask |= flag; }
2036        uint64 GetAuraUpdateMask() { return m_auraUpdateMask; }
2037        void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); }
2038        Player* GetNextRandomRaidMember(float radius);
2039
2040        GridReference<Player> &GetGridRef() { return m_gridRef; }
2041        bool isAllowedToLoot(Creature* creature);
2042
2043        WorldLocation& GetTeleportDest() { return m_teleport_dest; }
2044
2045        DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
2046
2047    protected:
2048
2049        /*********************************************************/
2050        /***               BATTLEGROUND SYSTEM                 ***/
2051        /*********************************************************/
2052
2053        /* this variable is set to bg->m_InstanceID, when player is teleported to BG - (it is battleground's GUID)*/
2054        uint32 m_bgBattleGroundID;
2055        /*
2056        this is an array of BG queues (BgTypeIDs) in which is player
2057        */
2058        struct BgBattleGroundQueueID_Rec
2059        {
2060            uint32 bgQueueType;
2061            uint32 invitedToInstance;
2062        };
2063        BgBattleGroundQueueID_Rec m_bgBattleGroundQueueID[PLAYER_MAX_BATTLEGROUND_QUEUES];
2064        uint32 m_bgEntryPointMap;
2065        float m_bgEntryPointX;
2066        float m_bgEntryPointY;
2067        float m_bgEntryPointZ;
2068        float m_bgEntryPointO;
2069
2070        std::set<uint32> m_bgAfkReporter;
2071        uint8 m_bgAfkReportedCount;
2072        time_t m_bgAfkReportedTimer;
2073        uint32 m_contestedPvPTimer;
2074
2075        uint32 m_bgTeam;    // what side the player will be added to
2076
2077        /*********************************************************/
2078        /***                    QUEST SYSTEM                   ***/
2079        /*********************************************************/
2080
2081        std::set<uint32> m_timedquests;
2082
2083        uint64 m_divider;
2084        uint32 m_ingametime;
2085
2086        /*********************************************************/
2087        /***                   LOAD SYSTEM                     ***/
2088        /*********************************************************/
2089
2090        void _LoadActions(QueryResult *result);
2091        void _LoadAuras(QueryResult *result, uint32 timediff);
2092        void _LoadBoundInstances(QueryResult *result);
2093        void _LoadInventory(QueryResult *result, uint32 timediff);
2094        void _LoadMailInit(QueryResult *resultUnread, QueryResult *resultDelivery);
2095        void _LoadMail();
2096        void _LoadMailedItems(Mail *mail);
2097        void _LoadQuestStatus(QueryResult *result);
2098        void _LoadDailyQuestStatus(QueryResult *result);
2099        void _LoadGroup(QueryResult *result);
2100        void _LoadReputation(QueryResult *result);
2101        void _LoadSpells(QueryResult *result);
2102        void _LoadTutorials(QueryResult *result);
2103        void _LoadFriendList(QueryResult *result);
2104        bool _LoadHomeBind(QueryResult *result);
2105        void _LoadDeclinedNames(QueryResult *result);
2106
2107        /*********************************************************/
2108        /***                   SAVE SYSTEM                     ***/
2109        /*********************************************************/
2110
2111        void _SaveActions();
2112        void _SaveAuras();
2113        void _SaveInventory();
2114        void _SaveMail();
2115        void _SaveQuestStatus();
2116        void _SaveDailyQuestStatus();
2117        void _SaveReputation();
2118        void _SaveSpells();
2119        void _SaveTutorials();
2120
2121        void _SetCreateBits(UpdateMask *updateMask, Player *target) const;
2122        void _SetUpdateBits(UpdateMask *updateMask, Player *target) const;
2123
2124        /*********************************************************/
2125        /***              ENVIRONMENTAL SYSTEM                 ***/
2126        /*********************************************************/
2127        void HandleLava();
2128        void HandleSobering();
2129        void StartMirrorTimer(MirrorTimerType Type, uint32 MaxValue);
2130        void ModifyMirrorTimer(MirrorTimerType Type, uint32 MaxValue, uint32 CurrentValue, uint32 Regen);
2131        void StopMirrorTimer(MirrorTimerType Type);
2132        uint8 m_isunderwater;
2133        bool m_isInWater;
2134
2135        /*********************************************************/
2136        /***                  HONOR SYSTEM                     ***/
2137        /*********************************************************/
2138        time_t m_lastHonorUpdateTime;
2139
2140        void outDebugValues() const;
2141        bool _removeSpell(uint16 spell_id);
2142        uint64 m_lootGuid;
2143
2144        uint32 m_race;
2145        uint32 m_class;
2146        uint32 m_team;
2147        uint32 m_nextSave;
2148        time_t m_speakTime;
2149        uint32 m_speakCount;
2150        uint32 m_dungeonDifficulty;
2151
2152        uint32 m_atLoginFlags;
2153
2154        Item* m_items[PLAYER_SLOTS_COUNT];
2155        uint32 m_currentBuybackSlot;
2156
2157        std::vector<Item*> m_itemUpdateQueue;
2158        bool m_itemUpdateQueueBlocked;
2159
2160        uint32 m_ExtraFlags;
2161        uint64 m_curSelection;
2162
2163        uint64 m_comboTarget;
2164        int8 m_comboPoints;
2165
2166        QuestStatusMap mQuestStatus;
2167
2168        uint32 m_GuildIdInvited;
2169        uint32 m_ArenaTeamIdInvited;
2170
2171        PlayerMails m_mail;
2172        PlayerSpellMap m_spells;
2173        SpellCooldowns m_spellCooldowns;
2174
2175        ActionButtonList m_actionButtons;
2176
2177        float m_auraBaseMod[BASEMOD_END][MOD_END];
2178
2179        SpellModList m_spellMods[MAX_SPELLMOD];
2180        int32 m_SpellModRemoveCount;
2181        EnchantDurationList m_enchantDuration;
2182        ItemDurationList m_itemDuration;
2183
2184        uint64 m_resurrectGUID;
2185        uint32 m_resurrectMap;
2186        float m_resurrectX, m_resurrectY, m_resurrectZ;
2187        uint32 m_resurrectHealth, m_resurrectMana;
2188
2189        WorldSession *m_session;
2190
2191        typedef std::list<Channel*> JoinedChannelsList;
2192        JoinedChannelsList m_channels;
2193
2194        bool m_dontMove;
2195
2196        int m_cinematic;
2197
2198        Player *pTrader;
2199        bool acceptTrade;
2200        uint16 tradeItems[TRADE_SLOT_COUNT];
2201        uint32 tradeGold;
2202
2203        time_t m_nextThinkTime;
2204
2205        uint32 m_Tutorials[8];
2206        bool   m_TutorialsChanged;
2207
2208        bool   m_DailyQuestChanged;
2209        time_t m_lastDailyQuestTime;
2210
2211        uint32 m_regenTimer;
2212        uint32 m_breathTimer;
2213        uint32 m_drunkTimer;
2214        uint16 m_drunk;
2215        uint32 m_weaponChangeTimer;
2216
2217        uint32 m_zoneUpdateId;
2218        uint32 m_zoneUpdateTimer;
2219        uint32 m_areaUpdateId;
2220
2221        uint32 m_deathTimer;
2222        time_t m_deathExpireTime;
2223
2224        uint32 m_restTime;
2225
2226        uint32 m_WeaponProficiency;
2227        uint32 m_ArmorProficiency;
2228        bool m_canParry;
2229        bool m_canBlock;
2230        bool m_canDualWield;
2231        uint8 m_swingErrorMsg;
2232        float m_ammoDPS;
2233        ////////////////////Rest System/////////////////////
2234        int time_inn_enter;
2235        uint32 inn_pos_mapid;
2236        float  inn_pos_x;
2237        float  inn_pos_y;
2238        float  inn_pos_z;
2239        float m_rest_bonus;
2240        RestType rest_type;
2241        ////////////////////Rest System/////////////////////
2242
2243        // Transports
2244        Transport * m_transport;
2245
2246        uint32 m_resetTalentsCost;
2247        time_t m_resetTalentsTime;
2248        uint32 m_usedTalentCount;
2249
2250        // Social
2251        PlayerSocial *m_social;
2252
2253        // Groups
2254        GroupReference m_group;
2255        Group *m_groupInvite;
2256        uint32 m_groupUpdateMask;
2257        uint64 m_auraUpdateMask;
2258
2259        // Temporarily removed pet cache
2260        uint32 m_temporaryUnsummonedPetNumber;
2261        uint32 m_oldpetspell;
2262
2263        uint64 m_miniPet;
2264        GuardianPetList m_guardianPets;
2265
2266        // Player summoning
2267        time_t m_summon_expire;
2268        uint32 m_summon_mapid;
2269        float  m_summon_x;
2270        float  m_summon_y;
2271        float  m_summon_z;
2272
2273        // Far Teleport
2274        WorldLocation m_teleport_dest;
2275
2276        DeclinedName *m_declinedname;
2277    private:
2278        // internal common parts for CanStore/StoreItem functions
2279        uint8 _CanStoreItem_InSpecificSlot( uint8 bag, uint8 slot, ItemPosCountVec& dest, ItemPrototype const *pProto, uint32& count, bool swap, Item *pSrcItem ) const;
2280        uint8 _CanStoreItem_InBag( uint8 bag, ItemPosCountVec& dest, ItemPrototype const *pProto, uint32& count, bool merge, bool non_specialized, Item *pSrcItem, uint8 skip_bag, uint8 skip_slot ) const;
2281        uint8 _CanStoreItem_InInventorySlots( uint8 slot_begin, uint8 slot_end, ItemPosCountVec& dest, ItemPrototype const *pProto, uint32& count, bool merge, Item *pSrcItem, uint8 skip_bag, uint8 skip_slot ) const;
2282        Item* _StoreItem( uint16 pos, Item *pItem, uint32 count, bool clone, bool update );
2283
2284        GridReference<Player> m_gridRef;
2285};
2286
2287void AddItemsSetItem(Player*player,Item *item);
2288void RemoveItemsSetItem(Player*player,ItemPrototype const *proto);
2289
2290// "the bodies of template functions must be made available in a header file"
2291template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &basevalue, Spell const* spell)
2292{
2293    SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
2294    if (!spellInfo) return 0;
2295    int32 totalpct = 0;
2296    int32 totalflat = 0;
2297    for (SpellModList::iterator itr = m_spellMods[op].begin(); itr != m_spellMods[op].end(); ++itr)
2298    {
2299        SpellModifier *mod = *itr;
2300
2301        if(!IsAffectedBySpellmod(spellInfo,mod,spell))
2302            continue;
2303        if (mod->type == SPELLMOD_FLAT)
2304            totalflat += mod->value;
2305        else if (mod->type == SPELLMOD_PCT)
2306        {
2307            // skip percent mods for null basevalue (most important for spell mods with charges )
2308            if(basevalue == T(0))
2309                continue;
2310
2311            // special case (skip >10sec spell casts for instant cast setting)
2312            if( mod->op==SPELLMOD_CASTING_TIME  && basevalue >= T(10000) && mod->value <= -100)
2313                continue;
2314
2315            totalpct += mod->value;
2316        }
2317
2318        if (mod->charges > 0 )
2319        {
2320            --mod->charges;
2321            if (mod->charges == 0)
2322            {
2323                mod->charges = -1;
2324                mod->lastAffected = spell;
2325                if(!mod->lastAffected)
2326                    mod->lastAffected = FindCurrentSpellBySpellId(spellId);
2327                ++m_SpellModRemoveCount;
2328            }
2329        }
2330    }
2331
2332    float diff = (float)basevalue*(float)totalpct/100.0f + (float)totalflat;
2333    basevalue = T((float)basevalue + diff);
2334    return T(diff);
2335}
2336#endif
Note: See TracBrowser for help on using the browser.