[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / Player.h
blob9e102436ae2e7ffde8f0c450523253ba19056701
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
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.
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.
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
19 #ifndef _PLAYER_H
20 #define _PLAYER_H
22 #include "Common.h"
23 #include "ItemPrototype.h"
24 #include "Unit.h"
25 #include "Item.h"
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 "MapReference.h"
35 #include "Util.h" // for Tokens typedef
36 #include "AchievementMgr.h"
37 #include "BattleGround.h"
39 #include<string>
40 #include<vector>
42 struct Mail;
43 class Channel;
44 class DynamicObject;
45 class Creature;
46 class Pet;
47 class PlayerMenu;
48 class Transport;
49 class UpdateMask;
50 class SpellCastTargets;
51 class PlayerSocial;
52 class AchievementMgr;
53 class Vehicle;
55 typedef std::deque<Mail*> PlayerMails;
57 #define PLAYER_MAX_SKILLS 127
58 #define PLAYER_MAX_DAILY_QUESTS 25
60 // Note: SPELLMOD_* values is aura types in fact
61 enum SpellModType
63 SPELLMOD_FLAT = 107, // SPELL_AURA_ADD_FLAT_MODIFIER
64 SPELLMOD_PCT = 108 // SPELL_AURA_ADD_PCT_MODIFIER
67 // 2^n values, Player::m_isunderwater is a bitmask. These are mangos internal values, they are never send to any client
68 enum PlayerUnderwaterState
70 UNDERWATER_NONE = 0x00,
71 UNDERWATER_INWATER = 0x01, // terrain type is water and player is afflicted by it
72 UNDERWATER_WATER_TRIGGER = 0x02, // m_breathTimer has been initialized
73 UNDERWATER_WATER_BREATHB = 0x04, // breathbar has been send to client
74 UNDERWATER_WATER_BREATHB_RETRACTING = 0x10, // breathbar is currently refilling - the player is above water level
75 UNDERWATER_INLAVA = 0x80 // terrain type is lava and player is afflicted by it
78 enum PlayerSpellState
80 PLAYERSPELL_UNCHANGED = 0,
81 PLAYERSPELL_CHANGED = 1,
82 PLAYERSPELL_NEW = 2,
83 PLAYERSPELL_REMOVED = 3
86 struct PlayerSpell
88 PlayerSpellState state : 8;
89 bool active : 1; // show in spellbook
90 bool dependent : 1; // learned as result another spell learn, skill grow, quest reward, etc
91 bool disabled : 1; // first rank has been learned in result talent learn but currently talent unlearned, save max learned ranks
94 // Spell modifier (used for modify other spells)
95 struct SpellModifier
97 SpellModifier() : charges(0), lastAffected(NULL) {}
98 SpellModOp op : 8;
99 SpellModType type : 8;
100 int16 charges : 16;
101 int32 value;
102 uint64 mask;
103 uint64 mask2;
104 uint32 spellId;
105 Spell const* lastAffected;
108 typedef UNORDERED_MAP<uint32, PlayerSpell*> PlayerSpellMap;
109 typedef std::list<SpellModifier*> SpellModList;
111 struct SpellCooldown
113 time_t end;
114 uint16 itemid;
117 typedef std::map<uint32, SpellCooldown> SpellCooldowns;
119 enum TrainerSpellState
121 TRAINER_SPELL_GREEN = 0,
122 TRAINER_SPELL_RED = 1,
123 TRAINER_SPELL_GRAY = 2
126 enum ActionButtonUpdateState
128 ACTIONBUTTON_UNCHANGED = 0,
129 ACTIONBUTTON_CHANGED = 1,
130 ACTIONBUTTON_NEW = 2,
131 ACTIONBUTTON_DELETED = 3
134 struct ActionButton
136 ActionButton() : action(0), type(0), misc(0), uState( ACTIONBUTTON_NEW ) {}
137 ActionButton(uint16 _action, uint8 _type, uint8 _misc) : action(_action), type(_type), misc(_misc), uState( ACTIONBUTTON_NEW ) {}
139 uint16 action;
140 uint8 type;
141 uint8 misc;
142 ActionButtonUpdateState uState;
145 enum ActionButtonType
147 ACTION_BUTTON_SPELL = 0,
148 ACTION_BUTTON_MACRO = 64,
149 ACTION_BUTTON_CMACRO= 65,
150 ACTION_BUTTON_ITEM = 128
153 #define MAX_ACTION_BUTTONS 132 //checked in 2.3.0
155 typedef std::map<uint8,ActionButton> ActionButtonList;
157 struct PlayerCreateInfoItem
159 PlayerCreateInfoItem(uint32 id, uint32 amount) : item_id(id), item_amount(amount) {}
161 uint32 item_id;
162 uint32 item_amount;
165 typedef std::list<PlayerCreateInfoItem> PlayerCreateInfoItems;
167 struct PlayerClassLevelInfo
169 PlayerClassLevelInfo() : basehealth(0), basemana(0) {}
170 uint16 basehealth;
171 uint16 basemana;
174 struct PlayerClassInfo
176 PlayerClassInfo() : levelInfo(NULL) { }
178 PlayerClassLevelInfo* levelInfo; //[level-1] 0..MaxPlayerLevel-1
181 struct PlayerLevelInfo
183 PlayerLevelInfo() { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
185 uint8 stats[MAX_STATS];
188 typedef std::list<uint32> PlayerCreateInfoSpells;
190 struct PlayerInfo
192 // existence checked by displayId != 0 // existence checked by displayId != 0
193 PlayerInfo() : displayId_m(0),displayId_f(0),levelInfo(NULL)
197 uint32 mapId;
198 uint32 zoneId;
199 float positionX;
200 float positionY;
201 float positionZ;
202 uint16 displayId_m;
203 uint16 displayId_f;
204 PlayerCreateInfoItems item;
205 PlayerCreateInfoSpells spell;
206 std::list<uint16> action[4];
208 PlayerLevelInfo* levelInfo; //[level-1] 0..MaxPlayerLevel-1
211 struct PvPInfo
213 PvPInfo() : inHostileArea(false), endTimer(0) {}
215 bool inHostileArea;
216 time_t endTimer;
219 struct DuelInfo
221 DuelInfo() : initiator(NULL), opponent(NULL), startTimer(0), startTime(0), outOfBound(0) {}
223 Player *initiator;
224 Player *opponent;
225 time_t startTimer;
226 time_t startTime;
227 time_t outOfBound;
230 struct Areas
232 uint32 areaID;
233 uint32 areaFlag;
234 float x1;
235 float x2;
236 float y1;
237 float y2;
240 #define MAX_RUNES 6
241 #define RUNE_COOLDOWN 5 // 5*2=10 sec
243 enum RuneType
245 RUNE_BLOOD = 0,
246 RUNE_UNHOLY = 1,
247 RUNE_FROST = 2,
248 RUNE_DEATH = 3,
249 NUM_RUNE_TYPES = 4
252 struct RuneInfo
254 uint8 BaseRune;
255 uint8 CurrentRune;
256 uint8 Cooldown;
259 struct Runes
261 RuneInfo runes[MAX_RUNES];
262 uint8 runeState; // mask of available runes
264 void SetRuneState(uint8 index, bool set = true)
266 if(set)
267 runeState |= (1 << index); // usable
268 else
269 runeState &= ~(1 << index); // on cooldown
273 enum FactionFlags
275 FACTION_FLAG_VISIBLE = 0x01, // makes visible in client (set or can be set at interaction with target of this faction)
276 FACTION_FLAG_AT_WAR = 0x02, // enable AtWar-button in client. player controlled (except opposition team always war state), Flag only set on initial creation
277 FACTION_FLAG_HIDDEN = 0x04, // hidden faction from reputation pane in client (player can gain reputation, but this update not sent to client)
278 FACTION_FLAG_INVISIBLE_FORCED = 0x08, // always overwrite FACTION_FLAG_VISIBLE and hide faction in rep.list, used for hide opposite team factions
279 FACTION_FLAG_PEACE_FORCED = 0x10, // always overwrite FACTION_FLAG_AT_WAR, used for prevent war with own team factions
280 FACTION_FLAG_INACTIVE = 0x20, // player controlled, state stored in characters.data ( CMSG_SET_FACTION_INACTIVE )
281 FACTION_FLAG_RIVAL = 0x40 // flag for the two competing outland factions
284 typedef uint32 RepListID;
285 struct FactionState
287 uint32 ID;
288 RepListID ReputationListID;
289 uint32 Flags;
290 int32 Standing;
291 bool Changed;
294 typedef std::map<RepListID,FactionState> FactionStateList;
296 typedef std::map<uint32,ReputationRank> ForcedReactions;
298 typedef std::set<uint64> GuardianPetList;
300 struct EnchantDuration
302 EnchantDuration() : item(NULL), slot(MAX_ENCHANTMENT_SLOT), leftduration(0) {};
303 EnchantDuration(Item * _item, EnchantmentSlot _slot, uint32 _leftduration) : item(_item), slot(_slot), leftduration(_leftduration) { assert(item); };
305 Item * item;
306 EnchantmentSlot slot;
307 uint32 leftduration;
310 typedef std::list<EnchantDuration> EnchantDurationList;
311 typedef std::list<Item*> ItemDurationList;
313 struct LookingForGroupSlot
315 LookingForGroupSlot() : entry(0), type(0) {}
316 bool Empty() const { return !entry && !type; }
317 void Clear() { entry = 0; type = 0; }
318 void Set(uint32 _entry, uint32 _type ) { entry = _entry; type = _type; }
319 bool Is(uint32 _entry, uint32 _type) const { return entry==_entry && type==_type; }
320 bool canAutoJoin() const { return entry && (type == 1 || type == 5); }
322 uint32 entry;
323 uint32 type;
326 #define MAX_LOOKING_FOR_GROUP_SLOT 3
328 struct LookingForGroup
330 LookingForGroup() {}
331 bool HaveInSlot(LookingForGroupSlot const& slot) const { return HaveInSlot(slot.entry,slot.type); }
332 bool HaveInSlot(uint32 _entry, uint32 _type) const
334 for(int i = 0; i < MAX_LOOKING_FOR_GROUP_SLOT; ++i)
335 if(slots[i].Is(_entry,_type))
336 return true;
337 return false;
340 bool canAutoJoin() const
342 for(int i = 0; i < MAX_LOOKING_FOR_GROUP_SLOT; ++i)
343 if(slots[i].canAutoJoin())
344 return true;
345 return false;
348 bool Empty() const
350 for(int i = 0; i < MAX_LOOKING_FOR_GROUP_SLOT; ++i)
351 if(!slots[i].Empty())
352 return false;
353 return more.Empty();
356 LookingForGroupSlot slots[MAX_LOOKING_FOR_GROUP_SLOT];
357 LookingForGroupSlot more;
358 std::string comment;
361 enum PlayerMovementType
363 MOVE_ROOT = 1,
364 MOVE_UNROOT = 2,
365 MOVE_WATER_WALK = 3,
366 MOVE_LAND_WALK = 4
369 enum DrunkenState
371 DRUNKEN_SOBER = 0,
372 DRUNKEN_TIPSY = 1,
373 DRUNKEN_DRUNK = 2,
374 DRUNKEN_SMASHED = 3
377 enum PlayerFlags
379 PLAYER_FLAGS_GROUP_LEADER = 0x00000001,
380 PLAYER_FLAGS_AFK = 0x00000002,
381 PLAYER_FLAGS_DND = 0x00000004,
382 PLAYER_FLAGS_GM = 0x00000008,
383 PLAYER_FLAGS_GHOST = 0x00000010,
384 PLAYER_FLAGS_RESTING = 0x00000020,
385 PLAYER_FLAGS_UNK7 = 0x00000040,
386 PLAYER_FLAGS_UNK8 = 0x00000080, // pre-3.0.3 PLAYER_FLAGS_FFA_PVP flag for FFA PVP state
387 PLAYER_FLAGS_CONTESTED_PVP = 0x00000100, // Player has been involved in a PvP combat and will be attacked by contested guards
388 PLAYER_FLAGS_IN_PVP = 0x00000200,
389 PLAYER_FLAGS_HIDE_HELM = 0x00000400,
390 PLAYER_FLAGS_HIDE_CLOAK = 0x00000800,
391 PLAYER_FLAGS_UNK13 = 0x00001000, // played long time
392 PLAYER_FLAGS_UNK14 = 0x00002000, // played too long time
393 PLAYER_FLAGS_UNK15 = 0x00004000,
394 PLAYER_FLAGS_UNK16 = 0x00008000, // strange visual effect (2.0.1), looks like PLAYER_FLAGS_GHOST flag
395 PLAYER_FLAGS_UNK17 = 0x00010000, // pre-3.0.3 PLAYER_FLAGS_SANCTUARY flag for player entered sanctuary
396 PLAYER_FLAGS_UNK18 = 0x00020000, // taxi benchmark mode (on/off) (2.0.1)
397 PLAYER_FLAGS_PVP_TIMER = 0x00040000, // 3.0.2, pvp timer active (after you disable pvp manually)
398 PLAYER_FLAGS_UNK20 = 0x00080000,
399 PLAYER_FLAGS_UNK21 = 0x00100000,
400 PLAYER_FLAGS_UNK22 = 0x00200000,
401 PLAYER_FLAGS_UNK23 = 0x00400000,
402 PLAYER_FLAGS_UNK24 = 0x00800000, // disabled all abilitys on tab except autoattack
403 PLAYER_FLAGS_UNK25 = 0x01000000, // disabled all melee ability on tab include autoattack
407 // used for PLAYER__FIELD_KNOWN_TITLES field (uint64), (1<<bit_index) without (-1)
408 // can't use enum for uint64 values
409 #define PLAYER_TITLE_DISABLED 0x0000000000000000LL
410 #define PLAYER_TITLE_NONE 0x0000000000000001LL
411 #define PLAYER_TITLE_PRIVATE 0x0000000000000002LL // 1
412 #define PLAYER_TITLE_CORPORAL 0x0000000000000004LL // 2
413 #define PLAYER_TITLE_SERGEANT_A 0x0000000000000008LL // 3
414 #define PLAYER_TITLE_MASTER_SERGEANT 0x0000000000000010LL // 4
415 #define PLAYER_TITLE_SERGEANT_MAJOR 0x0000000000000020LL // 5
416 #define PLAYER_TITLE_KNIGHT 0x0000000000000040LL // 6
417 #define PLAYER_TITLE_KNIGHT_LIEUTENANT 0x0000000000000080LL // 7
418 #define PLAYER_TITLE_KNIGHT_CAPTAIN 0x0000000000000100LL // 8
419 #define PLAYER_TITLE_KNIGHT_CHAMPION 0x0000000000000200LL // 9
420 #define PLAYER_TITLE_LIEUTENANT_COMMANDER 0x0000000000000400LL // 10
421 #define PLAYER_TITLE_COMMANDER 0x0000000000000800LL // 11
422 #define PLAYER_TITLE_MARSHAL 0x0000000000001000LL // 12
423 #define PLAYER_TITLE_FIELD_MARSHAL 0x0000000000002000LL // 13
424 #define PLAYER_TITLE_GRAND_MARSHAL 0x0000000000004000LL // 14
425 #define PLAYER_TITLE_SCOUT 0x0000000000008000LL // 15
426 #define PLAYER_TITLE_GRUNT 0x0000000000010000LL // 16
427 #define PLAYER_TITLE_SERGEANT_H 0x0000000000020000LL // 17
428 #define PLAYER_TITLE_SENIOR_SERGEANT 0x0000000000040000LL // 18
429 #define PLAYER_TITLE_FIRST_SERGEANT 0x0000000000080000LL // 19
430 #define PLAYER_TITLE_STONE_GUARD 0x0000000000100000LL // 20
431 #define PLAYER_TITLE_BLOOD_GUARD 0x0000000000200000LL // 21
432 #define PLAYER_TITLE_LEGIONNAIRE 0x0000000000400000LL // 22
433 #define PLAYER_TITLE_CENTURION 0x0000000000800000LL // 23
434 #define PLAYER_TITLE_CHAMPION 0x0000000001000000LL // 24
435 #define PLAYER_TITLE_LIEUTENANT_GENERAL 0x0000000002000000LL // 25
436 #define PLAYER_TITLE_GENERAL 0x0000000004000000LL // 26
437 #define PLAYER_TITLE_WARLORD 0x0000000008000000LL // 27
438 #define PLAYER_TITLE_HIGH_WARLORD 0x0000000010000000LL // 28
439 #define PLAYER_TITLE_GLADIATOR 0x0000000020000000LL // 29
440 #define PLAYER_TITLE_DUELIST 0x0000000040000000LL // 30
441 #define PLAYER_TITLE_RIVAL 0x0000000080000000LL // 31
442 #define PLAYER_TITLE_CHALLENGER 0x0000000100000000LL // 32
443 #define PLAYER_TITLE_SCARAB_LORD 0x0000000200000000LL // 33
444 #define PLAYER_TITLE_CONQUEROR 0x0000000400000000LL // 34
445 #define PLAYER_TITLE_JUSTICAR 0x0000000800000000LL // 35
446 #define PLAYER_TITLE_CHAMPION_OF_THE_NAARU 0x0000001000000000LL // 36
447 #define PLAYER_TITLE_MERCILESS_GLADIATOR 0x0000002000000000LL // 37
448 #define PLAYER_TITLE_OF_THE_SHATTERED_SUN 0x0000004000000000LL // 38
449 #define PLAYER_TITLE_HAND_OF_ADAL 0x0000008000000000LL // 39
450 #define PLAYER_TITLE_VENGEFUL_GLADIATOR 0x0000010000000000LL // 40
452 // used in PLAYER_FIELD_BYTES values
453 enum PlayerFieldByteFlags
455 PLAYER_FIELD_BYTE_TRACK_STEALTHED = 0x00000002,
456 PLAYER_FIELD_BYTE_RELEASE_TIMER = 0x00000008, // Display time till auto release spirit
457 PLAYER_FIELD_BYTE_NO_RELEASE_WINDOW = 0x00000010 // Display no "release spirit" window at all
460 // used in PLAYER_FIELD_BYTES2 values
461 enum PlayerFieldByte2Flags
463 PLAYER_FIELD_BYTE2_NONE = 0x0000,
464 PLAYER_FIELD_BYTE2_INVISIBILITY_GLOW = 0x4000
467 enum ActivateTaxiReplies
469 ERR_TAXIOK = 0,
470 ERR_TAXIUNSPECIFIEDSERVERERROR = 1,
471 ERR_TAXINOSUCHPATH = 2,
472 ERR_TAXINOTENOUGHMONEY = 3,
473 ERR_TAXITOOFARAWAY = 4,
474 ERR_TAXINOVENDORNEARBY = 5,
475 ERR_TAXINOTVISITED = 6,
476 ERR_TAXIPLAYERBUSY = 7,
477 ERR_TAXIPLAYERALREADYMOUNTED = 8,
478 ERR_TAXIPLAYERSHAPESHIFTED = 9,
479 ERR_TAXIPLAYERMOVING = 10,
480 ERR_TAXISAMENODE = 11,
481 ERR_TAXINOTSTANDING = 12
484 enum LootType
486 LOOT_CORPSE = 1,
487 LOOT_SKINNING = 2,
488 LOOT_FISHING = 3,
489 LOOT_PICKPOCKETING = 4, // unsupported by client, sending LOOT_SKINNING instead
490 LOOT_DISENCHANTING = 5, // unsupported by client, sending LOOT_SKINNING instead
491 LOOT_PROSPECTING = 6, // unsupported by client, sending LOOT_SKINNING instead
492 LOOT_INSIGNIA = 7, // unsupported by client, sending LOOT_SKINNING instead
493 LOOT_FISHINGHOLE = 8, // unsupported by client, sending LOOT_FISHING instead
494 LOOT_MILLING = 9 // unsupported by client, sending LOOT_SKINNING instead
497 enum MirrorTimerType
499 FATIGUE_TIMER = 0,
500 BREATH_TIMER = 1,
501 FIRE_TIMER = 2
504 // 2^n values
505 enum PlayerExtraFlags
507 // gm abilities
508 PLAYER_EXTRA_GM_ON = 0x0001,
509 PLAYER_EXTRA_GM_ACCEPT_TICKETS = 0x0002,
510 PLAYER_EXTRA_ACCEPT_WHISPERS = 0x0004,
511 PLAYER_EXTRA_TAXICHEAT = 0x0008,
512 PLAYER_EXTRA_GM_INVISIBLE = 0x0010,
513 PLAYER_EXTRA_GM_CHAT = 0x0020, // Show GM badge in chat messages
515 // other states
516 PLAYER_EXTRA_PVP_DEATH = 0x0100 // store PvP death status until corpse creating.
519 // 2^n values
520 enum AtLoginFlags
522 AT_LOGIN_NONE = 0,
523 AT_LOGIN_RENAME = 1,
524 AT_LOGIN_RESET_SPELLS = 2,
525 AT_LOGIN_RESET_TALENTS = 4,
526 AT_LOGIN_CUSTOMIZE = 8
529 typedef std::map<uint32, QuestStatusData> QuestStatusMap;
531 enum QuestSlotOffsets
533 QUEST_ID_OFFSET = 0,
534 QUEST_STATE_OFFSET = 1,
535 QUEST_COUNTS_OFFSET = 2,
536 QUEST_TIME_OFFSET = 3
539 #define MAX_QUEST_OFFSET 4
541 enum QuestSlotStateMask
543 QUEST_STATE_NONE = 0x0000,
544 QUEST_STATE_COMPLETE = 0x0001,
545 QUEST_STATE_FAIL = 0x0002
548 class Quest;
549 class Spell;
550 class Item;
551 class WorldSession;
553 enum PlayerSlots
555 // first slot for item stored (in any way in player m_items data)
556 PLAYER_SLOT_START = 0,
557 // last+1 slot for item stored (in any way in player m_items data)
558 PLAYER_SLOT_END = 200,
559 PLAYER_SLOTS_COUNT = (PLAYER_SLOT_END - PLAYER_SLOT_START)
562 enum EquipmentSlots
564 EQUIPMENT_SLOT_START = 0,
565 EQUIPMENT_SLOT_HEAD = 0,
566 EQUIPMENT_SLOT_NECK = 1,
567 EQUIPMENT_SLOT_SHOULDERS = 2,
568 EQUIPMENT_SLOT_BODY = 3,
569 EQUIPMENT_SLOT_CHEST = 4,
570 EQUIPMENT_SLOT_WAIST = 5,
571 EQUIPMENT_SLOT_LEGS = 6,
572 EQUIPMENT_SLOT_FEET = 7,
573 EQUIPMENT_SLOT_WRISTS = 8,
574 EQUIPMENT_SLOT_HANDS = 9,
575 EQUIPMENT_SLOT_FINGER1 = 10,
576 EQUIPMENT_SLOT_FINGER2 = 11,
577 EQUIPMENT_SLOT_TRINKET1 = 12,
578 EQUIPMENT_SLOT_TRINKET2 = 13,
579 EQUIPMENT_SLOT_BACK = 14,
580 EQUIPMENT_SLOT_MAINHAND = 15,
581 EQUIPMENT_SLOT_OFFHAND = 16,
582 EQUIPMENT_SLOT_RANGED = 17,
583 EQUIPMENT_SLOT_TABARD = 18,
584 EQUIPMENT_SLOT_END = 19
587 enum InventorySlots
589 INVENTORY_SLOT_BAG_0 = 255,
590 INVENTORY_SLOT_BAG_START = 19,
591 INVENTORY_SLOT_BAG_1 = 19,
592 INVENTORY_SLOT_BAG_2 = 20,
593 INVENTORY_SLOT_BAG_3 = 21,
594 INVENTORY_SLOT_BAG_4 = 22,
595 INVENTORY_SLOT_BAG_END = 23,
597 INVENTORY_SLOT_ITEM_START = 23,
598 INVENTORY_SLOT_ITEM_1 = 23,
599 INVENTORY_SLOT_ITEM_2 = 24,
600 INVENTORY_SLOT_ITEM_3 = 25,
601 INVENTORY_SLOT_ITEM_4 = 26,
602 INVENTORY_SLOT_ITEM_5 = 27,
603 INVENTORY_SLOT_ITEM_6 = 28,
604 INVENTORY_SLOT_ITEM_7 = 29,
605 INVENTORY_SLOT_ITEM_8 = 30,
606 INVENTORY_SLOT_ITEM_9 = 31,
607 INVENTORY_SLOT_ITEM_10 = 32,
608 INVENTORY_SLOT_ITEM_11 = 33,
609 INVENTORY_SLOT_ITEM_12 = 34,
610 INVENTORY_SLOT_ITEM_13 = 35,
611 INVENTORY_SLOT_ITEM_14 = 36,
612 INVENTORY_SLOT_ITEM_15 = 37,
613 INVENTORY_SLOT_ITEM_16 = 38,
614 INVENTORY_SLOT_ITEM_END = 39
617 enum BankSlots
619 BANK_SLOT_ITEM_START = 39,
620 BANK_SLOT_ITEM_1 = 39,
621 BANK_SLOT_ITEM_2 = 40,
622 BANK_SLOT_ITEM_3 = 41,
623 BANK_SLOT_ITEM_4 = 42,
624 BANK_SLOT_ITEM_5 = 43,
625 BANK_SLOT_ITEM_6 = 44,
626 BANK_SLOT_ITEM_7 = 45,
627 BANK_SLOT_ITEM_8 = 46,
628 BANK_SLOT_ITEM_9 = 47,
629 BANK_SLOT_ITEM_10 = 48,
630 BANK_SLOT_ITEM_11 = 49,
631 BANK_SLOT_ITEM_12 = 50,
632 BANK_SLOT_ITEM_13 = 51,
633 BANK_SLOT_ITEM_14 = 52,
634 BANK_SLOT_ITEM_15 = 53,
635 BANK_SLOT_ITEM_16 = 54,
636 BANK_SLOT_ITEM_17 = 55,
637 BANK_SLOT_ITEM_18 = 56,
638 BANK_SLOT_ITEM_19 = 57,
639 BANK_SLOT_ITEM_20 = 58,
640 BANK_SLOT_ITEM_21 = 59,
641 BANK_SLOT_ITEM_22 = 60,
642 BANK_SLOT_ITEM_23 = 61,
643 BANK_SLOT_ITEM_24 = 62,
644 BANK_SLOT_ITEM_25 = 63,
645 BANK_SLOT_ITEM_26 = 64,
646 BANK_SLOT_ITEM_27 = 65,
647 BANK_SLOT_ITEM_28 = 66,
648 BANK_SLOT_ITEM_END = 67,
650 BANK_SLOT_BAG_START = 67,
651 BANK_SLOT_BAG_1 = 67,
652 BANK_SLOT_BAG_2 = 68,
653 BANK_SLOT_BAG_3 = 69,
654 BANK_SLOT_BAG_4 = 70,
655 BANK_SLOT_BAG_5 = 71,
656 BANK_SLOT_BAG_6 = 72,
657 BANK_SLOT_BAG_7 = 73,
658 BANK_SLOT_BAG_END = 74
661 enum BuyBackSlots
663 // stored in m_buybackitems
664 BUYBACK_SLOT_START = 74,
665 BUYBACK_SLOT_1 = 74,
666 BUYBACK_SLOT_2 = 75,
667 BUYBACK_SLOT_3 = 76,
668 BUYBACK_SLOT_4 = 77,
669 BUYBACK_SLOT_5 = 78,
670 BUYBACK_SLOT_6 = 79,
671 BUYBACK_SLOT_7 = 80,
672 BUYBACK_SLOT_8 = 81,
673 BUYBACK_SLOT_9 = 82,
674 BUYBACK_SLOT_10 = 83,
675 BUYBACK_SLOT_11 = 84,
676 BUYBACK_SLOT_12 = 85,
677 BUYBACK_SLOT_END = 86
680 enum KeyRingSlots
682 KEYRING_SLOT_START = 86,
683 KEYRING_SLOT_END = 118
686 enum VanityPetSlots
688 VANITYPET_SLOT_START = 118, // not use, vanity pets stored as spells
689 VANITYPET_SLOT_END = 136 // not alloed any content in.
692 enum CurrencyTokenSlots
694 CURRENCYTOKEN_SLOT_START = 136,
695 CURRENCYTOKEN_SLOT_END = 168
698 enum QuestBagSlots
700 QUESTBAG_SLOT_START = 168,
701 QUESTBAG_SLOT_END = 200
704 struct ItemPosCount
706 ItemPosCount(uint16 _pos, uint32 _count) : pos(_pos), count(_count) {}
707 bool isContainedIn(std::vector<ItemPosCount> const& vec) const;
708 uint16 pos;
709 uint32 count;
711 typedef std::vector<ItemPosCount> ItemPosCountVec;
713 enum TradeSlots
715 TRADE_SLOT_COUNT = 7,
716 TRADE_SLOT_TRADED_COUNT = 6,
717 TRADE_SLOT_NONTRADED = 6
720 enum TransferAbortReason
722 TRANSFER_ABORT_ERROR = 0x00,
723 TRANSFER_ABORT_MAX_PLAYERS = 0x01, // Transfer Aborted: instance is full
724 TRANSFER_ABORT_NOT_FOUND = 0x02, // Transfer Aborted: instance not found
725 TRANSFER_ABORT_TOO_MANY_INSTANCES = 0x03, // You have entered too many instances recently.
726 TRANSFER_ABORT_ZONE_IN_COMBAT = 0x05, // Unable to zone in while an encounter is in progress.
727 TRANSFER_ABORT_INSUF_EXPAN_LVL = 0x06, // You must have <TBC,WotLK> expansion installed to access this area.
728 TRANSFER_ABORT_DIFFICULTY = 0x07, // <Normal,Heroic,Epic> difficulty mode is not available for %s.
729 TRANSFER_ABORT_UNIQUE_MESSAGE = 0x08, // Until you've escaped TLK's grasp, you cannot leave this place!
730 TRANSFER_ABORT_TOO_MANY_REALM_INSTANCES = 0x09 // Additional instances cannot be launched, please try again later.
733 enum InstanceResetWarningType
735 RAID_INSTANCE_WARNING_HOURS = 1, // WARNING! %s is scheduled to reset in %d hour(s).
736 RAID_INSTANCE_WARNING_MIN = 2, // WARNING! %s is scheduled to reset in %d minute(s)!
737 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!
738 RAID_INSTANCE_WELCOME = 4 // Welcome to %s. This raid instance is scheduled to reset in %s.
741 struct MovementInfo
743 // common
744 uint32 flags;
745 uint16 unk1;
746 uint32 time;
747 float x, y, z, o;
748 // transport
749 uint64 t_guid;
750 float t_x, t_y, t_z, t_o;
751 uint32 t_time;
752 int8 t_seat;
753 // swimming and unknown
754 float s_pitch;
755 // last fall time
756 uint32 fallTime;
757 // jumping
758 float j_unk, j_sinAngle, j_cosAngle, j_xyspeed;
759 // spline
760 float u_unk1;
762 MovementInfo()
764 flags = 0;
765 time = t_time = fallTime = 0;
766 unk1 = 0;
767 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;
768 t_guid = 0;
771 void SetMovementFlags(uint32 _flags)
773 flags = _flags;
777 // flags that use in movement check for example at spell casting
778 MovementFlags const movementFlagsMask = MovementFlags(
779 MOVEMENTFLAG_FORWARD |MOVEMENTFLAG_BACKWARD |MOVEMENTFLAG_STRAFE_LEFT|MOVEMENTFLAG_STRAFE_RIGHT|
780 MOVEMENTFLAG_PITCH_UP|MOVEMENTFLAG_PITCH_DOWN|MOVEMENTFLAG_FLY_UNK1 |
781 MOVEMENTFLAG_JUMPING |MOVEMENTFLAG_FALLING |MOVEMENTFLAG_FLY_UP |
782 MOVEMENTFLAG_FLYING |MOVEMENTFLAG_SPLINE
785 MovementFlags const movementOrTurningFlagsMask = MovementFlags(
786 movementFlagsMask | MOVEMENTFLAG_LEFT | MOVEMENTFLAG_RIGHT
788 class InstanceSave;
790 enum RestType
792 REST_TYPE_NO = 0,
793 REST_TYPE_IN_TAVERN = 1,
794 REST_TYPE_IN_CITY = 2
797 enum DuelCompleteType
799 DUEL_INTERUPTED = 0,
800 DUEL_WON = 1,
801 DUEL_FLED = 2
804 enum TeleportToOptions
806 TELE_TO_GM_MODE = 0x01,
807 TELE_TO_NOT_LEAVE_TRANSPORT = 0x02,
808 TELE_TO_NOT_LEAVE_COMBAT = 0x04,
809 TELE_TO_NOT_UNSUMMON_PET = 0x08,
810 TELE_TO_SPELL = 0x10,
813 /// Type of environmental damages
814 enum EnviromentalDamage
816 DAMAGE_EXHAUSTED = 0,
817 DAMAGE_DROWNING = 1,
818 DAMAGE_FALL = 2,
819 DAMAGE_LAVA = 3,
820 DAMAGE_SLIME = 4,
821 DAMAGE_FIRE = 5,
822 DAMAGE_FALL_TO_VOID = 6 // custom case for fall without durability loss
825 // used at player loading query list preparing, and later result selection
826 enum PlayerLoginQueryIndex
828 PLAYER_LOGIN_QUERY_LOADFROM = 0,
829 PLAYER_LOGIN_QUERY_LOADGROUP = 1,
830 PLAYER_LOGIN_QUERY_LOADBOUNDINSTANCES = 2,
831 PLAYER_LOGIN_QUERY_LOADAURAS = 3,
832 PLAYER_LOGIN_QUERY_LOADSPELLS = 4,
833 PLAYER_LOGIN_QUERY_LOADQUESTSTATUS = 5,
834 PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS = 6,
835 PLAYER_LOGIN_QUERY_LOADTUTORIALS = 7, // common for all characters for some account at specific realm
836 PLAYER_LOGIN_QUERY_LOADREPUTATION = 8,
837 PLAYER_LOGIN_QUERY_LOADINVENTORY = 9,
838 PLAYER_LOGIN_QUERY_LOADACTIONS = 10,
839 PLAYER_LOGIN_QUERY_LOADMAILCOUNT = 11,
840 PLAYER_LOGIN_QUERY_LOADMAILDATE = 12,
841 PLAYER_LOGIN_QUERY_LOADSOCIALLIST = 13,
842 PLAYER_LOGIN_QUERY_LOADHOMEBIND = 14,
843 PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS = 15,
844 PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES = 16,
845 PLAYER_LOGIN_QUERY_LOADGUILD = 17,
846 PLAYER_LOGIN_QUERY_LOADARENAINFO = 18,
847 PLAYER_LOGIN_QUERY_LOADACHIEVEMENTS = 19,
848 PLAYER_LOGIN_QUERY_LOADCRITERIAPROGRESS = 20,
849 MAX_PLAYER_LOGIN_QUERY = 21
853 // Player summoning auto-decline time (in secs)
854 #define MAX_PLAYER_SUMMON_DELAY (2*MINUTE)
855 #define MAX_MONEY_AMOUNT (0x7FFFFFFF-1)
857 struct InstancePlayerBind
859 InstanceSave *save;
860 bool perm;
861 /* permanent PlayerInstanceBinds are created in Raid/Heroic instances for players
862 that aren't already permanently bound when they are inside when a boss is killed
863 or when they enter an instance that the group leader is permanently bound to. */
864 InstancePlayerBind() : save(NULL), perm(false) {}
867 class MANGOS_DLL_SPEC PlayerTaxi
869 public:
870 PlayerTaxi();
871 ~PlayerTaxi() {}
872 // Nodes
873 void InitTaxiNodesForLevel(uint32 race, uint32 chrClass, uint32 level);
874 void LoadTaxiMask(const char* data);
876 bool IsTaximaskNodeKnown(uint32 nodeidx) const
878 uint8 field = uint8((nodeidx - 1) / 32);
879 uint32 submask = 1<<((nodeidx-1)%32);
880 return (m_taximask[field] & submask) == submask;
882 bool SetTaximaskNode(uint32 nodeidx)
884 uint8 field = uint8((nodeidx - 1) / 32);
885 uint32 submask = 1<<((nodeidx-1)%32);
886 if ((m_taximask[field] & submask) != submask )
888 m_taximask[field] |= submask;
889 return true;
891 else
892 return false;
894 void AppendTaximaskTo(ByteBuffer& data,bool all);
896 // Destinations
897 bool LoadTaxiDestinationsFromString(const std::string& values, uint32 team);
898 std::string SaveTaxiDestinationsToString();
900 void ClearTaxiDestinations() { m_TaxiDestinations.clear(); }
901 void AddTaxiDestination(uint32 dest) { m_TaxiDestinations.push_back(dest); }
902 uint32 GetTaxiSource() const { return m_TaxiDestinations.empty() ? 0 : m_TaxiDestinations.front(); }
903 uint32 GetTaxiDestination() const { return m_TaxiDestinations.size() < 2 ? 0 : m_TaxiDestinations[1]; }
904 uint32 GetCurrentTaxiPath() const;
905 uint32 NextTaxiDestination()
907 m_TaxiDestinations.pop_front();
908 return GetTaxiDestination();
910 bool empty() const { return m_TaxiDestinations.empty(); }
912 friend std::ostringstream& operator<< (std::ostringstream& ss, PlayerTaxi const& taxi);
913 private:
914 TaxiMask m_taximask;
915 std::deque<uint32> m_TaxiDestinations;
918 std::ostringstream& operator<< (std::ostringstream& ss, PlayerTaxi const& taxi);
920 class MANGOS_DLL_SPEC Player : public Unit
922 friend class WorldSession;
923 friend void Item::AddToUpdateQueueOf(Player *player);
924 friend void Item::RemoveFromUpdateQueueOf(Player *player);
925 public:
926 explicit Player (WorldSession *session);
927 ~Player ( );
929 void CleanupsBeforeDelete();
931 static UpdateMask updateVisualBits;
932 static void InitVisibleBits();
934 void AddToWorld();
935 void RemoveFromWorld();
937 bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options = 0);
939 bool TeleportTo(WorldLocation const &loc, uint32 options = 0)
941 return TeleportTo(loc.mapid, loc.x, loc.y, loc.z, options);
944 void SetSummonPoint(uint32 mapid, float x, float y, float z)
946 m_summon_expire = time(NULL) + MAX_PLAYER_SUMMON_DELAY;
947 m_summon_mapid = mapid;
948 m_summon_x = x;
949 m_summon_y = y;
950 m_summon_z = z;
952 void SummonIfPossible(bool agree);
954 bool Create( uint32 guidlow, const std::string& name, uint8 race, uint8 class_, uint8 gender, uint8 skin, uint8 face, uint8 hairStyle, uint8 hairColor, uint8 facialHair, uint8 outfitId );
956 void Update( uint32 time );
958 void BuildEnumData( QueryResult * result, WorldPacket * p_data );
960 void SetInWater(bool apply);
962 bool IsInWater() const { return m_isInWater; }
963 bool IsUnderWater() const;
965 void SendInitialPacketsBeforeAddToMap();
966 void SendInitialPacketsAfterAddToMap();
967 void SendTransferAborted(uint32 mapid, uint8 reason, uint8 arg = 0);
968 void SendInstanceResetWarning(uint32 mapid, uint32 time);
970 bool CanInteractWithNPCs(bool alive = true) const;
972 bool ToggleAFK();
973 bool ToggleDND();
974 bool isAFK() const { return HasFlag(PLAYER_FLAGS,PLAYER_FLAGS_AFK); };
975 bool isDND() const { return HasFlag(PLAYER_FLAGS,PLAYER_FLAGS_DND); };
976 uint8 chatTag() const;
977 std::string afkMsg;
978 std::string dndMsg;
980 uint32 GetBarberShopCost(uint8 newhairstyle, uint8 newhaircolor, uint8 newfacialhair);
982 PlayerSocial *GetSocial() { return m_social; }
984 PlayerTaxi m_taxi;
985 void InitTaxiNodesForLevel() { m_taxi.InitTaxiNodesForLevel(getRace(), getClass(), getLevel()); }
986 bool ActivateTaxiPathTo(std::vector<uint32> const& nodes, uint32 mount_id = 0 , Creature* npc = NULL);
987 // mount_id can be used in scripting calls
988 bool isAcceptTickets() const { return GetSession()->GetSecurity() >= SEC_GAMEMASTER && (m_ExtraFlags & PLAYER_EXTRA_GM_ACCEPT_TICKETS); }
989 void SetAcceptTicket(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_GM_ACCEPT_TICKETS; else m_ExtraFlags &= ~PLAYER_EXTRA_GM_ACCEPT_TICKETS; }
990 bool isAcceptWhispers() const { return m_ExtraFlags & PLAYER_EXTRA_ACCEPT_WHISPERS; }
991 void SetAcceptWhispers(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_ACCEPT_WHISPERS; else m_ExtraFlags &= ~PLAYER_EXTRA_ACCEPT_WHISPERS; }
992 bool isGameMaster() const { return m_ExtraFlags & PLAYER_EXTRA_GM_ON; }
993 void SetGameMaster(bool on);
994 bool isGMChat() const { return GetSession()->GetSecurity() >= SEC_MODERATOR && (m_ExtraFlags & PLAYER_EXTRA_GM_CHAT); }
995 void SetGMChat(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_GM_CHAT; else m_ExtraFlags &= ~PLAYER_EXTRA_GM_CHAT; }
996 bool isTaxiCheater() const { return m_ExtraFlags & PLAYER_EXTRA_TAXICHEAT; }
997 void SetTaxiCheater(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_TAXICHEAT; else m_ExtraFlags &= ~PLAYER_EXTRA_TAXICHEAT; }
998 bool isGMVisible() const { return !(m_ExtraFlags & PLAYER_EXTRA_GM_INVISIBLE); }
999 void SetGMVisible(bool on);
1000 void SetPvPDeath(bool on) { if(on) m_ExtraFlags |= PLAYER_EXTRA_PVP_DEATH; else m_ExtraFlags &= ~PLAYER_EXTRA_PVP_DEATH; }
1002 void GiveXP(uint32 xp, Unit* victim);
1003 void GiveLevel(uint32 level);
1004 void InitStatsForLevel(bool reapplyMods = false);
1006 // Played Time Stuff
1007 time_t m_logintime;
1008 time_t m_Last_tick;
1009 uint32 m_Played_time[2];
1010 uint32 GetTotalPlayedTime() { return m_Played_time[0]; };
1011 uint32 GetLevelPlayedTime() { return m_Played_time[1]; };
1013 void setDeathState(DeathState s); // overwrite Unit::setDeathState
1015 void InnEnter (int time,uint32 mapid, float x,float y,float z)
1017 inn_pos_mapid = mapid;
1018 inn_pos_x = x;
1019 inn_pos_y = y;
1020 inn_pos_z = z;
1021 time_inn_enter = time;
1024 float GetRestBonus() const { return m_rest_bonus; };
1025 void SetRestBonus(float rest_bonus_new);
1027 RestType GetRestType() const { return rest_type; };
1028 void SetRestType(RestType n_r_type) { rest_type = n_r_type; };
1030 uint32 GetInnPosMapId() const { return inn_pos_mapid; };
1031 float GetInnPosX() const { return inn_pos_x; };
1032 float GetInnPosY() const { return inn_pos_y; };
1033 float GetInnPosZ() const { return inn_pos_z; };
1035 int GetTimeInnEnter() const { return time_inn_enter; };
1036 void UpdateInnerTime (int time) { time_inn_enter = time; };
1038 void RemovePet(Pet* pet, PetSaveMode mode, bool returnreagent = false);
1039 void RemoveMiniPet();
1040 Pet* GetMiniPet();
1041 void SetMiniPet(Pet* pet) { m_miniPet = pet->GetGUID(); }
1042 void RemoveGuardians();
1043 bool HasGuardianWithEntry(uint32 entry);
1044 void AddGuardian(Pet* pet) { m_guardianPets.insert(pet->GetGUID()); }
1045 GuardianPetList const& GetGuardians() const { return m_guardianPets; }
1046 void Uncharm();
1047 uint32 GetPhaseMaskForSpawn() const; // used for proper set phase for DB at GM-mode creature/GO spawn
1049 void Say(const std::string& text, const uint32 language);
1050 void Yell(const std::string& text, const uint32 language);
1051 void TextEmote(const std::string& text);
1052 void Whisper(const std::string& text, const uint32 language,uint64 receiver);
1053 void BuildPlayerChat(WorldPacket *data, uint8 msgtype, const std::string& text, uint32 language) const;
1055 /*********************************************************/
1056 /*** STORAGE SYSTEM ***/
1057 /*********************************************************/
1059 void SetVirtualItemSlot( uint8 i, Item* item);
1060 void SetSheath( uint32 sheathed );
1061 uint8 FindEquipSlot( ItemPrototype const* proto, uint32 slot, bool swap ) const;
1062 uint32 GetItemCount( uint32 item, bool inBankAlso = false, Item* skipItem = NULL ) const;
1063 Item* GetItemByGuid( uint64 guid ) const;
1064 Item* GetItemByPos( uint16 pos ) const;
1065 Item* GetItemByPos( uint8 bag, uint8 slot ) const;
1066 Item* GetWeaponForAttack(WeaponAttackType attackType, bool useable = false) const;
1067 Item* GetShield(bool useable = false) const;
1068 static uint32 GetAttackBySlot( uint8 slot ); // MAX_ATTACK if not weapon slot
1069 std::vector<Item *> &GetItemUpdateQueue() { return m_itemUpdateQueue; }
1070 static bool IsInventoryPos( uint16 pos ) { return IsInventoryPos(pos >> 8,pos & 255); }
1071 static bool IsInventoryPos( uint8 bag, uint8 slot );
1072 static bool IsEquipmentPos( uint16 pos ) { return IsEquipmentPos(pos >> 8,pos & 255); }
1073 static bool IsEquipmentPos( uint8 bag, uint8 slot );
1074 static bool IsBagPos( uint16 pos );
1075 static bool IsBankPos( uint16 pos ) { return IsBankPos(pos >> 8,pos & 255); }
1076 static bool IsBankPos( uint8 bag, uint8 slot );
1077 bool IsValidPos( uint16 pos ) { return IsBankPos(pos >> 8,pos & 255); }
1078 bool IsValidPos( uint8 bag, uint8 slot );
1079 bool HasBankBagSlot( uint8 slot ) const;
1080 bool HasItemCount( uint32 item, uint32 count, bool inBankAlso = false ) const;
1081 bool HasItemFitToSpellReqirements(SpellEntry const* spellInfo, Item const* ignoreItem = NULL);
1082 bool CanNoReagentCast(SpellEntry const* spellInfo) const;
1083 bool HasItemOrGemWithIdEquipped( uint32 item, uint32 count, uint8 except_slot = NULL_SLOT) const;
1084 bool HasItemOrGemWithLimitCategoryEquipped( uint32 limitCategory, uint32 count, uint8 except_slot = NULL_SLOT) const;
1085 uint8 CanTakeMoreSimilarItems(Item* pItem) const { return _CanTakeMoreSimilarItems(pItem->GetEntry(),pItem->GetCount(),pItem); }
1086 uint8 CanTakeMoreSimilarItems(uint32 entry, uint32 count) const { return _CanTakeMoreSimilarItems(entry,count,NULL); }
1087 uint8 CanStoreNewItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 item, uint32 count, uint32* no_space_count = NULL ) const
1089 return _CanStoreItem(bag, slot, dest, item, count, NULL, false, no_space_count );
1091 uint8 CanStoreItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, Item *pItem, bool swap = false ) const
1093 if(!pItem)
1094 return EQUIP_ERR_ITEM_NOT_FOUND;
1095 uint32 count = pItem->GetCount();
1096 return _CanStoreItem( bag, slot, dest, pItem->GetEntry(), count, pItem, swap, NULL );
1099 uint8 CanStoreItems( Item **pItem,int count) const;
1100 uint8 CanEquipNewItem( uint8 slot, uint16 &dest, uint32 item, bool swap ) const;
1101 uint8 CanEquipItem( uint8 slot, uint16 &dest, Item *pItem, bool swap, bool not_loading = true ) const;
1103 uint8 CanEquipUniqueItem( Item * pItem, uint8 except_slot = NULL_SLOT, uint32 limit_count = 1 ) const;
1104 uint8 CanEquipUniqueItem( ItemPrototype const* itemProto, uint8 except_slot = NULL_SLOT, uint32 limit_count = 1 ) const;
1105 uint8 CanUnequipItems( uint32 item, uint32 count ) const;
1106 uint8 CanUnequipItem( uint16 src, bool swap ) const;
1107 uint8 CanBankItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, Item *pItem, bool swap, bool not_loading = true ) const;
1108 uint8 CanUseItem( Item *pItem, bool not_loading = true ) const;
1109 bool HasItemTotemCategory( uint32 TotemCategory ) const;
1110 bool CanUseItem( ItemPrototype const *pItem );
1111 uint8 CanUseAmmo( uint32 item ) const;
1112 Item* StoreNewItem( ItemPosCountVec const& pos, uint32 item, bool update,int32 randomPropertyId = 0 );
1113 Item* StoreItem( ItemPosCountVec const& pos, Item *pItem, bool update );
1114 Item* EquipNewItem( uint16 pos, uint32 item, bool update );
1115 Item* EquipItem( uint16 pos, Item *pItem, bool update );
1116 void AutoUnequipOffhandIfNeed();
1117 bool StoreNewItemInBestSlots(uint32 item_id, uint32 item_count);
1118 void AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, bool broadcast = false);
1119 void AutoStoreLoot(uint32 loot_id, LootStore const& store, bool broadcast = false) { AutoStoreLoot(NULL_BAG,NULL_SLOT,loot_id,store,broadcast); }
1121 uint8 _CanTakeMoreSimilarItems(uint32 entry, uint32 count, Item* pItem, uint32* no_space_count = NULL) const;
1122 uint8 _CanStoreItem( uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 entry, uint32 count, Item *pItem = NULL, bool swap = false, uint32* no_space_count = NULL ) const;
1124 void ApplyEquipCooldown( Item * pItem );
1125 void SetAmmo( uint32 item );
1126 void RemoveAmmo();
1127 float GetAmmoDPS() const { return m_ammoDPS; }
1128 bool CheckAmmoCompatibility(const ItemPrototype *ammo_proto) const;
1129 void QuickEquipItem( uint16 pos, Item *pItem);
1130 void VisualizeItem( uint8 slot, Item *pItem);
1131 void SetVisibleItemSlot(uint8 slot, Item *pItem);
1132 Item* BankItem( ItemPosCountVec const& dest, Item *pItem, bool update )
1134 return StoreItem( dest, pItem, update);
1136 Item* BankItem( uint16 pos, Item *pItem, bool update );
1137 void RemoveItem( uint8 bag, uint8 slot, bool update );
1138 void MoveItemFromInventory(uint8 bag, uint8 slot, bool update);
1139 // in trade, auction, guild bank, mail....
1140 void MoveItemToInventory(ItemPosCountVec const& dest, Item* pItem, bool update, bool in_characterInventoryDB = false);
1141 // in trade, guild bank, mail....
1142 void RemoveItemDependentAurasAndCasts( Item * pItem );
1143 void DestroyItem( uint8 bag, uint8 slot, bool update );
1144 void DestroyItemCount( uint32 item, uint32 count, bool update, bool unequip_check = false);
1145 void DestroyItemCount( Item* item, uint32& count, bool update );
1146 void DestroyConjuredItems( bool update );
1147 void DestroyZoneLimitedItem( bool update, uint32 new_zone );
1148 void SplitItem( uint16 src, uint16 dst, uint32 count );
1149 void SwapItem( uint16 src, uint16 dst );
1150 void AddItemToBuyBackSlot( Item *pItem );
1151 Item* GetItemFromBuyBackSlot( uint32 slot );
1152 void RemoveItemFromBuyBackSlot( uint32 slot, bool del );
1153 uint32 GetMaxKeyringSize() const { return KEYRING_SLOT_END-KEYRING_SLOT_START; }
1154 void SendEquipError( uint8 msg, Item* pItem, Item *pItem2 );
1155 void SendBuyError( uint8 msg, Creature* pCreature, uint32 item, uint32 param );
1156 void SendSellError( uint8 msg, Creature* pCreature, uint64 guid, uint32 param );
1157 void AddWeaponProficiency(uint32 newflag) { m_WeaponProficiency |= newflag; }
1158 void AddArmorProficiency(uint32 newflag) { m_ArmorProficiency |= newflag; }
1159 uint32 GetWeaponProficiency() const { return m_WeaponProficiency; }
1160 uint32 GetArmorProficiency() const { return m_ArmorProficiency; }
1161 bool IsInFeralForm() const { return m_form == FORM_CAT || m_form == FORM_BEAR || m_form == FORM_DIREBEAR; }
1162 bool IsUseEquipedWeapon( bool mainhand ) const
1164 // disarm applied only to mainhand weapon
1165 return !IsInFeralForm() && (!mainhand || !HasFlag(UNIT_FIELD_FLAGS,UNIT_FLAG_DISARMED) );
1167 bool IsTwoHandUsed() const
1169 Item* mainItem = GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
1170 return mainItem && mainItem->GetProto()->InventoryType == INVTYPE_2HWEAPON && !CanTitanGrip();
1172 void SendNewItem( Item *item, uint32 count, bool received, bool created, bool broadcast = false );
1173 bool BuyItemFromVendor(uint64 vendorguid, uint32 item, uint8 count, uint64 bagguid, uint8 slot);
1175 float GetReputationPriceDiscount( Creature const* pCreature ) const;
1176 Player* GetTrader() const { return pTrader; }
1177 void ClearTrade();
1178 void TradeCancel(bool sendback);
1179 uint16 GetItemPosByTradeSlot(uint32 slot) const { return tradeItems[slot]; }
1181 void UpdateEnchantTime(uint32 time);
1182 void UpdateItemDuration(uint32 time, bool realtimeonly=false);
1183 void AddEnchantmentDurations(Item *item);
1184 void RemoveEnchantmentDurations(Item *item);
1185 void RemoveAllEnchantments(EnchantmentSlot slot);
1186 void AddEnchantmentDuration(Item *item,EnchantmentSlot slot,uint32 duration);
1187 void ApplyEnchantment(Item *item,EnchantmentSlot slot,bool apply, bool apply_dur = true, bool ignore_condition = false);
1188 void ApplyEnchantment(Item *item,bool apply);
1189 void SendEnchantmentDurations();
1190 void AddItemDurations(Item *item);
1191 void RemoveItemDurations(Item *item);
1192 void SendItemDurations();
1193 void LoadCorpse();
1194 void LoadPet();
1196 uint32 m_stableSlots;
1198 /*********************************************************/
1199 /*** QUEST SYSTEM ***/
1200 /*********************************************************/
1202 void PrepareQuestMenu( uint64 guid );
1203 void SendPreparedQuest( uint64 guid );
1204 bool IsActiveQuest( uint32 quest_id ) const;
1205 Quest const *GetNextQuest( uint64 guid, Quest const *pQuest );
1206 bool CanSeeStartQuest( Quest const *pQuest );
1207 bool CanTakeQuest( Quest const *pQuest, bool msg );
1208 bool CanAddQuest( Quest const *pQuest, bool msg );
1209 bool CanCompleteQuest( uint32 quest_id );
1210 bool CanCompleteRepeatableQuest(Quest const *pQuest);
1211 bool CanRewardQuest( Quest const *pQuest, bool msg );
1212 bool CanRewardQuest( Quest const *pQuest, uint32 reward, bool msg );
1213 void AddQuest( Quest const *pQuest, Object *questGiver );
1214 void CompleteQuest( uint32 quest_id );
1215 void IncompleteQuest( uint32 quest_id );
1216 void RewardQuest( Quest const *pQuest, uint32 reward, Object* questGiver, bool announce = true );
1217 void FailQuest( uint32 quest_id );
1218 void FailTimedQuest( uint32 quest_id );
1219 bool SatisfyQuestSkillOrClass( Quest const* qInfo, bool msg );
1220 bool SatisfyQuestLevel( Quest const* qInfo, bool msg );
1221 bool SatisfyQuestLog( bool msg );
1222 bool SatisfyQuestPreviousQuest( Quest const* qInfo, bool msg );
1223 bool SatisfyQuestRace( Quest const* qInfo, bool msg );
1224 bool SatisfyQuestReputation( Quest const* qInfo, bool msg );
1225 bool SatisfyQuestStatus( Quest const* qInfo, bool msg );
1226 bool SatisfyQuestTimed( Quest const* qInfo, bool msg );
1227 bool SatisfyQuestExclusiveGroup( Quest const* qInfo, bool msg );
1228 bool SatisfyQuestNextChain( Quest const* qInfo, bool msg );
1229 bool SatisfyQuestPrevChain( Quest const* qInfo, bool msg );
1230 bool SatisfyQuestDay( Quest const* qInfo, bool msg );
1231 bool GiveQuestSourceItem( Quest const *pQuest );
1232 bool TakeQuestSourceItem( uint32 quest_id, bool msg );
1233 bool GetQuestRewardStatus( uint32 quest_id ) const;
1234 QuestStatus GetQuestStatus( uint32 quest_id ) const;
1235 void SetQuestStatus( uint32 quest_id, QuestStatus status );
1237 void SetDailyQuestStatus( uint32 quest_id );
1238 void ResetDailyQuestStatus();
1240 uint16 FindQuestSlot( uint32 quest_id ) const;
1241 uint32 GetQuestSlotQuestId(uint16 slot) const { return GetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_ID_OFFSET); }
1242 uint32 GetQuestSlotState(uint16 slot) const { return GetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_STATE_OFFSET); }
1243 uint32 GetQuestSlotCounters(uint16 slot)const { return GetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_COUNTS_OFFSET); }
1244 uint8 GetQuestSlotCounter(uint16 slot,uint8 counter) const { return GetByteValue(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_COUNTS_OFFSET,counter); }
1245 uint32 GetQuestSlotTime(uint16 slot) const { return GetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_TIME_OFFSET); }
1246 void SetQuestSlot(uint16 slot,uint32 quest_id, uint32 timer = 0)
1248 SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_ID_OFFSET,quest_id);
1249 SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_STATE_OFFSET,0);
1250 SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_COUNTS_OFFSET,0);
1251 SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_TIME_OFFSET,timer);
1253 void SetQuestSlotCounter(uint16 slot,uint8 counter,uint8 count) { SetByteValue(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_COUNTS_OFFSET,counter,count); }
1254 void SetQuestSlotState(uint16 slot,uint32 state) { SetFlag(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_STATE_OFFSET,state); }
1255 void RemoveQuestSlotState(uint16 slot,uint32 state) { RemoveFlag(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_STATE_OFFSET,state); }
1256 void SetQuestSlotTimer(uint16 slot,uint32 timer) { SetUInt32Value(PLAYER_QUEST_LOG_1_1 + slot*MAX_QUEST_OFFSET + QUEST_TIME_OFFSET,timer); }
1257 void SwapQuestSlot(uint16 slot1,uint16 slot2)
1259 for (int i = 0; i < MAX_QUEST_OFFSET ; ++i )
1261 uint32 temp1 = GetUInt32Value(PLAYER_QUEST_LOG_1_1 + MAX_QUEST_OFFSET *slot1 + i);
1262 uint32 temp2 = GetUInt32Value(PLAYER_QUEST_LOG_1_1 + MAX_QUEST_OFFSET *slot2 + i);
1264 SetUInt32Value(PLAYER_QUEST_LOG_1_1 + MAX_QUEST_OFFSET *slot1 + i, temp2);
1265 SetUInt32Value(PLAYER_QUEST_LOG_1_1 + MAX_QUEST_OFFSET *slot2 + i, temp1);
1268 uint32 GetReqKillOrCastCurrentCount(uint32 quest_id, int32 entry);
1269 void AreaExploredOrEventHappens( uint32 questId );
1270 void GroupEventHappens( uint32 questId, WorldObject const* pEventObject );
1271 void ItemAddedQuestCheck( uint32 entry, uint32 count );
1272 void ItemRemovedQuestCheck( uint32 entry, uint32 count );
1273 void KilledMonster( uint32 entry, uint64 guid );
1274 void CastedCreatureOrGO( uint32 entry, uint64 guid, uint32 spell_id );
1275 void TalkedToCreature( uint32 entry, uint64 guid );
1276 void MoneyChanged( uint32 value );
1277 bool HasQuestForItem( uint32 itemid ) const;
1278 bool HasQuestForGO(int32 GOId) const;
1279 void UpdateForQuestsGO();
1280 bool CanShareQuest(uint32 quest_id) const;
1282 void SendQuestComplete( uint32 quest_id );
1283 void SendQuestReward( Quest const *pQuest, uint32 XP, Object* questGiver );
1284 void SendQuestFailed( uint32 quest_id );
1285 void SendQuestTimerFailed( uint32 quest_id );
1286 void SendCanTakeQuestResponse( uint32 msg );
1287 void SendPushToPartyResponse( Player *pPlayer, uint32 msg );
1288 void SendQuestUpdateAddItem( Quest const* pQuest, uint32 item_idx, uint32 count );
1289 void SendQuestUpdateAddCreatureOrGo( Quest const* pQuest, uint64 guid, uint32 creatureOrGO_idx, uint32 old_count, uint32 add_count );
1291 uint64 GetDivider() { return m_divider; };
1292 void SetDivider( uint64 guid ) { m_divider = guid; };
1294 uint32 GetInGameTime() { return m_ingametime; };
1296 void SetInGameTime( uint32 time ) { m_ingametime = time; };
1298 void AddTimedQuest( uint32 quest_id ) { m_timedquests.insert(quest_id); }
1300 /*********************************************************/
1301 /*** LOAD SYSTEM ***/
1302 /*********************************************************/
1304 bool LoadFromDB(uint32 guid, SqlQueryHolder *holder);
1306 bool MinimalLoadFromDB(QueryResult *result, uint32 guid);
1307 static bool LoadValuesArrayFromDB(Tokens& data,uint64 guid);
1308 static uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index);
1309 static float GetFloatValueFromArray(Tokens const& data, uint16 index);
1310 static uint32 GetUInt32ValueFromDB(uint16 index, uint64 guid);
1311 static float GetFloatValueFromDB(uint16 index, uint64 guid);
1312 static uint32 GetZoneIdFromDB(uint64 guid);
1313 static bool LoadPositionFromDB(uint32& mapid, float& x,float& y,float& z,float& o, bool& in_flight, uint64 guid);
1315 /*********************************************************/
1316 /*** SAVE SYSTEM ***/
1317 /*********************************************************/
1319 void SaveToDB();
1320 void SaveInventoryAndGoldToDB(); // fast save function for item/money cheating preventing
1321 void SaveDataFieldToDB();
1322 static bool SaveValuesArrayInDB(Tokens const& data,uint64 guid);
1323 static void SetUInt32ValueInArray(Tokens& data,uint16 index, uint32 value);
1324 static void SetFloatValueInArray(Tokens& data,uint16 index, float value);
1325 static void SetUInt32ValueInDB(uint16 index, uint32 value, uint64 guid);
1326 static void SetFloatValueInDB(uint16 index, float value, uint64 guid);
1327 static void Customize(uint64 guid, uint8 gender, uint8 skin, uint8 face, uint8 hairStyle, uint8 hairColor, uint8 facialHair);
1328 static void SavePositionInDB(uint32 mapid, float x,float y,float z,float o,uint32 zone,uint64 guid);
1330 bool m_mailsLoaded;
1331 bool m_mailsUpdated;
1333 void SetBindPoint(uint64 guid);
1334 void SendTalentWipeConfirm(uint64 guid);
1335 void RewardRage( uint32 damage, uint32 weaponSpeedHitFactor, bool attacker );
1336 void SendPetSkillWipeConfirm();
1337 void CalcRage( uint32 damage,bool attacker );
1338 void RegenerateAll();
1339 void Regenerate(Powers power);
1340 void RegenerateHealth();
1341 void setRegenTimer(uint32 time) {m_regenTimer = time;}
1342 void setWeaponChangeTimer(uint32 time) {m_weaponChangeTimer = time;}
1344 uint32 GetMoney() { return GetUInt32Value (PLAYER_FIELD_COINAGE); }
1345 void ModifyMoney( int32 d )
1347 if(d < 0)
1348 SetMoney (GetMoney() > uint32(-d) ? GetMoney() + d : 0);
1349 else
1350 SetMoney (GetMoney() < uint32(MAX_MONEY_AMOUNT - d) ? GetMoney() + d : MAX_MONEY_AMOUNT);
1352 // "At Gold Limit"
1353 if(GetMoney() >= MAX_MONEY_AMOUNT)
1354 SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD,NULL,NULL);
1356 void SetMoney( uint32 value )
1358 SetUInt32Value (PLAYER_FIELD_COINAGE, value);
1359 MoneyChanged( value );
1362 uint32 GetTutorialInt(uint32 intId )
1364 ASSERT( (intId < 8) );
1365 return m_Tutorials[intId];
1368 void SetTutorialInt(uint32 intId, uint32 value)
1370 ASSERT( (intId < 8) );
1371 if(m_Tutorials[intId]!=value)
1373 m_Tutorials[intId] = value;
1374 m_TutorialsChanged = true;
1378 QuestStatusMap& getQuestStatusMap() { return mQuestStatus; };
1380 const uint64& GetSelection( ) const { return m_curSelection; }
1381 void SetSelection(const uint64 &guid) { m_curSelection = guid; SetUInt64Value(UNIT_FIELD_TARGET, guid); }
1383 uint8 GetComboPoints() { return m_comboPoints; }
1384 const uint64& GetComboTarget() const { return m_comboTarget; }
1386 void AddComboPoints(Unit* target, int8 count);
1387 void ClearComboPoints();
1388 void SendComboPoints();
1390 void SendMailResult(uint32 mailId, uint32 mailAction, uint32 mailError, uint32 equipError = 0, uint32 item_guid = 0, uint32 item_count = 0);
1391 void SendNewMail();
1392 void UpdateNextMailTimeAndUnreads();
1393 void AddNewMailDeliverTime(time_t deliver_time);
1394 bool IsMailsLoaded() const { return m_mailsLoaded; }
1396 //void SetMail(Mail *m);
1397 void RemoveMail(uint32 id);
1399 void AddMail(Mail* mail) { m_mail.push_front(mail);}// for call from WorldSession::SendMailTo
1400 uint32 GetMailSize() { return m_mail.size();};
1401 Mail* GetMail(uint32 id);
1403 PlayerMails::iterator GetmailBegin() { return m_mail.begin();};
1404 PlayerMails::iterator GetmailEnd() { return m_mail.end();};
1406 /*********************************************************/
1407 /*** MAILED ITEMS SYSTEM ***/
1408 /*********************************************************/
1410 uint8 unReadMails;
1411 time_t m_nextMailDelivereTime;
1413 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
1415 ItemMap mMitems; //template defined in objectmgr.cpp
1417 Item* GetMItem(uint32 id)
1419 ItemMap::const_iterator itr = mMitems.find(id);
1420 return itr != mMitems.end() ? itr->second : NULL;
1423 void AddMItem(Item* it)
1425 ASSERT( it );
1426 //assert deleted, because items can be added before loading
1427 mMitems[it->GetGUIDLow()] = it;
1430 bool RemoveMItem(uint32 id)
1432 return mMitems.erase(id) ? true : false;
1435 void PetSpellInitialize();
1436 void CharmSpellInitialize();
1437 void PossessSpellInitialize();
1438 bool HasSpell(uint32 spell) const;
1439 bool HasActiveSpell(uint32 spell) const; // show in spellbook
1440 TrainerSpellState GetTrainerSpellState(TrainerSpell const* trainer_spell) const;
1441 bool IsSpellFitByClassAndRace( uint32 spell_id ) const;
1442 bool IsNeedCastPassiveSpellAtLearn(SpellEntry const* spellInfo) const;
1444 void SendProficiency(uint8 pr1, uint32 pr2);
1445 void SendInitialSpells();
1446 bool addSpell(uint32 spell_id, bool active, bool learning, bool dependent, bool disabled);
1447 void learnSpell(uint32 spell_id, bool dependent);
1448 void removeSpell(uint32 spell_id, bool disabled = false, bool update_action_bar_for_low_rank = false);
1449 void resetSpells();
1450 void learnDefaultSpells();
1451 void learnQuestRewardedSpells();
1452 void learnQuestRewardedSpells(Quest const* quest);
1453 void learnSpellHighRank(uint32 spellid);
1455 uint32 GetFreeTalentPoints() const { return GetUInt32Value(PLAYER_CHARACTER_POINTS1); }
1456 void SetFreeTalentPoints(uint32 points) { SetUInt32Value(PLAYER_CHARACTER_POINTS1,points); }
1457 bool resetTalents(bool no_cost = false);
1458 uint32 resetTalentsCost() const;
1459 void InitTalentForLevel();
1461 uint32 CalculateTalentsPoints() const;
1463 void InitGlyphsForLevel();
1464 void SetGlyphSlot(uint8 slot, uint32 slottype) { SetUInt32Value(PLAYER_FIELD_GLYPH_SLOTS_1 + slot, slottype); }
1465 uint32 GetGlyphSlot(uint8 slot) { return GetUInt32Value(PLAYER_FIELD_GLYPH_SLOTS_1 + slot); }
1466 void SetGlyph(uint8 slot, uint32 glyph) { SetUInt32Value(PLAYER_FIELD_GLYPHS_1 + slot, glyph); }
1467 uint32 GetGlyph(uint8 slot) { return GetUInt32Value(PLAYER_FIELD_GLYPHS_1 + slot); }
1469 uint32 GetFreePrimaryProffesionPoints() const { return GetUInt32Value(PLAYER_CHARACTER_POINTS2); }
1470 void SetFreePrimaryProffesions(uint16 profs) { SetUInt32Value(PLAYER_CHARACTER_POINTS2,profs); }
1471 void InitPrimaryProffesions();
1473 PlayerSpellMap const& GetSpellMap() const { return m_spells; }
1474 PlayerSpellMap & GetSpellMap() { return m_spells; }
1476 void AddSpellMod(SpellModifier* mod, bool apply);
1477 bool IsAffectedBySpellmod(SpellEntry const *spellInfo, SpellModifier *mod, Spell const* spell = NULL);
1478 template <class T> T ApplySpellMod(uint32 spellId, SpellModOp op, T &basevalue, Spell const* spell = NULL);
1479 void RemoveSpellMods(Spell const* spell);
1481 bool HasSpellCooldown(uint32 spell_id) const
1483 SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id);
1484 return itr != m_spellCooldowns.end() && itr->second.end > time(NULL);
1486 uint32 GetSpellCooldownDelay(uint32 spell_id) const
1488 SpellCooldowns::const_iterator itr = m_spellCooldowns.find(spell_id);
1489 time_t t = time(NULL);
1490 return itr != m_spellCooldowns.end() && itr->second.end > t ? itr->second.end - t : 0;
1492 void AddSpellCooldown(uint32 spell_id, uint32 itemid, time_t end_time);
1493 void SendCooldownEvent(SpellEntry const *spellInfo);
1494 void ProhibitSpellScholl(SpellSchoolMask idSchoolMask, uint32 unTimeMs );
1495 void RemoveSpellCooldown(uint32 spell_id) { m_spellCooldowns.erase(spell_id); }
1496 void RemoveArenaSpellCooldowns();
1497 void RemoveAllSpellCooldown();
1498 void _LoadSpellCooldowns(QueryResult *result);
1499 void _SaveSpellCooldowns();
1501 void setResurrectRequestData(uint64 guid, uint32 mapId, float X, float Y, float Z, uint32 health, uint32 mana)
1503 m_resurrectGUID = guid;
1504 m_resurrectMap = mapId;
1505 m_resurrectX = X;
1506 m_resurrectY = Y;
1507 m_resurrectZ = Z;
1508 m_resurrectHealth = health;
1509 m_resurrectMana = mana;
1511 void clearResurrectRequestData() { setResurrectRequestData(0,0,0.0f,0.0f,0.0f,0,0); }
1512 bool isRessurectRequestedBy(uint64 guid) const { return m_resurrectGUID == guid; }
1513 bool isRessurectRequested() const { return m_resurrectGUID != 0; }
1514 void ResurectUsingRequestData();
1516 int getCinematic()
1518 return m_cinematic;
1520 void setCinematic(int cine)
1522 m_cinematic = cine;
1525 void addActionButton(uint8 button, uint16 action, uint8 type, uint8 misc);
1526 void removeActionButton(uint8 button);
1527 void SendInitialActionButtons();
1529 PvPInfo pvpInfo;
1530 void UpdatePvP(bool state, bool ovrride=false);
1531 void UpdateZone(uint32 newZone);
1532 void UpdateArea(uint32 newArea);
1534 void UpdateZoneDependentAuras( uint32 zone_id ); // zones
1535 void UpdateAreaDependentAuras( uint32 area_id ); // subzones
1537 void UpdateAfkReport(time_t currTime);
1538 void UpdatePvPFlag(time_t currTime);
1539 void UpdateContestedPvP(uint32 currTime);
1540 void SetContestedPvPTimer(uint32 newTime) {m_contestedPvPTimer = newTime;}
1541 void ResetContestedPvP()
1543 clearUnitState(UNIT_STAT_ATTACK_PLAYER);
1544 RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP);
1545 m_contestedPvPTimer = 0;
1548 /** todo: -maybe move UpdateDuelFlag+DuelComplete to independent DuelHandler.. **/
1549 DuelInfo *duel;
1550 void UpdateDuelFlag(time_t currTime);
1551 void CheckDuelDistance(time_t currTime);
1552 void DuelComplete(DuelCompleteType type);
1554 bool IsGroupVisibleFor(Player* p) const;
1555 bool IsInSameGroupWith(Player const* p) const;
1556 bool IsInSameRaidWith(Player const* p) const { return p==this || (GetGroup() != NULL && GetGroup() == p->GetGroup()); }
1557 void UninviteFromGroup();
1558 static void RemoveFromGroup(Group* group, uint64 guid);
1559 void RemoveFromGroup() { RemoveFromGroup(GetGroup(),GetGUID()); }
1560 void SendUpdateToOutOfRangeGroupMembers();
1562 void SetInGuild(uint32 GuildId) { SetUInt32Value(PLAYER_GUILDID, GuildId); }
1563 void SetRank(uint32 rankId){ SetUInt32Value(PLAYER_GUILDRANK, rankId); }
1564 void SetGuildIdInvited(uint32 GuildId) { m_GuildIdInvited = GuildId; }
1565 uint32 GetGuildId() { return GetUInt32Value(PLAYER_GUILDID); }
1566 static uint32 GetGuildIdFromDB(uint64 guid);
1567 uint32 GetRank(){ return GetUInt32Value(PLAYER_GUILDRANK); }
1568 static uint32 GetRankFromDB(uint64 guid);
1569 int GetGuildIdInvited() { return m_GuildIdInvited; }
1570 static void RemovePetitionsAndSigns(uint64 guid, uint32 type);
1572 // Arena Team
1573 void SetInArenaTeam(uint32 ArenaTeamId, uint8 slot)
1575 SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * 6), ArenaTeamId);
1577 uint32 GetArenaTeamId(uint8 slot) { return GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * 6)); }
1578 static uint32 GetArenaTeamIdFromDB(uint64 guid, uint8 slot);
1579 void SetArenaTeamIdInvited(uint32 ArenaTeamId) { m_ArenaTeamIdInvited = ArenaTeamId; }
1580 uint32 GetArenaTeamIdInvited() { return m_ArenaTeamIdInvited; }
1581 static void LeaveAllArenaTeams(uint64 guid);
1583 void SetDifficulty(uint32 dungeon_difficulty) { m_dungeonDifficulty = dungeon_difficulty; }
1584 uint8 GetDifficulty() { return m_dungeonDifficulty; }
1586 bool UpdateSkill(uint32 skill_id, uint32 step);
1587 bool UpdateSkillPro(uint16 SkillId, int32 Chance, uint32 step);
1589 bool UpdateCraftSkill(uint32 spellid);
1590 bool UpdateGatherSkill(uint32 SkillId, uint32 SkillValue, uint32 RedLevel, uint32 Multiplicator = 1);
1591 bool UpdateFishingSkill();
1593 uint32 GetBaseDefenseSkillValue() const { return GetBaseSkillValue(SKILL_DEFENSE); }
1594 uint32 GetBaseWeaponSkillValue(WeaponAttackType attType) const;
1596 uint32 GetSpellByProto(ItemPrototype *proto);
1598 float GetHealthBonusFromStamina();
1599 float GetManaBonusFromIntellect();
1601 bool UpdateStats(Stats stat);
1602 bool UpdateAllStats();
1603 void UpdateResistances(uint32 school);
1604 void UpdateArmor();
1605 void UpdateMaxHealth();
1606 void UpdateMaxPower(Powers power);
1607 void ApplyFeralAPBonus(int32 amount, bool apply);
1608 void UpdateAttackPowerAndDamage(bool ranged = false);
1609 void UpdateShieldBlockValue();
1610 void UpdateDamagePhysical(WeaponAttackType attType);
1611 void ApplySpellDamageBonus(int32 amount, bool apply);
1612 void ApplySpellHealingBonus(int32 amount, bool apply);
1613 void UpdateSpellDamageAndHealingBonus();
1615 void CalculateMinMaxDamage(WeaponAttackType attType, bool normalized, float& min_damage, float& max_damage);
1617 void UpdateDefenseBonusesMod();
1618 void ApplyRatingMod(CombatRating cr, int32 value, bool apply);
1619 float GetMeleeCritFromAgility();
1620 float GetDodgeFromAgility();
1621 float GetSpellCritFromIntellect();
1622 float OCTRegenHPPerSpirit();
1623 float OCTRegenMPPerSpirit();
1624 float GetRatingCoefficient(CombatRating cr) const;
1625 float GetRatingBonusValue(CombatRating cr) const;
1626 uint32 GetMeleeCritDamageReduction(uint32 damage) const;
1627 uint32 GetRangedCritDamageReduction(uint32 damage) const;
1628 uint32 GetSpellCritDamageReduction(uint32 damage) const;
1629 uint32 GetDotDamageReduction(uint32 damage) const;
1630 uint32 GetBaseSpellDamageBonus() { return m_baseSpellDamage;}
1631 uint32 GetBaseSpellHealingBonus() { return m_baseSpellHealing;}
1633 float GetExpertiseDodgeOrParryReduction(WeaponAttackType attType) const;
1634 void UpdateBlockPercentage();
1635 void UpdateCritPercentage(WeaponAttackType attType);
1636 void UpdateAllCritPercentages();
1637 void UpdateParryPercentage();
1638 void UpdateDodgePercentage();
1639 void UpdateMeleeHitChances();
1640 void UpdateRangedHitChances();
1641 void UpdateSpellHitChances();
1643 void UpdateAllSpellCritChances();
1644 void UpdateSpellCritChance(uint32 school);
1645 void UpdateExpertise(WeaponAttackType attType);
1646 void ApplyManaRegenBonus(int32 amount, bool apply);
1647 void UpdateManaRegen();
1649 const uint64& GetLootGUID() const { return m_lootGuid; }
1650 void SetLootGUID(const uint64 &guid) { m_lootGuid = guid; }
1652 void RemovedInsignia(Player* looterPlr);
1654 WorldSession* GetSession() const { return m_session; }
1655 void SetSession(WorldSession *s) { m_session = s; }
1657 void BuildCreateUpdateBlockForPlayer( UpdateData *data, Player *target ) const;
1658 void DestroyForPlayer( Player *target ) const;
1659 void SendDelayResponse(const uint32);
1660 void SendLogXPGain(uint32 GivenXP,Unit* victim,uint32 RestXP);
1662 //Low Level Packets
1663 void PlaySound(uint32 Sound, bool OnlySelf);
1664 //notifiers
1665 void SendAttackSwingCantAttack();
1666 void SendAttackSwingCancelAttack();
1667 void SendAttackSwingDeadTarget();
1668 void SendAttackSwingNotStanding();
1669 void SendAttackSwingNotInRange();
1670 void SendAttackSwingBadFacingAttack();
1671 void SendAutoRepeatCancel();
1672 void SendExplorationExperience(uint32 Area, uint32 Experience);
1674 void SendDungeonDifficulty(bool IsInGroup);
1675 void ResetInstances(uint8 method);
1676 void SendResetInstanceSuccess(uint32 MapId);
1677 void SendResetInstanceFailed(uint32 reason, uint32 MapId);
1678 void SendResetFailedNotify(uint32 mapid);
1680 bool SetPosition(float x, float y, float z, float orientation, bool teleport = false);
1681 void UpdateUnderwaterState( Map * m, float x, float y, float z );
1683 void SendMessageToSet(WorldPacket *data, bool self);// overwrite Object::SendMessageToSet
1684 void SendMessageToSetInRange(WorldPacket *data, float fist, bool self);
1685 // overwrite Object::SendMessageToSetInRange
1686 void SendMessageToSetInRange(WorldPacket *data, float dist, bool self, bool own_team_only);
1688 static void DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmChars = true);
1690 Corpse *GetCorpse() const;
1691 void SpawnCorpseBones();
1692 void CreateCorpse();
1693 void KillPlayer();
1694 uint32 GetResurrectionSpellId();
1695 void ResurrectPlayer(float restore_percent, bool applySickness = false);
1696 void BuildPlayerRepop();
1697 void RepopAtGraveyard();
1699 void DurabilityLossAll(double percent, bool inventory);
1700 void DurabilityLoss(Item* item, double percent);
1701 void DurabilityPointsLossAll(int32 points, bool inventory);
1702 void DurabilityPointsLoss(Item* item, int32 points);
1703 void DurabilityPointLossForEquipSlot(EquipmentSlots slot);
1704 uint32 DurabilityRepairAll(bool cost, float discountMod, bool guildBank);
1705 uint32 DurabilityRepair(uint16 pos, bool cost, float discountMod, bool guildBank);
1707 void StopMirrorTimers()
1709 StopMirrorTimer(FATIGUE_TIMER);
1710 StopMirrorTimer(BREATH_TIMER);
1711 StopMirrorTimer(FIRE_TIMER);
1714 void SetMovement(PlayerMovementType pType);
1716 void JoinedChannel(Channel *c);
1717 void LeftChannel(Channel *c);
1718 void CleanupChannels();
1719 void UpdateLocalChannels( uint32 newZone );
1720 void LeaveLFGChannel();
1722 void UpdateDefense();
1723 void UpdateWeaponSkill (WeaponAttackType attType);
1724 void UpdateCombatSkills(Unit *pVictim, WeaponAttackType attType, bool defence);
1726 void SetSkill(uint32 id, uint16 currVal, uint16 maxVal);
1727 uint16 GetMaxSkillValue(uint32 skill) const; // max + perm. bonus + temp bonus
1728 uint16 GetPureMaxSkillValue(uint32 skill) const; // max
1729 uint16 GetSkillValue(uint32 skill) const; // skill value + perm. bonus + temp bonus
1730 uint16 GetBaseSkillValue(uint32 skill) const; // skill value + perm. bonus
1731 uint16 GetPureSkillValue(uint32 skill) const; // skill value
1732 int16 GetSkillPermBonusValue(uint32 skill) const;
1733 int16 GetSkillTempBonusValue(uint32 skill) const;
1734 bool HasSkill(uint32 skill) const;
1735 void learnSkillRewardedSpells(uint32 id, uint32 value);
1737 void SetDontMove(bool dontMove);
1738 bool GetDontMove() const { return m_dontMove; }
1740 void CheckExploreSystem(void);
1742 static uint32 TeamForRace(uint8 race);
1743 uint32 GetTeam() const { return m_team; }
1744 static uint32 getFactionForRace(uint8 race);
1745 void setFactionForRace(uint8 race);
1747 bool IsAtGroupRewardDistance(WorldObject const* pRewardSource) const;
1748 bool RewardPlayerAndGroupAtKill(Unit* pVictim);
1749 bool isHonorOrXPTarget(Unit* pVictim);
1751 FactionStateList m_factions;
1752 ForcedReactions m_forcedReactions;
1753 FactionStateList const& GetFactionStateList() { return m_factions; }
1754 uint32 GetDefaultReputationFlags(const FactionEntry *factionEntry) const;
1755 int32 GetBaseReputation(const FactionEntry *factionEntry) const;
1756 int32 GetReputation(uint32 faction_id) const;
1757 int32 GetReputation(const FactionEntry *factionEntry) const;
1758 ReputationRank GetReputationRank(uint32 faction) const;
1759 ReputationRank GetReputationRank(const FactionEntry *factionEntry) const;
1760 ReputationRank GetBaseReputationRank(const FactionEntry *factionEntry) const;
1761 ReputationRank ReputationToRank(int32 standing) const;
1762 const static int32 ReputationRank_Length[MAX_REPUTATION_RANK];
1763 const static int32 Reputation_Cap = 42999;
1764 const static int32 Reputation_Bottom = -42000;
1765 bool ModifyFactionReputation(uint32 FactionTemplateId, int32 DeltaReputation);
1766 bool ModifyFactionReputation(FactionEntry const* factionEntry, int32 standing);
1767 bool ModifyOneFactionReputation(FactionEntry const* factionEntry, int32 standing);
1768 bool SetFactionReputation(uint32 FactionTemplateId, int32 standing);
1769 bool SetFactionReputation(FactionEntry const* factionEntry, int32 standing);
1770 bool SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing);
1771 int32 CalculateReputationGain(uint32 creatureOrQuestLevel, int32 rep, bool for_quest);
1772 void RewardReputation(Unit *pVictim, float rate);
1773 void RewardReputation(Quest const *pQuest);
1774 void SetInitialFactions();
1775 void UpdateReputation() const;
1776 void SendFactionState(FactionState const* faction) const;
1777 void SendInitialReputations();
1778 FactionState const* GetFactionState( FactionEntry const* factionEntry) const;
1779 void SetFactionAtWar(FactionState* faction, bool atWar);
1780 void SetFactionInactive(FactionState* faction, bool inactive);
1781 void SetFactionVisible(FactionState* faction);
1782 void SetFactionVisibleForFactionTemplateId(uint32 FactionTemplateId);
1783 void SetFactionVisibleForFactionId(uint32 FactionId);
1784 void UpdateSkillsForLevel();
1785 void UpdateSkillsToMaxSkillsForLevel(); // for .levelup
1786 void ModifySkillBonus(uint32 skillid,int32 val, bool talent);
1788 /*********************************************************/
1789 /*** PVP SYSTEM ***/
1790 /*********************************************************/
1791 void UpdateArenaFields();
1792 void UpdateHonorFields();
1793 bool RewardHonor(Unit *pVictim, uint32 groupsize, float honor = -1);
1794 uint32 GetHonorPoints() { return GetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY); }
1795 uint32 GetArenaPoints() { return GetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY); }
1796 void ModifyHonorPoints( int32 value );
1797 void ModifyArenaPoints( int32 value );
1798 uint32 GetMaxPersonalArenaRatingRequirement();
1800 //End of PvP System
1802 void SetDrunkValue(uint16 newDrunkValue, uint32 itemid=0);
1803 uint16 GetDrunkValue() const { return m_drunk; }
1804 static DrunkenState GetDrunkenstateByValue(uint16 value);
1806 uint32 GetDeathTimer() const { return m_deathTimer; }
1807 uint32 GetCorpseReclaimDelay(bool pvp) const;
1808 void UpdateCorpseReclaimDelay();
1809 void SendCorpseReclaimDelay(bool load = false);
1811 uint32 GetShieldBlockValue() const; // overwrite Unit version (virtual)
1812 bool CanParry() const { return m_canParry; }
1813 void SetCanParry(bool value);
1814 bool CanBlock() const { return m_canBlock; }
1815 void SetCanBlock(bool value);
1816 bool CanDualWield() const { return m_canDualWield; }
1817 void SetCanDualWield(bool value) { m_canDualWield = value; }
1818 bool CanTitanGrip() const { return m_canTitanGrip ; }
1819 void SetCanTitanGrip(bool value) { m_canTitanGrip = value; }
1821 void SetRegularAttackTime();
1822 void SetBaseModValue(BaseModGroup modGroup, BaseModType modType, float value) { m_auraBaseMod[modGroup][modType] = value; }
1823 void HandleBaseModValue(BaseModGroup modGroup, BaseModType modType, float amount, bool apply);
1824 float GetBaseModValue(BaseModGroup modGroup, BaseModType modType) const;
1825 float GetTotalBaseModValue(BaseModGroup modGroup) const;
1826 float GetTotalPercentageModValue(BaseModGroup modGroup) const { return m_auraBaseMod[modGroup][FLAT_MOD] + m_auraBaseMod[modGroup][PCT_MOD]; }
1827 void _ApplyAllStatBonuses();
1828 void _RemoveAllStatBonuses();
1830 void _ApplyWeaponDependentAuraMods(Item *item, WeaponAttackType attackType, bool apply);
1831 void _ApplyWeaponDependentAuraCritMod(Item *item, WeaponAttackType attackType, Aura* aura, bool apply);
1832 void _ApplyWeaponDependentAuraDamageMod(Item *item, WeaponAttackType attackType, Aura* aura, bool apply);
1834 void _ApplyItemMods(Item *item,uint8 slot,bool apply);
1835 void _RemoveAllItemMods();
1836 void _ApplyAllItemMods();
1837 void _ApplyItemBonuses(ItemPrototype const *proto,uint8 slot,bool apply);
1838 void _ApplyAmmoBonuses();
1839 bool EnchantmentFitsRequirements(uint32 enchantmentcondition, int8 slot);
1840 void ToggleMetaGemsActive(uint8 exceptslot, bool apply);
1841 void CorrectMetaGemEnchants(uint8 slot, bool apply);
1842 void InitDataForForm(bool reapplyMods = false);
1844 void ApplyItemEquipSpell(Item *item, bool apply, bool form_change = false);
1845 void ApplyEquipSpell(SpellEntry const* spellInfo, Item* item, bool apply, bool form_change = false);
1846 void UpdateEquipSpellsAtFormChange();
1847 void CastItemCombatSpell(Item *item,Unit* Target, WeaponAttackType attType);
1848 void CastItemUseSpell(Item *item,SpellCastTargets const& targets,uint8 cast_count, uint32 glyphIndex);
1850 void SendInitWorldStates();
1851 void SendUpdateWorldState(uint32 Field, uint32 Value);
1852 void SendDirectMessage(WorldPacket *data);
1854 void SendAurasForTarget(Unit *target);
1856 PlayerMenu* PlayerTalkClass;
1857 std::vector<ItemSetEffect *> ItemSetEff;
1859 void SendLoot(uint64 guid, LootType loot_type);
1860 void SendLootRelease( uint64 guid );
1861 void SendNotifyLootItemRemoved(uint8 lootSlot);
1862 void SendNotifyLootMoneyRemoved();
1864 /*********************************************************/
1865 /*** BATTLEGROUND SYSTEM ***/
1866 /*********************************************************/
1868 bool InBattleGround() const { return m_bgBattleGroundID != 0; }
1869 uint32 GetBattleGroundId() const { return m_bgBattleGroundID; }
1870 BattleGround* GetBattleGround() const;
1871 bool InArena() const;
1873 static uint32 GetMinLevelForBattleGroundQueueId(uint32 queue_id, BattleGroundTypeId bgTypeId);
1874 static uint32 GetMaxLevelForBattleGroundQueueId(uint32 queue_id, BattleGroundTypeId bgTypeId);
1875 uint32 GetBattleGroundQueueIdFromLevel(BattleGroundTypeId bgTypeId) const;
1877 bool InBattleGroundQueue() const
1879 for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1880 if (m_bgBattleGroundQueueID[i].bgQueueTypeId != BATTLEGROUND_QUEUE_NONE)
1881 return true;
1882 return false;
1885 BattleGroundQueueTypeId GetBattleGroundQueueTypeId(uint32 index) const { return m_bgBattleGroundQueueID[index].bgQueueTypeId; }
1886 uint32 GetBattleGroundQueueIndex(BattleGroundQueueTypeId bgQueueTypeId) const
1888 for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1889 if (m_bgBattleGroundQueueID[i].bgQueueTypeId == bgQueueTypeId)
1890 return i;
1891 return PLAYER_MAX_BATTLEGROUND_QUEUES;
1893 bool IsInvitedForBattleGroundQueueType(BattleGroundQueueTypeId bgQueueTypeId) const
1895 for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1896 if (m_bgBattleGroundQueueID[i].bgQueueTypeId == bgQueueTypeId)
1897 return m_bgBattleGroundQueueID[i].invitedToInstance != 0;
1898 return PLAYER_MAX_BATTLEGROUND_QUEUES;
1900 bool InBattleGroundQueueForBattleGroundQueueType(BattleGroundQueueTypeId bgQueueTypeId) const
1902 return GetBattleGroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES;
1905 void SetBattleGroundId(uint32 val) { m_bgBattleGroundID = val; }
1906 uint32 AddBattleGroundQueueId(BattleGroundQueueTypeId val)
1908 for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1910 if (m_bgBattleGroundQueueID[i].bgQueueTypeId == BATTLEGROUND_QUEUE_NONE || m_bgBattleGroundQueueID[i].bgQueueTypeId == val)
1912 m_bgBattleGroundQueueID[i].bgQueueTypeId = val;
1913 m_bgBattleGroundQueueID[i].invitedToInstance = 0;
1914 return i;
1917 return PLAYER_MAX_BATTLEGROUND_QUEUES;
1919 bool HasFreeBattleGroundQueueId()
1921 for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1922 if (m_bgBattleGroundQueueID[i].bgQueueTypeId == BATTLEGROUND_QUEUE_NONE)
1923 return true;
1924 return false;
1926 void RemoveBattleGroundQueueId(BattleGroundQueueTypeId val)
1928 for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1930 if (m_bgBattleGroundQueueID[i].bgQueueTypeId == val)
1932 m_bgBattleGroundQueueID[i].bgQueueTypeId = BATTLEGROUND_QUEUE_NONE;
1933 m_bgBattleGroundQueueID[i].invitedToInstance = 0;
1934 return;
1938 void SetInviteForBattleGroundQueueType(BattleGroundQueueTypeId bgQueueTypeId, uint32 instanceId)
1940 for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1941 if (m_bgBattleGroundQueueID[i].bgQueueTypeId == bgQueueTypeId)
1942 m_bgBattleGroundQueueID[i].invitedToInstance = instanceId;
1944 bool IsInvitedForBattleGroundInstance(uint32 instanceId) const
1946 for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
1947 if (m_bgBattleGroundQueueID[i].invitedToInstance == instanceId)
1948 return true;
1949 return false;
1951 WorldLocation const& GetBattleGroundEntryPoint() const { return m_bgEntryPoint; }
1952 void SetBattleGroundEntryPoint(uint32 Map, float PosX, float PosY, float PosZ, float PosO )
1954 m_bgEntryPoint = WorldLocation(Map,PosX,PosY,PosZ,PosO);
1957 void SetBGTeam(uint32 team) { m_bgTeam = team; }
1958 uint32 GetBGTeam() const { return m_bgTeam ? m_bgTeam : GetTeam(); }
1960 void LeaveBattleground(bool teleportToEntryPoint = true);
1961 bool CanJoinToBattleground() const;
1962 bool CanReportAfkDueToLimit();
1963 void ReportedAfkBy(Player* reporter);
1964 void ClearAfkReports() { m_bgAfkReporter.clear(); }
1966 bool GetBGAccessByLevel(BattleGroundTypeId bgTypeId) const;
1967 bool isAllowUseBattleGroundObject();
1969 /*********************************************************/
1970 /*** REST SYSTEM ***/
1971 /*********************************************************/
1973 bool isRested() const { return GetRestTime() >= 10000; }
1974 uint32 GetXPRestBonus(uint32 xp);
1975 uint32 GetRestTime() const { return m_restTime;};
1976 void SetRestTime(uint32 v) { m_restTime = v;};
1978 /*********************************************************/
1979 /*** ENVIROMENTAL SYSTEM ***/
1980 /*********************************************************/
1982 void EnvironmentalDamage(uint64 guid, EnviromentalDamage type, uint32 damage);
1984 /*********************************************************/
1985 /*** FLOOD FILTER SYSTEM ***/
1986 /*********************************************************/
1988 void UpdateSpeakTime();
1989 bool CanSpeak() const;
1990 void ChangeSpeakTime(int utime);
1992 /*********************************************************/
1993 /*** VARIOUS SYSTEMS ***/
1994 /*********************************************************/
1995 MovementInfo m_movementInfo;
1996 uint32 m_lastFallTime;
1997 float m_lastFallZ;
1998 Unit *m_mover;
1999 void SetFallInformation(uint32 time, float z)
2001 m_lastFallTime = time;
2002 m_lastFallZ = z;
2004 bool isMoving() const { return HasUnitMovementFlag(movementFlagsMask); }
2005 bool isMovingOrTurning() const { return HasUnitMovementFlag(movementOrTurningFlagsMask); }
2007 bool CanFly() const { return HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY); }
2008 bool IsFlying() const { return HasUnitMovementFlag(MOVEMENTFLAG_FLYING); }
2009 bool IsAllowUseFlyMountsHere() const;
2011 void HandleDrowning();
2013 void SetClientControl(Unit* target, uint8 allowMove);
2015 void EnterVehicle(Vehicle *vehicle);
2016 void ExitVehicle(Vehicle *vehicle);
2018 uint64 GetFarSight() const { return GetUInt64Value(PLAYER_FARSIGHT); }
2019 void SetFarSightGUID(uint64 guid) { SetUInt64Value(PLAYER_FARSIGHT, guid); }
2021 // Transports
2022 Transport * GetTransport() const { return m_transport; }
2023 void SetTransport(Transport * t) { m_transport = t; }
2025 float GetTransOffsetX() const { return m_movementInfo.t_x; }
2026 float GetTransOffsetY() const { return m_movementInfo.t_y; }
2027 float GetTransOffsetZ() const { return m_movementInfo.t_z; }
2028 float GetTransOffsetO() const { return m_movementInfo.t_o; }
2029 uint32 GetTransTime() const { return m_movementInfo.t_time; }
2030 int8 GetTransSeat() const { return m_movementInfo.t_seat; }
2032 uint32 GetSaveTimer() const { return m_nextSave; }
2033 void SetSaveTimer(uint32 timer) { m_nextSave = timer; }
2035 // Recall position
2036 uint32 m_recallMap;
2037 float m_recallX;
2038 float m_recallY;
2039 float m_recallZ;
2040 float m_recallO;
2041 void SaveRecallPosition();
2043 // Homebind coordinates
2044 uint32 m_homebindMapId;
2045 uint16 m_homebindZoneId;
2046 float m_homebindX;
2047 float m_homebindY;
2048 float m_homebindZ;
2049 void RelocateToHomebind() { SetMapId(m_homebindMapId); Relocate(m_homebindX,m_homebindY,m_homebindZ); }
2051 // currently visible objects at player client
2052 typedef std::set<uint64> ClientGUIDs;
2053 ClientGUIDs m_clientGUIDs;
2055 bool HaveAtClient(WorldObject const* u) { return u==this || m_clientGUIDs.find(u->GetGUID())!=m_clientGUIDs.end(); }
2057 bool IsVisibleInGridForPlayer(Player* pl) const;
2058 bool IsVisibleGloballyFor(Player* pl) const;
2060 void UpdateVisibilityOf(WorldObject* target);
2062 template<class T>
2063 void UpdateVisibilityOf(T* target, UpdateData& data, UpdateDataMapType& data_updates, std::set<WorldObject*>& visibleNow);
2065 // Stealth detection system
2066 uint32 m_DetectInvTimer;
2067 void HandleStealthedUnitsDetection();
2069 uint8 m_forced_speed_changes[MAX_MOVE_TYPE];
2071 bool HasAtLoginFlag(AtLoginFlags f) const { return m_atLoginFlags & f; }
2072 void SetAtLoginFlag(AtLoginFlags f) { m_atLoginFlags |= f; }
2074 LookingForGroup m_lookingForGroup;
2076 // Temporarily removed pet cache
2077 uint32 GetTemporaryUnsummonedPetNumber() const { return m_temporaryUnsummonedPetNumber; }
2078 void SetTemporaryUnsummonedPetNumber(uint32 petnumber) { m_temporaryUnsummonedPetNumber = petnumber; }
2079 uint32 GetOldPetSpell() const { return m_oldpetspell; }
2080 void SetOldPetSpell(uint32 petspell) { m_oldpetspell = petspell; }
2082 /*********************************************************/
2083 /*** INSTANCE SYSTEM ***/
2084 /*********************************************************/
2086 typedef UNORDERED_MAP< uint32 /*mapId*/, InstancePlayerBind > BoundInstancesMap;
2088 void UpdateHomebindTime(uint32 time);
2090 uint32 m_HomebindTimer;
2091 bool m_InstanceValid;
2092 // permanent binds and solo binds by difficulty
2093 BoundInstancesMap m_boundInstances[TOTAL_DIFFICULTIES];
2094 InstancePlayerBind* GetBoundInstance(uint32 mapid, uint8 difficulty);
2095 BoundInstancesMap& GetBoundInstances(uint8 difficulty) { return m_boundInstances[difficulty]; }
2096 void UnbindInstance(uint32 mapid, uint8 difficulty, bool unload = false);
2097 void UnbindInstance(BoundInstancesMap::iterator &itr, uint8 difficulty, bool unload = false);
2098 InstancePlayerBind* BindToInstance(InstanceSave *save, bool permanent, bool load = false);
2099 void SendRaidInfo();
2100 void SendSavedInstances();
2101 static void ConvertInstancesToGroup(Player *player, Group *group = NULL, uint64 player_guid = 0);
2103 /*********************************************************/
2104 /*** GROUP SYSTEM ***/
2105 /*********************************************************/
2107 Group * GetGroupInvite() { return m_groupInvite; }
2108 void SetGroupInvite(Group *group) { m_groupInvite = group; }
2109 Group * GetGroup() { return m_group.getTarget(); }
2110 const Group * GetGroup() const { return (const Group*)m_group.getTarget(); }
2111 GroupReference& GetGroupRef() { return m_group; }
2112 void SetGroup(Group *group, int8 subgroup = -1);
2113 uint8 GetSubGroup() const { return m_group.getSubGroup(); }
2114 uint32 GetGroupUpdateFlag() const { return m_groupUpdateMask; }
2115 void SetGroupUpdateFlag(uint32 flag) { m_groupUpdateMask |= flag; }
2116 const uint64& GetAuraUpdateMask() const { return m_auraUpdateMask; }
2117 void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); }
2118 Player* GetNextRandomRaidMember(float radius);
2119 PartyResult CanUninviteFromGroup() const;
2121 GridReference<Player> &GetGridRef() { return m_gridRef; }
2122 MapReference &GetMapRef() { return m_mapRef; }
2124 bool isAllowedToLoot(Creature* creature);
2126 WorldLocation& GetTeleportDest() { return m_teleport_dest; }
2128 DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
2129 uint8 GetRunesState() const { return m_runes->runeState; }
2130 uint8 GetBaseRune(uint8 index) const { return m_runes->runes[index].BaseRune; }
2131 uint8 GetCurrentRune(uint8 index) const { return m_runes->runes[index].CurrentRune; }
2132 uint8 GetRuneCooldown(uint8 index) const { return m_runes->runes[index].Cooldown; }
2133 void SetBaseRune(uint8 index, uint8 baseRune) { m_runes->runes[index].BaseRune = baseRune; }
2134 void SetCurrentRune(uint8 index, uint8 currentRune) { m_runes->runes[index].CurrentRune = currentRune; }
2135 void SetRuneCooldown(uint8 index, uint8 cooldown) { m_runes->runes[index].Cooldown = cooldown; m_runes->SetRuneState(index, (cooldown == 0) ? true : false); }
2136 void ConvertRune(uint8 index, uint8 newType);
2137 void ResyncRunes(uint8 count);
2138 void AddRunePower(uint8 index);
2139 void InitRunes();
2140 AchievementMgr& GetAchievementMgr() { return m_achievementMgr; }
2141 bool HasTitle(uint32 bitIndex);
2142 bool HasTitle(CharTitlesEntry const* title) { return HasTitle(title->bit_index); }
2143 void SetTitle(CharTitlesEntry const* title);
2145 protected:
2147 /*********************************************************/
2148 /*** BATTLEGROUND SYSTEM ***/
2149 /*********************************************************/
2151 /* this variable is set to bg->m_InstanceID, when player is teleported to BG - (it is battleground's GUID)*/
2152 uint32 m_bgBattleGroundID;
2154 this is an array of BG queues (BgTypeIDs) in which is player
2156 struct BgBattleGroundQueueID_Rec
2158 BattleGroundQueueTypeId bgQueueTypeId;
2159 uint32 invitedToInstance;
2161 BgBattleGroundQueueID_Rec m_bgBattleGroundQueueID[PLAYER_MAX_BATTLEGROUND_QUEUES];
2162 WorldLocation m_bgEntryPoint;
2164 std::set<uint32> m_bgAfkReporter;
2165 uint8 m_bgAfkReportedCount;
2166 time_t m_bgAfkReportedTimer;
2167 uint32 m_contestedPvPTimer;
2169 uint32 m_bgTeam; // what side the player will be added to
2171 /*********************************************************/
2172 /*** QUEST SYSTEM ***/
2173 /*********************************************************/
2175 std::set<uint32> m_timedquests;
2177 uint64 m_divider;
2178 uint32 m_ingametime;
2180 /*********************************************************/
2181 /*** LOAD SYSTEM ***/
2182 /*********************************************************/
2184 void _LoadActions(QueryResult *result);
2185 void _LoadAuras(QueryResult *result, uint32 timediff);
2186 void _LoadGlyphAuras();
2187 void _LoadBoundInstances(QueryResult *result);
2188 void _LoadInventory(QueryResult *result, uint32 timediff);
2189 void _LoadMailInit(QueryResult *resultUnread, QueryResult *resultDelivery);
2190 void _LoadMail();
2191 void _LoadMailedItems(Mail *mail);
2192 void _LoadQuestStatus(QueryResult *result);
2193 void _LoadDailyQuestStatus(QueryResult *result);
2194 void _LoadGroup(QueryResult *result);
2195 void _LoadReputation(QueryResult *result);
2196 void _LoadSkills();
2197 void _LoadSpells(QueryResult *result);
2198 void _LoadTutorials(QueryResult *result);
2199 void _LoadFriendList(QueryResult *result);
2200 bool _LoadHomeBind(QueryResult *result);
2201 void _LoadDeclinedNames(QueryResult *result);
2202 void _LoadArenaTeamInfo(QueryResult *result);
2204 /*********************************************************/
2205 /*** SAVE SYSTEM ***/
2206 /*********************************************************/
2208 void _SaveActions();
2209 void _SaveAuras();
2210 void _SaveInventory();
2211 void _SaveMail();
2212 void _SaveQuestStatus();
2213 void _SaveDailyQuestStatus();
2214 void _SaveReputation();
2215 void _SaveSpells();
2216 void _SaveTutorials();
2218 void _SetCreateBits(UpdateMask *updateMask, Player *target) const;
2219 void _SetUpdateBits(UpdateMask *updateMask, Player *target) const;
2221 /*********************************************************/
2222 /*** ENVIRONMENTAL SYSTEM ***/
2223 /*********************************************************/
2224 void HandleLava();
2225 void HandleSobering();
2226 void StartMirrorTimer(MirrorTimerType Type, uint32 MaxValue);
2227 void ModifyMirrorTimer(MirrorTimerType Type, uint32 MaxValue, uint32 CurrentValue, uint32 Regen);
2228 void StopMirrorTimer(MirrorTimerType Type);
2229 uint8 m_isunderwater;
2230 bool m_isInWater;
2232 /*********************************************************/
2233 /*** HONOR SYSTEM ***/
2234 /*********************************************************/
2235 time_t m_lastHonorUpdateTime;
2237 void outDebugValues() const;
2238 uint64 m_lootGuid;
2240 uint32 m_race;
2241 uint32 m_class;
2242 uint32 m_team;
2243 uint32 m_nextSave;
2244 time_t m_speakTime;
2245 uint32 m_speakCount;
2246 uint32 m_dungeonDifficulty;
2248 uint32 m_atLoginFlags;
2250 Item* m_items[PLAYER_SLOTS_COUNT];
2251 uint32 m_currentBuybackSlot;
2253 std::vector<Item*> m_itemUpdateQueue;
2254 bool m_itemUpdateQueueBlocked;
2256 uint32 m_ExtraFlags;
2257 uint64 m_curSelection;
2259 uint64 m_comboTarget;
2260 int8 m_comboPoints;
2262 QuestStatusMap mQuestStatus;
2264 uint32 m_GuildIdInvited;
2265 uint32 m_ArenaTeamIdInvited;
2267 PlayerMails m_mail;
2268 PlayerSpellMap m_spells;
2269 SpellCooldowns m_spellCooldowns;
2271 ActionButtonList m_actionButtons;
2273 float m_auraBaseMod[BASEMOD_END][MOD_END];
2274 int16 m_baseRatingValue[MAX_COMBAT_RATING];
2275 uint16 m_baseSpellDamage;
2276 uint16 m_baseSpellHealing;
2277 uint16 m_baseFeralAP;
2278 uint16 m_baseManaRegen;
2280 SpellModList m_spellMods[MAX_SPELLMOD];
2281 int32 m_SpellModRemoveCount;
2282 EnchantDurationList m_enchantDuration;
2283 ItemDurationList m_itemDuration;
2285 uint64 m_resurrectGUID;
2286 uint32 m_resurrectMap;
2287 float m_resurrectX, m_resurrectY, m_resurrectZ;
2288 uint32 m_resurrectHealth, m_resurrectMana;
2290 WorldSession *m_session;
2292 typedef std::list<Channel*> JoinedChannelsList;
2293 JoinedChannelsList m_channels;
2295 bool m_dontMove;
2297 int m_cinematic;
2299 Player *pTrader;
2300 bool acceptTrade;
2301 uint16 tradeItems[TRADE_SLOT_COUNT];
2302 uint32 tradeGold;
2304 time_t m_nextThinkTime;
2306 uint32 m_Tutorials[8];
2307 bool m_TutorialsChanged;
2309 bool m_DailyQuestChanged;
2310 time_t m_lastDailyQuestTime;
2312 uint32 m_breathTimer;
2313 uint32 m_drunkTimer;
2314 uint16 m_drunk;
2315 uint32 m_weaponChangeTimer;
2317 uint32 m_zoneUpdateId;
2318 uint32 m_zoneUpdateTimer;
2319 uint32 m_areaUpdateId;
2321 uint32 m_deathTimer;
2322 time_t m_deathExpireTime;
2324 uint32 m_restTime;
2326 uint32 m_WeaponProficiency;
2327 uint32 m_ArmorProficiency;
2328 bool m_canParry;
2329 bool m_canBlock;
2330 bool m_canDualWield;
2331 bool m_canTitanGrip;
2332 uint8 m_swingErrorMsg;
2333 float m_ammoDPS;
2335 ////////////////////Rest System/////////////////////
2336 int time_inn_enter;
2337 uint32 inn_pos_mapid;
2338 float inn_pos_x;
2339 float inn_pos_y;
2340 float inn_pos_z;
2341 float m_rest_bonus;
2342 RestType rest_type;
2343 ////////////////////Rest System/////////////////////
2345 // Transports
2346 Transport * m_transport;
2348 uint32 m_resetTalentsCost;
2349 time_t m_resetTalentsTime;
2350 uint32 m_usedTalentCount;
2351 uint32 m_questRewardTalentCount;
2353 // Social
2354 PlayerSocial *m_social;
2356 // Groups
2357 GroupReference m_group;
2358 Group *m_groupInvite;
2359 uint32 m_groupUpdateMask;
2360 uint64 m_auraUpdateMask;
2362 // Temporarily removed pet cache
2363 uint32 m_temporaryUnsummonedPetNumber;
2364 uint32 m_oldpetspell;
2366 uint64 m_miniPet;
2367 GuardianPetList m_guardianPets;
2369 // Player summoning
2370 time_t m_summon_expire;
2371 uint32 m_summon_mapid;
2372 float m_summon_x;
2373 float m_summon_y;
2374 float m_summon_z;
2376 // Far Teleport
2377 WorldLocation m_teleport_dest;
2379 DeclinedName *m_declinedname;
2380 Runes *m_runes;
2381 AchievementMgr m_achievementMgr;
2382 private:
2383 // internal common parts for CanStore/StoreItem functions
2384 uint8 _CanStoreItem_InSpecificSlot( uint8 bag, uint8 slot, ItemPosCountVec& dest, ItemPrototype const *pProto, uint32& count, bool swap, Item *pSrcItem ) const;
2385 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;
2386 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;
2387 Item* _StoreItem( uint16 pos, Item *pItem, uint32 count, bool clone, bool update );
2389 void AdjustQuestReqItemCount( Quest const* pQuest, QuestStatusData& questStatusData );
2391 GridReference<Player> m_gridRef;
2392 MapReference m_mapRef;
2395 void AddItemsSetItem(Player*player,Item *item);
2396 void RemoveItemsSetItem(Player*player,ItemPrototype const *proto);
2398 // "the bodies of template functions must be made available in a header file"
2399 template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &basevalue, Spell const* spell)
2401 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
2402 if (!spellInfo) return 0;
2403 int32 totalpct = 0;
2404 int32 totalflat = 0;
2405 for (SpellModList::iterator itr = m_spellMods[op].begin(); itr != m_spellMods[op].end(); ++itr)
2407 SpellModifier *mod = *itr;
2409 if(!IsAffectedBySpellmod(spellInfo,mod,spell))
2410 continue;
2411 if (mod->type == SPELLMOD_FLAT)
2412 totalflat += mod->value;
2413 else if (mod->type == SPELLMOD_PCT)
2415 // skip percent mods for null basevalue (most important for spell mods with charges )
2416 if(basevalue == T(0))
2417 continue;
2419 // special case (skip >10sec spell casts for instant cast setting)
2420 if( mod->op==SPELLMOD_CASTING_TIME && basevalue >= T(10000) && mod->value <= -100)
2421 continue;
2423 totalpct += mod->value;
2426 if (mod->charges > 0 )
2428 --mod->charges;
2429 if (mod->charges == 0)
2431 mod->charges = -1;
2432 mod->lastAffected = spell;
2433 if(!mod->lastAffected)
2434 mod->lastAffected = FindCurrentSpellBySpellId(spellId);
2435 ++m_SpellModRemoveCount;
2440 float diff = (float)basevalue*(float)totalpct/100.0f + (float)totalflat;
2441 basevalue = T((float)basevalue + diff);
2442 return T(diff);
2444 #endif