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
21 #include "Database/DatabaseEnv.h"
24 #include "ObjectMgr.h"
27 #include "WorldPacket.h"
28 #include "WorldSession.h"
29 #include "UpdateMask.h"
31 #include "SkillDiscovery.h"
33 #include "GossipDef.h"
34 #include "UpdateData.h"
36 #include "ChannelMgr.h"
37 #include "MapManager.h"
38 #include "MapInstanced.h"
39 #include "InstanceSaveMgr.h"
40 #include "GridNotifiers.h"
41 #include "GridNotifiersImpl.h"
43 #include "ObjectMgr.h"
44 #include "ObjectAccessor.h"
45 #include "CreatureAI.h"
50 #include "SpellAuras.h"
52 #include "Transports.h"
54 #include "BattleGround.h"
55 #include "BattleGroundMgr.h"
56 #include "ArenaTeam.h"
58 #include "Database/DatabaseImpl.h"
60 #include "SocialMgr.h"
61 #include "AchievementMgr.h"
65 #define ZONE_UPDATE_INTERVAL 1000
67 #define PLAYER_SKILL_INDEX(x) (PLAYER_SKILL_INFO_1_1 + ((x)*3))
68 #define PLAYER_SKILL_VALUE_INDEX(x) (PLAYER_SKILL_INDEX(x)+1)
69 #define PLAYER_SKILL_BONUS_INDEX(x) (PLAYER_SKILL_INDEX(x)+2)
71 #define SKILL_VALUE(x) PAIR32_LOPART(x)
72 #define SKILL_MAX(x) PAIR32_HIPART(x)
73 #define MAKE_SKILL_VALUE(v, m) MAKE_PAIR32(v,m)
75 #define SKILL_TEMP_BONUS(x) int16(PAIR32_LOPART(x))
76 #define SKILL_PERM_BONUS(x) int16(PAIR32_HIPART(x))
77 #define MAKE_SKILL_BONUS(t, p) MAKE_PAIR32(t,p)
81 CHARACTER_FLAG_NONE
= 0x00000000,
82 CHARACTER_FLAG_UNK1
= 0x00000001,
83 CHARACTER_FLAG_UNK2
= 0x00000002,
84 CHARACTER_LOCKED_FOR_TRANSFER
= 0x00000004,
85 CHARACTER_FLAG_UNK4
= 0x00000008,
86 CHARACTER_FLAG_UNK5
= 0x00000010,
87 CHARACTER_FLAG_UNK6
= 0x00000020,
88 CHARACTER_FLAG_UNK7
= 0x00000040,
89 CHARACTER_FLAG_UNK8
= 0x00000080,
90 CHARACTER_FLAG_UNK9
= 0x00000100,
91 CHARACTER_FLAG_UNK10
= 0x00000200,
92 CHARACTER_FLAG_HIDE_HELM
= 0x00000400,
93 CHARACTER_FLAG_HIDE_CLOAK
= 0x00000800,
94 CHARACTER_FLAG_UNK13
= 0x00001000,
95 CHARACTER_FLAG_GHOST
= 0x00002000,
96 CHARACTER_FLAG_RENAME
= 0x00004000,
97 CHARACTER_FLAG_UNK16
= 0x00008000,
98 CHARACTER_FLAG_UNK17
= 0x00010000,
99 CHARACTER_FLAG_UNK18
= 0x00020000,
100 CHARACTER_FLAG_UNK19
= 0x00040000,
101 CHARACTER_FLAG_UNK20
= 0x00080000,
102 CHARACTER_FLAG_UNK21
= 0x00100000,
103 CHARACTER_FLAG_UNK22
= 0x00200000,
104 CHARACTER_FLAG_UNK23
= 0x00400000,
105 CHARACTER_FLAG_UNK24
= 0x00800000,
106 CHARACTER_FLAG_LOCKED_BY_BILLING
= 0x01000000,
107 CHARACTER_FLAG_DECLINED
= 0x02000000,
108 CHARACTER_FLAG_UNK27
= 0x04000000,
109 CHARACTER_FLAG_UNK28
= 0x08000000,
110 CHARACTER_FLAG_UNK29
= 0x10000000,
111 CHARACTER_FLAG_UNK30
= 0x20000000,
112 CHARACTER_FLAG_UNK31
= 0x40000000,
113 CHARACTER_FLAG_UNK32
= 0x80000000
116 // corpse reclaim times
117 #define DEATH_EXPIRE_STEP (5*MINUTE)
118 #define MAX_DEATH_COUNT 3
120 static uint32 copseReclaimDelay
[MAX_DEATH_COUNT
] = { 30, 60, 120 };
122 //== PlayerTaxi ================================================
124 PlayerTaxi::PlayerTaxi()
127 memset(m_taximask
, 0, sizeof(m_taximask
));
130 void PlayerTaxi::InitTaxiNodesForLevel(uint32 race
, uint32 chrClass
, uint32 level
)
132 // capital and taxi hub masks
135 case RACE_HUMAN
: SetTaximaskNode(2); break; // Human
136 case RACE_ORC
: SetTaximaskNode(23); break; // Orc
137 case RACE_DWARF
: SetTaximaskNode(6); break; // Dwarf
138 case RACE_NIGHTELF
: SetTaximaskNode(26);
139 SetTaximaskNode(27); break; // Night Elf
140 case RACE_UNDEAD_PLAYER
: SetTaximaskNode(11); break;// Undead
141 case RACE_TAUREN
: SetTaximaskNode(22); break; // Tauren
142 case RACE_GNOME
: SetTaximaskNode(6); break; // Gnome
143 case RACE_TROLL
: SetTaximaskNode(23); break; // Troll
144 case RACE_BLOODELF
: SetTaximaskNode(82); break; // Blood Elf
145 case RACE_DRAENEI
: SetTaximaskNode(94); break; // Draenei
150 case CLASS_DEATH_KNIGHT
: // TODO: figure out initial known nodes
154 // new continent starting masks (It will be accessible only at new map)
155 switch(Player::TeamForRace(race
))
157 case ALLIANCE
: SetTaximaskNode(100); break;
158 case HORDE
: SetTaximaskNode(99); break;
160 // level dependent taxi hubs
162 SetTaximaskNode(213); //Shattered Sun Staging Area
165 void PlayerTaxi::LoadTaxiMask(const char* data
)
167 Tokens tokens
= StrSplit(data
, " ");
170 Tokens::iterator iter
;
171 for (iter
= tokens
.begin(), index
= 0;
172 (index
< TaxiMaskSize
) && (iter
!= tokens
.end()); ++iter
, ++index
)
174 // load and set bits only for existed taxi nodes
175 m_taximask
[index
] = sTaxiNodesMask
[index
] & uint32(atol((*iter
).c_str()));
179 void PlayerTaxi::AppendTaximaskTo( ByteBuffer
& data
, bool all
)
183 for (uint8 i
=0; i
<TaxiMaskSize
; i
++)
184 data
<< uint32(sTaxiNodesMask
[i
]); // all existed nodes
188 for (uint8 i
=0; i
<TaxiMaskSize
; i
++)
189 data
<< uint32(m_taximask
[i
]); // known nodes
193 bool PlayerTaxi::LoadTaxiDestinationsFromString( const std::string
& values
)
195 ClearTaxiDestinations();
197 Tokens tokens
= StrSplit(values
," ");
199 for(Tokens::iterator iter
= tokens
.begin(); iter
!= tokens
.end(); ++iter
)
201 uint32 node
= uint32(atol(iter
->c_str()));
202 AddTaxiDestination(node
);
205 if(m_TaxiDestinations
.empty())
209 if(m_TaxiDestinations
.size() < 2)
212 for(size_t i
= 1; i
< m_TaxiDestinations
.size(); ++i
)
216 objmgr
.GetTaxiPath(m_TaxiDestinations
[i
-1],m_TaxiDestinations
[i
],path
,cost
);
224 std::string
PlayerTaxi::SaveTaxiDestinationsToString()
226 if(m_TaxiDestinations
.empty())
229 std::ostringstream ss
;
231 for(size_t i
=0; i
< m_TaxiDestinations
.size(); ++i
)
232 ss
<< m_TaxiDestinations
[i
] << " ";
237 uint32
PlayerTaxi::GetCurrentTaxiPath() const
239 if(m_TaxiDestinations
.size() < 2)
245 objmgr
.GetTaxiPath(m_TaxiDestinations
[0],m_TaxiDestinations
[1],path
,cost
);
250 std::ostringstream
& operator<< (std::ostringstream
& ss
, PlayerTaxi
const& taxi
)
253 for(int i
= 0; i
< TaxiMaskSize
; ++i
)
254 ss
<< taxi
.m_taximask
[i
] << " ";
259 //== Player ====================================================
261 const int32
Player::ReputationRank_Length
[MAX_REPUTATION_RANK
] = {36000, 3000, 3000, 3000, 6000, 12000, 21000, 1000};
263 UpdateMask
Player::updateVisualBits
;
265 Player::Player (WorldSession
*session
): Unit(), m_achievementMgr(this)
272 m_objectType
|= TYPEMASK_PLAYER
;
273 m_objectTypeId
= TYPEID_PLAYER
;
275 m_valuesCount
= PLAYER_END
;
282 if(GetSession()->GetSecurity() >= SEC_GAMEMASTER
)
283 SetAcceptTicket(true);
285 // players always accept
286 if(GetSession()->GetSecurity() == SEC_PLAYER
)
287 SetAcceptWhispers(true);
295 m_usedTalentCount
= 0;
298 m_weaponChangeTimer
= 0;
301 m_zoneUpdateTimer
= 0;
305 m_nextSave
= sWorld
.getConfig(CONFIG_INTERVAL_SAVE
);
307 // randomize first save time in range [CONFIG_INTERVAL_SAVE] around [CONFIG_INTERVAL_SAVE]
308 // this must help in case next save after mass player load after server startup
309 m_nextSave
= urand(m_nextSave
/2,m_nextSave
*3/2);
311 clearResurrectRequestData();
313 m_SpellModRemoveCount
= 0;
315 memset(m_items
, 0, sizeof(Item
*)*PLAYER_SLOTS_COUNT
);
319 // group is initialized in the reference constructor
320 SetGroupInvite(NULL
);
321 m_groupUpdateMask
= 0;
322 m_auraUpdateMask
= 0;
326 m_GuildIdInvited
= 0;
327 m_ArenaTeamIdInvited
= 0;
329 m_atLoginFlags
= AT_LOGIN_NONE
;
338 PlayerTalkClass
= new PlayerMenu( GetSession() );
339 m_currentBuybackSlot
= BUYBACK_SLOT_START
;
341 for ( int aX
= 0 ; aX
< 8 ; aX
++ )
342 m_Tutorials
[ aX
] = 0x00;
343 m_TutorialsChanged
= false;
345 m_DailyQuestChanged
= false;
346 m_lastDailyQuestTime
= 0;
349 m_weaponChangeTimer
= 0;
351 m_isunderwater
= UNDERWATER_NONE
;
357 m_deathExpireTime
= 0;
361 m_DetectInvTimer
= 1000;
363 m_bgBattleGroundID
= 0;
364 for (int j
=0; j
< PLAYER_MAX_BATTLEGROUND_QUEUES
; j
++)
366 m_bgBattleGroundQueueID
[j
].bgQueueType
= 0;
367 m_bgBattleGroundQueueID
[j
].invitedToInstance
= 0;
371 m_logintime
= time(NULL
);
372 m_Last_tick
= m_logintime
;
373 m_WeaponProficiency
= 0;
374 m_ArmorProficiency
= 0;
377 m_canDualWield
= false;
378 m_canTitanGrip
= false;
381 m_temporaryUnsummonedPetNumber
= 0;
382 //cache for UNIT_CREATED_BY_SPELL to allow
383 //returning reagents for temporarily removed pets
384 //when dying/logging out
387 ////////////////////Rest System/////////////////////
394 rest_type
=REST_TYPE_NO
;
395 ////////////////////Rest System/////////////////////
397 m_mailsLoaded
= false;
398 m_mailsUpdated
= false;
400 m_nextMailDelivereTime
= 0;
402 m_resetTalentsCost
= 0;
403 m_resetTalentsTime
= 0;
404 m_itemUpdateQueueBlocked
= false;
406 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
407 m_forced_speed_changes
[i
] = 0;
411 /////////////////// Instance System /////////////////////
414 m_InstanceValid
= true;
415 m_dungeonDifficulty
= DIFFICULTY_NORMAL
;
417 for (int i
= 0; i
< BASEMOD_END
; i
++)
419 m_auraBaseMod
[i
][FLAT_MOD
] = 0.0f
;
420 m_auraBaseMod
[i
][PCT_MOD
] = 1.0f
;
423 for (int i
= 0; i
< MAX_COMBAT_RATING
; i
++)
424 m_baseRatingValue
[i
] = 0;
427 m_lastHonorUpdateTime
= time(NULL
);
436 //Default movement to run mode
437 m_unit_movement_flags
= 0;
442 m_bgAfkReportedTimer
= 0;
443 m_contestedPvPTimer
= 0;
445 m_declinedname
= NULL
;
451 CleanupsBeforeDelete();
453 // it must be unloaded already in PlayerLogout and accessed only for loggined player
456 // Note: buy back item already deleted from DB when player was saved
457 for(int i
= 0; i
< PLAYER_SLOTS_COUNT
; ++i
)
464 for (PlayerSpellMap::const_iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
467 //all mailed items should be deleted, also all mail should be deallocated
468 for (PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end();++itr
)
471 for (ItemMap::iterator iter
= mMitems
.begin(); iter
!= mMitems
.end(); ++iter
)
472 delete iter
->second
; //if item is duplicated... then server may crash ... but that item should be deallocated
474 delete PlayerTalkClass
;
478 m_transport
->RemovePassenger(this);
481 for(size_t x
= 0; x
< ItemSetEff
.size(); x
++)
483 delete ItemSetEff
[x
];
485 // clean up player-instance binds, may unload some instance saves
486 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
487 for(BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); ++itr
)
488 itr
->second
.save
->RemovePlayer(this);
490 delete m_declinedname
;
494 void Player::CleanupsBeforeDelete()
496 if(m_uint32Values
) // only for fully created Object
499 DuelComplete(DUEL_INTERUPTED
);
501 Unit::CleanupsBeforeDelete();
504 bool Player::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
)
506 //FIXME: outfitId not used in player creating
508 Object::_Create(guidlow
, 0, HIGHGUID_PLAYER
);
512 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(race
, class_
);
515 sLog
.outError("Player have incorrect race/class pair. Can't be loaded.");
519 for (int i
= 0; i
< PLAYER_SLOTS_COUNT
; i
++)
525 SetMapId(info
->mapId
);
526 Relocate(info
->positionX
,info
->positionY
,info
->positionZ
);
528 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(class_
);
531 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",class_
);
535 uint8 powertype
= cEntry
->powerType
;
543 unitfield = 0x00000000;
546 unitfield = 0x00110000;
548 case POWER_RUNIC_POWER:
549 unitfield = 0x0000EE00; //TODO: find correct unitfield here
552 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,class_);
556 SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
557 SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
562 SetDisplayId(info
->displayId_f
);
563 SetNativeDisplayId(info
->displayId_f
);
566 SetDisplayId(info
->displayId_m
);
567 SetNativeDisplayId(info
->displayId_m
);
570 sLog
.outError("Invalid gender %u for player",gender
);
575 setFactionForRace(m_race
);
577 uint32 RaceClassGender
= ( race
) | ( class_
<< 8 ) | ( gender
<< 16 );
579 SetUInt32Value(UNIT_FIELD_BYTES_0
, ( RaceClassGender
| ( powertype
<< 24 ) ) );
580 //SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
581 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
582 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
583 SetFlag(UNIT_FIELD_FLAGS_2
, UNIT_FLAG2_REGENERATE_POWER
);
584 SetFloatValue(UNIT_MOD_CAST_SPEED
, 1.0f
); // fix cast time showed in spell tooltip on client
585 SetFloatValue(UNIT_FIELD_HOVERHEIGHT
, 1.0f
); // default for players in 3.0.3
587 // -1 is default value
588 SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
590 SetUInt32Value(PLAYER_BYTES
, (skin
| (face
<< 8) | (hairStyle
<< 16) | (hairColor
<< 24)));
591 SetUInt32Value(PLAYER_BYTES_2
, (facialHair
| (0x00 << 8) | (0x00 << 16) | (0x02 << 24)));
592 SetByteValue(PLAYER_BYTES_3
, 0, gender
);
594 SetUInt32Value( PLAYER_GUILDID
, 0 );
595 SetUInt32Value( PLAYER_GUILDRANK
, 0 );
596 SetUInt32Value( PLAYER_GUILD_TIMESTAMP
, 0 );
598 SetUInt64Value( PLAYER__FIELD_KNOWN_TITLES
, 0 ); // 0=disabled
599 SetUInt64Value( PLAYER__FIELD_KNOWN_TITLES1
, 0 ); // 0=disabled
600 SetUInt32Value( PLAYER_CHOSEN_TITLE
, 0 );
601 SetUInt32Value( PLAYER_FIELD_KILLS
, 0 );
602 SetUInt32Value( PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0 );
603 SetUInt32Value( PLAYER_FIELD_TODAY_CONTRIBUTION
, 0 );
604 SetUInt32Value( PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0 );
606 // set starting level
607 uint32 start_level
= getClass() != CLASS_DEATH_KNIGHT
608 ? sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
)
609 : sWorld
.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL
);
611 if (GetSession()->GetSecurity() >= SEC_MODERATOR
)
613 uint32 gm_level
= sWorld
.getConfig(CONFIG_START_GM_LEVEL
);
614 if(gm_level
> start_level
)
615 start_level
= gm_level
;
618 SetUInt32Value(UNIT_FIELD_LEVEL
, start_level
);
622 SetUInt32Value (PLAYER_FIELD_COINAGE
, sWorld
.getConfig(CONFIG_START_PLAYER_MONEY
));
623 SetUInt32Value (PLAYER_FIELD_HONOR_CURRENCY
, sWorld
.getConfig(CONFIG_START_HONOR_POINTS
));
624 SetUInt32Value (PLAYER_FIELD_ARENA_CURRENCY
, sWorld
.getConfig(CONFIG_START_ARENA_POINTS
));
627 m_Last_tick
= time(NULL
);
628 m_Played_time
[0] = 0;
629 m_Played_time
[1] = 0;
631 // base stats and related field values
633 InitTaxiNodesForLevel();
634 InitGlyphsForLevel();
635 InitTalentForLevel();
636 InitPrimaryProffesions(); // to max set before any spell added
638 // apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()
639 UpdateMaxHealth(); // Update max Health (for add bonus from stamina)
640 SetHealth(GetMaxHealth());
641 if (getPowerType()==POWER_MANA
)
643 UpdateMaxPower(POWER_MANA
); // Update max Mana (for add bonus from intellect)
644 SetPower(POWER_MANA
,GetMaxPower(POWER_MANA
));
647 if(getPowerType() == POWER_RUNIC_POWER
)
649 SetPower(POWER_RUNE
, 8);
650 SetMaxPower(POWER_RUNE
, 8);
651 SetPower(POWER_RUNIC_POWER
, 0);
652 SetMaxPower(POWER_RUNIC_POWER
, 1000);
656 learnDefaultSpells();
658 // original action bar
659 std::list
<uint16
>::const_iterator action_itr
[4];
660 for(int i
=0; i
<4; i
++)
661 action_itr
[i
] = info
->action
[i
].begin();
663 for (; action_itr
[0]!=info
->action
[0].end() && action_itr
[1]!=info
->action
[1].end();)
666 for(int i
=0; i
<4 ;i
++)
667 taction
[i
] = (*action_itr
[i
]);
669 addActionButton((uint8
)taction
[0], taction
[1], (uint8
)taction
[2], (uint8
)taction
[3]);
671 for(int i
=0; i
<4 ;i
++)
676 CharStartOutfitEntry
const* oEntry
= NULL
;
677 for (uint32 i
= 1; i
< sCharStartOutfitStore
.GetNumRows(); ++i
)
679 if(CharStartOutfitEntry
const* entry
= sCharStartOutfitStore
.LookupEntry(i
))
681 if(entry
->RaceClassGender
== RaceClassGender
)
691 for(int j
= 0; j
< MAX_OUTFIT_ITEMS
; ++j
)
693 if(oEntry
->ItemId
[j
] <= 0)
696 uint32 item_id
= oEntry
->ItemId
[j
];
699 // Hack for not existed item id in dbc 3.0.3
703 ItemPrototype
const* iProto
= objmgr
.GetItemPrototype(item_id
);
706 sLog
.outErrorDb("Initial item id %u (race %u class %u) from CharStartOutfit.dbc not listed in `item_template`, ignoring.",item_id
,getRace(),getClass());
710 // max stack by default (mostly 1), 1 for infinity stackable
711 uint32 count
= iProto
->Stackable
> 0 ? uint32(iProto
->Stackable
) : 1;
713 if(iProto
->Class
==ITEM_CLASS_CONSUMABLE
&& iProto
->SubClass
==ITEM_SUBCLASS_FOOD
)
715 switch(iProto
->Spells
[0].SpellCategory
)
718 if(iProto
->Stackable
> 4)
722 if(iProto
->Stackable
> 2)
728 StoreNewItemInBestSlots(item_id
, count
);
732 for (PlayerCreateInfoItems::const_iterator item_id_itr
= info
->item
.begin(); item_id_itr
!=info
->item
.end(); ++item_id_itr
++)
733 StoreNewItemInBestSlots(item_id_itr
->item_id
, item_id_itr
->item_amount
);
735 // bags and main-hand weapon must equipped at this moment
736 // now second pass for not equipped (offhand weapon/shield if it attempt equipped before main-hand weapon)
737 // or ammo not equipped in special bag
738 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
740 if(Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
743 // equip offhand weapon/shield if it attempt equipped before main-hand weapon
744 uint8 msg
= CanEquipItem( NULL_SLOT
, eDest
, pItem
, false );
745 if( msg
== EQUIP_ERR_OK
)
747 RemoveItem(INVENTORY_SLOT_BAG_0
, i
,true);
748 EquipItem( eDest
, pItem
, true);
750 // move other items to more appropriate slots (ammo not equipped in special bag)
753 ItemPosCountVec sDest
;
754 msg
= CanStoreItem( NULL_BAG
, NULL_SLOT
, sDest
, pItem
, false );
755 if( msg
== EQUIP_ERR_OK
)
757 RemoveItem(INVENTORY_SLOT_BAG_0
, i
,true);
758 pItem
= StoreItem( sDest
, pItem
, true);
761 // if this is ammo then use it
762 uint8 msg
= CanUseAmmo( pItem
->GetProto()->ItemId
);
763 if( msg
== EQUIP_ERR_OK
)
764 SetAmmo( pItem
->GetProto()->ItemId
);
768 // all item positions resolved
773 bool Player::StoreNewItemInBestSlots(uint32 titem_id
, uint32 titem_amount
)
775 sLog
.outDebug("STORAGE: Creating initial item, itemId = %u, count = %u",titem_id
, titem_amount
);
777 // attempt equip by one
778 while(titem_amount
> 0)
781 uint8 msg
= CanEquipNewItem( NULL_SLOT
, eDest
, titem_id
, false );
782 if( msg
!= EQUIP_ERR_OK
)
785 EquipNewItem( eDest
, titem_id
, true);
786 AutoUnequipOffhandIfNeed();
790 if(titem_amount
== 0)
791 return true; // equipped
794 ItemPosCountVec sDest
;
795 // store in main bag to simplify second pass (special bags can be not equipped yet at this moment)
796 uint8 msg
= CanStoreNewItem( INVENTORY_SLOT_BAG_0
, NULL_SLOT
, sDest
, titem_id
, titem_amount
);
797 if( msg
== EQUIP_ERR_OK
)
799 StoreNewItem( sDest
, titem_id
, true, Item::GenerateItemRandomPropertyId(titem_id
) );
800 return true; // stored
803 // item can't be added
804 sLog
.outError("STORAGE: Can't equip or store initial item %u for race %u class %u , error msg = %u",titem_id
,getRace(),getClass(),msg
);
808 void Player::StartMirrorTimer(MirrorTimerType Type
, uint32 MaxValue
)
810 uint32 BreathRegen
= (uint32
)-1;
812 WorldPacket
data(SMSG_START_MIRROR_TIMER
, (21));
813 data
<< (uint32
)Type
;
818 data
<< (uint32
)0; // spell id
819 GetSession()->SendPacket(&data
);
822 void Player::ModifyMirrorTimer(MirrorTimerType Type
, uint32 MaxValue
, uint32 CurrentValue
, uint32 Regen
)
824 if(Type
==BREATH_TIMER
)
825 m_breathTimer
= ((MaxValue
+ 1000) - CurrentValue
) / Regen
;
827 WorldPacket
data(SMSG_START_MIRROR_TIMER
, (21));
828 data
<< (uint32
)Type
;
829 data
<< CurrentValue
;
833 data
<< (uint32
)0; // spell id
834 GetSession()->SendPacket( &data
);
837 void Player::StopMirrorTimer(MirrorTimerType Type
)
839 if(Type
==BREATH_TIMER
)
842 WorldPacket
data(SMSG_STOP_MIRROR_TIMER
, 4);
843 data
<< (uint32
)Type
;
844 GetSession()->SendPacket( &data
);
847 void Player::EnvironmentalDamage(uint64 guid
, EnviromentalDamage type
, uint32 damage
)
849 WorldPacket
data(SMSG_ENVIRONMENTALDAMAGELOG
, (21));
850 data
<< (uint64
)guid
;
851 data
<< (uint8
)(type
!=DAMAGE_FALL_TO_VOID
? type
: DAMAGE_FALL
);
852 data
<< (uint32
)damage
;
855 SendMessageToSet(&data
, true);
857 DealDamage(this, damage
, NULL
, SELF_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
859 if(type
==DAMAGE_FALL
&& !isAlive()) // DealDamage not apply item durability loss at self damage
861 DEBUG_LOG("We are fall to death, loosing 10 percents durability");
862 DurabilityLossAll(0.10f
,false);
863 // durability lost message
864 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
865 GetSession()->SendPacket(&data
);
869 void Player::HandleDrowning()
871 if(!(m_isunderwater
&~UNDERWATER_INLAVA
))
874 //if player is GM, have waterbreath, is dead or if breathing is disabled then return
875 if(isGameMaster() || !isAlive() || HasAuraType(SPELL_AURA_WATER_BREATHING
) || GetSession()->GetSecurity() >= sWorld
.getConfig(CONFIG_DISABLE_BREATHING
))
877 StopMirrorTimer(BREATH_TIMER
);
878 // drop every flag _except_ LAVA - otherwise waterbreathing will prevent lava damage
879 m_isunderwater
&= UNDERWATER_INLAVA
;
883 uint32 UnderWaterTime
= 1*MINUTE
*1000; // default length 1 min
885 AuraList
const& mModWaterBreathing
= GetAurasByType(SPELL_AURA_MOD_WATER_BREATHING
);
886 for(AuraList::const_iterator i
= mModWaterBreathing
.begin(); i
!= mModWaterBreathing
.end(); ++i
)
887 UnderWaterTime
= uint32(UnderWaterTime
* (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
);
889 if ((m_isunderwater
& UNDERWATER_INWATER
) && !(m_isunderwater
& UNDERWATER_INLAVA
) && isAlive())
891 //single trigger timer
892 if (!(m_isunderwater
& UNDERWATER_WATER_TRIGGER
))
894 m_isunderwater
|= UNDERWATER_WATER_TRIGGER
;
895 m_breathTimer
= UnderWaterTime
+ 1000;
897 //single trigger "show Breathbar"
898 if ( m_breathTimer
<= UnderWaterTime
&& !(m_isunderwater
& UNDERWATER_WATER_BREATHB
))
900 m_isunderwater
|= UNDERWATER_WATER_BREATHB
;
901 StartMirrorTimer(BREATH_TIMER
, UnderWaterTime
);
903 //continuous trigger drowning "Damage"
904 if ((m_breathTimer
== 0) && (m_isunderwater
& UNDERWATER_INWATER
))
906 //TODO: Check this formula
907 uint64 guid
= GetGUID();
908 uint32 damage
= GetMaxHealth() / 5 + urand(0, getLevel()-1);
910 EnvironmentalDamage(guid
, DAMAGE_DROWNING
,damage
);
911 m_breathTimer
= 2000;
914 //single trigger retract bar
915 else if (!(m_isunderwater
& UNDERWATER_INWATER
) && (m_isunderwater
& UNDERWATER_WATER_TRIGGER
) && (m_breathTimer
> 0) && isAlive())
917 uint32 BreathRegen
= 10;
918 // m_breathTimer will be reduced in ModifyMirrorTimer
919 ModifyMirrorTimer(BREATH_TIMER
, UnderWaterTime
, m_breathTimer
,BreathRegen
);
920 m_isunderwater
= UNDERWATER_WATER_BREATHB_RETRACTING
;
923 else if ((m_breathTimer
< 50) && !(m_isunderwater
& UNDERWATER_INWATER
) && (m_isunderwater
== UNDERWATER_WATER_BREATHB_RETRACTING
))
925 StopMirrorTimer(BREATH_TIMER
);
926 m_isunderwater
= UNDERWATER_NONE
;
930 void Player::HandleLava()
932 if ((m_isunderwater
& UNDERWATER_INLAVA
) && isAlive())
935 * arrai: how is this supposed to work? UNDERWATER_INLAVA is always set in this scope!
936 // Single trigger Set BreathTimer
937 if (!(m_isunderwater & UNDERWATER_INLAVA))
939 m_isunderwater|= UNDERWATER_WATER_BREATHB;
940 m_breathTimer = 1000;
943 // Reset BreathTimer and still in the lava
946 uint64 guid
= GetGUID();
947 uint32 damage
= urand(600, 700); // TODO: Get more detailed information about lava damage
949 // if not gamemaster then deal damage
950 if ( !isGameMaster() )
951 EnvironmentalDamage(guid
, DAMAGE_LAVA
, damage
);
953 m_breathTimer
= 1000;
956 else if (!isAlive()) // Disable breath timer and reset underwater flags
959 m_isunderwater
= UNDERWATER_NONE
;
963 ///The player sobers by 256 every 10 seconds
964 void Player::HandleSobering()
968 uint32 drunk
= (m_drunk
<= 256) ? 0 : (m_drunk
- 256);
969 SetDrunkValue(drunk
);
972 DrunkenState
Player::GetDrunkenstateByValue(uint16 value
)
975 return DRUNKEN_SMASHED
;
977 return DRUNKEN_DRUNK
;
979 return DRUNKEN_TIPSY
;
980 return DRUNKEN_SOBER
;
983 void Player::SetDrunkValue(uint16 newDrunkenValue
, uint32 itemId
)
985 uint32 oldDrunkenState
= Player::GetDrunkenstateByValue(m_drunk
);
987 m_drunk
= newDrunkenValue
;
988 SetUInt32Value(PLAYER_BYTES_3
,(GetUInt32Value(PLAYER_BYTES_3
) & 0xFFFF0001) | (m_drunk
& 0xFFFE));
990 uint32 newDrunkenState
= Player::GetDrunkenstateByValue(m_drunk
);
992 // special drunk invisibility detection
993 if(newDrunkenState
>= DRUNKEN_DRUNK
)
994 m_detectInvisibilityMask
|= (1<<6);
996 m_detectInvisibilityMask
&= ~(1<<6);
998 if(newDrunkenState
== oldDrunkenState
)
1001 WorldPacket
data(SMSG_CROSSED_INEBRIATION_THRESHOLD
, (8+4+4));
1002 data
<< uint64(GetGUID());
1003 data
<< uint32(newDrunkenState
);
1004 data
<< uint32(itemId
);
1006 SendMessageToSet(&data
, true);
1009 void Player::Update( uint32 p_time
)
1015 if(m_nextMailDelivereTime
&& m_nextMailDelivereTime
<= time(NULL
))
1020 // It will be recalculate at mailbox open (for unReadMails important non-0 until mailbox open, it also will be recalculated)
1021 m_nextMailDelivereTime
= 0;
1024 Unit::Update( p_time
);
1026 // update player only attacks
1027 if(uint32 ranged_att
= getAttackTimer(RANGED_ATTACK
))
1029 setAttackTimer(RANGED_ATTACK
, (p_time
>= ranged_att
? 0 : ranged_att
- p_time
) );
1032 if(uint32 off_att
= getAttackTimer(OFF_ATTACK
))
1034 setAttackTimer(OFF_ATTACK
, (p_time
>= off_att
? 0 : off_att
- p_time
) );
1037 time_t now
= time (NULL
);
1041 UpdateContestedPvP(p_time
);
1043 UpdateDuelFlag(now
);
1045 CheckDuelDistance(now
);
1047 UpdateAfkReport(now
);
1049 CheckExploreSystem();
1051 // Update items that have just a limited lifetime
1052 if (now
>m_Last_tick
)
1053 UpdateItemDuration(uint32(now
- m_Last_tick
));
1055 if (!m_timedquests
.empty())
1057 std::set
<uint32
>::iterator iter
= m_timedquests
.begin();
1058 while (iter
!= m_timedquests
.end())
1060 QuestStatusData
& q_status
= mQuestStatus
[*iter
];
1061 if( q_status
.m_timer
<= p_time
)
1063 uint32 quest_id
= *iter
;
1064 ++iter
; // current iter will be removed in FailTimedQuest
1065 FailTimedQuest( quest_id
);
1069 q_status
.m_timer
-= p_time
;
1070 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
1076 if (hasUnitState(UNIT_STAT_MELEE_ATTACKING
))
1078 Unit
*pVictim
= getVictim();
1079 if( !IsNonMeleeSpellCasted(false) && pVictim
)
1081 // default combat reach 10
1082 // TODO add weapon,skill check
1084 float pldistance
= ATTACK_DISTANCE
;
1086 if (isAttackReady(BASE_ATTACK
))
1088 if(!IsWithinDistInMap(pVictim
, pldistance
))
1090 setAttackTimer(BASE_ATTACK
,100);
1091 if(m_swingErrorMsg
!= 1) // send single time (client auto repeat)
1093 SendAttackSwingNotInRange();
1094 m_swingErrorMsg
= 1;
1097 //120 degrees of radiant range
1098 else if( !HasInArc( 2*M_PI
/3, pVictim
))
1100 setAttackTimer(BASE_ATTACK
,100);
1101 if(m_swingErrorMsg
!= 2) // send single time (client auto repeat)
1103 SendAttackSwingBadFacingAttack();
1104 m_swingErrorMsg
= 2;
1109 m_swingErrorMsg
= 0; // reset swing error state
1111 // prevent base and off attack in same time, delay attack at 0.2 sec
1112 if(haveOffhandWeapon())
1114 uint32 off_att
= getAttackTimer(OFF_ATTACK
);
1115 if(off_att
< ATTACK_DISPLAY_DELAY
)
1116 setAttackTimer(OFF_ATTACK
,ATTACK_DISPLAY_DELAY
);
1118 AttackerStateUpdate(pVictim
, BASE_ATTACK
);
1119 resetAttackTimer(BASE_ATTACK
);
1123 if ( haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
1125 if(!IsWithinDistInMap(pVictim
, pldistance
))
1127 setAttackTimer(OFF_ATTACK
,100);
1129 else if( !HasInArc( 2*M_PI
/3, pVictim
))
1131 setAttackTimer(OFF_ATTACK
,100);
1135 // prevent base and off attack in same time, delay attack at 0.2 sec
1136 uint32 base_att
= getAttackTimer(BASE_ATTACK
);
1137 if(base_att
< ATTACK_DISPLAY_DELAY
)
1138 setAttackTimer(BASE_ATTACK
,ATTACK_DISPLAY_DELAY
);
1140 AttackerStateUpdate(pVictim
, OFF_ATTACK
);
1141 resetAttackTimer(OFF_ATTACK
);
1145 Unit
*owner
= pVictim
->GetOwner();
1146 Unit
*u
= owner
? owner
: pVictim
;
1147 if(u
->IsPvP() && (!duel
|| duel
->opponent
!= u
))
1150 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
1155 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
))
1157 if(roll_chance_i(3) && GetTimeInnEnter() > 0) //freeze update
1159 int time_inn
= time(NULL
)-GetTimeInnEnter();
1160 if (time_inn
>= 10) //freeze update
1162 float bubble
= 0.125*sWorld
.getRate(RATE_REST_INGAME
);
1163 //speed collect rest bonus (section/in hour)
1164 SetRestBonus( GetRestBonus()+ time_inn
*((float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP
)/72000)*bubble
);
1165 UpdateInnerTime(time(NULL
));
1170 if(m_regenTimer
> 0)
1172 if(p_time
>= m_regenTimer
)
1175 m_regenTimer
-= p_time
;
1178 if (m_weaponChangeTimer
> 0)
1180 if(p_time
>= m_weaponChangeTimer
)
1181 m_weaponChangeTimer
= 0;
1183 m_weaponChangeTimer
-= p_time
;
1186 if (m_zoneUpdateTimer
> 0)
1188 if(p_time
>= m_zoneUpdateTimer
)
1190 uint32 newzone
= GetZoneId();
1191 if( m_zoneUpdateId
!= newzone
)
1192 UpdateZone(newzone
); // also update area
1195 // use area updates as well
1196 // needed for free far all arenas for example
1197 uint32 newarea
= GetAreaId();
1198 if( m_areaUpdateId
!= newarea
)
1199 UpdateArea(newarea
);
1201 m_zoneUpdateTimer
= ZONE_UPDATE_INTERVAL
;
1205 m_zoneUpdateTimer
-= p_time
;
1213 if (m_deathState
== JUST_DIED
)
1220 if(p_time
>= m_nextSave
)
1222 // m_nextSave reseted in SaveToDB call
1224 sLog
.outDetail("Player '%s' (GUID: %u) saved", GetName(), GetGUIDLow());
1228 m_nextSave
-= p_time
;
1233 if(m_breathTimer
> 0)
1235 if(p_time
>= m_breathTimer
)
1238 m_breathTimer
-= p_time
;
1242 //Handle Water/drowning
1248 //Handle detect stealth players
1249 if (m_DetectInvTimer
> 0)
1251 if (p_time
>= m_DetectInvTimer
)
1253 m_DetectInvTimer
= 3000;
1254 HandleStealthedUnitsDetection();
1257 m_DetectInvTimer
-= p_time
;
1261 if (now
> m_Last_tick
)
1263 uint32 elapsed
= uint32(now
- m_Last_tick
);
1264 m_Played_time
[0] += elapsed
; // Total played time
1265 m_Played_time
[1] += elapsed
; // Level played time
1271 m_drunkTimer
+= p_time
;
1273 if (m_drunkTimer
> 10000)
1277 // not auto-free ghost from body in instances
1278 if(m_deathTimer
> 0 && !GetBaseMap()->Instanceable())
1280 if(p_time
>= m_deathTimer
)
1287 m_deathTimer
-= p_time
;
1290 UpdateEnchantTime(p_time
);
1291 UpdateHomebindTime(p_time
);
1294 SendUpdateToOutOfRangeGroupMembers();
1296 Pet
* pet
= GetPet();
1297 if(pet
&& !IsWithinDistInMap(pet
, OWNER_MAX_DISTANCE
) && (GetCharmGUID() && (pet
->GetGUID() != GetCharmGUID())))
1299 RemovePet(pet
, PET_SAVE_NOT_IN_SLOT
, true);
1304 void Player::setDeathState(DeathState s
)
1306 uint32 ressSpellId
= 0;
1308 bool cur
= isAlive();
1310 if(s
== JUST_DIED
&& cur
)
1312 // drunken state is cleared on death
1314 // lost combo points at any target (targeted combo points clear in Unit::setDeathState)
1317 clearResurrectRequestData();
1319 // remove form before other mods to prevent incorrect stats calculation
1320 RemoveAurasDueToSpell(m_ShapeShiftFormSpellId
);
1322 //FIXME: is pet dismissed at dying or releasing spirit? if second, add setDeathState(DEAD) to HandleRepopRequestOpcode and define pet unsummon here with (s == DEAD)
1323 RemovePet(NULL
, PET_SAVE_NOT_IN_SLOT
, true);
1325 // remove uncontrolled pets
1329 // save value before aura remove in Unit::setDeathState
1330 ressSpellId
= GetUInt32Value(PLAYER_SELF_RES_SPELL
);
1334 ressSpellId
= GetResurrectionSpellId();
1335 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DEATH_AT_MAP
, 1);
1337 Unit::setDeathState(s
);
1339 // restore resurrection spell id for player after aura remove
1340 if(s
== JUST_DIED
&& cur
&& ressSpellId
)
1341 SetUInt32Value(PLAYER_SELF_RES_SPELL
, ressSpellId
);
1343 if(isAlive() && !cur
)
1345 //clear aura case after resurrection by another way (spells will be applied before next death)
1346 SetUInt32Value(PLAYER_SELF_RES_SPELL
, 0);
1348 // restore default warrior stance
1349 if(getClass()== CLASS_WARRIOR
)
1350 CastSpell(this,SPELL_ID_PASSIVE_BATTLE_STANCE
,true);
1354 void Player::BuildEnumData( QueryResult
* result
, WorldPacket
* p_data
)
1356 Field
*fields
= result
->Fetch();
1358 *p_data
<< uint64(GetGUID());
1361 *p_data
<< uint8(getRace());
1362 uint8 pClass
= getClass();
1363 *p_data
<< uint8(pClass
);
1364 *p_data
<< uint8(getGender());
1366 uint32 bytes
= GetUInt32Value(PLAYER_BYTES
);
1367 *p_data
<< uint8(bytes
);
1368 *p_data
<< uint8(bytes
>> 8);
1369 *p_data
<< uint8(bytes
>> 16);
1370 *p_data
<< uint8(bytes
>> 24);
1372 bytes
= GetUInt32Value(PLAYER_BYTES_2
);
1373 *p_data
<< uint8(bytes
);
1375 *p_data
<< uint8(getLevel()); // player level
1376 // do not use GetMap! it will spawn a new instance since the bound instances are not loaded
1377 uint32 zoneId
= MapManager::Instance().GetZoneId(GetMapId(), GetPositionX(),GetPositionY(),GetPositionZ());
1378 sLog
.outDebug("Player::BuildEnumData: m:%u, x:%f, y:%f, z:%f zone:%u", GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ(), zoneId
);
1379 *p_data
<< uint32(zoneId
);
1380 *p_data
<< uint32(GetMapId());
1382 *p_data
<< GetPositionX();
1383 *p_data
<< GetPositionY();
1384 *p_data
<< GetPositionZ();
1387 *p_data
<< (result
? fields
[13].GetUInt32() : 0);
1389 uint32 char_flags
= 0;
1390 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_HELM
))
1391 char_flags
|= CHARACTER_FLAG_HIDE_HELM
;
1392 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_CLOAK
))
1393 char_flags
|= CHARACTER_FLAG_HIDE_CLOAK
;
1394 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
))
1395 char_flags
|= CHARACTER_FLAG_GHOST
;
1396 if(HasAtLoginFlag(AT_LOGIN_RENAME
))
1397 char_flags
|= CHARACTER_FLAG_RENAME
;
1398 if(sWorld
.getConfig(CONFIG_DECLINED_NAMES_USED
) && (fields
[14].GetCppString() != ""))
1399 char_flags
|= CHARACTER_FLAG_DECLINED
;
1401 *p_data
<< uint32(char_flags
); // character flags
1402 // character customize (flags?)
1403 *p_data
<< uint32(HasAtLoginFlag(AT_LOGIN_CUSTOMIZE
) ? 1 : 0);
1404 *p_data
<< uint8(1); // unknown
1408 uint32 petDisplayId
= 0;
1409 uint32 petLevel
= 0;
1410 uint32 petFamily
= 0;
1412 // show pet at selection character in character list only for non-ghost character
1413 if(result
&& isAlive() && (pClass
== CLASS_WARLOCK
|| pClass
== CLASS_HUNTER
))
1415 uint32 entry
= fields
[10].GetUInt32();
1416 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
>(entry
);
1419 petDisplayId
= fields
[11].GetUInt32();
1420 petLevel
= fields
[12].GetUInt32();
1421 petFamily
= cInfo
->family
;
1425 *p_data
<< uint32(petDisplayId
);
1426 *p_data
<< uint32(petLevel
);
1427 *p_data
<< uint32(petFamily
);
1430 for (uint8 slot
= 0; slot
< EQUIPMENT_SLOT_END
; slot
++)
1432 uint32 visualbase
= PLAYER_VISIBLE_ITEM_1_0
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
);
1433 uint32 item_id
= GetUInt32Value(visualbase
);
1434 const ItemPrototype
* proto
= objmgr
.GetItemPrototype(item_id
);
1435 SpellItemEnchantmentEntry
const *enchant
= NULL
;
1437 for(uint8 enchantSlot
= PERM_ENCHANTMENT_SLOT
; enchantSlot
<=TEMP_ENCHANTMENT_SLOT
; enchantSlot
++)
1439 uint32 enchantId
= GetUInt32Value(visualbase
+1+enchantSlot
);
1440 if(enchant
= sSpellItemEnchantmentStore
.LookupEntry(enchantId
))
1446 *p_data
<< uint32(proto
->DisplayInfoID
);
1447 *p_data
<< uint8(proto
->InventoryType
);
1448 *p_data
<< uint32(enchant
? enchant
->aura_id
: 0);
1452 *p_data
<< uint32(0);
1453 *p_data
<< uint8(0);
1454 *p_data
<< uint32(0); // enchant?
1457 *p_data
<< uint32(0); // first bag display id
1458 *p_data
<< uint8(0); // first bag inventory type
1459 *p_data
<< uint32(0); // enchant?
1462 bool Player::ToggleAFK()
1464 ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_AFK
);
1466 bool state
= HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_AFK
);
1468 // afk player not allowed in battleground
1469 if(state
&& InBattleGround())
1470 LeaveBattleground();
1475 bool Player::ToggleDND()
1477 ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_DND
);
1479 return HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_DND
);
1482 uint8
Player::chatTag() const
1499 bool Player::TeleportTo(uint32 mapid
, float x
, float y
, float z
, float orientation
, uint32 options
)
1501 if(!MapManager::IsValidMapCoord(mapid
, x
, y
, z
, orientation
))
1503 sLog
.outError("TeleportTo: invalid map %d or absent instance template.", mapid
);
1507 // preparing unsummon pet if lost (we must get pet before teleportation or will not find it later)
1508 Pet
* pet
= GetPet();
1510 MapEntry
const* mEntry
= sMapStore
.LookupEntry(mapid
);
1512 // don't let enter battlegrounds without assigned battleground id (for example through areatrigger)...
1513 // don't let gm level > 1 either
1514 if(!InBattleGround() && mEntry
->IsBattleGroundOrArena())
1517 // client without expansion support
1518 if(GetSession()->Expansion() < mEntry
->Expansion())
1520 sLog
.outDebug("Player %s using client without required expansion tried teleport to non accessible map %u", GetName(), mapid
);
1523 RepopAtGraveyard(); // teleport to near graveyard if on transport, looks blizz like :)
1525 SendTransferAborted(mapid
, TRANSFER_ABORT_INSUF_EXPAN_LVL
, mEntry
->Expansion());
1527 return false; // normal client can't teleport to this map...
1531 sLog
.outDebug("Player %s will teleported to map %u", GetName(), mapid
);
1534 // if we were on a transport, leave
1535 if (!(options
& TELE_TO_NOT_LEAVE_TRANSPORT
) && m_transport
)
1537 m_transport
->RemovePassenger(this);
1539 m_movementInfo
.t_x
= 0.0f
;
1540 m_movementInfo
.t_y
= 0.0f
;
1541 m_movementInfo
.t_z
= 0.0f
;
1542 m_movementInfo
.t_o
= 0.0f
;
1543 m_movementInfo
.t_time
= 0;
1546 SetSemaphoreTeleport(true);
1548 // The player was ported to another map and looses the duel immediately.
1549 // We have to perform this check before the teleport, otherwise the
1550 // ObjectAccessor won't find the flag.
1551 if (duel
&& GetMapId()!=mapid
)
1553 GameObject
* obj
= ObjectAccessor::GetGameObject(*this, GetUInt64Value(PLAYER_DUEL_ARBITER
));
1555 DuelComplete(DUEL_FLED
);
1558 // reset movement flags at teleport, because player will continue move with these flags after teleport
1559 SetUnitMovementFlags(0);
1561 if ((GetMapId() == mapid
) && (!m_transport
))
1563 // prepare zone change detect
1564 uint32 old_zone
= GetZoneId();
1567 if(!GetSession()->PlayerLogout())
1570 BuildTeleportAckMsg(&data
, x
, y
, z
, orientation
);
1571 GetSession()->SendPacket(&data
);
1572 SetPosition( x
, y
, z
, orientation
, true);
1575 // this will be used instead of the current location in SaveToDB
1576 m_teleport_dest
= WorldLocation(mapid
, x
, y
, z
, orientation
);
1577 SetFallInformation(0, z
);
1579 //BuildHeartBeatMsg(&data);
1580 //SendMessageToSet(&data, true);
1581 if (!(options
& TELE_TO_NOT_UNSUMMON_PET
))
1583 //same map, only remove pet if out of range
1584 if(pet
&& !IsWithinDistInMap(pet
, OWNER_MAX_DISTANCE
))
1586 if(pet
->isControlled() && !pet
->isTemporarySummoned() )
1587 m_temporaryUnsummonedPetNumber
= pet
->GetCharmInfo()->GetPetNumber();
1589 m_temporaryUnsummonedPetNumber
= 0;
1591 RemovePet(pet
, PET_SAVE_NOT_IN_SLOT
);
1595 if(!(options
& TELE_TO_NOT_LEAVE_COMBAT
))
1598 if (!(options
& TELE_TO_NOT_UNSUMMON_PET
))
1601 if(pet
&& m_temporaryUnsummonedPetNumber
)
1603 Pet
* NewPet
= new Pet
;
1604 if(!NewPet
->LoadPetFromDB(this, 0, m_temporaryUnsummonedPetNumber
, true))
1607 m_temporaryUnsummonedPetNumber
= 0;
1611 if(!GetSession()->PlayerLogout())
1613 // don't reset teleport semaphore while logging out, otherwise m_teleport_dest won't be used in Player::SaveToDB
1614 SetSemaphoreTeleport(false);
1616 UpdateZone(GetZoneId());
1620 if(old_zone
!= GetZoneId())
1623 if(pvpInfo
.inHostileArea
)
1624 CastSpell(this, 2479, true);
1629 // far teleport to another map
1630 Map
* oldmap
= IsInWorld() ? GetMap() : NULL
;
1631 // check if we can enter before stopping combat / removing pet / totems / interrupting spells
1633 // Check enter rights before map getting to avoid creating instance copy for player
1634 // this check not dependent from map instance copy and same for all instance copies of selected map
1635 if (!MapManager::Instance().CanPlayerEnter(mapid
, this))
1637 SetSemaphoreTeleport(false);
1641 // If the map is not created, assume it is possible to enter it.
1642 // It will be created in the WorldPortAck.
1643 Map
*map
= MapManager::Instance().FindMap(mapid
);
1644 if (!map
|| map
->CanEnter(this))
1650 ResetContestedPvP();
1652 // remove player from battleground on far teleport (when changing maps)
1653 if(BattleGround
const* bg
= GetBattleGround())
1655 // Note: at battleground join battleground id set before teleport
1656 // and we already will found "current" battleground
1657 // just need check that this is targeted map or leave
1658 if(bg
->GetMapId() != mapid
)
1659 LeaveBattleground(false); // don't teleport to entry point
1662 // remove pet on map change
1665 //leaving map -> delete pet right away (doing this later will cause problems)
1666 if(pet
->isControlled() && !pet
->isTemporarySummoned())
1667 m_temporaryUnsummonedPetNumber
= pet
->GetCharmInfo()->GetPetNumber();
1669 m_temporaryUnsummonedPetNumber
= 0;
1671 RemovePet(pet
, PET_SAVE_NOT_IN_SLOT
);
1674 // remove all dyn objects
1675 RemoveAllDynObjects();
1677 // stop spellcasting
1678 // not attempt interrupt teleportation spell at caster teleport
1679 if(!(options
& TELE_TO_SPELL
))
1680 if(IsNonMeleeSpellCasted(true))
1681 InterruptNonMeleeSpells(true);
1683 if(!GetSession()->PlayerLogout())
1685 // send transfer packets
1686 WorldPacket
data(SMSG_TRANSFER_PENDING
, (4+4+4));
1687 data
<< uint32(mapid
);
1690 data
<< m_transport
->GetEntry() << GetMapId();
1692 GetSession()->SendPacket(&data
);
1694 data
.Initialize(SMSG_NEW_WORLD
, (20));
1697 data
<< (uint32
)mapid
<< m_movementInfo
.t_x
<< m_movementInfo
.t_y
<< m_movementInfo
.t_z
<< m_movementInfo
.t_o
;
1701 data
<< (uint32
)mapid
<< (float)x
<< (float)y
<< (float)z
<< (float)orientation
;
1703 GetSession()->SendPacket( &data
);
1704 SendSavedInstances();
1706 // remove from old map now
1707 if(oldmap
) oldmap
->Remove(this, false);
1710 // new final coordinates
1714 float final_o
= orientation
;
1718 final_x
+= m_movementInfo
.t_x
;
1719 final_y
+= m_movementInfo
.t_y
;
1720 final_z
+= m_movementInfo
.t_z
;
1721 final_o
+= m_movementInfo
.t_o
;
1724 m_teleport_dest
= WorldLocation(mapid
, final_x
, final_y
, final_z
, final_o
);
1725 SetFallInformation(0, final_z
);
1726 // if the player is saved before worldportack (at logout for example)
1727 // this will be used instead of the current location in SaveToDB
1729 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_CHANGE_MAP
);
1731 // move packet sent by client always after far teleport
1732 // SetPosition(final_x, final_y, final_z, final_o, true);
1735 // code for finish transfer to new map called in WorldSession::HandleMoveWorldportAckOpcode at client packet
1743 void Player::AddToWorld()
1745 ///- Do not add/remove the player from the object storage
1746 ///- It will crash when updating the ObjectAccessor
1747 ///- The player should only be added when logging in
1750 for(int i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
1753 m_items
[i
]->AddToWorld();
1757 void Player::RemoveFromWorld()
1762 ///- Release charmed creatures, unsummon totems and remove pets/guardians
1764 UnsummonAllTotems();
1769 for(int i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
1772 m_items
[i
]->RemoveFromWorld();
1775 ///- Do not add/remove the player from the object storage
1776 ///- It will crash when updating the ObjectAccessor
1777 ///- The player should only be removed when logging out
1778 Unit::RemoveFromWorld();
1781 void Player::RewardRage( uint32 damage
, uint32 weaponSpeedHitFactor
, bool attacker
)
1785 float rageconversion
= ((0.0091107836 * getLevel()*getLevel())+3.225598133*getLevel())+4.2652911;
1789 addRage
= ((damage
/rageconversion
*7.5 + weaponSpeedHitFactor
)/2);
1791 // talent who gave more rage on attack
1792 addRage
*= 1.0f
+ GetTotalAuraModifier(SPELL_AURA_MOD_RAGE_FROM_DAMAGE_DEALT
) / 100.0f
;
1796 addRage
= damage
/rageconversion
*2.5;
1798 // Berserker Rage effect
1799 if(HasAura(18499,0))
1803 addRage
*= sWorld
.getRate(RATE_POWER_RAGE_INCOME
);
1805 ModifyPower(POWER_RAGE
, uint32(addRage
*10));
1808 void Player::RegenerateAll()
1810 if (m_regenTimer
!= 0)
1812 uint32 regenDelay
= 2000;
1814 // Not in combat or they have regeneration
1815 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT
) ||
1816 HasAuraType(SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT
) || IsPolymorphed() )
1819 if (!isInCombat() && !HasAuraType(SPELL_AURA_INTERRUPT_REGEN
))
1821 Regenerate(POWER_RAGE
);
1822 if(getClass() == CLASS_DEATH_KNIGHT
)
1823 Regenerate(POWER_RUNIC_POWER
);
1827 Regenerate( POWER_ENERGY
);
1829 Regenerate( POWER_MANA
);
1831 if(getClass() == CLASS_DEATH_KNIGHT
)
1832 Regenerate( POWER_RUNE
);
1834 m_regenTimer
= regenDelay
;
1837 void Player::Regenerate(Powers power
)
1839 uint32 curValue
= GetPower(power
);
1840 uint32 maxValue
= GetMaxPower(power
);
1842 float addvalue
= 0.0f
;
1848 bool recentCast
= IsUnderLastManaUseEffect();
1849 float ManaIncreaseRate
= sWorld
.getRate(RATE_POWER_MANA
);
1852 // Mangos Updates Mana in intervals of 2s, which is correct
1853 addvalue
= GetFloatValue(UNIT_FIELD_POWER_REGEN_INTERRUPTED_FLAT_MODIFIER
) * ManaIncreaseRate
* 2.00f
;
1857 addvalue
= GetFloatValue(UNIT_FIELD_POWER_REGEN_FLAT_MODIFIER
) * ManaIncreaseRate
* 2.00f
;
1860 case POWER_RAGE
: // Regenerate rage
1862 float RageDecreaseRate
= sWorld
.getRate(RATE_POWER_RAGE_LOSS
);
1863 addvalue
= 30 * RageDecreaseRate
; // 3 rage by tick
1865 case POWER_ENERGY
: // Regenerate energy (rogue)
1868 case POWER_RUNIC_POWER
:
1870 float RunicPowerDecreaseRate
= sWorld
.getRate(RATE_POWER_RUNICPOWER_LOSS
);
1871 addvalue
= 30 * RunicPowerDecreaseRate
; // 3 RunicPower by tick
1875 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
1876 if(uint8 cd
= GetRuneCooldown(i
)) // if we have cooldown, reduce it...
1877 SetRuneCooldown(i
, cd
- 1); // ... by 2 sec (because update is every 2 sec)
1880 case POWER_HAPPINESS
:
1884 // Mana regen calculated in Player::UpdateManaRegen()
1885 // Exist only for POWER_MANA, POWER_ENERGY, POWER_FOCUS auras
1886 if(power
!= POWER_MANA
)
1888 AuraList
const& ModPowerRegenPCTAuras
= GetAurasByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT
);
1889 for(AuraList::const_iterator i
= ModPowerRegenPCTAuras
.begin(); i
!= ModPowerRegenPCTAuras
.end(); ++i
)
1890 if ((*i
)->GetModifier()->m_miscvalue
== power
)
1891 addvalue
*= ((*i
)->GetModifier()->m_amount
+ 100) / 100.0f
;
1894 if (power
!= POWER_RAGE
&& power
!= POWER_RUNIC_POWER
)
1896 curValue
+= uint32(addvalue
);
1897 if (curValue
> maxValue
)
1898 curValue
= maxValue
;
1902 if(curValue
<= uint32(addvalue
))
1905 curValue
-= uint32(addvalue
);
1907 SetPower(power
, curValue
);
1910 void Player::RegenerateHealth()
1912 uint32 curValue
= GetHealth();
1913 uint32 maxValue
= GetMaxHealth();
1915 if (curValue
>= maxValue
) return;
1917 float HealthIncreaseRate
= sWorld
.getRate(RATE_HEALTH
);
1919 float addvalue
= 0.0f
;
1922 if ( IsPolymorphed() )
1923 addvalue
= GetMaxHealth()/3;
1924 // normal regen case (maybe partly in combat case)
1925 else if (!isInCombat() || HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT
) )
1927 addvalue
= OCTRegenHPPerSpirit()* HealthIncreaseRate
;
1930 AuraList
const& mModHealthRegenPct
= GetAurasByType(SPELL_AURA_MOD_HEALTH_REGEN_PERCENT
);
1931 for(AuraList::const_iterator i
= mModHealthRegenPct
.begin(); i
!= mModHealthRegenPct
.end(); ++i
)
1932 addvalue
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
1934 else if(HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT
))
1935 addvalue
*= GetTotalAuraModifier(SPELL_AURA_MOD_REGEN_DURING_COMBAT
) / 100.0f
;
1941 // always regeneration bonus (including combat)
1942 addvalue
+= GetTotalAuraModifier(SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT
);
1947 ModifyHealth(int32(addvalue
));
1950 bool Player::CanInteractWithNPCs(bool alive
) const
1952 if(alive
&& !isAlive())
1960 bool Player::IsUnderWater() const
1962 return IsInWater() &&
1963 GetPositionZ() < (MapManager::Instance().GetBaseMap(GetMapId())->GetWaterLevel(GetPositionX(),GetPositionY())-2);
1966 void Player::SetInWater(bool apply
)
1968 if(m_isInWater
==apply
)
1971 //define player in water by opcodes
1972 //move player's guid into HateOfflineList of those mobs
1973 //which can't swim and move guid back into ThreatList when
1975 //TODO: exist also swimming mobs, and function must be symmetric to enter/leave water
1976 m_isInWater
= apply
;
1978 // remove auras that need water/land
1979 RemoveAurasWithInterruptFlags(apply
? AURA_INTERRUPT_FLAG_NOT_ABOVEWATER
: AURA_INTERRUPT_FLAG_NOT_UNDERWATER
);
1981 getHostilRefManager().updateThreatTables();
1984 void Player::SetGameMaster(bool on
)
1988 m_ExtraFlags
|= PLAYER_EXTRA_GM_ON
;
1990 SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GM
);
1992 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
1993 ResetContestedPvP();
1995 getHostilRefManager().setOnlineOfflineState(false);
2000 m_ExtraFlags
&= ~ PLAYER_EXTRA_GM_ON
;
2001 setFactionForRace(getRace());
2002 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GM
);
2004 // restore FFA PvP Server state
2005 if(sWorld
.IsFFAPvPRealm())
2006 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
2008 // restore FFA PvP area state, remove not allowed for GM mounts
2009 UpdateArea(m_areaUpdateId
);
2011 getHostilRefManager().setOnlineOfflineState(true);
2014 ObjectAccessor::UpdateVisibilityForPlayer(this);
2017 void Player::SetGMVisible(bool on
)
2021 m_ExtraFlags
&= ~PLAYER_EXTRA_GM_INVISIBLE
; //remove flag
2023 // Reapply stealth/invisibility if active or show if not any
2024 if(HasAuraType(SPELL_AURA_MOD_STEALTH
))
2025 SetVisibility(VISIBILITY_GROUP_STEALTH
);
2026 else if(HasAuraType(SPELL_AURA_MOD_INVISIBILITY
))
2027 SetVisibility(VISIBILITY_GROUP_INVISIBILITY
);
2029 SetVisibility(VISIBILITY_ON
);
2033 m_ExtraFlags
|= PLAYER_EXTRA_GM_INVISIBLE
; //add flag
2035 SetAcceptWhispers(false);
2036 SetGameMaster(true);
2038 SetVisibility(VISIBILITY_OFF
);
2042 bool Player::IsGroupVisibleFor(Player
* p
) const
2044 switch(sWorld
.getConfig(CONFIG_GROUP_VISIBILITY
))
2046 default: return IsInSameGroupWith(p
);
2047 case 1: return IsInSameRaidWith(p
);
2048 case 2: return GetTeam()==p
->GetTeam();
2052 bool Player::IsInSameGroupWith(Player
const* p
) const
2054 return p
==this || GetGroup() != NULL
&&
2055 GetGroup() == p
->GetGroup() &&
2056 GetGroup()->SameSubGroup((Player
*)this, (Player
*)p
);
2059 ///- If the player is invited, remove him. If the group if then only 1 person, disband the group.
2060 /// \todo Shouldn't we also check if there is no other invitees before disbanding the group?
2061 void Player::UninviteFromGroup()
2063 Group
* group
= GetGroupInvite();
2067 group
->RemoveInvite(this);
2069 if(group
->GetMembersCount() <= 1) // group has just 1 member => disband
2071 if(group
->IsCreated())
2073 group
->Disband(true);
2074 objmgr
.RemoveGroup(group
);
2077 group
->RemoveAllInvites();
2083 void Player::RemoveFromGroup(Group
* group
, uint64 guid
)
2087 if (group
->RemoveMember(guid
, 0) <= 1)
2089 // group->Disband(); already disbanded in RemoveMember
2090 objmgr
.RemoveGroup(group
);
2092 // removemember sets the player's group pointer to NULL
2097 void Player::SendLogXPGain(uint32 GivenXP
, Unit
* victim
, uint32 RestXP
)
2099 WorldPacket
data(SMSG_LOG_XPGAIN
, 21);
2100 data
<< uint64(victim
? victim
->GetGUID() : 0); // guid
2101 data
<< uint32(GivenXP
+RestXP
); // given experience
2102 data
<< uint8(victim
? 0 : 1); // 00-kill_xp type, 01-non_kill_xp type
2105 data
<< uint32(GivenXP
); // experience without rested bonus
2106 data
<< float(1); // 1 - none 0 - 100% group bonus output
2108 data
<< uint8(0); // new 2.4.0
2109 GetSession()->SendPacket(&data
);
2112 void Player::GiveXP(uint32 xp
, Unit
* victim
)
2120 uint32 level
= getLevel();
2122 // XP to money conversion processed in Player::RewardQuest
2123 if(level
>= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2126 // handle SPELL_AURA_MOD_XP_PCT auras
2127 Unit::AuraList
const& ModXPPctAuras
= GetAurasByType(SPELL_AURA_MOD_XP_PCT
);
2128 for(Unit::AuraList::const_iterator i
= ModXPPctAuras
.begin();i
!= ModXPPctAuras
.end(); ++i
)
2129 xp
= uint32(xp
*(1.0f
+ (*i
)->GetModifier()->m_amount
/ 100.0f
));
2131 // XP resting bonus for kill
2132 uint32 rested_bonus_xp
= victim
? GetXPRestBonus(xp
) : 0;
2134 SendLogXPGain(xp
,victim
,rested_bonus_xp
);
2136 uint32 curXP
= GetUInt32Value(PLAYER_XP
);
2137 uint32 nextLvlXP
= GetUInt32Value(PLAYER_NEXT_LEVEL_XP
);
2138 uint32 newXP
= curXP
+ xp
+ rested_bonus_xp
;
2140 while( newXP
>= nextLvlXP
&& level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) )
2144 if ( level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) )
2145 GiveLevel(level
+ 1);
2148 nextLvlXP
= GetUInt32Value(PLAYER_NEXT_LEVEL_XP
);
2151 SetUInt32Value(PLAYER_XP
, newXP
);
2154 // Update player to next level
2155 // Current player experience not update (must be update by caller)
2156 void Player::GiveLevel(uint32 level
)
2158 if ( level
== getLevel() )
2161 PlayerLevelInfo info
;
2162 objmgr
.GetPlayerLevelInfo(getRace(),getClass(),level
,&info
);
2164 PlayerClassLevelInfo classInfo
;
2165 objmgr
.GetPlayerClassLevelInfo(getClass(),level
,&classInfo
);
2167 // send levelup info to client
2168 WorldPacket
data(SMSG_LEVELUP_INFO
, (4+4+MAX_POWERS
*4+MAX_STATS
*4));
2169 data
<< uint32(level
);
2170 data
<< uint32(int32(classInfo
.basehealth
) - int32(GetCreateHealth()));
2171 // for(int i = 0; i < MAX_POWERS; ++i) // Powers loop (0-6)
2172 data
<< uint32(int32(classInfo
.basemana
) - int32(GetCreateMana()));
2180 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
) // Stats loop (0-4)
2181 data
<< uint32(int32(info
.stats
[i
]) - GetCreateStat(Stats(i
)));
2183 GetSession()->SendPacket(&data
);
2185 SetUInt32Value(PLAYER_NEXT_LEVEL_XP
, objmgr
.GetXPForLevel(level
));
2187 //update level, max level of skills
2188 if(getLevel()!= level
)
2189 m_Played_time
[1] = 0; // Level Played Time reset
2191 UpdateSkillsForLevel ();
2193 // save base values (bonuses already included in stored stats
2194 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
)
2195 SetCreateStat(Stats(i
), info
.stats
[i
]);
2197 SetCreateHealth(classInfo
.basehealth
);
2198 SetCreateMana(classInfo
.basemana
);
2200 InitTalentForLevel();
2201 InitTaxiNodesForLevel();
2202 InitGlyphsForLevel();
2206 // set current level health and mana/energy to maximum after applying all mods.
2207 SetHealth(GetMaxHealth());
2208 SetPower(POWER_MANA
, GetMaxPower(POWER_MANA
));
2209 SetPower(POWER_ENERGY
, GetMaxPower(POWER_ENERGY
));
2210 if(GetPower(POWER_RAGE
) > GetMaxPower(POWER_RAGE
))
2211 SetPower(POWER_RAGE
, GetMaxPower(POWER_RAGE
));
2212 SetPower(POWER_FOCUS
, 0);
2213 SetPower(POWER_HAPPINESS
, 0);
2215 // give level to summoned pet
2216 Pet
* pet
= GetPet();
2217 if(pet
&& pet
->getPetType()==SUMMON_PET
)
2218 pet
->GivePetLevel(level
);
2219 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_LEVEL
);
2222 void Player::InitTalentForLevel()
2224 uint32 level
= getLevel();
2225 // talents base at level diff ( talents = level - 9 but some can be used already)
2228 // Remove all talent points
2229 if(m_usedTalentCount
> 0) // Free any used talents
2232 SetFreeTalentPoints(0);
2237 uint32 talentPointsForLevel
= uint32((level
-9)*sWorld
.getRate(RATE_TALENT
));
2238 // if used more that have then reset
2239 if(m_usedTalentCount
> talentPointsForLevel
)
2241 if (GetSession()->GetSecurity() < SEC_ADMINISTRATOR
)
2244 SetFreeTalentPoints(0);
2246 // else update amount of free points
2248 SetFreeTalentPoints(talentPointsForLevel
-m_usedTalentCount
);
2252 void Player::InitStatsForLevel(bool reapplyMods
)
2254 if(reapplyMods
) //reapply stats values only on .reset stats (level) command
2255 _RemoveAllStatBonuses();
2257 PlayerClassLevelInfo classInfo
;
2258 objmgr
.GetPlayerClassLevelInfo(getClass(),getLevel(),&classInfo
);
2260 PlayerLevelInfo info
;
2261 objmgr
.GetPlayerLevelInfo(getRace(),getClass(),getLevel(),&info
);
2263 SetUInt32Value(PLAYER_FIELD_MAX_LEVEL
, sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) );
2264 SetUInt32Value(PLAYER_NEXT_LEVEL_XP
, objmgr
.GetXPForLevel(getLevel()));
2266 UpdateSkillsForLevel ();
2268 // set default cast time multiplier
2269 SetFloatValue(UNIT_MOD_CAST_SPEED
, 1.0f
);
2271 // reset size before reapply auras
2272 SetFloatValue(OBJECT_FIELD_SCALE_X
,1.0f
);
2274 // save base values (bonuses already included in stored stats
2275 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
)
2276 SetCreateStat(Stats(i
), info
.stats
[i
]);
2278 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
)
2279 SetStat(Stats(i
), info
.stats
[i
]);
2281 SetCreateHealth(classInfo
.basehealth
);
2284 SetCreateMana(classInfo
.basemana
);
2286 SetArmor(int32(m_createStats
[STAT_AGILITY
]*2));
2290 //reset rating fields values
2291 for(uint16 index
= PLAYER_FIELD_COMBAT_RATING_1
; index
< PLAYER_FIELD_COMBAT_RATING_1
+ MAX_COMBAT_RATING
; ++index
)
2292 SetUInt32Value(index
, 0);
2294 SetUInt32Value(PLAYER_FIELD_MOD_HEALING_DONE_POS
,0);
2295 for (int i
= 0; i
< 7; i
++)
2297 SetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG
+i
, 0);
2298 SetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS
+i
, 0);
2299 SetFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT
+i
, 1.00f
);
2302 //reset attack power, damage and attack speed fields
2303 SetFloatValue(UNIT_FIELD_BASEATTACKTIME
, 2000.0f
);
2304 SetFloatValue(UNIT_FIELD_BASEATTACKTIME
+ 1, 2000.0f
); // offhand attack time
2305 SetFloatValue(UNIT_FIELD_RANGEDATTACKTIME
, 2000.0f
);
2307 SetFloatValue(UNIT_FIELD_MINDAMAGE
, 0.0f
);
2308 SetFloatValue(UNIT_FIELD_MAXDAMAGE
, 0.0f
);
2309 SetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
, 0.0f
);
2310 SetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
, 0.0f
);
2311 SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
, 0.0f
);
2312 SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
, 0.0f
);
2314 SetUInt32Value(UNIT_FIELD_ATTACK_POWER
, 0 );
2315 SetUInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
, 0 );
2316 SetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
,0.0f
);
2317 SetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
, 0 );
2318 SetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
,0 );
2319 SetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
,0.0f
);
2321 // Base crit values (will be recalculated in UpdateAllStats() at loading and in _ApplyAllStatBonuses() at reset
2322 SetFloatValue(PLAYER_CRIT_PERCENTAGE
,0.0f
);
2323 SetFloatValue(PLAYER_OFFHAND_CRIT_PERCENTAGE
,0.0f
);
2324 SetFloatValue(PLAYER_RANGED_CRIT_PERCENTAGE
,0.0f
);
2326 // Init spell schools (will be recalculated in UpdateAllStats() at loading and in _ApplyAllStatBonuses() at reset
2327 for (uint8 i
= 0; i
< 7; ++i
)
2328 SetFloatValue(PLAYER_SPELL_CRIT_PERCENTAGE1
+i
, 0.0f
);
2330 SetFloatValue(PLAYER_PARRY_PERCENTAGE
, 0.0f
);
2331 SetFloatValue(PLAYER_BLOCK_PERCENTAGE
, 0.0f
);
2332 SetUInt32Value(PLAYER_SHIELD_BLOCK
, 0);
2335 SetFloatValue(PLAYER_DODGE_PERCENTAGE
, 0.0f
);
2337 // set armor (resistance 0) to original value (create_agility*2)
2338 SetArmor(int32(m_createStats
[STAT_AGILITY
]*2));
2339 SetResistanceBuffMods(SpellSchools(0), true, 0.0f
);
2340 SetResistanceBuffMods(SpellSchools(0), false, 0.0f
);
2341 // set other resistance to original value (0)
2342 for (int i
= 1; i
< MAX_SPELL_SCHOOL
; i
++)
2344 SetResistance(SpellSchools(i
), 0);
2345 SetResistanceBuffMods(SpellSchools(i
), true, 0.0f
);
2346 SetResistanceBuffMods(SpellSchools(i
), false, 0.0f
);
2349 SetUInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE
,0);
2350 SetUInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE
,0);
2351 for(int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
2353 SetFloatValue(UNIT_FIELD_POWER_COST_MODIFIER
+i
,0.0f
);
2354 SetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+i
,0.0f
);
2356 // Reset no reagent cost field
2357 for(int i
= 0; i
< 3; i
++)
2358 SetUInt32Value(PLAYER_NO_REAGENT_COST_1
+ i
, 0);
2359 // Init data for form but skip reapply item mods for form
2360 InitDataForForm(reapplyMods
);
2363 for (int i
= POWER_MANA
; i
< MAX_POWERS
; i
++)
2364 SetMaxPower(Powers(i
), uint32(GetCreatePowers(Powers(i
))));
2366 SetMaxHealth(classInfo
.basehealth
); // stamina bonus will applied later
2368 // cleanup mounted state (it will set correctly at aura loading if player saved at mount.
2369 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
2371 // cleanup unit flags (will be re-applied if need at aura load).
2372 RemoveFlag( UNIT_FIELD_FLAGS
,
2373 UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_DISABLE_MOVE
| UNIT_FLAG_NOT_ATTACKABLE_1
|
2374 UNIT_FLAG_PET_IN_COMBAT
| UNIT_FLAG_SILENCED
| UNIT_FLAG_PACIFIED
|
2375 UNIT_FLAG_STUNNED
| UNIT_FLAG_IN_COMBAT
| UNIT_FLAG_DISARMED
|
2376 UNIT_FLAG_CONFUSED
| UNIT_FLAG_FLEEING
| UNIT_FLAG_NOT_SELECTABLE
|
2377 UNIT_FLAG_SKINNABLE
| UNIT_FLAG_MOUNT
| UNIT_FLAG_TAXI_FLIGHT
);
2378 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
); // must be set
2380 // cleanup player flags (will be re-applied if need at aura load), to avoid have ghost flag without ghost aura, for example.
2381 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_AFK
| PLAYER_FLAGS_DND
| PLAYER_FLAGS_GM
| PLAYER_FLAGS_GHOST
);
2383 SetByteValue(UNIT_FIELD_BYTES_1
, 2, 0x00); // one form stealth modified bytes
2384 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
| UNIT_BYTE2_FLAG_SANCTUARY
);
2386 // restore if need some important flags
2387 SetUInt32Value(PLAYER_FIELD_BYTES2
, 0 ); // flags empty by default
2389 if(reapplyMods
) //reapply stats values only on .reset stats (level) command
2390 _ApplyAllStatBonuses();
2392 // set current level health and mana/energy to maximum after applying all mods.
2393 SetHealth(GetMaxHealth());
2394 SetPower(POWER_MANA
, GetMaxPower(POWER_MANA
));
2395 SetPower(POWER_ENERGY
, GetMaxPower(POWER_ENERGY
));
2396 if(GetPower(POWER_RAGE
) > GetMaxPower(POWER_RAGE
))
2397 SetPower(POWER_RAGE
, GetMaxPower(POWER_RAGE
));
2398 SetPower(POWER_FOCUS
, 0);
2399 SetPower(POWER_HAPPINESS
, 0);
2400 SetPower(POWER_RUNIC_POWER
, 0);
2403 void Player::SendInitialSpells()
2405 uint16 spellCount
= 0;
2407 WorldPacket
data(SMSG_INITIAL_SPELLS
, (1+2+4*m_spells
.size()+2+m_spellCooldowns
.size()*(2+2+2+4+4)));
2410 size_t countPos
= data
.wpos();
2411 data
<< uint16(spellCount
); // spell count placeholder
2413 for (PlayerSpellMap::const_iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
2415 if(itr
->second
->state
== PLAYERSPELL_REMOVED
)
2418 if(!itr
->second
->active
|| itr
->second
->disabled
)
2421 data
<< uint16(itr
->first
);
2422 data
<< uint16(0); // it's not slot id
2427 data
.put
<uint16
>(countPos
,spellCount
); // write real count value
2429 uint16 spellCooldowns
= m_spellCooldowns
.size();
2430 data
<< uint16(spellCooldowns
);
2431 for(SpellCooldowns::const_iterator itr
=m_spellCooldowns
.begin(); itr
!=m_spellCooldowns
.end(); ++itr
)
2433 SpellEntry
const *sEntry
= sSpellStore
.LookupEntry(itr
->first
);
2437 data
<< uint16(itr
->first
);
2439 time_t cooldown
= 0;
2440 time_t curTime
= time(NULL
);
2441 if(itr
->second
.end
> curTime
)
2442 cooldown
= (itr
->second
.end
-curTime
)*1000;
2444 data
<< uint16(itr
->second
.itemid
); // cast item id
2445 data
<< uint16(sEntry
->Category
); // spell category
2446 if(sEntry
->Category
) // may be wrong, but anyway better than nothing...
2448 data
<< uint32(0); // cooldown
2449 data
<< uint32(cooldown
); // category cooldown
2453 data
<< uint32(cooldown
); // cooldown
2454 data
<< uint32(0); // category cooldown
2458 GetSession()->SendPacket(&data
);
2460 sLog
.outDetail( "CHARACTER: Sent Initial Spells" );
2463 void Player::RemoveMail(uint32 id
)
2465 for(PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end();++itr
)
2467 if ((*itr
)->messageID
== id
)
2469 //do not delete item, because Player::removeMail() is called when returning mail to sender.
2476 void Player::SendMailResult(uint32 mailId
, uint32 mailAction
, uint32 mailError
, uint32 equipError
, uint32 item_guid
, uint32 item_count
)
2478 WorldPacket
data(SMSG_SEND_MAIL_RESULT
, (4+4+4+(mailError
== MAIL_ERR_BAG_FULL
?4:(mailAction
== MAIL_ITEM_TAKEN
?4+4:0))));
2479 data
<< (uint32
) mailId
;
2480 data
<< (uint32
) mailAction
;
2481 data
<< (uint32
) mailError
;
2482 if ( mailError
== MAIL_ERR_BAG_FULL
)
2483 data
<< (uint32
) equipError
;
2484 else if( mailAction
== MAIL_ITEM_TAKEN
)
2486 data
<< (uint32
) item_guid
; // item guid low?
2487 data
<< (uint32
) item_count
; // item count?
2489 GetSession()->SendPacket(&data
);
2492 void Player::SendNewMail()
2494 // deliver undelivered mail
2495 WorldPacket
data(SMSG_RECEIVED_MAIL
, 4);
2497 GetSession()->SendPacket(&data
);
2500 void Player::UpdateNextMailTimeAndUnreads()
2502 // calculate next delivery time (min. from non-delivered mails
2503 // and recalculate unReadMail
2504 time_t cTime
= time(NULL
);
2505 m_nextMailDelivereTime
= 0;
2507 for(PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end(); ++itr
)
2509 if((*itr
)->deliver_time
> cTime
)
2511 if(!m_nextMailDelivereTime
|| m_nextMailDelivereTime
> (*itr
)->deliver_time
)
2512 m_nextMailDelivereTime
= (*itr
)->deliver_time
;
2514 else if(((*itr
)->checked
& MAIL_CHECK_MASK_READ
) == 0)
2519 void Player::AddNewMailDeliverTime(time_t deliver_time
)
2521 if(deliver_time
<= time(NULL
)) // ready now
2526 else // not ready and no have ready mails
2528 if(!m_nextMailDelivereTime
|| m_nextMailDelivereTime
> deliver_time
)
2529 m_nextMailDelivereTime
= deliver_time
;
2533 bool Player::addSpell(uint32 spell_id
, bool active
, bool learning
, bool disabled
)
2535 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spell_id
);
2538 // do character spell book cleanup (all characters)
2539 if(!IsInWorld() && !learning
) // spell load case
2541 sLog
.outError("Player::addSpell: Non-existed in SpellStore spell #%u request, deleting for all characters in `character_spell`.",spell_id
);
2542 CharacterDatabase
.PExecute("DELETE FROM character_spell WHERE spell = '%u'",spell_id
);
2545 sLog
.outError("Player::addSpell: Non-existed in SpellStore spell #%u request.",spell_id
);
2550 if(!SpellMgr::IsSpellValid(spellInfo
,this,false))
2552 // do character spell book cleanup (all characters)
2553 if(!IsInWorld() && !learning
) // spell load case
2555 sLog
.outError("Player::addSpell: Broken spell #%u learning not allowed, deleting for all characters in `character_spell`.",spell_id
);
2556 CharacterDatabase
.PExecute("DELETE FROM character_spell WHERE spell = '%u'",spell_id
);
2559 sLog
.outError("Player::addSpell: Broken spell #%u learning not allowed.",spell_id
);
2564 PlayerSpellState state
= learning
? PLAYERSPELL_NEW
: PLAYERSPELL_UNCHANGED
;
2566 bool disabled_case
= false;
2567 bool superceded_old
= false;
2569 PlayerSpellMap::iterator itr
= m_spells
.find(spell_id
);
2570 if (itr
!= m_spells
.end())
2572 // update active state for known spell
2573 if(itr
->second
->active
!= active
&& itr
->second
->state
!= PLAYERSPELL_REMOVED
&& !itr
->second
->disabled
)
2575 itr
->second
->active
= active
;
2577 // !IsInWorld() && !learning == explicitly load from DB and then exist in it already and set correctly
2578 if(!IsInWorld() && !learning
)
2579 itr
->second
->state
= PLAYERSPELL_UNCHANGED
;
2580 else if(itr
->second
->state
!= PLAYERSPELL_NEW
)
2581 itr
->second
->state
= PLAYERSPELL_CHANGED
;
2585 WorldPacket
data(SMSG_REMOVED_SPELL
, 4);
2586 data
<< uint16(spell_id
);
2587 GetSession()->SendPacket(&data
);
2589 return active
; // learn (show in spell book if active now)
2592 if(itr
->second
->disabled
!= disabled
&& itr
->second
->state
!= PLAYERSPELL_REMOVED
)
2594 if(itr
->second
->state
!= PLAYERSPELL_NEW
)
2595 itr
->second
->state
= PLAYERSPELL_CHANGED
;
2596 itr
->second
->disabled
= disabled
;
2601 disabled_case
= true;
2603 else switch(itr
->second
->state
)
2605 case PLAYERSPELL_UNCHANGED
: // known saved spell
2607 case PLAYERSPELL_REMOVED
: // re-learning removed not saved spell
2610 m_spells
.erase(itr
);
2611 state
= PLAYERSPELL_CHANGED
;
2612 break; // need re-add
2614 default: // known not saved yet spell (new or modified)
2616 // can be in case spell loading but learned at some previous spell loading
2617 if(!IsInWorld() && !learning
)
2618 itr
->second
->state
= PLAYERSPELL_UNCHANGED
;
2625 if(!disabled_case
) // skip new spell adding if spell already known (disabled spells case)
2627 // talent: unlearn all other talent ranks (high and low)
2628 if(TalentSpellPos
const* talentPos
= GetTalentSpellPos(spell_id
))
2630 if(TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry( talentPos
->talent_id
))
2632 for(int i
=0; i
<5; ++i
)
2634 // skip learning spell and no rank spell case
2635 uint32 rankSpellId
= talentInfo
->RankID
[i
];
2636 if(!rankSpellId
|| rankSpellId
==spell_id
)
2639 // skip unknown ranks
2640 if(!HasSpell(rankSpellId
))
2643 removeSpell(rankSpellId
);
2647 // non talent spell: learn low ranks (recursive call)
2648 else if(uint32 prev_spell
= spellmgr
.GetPrevSpellInChain(spell_id
))
2650 if(!IsInWorld()) // at spells loading, no output, but allow save
2651 addSpell(prev_spell
,active
,true,disabled
);
2652 else // at normal learning
2653 learnSpell(prev_spell
);
2656 PlayerSpell
*newspell
= new PlayerSpell
;
2657 newspell
->active
= active
;
2658 newspell
->state
= state
;
2659 newspell
->disabled
= disabled
;
2661 // replace spells in action bars and spellbook to bigger rank if only one spell rank must be accessible
2662 if(newspell
->active
&& !newspell
->disabled
&& !SpellMgr::canStackSpellRanks(spellInfo
) && spellmgr
.GetSpellRank(spellInfo
->Id
) != 0)
2664 for( PlayerSpellMap::iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
2666 if(itr
->second
->state
== PLAYERSPELL_REMOVED
) continue;
2667 SpellEntry
const *i_spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
2668 if(!i_spellInfo
) continue;
2670 if( spellmgr
.IsRankSpellDueToSpell(spellInfo
,itr
->first
) )
2672 if(itr
->second
->active
)
2674 if(spellmgr
.IsHighRankOfSpell(spell_id
,itr
->first
))
2676 if(IsInWorld()) // not send spell (re-/over-)learn packets at loading
2678 WorldPacket
data(SMSG_SUPERCEDED_SPELL
, (4));
2679 data
<< uint16(itr
->first
);
2680 data
<< uint16(spell_id
);
2681 GetSession()->SendPacket( &data
);
2684 // mark old spell as disable (SMSG_SUPERCEDED_SPELL replace it in client by new)
2685 itr
->second
->active
= false;
2686 itr
->second
->state
= PLAYERSPELL_CHANGED
;
2687 superceded_old
= true; // new spell replace old in action bars and spell book.
2689 else if(spellmgr
.IsHighRankOfSpell(itr
->first
,spell_id
))
2691 if(IsInWorld()) // not send spell (re-/over-)learn packets at loading
2693 WorldPacket
data(SMSG_SUPERCEDED_SPELL
, (4));
2694 data
<< uint16(spell_id
);
2695 data
<< uint16(itr
->first
);
2696 GetSession()->SendPacket( &data
);
2699 // mark new spell as disable (not learned yet for client and will not learned)
2700 newspell
->active
= false;
2701 if(newspell
->state
!= PLAYERSPELL_NEW
)
2702 newspell
->state
= PLAYERSPELL_CHANGED
;
2709 m_spells
[spell_id
] = newspell
;
2711 // return false if spell disabled
2712 if (newspell
->disabled
)
2716 uint32 talentCost
= GetTalentSpellCost(spell_id
);
2718 // cast talents with SPELL_EFFECT_LEARN_SPELL (other dependent spells will learned later as not auto-learned)
2719 // note: all spells with SPELL_EFFECT_LEARN_SPELL isn't passive
2720 if( talentCost
> 0 && IsSpellHaveEffect(spellInfo
,SPELL_EFFECT_LEARN_SPELL
) )
2722 // ignore stance requirement for talent learn spell (stance set for spell only for client spell description show)
2723 CastSpell(this, spell_id
, true);
2725 // also cast passive spells (including all talents without SPELL_EFFECT_LEARN_SPELL) with additional checks
2726 else if (IsPassiveSpell(spell_id
))
2728 bool need_cast
= false;
2732 // some spells not have stance data expacted cast at form change or present
2733 case 5420: need_cast
= (m_form
== FORM_TREE
); break;
2734 case 5419: need_cast
= (m_form
== FORM_TRAVEL
); break;
2735 case 7376: need_cast
= (m_form
== FORM_DEFENSIVESTANCE
); break;
2736 case 7381: need_cast
= (m_form
== FORM_BERSERKERSTANCE
); break;
2737 case 21156: need_cast
= (m_form
== FORM_BATTLESTANCE
); break;
2738 case 21178: need_cast
= (m_form
== FORM_BEAR
|| m_form
== FORM_DIREBEAR
); break;
2739 case 33948: need_cast
= (m_form
== FORM_FLIGHT
); break;
2740 case 34764: need_cast
= (m_form
== FORM_FLIGHT
); break;
2741 case 40121: need_cast
= (m_form
== FORM_FLIGHT_EPIC
); break;
2742 case 40122: need_cast
= (m_form
== FORM_FLIGHT_EPIC
); break;
2743 // another spells have proper stance data
2744 default: need_cast
= !spellInfo
->Stances
|| m_form
!= 0 && (spellInfo
->Stances
& (1<<(m_form
-1))); break;
2746 //Check CasterAuraStates
2747 if (need_cast
&& (!spellInfo
->CasterAuraState
|| HasAuraState(AuraState(spellInfo
->CasterAuraState
))))
2748 CastSpell(this, spell_id
, true);
2750 else if( IsSpellHaveEffect(spellInfo
,SPELL_EFFECT_SKILL_STEP
) )
2752 CastSpell(this, spell_id
, true);
2756 // update used talent points count
2757 m_usedTalentCount
+= talentCost
;
2759 // update free primary prof.points (if any, can be none in case GM .learn prof. learning)
2760 if(uint32 freeProfs
= GetFreePrimaryProffesionPoints())
2762 if(spellmgr
.IsPrimaryProfessionFirstRankSpell(spell_id
))
2763 SetFreePrimaryProffesions(freeProfs
-1);
2766 // add dependent skills
2767 uint16 maxskill
= GetMaxSkillValueForLevel();
2769 SpellLearnSkillNode
const* spellLearnSkill
= spellmgr
.GetSpellLearnSkill(spell_id
);
2773 uint32 skill_value
= GetPureSkillValue(spellLearnSkill
->skill
);
2774 uint32 skill_max_value
= GetPureMaxSkillValue(spellLearnSkill
->skill
);
2776 if(skill_value
< spellLearnSkill
->value
)
2777 skill_value
= spellLearnSkill
->value
;
2779 uint32 new_skill_max_value
= spellLearnSkill
->maxvalue
== 0 ? maxskill
: spellLearnSkill
->maxvalue
;
2781 if(skill_max_value
< new_skill_max_value
)
2782 skill_max_value
= new_skill_max_value
;
2784 SetSkill(spellLearnSkill
->skill
,skill_value
,skill_max_value
);
2788 // not ranked skills
2789 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(spell_id
);
2790 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(spell_id
);
2792 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
2794 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(_spell_idx
->second
->skillId
);
2798 if(HasSkill(pSkill
->id
))
2801 if(_spell_idx
->second
->learnOnGetSkill
== ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
||
2802 // lockpicking special case, not have ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
2803 pSkill
->id
==SKILL_LOCKPICKING
&& _spell_idx
->second
->max_value
==0 )
2805 switch(GetSkillRangeType(pSkill
,_spell_idx
->second
->racemask
!=0))
2807 case SKILL_RANGE_LANGUAGE
:
2808 SetSkill(pSkill
->id
, 300, 300 );
2810 case SKILL_RANGE_LEVEL
:
2811 SetSkill(pSkill
->id
, 1, GetMaxSkillValueForLevel() );
2813 case SKILL_RANGE_MONO
:
2814 SetSkill(pSkill
->id
, 1, 1 );
2823 // learn dependent spells
2824 SpellLearnSpellMap::const_iterator spell_begin
= spellmgr
.GetBeginSpellLearnSpell(spell_id
);
2825 SpellLearnSpellMap::const_iterator spell_end
= spellmgr
.GetEndSpellLearnSpell(spell_id
);
2827 for(SpellLearnSpellMap::const_iterator itr
= spell_begin
; itr
!= spell_end
; ++itr
)
2829 if(!itr
->second
.autoLearned
)
2831 if(!IsInWorld() || !itr
->second
.active
) // at spells loading, no output, but allow save
2832 addSpell(itr
->second
.spell
,itr
->second
.active
,true,false);
2833 else // at normal learning
2834 learnSpell(itr
->second
.spell
);
2840 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL
);
2841 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS
);
2844 // return true (for send learn packet) only if spell active (in case ranked spells) and not replace old spell
2845 return active
&& !disabled
&& !superceded_old
;
2848 void Player::learnSpell(uint32 spell_id
)
2850 PlayerSpellMap::iterator itr
= m_spells
.find(spell_id
);
2852 bool disabled
= (itr
!= m_spells
.end()) ? itr
->second
->disabled
: false;
2853 bool active
= disabled
? itr
->second
->active
: true;
2855 bool learning
= addSpell(spell_id
,active
,true,false);
2857 // learn all disabled higher ranks (recursive)
2858 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
2859 for(SpellChainMapNext::const_iterator i
= nextMap
.lower_bound(spell_id
); i
!= nextMap
.upper_bound(spell_id
); ++i
)
2861 PlayerSpellMap::iterator iter
= m_spells
.find(i
->second
);
2862 if (disabled
&& iter
!= m_spells
.end() && iter
->second
->disabled
)
2863 learnSpell(i
->second
);
2866 // prevent duplicated entires in spell book, also not send if not in world (loading)
2867 if(!learning
|| !IsInWorld ())
2870 WorldPacket
data(SMSG_LEARNED_SPELL
, 4);
2871 data
<< uint32(spell_id
);
2872 GetSession()->SendPacket(&data
);
2875 void Player::removeSpell(uint32 spell_id
, bool disabled
)
2877 PlayerSpellMap::iterator itr
= m_spells
.find(spell_id
);
2878 if (itr
== m_spells
.end())
2881 if(itr
->second
->state
== PLAYERSPELL_REMOVED
|| disabled
&& itr
->second
->disabled
)
2884 // unlearn non talent higher ranks (recursive)
2885 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
2886 for(SpellChainMapNext::const_iterator itr2
= nextMap
.lower_bound(spell_id
); itr2
!= nextMap
.upper_bound(spell_id
); ++itr2
)
2887 if(HasSpell(itr2
->second
) && !GetTalentSpellPos(itr2
->second
))
2888 removeSpell(itr2
->second
,disabled
);
2891 WorldPacket
data(SMSG_REMOVED_SPELL
, 4);
2892 data
<< uint16(spell_id
);
2893 GetSession()->SendPacket(&data
);
2897 itr
->second
->disabled
= disabled
;
2898 if(itr
->second
->state
!= PLAYERSPELL_NEW
)
2899 itr
->second
->state
= PLAYERSPELL_CHANGED
;
2903 if(itr
->second
->state
== PLAYERSPELL_NEW
)
2906 m_spells
.erase(itr
);
2909 itr
->second
->state
= PLAYERSPELL_REMOVED
;
2912 RemoveAurasDueToSpell(spell_id
);
2915 if(PetAura
const* petSpell
= spellmgr
.GetPetAura(spell_id
))
2916 RemovePetAura(petSpell
);
2918 // free talent points
2919 uint32 talentCosts
= GetTalentSpellCost(spell_id
);
2922 if(talentCosts
< m_usedTalentCount
)
2923 m_usedTalentCount
-= talentCosts
;
2925 m_usedTalentCount
= 0;
2928 // update free primary prof.points (if not overflow setting, can be in case GM use before .learn prof. learning)
2929 if(spellmgr
.IsPrimaryProfessionFirstRankSpell(spell_id
))
2931 uint32 freeProfs
= GetFreePrimaryProffesionPoints()+1;
2932 if(freeProfs
<= sWorld
.getConfig(CONFIG_MAX_PRIMARY_TRADE_SKILL
))
2933 SetFreePrimaryProffesions(freeProfs
);
2936 // remove dependent skill
2937 SpellLearnSkillNode
const* spellLearnSkill
= spellmgr
.GetSpellLearnSkill(spell_id
);
2940 uint32 prev_spell
= spellmgr
.GetPrevSpellInChain(spell_id
);
2941 if(!prev_spell
) // first rank, remove skill
2942 SetSkill(spellLearnSkill
->skill
,0,0);
2945 // search prev. skill setting by spell ranks chain
2946 SpellLearnSkillNode
const* prevSkill
= spellmgr
.GetSpellLearnSkill(prev_spell
);
2947 while(!prevSkill
&& prev_spell
)
2949 prev_spell
= spellmgr
.GetPrevSpellInChain(prev_spell
);
2950 prevSkill
= spellmgr
.GetSpellLearnSkill(spellmgr
.GetFirstSpellInChain(prev_spell
));
2953 if(!prevSkill
) // not found prev skill setting, remove skill
2954 SetSkill(spellLearnSkill
->skill
,0,0);
2955 else // set to prev. skill setting values
2957 uint32 skill_value
= GetPureSkillValue(prevSkill
->skill
);
2958 uint32 skill_max_value
= GetPureMaxSkillValue(prevSkill
->skill
);
2960 if(skill_value
> prevSkill
->value
)
2961 skill_value
= prevSkill
->value
;
2963 uint32 new_skill_max_value
= prevSkill
->maxvalue
== 0 ? GetMaxSkillValueForLevel() : prevSkill
->maxvalue
;
2965 if(skill_max_value
> new_skill_max_value
)
2966 skill_max_value
= new_skill_max_value
;
2968 SetSkill(prevSkill
->skill
,skill_value
,skill_max_value
);
2975 // not ranked skills
2976 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(spell_id
);
2977 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(spell_id
);
2979 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
2981 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(_spell_idx
->second
->skillId
);
2985 if(_spell_idx
->second
->learnOnGetSkill
== ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
||
2986 // lockpicking special case, not have ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
2987 pSkill
->id
==SKILL_LOCKPICKING
&& _spell_idx
->second
->max_value
==0 )
2989 // not reset skills for professions and racial abilities
2990 if( (pSkill
->categoryId
==SKILL_CATEGORY_SECONDARY
|| pSkill
->categoryId
==SKILL_CATEGORY_PROFESSION
) &&
2991 (IsProfessionSkill(pSkill
->id
) || _spell_idx
->second
->racemask
!=0) )
2994 SetSkill(pSkill
->id
, 0, 0 );
2999 // remove dependent spells
3000 SpellLearnSpellMap::const_iterator spell_begin
= spellmgr
.GetBeginSpellLearnSpell(spell_id
);
3001 SpellLearnSpellMap::const_iterator spell_end
= spellmgr
.GetEndSpellLearnSpell(spell_id
);
3003 for(SpellLearnSpellMap::const_iterator itr2
= spell_begin
; itr2
!= spell_end
; ++itr2
)
3004 removeSpell(itr2
->second
.spell
, disabled
);
3006 // TODO: recast if need lesser ranks spell for passive with IsPassiveSpellStackableWithRanks
3009 void Player::RemoveArenaSpellCooldowns()
3011 // remove cooldowns on spells that has < 15 min CD
3012 SpellCooldowns::iterator itr
, next
;
3013 // iterate spell cooldowns
3014 for(itr
= m_spellCooldowns
.begin();itr
!= m_spellCooldowns
.end(); itr
= next
)
3018 SpellEntry
const * entry
= sSpellStore
.LookupEntry(itr
->first
);
3019 // check if spellentry is present and if the cooldown is less than 15 mins
3021 entry
->RecoveryTime
<= 15 * MINUTE
* 1000 &&
3022 entry
->CategoryRecoveryTime
<= 15 * MINUTE
* 1000 )
3025 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
3026 data
<< uint32(itr
->first
);
3028 GetSession()->SendPacket(&data
);
3030 m_spellCooldowns
.erase(itr
);
3035 void Player::RemoveAllSpellCooldown()
3037 if(!m_spellCooldowns
.empty())
3039 for(SpellCooldowns::const_iterator itr
= m_spellCooldowns
.begin();itr
!= m_spellCooldowns
.end(); ++itr
)
3041 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
3042 data
<< uint32(itr
->first
);
3043 data
<< uint64(GetGUID());
3044 GetSession()->SendPacket(&data
);
3046 m_spellCooldowns
.clear();
3050 void Player::_LoadSpellCooldowns(QueryResult
*result
)
3052 m_spellCooldowns
.clear();
3054 //QueryResult *result = CharacterDatabase.PQuery("SELECT spell,item,time FROM character_spell_cooldown WHERE guid = '%u'",GetGUIDLow());
3058 time_t curTime
= time(NULL
);
3062 Field
*fields
= result
->Fetch();
3064 uint32 spell_id
= fields
[0].GetUInt32();
3065 uint32 item_id
= fields
[1].GetUInt32();
3066 time_t db_time
= (time_t)fields
[2].GetUInt64();
3068 if(!sSpellStore
.LookupEntry(spell_id
))
3070 sLog
.outError("Player %u have unknown spell %u in `character_spell_cooldown`, skipping.",GetGUIDLow(),spell_id
);
3074 // skip outdated cooldown
3075 if(db_time
<= curTime
)
3078 AddSpellCooldown(spell_id
, item_id
, db_time
);
3080 sLog
.outDebug("Player (GUID: %u) spell %u, item %u cooldown loaded (%u secs).", GetGUIDLow(), spell_id
, item_id
, uint32(db_time
-curTime
));
3082 while( result
->NextRow() );
3088 void Player::_SaveSpellCooldowns()
3090 CharacterDatabase
.PExecute("DELETE FROM character_spell_cooldown WHERE guid = '%u'", GetGUIDLow());
3092 time_t curTime
= time(NULL
);
3094 // remove outdated and save active
3095 for(SpellCooldowns::iterator itr
= m_spellCooldowns
.begin();itr
!= m_spellCooldowns
.end();)
3097 if(itr
->second
.end
<= curTime
)
3098 m_spellCooldowns
.erase(itr
++);
3101 CharacterDatabase
.PExecute("INSERT INTO character_spell_cooldown (guid,spell,item,time) VALUES ('%u', '%u', '%u', '" I64FMTD
"')", GetGUIDLow(), itr
->first
, itr
->second
.itemid
, uint64(itr
->second
.end
));
3107 uint32
Player::resetTalentsCost() const
3109 // The first time reset costs 1 gold
3110 if(m_resetTalentsCost
< 1*GOLD
)
3113 else if(m_resetTalentsCost
< 5*GOLD
)
3115 // After that it increases in increments of 5 gold
3116 else if(m_resetTalentsCost
< 10*GOLD
)
3120 uint32 months
= (sWorld
.GetGameTime() - m_resetTalentsTime
)/MONTH
;
3123 // This cost will be reduced by a rate of 5 gold per month
3124 int32 new_cost
= int32(m_resetTalentsCost
) - 5*GOLD
*months
;
3125 // to a minimum of 10 gold.
3126 return (new_cost
< 10*GOLD
? 10*GOLD
: new_cost
);
3130 // After that it increases in increments of 5 gold
3131 int32 new_cost
= m_resetTalentsCost
+ 5*GOLD
;
3132 // until it hits a cap of 50 gold.
3133 if(new_cost
> 50*GOLD
)
3140 bool Player::resetTalents(bool no_cost
)
3142 // not need after this call
3143 if(HasAtLoginFlag(AT_LOGIN_RESET_TALENTS
))
3145 m_atLoginFlags
= m_atLoginFlags
& ~AT_LOGIN_RESET_TALENTS
;
3146 CharacterDatabase
.PExecute("UPDATE characters set at_login = at_login & ~ %u WHERE guid ='%u'", uint32(AT_LOGIN_RESET_TALENTS
), GetGUIDLow());
3149 uint32 level
= getLevel();
3150 uint32 talentPointsForLevel
= level
< 10 ? 0 : uint32((level
-9)*sWorld
.getRate(RATE_TALENT
));
3152 if (m_usedTalentCount
== 0)
3154 SetFreeTalentPoints(talentPointsForLevel
);
3162 cost
= resetTalentsCost();
3164 if (GetMoney() < cost
)
3166 SendBuyError( BUY_ERR_NOT_ENOUGHT_MONEY
, 0, 0, 0);
3171 for (unsigned int i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
3173 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
3175 if (!talentInfo
) continue;
3177 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
3182 // unlearn only talents for character class
3183 // some spell learned by one class as normal spells or know at creation but another class learn it as talent,
3184 // to prevent unexpected lost normal learned spell skip another class talents
3185 if( (getClassMask() & talentTabInfo
->ClassMask
) == 0 )
3188 for (int j
= 0; j
< 5; j
++)
3190 for(PlayerSpellMap::iterator itr
= GetSpellMap().begin(); itr
!= GetSpellMap().end();)
3192 if(itr
->second
->state
== PLAYERSPELL_REMOVED
|| itr
->second
->disabled
)
3198 // remove learned spells (all ranks)
3199 uint32 itrFirstId
= spellmgr
.GetFirstSpellInChain(itr
->first
);
3201 // unlearn if first rank is talent or learned by talent
3202 if (itrFirstId
== talentInfo
->RankID
[j
] || spellmgr
.IsSpellLearnToSpell(talentInfo
->RankID
[j
],itrFirstId
))
3204 removeSpell(itr
->first
,!IsPassiveSpell(itr
->first
));
3205 itr
= GetSpellMap().begin();
3214 SetFreeTalentPoints(talentPointsForLevel
);
3218 ModifyMoney(-(int32
)cost
);
3220 m_resetTalentsCost
= cost
;
3221 m_resetTalentsTime
= time(NULL
);
3224 //FIXME: remove pet before or after unlearn spells? for now after unlearn to allow removing of talent related, pet affecting auras
3225 RemovePet(NULL
,PET_SAVE_NOT_IN_SLOT
, true);
3230 bool Player::_removeSpell(uint16 spell_id
)
3232 PlayerSpellMap::iterator itr
= m_spells
.find(spell_id
);
3233 if (itr
!= m_spells
.end())
3236 m_spells
.erase(itr
);
3242 Mail
* Player::GetMail(uint32 id
)
3244 for(PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end(); ++itr
)
3246 if ((*itr
)->messageID
== id
)
3254 void Player::_SetCreateBits(UpdateMask
*updateMask
, Player
*target
) const
3258 Object::_SetCreateBits(updateMask
, target
);
3262 for(uint16 index
= 0; index
< m_valuesCount
; index
++)
3264 if(GetUInt32Value(index
) != 0 && updateVisualBits
.GetBit(index
))
3265 updateMask
->SetBit(index
);
3270 void Player::_SetUpdateBits(UpdateMask
*updateMask
, Player
*target
) const
3274 Object::_SetUpdateBits(updateMask
, target
);
3278 Object::_SetUpdateBits(updateMask
, target
);
3279 *updateMask
&= updateVisualBits
;
3283 void Player::InitVisibleBits()
3285 updateVisualBits
.SetCount(PLAYER_END
);
3287 updateVisualBits
.SetBit(OBJECT_FIELD_GUID
);
3288 updateVisualBits
.SetBit(OBJECT_FIELD_TYPE
);
3289 updateVisualBits
.SetBit(OBJECT_FIELD_ENTRY
);
3290 updateVisualBits
.SetBit(OBJECT_FIELD_SCALE_X
);
3291 updateVisualBits
.SetBit(UNIT_FIELD_CHARM
+ 0);
3292 updateVisualBits
.SetBit(UNIT_FIELD_CHARM
+ 1);
3293 updateVisualBits
.SetBit(UNIT_FIELD_SUMMON
+ 0);
3294 updateVisualBits
.SetBit(UNIT_FIELD_SUMMON
+ 1);
3295 updateVisualBits
.SetBit(UNIT_FIELD_CHARMEDBY
+ 0);
3296 updateVisualBits
.SetBit(UNIT_FIELD_CHARMEDBY
+ 1);
3297 updateVisualBits
.SetBit(UNIT_FIELD_TARGET
+ 0);
3298 updateVisualBits
.SetBit(UNIT_FIELD_TARGET
+ 1);
3299 updateVisualBits
.SetBit(UNIT_FIELD_CHANNEL_OBJECT
+ 0);
3300 updateVisualBits
.SetBit(UNIT_FIELD_CHANNEL_OBJECT
+ 1);
3301 updateVisualBits
.SetBit(UNIT_FIELD_BYTES_0
);
3302 updateVisualBits
.SetBit(UNIT_FIELD_HEALTH
);
3303 updateVisualBits
.SetBit(UNIT_FIELD_POWER1
);
3304 updateVisualBits
.SetBit(UNIT_FIELD_POWER2
);
3305 updateVisualBits
.SetBit(UNIT_FIELD_POWER3
);
3306 updateVisualBits
.SetBit(UNIT_FIELD_POWER4
);
3307 updateVisualBits
.SetBit(UNIT_FIELD_POWER5
);
3308 updateVisualBits
.SetBit(UNIT_FIELD_POWER6
);
3309 updateVisualBits
.SetBit(UNIT_FIELD_POWER7
);
3310 updateVisualBits
.SetBit(UNIT_FIELD_MAXHEALTH
);
3311 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER1
);
3312 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER2
);
3313 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER3
);
3314 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER4
);
3315 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER5
);
3316 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER6
);
3317 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER7
);
3318 updateVisualBits
.SetBit(UNIT_FIELD_LEVEL
);
3319 updateVisualBits
.SetBit(UNIT_FIELD_FACTIONTEMPLATE
);
3320 updateVisualBits
.SetBit(UNIT_VIRTUAL_ITEM_SLOT_ID
+ 0);
3321 updateVisualBits
.SetBit(UNIT_VIRTUAL_ITEM_SLOT_ID
+ 1);
3322 updateVisualBits
.SetBit(UNIT_VIRTUAL_ITEM_SLOT_ID
+ 2);
3323 updateVisualBits
.SetBit(UNIT_FIELD_FLAGS
);
3324 updateVisualBits
.SetBit(UNIT_FIELD_FLAGS_2
);
3325 updateVisualBits
.SetBit(UNIT_FIELD_AURASTATE
);
3326 updateVisualBits
.SetBit(UNIT_FIELD_BASEATTACKTIME
+ 0);
3327 updateVisualBits
.SetBit(UNIT_FIELD_BASEATTACKTIME
+ 1);
3328 updateVisualBits
.SetBit(UNIT_FIELD_BOUNDINGRADIUS
);
3329 updateVisualBits
.SetBit(UNIT_FIELD_COMBATREACH
);
3330 updateVisualBits
.SetBit(UNIT_FIELD_DISPLAYID
);
3331 updateVisualBits
.SetBit(UNIT_FIELD_NATIVEDISPLAYID
);
3332 updateVisualBits
.SetBit(UNIT_FIELD_MOUNTDISPLAYID
);
3333 updateVisualBits
.SetBit(UNIT_FIELD_BYTES_1
);
3334 updateVisualBits
.SetBit(UNIT_FIELD_PETNUMBER
);
3335 updateVisualBits
.SetBit(UNIT_FIELD_PET_NAME_TIMESTAMP
);
3336 updateVisualBits
.SetBit(UNIT_DYNAMIC_FLAGS
);
3337 updateVisualBits
.SetBit(UNIT_CHANNEL_SPELL
);
3338 updateVisualBits
.SetBit(UNIT_MOD_CAST_SPEED
);
3339 updateVisualBits
.SetBit(UNIT_FIELD_BASE_MANA
);
3340 updateVisualBits
.SetBit(UNIT_FIELD_BYTES_2
);
3341 updateVisualBits
.SetBit(UNIT_FIELD_HOVERHEIGHT
);
3343 updateVisualBits
.SetBit(PLAYER_DUEL_ARBITER
+ 0);
3344 updateVisualBits
.SetBit(PLAYER_DUEL_ARBITER
+ 1);
3345 updateVisualBits
.SetBit(PLAYER_FLAGS
);
3346 updateVisualBits
.SetBit(PLAYER_GUILDID
);
3347 updateVisualBits
.SetBit(PLAYER_GUILDRANK
);
3348 updateVisualBits
.SetBit(PLAYER_BYTES
);
3349 updateVisualBits
.SetBit(PLAYER_BYTES_2
);
3350 updateVisualBits
.SetBit(PLAYER_BYTES_3
);
3351 updateVisualBits
.SetBit(PLAYER_DUEL_TEAM
);
3352 updateVisualBits
.SetBit(PLAYER_GUILD_TIMESTAMP
);
3354 // PLAYER_QUEST_LOG_x also visible bit on official (but only on party/raid)...
3355 for(uint16 i
= PLAYER_QUEST_LOG_1_1
; i
< PLAYER_QUEST_LOG_25_2
; i
+= 4)
3356 updateVisualBits
.SetBit(i
);
3358 // Players visible items are not inventory stuff
3359 for(uint16 i
= 0; i
< EQUIPMENT_SLOT_END
; ++i
)
3361 uint32 offset
= i
* MAX_VISIBLE_ITEM_OFFSET
;
3364 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_CREATOR
+ 0 + offset
);
3365 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_CREATOR
+ 1 + offset
);
3368 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_0
+ 0 + offset
);
3370 // item enchantments
3371 for(uint8 j
= 0; j
< MAX_ENCHANTMENT_SLOT
; ++j
)
3372 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_0
+ 1 + j
+ offset
);
3374 // random properties
3375 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ offset
);
3376 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_SEED
+ offset
);
3377 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_PAD
+ offset
);
3380 updateVisualBits
.SetBit(PLAYER_CHOSEN_TITLE
);
3383 void Player::BuildCreateUpdateBlockForPlayer( UpdateData
*data
, Player
*target
) const
3385 for(int i
= 0; i
< EQUIPMENT_SLOT_END
; i
++)
3387 if(m_items
[i
] == NULL
)
3390 m_items
[i
]->BuildCreateUpdateBlockForPlayer( data
, target
);
3395 for(int i
= INVENTORY_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
3397 if(m_items
[i
] == NULL
)
3400 m_items
[i
]->BuildCreateUpdateBlockForPlayer( data
, target
);
3402 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
3404 if(m_items
[i
] == NULL
)
3407 m_items
[i
]->BuildCreateUpdateBlockForPlayer( data
, target
);
3411 Unit::BuildCreateUpdateBlockForPlayer( data
, target
);
3414 void Player::DestroyForPlayer( Player
*target
) const
3416 Unit::DestroyForPlayer( target
);
3418 for(int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
3420 if(m_items
[i
] == NULL
)
3423 m_items
[i
]->DestroyForPlayer( target
);
3428 for(int i
= INVENTORY_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
3430 if(m_items
[i
] == NULL
)
3433 m_items
[i
]->DestroyForPlayer( target
);
3435 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
3437 if(m_items
[i
] == NULL
)
3440 m_items
[i
]->DestroyForPlayer( target
);
3445 bool Player::HasSpell(uint32 spell
) const
3447 PlayerSpellMap::const_iterator itr
= m_spells
.find((uint16
)spell
);
3448 return (itr
!= m_spells
.end() && itr
->second
->state
!= PLAYERSPELL_REMOVED
&& !itr
->second
->disabled
);
3451 TrainerSpellState
Player::GetTrainerSpellState(TrainerSpell
const* trainer_spell
) const
3454 return TRAINER_SPELL_RED
;
3456 if (!trainer_spell
->learned_spell
)
3457 return TRAINER_SPELL_RED
;
3460 if(HasSpell(trainer_spell
->learned_spell
))
3461 return TRAINER_SPELL_GRAY
;
3463 // check race/class requirement
3464 if(!IsSpellFitByClassAndRace(trainer_spell
->learned_spell
))
3465 return TRAINER_SPELL_RED
;
3467 // check level requirement
3468 if(getLevel() < trainer_spell
->reqlevel
)
3469 return TRAINER_SPELL_RED
;
3471 if(SpellChainNode
const* spell_chain
= spellmgr
.GetSpellChainNode(trainer_spell
->learned_spell
))
3473 // check prev.rank requirement
3474 if(spell_chain
->prev
&& !HasSpell(spell_chain
->prev
))
3475 return TRAINER_SPELL_RED
;
3477 // check additional spell requirement
3478 if(spell_chain
->req
&& !HasSpell(spell_chain
->req
))
3479 return TRAINER_SPELL_RED
;
3482 // check skill requirement
3483 if(trainer_spell
->reqskill
&& GetBaseSkillValue(trainer_spell
->reqskill
) < trainer_spell
->reqskillvalue
)
3484 return TRAINER_SPELL_RED
;
3486 // exist, already checked at loading
3487 SpellEntry
const* spell
= sSpellStore
.LookupEntry(trainer_spell
->learned_spell
);
3489 // secondary prof. or not prof. spell
3490 uint32 skill
= spell
->EffectMiscValue
[1];
3492 if(spell
->Effect
[1] != SPELL_EFFECT_SKILL
|| !IsPrimaryProfessionSkill(skill
))
3493 return TRAINER_SPELL_GREEN
;
3495 // check primary prof. limit
3496 if(spellmgr
.IsPrimaryProfessionFirstRankSpell(spell
->Id
) && GetFreePrimaryProffesionPoints() == 0)
3497 return TRAINER_SPELL_RED
;
3499 return TRAINER_SPELL_GREEN
;
3502 void Player::DeleteFromDB(uint64 playerguid
, uint32 accountId
, bool updateRealmChars
)
3504 uint32 guid
= GUID_LOPART(playerguid
);
3506 // convert corpse to bones if exist (to prevent exiting Corpse in World without DB entry)
3507 // bones will be deleted by corpse/bones deleting thread shortly
3508 ObjectAccessor::Instance().ConvertCorpseForPlayer(playerguid
);
3510 // remove from guild
3511 uint32 guildId
= GetGuildIdFromDB(playerguid
);
3514 Guild
* guild
= objmgr
.GetGuildById(guildId
);
3516 guild
->DelMember(guid
);
3519 // remove from arena teams
3520 LeaveAllArenaTeams(playerguid
);
3522 // the player was uninvited already on logout so just remove from group
3523 QueryResult
*resultGroup
= CharacterDatabase
.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", guid
);
3526 uint64 leaderGuid
= MAKE_NEW_GUID((*resultGroup
)[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
3528 Group
* group
= objmgr
.GetGroupByLeader(leaderGuid
);
3531 RemoveFromGroup(group
, playerguid
);
3535 // remove signs from petitions (also remove petitions if owner);
3536 RemovePetitionsAndSigns(playerguid
, 10);
3538 // return back all mails with COD and Item 0 1 2 3 4 5 6
3539 QueryResult
*resultMail
= CharacterDatabase
.PQuery("SELECT id,mailTemplateId,sender,subject,itemTextId,money,has_items FROM mail WHERE receiver='%u' AND has_items<>0 AND cod<>0", guid
);
3544 Field
*fields
= resultMail
->Fetch();
3546 uint32 mail_id
= fields
[0].GetUInt32();
3547 uint16 mailTemplateId
= fields
[1].GetUInt16();
3548 uint32 sender
= fields
[2].GetUInt32();
3549 std::string subject
= fields
[3].GetCppString();
3550 uint32 itemTextId
= fields
[4].GetUInt32();
3551 uint32 money
= fields
[5].GetUInt32();
3552 bool has_items
= fields
[6].GetBool();
3554 //we can return mail now
3555 //so firstly delete the old one
3556 CharacterDatabase
.PExecute("DELETE FROM mail WHERE id = '%u'", mail_id
);
3561 // data needs to be at first place for Item::LoadFromDB
3562 QueryResult
*resultItems
= CharacterDatabase
.PQuery("SELECT data,item_guid,item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id
);
3567 Field
*fields2
= resultItems
->Fetch();
3569 uint32 item_guidlow
= fields2
[1].GetUInt32();
3570 uint32 item_template
= fields2
[2].GetUInt32();
3572 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_template
);
3575 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", item_guidlow
);
3579 Item
*pItem
= NewItemOrBag(itemProto
);
3580 if(!pItem
->LoadFromDB(item_guidlow
, MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
),resultItems
))
3582 pItem
->FSetState(ITEM_REMOVED
);
3583 pItem
->SaveToDB(); // it also deletes item object !
3587 mi
.AddItem(item_guidlow
, item_template
, pItem
);
3589 while (resultItems
->NextRow());
3595 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE mail_id = '%u'", mail_id
);
3597 uint32 pl_account
= objmgr
.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
));
3599 WorldSession::SendReturnToSender(MAIL_NORMAL
, pl_account
, guid
, sender
, subject
, itemTextId
, &mi
, money
, mailTemplateId
);
3601 while (resultMail
->NextRow());
3606 // unsummon and delete for pets in world is not required: player deleted from CLI or character list with not loaded pet.
3607 // Get guids of character's pets, will deleted in transaction
3608 QueryResult
*resultPets
= CharacterDatabase
.PQuery("SELECT id FROM character_pet WHERE owner = '%u'",guid
);
3610 // NOW we can finally clear other DB data related to character
3611 CharacterDatabase
.BeginTransaction();
3616 Field
*fields3
= resultPets
->Fetch();
3617 uint32 petguidlow
= fields3
[0].GetUInt32();
3618 Pet::DeleteFromDB(petguidlow
);
3619 } while (resultPets
->NextRow());
3623 CharacterDatabase
.PExecute("DELETE FROM characters WHERE guid = '%u'",guid
);
3624 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'",guid
);
3625 CharacterDatabase
.PExecute("DELETE FROM character_action WHERE guid = '%u'",guid
);
3626 CharacterDatabase
.PExecute("DELETE FROM character_aura WHERE guid = '%u'",guid
);
3627 CharacterDatabase
.PExecute("DELETE FROM character_gifts WHERE guid = '%u'",guid
);
3628 CharacterDatabase
.PExecute("DELETE FROM character_homebind WHERE guid = '%u'",guid
);
3629 CharacterDatabase
.PExecute("DELETE FROM character_instance WHERE guid = '%u'",guid
);
3630 CharacterDatabase
.PExecute("DELETE FROM group_instance WHERE leaderGuid = '%u'",guid
);
3631 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE guid = '%u'",guid
);
3632 CharacterDatabase
.PExecute("DELETE FROM character_queststatus WHERE guid = '%u'",guid
);
3633 CharacterDatabase
.PExecute("DELETE FROM character_reputation WHERE guid = '%u'",guid
);
3634 CharacterDatabase
.PExecute("DELETE FROM character_spell WHERE guid = '%u'",guid
);
3635 CharacterDatabase
.PExecute("DELETE FROM character_spell_cooldown WHERE guid = '%u'",guid
);
3636 CharacterDatabase
.PExecute("DELETE FROM character_ticket WHERE guid = '%u'",guid
);
3637 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE owner_guid = '%u'",guid
);
3638 CharacterDatabase
.PExecute("DELETE FROM character_social WHERE guid = '%u' OR friend='%u'",guid
,guid
);
3639 CharacterDatabase
.PExecute("DELETE FROM mail WHERE receiver = '%u'",guid
);
3640 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE receiver = '%u'",guid
);
3641 CharacterDatabase
.PExecute("DELETE FROM character_pet WHERE owner = '%u'",guid
);
3642 CharacterDatabase
.PExecute("DELETE FROM character_pet_declinedname WHERE owner = '%u'",guid
);
3643 CharacterDatabase
.PExecute("DELETE FROM character_achievement WHERE guid = '%u'",guid
);
3644 CharacterDatabase
.PExecute("DELETE FROM character_achievement_progress WHERE guid = '%u'",guid
);
3645 CharacterDatabase
.CommitTransaction();
3647 //loginDatabase.PExecute("UPDATE realmcharacters SET numchars = numchars - 1 WHERE acctid = %d AND realmid = %d", accountId, realmID);
3648 if(updateRealmChars
) sWorld
.UpdateRealmCharCount(accountId
);
3651 void Player::SetMovement(PlayerMovementType pType
)
3656 case MOVE_ROOT
: data
.Initialize(SMSG_FORCE_MOVE_ROOT
, GetPackGUID().size()+4); break;
3657 case MOVE_UNROOT
: data
.Initialize(SMSG_FORCE_MOVE_UNROOT
, GetPackGUID().size()+4); break;
3658 case MOVE_WATER_WALK
: data
.Initialize(SMSG_MOVE_WATER_WALK
, GetPackGUID().size()+4); break;
3659 case MOVE_LAND_WALK
: data
.Initialize(SMSG_MOVE_LAND_WALK
, GetPackGUID().size()+4); break;
3661 sLog
.outError("Player::SetMovement: Unsupported move type (%d), data not sent to client.",pType
);
3664 data
.append(GetPackGUID());
3666 GetSession()->SendPacket( &data
);
3670 - a resurrectable corpse must not be loaded for the player (only bones)
3671 - the player must be in world
3673 void Player::BuildPlayerRepop()
3675 WorldPacket
data(SMSG_PRE_RESURRECT
, GetPackGUID().size());
3676 data
.append(GetPackGUID());
3677 GetSession()->SendPacket(&data
);
3679 if(getRace() == RACE_NIGHTELF
)
3680 CastSpell(this, 20584, true); // auras SPELL_AURA_INCREASE_SPEED(+speed in wisp form), SPELL_AURA_INCREASE_SWIM_SPEED(+swim speed in wisp form), SPELL_AURA_TRANSFORM (to wisp form)
3681 CastSpell(this, 8326, true); // auras SPELL_AURA_GHOST, SPELL_AURA_INCREASE_SPEED(why?), SPELL_AURA_INCREASE_SWIM_SPEED(why?)
3683 // there must be SMSG.FORCE_RUN_SPEED_CHANGE, SMSG.FORCE_SWIM_SPEED_CHANGE, SMSG.MOVE_WATER_WALK
3684 // there must be SMSG.STOP_MIRROR_TIMER
3685 // there we must send 888 opcode
3687 // the player cannot have a corpse already, only bones which are not returned by GetCorpse
3690 sLog
.outError("BuildPlayerRepop: player %s(%d) already has a corpse", GetName(), GetGUIDLow());
3694 // create a corpse and place it at the player's location
3696 Corpse
*corpse
= GetCorpse();
3699 sLog
.outError("Error creating corpse for Player %s [%u]", GetName(), GetGUIDLow());
3702 GetMap()->Add(corpse
);
3704 // convert player body to ghost
3707 SetMovement(MOVE_WATER_WALK
);
3708 if(!GetSession()->isLogingOut())
3709 SetMovement(MOVE_UNROOT
);
3711 // BG - remove insignia related
3712 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
);
3714 SendCorpseReclaimDelay();
3716 // to prevent cheating
3717 corpse
->ResetGhostTime();
3719 StopMirrorTimers(); //disable timers(bars)
3721 SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, (float)1.0); //see radius of death player?
3723 SetByteValue(UNIT_FIELD_BYTES_1
, 3, PLAYER_STATE_FLAG_ALWAYS_STAND
);
3726 void Player::SendDelayResponse(const uint32 ml_seconds
)
3728 //FIXME: is this delay time arg really need? 50msec by default in code
3729 WorldPacket
data( SMSG_QUERY_TIME_RESPONSE
, 4+4 );
3730 data
<< (uint32
)time(NULL
);
3732 GetSession()->SendPacket( &data
);
3735 void Player::ResurrectPlayer(float restore_percent
, bool applySickness
)
3737 WorldPacket
data(SMSG_DEATH_RELEASE_LOC
, 4*4); // remove spirit healer position
3742 GetSession()->SendPacket(&data
);
3744 // speed change, land walk
3746 // remove death flag + set aura
3747 SetByteValue(UNIT_FIELD_BYTES_1
, 3, 0x00);
3748 if(getRace() == RACE_NIGHTELF
)
3749 RemoveAurasDueToSpell(20584); // speed bonuses
3750 RemoveAurasDueToSpell(8326); // SPELL_AURA_GHOST
3752 setDeathState(ALIVE
);
3754 SetMovement(MOVE_LAND_WALK
);
3755 SetMovement(MOVE_UNROOT
);
3759 // set health/powers (0- will be set in caller)
3760 if(restore_percent
>0.0f
)
3762 SetHealth(uint32(GetMaxHealth()*restore_percent
));
3763 SetPower(POWER_MANA
, uint32(GetMaxPower(POWER_MANA
)*restore_percent
));
3764 SetPower(POWER_RAGE
, 0);
3765 SetPower(POWER_ENERGY
, uint32(GetMaxPower(POWER_ENERGY
)*restore_percent
));
3768 // update visibility
3769 ObjectAccessor::UpdateVisibilityForPlayer(this);
3771 // some items limited to specific map
3772 DestroyZoneLimitedItem( true, GetZoneId());
3777 //Characters from level 1-10 are not affected by resurrection sickness.
3778 //Characters from level 11-19 will suffer from one minute of sickness
3779 //for each level they are above 10.
3780 //Characters level 20 and up suffer from ten minutes of sickness.
3781 int32 startLevel
= sWorld
.getConfig(CONFIG_DEATH_SICKNESS_LEVEL
);
3783 if(int32(getLevel()) >= startLevel
)
3785 // set resurrection sickness
3786 CastSpell(this,SPELL_ID_PASSIVE_RESURRECTION_SICKNESS
,true);
3788 // not full duration
3789 if(int32(getLevel()) < startLevel
+9)
3791 int32 delta
= (int32(getLevel()) - startLevel
+ 1)*MINUTE
;
3793 for(int i
=0; i
< 3; ++i
)
3795 if(Aura
* Aur
= GetAura(SPELL_ID_PASSIVE_RESURRECTION_SICKNESS
,i
))
3797 Aur
->SetAuraDuration(delta
*1000);
3798 Aur
->SendAuraUpdate(false);
3805 void Player::KillPlayer()
3807 SetMovement(MOVE_ROOT
);
3809 StopMirrorTimers(); //disable timers(bars)
3811 setDeathState(CORPSE
);
3812 //SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_IN_PVP );
3814 SetFlag(UNIT_DYNAMIC_FLAGS
, 0x00);
3815 ApplyModFlag(PLAYER_FIELD_BYTES
, PLAYER_FIELD_BYTE_RELEASE_TIMER
, !sMapStore
.LookupEntry(GetMapId())->Instanceable());
3817 // 6 minutes until repop at graveyard
3818 m_deathTimer
= 6*MINUTE
*1000;
3820 UpdateCorpseReclaimDelay(); // dependent at use SetDeathPvP() call before kill
3822 // don't create corpse at this moment, player might be falling
3824 // update visibility
3825 ObjectAccessor::UpdateObjectVisibility(this);
3828 void Player::CreateCorpse()
3830 // prevent existence 2 corpse for player
3833 uint32 _uf
, _pb
, _pb2
, _cfb1
, _cfb2
;
3835 Corpse
*corpse
= new Corpse( (m_ExtraFlags
& PLAYER_EXTRA_PVP_DEATH
) ? CORPSE_RESURRECTABLE_PVP
: CORPSE_RESURRECTABLE_PVE
);
3838 if(!corpse
->Create(objmgr
.GenerateLowGuid(HIGHGUID_CORPSE
), this, GetMapId(), GetPositionX(),
3839 GetPositionY(), GetPositionZ(), GetOrientation()))
3845 _uf
= GetUInt32Value(UNIT_FIELD_BYTES_0
);
3846 _pb
= GetUInt32Value(PLAYER_BYTES
);
3847 _pb2
= GetUInt32Value(PLAYER_BYTES_2
);
3849 uint8 race
= (uint8
)(_uf
);
3850 uint8 skin
= (uint8
)(_pb
);
3851 uint8 face
= (uint8
)(_pb
>> 8);
3852 uint8 hairstyle
= (uint8
)(_pb
>> 16);
3853 uint8 haircolor
= (uint8
)(_pb
>> 24);
3854 uint8 facialhair
= (uint8
)(_pb2
);
3856 _cfb1
= ((0x00) | (race
<< 8) | (getGender() << 16) | (skin
<< 24));
3857 _cfb2
= ((face
) | (hairstyle
<< 8) | (haircolor
<< 16) | (facialhair
<< 24));
3859 corpse
->SetUInt32Value( CORPSE_FIELD_BYTES_1
, _cfb1
);
3860 corpse
->SetUInt32Value( CORPSE_FIELD_BYTES_2
, _cfb2
);
3862 uint32 flags
= CORPSE_FLAG_UNK2
;
3863 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_HELM
))
3864 flags
|= CORPSE_FLAG_HIDE_HELM
;
3865 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_CLOAK
))
3866 flags
|= CORPSE_FLAG_HIDE_CLOAK
;
3867 if(InBattleGround())
3868 flags
|= CORPSE_FLAG_LOOTABLE
; // to be able to remove insignia
3869 corpse
->SetUInt32Value( CORPSE_FIELD_FLAGS
, flags
);
3871 corpse
->SetUInt32Value( CORPSE_FIELD_DISPLAY_ID
, GetNativeDisplayId() );
3873 corpse
->SetUInt32Value( CORPSE_FIELD_GUILD
, GetGuildId() );
3876 uint16 iIventoryType
;
3878 for (int i
= 0; i
< EQUIPMENT_SLOT_END
; i
++)
3882 iDisplayID
= m_items
[i
]->GetProto()->DisplayInfoID
;
3883 iIventoryType
= (uint16
)m_items
[i
]->GetProto()->InventoryType
;
3885 _cfi
= (uint16(iDisplayID
)) | (iIventoryType
)<< 24;
3886 corpse
->SetUInt32Value(CORPSE_FIELD_ITEM
+ i
,_cfi
);
3890 // we don't SaveToDB for players in battlegrounds so don't do it for corpses either
3891 const MapEntry
*entry
= sMapStore
.LookupEntry(corpse
->GetMapId());
3893 if(entry
->map_type
!= MAP_BATTLEGROUND
)
3896 // register for player, but not show
3897 ObjectAccessor::Instance().AddCorpse(corpse
);
3900 void Player::SpawnCorpseBones()
3902 if(ObjectAccessor::Instance().ConvertCorpseForPlayer(GetGUID()))
3903 SaveToDB(); // prevent loading as ghost without corpse
3906 Corpse
* Player::GetCorpse() const
3908 return ObjectAccessor::Instance().GetCorpseForPlayerGUID(GetGUID());
3911 void Player::DurabilityLossAll(double percent
, bool inventory
)
3913 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
3914 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3915 DurabilityLoss(pItem
,percent
);
3919 // bags not have durability
3920 // for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
3922 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
3923 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3924 DurabilityLoss(pItem
,percent
);
3926 // keys not have durability
3927 //for(int i = KEYRING_SLOT_START; i < KEYRING_SLOT_END; i++)
3929 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
3930 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3931 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
3932 if(Item
* pItem
= GetItemByPos( i
, j
))
3933 DurabilityLoss(pItem
,percent
);
3937 void Player::DurabilityLoss(Item
* item
, double percent
)
3942 uint32 pMaxDurability
= item
->GetUInt32Value(ITEM_FIELD_MAXDURABILITY
);
3947 uint32 pDurabilityLoss
= uint32(pMaxDurability
*percent
);
3949 if(pDurabilityLoss
< 1 )
3950 pDurabilityLoss
= 1;
3952 DurabilityPointsLoss(item
,pDurabilityLoss
);
3955 void Player::DurabilityPointsLossAll(int32 points
, bool inventory
)
3957 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
3958 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3959 DurabilityPointsLoss(pItem
,points
);
3963 // bags not have durability
3964 // for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
3966 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
3967 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3968 DurabilityPointsLoss(pItem
,points
);
3970 // keys not have durability
3971 //for(int i = KEYRING_SLOT_START; i < KEYRING_SLOT_END; i++)
3973 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
3974 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3975 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
3976 if(Item
* pItem
= GetItemByPos( i
, j
))
3977 DurabilityPointsLoss(pItem
,points
);
3981 void Player::DurabilityPointsLoss(Item
* item
, int32 points
)
3983 int32 pMaxDurability
= item
->GetUInt32Value(ITEM_FIELD_MAXDURABILITY
);
3984 int32 pOldDurability
= item
->GetUInt32Value(ITEM_FIELD_DURABILITY
);
3985 int32 pNewDurability
= pOldDurability
- points
;
3987 if (pNewDurability
< 0)
3989 else if (pNewDurability
> pMaxDurability
)
3990 pNewDurability
= pMaxDurability
;
3992 if (pOldDurability
!= pNewDurability
)
3994 // modify item stats _before_ Durability set to 0 to pass _ApplyItemMods internal check
3995 if ( pNewDurability
== 0 && pOldDurability
> 0 && item
->IsEquipped())
3996 _ApplyItemMods(item
,item
->GetSlot(), false);
3998 item
->SetUInt32Value(ITEM_FIELD_DURABILITY
, pNewDurability
);
4000 // modify item stats _after_ restore durability to pass _ApplyItemMods internal check
4001 if ( pNewDurability
> 0 && pOldDurability
== 0 && item
->IsEquipped())
4002 _ApplyItemMods(item
,item
->GetSlot(), true);
4004 item
->SetState(ITEM_CHANGED
, this);
4008 void Player::DurabilityPointLossForEquipSlot(EquipmentSlots slot
)
4010 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, slot
))
4011 DurabilityPointsLoss(pItem
,1);
4014 uint32
Player::DurabilityRepairAll(bool cost
, float discountMod
, bool guildBank
)
4016 uint32 TotalCost
= 0;
4017 // equipped, backpack, bags itself
4018 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
4019 TotalCost
+= DurabilityRepair(( (INVENTORY_SLOT_BAG_0
<< 8) | i
),cost
,discountMod
, guildBank
);
4021 // bank, buyback and keys not repaired
4023 // items in inventory bags
4024 for(int j
= INVENTORY_SLOT_BAG_START
; j
< INVENTORY_SLOT_BAG_END
; j
++)
4025 for(int i
= 0; i
< MAX_BAG_SIZE
; i
++)
4026 TotalCost
+= DurabilityRepair(( (j
<< 8) | i
),cost
,discountMod
, guildBank
);
4030 uint32
Player::DurabilityRepair(uint16 pos
, bool cost
, float discountMod
, bool guildBank
)
4032 Item
* item
= GetItemByPos(pos
);
4034 uint32 TotalCost
= 0;
4038 uint32 maxDurability
= item
->GetUInt32Value(ITEM_FIELD_MAXDURABILITY
);
4042 uint32 curDurability
= item
->GetUInt32Value(ITEM_FIELD_DURABILITY
);
4046 uint32 LostDurability
= maxDurability
- curDurability
;
4047 if(LostDurability
>0)
4049 ItemPrototype
const *ditemProto
= item
->GetProto();
4051 DurabilityCostsEntry
const *dcost
= sDurabilityCostsStore
.LookupEntry(ditemProto
->ItemLevel
);
4054 sLog
.outError("ERROR: RepairDurability: Wrong item lvl %u", ditemProto
->ItemLevel
);
4058 uint32 dQualitymodEntryId
= (ditemProto
->Quality
+1)*2;
4059 DurabilityQualityEntry
const *dQualitymodEntry
= sDurabilityQualityStore
.LookupEntry(dQualitymodEntryId
);
4060 if(!dQualitymodEntry
)
4062 sLog
.outError("ERROR: RepairDurability: Wrong dQualityModEntry %u", dQualitymodEntryId
);
4066 uint32 dmultiplier
= dcost
->multiplier
[ItemSubClassToDurabilityMultiplierId(ditemProto
->Class
,ditemProto
->SubClass
)];
4067 uint32 costs
= uint32(LostDurability
*dmultiplier
*double(dQualitymodEntry
->quality_mod
));
4069 costs
= uint32(costs
* discountMod
);
4071 if (costs
==0) //fix for ITEM_QUALITY_ARTIFACT
4076 if (GetGuildId()==0)
4078 DEBUG_LOG("You are not member of a guild");
4082 Guild
*pGuild
= objmgr
.GetGuildById(GetGuildId());
4086 if (!pGuild
->HasRankRight(GetRank(), GR_RIGHT_WITHDRAW_REPAIR
))
4088 DEBUG_LOG("You do not have rights to withdraw for repairs");
4092 if (pGuild
->GetMemberMoneyWithdrawRem(GetGUIDLow()) < costs
)
4094 DEBUG_LOG("You do not have enough money withdraw amount remaining");
4098 if (pGuild
->GetGuildBankMoney() < costs
)
4100 DEBUG_LOG("There is not enough money in bank");
4104 pGuild
->MemberMoneyWithdraw(costs
, GetGUIDLow());
4107 else if (GetMoney() < costs
)
4109 DEBUG_LOG("You do not have enough money");
4113 ModifyMoney( -int32(costs
) );
4117 item
->SetUInt32Value(ITEM_FIELD_DURABILITY
, maxDurability
);
4118 item
->SetState(ITEM_CHANGED
, this);
4120 // reapply mods for total broken and repaired item if equipped
4121 if(IsEquipmentPos(pos
) && !curDurability
)
4122 _ApplyItemMods(item
,pos
& 255, true);
4126 void Player::RepopAtGraveyard()
4128 // note: this can be called also when the player is alive
4129 // for example from WorldSession::HandleMovementOpcodes
4131 AreaTableEntry
const *zone
= GetAreaEntryByAreaID(GetAreaId());
4133 // Such zones are considered unreachable as a ghost and the player must be automatically revived
4134 if(!isAlive() && zone
&& zone
->flags
& AREA_FLAG_NEED_FLY
|| GetTransport())
4136 ResurrectPlayer(0.5f
);
4140 WorldSafeLocsEntry
const *ClosestGrave
= NULL
;
4142 // Special handle for battleground maps
4143 BattleGround
*bg
= sBattleGroundMgr
.GetBattleGround(GetBattleGroundId());
4145 if(bg
&& (bg
->GetTypeID() == BATTLEGROUND_AB
|| bg
->GetTypeID() == BATTLEGROUND_EY
))
4146 ClosestGrave
= bg
->GetClosestGraveYard(GetPositionX(), GetPositionY(), GetPositionZ(), GetTeam());
4148 ClosestGrave
= objmgr
.GetClosestGraveYard( GetPositionX(), GetPositionY(), GetPositionZ(), GetMapId(), GetTeam() );
4150 // stop countdown until repop
4153 // if no grave found, stay at the current location
4154 // and don't show spirit healer location
4157 TeleportTo(ClosestGrave
->map_id
, ClosestGrave
->x
, ClosestGrave
->y
, ClosestGrave
->z
, GetOrientation());
4158 if(isDead()) // not send if alive, because it used in TeleportTo()
4160 WorldPacket
data(SMSG_DEATH_RELEASE_LOC
, 4*4); // show spirit healer position on minimap
4161 data
<< ClosestGrave
->map_id
;
4162 data
<< ClosestGrave
->x
;
4163 data
<< ClosestGrave
->y
;
4164 data
<< ClosestGrave
->z
;
4165 GetSession()->SendPacket(&data
);
4170 void Player::JoinedChannel(Channel
*c
)
4172 m_channels
.push_back(c
);
4175 void Player::LeftChannel(Channel
*c
)
4177 m_channels
.remove(c
);
4180 void Player::CleanupChannels()
4182 while(!m_channels
.empty())
4184 Channel
* ch
= *m_channels
.begin();
4185 m_channels
.erase(m_channels
.begin()); // remove from player's channel list
4186 ch
->Leave(GetGUID(), false); // not send to client, not remove from player's channel list
4187 if (ChannelMgr
* cMgr
= channelMgr(GetTeam()))
4188 cMgr
->LeftChannel(ch
->GetName()); // deleted channel if empty
4191 sLog
.outDebug("Player: channels cleaned up!");
4194 void Player::UpdateLocalChannels(uint32 newZone
)
4196 if(m_channels
.empty())
4199 AreaTableEntry
const* current_zone
= GetAreaEntryByAreaID(newZone
);
4203 ChannelMgr
* cMgr
= channelMgr(GetTeam());
4207 std::string current_zone_name
= current_zone
->area_name
[GetSession()->GetSessionDbcLocale()];
4209 for(JoinedChannelsList::iterator i
= m_channels
.begin(), next
; i
!= m_channels
.end(); i
= next
)
4213 // skip non built-in channels
4214 if(!(*i
)->IsConstant())
4217 ChatChannelsEntry
const* ch
= GetChannelEntryFor((*i
)->GetChannelId());
4221 if((ch
->flags
& 4) == 4) // global channel without zone name in pattern
4225 char new_channel_name_buf
[100];
4226 snprintf(new_channel_name_buf
,100,ch
->pattern
[m_session
->GetSessionDbcLocale()],current_zone_name
.c_str());
4227 Channel
* new_channel
= cMgr
->GetJoinChannel(new_channel_name_buf
,ch
->ChannelID
);
4229 if((*i
)!=new_channel
)
4231 new_channel
->Join(GetGUID(),""); // will output Changed Channel: N. Name
4233 // leave old channel
4234 (*i
)->Leave(GetGUID(),false); // not send leave channel, it already replaced at client
4235 std::string name
= (*i
)->GetName(); // store name, (*i)erase in LeftChannel
4236 LeftChannel(*i
); // remove from player's channel list
4237 cMgr
->LeftChannel(name
); // delete if empty
4240 sLog
.outDebug("Player: channels cleaned up!");
4243 void Player::LeaveLFGChannel()
4245 for(JoinedChannelsList::iterator i
= m_channels
.begin(); i
!= m_channels
.end(); ++i
)
4249 (*i
)->Leave(GetGUID());
4255 void Player::UpdateDefense()
4257 uint32 defense_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_DEFENSE
);
4259 if(UpdateSkill(SKILL_DEFENSE
,defense_skill_gain
))
4261 // update dependent from defense skill part
4262 UpdateDefenseBonusesMod();
4266 void Player::HandleBaseModValue(BaseModGroup modGroup
, BaseModType modType
, float amount
, bool apply
)
4268 if(modGroup
>= BASEMOD_END
|| modType
>= MOD_END
)
4270 sLog
.outError("ERROR in HandleBaseModValue(): non existed BaseModGroup of wrong BaseModType!");
4279 m_auraBaseMod
[modGroup
][modType
] += apply
? amount
: -amount
;
4282 if(amount
<= -100.0f
)
4285 val
= (100.0f
+ amount
) / 100.0f
;
4286 m_auraBaseMod
[modGroup
][modType
] *= apply
? val
: (1.0f
/val
);
4290 if(!CanModifyStats())
4295 case CRIT_PERCENTAGE
: UpdateCritPercentage(BASE_ATTACK
); break;
4296 case RANGED_CRIT_PERCENTAGE
: UpdateCritPercentage(RANGED_ATTACK
); break;
4297 case OFFHAND_CRIT_PERCENTAGE
: UpdateCritPercentage(OFF_ATTACK
); break;
4298 case SHIELD_BLOCK_VALUE
: UpdateShieldBlockValue(); break;
4303 float Player::GetBaseModValue(BaseModGroup modGroup
, BaseModType modType
) const
4305 if(modGroup
>= BASEMOD_END
|| modType
> MOD_END
)
4307 sLog
.outError("ERROR: trial to access non existed BaseModGroup or wrong BaseModType!");
4311 if(modType
== PCT_MOD
&& m_auraBaseMod
[modGroup
][PCT_MOD
] <= 0.0f
)
4314 return m_auraBaseMod
[modGroup
][modType
];
4317 float Player::GetTotalBaseModValue(BaseModGroup modGroup
) const
4319 if(modGroup
>= BASEMOD_END
)
4321 sLog
.outError("ERROR: wrong BaseModGroup in GetTotalBaseModValue()!");
4325 if(m_auraBaseMod
[modGroup
][PCT_MOD
] <= 0.0f
)
4328 return m_auraBaseMod
[modGroup
][FLAT_MOD
] * m_auraBaseMod
[modGroup
][PCT_MOD
];
4331 uint32
Player::GetShieldBlockValue() const
4333 BaseModGroup modGroup
= SHIELD_BLOCK_VALUE
;
4335 float value
= GetTotalBaseModValue(modGroup
) + GetStat(STAT_STRENGTH
) * 0.5f
- 10;
4337 value
= (value
< 0) ? 0 : value
;
4339 return uint32(value
);
4342 float Player::GetMeleeCritFromAgility()
4344 uint32 level
= getLevel();
4345 uint32 pclass
= getClass();
4347 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4349 GtChanceToMeleeCritBaseEntry
const *critBase
= sGtChanceToMeleeCritBaseStore
.LookupEntry(pclass
-1);
4350 GtChanceToMeleeCritEntry
const *critRatio
= sGtChanceToMeleeCritStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4351 if (critBase
==NULL
|| critRatio
==NULL
)
4354 float crit
=critBase
->base
+ GetStat(STAT_AGILITY
)*critRatio
->ratio
;
4358 float Player::GetDodgeFromAgility()
4360 // Table for base dodge values
4361 float dodge_base
[MAX_CLASSES
] = {
4363 0.00652f
, // Paladin
4370 0.02011f
, // Warlock
4374 // Crit/agility to dodge/agility coefficient multipliers
4375 float crit_to_dodge
[MAX_CLASSES
] = {
4389 uint32 level
= getLevel();
4390 uint32 pclass
= getClass();
4392 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4394 // Dodge per agility for most classes equal crit per agility (but for some classes need apply some multiplier)
4395 GtChanceToMeleeCritEntry
const *dodgeRatio
= sGtChanceToMeleeCritStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4396 if (dodgeRatio
==NULL
|| pclass
> MAX_CLASSES
)
4399 float dodge
=dodge_base
[pclass
-1] + GetStat(STAT_AGILITY
) * dodgeRatio
->ratio
* crit_to_dodge
[pclass
-1];
4400 return dodge
*100.0f
;
4403 float Player::GetSpellCritFromIntellect()
4405 uint32 level
= getLevel();
4406 uint32 pclass
= getClass();
4408 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4410 GtChanceToSpellCritBaseEntry
const *critBase
= sGtChanceToSpellCritBaseStore
.LookupEntry(pclass
-1);
4411 GtChanceToSpellCritEntry
const *critRatio
= sGtChanceToSpellCritStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4412 if (critBase
==NULL
|| critRatio
==NULL
)
4415 float crit
=critBase
->base
+ GetStat(STAT_INTELLECT
)*critRatio
->ratio
;
4419 float Player::GetRatingCoefficient(CombatRating cr
) const
4421 uint32 level
= getLevel();
4423 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4425 GtCombatRatingsEntry
const *Rating
= sGtCombatRatingsStore
.LookupEntry(cr
*GT_MAX_LEVEL
+level
-1);
4427 return 1.0f
; // By default use minimum coefficient (not must be called)
4429 return Rating
->ratio
;
4432 float Player::GetRatingBonusValue(CombatRating cr
) const
4434 return float(GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1
+ cr
)) / GetRatingCoefficient(cr
);
4437 uint32
Player::GetMeleeCritDamageReduction(uint32 damage
) const
4439 float melee
= GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*2.0f
;
4440 if (melee
>25.0f
) melee
= 25.0f
;
4441 return uint32 (melee
* damage
/100.0f
);
4444 uint32
Player::GetRangedCritDamageReduction(uint32 damage
) const
4446 float ranged
= GetRatingBonusValue(CR_CRIT_TAKEN_RANGED
)*2.0f
;
4447 if (ranged
>25.0f
) ranged
=25.0f
;
4448 return uint32 (ranged
* damage
/100.0f
);
4451 uint32
Player::GetSpellCritDamageReduction(uint32 damage
) const
4453 float spell
= GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2.0f
;
4454 // In wow script resilience limited to 25%
4457 return uint32 (spell
* damage
/ 100.0f
);
4460 uint32
Player::GetDotDamageReduction(uint32 damage
) const
4462 float spellDot
= GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
);
4463 // Dot resilience not limited (limit it by 100%)
4464 if (spellDot
> 100.0f
)
4466 return uint32 (spellDot
* damage
/ 100.0f
);
4469 float Player::GetExpertiseDodgeOrParryReduction(WeaponAttackType attType
) const
4474 return GetUInt32Value(PLAYER_EXPERTISE
) / 4.0f
;
4476 return GetUInt32Value(PLAYER_OFFHAND_EXPERTISE
) / 4.0f
;
4483 float Player::OCTRegenHPPerSpirit()
4485 uint32 level
= getLevel();
4486 uint32 pclass
= getClass();
4488 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4490 GtOCTRegenHPEntry
const *baseRatio
= sGtOCTRegenHPStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4491 GtRegenHPPerSptEntry
const *moreRatio
= sGtRegenHPPerSptStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4492 if (baseRatio
==NULL
|| moreRatio
==NULL
)
4495 // Formula from PaperDollFrame script
4496 float spirit
= GetStat(STAT_SPIRIT
);
4497 float baseSpirit
= spirit
;
4498 if (baseSpirit
>50) baseSpirit
= 50;
4499 float moreSpirit
= spirit
- baseSpirit
;
4500 float regen
= baseSpirit
* baseRatio
->ratio
+ moreSpirit
* moreRatio
->ratio
;
4504 float Player::OCTRegenMPPerSpirit()
4506 uint32 level
= getLevel();
4507 uint32 pclass
= getClass();
4509 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4511 // GtOCTRegenMPEntry const *baseRatio = sGtOCTRegenMPStore.LookupEntry((pclass-1)*GT_MAX_LEVEL + level-1);
4512 GtRegenMPPerSptEntry
const *moreRatio
= sGtRegenMPPerSptStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4513 if (moreRatio
==NULL
)
4516 // Formula get from PaperDollFrame script
4517 float spirit
= GetStat(STAT_SPIRIT
);
4518 float regen
= spirit
* moreRatio
->ratio
;
4522 void Player::ApplyRatingMod(CombatRating cr
, int32 value
, bool apply
)
4524 m_baseRatingValue
[cr
]+=(apply
? value
: -value
);
4526 int32 amount
= uint32(m_baseRatingValue
[cr
]);
4527 // Apply bonus from SPELL_AURA_MOD_RATING_FROM_STAT
4528 // stat used stored in miscValueB for this aura
4529 AuraList
const& modRatingFromStat
= GetAurasByType(SPELL_AURA_MOD_RATING_FROM_STAT
);
4530 for(AuraList::const_iterator i
= modRatingFromStat
.begin();i
!= modRatingFromStat
.end(); ++i
)
4531 if ((*i
)->GetMiscValue() & (1<<cr
))
4532 amount
+= GetStat(Stats((*i
)->GetMiscBValue())) * (*i
)->GetModifier()->m_amount
/ 100.0f
;
4535 SetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1
+ cr
, uint32(amount
));
4537 float RatingCoeffecient
= GetRatingCoefficient(cr
);
4538 float RatingChange
= 0.0f
;
4540 bool affectStats
= CanModifyStats();
4544 case CR_WEAPON_SKILL
: // Implemented in Unit::RollMeleeOutcomeAgainst
4545 case CR_DEFENSE_SKILL
:
4546 UpdateDefenseBonusesMod();
4549 UpdateDodgePercentage();
4552 UpdateParryPercentage();
4555 UpdateBlockPercentage();
4558 UpdateMeleeHitChances();
4561 UpdateRangedHitChances();
4564 UpdateSpellHitChances();
4569 UpdateCritPercentage(BASE_ATTACK
);
4570 UpdateCritPercentage(OFF_ATTACK
);
4573 case CR_CRIT_RANGED
:
4575 UpdateCritPercentage(RANGED_ATTACK
);
4579 UpdateAllSpellCritChances();
4581 case CR_HIT_TAKEN_MELEE
: // Implemented in Unit::MeleeMissChanceCalc
4582 case CR_HIT_TAKEN_RANGED
:
4584 case CR_HIT_TAKEN_SPELL
: // Implemented in Unit::MagicSpellHitResult
4586 case CR_CRIT_TAKEN_MELEE
: // Implemented in Unit::RollMeleeOutcomeAgainst (only for chance to crit)
4587 case CR_CRIT_TAKEN_RANGED
:
4589 case CR_CRIT_TAKEN_SPELL
: // Implemented in Unit::SpellCriticalBonus (only for chance to crit)
4591 case CR_HASTE_MELEE
:
4592 RatingChange
= value
/ RatingCoeffecient
;
4593 ApplyAttackTimePercentMod(BASE_ATTACK
,RatingChange
,apply
);
4594 ApplyAttackTimePercentMod(OFF_ATTACK
,RatingChange
,apply
);
4596 case CR_HASTE_RANGED
:
4597 RatingChange
= value
/ RatingCoeffecient
;
4598 ApplyAttackTimePercentMod(RANGED_ATTACK
, RatingChange
, apply
);
4600 case CR_HASTE_SPELL
:
4601 RatingChange
= value
/ RatingCoeffecient
;
4602 ApplyCastTimePercentMod(RatingChange
,apply
);
4604 case CR_WEAPON_SKILL_MAINHAND
: // Implemented in Unit::RollMeleeOutcomeAgainst
4605 case CR_WEAPON_SKILL_OFFHAND
:
4606 case CR_WEAPON_SKILL_RANGED
:
4611 UpdateExpertise(BASE_ATTACK
);
4612 UpdateExpertise(OFF_ATTACK
);
4618 void Player::SetRegularAttackTime()
4620 for(int i
= 0; i
< MAX_ATTACK
; ++i
)
4622 Item
*tmpitem
= GetWeaponForAttack(WeaponAttackType(i
));
4623 if(tmpitem
&& !tmpitem
->IsBroken())
4625 ItemPrototype
const *proto
= tmpitem
->GetProto();
4627 SetAttackTime(WeaponAttackType(i
), proto
->Delay
);
4629 SetAttackTime(WeaponAttackType(i
), BASE_ATTACK_TIME
);
4634 //skill+step, checking for max value
4635 bool Player::UpdateSkill(uint32 skill_id
, uint32 step
)
4641 for (; i
< PLAYER_MAX_SKILLS
; i
++)
4642 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill_id
)
4645 if(i
>=PLAYER_MAX_SKILLS
)
4648 uint32 data
= GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
));
4649 uint32 value
= SKILL_VALUE(data
);
4650 uint32 max
= SKILL_MAX(data
);
4652 if ((!max
) || (!value
) || (value
>= max
))
4655 if (value
*512 < max
*urand(0,512))
4657 uint32 new_value
= value
+step
;
4661 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(new_value
,max
));
4662 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
);
4669 inline int SkillGainChance(uint32 SkillValue
, uint32 GrayLevel
, uint32 GreenLevel
, uint32 YellowLevel
)
4671 if ( SkillValue
>= GrayLevel
)
4672 return sWorld
.getConfig(CONFIG_SKILL_CHANCE_GREY
)*10;
4673 if ( SkillValue
>= GreenLevel
)
4674 return sWorld
.getConfig(CONFIG_SKILL_CHANCE_GREEN
)*10;
4675 if ( SkillValue
>= YellowLevel
)
4676 return sWorld
.getConfig(CONFIG_SKILL_CHANCE_YELLOW
)*10;
4677 return sWorld
.getConfig(CONFIG_SKILL_CHANCE_ORANGE
)*10;
4680 bool Player::UpdateCraftSkill(uint32 spellid
)
4682 sLog
.outDebug("UpdateCraftSkill spellid %d", spellid
);
4684 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(spellid
);
4685 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(spellid
);
4687 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
4689 if(_spell_idx
->second
->skillId
)
4691 uint32 SkillValue
= GetPureSkillValue(_spell_idx
->second
->skillId
);
4693 // Alchemy Discoveries here
4694 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellid
);
4695 if(spellEntry
&& spellEntry
->Mechanic
==MECHANIC_DISCOVERY
)
4697 if(uint32 discoveredSpell
= GetSkillDiscoverySpell(_spell_idx
->second
->skillId
, spellid
, this))
4698 learnSpell(discoveredSpell
);
4701 uint32 craft_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_CRAFTING
);
4703 return UpdateSkillPro(_spell_idx
->second
->skillId
, SkillGainChance(SkillValue
,
4704 _spell_idx
->second
->max_value
,
4705 (_spell_idx
->second
->max_value
+ _spell_idx
->second
->min_value
)/2,
4706 _spell_idx
->second
->min_value
),
4713 bool Player::UpdateGatherSkill(uint32 SkillId
, uint32 SkillValue
, uint32 RedLevel
, uint32 Multiplicator
)
4715 sLog
.outDebug("UpdateGatherSkill(SkillId %d SkillLevel %d RedLevel %d)", SkillId
, SkillValue
, RedLevel
);
4717 uint32 gathering_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_GATHERING
);
4719 // For skinning and Mining chance decrease with level. 1-74 - no decrease, 75-149 - 2 times, 225-299 - 8 times
4722 case SKILL_HERBALISM
:
4723 case SKILL_LOCKPICKING
:
4724 case SKILL_JEWELCRAFTING
:
4725 case SKILL_INSCRIPTION
:
4726 return UpdateSkillPro(SkillId
, SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
,gathering_skill_gain
);
4727 case SKILL_SKINNING
:
4728 if( sWorld
.getConfig(CONFIG_SKILL_CHANCE_SKINNING_STEPS
)==0)
4729 return UpdateSkillPro(SkillId
, SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
,gathering_skill_gain
);
4731 return UpdateSkillPro(SkillId
, (SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
) >> (SkillValue
/sWorld
.getConfig(CONFIG_SKILL_CHANCE_SKINNING_STEPS
)), gathering_skill_gain
);
4733 if (sWorld
.getConfig(CONFIG_SKILL_CHANCE_MINING_STEPS
)==0)
4734 return UpdateSkillPro(SkillId
, SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
,gathering_skill_gain
);
4736 return UpdateSkillPro(SkillId
, (SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
) >> (SkillValue
/sWorld
.getConfig(CONFIG_SKILL_CHANCE_MINING_STEPS
)),gathering_skill_gain
);
4741 bool Player::UpdateFishingSkill()
4743 sLog
.outDebug("UpdateFishingSkill");
4745 uint32 SkillValue
= GetPureSkillValue(SKILL_FISHING
);
4747 int32 chance
= SkillValue
< 75 ? 100 : 2500/(SkillValue
-50);
4749 uint32 gathering_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_GATHERING
);
4751 return UpdateSkillPro(SKILL_FISHING
,chance
*10,gathering_skill_gain
);
4754 bool Player::UpdateSkillPro(uint16 SkillId
, int32 Chance
, uint32 step
)
4756 sLog
.outDebug("UpdateSkillPro(SkillId %d, Chance %3.1f%%)", SkillId
, Chance
/10.0);
4760 if(Chance
<= 0) // speedup in 0 chance case
4762 sLog
.outDebug("Player::UpdateSkillPro Chance=%3.1f%% missed", Chance
/10.0);
4767 for (; i
< PLAYER_MAX_SKILLS
; i
++)
4768 if ( SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_INDEX(i
))) == SkillId
) break;
4769 if ( i
>= PLAYER_MAX_SKILLS
)
4772 uint32 data
= GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
));
4773 uint16 SkillValue
= SKILL_VALUE(data
);
4774 uint16 MaxValue
= SKILL_MAX(data
);
4776 if ( !MaxValue
|| !SkillValue
|| SkillValue
>= MaxValue
)
4779 int32 Roll
= irand(1,1000);
4781 if ( Roll
<= Chance
)
4783 uint32 new_value
= SkillValue
+step
;
4784 if(new_value
> MaxValue
)
4785 new_value
= MaxValue
;
4787 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(new_value
,MaxValue
));
4788 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
);
4789 sLog
.outDebug("Player::UpdateSkillPro Chance=%3.1f%% taken", Chance
/10.0);
4793 sLog
.outDebug("Player::UpdateSkillPro Chance=%3.1f%% missed", Chance
/10.0);
4797 void Player::UpdateWeaponSkill (WeaponAttackType attType
)
4799 // no skill gain in pvp
4800 Unit
*pVictim
= getVictim();
4801 if(pVictim
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
4805 return; // always maximized SKILL_FERAL_COMBAT in fact
4807 if(m_form
== FORM_TREE
)
4808 return; // use weapon but not skill up
4810 uint32 weapon_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_WEAPON
);
4816 Item
*tmpitem
= GetWeaponForAttack(attType
,true);
4819 UpdateSkill(SKILL_UNARMED
,weapon_skill_gain
);
4820 else if(tmpitem
->GetProto()->SubClass
!= ITEM_SUBCLASS_WEAPON_FISHING_POLE
)
4821 UpdateSkill(tmpitem
->GetSkill(),weapon_skill_gain
);
4827 Item
*tmpitem
= GetWeaponForAttack(attType
,true);
4829 UpdateSkill(tmpitem
->GetSkill(),weapon_skill_gain
);
4833 UpdateAllCritPercentages();
4836 void Player::UpdateCombatSkills(Unit
*pVictim
, WeaponAttackType attType
, bool defence
)
4838 uint32 plevel
= getLevel(); // if defense than pVictim == attacker
4839 uint32 greylevel
= MaNGOS::XP::GetGrayLevel(plevel
);
4840 uint32 moblevel
= pVictim
->getLevelForTarget(this);
4841 if(moblevel
< greylevel
)
4844 if (moblevel
> plevel
+ 5)
4845 moblevel
= plevel
+ 5;
4847 uint32 lvldif
= moblevel
- greylevel
;
4851 uint32 skilldif
= 5 * plevel
- (defence
? GetBaseDefenseSkillValue() : GetBaseWeaponSkillValue(attType
));
4855 float chance
= float(3 * lvldif
* skilldif
) / plevel
;
4858 if(getClass() == CLASS_WARRIOR
|| getClass() == CLASS_ROGUE
)
4859 chance
*= 0.1f
* GetStat(STAT_INTELLECT
);
4862 chance
= chance
< 1.0f
? 1.0f
: chance
; //minimum chance to increase skill is 1%
4864 if(roll_chance_f(chance
))
4869 UpdateWeaponSkill(attType
);
4875 void Player::ModifySkillBonus(uint32 skillid
,int32 val
, bool talent
)
4877 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
4878 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skillid
)
4880 uint32 bonus_val
= GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
));
4881 int16 temp_bonus
= SKILL_TEMP_BONUS(bonus_val
);
4882 int16 perm_bonus
= SKILL_PERM_BONUS(bonus_val
);
4884 if(talent
) // permanent bonus stored in high part
4885 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),MAKE_SKILL_BONUS(temp_bonus
,perm_bonus
+val
));
4886 else // temporary/item bonus stored in low part
4887 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),MAKE_SKILL_BONUS(temp_bonus
+val
,perm_bonus
));
4892 void Player::UpdateSkillsForLevel()
4894 uint16 maxconfskill
= sWorld
.GetConfigMaxSkillValue();
4895 uint32 maxSkill
= GetMaxSkillValueForLevel();
4897 bool alwaysMaxSkill
= sWorld
.getConfig(CONFIG_ALWAYS_MAX_SKILL_FOR_LEVEL
);
4899 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
4900 if (GetUInt32Value(PLAYER_SKILL_INDEX(i
)))
4902 uint32 pskill
= GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF;
4904 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(pskill
);
4908 if(GetSkillRangeType(pSkill
,false) != SKILL_RANGE_LEVEL
)
4911 uint32 data
= GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
));
4912 uint32 max
= SKILL_MAX(data
);
4913 uint32 val
= SKILL_VALUE(data
);
4915 /// update only level dependent max skill values
4918 /// miximize skill always
4920 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(maxSkill
,maxSkill
));
4921 /// update max skill value if current max skill not maximized
4922 else if(max
!= maxconfskill
)
4923 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(val
,maxSkill
));
4928 void Player::UpdateSkillsToMaxSkillsForLevel()
4930 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
4931 if (GetUInt32Value(PLAYER_SKILL_INDEX(i
)))
4933 uint32 pskill
= GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF;
4934 if( IsProfessionOrRidingSkill(pskill
))
4936 uint32 data
= GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
));
4938 uint32 max
= SKILL_MAX(data
);
4941 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(max
,max
));
4943 if(pskill
== SKILL_DEFENSE
)
4944 UpdateDefenseBonusesMod();
4948 // This functions sets a skill line value (and adds if doesn't exist yet)
4949 // To "remove" a skill line, set it's values to zero
4950 void Player::SetSkill(uint32 id
, uint16 currVal
, uint16 maxVal
)
4956 for (; i
< PLAYER_MAX_SKILLS
; i
++)
4957 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == id
) break;
4959 if(i
<PLAYER_MAX_SKILLS
) //has skill
4963 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(currVal
,maxVal
));
4964 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
);
4968 // clear skill fields
4969 SetUInt32Value(PLAYER_SKILL_INDEX(i
),0);
4970 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),0);
4971 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),0);
4973 // remove spells that depend on this skill when removing the skill
4974 for (PlayerSpellMap::const_iterator itr
= m_spells
.begin(), next
= m_spells
.begin(); itr
!= m_spells
.end(); itr
= next
)
4977 if(itr
->second
->state
== PLAYERSPELL_REMOVED
)
4980 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(itr
->first
);
4981 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(itr
->first
);
4983 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
4985 if (_spell_idx
->second
->skillId
== id
)
4987 // this may remove more than one spell (dependents)
4988 removeSpell(itr
->first
);
4989 next
= m_spells
.begin();
4996 else if(currVal
) //add
4998 for (i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
4999 if (!GetUInt32Value(PLAYER_SKILL_INDEX(i
)))
5001 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(id
);
5004 sLog
.outError("Skill not found in SkillLineStore: skill #%u", id
);
5007 // enable unlearn button for primary professions only
5008 if (pSkill
->categoryId
== SKILL_CATEGORY_PROFESSION
)
5009 SetUInt32Value(PLAYER_SKILL_INDEX(i
), MAKE_PAIR32(id
,1));
5011 SetUInt32Value(PLAYER_SKILL_INDEX(i
), MAKE_PAIR32(id
,0));
5012 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(currVal
,maxVal
));
5013 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
);
5015 // apply skill bonuses
5016 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),0);
5018 // temporary bonuses
5019 AuraList
const& mModSkill
= GetAurasByType(SPELL_AURA_MOD_SKILL
);
5020 for(AuraList::const_iterator i
= mModSkill
.begin(); i
!= mModSkill
.end(); ++i
)
5021 if ((*i
)->GetModifier()->m_miscvalue
== int32(id
))
5022 (*i
)->ApplyModifier(true);
5024 // permanent bonuses
5025 AuraList
const& mModSkillTalent
= GetAurasByType(SPELL_AURA_MOD_SKILL_TALENT
);
5026 for(AuraList::const_iterator i
= mModSkillTalent
.begin(); i
!= mModSkillTalent
.end(); ++i
)
5027 if ((*i
)->GetModifier()->m_miscvalue
== int32(id
))
5028 (*i
)->ApplyModifier(true);
5030 // Learn all spells for skill
5031 learnSkillRewardedSpells(id
);
5037 bool Player::HasSkill(uint32 skill
) const
5039 if(!skill
)return false;
5040 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5042 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5050 uint16
Player::GetSkillValue(uint32 skill
) const
5055 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5057 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5059 uint32 bonus
= GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
));
5061 int32 result
= int32(SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
))));
5062 result
+= SKILL_TEMP_BONUS(bonus
);
5063 result
+= SKILL_PERM_BONUS(bonus
);
5064 return result
< 0 ? 0 : result
;
5070 uint16
Player::GetMaxSkillValue(uint32 skill
) const
5073 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5075 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5077 uint32 bonus
= GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
));
5079 int32 result
= int32(SKILL_MAX(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
))));
5080 result
+= SKILL_TEMP_BONUS(bonus
);
5081 result
+= SKILL_PERM_BONUS(bonus
);
5082 return result
< 0 ? 0 : result
;
5088 uint16
Player::GetPureMaxSkillValue(uint32 skill
) const
5091 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5093 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5095 return SKILL_MAX(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
)));
5101 uint16
Player::GetBaseSkillValue(uint32 skill
) const
5104 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5106 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5108 int32 result
= int32(SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
))));
5109 result
+= SKILL_PERM_BONUS(GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
)));
5110 return result
< 0 ? 0 : result
;
5116 uint16
Player::GetPureSkillValue(uint32 skill
) const
5119 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5121 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5123 return SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
)));
5129 int16
Player::GetSkillTempBonusValue(uint32 skill
) const
5134 for (int i
= 0; i
< PLAYER_MAX_SKILLS
; i
++)
5136 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5138 return SKILL_TEMP_BONUS(GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
)));
5145 void Player::SendInitialActionButtons()
5147 sLog
.outDetail( "Initializing Action Buttons for '%u'", GetGUIDLow() );
5149 WorldPacket
data(SMSG_ACTION_BUTTONS
, (MAX_ACTION_BUTTONS
*4));
5150 for(int button
= 0; button
< MAX_ACTION_BUTTONS
; ++button
)
5152 ActionButtonList::const_iterator itr
= m_actionButtons
.find(button
);
5153 if(itr
!= m_actionButtons
.end() && itr
->second
.uState
!= ACTIONBUTTON_DELETED
)
5155 data
<< uint16(itr
->second
.action
);
5156 data
<< uint8(itr
->second
.misc
);
5157 data
<< uint8(itr
->second
.type
);
5165 GetSession()->SendPacket( &data
);
5166 sLog
.outDetail( "Action Buttons for '%u' Initialized", GetGUIDLow() );
5169 void Player::addActionButton(const uint8 button
, const uint16 action
, const uint8 type
, const uint8 misc
)
5171 if(button
>= MAX_ACTION_BUTTONS
)
5173 sLog
.outError( "Action %u not added into button %u for player %s: button must be < 132", action
, button
, GetName() );
5177 // check cheating with adding non-known spells to action bar
5178 if(type
==ACTION_BUTTON_SPELL
)
5180 if(!sSpellStore
.LookupEntry(action
))
5182 sLog
.outError( "Action %u not added into button %u for player %s: spell not exist", action
, button
, GetName() );
5186 if(!HasSpell(action
))
5188 sLog
.outError( "Action %u not added into button %u for player %s: player don't known this spell", action
, button
, GetName() );
5193 ActionButtonList::iterator buttonItr
= m_actionButtons
.find(button
);
5195 if (buttonItr
==m_actionButtons
.end())
5196 { // just add new button
5197 m_actionButtons
[button
] = ActionButton(action
,type
,misc
);
5200 { // change state of current button
5201 ActionButtonUpdateState uState
= buttonItr
->second
.uState
;
5202 buttonItr
->second
= ActionButton(action
,type
,misc
);
5203 if (uState
!= ACTIONBUTTON_NEW
) buttonItr
->second
.uState
= ACTIONBUTTON_CHANGED
;
5206 sLog
.outDetail( "Player '%u' Added Action '%u' to Button '%u'", GetGUIDLow(), action
, button
);
5209 void Player::removeActionButton(uint8 button
)
5211 ActionButtonList::iterator buttonItr
= m_actionButtons
.find(button
);
5212 if (buttonItr
==m_actionButtons
.end())
5215 if(buttonItr
->second
.uState
==ACTIONBUTTON_NEW
)
5216 m_actionButtons
.erase(buttonItr
); // new and not saved
5218 buttonItr
->second
.uState
= ACTIONBUTTON_DELETED
; // saved, will deleted at next save
5220 sLog
.outDetail( "Action Button '%u' Removed from Player '%u'", button
, GetGUIDLow() );
5223 void Player::SetDontMove(bool dontMove
)
5225 m_dontMove
= dontMove
;
5228 bool Player::SetPosition(float x
, float y
, float z
, float orientation
, bool teleport
)
5230 // prevent crash when a bad coord is sent by the client
5231 if(!MaNGOS::IsValidMapCoord(x
,y
,z
,orientation
))
5233 sLog
.outDebug("Player::SetPosition(%f, %f, %f, %f, %d) .. bad coordinates for player %d!",x
,y
,z
,orientation
,teleport
,GetGUIDLow());
5239 const float old_x
= GetPositionX();
5240 const float old_y
= GetPositionY();
5241 const float old_z
= GetPositionZ();
5242 const float old_r
= GetOrientation();
5244 if( teleport
|| old_x
!= x
|| old_y
!= y
|| old_z
!= z
|| old_r
!= orientation
)
5246 if (teleport
|| old_x
!= x
|| old_y
!= y
|| old_z
!= z
)
5247 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOVE
| AURA_INTERRUPT_FLAG_TURNING
);
5249 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_TURNING
);
5251 // move and update visible state if need
5252 m
->PlayerRelocation(this, x
, y
, z
, orientation
);
5254 // reread after Map::Relocation
5261 if(GetGroup() && (old_x
!= x
|| old_y
!= y
))
5262 SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POSITION
);
5265 // code block for underwater state update
5266 UpdateUnderwaterState(m
, x
, y
, z
);
5268 CheckExploreSystem();
5273 void Player::SaveRecallPosition()
5275 m_recallMap
= GetMapId();
5276 m_recallX
= GetPositionX();
5277 m_recallY
= GetPositionY();
5278 m_recallZ
= GetPositionZ();
5279 m_recallO
= GetOrientation();
5282 void Player::SendMessageToSet(WorldPacket
*data
, bool self
)
5284 GetMap()->MessageBroadcast(this, data
, self
);
5287 void Player::SendMessageToSetInRange(WorldPacket
*data
, float dist
, bool self
)
5289 GetMap()->MessageDistBroadcast(this, data
, dist
, self
);
5292 void Player::SendMessageToSetInRange(WorldPacket
*data
, float dist
, bool self
, bool own_team_only
)
5294 GetMap()->MessageDistBroadcast(this, data
, dist
, self
,own_team_only
);
5297 void Player::SendDirectMessage(WorldPacket
*data
)
5299 GetSession()->SendPacket(data
);
5302 void Player::CheckExploreSystem()
5310 uint16 areaFlag
=MapManager::Instance().GetBaseMap(GetMapId())->GetAreaFlag(GetPositionX(),GetPositionY(),GetPositionZ());
5311 if(areaFlag
==0xffff)
5313 int offset
= areaFlag
/ 32;
5317 sLog
.outError("ERROR: Wrong area flag %u in map data for (X: %f Y: %f) point to field PLAYER_EXPLORED_ZONES_1 + %u ( %u must be < 64 ).",areaFlag
,GetPositionX(),GetPositionY(),offset
,offset
);
5321 uint32 val
= (uint32
)(1 << (areaFlag
% 32));
5322 uint32 currFields
= GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
5324 if( !(currFields
& val
) )
5326 SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
5328 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EXPLORE_AREA
);
5330 AreaTableEntry
const *p
= GetAreaEntryByAreaFlagAndMap(areaFlag
,GetMapId());
5333 sLog
.outError("PLAYER: Player %u discovered unknown area (x: %f y: %f map: %u", GetGUIDLow(), GetPositionX(),GetPositionY(),GetMapId());
5335 else if(p
->area_level
> 0)
5337 uint32 area
= p
->ID
;
5338 if (getLevel() >= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
5340 SendExplorationExperience(area
,0);
5344 int32 diff
= int32(getLevel()) - p
->area_level
;
5348 XP
= uint32(objmgr
.GetBaseXP(getLevel()+5)*sWorld
.getRate(RATE_XP_EXPLORE
));
5352 int32 exploration_percent
= (100-((diff
-5)*5));
5353 if (exploration_percent
> 100)
5354 exploration_percent
= 100;
5355 else if (exploration_percent
< 0)
5356 exploration_percent
= 0;
5358 XP
= uint32(objmgr
.GetBaseXP(p
->area_level
)*exploration_percent
/100*sWorld
.getRate(RATE_XP_EXPLORE
));
5362 XP
= uint32(objmgr
.GetBaseXP(p
->area_level
)*sWorld
.getRate(RATE_XP_EXPLORE
));
5366 SendExplorationExperience(area
,XP
);
5368 sLog
.outDetail("PLAYER: Player %u discovered a new area: %u", GetGUIDLow(), area
);
5373 uint32
Player::TeamForRace(uint8 race
)
5375 ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(race
);
5378 sLog
.outError("Race %u not found in DBC: wrong DBC files?",uint32(race
));
5382 switch(rEntry
->TeamID
)
5384 case 7: return ALLIANCE
;
5385 case 1: return HORDE
;
5388 sLog
.outError("Race %u have wrong team id in DBC: wrong DBC files?",uint32(race
),rEntry
->TeamID
);
5392 uint32
Player::getFactionForRace(uint8 race
)
5394 ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(race
);
5397 sLog
.outError("Race %u not found in DBC: wrong DBC files?",uint32(race
));
5401 return rEntry
->FactionID
;
5404 void Player::setFactionForRace(uint8 race
)
5406 m_team
= TeamForRace(race
);
5407 setFaction( getFactionForRace(race
) );
5410 void Player::UpdateReputation() const
5412 sLog
.outDetail( "WORLD: Player::UpdateReputation" );
5414 for(FactionStateList::const_iterator itr
= m_factions
.begin(); itr
!= m_factions
.end(); ++itr
)
5416 SendFactionState(&(itr
->second
));
5420 void Player::SendFactionState(FactionState
const* faction
) const
5422 if(faction
->Flags
& FACTION_FLAG_VISIBLE
) //If faction is visible then update it
5424 WorldPacket
data(SMSG_SET_FACTION_STANDING
, (16)); // last check 2.4.0
5425 data
<< (float) 0; // unk 2.4.0
5426 data
<< (uint8
) 0; // wotlk 8634
5427 data
<< (uint32
) 1; // count
5429 data
<< (uint32
) faction
->ReputationListID
;
5430 data
<< (uint32
) faction
->Standing
;
5432 GetSession()->SendPacket(&data
);
5436 void Player::SendInitialReputations()
5438 WorldPacket
data(SMSG_INITIALIZE_FACTIONS
, (4+128*5));
5439 data
<< uint32 (0x00000080);
5443 for (FactionStateList::const_iterator itr
= m_factions
.begin(); itr
!= m_factions
.end(); ++itr
)
5445 // fill in absent fields
5446 for (; a
!= itr
->first
; a
++)
5448 data
<< uint8 (0x00);
5449 data
<< uint32 (0x00000000);
5452 // fill in encountered data
5453 data
<< uint8 (itr
->second
.Flags
);
5454 data
<< uint32 (itr
->second
.Standing
);
5459 // fill in absent fields
5460 for (; a
!= 128; a
++)
5462 data
<< uint8 (0x00);
5463 data
<< uint32 (0x00000000);
5466 GetSession()->SendPacket(&data
);
5469 FactionState
const* Player::GetFactionState( FactionEntry
const* factionEntry
) const
5471 FactionStateList::const_iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5472 if (itr
!= m_factions
.end())
5473 return &itr
->second
;
5478 void Player::SetFactionAtWar(FactionState
* faction
, bool atWar
)
5480 // not allow declare war to own faction
5481 if(atWar
&& (faction
->Flags
& FACTION_FLAG_PEACE_FORCED
) )
5485 if(((faction
->Flags
& FACTION_FLAG_AT_WAR
) != 0) == atWar
)
5489 faction
->Flags
|= FACTION_FLAG_AT_WAR
;
5491 faction
->Flags
&= ~FACTION_FLAG_AT_WAR
;
5493 faction
->Changed
= true;
5496 void Player::SetFactionInactive(FactionState
* faction
, bool inactive
)
5498 // always invisible or hidden faction can't be inactive
5499 if(inactive
&& ((faction
->Flags
& (FACTION_FLAG_INVISIBLE_FORCED
|FACTION_FLAG_HIDDEN
)) || !(faction
->Flags
& FACTION_FLAG_VISIBLE
) ) )
5503 if(((faction
->Flags
& FACTION_FLAG_INACTIVE
) != 0) == inactive
)
5507 faction
->Flags
|= FACTION_FLAG_INACTIVE
;
5509 faction
->Flags
&= ~FACTION_FLAG_INACTIVE
;
5511 faction
->Changed
= true;
5514 void Player::SetFactionVisibleForFactionTemplateId(uint32 FactionTemplateId
)
5516 FactionTemplateEntry
const*factionTemplateEntry
= sFactionTemplateStore
.LookupEntry(FactionTemplateId
);
5518 if(!factionTemplateEntry
)
5521 SetFactionVisibleForFactionId(factionTemplateEntry
->faction
);
5524 void Player::SetFactionVisibleForFactionId(uint32 FactionId
)
5526 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(FactionId
);
5530 if(factionEntry
->reputationListID
< 0)
5533 FactionStateList::iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5534 if (itr
== m_factions
.end())
5537 SetFactionVisible(&itr
->second
);
5540 void Player::SetFactionVisible(FactionState
* faction
)
5542 // always invisible or hidden faction can't be make visible
5543 if(faction
->Flags
& (FACTION_FLAG_INVISIBLE_FORCED
|FACTION_FLAG_HIDDEN
))
5547 if(faction
->Flags
& FACTION_FLAG_VISIBLE
)
5550 faction
->Flags
|= FACTION_FLAG_VISIBLE
;
5551 faction
->Changed
= true;
5553 if(!m_session
->PlayerLoading())
5555 // make faction visible in reputation list at client
5556 WorldPacket
data(SMSG_SET_FACTION_VISIBLE
, 4);
5557 data
<< faction
->ReputationListID
;
5558 GetSession()->SendPacket(&data
);
5562 void Player::SetInitialFactions()
5564 for(unsigned int i
= 1; i
< sFactionStore
.GetNumRows(); i
++)
5566 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(i
);
5568 if( factionEntry
&& (factionEntry
->reputationListID
>= 0))
5570 FactionState newFaction
;
5571 newFaction
.ID
= factionEntry
->ID
;
5572 newFaction
.ReputationListID
= factionEntry
->reputationListID
;
5573 newFaction
.Standing
= 0;
5574 newFaction
.Flags
= GetDefaultReputationFlags(factionEntry
);
5575 newFaction
.Changed
= true;
5577 m_factions
[newFaction
.ReputationListID
] = newFaction
;
5582 uint32
Player::GetDefaultReputationFlags(const FactionEntry
*factionEntry
) const
5587 uint32 raceMask
= getRaceMask();
5588 uint32 classMask
= getClassMask();
5589 for (int i
=0; i
< 4; i
++)
5591 if( (factionEntry
->BaseRepRaceMask
[i
] & raceMask
) &&
5592 (factionEntry
->BaseRepClassMask
[i
]==0 ||
5593 (factionEntry
->BaseRepClassMask
[i
] & classMask
) ) )
5594 return factionEntry
->ReputationFlags
[i
];
5599 int32
Player::GetBaseReputation(const FactionEntry
*factionEntry
) const
5604 uint32 raceMask
= getRaceMask();
5605 uint32 classMask
= getClassMask();
5606 for (int i
=0; i
< 4; i
++)
5608 if( (factionEntry
->BaseRepRaceMask
[i
] & raceMask
) &&
5609 (factionEntry
->BaseRepClassMask
[i
]==0 ||
5610 (factionEntry
->BaseRepClassMask
[i
] & classMask
) ) )
5611 return factionEntry
->BaseRepValue
[i
];
5614 // in faction.dbc exist factions with (RepListId >=0, listed in character reputation list) with all BaseRepRaceMask[i]==0
5618 int32
Player::GetReputation(uint32 faction_id
) const
5620 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(faction_id
);
5624 sLog
.outError("Player::GetReputation: Can't get reputation of %s for unknown faction (faction template id) #%u.",GetName(), faction_id
);
5628 return GetReputation(factionEntry
);
5631 int32
Player::GetReputation(const FactionEntry
*factionEntry
) const
5633 // Faction without recorded reputation. Just ignore.
5637 FactionStateList::const_iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5638 if (itr
!= m_factions
.end())
5639 return GetBaseReputation(factionEntry
) + itr
->second
.Standing
;
5644 ReputationRank
Player::GetReputationRank(uint32 faction
) const
5646 FactionEntry
const*factionEntry
= sFactionStore
.LookupEntry(faction
);
5648 return MIN_REPUTATION_RANK
;
5650 return GetReputationRank(factionEntry
);
5653 ReputationRank
Player::ReputationToRank(int32 standing
) const
5655 int32 Limit
= Reputation_Cap
+ 1;
5656 for (int i
= MAX_REPUTATION_RANK
-1; i
>= MIN_REPUTATION_RANK
; --i
)
5658 Limit
-= ReputationRank_Length
[i
];
5659 if (standing
>= Limit
)
5660 return ReputationRank(i
);
5662 return MIN_REPUTATION_RANK
;
5665 ReputationRank
Player::GetReputationRank(const FactionEntry
*factionEntry
) const
5667 int32 Reputation
= GetReputation(factionEntry
);
5668 return ReputationToRank(Reputation
);
5671 ReputationRank
Player::GetBaseReputationRank(const FactionEntry
*factionEntry
) const
5673 int32 Reputation
= GetBaseReputation(factionEntry
);
5674 return ReputationToRank(Reputation
);
5677 bool Player::ModifyFactionReputation(uint32 FactionTemplateId
, int32 DeltaReputation
)
5679 FactionTemplateEntry
const* factionTemplateEntry
= sFactionTemplateStore
.LookupEntry(FactionTemplateId
);
5681 if(!factionTemplateEntry
)
5683 sLog
.outError("Player::ModifyFactionReputation: Can't update reputation of %s for unknown faction (faction template id) #%u.", GetName(), FactionTemplateId
);
5687 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(factionTemplateEntry
->faction
);
5689 // Faction without recorded reputation. Just ignore.
5693 return ModifyFactionReputation(factionEntry
, DeltaReputation
);
5696 bool Player::ModifyFactionReputation(FactionEntry
const* factionEntry
, int32 standing
)
5698 SimpleFactionsList
const* flist
= GetFactionTeamList(factionEntry
->ID
);
5702 for (SimpleFactionsList::const_iterator itr
= flist
->begin();itr
!= flist
->end();++itr
)
5704 FactionEntry
const *factionEntryCalc
= sFactionStore
.LookupEntry(*itr
);
5705 if(factionEntryCalc
)
5706 res
= ModifyOneFactionReputation(factionEntryCalc
, standing
);
5711 return ModifyOneFactionReputation(factionEntry
, standing
);
5714 bool Player::ModifyOneFactionReputation(FactionEntry
const* factionEntry
, int32 standing
)
5716 FactionStateList::iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5717 if (itr
!= m_factions
.end())
5719 int32 BaseRep
= GetBaseReputation(factionEntry
);
5720 int32 new_rep
= BaseRep
+ itr
->second
.Standing
+ standing
;
5722 if (new_rep
> Reputation_Cap
)
5723 new_rep
= Reputation_Cap
;
5725 if (new_rep
< Reputation_Bottom
)
5726 new_rep
= Reputation_Bottom
;
5728 if(ReputationToRank(new_rep
) <= REP_HOSTILE
)
5729 SetFactionAtWar(&itr
->second
,true);
5731 itr
->second
.Standing
= new_rep
- BaseRep
;
5732 itr
->second
.Changed
= true;
5734 SetFactionVisible(&itr
->second
);
5736 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
5738 if(uint32 questid
= GetQuestSlotQuestId(i
))
5740 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
5741 if( qInfo
&& qInfo
->GetRepObjectiveFaction() == factionEntry
->ID
)
5743 QuestStatusData
& q_status
= mQuestStatus
[questid
];
5744 if( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
5746 if(GetReputation(factionEntry
) >= qInfo
->GetRepObjectiveValue())
5747 if ( CanCompleteQuest( questid
) )
5748 CompleteQuest( questid
);
5750 else if( q_status
.m_status
== QUEST_STATUS_COMPLETE
)
5752 if(GetReputation(factionEntry
) < qInfo
->GetRepObjectiveValue())
5753 IncompleteQuest( questid
);
5758 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION
);
5759 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION
);
5760 SendFactionState(&(itr
->second
));
5767 bool Player::SetFactionReputation(uint32 FactionTemplateId
, int32 standing
)
5769 FactionTemplateEntry
const* factionTemplateEntry
= sFactionTemplateStore
.LookupEntry(FactionTemplateId
);
5771 if(!factionTemplateEntry
)
5773 sLog
.outError("Player::SetFactionReputation: Can't set reputation of %s for unknown faction (faction template id) #%u.", GetName(), FactionTemplateId
);
5777 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(factionTemplateEntry
->faction
);
5779 // Faction without recorded reputation. Just ignore.
5783 return SetFactionReputation(factionEntry
, standing
);
5786 bool Player::SetFactionReputation(FactionEntry
const* factionEntry
, int32 standing
)
5788 SimpleFactionsList
const* flist
= GetFactionTeamList(factionEntry
->ID
);
5792 for (SimpleFactionsList::const_iterator itr
= flist
->begin();itr
!= flist
->end();++itr
)
5794 FactionEntry
const *factionEntryCalc
= sFactionStore
.LookupEntry(*itr
);
5795 if(factionEntryCalc
)
5796 res
= SetOneFactionReputation(factionEntryCalc
, standing
);
5801 return SetOneFactionReputation(factionEntry
, standing
);
5804 bool Player::SetOneFactionReputation(FactionEntry
const* factionEntry
, int32 standing
)
5806 FactionStateList::iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5807 if (itr
!= m_factions
.end())
5809 if (standing
> Reputation_Cap
)
5810 standing
= Reputation_Cap
;
5812 if (standing
< Reputation_Bottom
)
5813 standing
= Reputation_Bottom
;
5815 int32 BaseRep
= GetBaseReputation(factionEntry
);
5816 itr
->second
.Standing
= standing
- BaseRep
;
5817 itr
->second
.Changed
= true;
5819 SetFactionVisible(&itr
->second
);
5821 if(ReputationToRank(standing
) <= REP_HOSTILE
)
5822 SetFactionAtWar(&itr
->second
,true);
5824 SendFactionState(&(itr
->second
));
5825 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION
);
5826 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION
);
5832 //Calculate total reputation percent player gain with quest/creature level
5833 int32
Player::CalculateReputationGain(uint32 creatureOrQuestLevel
, int32 rep
, bool for_quest
)
5835 // for grey creature kill received 20%, in other case 100.
5836 int32 percent
= (!for_quest
&& (creatureOrQuestLevel
<= MaNGOS::XP::GetGrayLevel(getLevel()))) ? 20 : 100;
5838 int32 repMod
= GetTotalAuraModifier(SPELL_AURA_MOD_REPUTATION_GAIN
);
5840 percent
+= rep
> 0 ? repMod
: -repMod
;
5845 return int32(sWorld
.getRate(RATE_REPUTATION_GAIN
)*rep
*percent
/100);
5848 //Calculates how many reputation points player gains in victim's enemy factions
5849 void Player::RewardReputation(Unit
*pVictim
, float rate
)
5851 if(!pVictim
|| pVictim
->GetTypeId() == TYPEID_PLAYER
)
5854 ReputationOnKillEntry
const* Rep
= objmgr
.GetReputationOnKilEntry(((Creature
*)pVictim
)->GetCreatureInfo()->Entry
);
5859 if(Rep
->repfaction1
&& (!Rep
->team_dependent
|| GetTeam()==ALLIANCE
))
5861 int32 donerep1
= CalculateReputationGain(pVictim
->getLevel(),Rep
->repvalue1
,false);
5862 donerep1
= int32(donerep1
*rate
);
5863 FactionEntry
const *factionEntry1
= sFactionStore
.LookupEntry(Rep
->repfaction1
);
5864 uint32 current_reputation_rank1
= GetReputationRank(factionEntry1
);
5865 if(factionEntry1
&& current_reputation_rank1
<= Rep
->reputation_max_cap1
)
5866 ModifyFactionReputation(factionEntry1
, donerep1
);
5868 // Wiki: Team factions value divided by 2
5869 if(Rep
->is_teamaward1
)
5871 FactionEntry
const *team1_factionEntry
= sFactionStore
.LookupEntry(factionEntry1
->team
);
5872 if(team1_factionEntry
)
5873 ModifyFactionReputation(team1_factionEntry
, donerep1
/ 2);
5877 if(Rep
->repfaction2
&& (!Rep
->team_dependent
|| GetTeam()==HORDE
))
5879 int32 donerep2
= CalculateReputationGain(pVictim
->getLevel(),Rep
->repvalue2
,false);
5880 donerep2
= int32(donerep2
*rate
);
5881 FactionEntry
const *factionEntry2
= sFactionStore
.LookupEntry(Rep
->repfaction2
);
5882 uint32 current_reputation_rank2
= GetReputationRank(factionEntry2
);
5883 if(factionEntry2
&& current_reputation_rank2
<= Rep
->reputation_max_cap2
)
5884 ModifyFactionReputation(factionEntry2
, donerep2
);
5886 // Wiki: Team factions value divided by 2
5887 if(Rep
->is_teamaward2
)
5889 FactionEntry
const *team2_factionEntry
= sFactionStore
.LookupEntry(factionEntry2
->team
);
5890 if(team2_factionEntry
)
5891 ModifyFactionReputation(team2_factionEntry
, donerep2
/ 2);
5896 //Calculate how many reputation points player gain with the quest
5897 void Player::RewardReputation(Quest
const *pQuest
)
5899 // quest reputation reward/loss
5900 for(int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
)
5902 if(pQuest
->RewRepFaction
[i
] && pQuest
->RewRepValue
[i
] )
5904 int32 rep
= CalculateReputationGain(pQuest
->GetQuestLevel(),pQuest
->RewRepValue
[i
],true);
5905 FactionEntry
const* factionEntry
= sFactionStore
.LookupEntry(pQuest
->RewRepFaction
[i
]);
5907 ModifyFactionReputation(factionEntry
, rep
);
5911 // TODO: implement reputation spillover
5914 void Player::UpdateArenaFields(void)
5916 /* arena calcs go here */
5919 void Player::UpdateHonorFields()
5921 /// called when rewarding honor and at each save
5922 uint64 now
= time(NULL
);
5923 uint64 today
= uint64(time(NULL
) / DAY
) * DAY
;
5925 if(m_lastHonorUpdateTime
< today
)
5927 uint64 yesterday
= today
- DAY
;
5929 uint16 kills_today
= PAIR32_LOPART(GetUInt32Value(PLAYER_FIELD_KILLS
));
5931 // update yesterday's contribution
5932 if(m_lastHonorUpdateTime
>= yesterday
)
5934 SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
));
5936 // this is the first update today, reset today's contribution
5937 SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
5938 SetUInt32Value(PLAYER_FIELD_KILLS
, MAKE_PAIR32(0,kills_today
));
5942 // no honor/kills yesterday or today, reset
5943 SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
5944 SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
5948 m_lastHonorUpdateTime
= now
;
5951 ///Calculate the amount of honor gained based on the victim
5952 ///and the size of the group for which the honor is divided
5953 ///An exact honor value can also be given (overriding the calcs)
5954 bool Player::RewardHonor(Unit
*uVictim
, uint32 groupsize
, float honor
)
5956 // do not reward honor in arenas, but enable onkill spellproc
5959 if(!uVictim
|| uVictim
== this || uVictim
->GetTypeId() != TYPEID_PLAYER
)
5962 if( GetBGTeam() == ((Player
*)uVictim
)->GetBGTeam() )
5968 // 'Inactive' this aura prevents the player from gaining honor points and battleground tokens
5969 if(GetDummyAura(SPELL_AURA_PLAYER_INACTIVE
))
5972 uint64 victim_guid
= 0;
5973 uint32 victim_rank
= 0;
5975 // need call before fields update to have chance move yesterday data to appropriate fields before today data change.
5976 UpdateHonorFields();
5980 if(!uVictim
|| uVictim
== this || uVictim
->HasAuraType(SPELL_AURA_NO_PVP_CREDIT
))
5983 victim_guid
= uVictim
->GetGUID();
5985 if( uVictim
->GetTypeId() == TYPEID_PLAYER
)
5987 Player
*pVictim
= (Player
*)uVictim
;
5989 if( GetTeam() == pVictim
->GetTeam() && !sWorld
.IsFFAPvPRealm() )
5992 float f
= 1; //need for total kills (?? need more info)
5994 uint32 k_level
= getLevel();
5995 uint32 v_level
= pVictim
->getLevel();
5998 // PLAYER_CHOSEN_TITLE VALUES DESCRIPTION
6000 // [1..14] Alliance honor titles and player name
6001 // [15..28] Horde honor titles and player name
6002 // [29..38] Other title and player name
6004 uint32 victim_title
= pVictim
->GetUInt32Value(PLAYER_CHOSEN_TITLE
);
6005 // Get Killer titles, CharTitlesEntry::bit_index
6007 // title[1..14] -> rank[5..18]
6008 // title[15..28] -> rank[5..18]
6009 // title[other] -> 0
6010 if (victim_title
== 0)
6011 victim_guid
= 0; // Don't show HK: <rank> message, only log.
6012 else if (victim_title
< 15)
6013 victim_rank
= victim_title
+ 4;
6014 else if (victim_title
< 29)
6015 victim_rank
= victim_title
- 14 + 4;
6017 victim_guid
= 0; // Don't show HK: <rank> message, only log.
6020 k_grey
= MaNGOS::XP::GetGrayLevel(k_level
);
6025 float diff_level
= (k_level
== k_grey
) ? 1 : ((float(v_level
) - float(k_grey
)) / (float(k_level
) - float(k_grey
)));
6027 int32 v_rank
=1; //need more info
6029 honor
= ((f
* diff_level
* (190 + v_rank
*10))/6);
6030 honor
*= ((float)k_level
) / 70.0f
; //factor of dependence on levels of the killer
6032 // count the number of playerkills in one day
6033 ApplyModUInt32Value(PLAYER_FIELD_KILLS
, 1, true);
6034 // and those in a lifetime
6035 ApplyModUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 1, true);
6039 Creature
*cVictim
= (Creature
*)uVictim
;
6041 if (!cVictim
->isRacialLeader())
6044 honor
= 100; // ??? need more info
6045 victim_rank
= 19; // HK: Leader
6049 if (uVictim
!= NULL
)
6051 honor
*= sWorld
.getRate(RATE_HONOR
);
6056 honor
*= (((float)urand(8,12))/10); // approx honor: 80% - 120% of real honor
6059 // honor - for show honor points in log
6060 // victim_guid - for show victim name in log
6061 // victim_rank [1..4] HK: <dishonored rank>
6062 // victim_rank [5..19] HK: <alliance\horde rank>
6063 // victim_rank [0,20+] HK: <>
6064 WorldPacket
data(SMSG_PVP_CREDIT
,4+8+4);
6065 data
<< (uint32
) honor
;
6066 data
<< (uint64
) victim_guid
;
6067 data
<< (uint32
) victim_rank
;
6069 GetSession()->SendPacket(&data
);
6072 ModifyHonorPoints(int32(honor
));
6074 ApplyModUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, uint32(honor
), true);
6078 void Player::ModifyHonorPoints( int32 value
)
6082 if (GetHonorPoints() > sWorld
.getConfig(CONFIG_MAX_HONOR_POINTS
))
6083 SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, sWorld
.getConfig(CONFIG_MAX_HONOR_POINTS
) + value
);
6085 SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, GetHonorPoints() > uint32(-value
) ? GetHonorPoints() + value
: 0);
6088 SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, GetHonorPoints() < sWorld
.getConfig(CONFIG_MAX_HONOR_POINTS
) - value
? GetHonorPoints() + value
: sWorld
.getConfig(CONFIG_MAX_HONOR_POINTS
));
6091 void Player::ModifyArenaPoints( int32 value
)
6095 if (GetArenaPoints() > sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
))
6096 SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY
, sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
) + value
);
6098 SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY
, GetArenaPoints() > uint32(-value
) ? GetArenaPoints() + value
: 0);
6101 SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY
, GetArenaPoints() < sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
) - value
? GetArenaPoints() + value
: sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
));
6104 uint32
Player::GetGuildIdFromDB(uint64 guid
)
6106 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT guildid FROM guild_member WHERE guid='%u'", GUID_LOPART(guid
));
6110 uint32 id
= result
->Fetch()[0].GetUInt32();
6115 uint32
Player::GetRankFromDB(uint64 guid
)
6117 QueryResult
*result
= CharacterDatabase
.PQuery( "SELECT rank FROM guild_member WHERE guid='%u'", GUID_LOPART(guid
) );
6120 uint32 v
= result
->Fetch()[0].GetUInt32();
6128 uint32
Player::GetArenaTeamIdFromDB(uint64 guid
, uint8 type
)
6130 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u' AND type='%u' LIMIT 1", GUID_LOPART(guid
), type
);
6134 uint32 id
= (*result
)[0].GetUInt32();
6139 uint32
Player::GetZoneIdFromDB(uint64 guid
)
6141 uint32 guidLow
= GUID_LOPART(guid
);
6142 QueryResult
*result
= CharacterDatabase
.PQuery( "SELECT zone FROM characters WHERE guid='%u'", guidLow
);
6145 Field
* fields
= result
->Fetch();
6146 uint32 zone
= fields
[0].GetUInt32();
6151 // stored zone is zero, use generic and slow zone detection
6152 result
= CharacterDatabase
.PQuery("SELECT map,position_x,position_y,position_z FROM characters WHERE guid='%u'", guidLow
);
6155 fields
= result
->Fetch();
6156 uint32 map
= fields
[0].GetUInt32();
6157 float posx
= fields
[1].GetFloat();
6158 float posy
= fields
[2].GetFloat();
6159 float posz
= fields
[3].GetFloat();
6162 zone
= MapManager::Instance().GetZoneId(map
,posx
,posy
,posz
);
6164 CharacterDatabase
.PExecute("UPDATE characters SET zone='%u' WHERE guid='%u'", zone
, guidLow
);
6170 void Player::UpdateArea(uint32 newArea
)
6172 // FFA_PVP flags are area and not zone id dependent
6173 // so apply them accordingly
6174 m_areaUpdateId
= newArea
;
6176 AreaTableEntry
const* area
= GetAreaEntryByAreaID(newArea
);
6178 if(area
&& (area
->flags
& AREA_FLAG_ARENA
))
6181 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
6185 // remove ffa flag only if not ffapvp realm
6186 // removal in sanctuaries and capitals is handled in zone update
6187 if(HasByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
) && !sWorld
.IsFFAPvPRealm())
6188 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
6191 UpdateAreaDependentAuras(newArea
);
6194 void Player::UpdateZone(uint32 newZone
)
6196 m_zoneUpdateId
= newZone
;
6197 m_zoneUpdateTimer
= ZONE_UPDATE_INTERVAL
;
6199 // zone changed, so area changed as well, update it
6200 UpdateArea(GetAreaId());
6202 AreaTableEntry
const* zone
= GetAreaEntryByAreaID(newZone
);
6206 if (sWorld
.getConfig(CONFIG_WEATHER
))
6208 Weather
*wth
= sWorld
.FindWeather(zone
->ID
);
6211 wth
->SendWeatherUpdateToPlayer(this);
6215 if(!sWorld
.AddWeather(zone
->ID
))
6217 // send fine weather packet to remove old zone's weather
6218 Weather::SendFineWeatherUpdateToPlayer(this);
6223 pvpInfo
.inHostileArea
=
6224 GetTeam() == ALLIANCE
&& zone
->team
== AREATEAM_HORDE
||
6225 GetTeam() == HORDE
&& zone
->team
== AREATEAM_ALLY
||
6226 sWorld
.IsPvPRealm() && zone
->team
== AREATEAM_NONE
||
6227 InBattleGround(); // overwrite for battlegrounds, maybe batter some zone flags but current known not 100% fit to this
6229 if(pvpInfo
.inHostileArea
) // in hostile area
6231 if(!IsPvP() || pvpInfo
.endTimer
!= 0)
6232 UpdatePvP(true, true);
6234 else // in friendly area
6236 if(IsPvP() && !HasFlag(PLAYER_FLAGS
,PLAYER_FLAGS_IN_PVP
) && pvpInfo
.endTimer
== 0)
6237 pvpInfo
.endTimer
= time(0); // start toggle-off
6240 if(zone
->flags
& AREA_FLAG_SANCTUARY
) // in sanctuary
6242 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
);
6243 if(sWorld
.IsFFAPvPRealm())
6244 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
6248 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_SANCTUARY
);
6251 if(zone
->flags
& AREA_FLAG_CAPITAL
) // in capital city
6253 SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
);
6254 SetRestType(REST_TYPE_IN_CITY
);
6255 InnEnter(time(0),GetMapId(),0,0,0);
6257 if(sWorld
.IsFFAPvPRealm())
6258 RemoveByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
6260 else // anywhere else
6262 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
)) // but resting (walk from city or maybe in tavern or leave tavern recently)
6264 if(GetRestType()==REST_TYPE_IN_TAVERN
) // has been in tavern. Is still in?
6266 if(GetMapId()!=GetInnPosMapId() || sqrt((GetPositionX()-GetInnPosX())*(GetPositionX()-GetInnPosX())+(GetPositionY()-GetInnPosY())*(GetPositionY()-GetInnPosY())+(GetPositionZ()-GetInnPosZ())*(GetPositionZ()-GetInnPosZ()))>40)
6268 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
);
6269 SetRestType(REST_TYPE_NO
);
6271 if(sWorld
.IsFFAPvPRealm())
6272 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
6275 else // not in tavern (leave city then)
6277 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
);
6278 SetRestType(REST_TYPE_NO
);
6280 // Set player to FFA PVP when not in rested environment.
6281 if(sWorld
.IsFFAPvPRealm())
6282 SetByteFlag(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_FFA_PVP
);
6287 // remove items with area/map limitations (delete only for alive player to allow back in ghost mode)
6288 // if player resurrected at teleport this will be applied in resurrect code
6290 DestroyZoneLimitedItem( true, newZone
);
6292 // recent client version not send leave/join channel packets for built-in local channels
6293 UpdateLocalChannels( newZone
);
6297 SetGroupUpdateFlag(GROUP_UPDATE_FLAG_ZONE
);
6299 UpdateZoneDependentAuras(newZone
);
6302 //If players are too far way of duel flag... then player loose the duel
6303 void Player::CheckDuelDistance(time_t currTime
)
6308 uint64 duelFlagGUID
= GetUInt64Value(PLAYER_DUEL_ARBITER
);
6309 GameObject
* obj
= ObjectAccessor::GetGameObject(*this, duelFlagGUID
);
6313 if(duel
->outOfBound
== 0)
6315 if(!IsWithinDistInMap(obj
, 50))
6317 duel
->outOfBound
= currTime
;
6319 WorldPacket
data(SMSG_DUEL_OUTOFBOUNDS
, 0);
6320 GetSession()->SendPacket(&data
);
6325 if(IsWithinDistInMap(obj
, 40))
6327 duel
->outOfBound
= 0;
6329 WorldPacket
data(SMSG_DUEL_INBOUNDS
, 0);
6330 GetSession()->SendPacket(&data
);
6332 else if(currTime
>= (duel
->outOfBound
+10))
6334 DuelComplete(DUEL_FLED
);
6339 void Player::DuelComplete(DuelCompleteType type
)
6341 // duel not requested
6345 WorldPacket
data(SMSG_DUEL_COMPLETE
, (1));
6346 data
<< (uint8
)((type
!= DUEL_INTERUPTED
) ? 1 : 0);
6347 GetSession()->SendPacket(&data
);
6348 duel
->opponent
->GetSession()->SendPacket(&data
);
6350 if(type
!= DUEL_INTERUPTED
)
6352 data
.Initialize(SMSG_DUEL_WINNER
, (1+20)); // we guess size
6353 data
<< (uint8
)((type
==DUEL_WON
) ? 0 : 1); // 0 = just won; 1 = fled
6354 data
<< duel
->opponent
->GetName();
6356 SendMessageToSet(&data
,true);
6359 // cool-down duel spell
6360 /*data.Initialize(SMSG_SPELL_COOLDOWN, 17);
6367 GetSession()->SendPacket(&data);
6368 data.Initialize(SMSG_SPELL_COOLDOWN, 17);
6369 data<<duel->opponent->GetGUID();
6373 duel->opponent->GetSession()->SendPacket(&data);*/
6375 //Remove Duel Flag object
6376 GameObject
* obj
= ObjectAccessor::GetGameObject(*this, GetUInt64Value(PLAYER_DUEL_ARBITER
));
6378 duel
->initiator
->RemoveGameObject(obj
,true);
6381 std::vector
<uint32
> auras2remove
;
6382 AuraMap
const& vAuras
= duel
->opponent
->GetAuras();
6383 for (AuraMap::const_iterator i
= vAuras
.begin(); i
!= vAuras
.end(); ++i
)
6385 if (!i
->second
->IsPositive() && i
->second
->GetCasterGUID() == GetGUID() && i
->second
->GetAuraApplyTime() >= duel
->startTime
)
6386 auras2remove
.push_back(i
->second
->GetId());
6389 for(size_t i
=0; i
<auras2remove
.size(); i
++)
6390 duel
->opponent
->RemoveAurasDueToSpell(auras2remove
[i
]);
6392 auras2remove
.clear();
6393 AuraMap
const& auras
= GetAuras();
6394 for (AuraMap::const_iterator i
= auras
.begin(); i
!= auras
.end(); ++i
)
6396 if (!i
->second
->IsPositive() && i
->second
->GetCasterGUID() == duel
->opponent
->GetGUID() && i
->second
->GetAuraApplyTime() >= duel
->startTime
)
6397 auras2remove
.push_back(i
->second
->GetId());
6399 for(size_t i
=0; i
<auras2remove
.size(); i
++)
6400 RemoveAurasDueToSpell(auras2remove
[i
]);
6402 // cleanup combo points
6403 if(GetComboTarget()==duel
->opponent
->GetGUID())
6405 else if(GetComboTarget()==duel
->opponent
->GetPetGUID())
6408 if(duel
->opponent
->GetComboTarget()==GetGUID())
6409 duel
->opponent
->ClearComboPoints();
6410 else if(duel
->opponent
->GetComboTarget()==GetPetGUID())
6411 duel
->opponent
->ClearComboPoints();
6414 SetUInt64Value(PLAYER_DUEL_ARBITER
, 0);
6415 SetUInt32Value(PLAYER_DUEL_TEAM
, 0);
6416 duel
->opponent
->SetUInt64Value(PLAYER_DUEL_ARBITER
, 0);
6417 duel
->opponent
->SetUInt32Value(PLAYER_DUEL_TEAM
, 0);
6419 delete duel
->opponent
->duel
;
6420 duel
->opponent
->duel
= NULL
;
6425 //---------------------------------------------------------//
6427 void Player::_ApplyItemMods(Item
*item
, uint8 slot
,bool apply
)
6429 if(slot
>= INVENTORY_SLOT_BAG_END
|| !item
)
6432 // not apply/remove mods for broken item
6433 if(item
->IsBroken())
6436 ItemPrototype
const *proto
= item
->GetProto();
6441 sLog
.outDetail("applying mods for item %u ",item
->GetGUIDLow());
6443 uint32 attacktype
= Player::GetAttackBySlot(slot
);
6444 if(attacktype
< MAX_ATTACK
)
6445 _ApplyWeaponDependentAuraMods(item
,WeaponAttackType(attacktype
),apply
);
6447 _ApplyItemBonuses(proto
,slot
,apply
);
6449 if( slot
==EQUIPMENT_SLOT_RANGED
)
6450 _ApplyAmmoBonuses();
6452 ApplyItemEquipSpell(item
,apply
);
6453 ApplyEnchantment(item
, apply
);
6455 if(proto
->Socket
[0].Color
) //only (un)equipping of items with sockets can influence metagems, so no need to waste time with normal items
6456 CorrectMetaGemEnchants(slot
, apply
);
6458 sLog
.outDebug("_ApplyItemMods complete.");
6461 void Player::_ApplyItemBonuses(ItemPrototype
const *proto
, uint8 slot
, bool apply
)
6463 if(slot
>= INVENTORY_SLOT_BAG_END
|| !proto
)
6466 for (int i
= 0; i
< 10; i
++)
6468 uint32 statType
= 0;
6471 if(proto
->ScalingStatDistribution
)
6473 if(ScalingStatDistributionEntry
const *ssd
= sScalingStatDistributionStore
.LookupEntry(proto
->ScalingStatDistribution
))
6475 statType
= ssd
->StatMod
[i
];
6477 if(uint32 modifier
= ssd
->Modifier
[i
])
6479 uint32 level
= ((getLevel() > ssd
->MaxLevel
) ? ssd
->MaxLevel
: getLevel());
6480 if(ScalingStatValuesEntry
const *ssv
= sScalingStatValuesStore
.LookupEntry(level
))
6482 int multiplier
= ssv
->Multiplier
[proto
->GetScalingStatValuesColumn()];
6483 val
= (multiplier
* modifier
) / 10000;
6490 statType
= proto
->ItemStat
[i
].ItemStatType
;
6491 val
= float(proto
->ItemStat
[i
].ItemStatValue
);
6500 HandleStatModifier(UNIT_MOD_MANA
, BASE_VALUE
, float(val
), apply
);
6502 case ITEM_MOD_HEALTH
: // modify HP
6503 HandleStatModifier(UNIT_MOD_HEALTH
, BASE_VALUE
, float(val
), apply
);
6505 case ITEM_MOD_AGILITY
: // modify agility
6506 HandleStatModifier(UNIT_MOD_STAT_AGILITY
, BASE_VALUE
, float(val
), apply
);
6507 ApplyStatBuffMod(STAT_AGILITY
, float(val
), apply
);
6509 case ITEM_MOD_STRENGTH
: //modify strength
6510 HandleStatModifier(UNIT_MOD_STAT_STRENGTH
, BASE_VALUE
, float(val
), apply
);
6511 ApplyStatBuffMod(STAT_STRENGTH
, float(val
), apply
);
6513 case ITEM_MOD_INTELLECT
: //modify intellect
6514 HandleStatModifier(UNIT_MOD_STAT_INTELLECT
, BASE_VALUE
, float(val
), apply
);
6515 ApplyStatBuffMod(STAT_INTELLECT
, float(val
), apply
);
6517 case ITEM_MOD_SPIRIT
: //modify spirit
6518 HandleStatModifier(UNIT_MOD_STAT_SPIRIT
, BASE_VALUE
, float(val
), apply
);
6519 ApplyStatBuffMod(STAT_SPIRIT
, float(val
), apply
);
6521 case ITEM_MOD_STAMINA
: //modify stamina
6522 HandleStatModifier(UNIT_MOD_STAT_STAMINA
, BASE_VALUE
, float(val
), apply
);
6523 ApplyStatBuffMod(STAT_STAMINA
, float(val
), apply
);
6525 case ITEM_MOD_DEFENSE_SKILL_RATING
:
6526 ApplyRatingMod(CR_DEFENSE_SKILL
, int32(val
), apply
);
6528 case ITEM_MOD_DODGE_RATING
:
6529 ApplyRatingMod(CR_DODGE
, int32(val
), apply
);
6531 case ITEM_MOD_PARRY_RATING
:
6532 ApplyRatingMod(CR_PARRY
, int32(val
), apply
);
6534 case ITEM_MOD_BLOCK_RATING
:
6535 ApplyRatingMod(CR_BLOCK
, int32(val
), apply
);
6537 case ITEM_MOD_HIT_MELEE_RATING
:
6538 ApplyRatingMod(CR_HIT_MELEE
, int32(val
), apply
);
6540 case ITEM_MOD_HIT_RANGED_RATING
:
6541 ApplyRatingMod(CR_HIT_RANGED
, int32(val
), apply
);
6543 case ITEM_MOD_HIT_SPELL_RATING
:
6544 ApplyRatingMod(CR_HIT_SPELL
, int32(val
), apply
);
6546 case ITEM_MOD_CRIT_MELEE_RATING
:
6547 ApplyRatingMod(CR_CRIT_MELEE
, int32(val
), apply
);
6549 case ITEM_MOD_CRIT_RANGED_RATING
:
6550 ApplyRatingMod(CR_CRIT_RANGED
, int32(val
), apply
);
6552 case ITEM_MOD_CRIT_SPELL_RATING
:
6553 ApplyRatingMod(CR_CRIT_SPELL
, int32(val
), apply
);
6555 case ITEM_MOD_HIT_TAKEN_MELEE_RATING
:
6556 ApplyRatingMod(CR_HIT_TAKEN_MELEE
, int32(val
), apply
);
6558 case ITEM_MOD_HIT_TAKEN_RANGED_RATING
:
6559 ApplyRatingMod(CR_HIT_TAKEN_RANGED
, int32(val
), apply
);
6561 case ITEM_MOD_HIT_TAKEN_SPELL_RATING
:
6562 ApplyRatingMod(CR_HIT_TAKEN_SPELL
, int32(val
), apply
);
6564 case ITEM_MOD_CRIT_TAKEN_MELEE_RATING
:
6565 ApplyRatingMod(CR_CRIT_TAKEN_MELEE
, int32(val
), apply
);
6567 case ITEM_MOD_CRIT_TAKEN_RANGED_RATING
:
6568 ApplyRatingMod(CR_CRIT_TAKEN_RANGED
, int32(val
), apply
);
6570 case ITEM_MOD_CRIT_TAKEN_SPELL_RATING
:
6571 ApplyRatingMod(CR_CRIT_TAKEN_SPELL
, int32(val
), apply
);
6573 case ITEM_MOD_HASTE_MELEE_RATING
:
6574 ApplyRatingMod(CR_HASTE_MELEE
, int32(val
), apply
);
6576 case ITEM_MOD_HASTE_RANGED_RATING
:
6577 ApplyRatingMod(CR_HASTE_RANGED
, int32(val
), apply
);
6579 case ITEM_MOD_HASTE_SPELL_RATING
:
6580 ApplyRatingMod(CR_HASTE_SPELL
, int32(val
), apply
);
6582 case ITEM_MOD_HIT_RATING
:
6583 ApplyRatingMod(CR_HIT_MELEE
, int32(val
), apply
);
6584 ApplyRatingMod(CR_HIT_RANGED
, int32(val
), apply
);
6585 ApplyRatingMod(CR_HIT_SPELL
, int32(val
), apply
);
6587 case ITEM_MOD_CRIT_RATING
:
6588 ApplyRatingMod(CR_CRIT_MELEE
, int32(val
), apply
);
6589 ApplyRatingMod(CR_CRIT_RANGED
, int32(val
), apply
);
6590 ApplyRatingMod(CR_CRIT_SPELL
, int32(val
), apply
);
6592 case ITEM_MOD_HIT_TAKEN_RATING
:
6593 ApplyRatingMod(CR_HIT_TAKEN_MELEE
, int32(val
), apply
);
6594 ApplyRatingMod(CR_HIT_TAKEN_RANGED
, int32(val
), apply
);
6595 ApplyRatingMod(CR_HIT_TAKEN_SPELL
, int32(val
), apply
);
6597 case ITEM_MOD_CRIT_TAKEN_RATING
:
6598 ApplyRatingMod(CR_CRIT_TAKEN_MELEE
, int32(val
), apply
);
6599 ApplyRatingMod(CR_CRIT_TAKEN_RANGED
, int32(val
), apply
);
6600 ApplyRatingMod(CR_CRIT_TAKEN_SPELL
, int32(val
), apply
);
6602 case ITEM_MOD_RESILIENCE_RATING
:
6603 ApplyRatingMod(CR_CRIT_TAKEN_MELEE
, int32(val
), apply
);
6604 ApplyRatingMod(CR_CRIT_TAKEN_RANGED
, int32(val
), apply
);
6605 ApplyRatingMod(CR_CRIT_TAKEN_SPELL
, int32(val
), apply
);
6607 case ITEM_MOD_HASTE_RATING
:
6608 ApplyRatingMod(CR_HASTE_MELEE
, int32(val
), apply
);
6609 ApplyRatingMod(CR_HASTE_RANGED
, int32(val
), apply
);
6610 ApplyRatingMod(CR_HASTE_SPELL
, int32(val
), apply
);
6612 case ITEM_MOD_EXPERTISE_RATING
:
6613 ApplyRatingMod(CR_EXPERTISE
, int32(val
), apply
);
6615 case ITEM_MOD_ARMOR_PENETRATION_RATING
:
6616 ApplyRatingMod(CR_ARMOR_PENETRATION
, int32(val
), apply
);
6622 HandleStatModifier(UNIT_MOD_ARMOR
, BASE_VALUE
, float(proto
->Armor
), apply
);
6625 HandleBaseModValue(SHIELD_BLOCK_VALUE
, FLAT_MOD
, float(proto
->Block
), apply
);
6628 HandleStatModifier(UNIT_MOD_RESISTANCE_HOLY
, BASE_VALUE
, float(proto
->HolyRes
), apply
);
6631 HandleStatModifier(UNIT_MOD_RESISTANCE_FIRE
, BASE_VALUE
, float(proto
->FireRes
), apply
);
6633 if (proto
->NatureRes
)
6634 HandleStatModifier(UNIT_MOD_RESISTANCE_NATURE
, BASE_VALUE
, float(proto
->NatureRes
), apply
);
6636 if (proto
->FrostRes
)
6637 HandleStatModifier(UNIT_MOD_RESISTANCE_FROST
, BASE_VALUE
, float(proto
->FrostRes
), apply
);
6639 if (proto
->ShadowRes
)
6640 HandleStatModifier(UNIT_MOD_RESISTANCE_SHADOW
, BASE_VALUE
, float(proto
->ShadowRes
), apply
);
6642 if (proto
->ArcaneRes
)
6643 HandleStatModifier(UNIT_MOD_RESISTANCE_ARCANE
, BASE_VALUE
, float(proto
->ArcaneRes
), apply
);
6645 WeaponAttackType attType
= BASE_ATTACK
;
6646 float damage
= 0.0f
;
6648 if( slot
== EQUIPMENT_SLOT_RANGED
&& (
6649 proto
->InventoryType
== INVTYPE_RANGED
|| proto
->InventoryType
== INVTYPE_THROWN
||
6650 proto
->InventoryType
== INVTYPE_RANGEDRIGHT
))
6652 attType
= RANGED_ATTACK
;
6654 else if(slot
==EQUIPMENT_SLOT_OFFHAND
)
6656 attType
= OFF_ATTACK
;
6659 if (proto
->Damage
[0].DamageMin
> 0 )
6661 damage
= apply
? proto
->Damage
[0].DamageMin
: BASE_MINDAMAGE
;
6662 SetBaseWeaponDamage(attType
, MINDAMAGE
, damage
);
6663 //sLog.outError("applying mindam: assigning %f to weapon mindamage, now is: %f", damage, GetWeaponDamageRange(attType, MINDAMAGE));
6666 if (proto
->Damage
[0].DamageMax
> 0 )
6668 damage
= apply
? proto
->Damage
[0].DamageMax
: BASE_MAXDAMAGE
;
6669 SetBaseWeaponDamage(attType
, MAXDAMAGE
, damage
);
6672 if(!IsUseEquipedWeapon(slot
==EQUIPMENT_SLOT_MAINHAND
))
6677 if(slot
== EQUIPMENT_SLOT_RANGED
)
6678 SetAttackTime(RANGED_ATTACK
, apply
? proto
->Delay
: BASE_ATTACK_TIME
);
6679 else if(slot
==EQUIPMENT_SLOT_MAINHAND
)
6680 SetAttackTime(BASE_ATTACK
, apply
? proto
->Delay
: BASE_ATTACK_TIME
);
6681 else if(slot
==EQUIPMENT_SLOT_OFFHAND
)
6682 SetAttackTime(OFF_ATTACK
, apply
? proto
->Delay
: BASE_ATTACK_TIME
);
6685 if(CanModifyStats() && (damage
|| proto
->Delay
))
6686 UpdateDamagePhysical(attType
);
6689 void Player::_ApplyWeaponDependentAuraMods(Item
*item
,WeaponAttackType attackType
,bool apply
)
6691 AuraList
const& auraCritList
= GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT
);
6692 for(AuraList::const_iterator itr
= auraCritList
.begin(); itr
!=auraCritList
.end();++itr
)
6693 _ApplyWeaponDependentAuraCritMod(item
,attackType
,*itr
,apply
);
6695 AuraList
const& auraDamageFlatList
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
6696 for(AuraList::const_iterator itr
= auraDamageFlatList
.begin(); itr
!=auraDamageFlatList
.end();++itr
)
6697 _ApplyWeaponDependentAuraDamageMod(item
,attackType
,*itr
,apply
);
6699 AuraList
const& auraDamagePCTList
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
6700 for(AuraList::const_iterator itr
= auraDamagePCTList
.begin(); itr
!=auraDamagePCTList
.end();++itr
)
6701 _ApplyWeaponDependentAuraDamageMod(item
,attackType
,*itr
,apply
);
6704 void Player::_ApplyWeaponDependentAuraCritMod(Item
*item
, WeaponAttackType attackType
, Aura
* aura
, bool apply
)
6706 // generic not weapon specific case processes in aura code
6707 if(aura
->GetSpellProto()->EquippedItemClass
== -1)
6710 BaseModGroup mod
= BASEMOD_END
;
6713 case BASE_ATTACK
: mod
= CRIT_PERCENTAGE
; break;
6714 case OFF_ATTACK
: mod
= OFFHAND_CRIT_PERCENTAGE
;break;
6715 case RANGED_ATTACK
: mod
= RANGED_CRIT_PERCENTAGE
; break;
6719 if (item
->IsFitToSpellRequirements(aura
->GetSpellProto()))
6721 HandleBaseModValue(mod
, FLAT_MOD
, float (aura
->GetModifier()->m_amount
), apply
);
6725 void Player::_ApplyWeaponDependentAuraDamageMod(Item
*item
, WeaponAttackType attackType
, Aura
* aura
, bool apply
)
6727 // ignore spell mods for not wands
6728 Modifier
const* modifier
= aura
->GetModifier();
6729 if((modifier
->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)==0 && (getClassMask() & CLASSMASK_WAND_USERS
)==0)
6732 // generic not weapon specific case processes in aura code
6733 if(aura
->GetSpellProto()->EquippedItemClass
== -1)
6736 UnitMods unitMod
= UNIT_MOD_END
;
6739 case BASE_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_MAINHAND
; break;
6740 case OFF_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_OFFHAND
; break;
6741 case RANGED_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_RANGED
; break;
6745 UnitModifierType unitModType
= TOTAL_VALUE
;
6746 switch(modifier
->m_auraname
)
6748 case SPELL_AURA_MOD_DAMAGE_DONE
: unitModType
= TOTAL_VALUE
; break;
6749 case SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
: unitModType
= TOTAL_PCT
; break;
6753 if (item
->IsFitToSpellRequirements(aura
->GetSpellProto()))
6755 HandleStatModifier(unitMod
, unitModType
, float(modifier
->m_amount
),apply
);
6759 void Player::ApplyItemEquipSpell(Item
*item
, bool apply
, bool form_change
)
6764 ItemPrototype
const *proto
= item
->GetProto();
6768 for (int i
= 0; i
< 5; i
++)
6770 _Spell
const& spellData
= proto
->Spells
[i
];
6773 if(!spellData
.SpellId
)
6776 // wrong triggering type
6777 if(apply
&& spellData
.SpellTrigger
!= ITEM_SPELLTRIGGER_ON_EQUIP
)
6780 // check if it is valid spell
6781 SpellEntry
const* spellproto
= sSpellStore
.LookupEntry(spellData
.SpellId
);
6785 ApplyEquipSpell(spellproto
,item
,apply
,form_change
);
6789 void Player::ApplyEquipSpell(SpellEntry
const* spellInfo
, Item
* item
, bool apply
, bool form_change
)
6793 // Cannot be used in this stance/form
6794 if(GetErrorAtShapeshiftedCast(spellInfo
, m_form
)!=0)
6797 if(form_change
) // check aura active state from other form
6800 for (int k
=0; k
< 3; ++k
)
6802 spellEffectPair spair
= spellEffectPair(spellInfo
->Id
, k
);
6803 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
); ++iter
)
6805 if(!item
|| iter
->second
->GetCastItemGUID() == item
->GetGUID())
6815 if(found
) // and skip re-cast already active aura at form change
6819 DEBUG_LOG("WORLD: cast %s Equip spellId - %i", (item
? "item" : "itemset"), spellInfo
->Id
);
6821 CastSpell(this,spellInfo
,true,item
);
6825 if(form_change
) // check aura compatibility
6827 // Cannot be used in this stance/form
6828 if(GetErrorAtShapeshiftedCast(spellInfo
, m_form
)==0)
6829 return; // and remove only not compatible at form change
6833 RemoveAurasDueToItemSpell(item
,spellInfo
->Id
); // un-apply all spells , not only at-equipped
6835 RemoveAurasDueToSpell(spellInfo
->Id
); // un-apply spell (item set case)
6839 void Player::UpdateEquipSpellsAtFormChange()
6841 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
6843 if(m_items
[i
] && !m_items
[i
]->IsBroken())
6845 ApplyItemEquipSpell(m_items
[i
],false,true); // remove spells that not fit to form
6846 ApplyItemEquipSpell(m_items
[i
],true,true); // add spells that fit form but not active
6850 // item set bonuses not dependent from item broken state
6851 for(size_t setindex
= 0; setindex
< ItemSetEff
.size(); ++setindex
)
6853 ItemSetEffect
* eff
= ItemSetEff
[setindex
];
6857 for(uint32 y
=0;y
<8; ++y
)
6859 SpellEntry
const* spellInfo
= eff
->spells
[y
];
6863 ApplyEquipSpell(spellInfo
,NULL
,false,true); // remove spells that not fit to form
6864 ApplyEquipSpell(spellInfo
,NULL
,true,true); // add spells that fit form but not active
6869 void Player::CastItemCombatSpell(Item
*item
,Unit
* Target
, WeaponAttackType attType
)
6871 if(!item
|| item
->IsBroken())
6874 ItemPrototype
const *proto
= item
->GetProto();
6878 if (!Target
|| Target
== this )
6881 for (int i
= 0; i
< 5; i
++)
6883 _Spell
const& spellData
= proto
->Spells
[i
];
6886 if(!spellData
.SpellId
)
6889 // wrong triggering type
6890 if(spellData
.SpellTrigger
!= ITEM_SPELLTRIGGER_CHANCE_ON_HIT
)
6893 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellData
.SpellId
);
6896 sLog
.outError("WORLD: unknown Item spellid %i", spellData
.SpellId
);
6900 // not allow proc extra attack spell at extra attack
6901 if( m_extraAttacks
&& IsSpellHaveEffect(spellInfo
,SPELL_EFFECT_ADD_EXTRA_ATTACKS
) )
6904 float chance
= spellInfo
->procChance
;
6906 if(spellData
.SpellPPMRate
)
6908 uint32 WeaponSpeed
= GetAttackTime(attType
);
6909 chance
= GetPPMProcChance(WeaponSpeed
, spellData
.SpellPPMRate
);
6911 else if(chance
> 100.0f
)
6913 chance
= GetWeaponProcChance();
6916 if (roll_chance_f(chance
))
6917 CastSpell(Target
, spellInfo
->Id
, true, item
);
6920 // item combat enchantments
6921 for(int e_slot
= 0; e_slot
< MAX_ENCHANTMENT_SLOT
; ++e_slot
)
6923 uint32 enchant_id
= item
->GetEnchantmentId(EnchantmentSlot(e_slot
));
6924 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
6925 if(!pEnchant
) continue;
6926 for (int s
=0;s
<3;s
++)
6928 if(pEnchant
->type
[s
]!=ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL
)
6931 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(pEnchant
->spellid
[s
]);
6934 sLog
.outError("Player::CastItemCombatSpell Enchant %i, cast unknown spell %i", pEnchant
->ID
, pEnchant
->spellid
[s
]);
6938 float chance
= pEnchant
->amount
[s
] != 0 ? float(pEnchant
->amount
[s
]) : GetWeaponProcChance();
6939 if (roll_chance_f(chance
))
6941 if(IsPositiveSpell(pEnchant
->spellid
[s
]))
6942 CastSpell(this, pEnchant
->spellid
[s
], true, item
);
6944 CastSpell(Target
, pEnchant
->spellid
[s
], true, item
);
6950 void Player::CastItemUseSpell(Item
*item
,SpellCastTargets
const& targets
,uint8 cast_count
, uint32 glyphIndex
)
6952 ItemPrototype
const* proto
= item
->GetProto();
6953 // special learning case
6954 if(proto
->Spells
[0].SpellId
==SPELL_ID_GENERIC_LEARN
|| proto
->Spells
[0].SpellId
==SPELL_ID_GENERIC_LEARN_PET
)
6956 uint32 learn_spell_id
= proto
->Spells
[0].SpellId
;
6957 uint32 learning_spell_id
= proto
->Spells
[1].SpellId
;
6959 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(learn_spell_id
);
6962 sLog
.outError("Player::CastItemUseSpell: Item (Entry: %u) in have wrong spell id %u, ignoring ",proto
->ItemId
, learn_spell_id
);
6963 SendEquipError(EQUIP_ERR_NONE
,item
,NULL
);
6967 Spell
*spell
= new Spell(this, spellInfo
, false);
6968 spell
->m_CastItem
= item
;
6969 spell
->m_cast_count
= cast_count
; //set count of casts
6970 spell
->m_currentBasePoints
[0] = learning_spell_id
;
6971 spell
->prepare(&targets
);
6975 // use triggered flag only for items with many spell casts and for not first cast
6978 // item spells casted at use
6979 for(int i
= 0; i
< 5; ++i
)
6981 _Spell
const& spellData
= proto
->Spells
[i
];
6984 if(!spellData
.SpellId
)
6987 // wrong triggering type
6988 if( spellData
.SpellTrigger
!= ITEM_SPELLTRIGGER_ON_USE
&& spellData
.SpellTrigger
!= ITEM_SPELLTRIGGER_ON_NO_DELAY_USE
)
6991 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellData
.SpellId
);
6994 sLog
.outError("Player::CastItemUseSpell: Item (Entry: %u) in have wrong spell id %u, ignoring",proto
->ItemId
, spellData
.SpellId
);
6998 Spell
*spell
= new Spell(this, spellInfo
, (count
> 0));
6999 spell
->m_CastItem
= item
;
7000 spell
->m_cast_count
= cast_count
; // set count of casts
7001 spell
->m_glyphIndex
= glyphIndex
; // glyph index
7002 spell
->prepare(&targets
);
7007 // Item enchantments spells casted at use
7008 for(int e_slot
= 0; e_slot
< MAX_ENCHANTMENT_SLOT
; ++e_slot
)
7010 uint32 enchant_id
= item
->GetEnchantmentId(EnchantmentSlot(e_slot
));
7011 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
7012 if(!pEnchant
) continue;
7013 for (int s
=0;s
<3;s
++)
7015 if(pEnchant
->type
[s
]!=ITEM_ENCHANTMENT_TYPE_USE_SPELL
)
7018 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(pEnchant
->spellid
[s
]);
7021 sLog
.outError("Player::CastItemUseSpell Enchant %i, cast unknown spell %i", pEnchant
->ID
, pEnchant
->spellid
[s
]);
7025 Spell
*spell
= new Spell(this, spellInfo
, (count
> 0));
7026 spell
->m_CastItem
= item
;
7027 spell
->m_cast_count
= cast_count
; // set count of casts
7028 spell
->m_glyphIndex
= glyphIndex
; // glyph index
7029 spell
->prepare(&targets
);
7036 void Player::_RemoveAllItemMods()
7038 sLog
.outDebug("_RemoveAllItemMods start.");
7040 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
7044 ItemPrototype
const *proto
= m_items
[i
]->GetProto();
7048 // item set bonuses not dependent from item broken state
7050 RemoveItemsSetItem(this,proto
);
7052 if(m_items
[i
]->IsBroken())
7055 ApplyItemEquipSpell(m_items
[i
],false);
7056 ApplyEnchantment(m_items
[i
], false);
7060 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
7064 if(m_items
[i
]->IsBroken())
7066 ItemPrototype
const *proto
= m_items
[i
]->GetProto();
7070 uint32 attacktype
= Player::GetAttackBySlot(i
);
7071 if(attacktype
< MAX_ATTACK
)
7072 _ApplyWeaponDependentAuraMods(m_items
[i
],WeaponAttackType(attacktype
),false);
7074 _ApplyItemBonuses(proto
,i
, false);
7076 if( i
== EQUIPMENT_SLOT_RANGED
)
7077 _ApplyAmmoBonuses();
7081 sLog
.outDebug("_RemoveAllItemMods complete.");
7084 void Player::_ApplyAllItemMods()
7086 sLog
.outDebug("_ApplyAllItemMods start.");
7088 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
7092 if(m_items
[i
]->IsBroken())
7095 ItemPrototype
const *proto
= m_items
[i
]->GetProto();
7099 uint32 attacktype
= Player::GetAttackBySlot(i
);
7100 if(attacktype
< MAX_ATTACK
)
7101 _ApplyWeaponDependentAuraMods(m_items
[i
],WeaponAttackType(attacktype
),true);
7103 _ApplyItemBonuses(proto
,i
, true);
7105 if( i
== EQUIPMENT_SLOT_RANGED
)
7106 _ApplyAmmoBonuses();
7110 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
7114 ItemPrototype
const *proto
= m_items
[i
]->GetProto();
7118 // item set bonuses not dependent from item broken state
7120 AddItemsSetItem(this,m_items
[i
]);
7122 if(m_items
[i
]->IsBroken())
7125 ApplyItemEquipSpell(m_items
[i
],true);
7126 ApplyEnchantment(m_items
[i
], true);
7130 sLog
.outDebug("_ApplyAllItemMods complete.");
7133 void Player::_ApplyAmmoBonuses()
7136 uint32 ammo_id
= GetUInt32Value(PLAYER_AMMO_ID
);
7140 float currentAmmoDPS
;
7142 ItemPrototype
const *ammo_proto
= objmgr
.GetItemPrototype( ammo_id
);
7143 if( !ammo_proto
|| ammo_proto
->Class
!=ITEM_CLASS_PROJECTILE
|| !CheckAmmoCompatibility(ammo_proto
))
7144 currentAmmoDPS
= 0.0f
;
7146 currentAmmoDPS
= ammo_proto
->Damage
[0].DamageMin
;
7148 if(currentAmmoDPS
== GetAmmoDPS())
7151 m_ammoDPS
= currentAmmoDPS
;
7153 if(CanModifyStats())
7154 UpdateDamagePhysical(RANGED_ATTACK
);
7157 bool Player::CheckAmmoCompatibility(const ItemPrototype
*ammo_proto
) const
7162 // check ranged weapon
7163 Item
*weapon
= GetWeaponForAttack( RANGED_ATTACK
);
7164 if(!weapon
|| weapon
->IsBroken() )
7167 ItemPrototype
const* weapon_proto
= weapon
->GetProto();
7168 if(!weapon_proto
|| weapon_proto
->Class
!=ITEM_CLASS_WEAPON
)
7171 // check ammo ws. weapon compatibility
7172 switch(weapon_proto
->SubClass
)
7174 case ITEM_SUBCLASS_WEAPON_BOW
:
7175 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
7176 if(ammo_proto
->SubClass
!=ITEM_SUBCLASS_ARROW
)
7179 case ITEM_SUBCLASS_WEAPON_GUN
:
7180 if(ammo_proto
->SubClass
!=ITEM_SUBCLASS_BULLET
)
7190 /* If in a battleground a player dies, and an enemy removes the insignia, the player's bones is lootable
7191 Called by remove insignia spell effect */
7192 void Player::RemovedInsignia(Player
* looterPlr
)
7194 if (!GetBattleGroundId())
7197 // If not released spirit, do it !
7198 if(m_deathTimer
> 0)
7205 Corpse
*corpse
= GetCorpse();
7209 // We have to convert player corpse to bones, not to be able to resurrect there
7210 // SpawnCorpseBones isn't handy, 'cos it saves player while he in BG
7211 Corpse
*bones
= ObjectAccessor::Instance().ConvertCorpseForPlayer(GetGUID(),true);
7215 // Now we must make bones lootable, and send player loot
7216 bones
->SetFlag(CORPSE_FIELD_DYNAMIC_FLAGS
, CORPSE_DYNFLAG_LOOTABLE
);
7218 // We store the level of our player in the gold field
7219 // We retrieve this information at Player::SendLoot()
7220 bones
->loot
.gold
= getLevel();
7221 bones
->lootRecipient
= looterPlr
;
7222 looterPlr
->SendLoot(bones
->GetGUID(), LOOT_INSIGNIA
);
7231 void Player::SendLootRelease( uint64 guid
)
7233 WorldPacket
data( SMSG_LOOT_RELEASE_RESPONSE
, (8+1) );
7234 data
<< uint64(guid
) << uint8(1);
7235 SendDirectMessage( &data
);
7238 void Player::SendLoot(uint64 guid
, LootType loot_type
)
7241 PermissionTypes permission
= ALL_PERMISSION
;
7243 sLog
.outDebug("Player::SendLoot");
7244 if (IS_GAMEOBJECT_GUID(guid
))
7246 sLog
.outDebug(" IS_GAMEOBJECT_GUID(guid)");
7248 ObjectAccessor::GetGameObject(*this, guid
);
7250 // not check distance for GO in case owned GO (fishing bobber case, for example)
7251 // And permit out of range GO with no owner in case fishing hole
7252 if (!go
|| (loot_type
!= LOOT_FISHINGHOLE
&& (loot_type
!= LOOT_FISHING
|| go
->GetOwnerGUID() != GetGUID()) && !go
->IsWithinDistInMap(this,INTERACTION_DISTANCE
)))
7254 SendLootRelease(guid
);
7260 if(go
->getLootState() == GO_READY
)
7262 uint32 lootid
= go
->GetLootId();
7266 sLog
.outDebug(" if(lootid)");
7268 loot
->FillLoot(lootid
, LootTemplates_Gameobject
, this);
7271 if(loot_type
== LOOT_FISHING
)
7272 go
->getFishLoot(loot
);
7274 go
->SetLootState(GO_ACTIVATED
);
7277 else if (IS_ITEM_GUID(guid
))
7279 Item
*item
= GetItemByGuid( guid
);
7283 SendLootRelease(guid
);
7287 if(loot_type
== LOOT_DISENCHANTING
)
7291 if(!item
->m_lootGenerated
)
7293 item
->m_lootGenerated
= true;
7295 loot
->FillLoot(item
->GetProto()->DisenchantID
, LootTemplates_Disenchant
, this);
7298 else if(loot_type
== LOOT_PROSPECTING
)
7302 if(!item
->m_lootGenerated
)
7304 item
->m_lootGenerated
= true;
7306 loot
->FillLoot(item
->GetEntry(), LootTemplates_Prospecting
, this);
7309 else if(loot_type
== LOOT_MILLING
)
7313 if(!item
->m_lootGenerated
)
7315 item
->m_lootGenerated
= true;
7317 loot
->FillLoot(item
->GetEntry(), LootTemplates_Milling
, this);
7324 if(!item
->m_lootGenerated
)
7326 item
->m_lootGenerated
= true;
7328 loot
->FillLoot(item
->GetEntry(), LootTemplates_Item
, this);
7330 loot
->generateMoneyLoot(item
->GetProto()->MinMoneyLoot
,item
->GetProto()->MaxMoneyLoot
);
7334 else if (IS_CORPSE_GUID(guid
)) // remove insignia
7336 Corpse
*bones
= ObjectAccessor::GetCorpse(*this, guid
);
7338 if (!bones
|| !((loot_type
== LOOT_CORPSE
) || (loot_type
== LOOT_INSIGNIA
)) || (bones
->GetType() != CORPSE_BONES
) )
7340 SendLootRelease(guid
);
7344 loot
= &bones
->loot
;
7346 if (!bones
->lootForBody
)
7348 bones
->lootForBody
= true;
7349 uint32 pLevel
= bones
->loot
.gold
;
7350 bones
->loot
.clear();
7351 // It may need a better formula
7352 // Now it works like this: lvl10: ~6copper, lvl70: ~9silver
7353 bones
->loot
.gold
= (uint32
)( urand(50, 150) * 0.016f
* pow( ((float)pLevel
)/5.76f
, 2.5f
) * sWorld
.getRate(RATE_DROP_MONEY
) );
7356 if (bones
->lootRecipient
!= this)
7357 permission
= NONE_PERMISSION
;
7361 Creature
*creature
= ObjectAccessor::GetCreature(*this, guid
);
7363 // must be in range and creature must be alive for pickpocket and must be dead for another loot
7364 if (!creature
|| creature
->isAlive()!=(loot_type
== LOOT_PICKPOCKETING
) || !creature
->IsWithinDistInMap(this,INTERACTION_DISTANCE
))
7366 SendLootRelease(guid
);
7370 if(loot_type
== LOOT_PICKPOCKETING
&& IsFriendlyTo(creature
))
7372 SendLootRelease(guid
);
7376 loot
= &creature
->loot
;
7378 if(loot_type
== LOOT_PICKPOCKETING
)
7380 if ( !creature
->lootForPickPocketed
)
7382 creature
->lootForPickPocketed
= true;
7385 if (uint32 lootid
= creature
->GetCreatureInfo()->pickpocketLootId
)
7386 loot
->FillLoot(lootid
, LootTemplates_Pickpocketing
, this);
7388 // Generate extra money for pick pocket loot
7389 const uint32 a
= urand(0, creature
->getLevel()/2);
7390 const uint32 b
= urand(0, getLevel()/2);
7391 loot
->gold
= uint32(10 * (a
+ b
) * sWorld
.getRate(RATE_DROP_MONEY
));
7396 // the player whose group may loot the corpse
7397 Player
*recipient
= creature
->GetLootRecipient();
7400 creature
->SetLootRecipient(this);
7404 if (creature
->lootForPickPocketed
)
7406 creature
->lootForPickPocketed
= false;
7410 if(!creature
->lootForBody
)
7412 creature
->lootForBody
= true;
7415 if (uint32 lootid
= creature
->GetCreatureInfo()->lootid
)
7416 loot
->FillLoot(lootid
, LootTemplates_Creature
, recipient
);
7418 loot
->generateMoneyLoot(creature
->GetCreatureInfo()->mingold
,creature
->GetCreatureInfo()->maxgold
);
7420 if(Group
* group
= recipient
->GetGroup())
7422 group
->UpdateLooterGuid(creature
,true);
7424 switch (group
->GetLootMethod())
7427 // GroupLoot delete items over threshold (threshold even not implemented), and roll them. Items with quality<threshold, round robin
7428 group
->GroupLoot(recipient
->GetGUID(), loot
, creature
);
7430 case NEED_BEFORE_GREED
:
7431 group
->NeedBeforeGreed(recipient
->GetGUID(), loot
, creature
);
7434 group
->MasterLoot(recipient
->GetGUID(), loot
, creature
);
7442 // possible only if creature->lootForBody && loot->empty() at spell cast check
7443 if (loot_type
== LOOT_SKINNING
)
7446 loot
->FillLoot(creature
->GetCreatureInfo()->SkinLootId
, LootTemplates_Skinning
, this);
7448 // set group rights only for loot_type != LOOT_SKINNING
7451 if(Group
* group
= GetGroup())
7453 if( group
== recipient
->GetGroup() )
7455 if(group
->GetLootMethod() == FREE_FOR_ALL
)
7456 permission
= ALL_PERMISSION
;
7457 else if(group
->GetLooterGuid() == GetGUID())
7459 if(group
->GetLootMethod() == MASTER_LOOT
)
7460 permission
= MASTER_PERMISSION
;
7462 permission
= ALL_PERMISSION
;
7465 permission
= GROUP_PERMISSION
;
7468 permission
= NONE_PERMISSION
;
7470 else if(recipient
== this)
7471 permission
= ALL_PERMISSION
;
7473 permission
= NONE_PERMISSION
;
7480 QuestItemList
*q_list
= 0;
7481 if (permission
!= NONE_PERMISSION
)
7483 QuestItemMap
const& lootPlayerQuestItems
= loot
->GetPlayerQuestItems();
7484 QuestItemMap::const_iterator itr
= lootPlayerQuestItems
.find(GetGUIDLow());
7485 if (itr
== lootPlayerQuestItems
.end())
7486 q_list
= loot
->FillQuestLoot(this);
7488 q_list
= itr
->second
;
7491 QuestItemList
*ffa_list
= 0;
7492 if (permission
!= NONE_PERMISSION
)
7494 QuestItemMap
const& lootPlayerFFAItems
= loot
->GetPlayerFFAItems();
7495 QuestItemMap::const_iterator itr
= lootPlayerFFAItems
.find(GetGUIDLow());
7496 if (itr
== lootPlayerFFAItems
.end())
7497 ffa_list
= loot
->FillFFALoot(this);
7499 ffa_list
= itr
->second
;
7502 QuestItemList
*conditional_list
= 0;
7503 if (permission
!= NONE_PERMISSION
)
7505 QuestItemMap
const& lootPlayerNonQuestNonFFAConditionalItems
= loot
->GetPlayerNonQuestNonFFAConditionalItems();
7506 QuestItemMap::const_iterator itr
= lootPlayerNonQuestNonFFAConditionalItems
.find(GetGUIDLow());
7507 if (itr
== lootPlayerNonQuestNonFFAConditionalItems
.end())
7508 conditional_list
= loot
->FillNonQuestNonFFAConditionalLoot(this);
7510 conditional_list
= itr
->second
;
7513 // LOOT_PICKPOCKETING, LOOT_PROSPECTING, LOOT_DISENCHANTING, LOOT_INSIGNIA and LOOT_MILLING unsupported by client, sending LOOT_SKINNING instead
7514 if(loot_type
== LOOT_PICKPOCKETING
|| loot_type
== LOOT_DISENCHANTING
|| loot_type
== LOOT_PROSPECTING
|| loot_type
== LOOT_INSIGNIA
|| loot_type
== LOOT_MILLING
)
7515 loot_type
= LOOT_SKINNING
;
7517 if(loot_type
== LOOT_FISHINGHOLE
)
7518 loot_type
= LOOT_FISHING
;
7520 WorldPacket
data(SMSG_LOOT_RESPONSE
, (9+50)); // we guess size
7522 data
<< uint64(guid
);
7523 data
<< uint8(loot_type
);
7524 data
<< LootView(*loot
, q_list
, ffa_list
, conditional_list
, this, permission
);
7526 SendDirectMessage(&data
);
7528 // add 'this' player as one of the players that are looting 'loot'
7529 if (permission
!= NONE_PERMISSION
)
7530 loot
->AddLooter(GetGUID());
7532 if ( loot_type
== LOOT_CORPSE
&& !IS_ITEM_GUID(guid
) )
7533 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_LOOTING
);
7536 void Player::SendNotifyLootMoneyRemoved()
7538 WorldPacket
data(SMSG_LOOT_CLEAR_MONEY
, 0);
7539 GetSession()->SendPacket( &data
);
7542 void Player::SendNotifyLootItemRemoved(uint8 lootSlot
)
7544 WorldPacket
data(SMSG_LOOT_REMOVED
, 1);
7545 data
<< uint8(lootSlot
);
7546 GetSession()->SendPacket( &data
);
7549 void Player::SendUpdateWorldState(uint32 Field
, uint32 Value
)
7551 WorldPacket
data(SMSG_UPDATE_WORLD_STATE
, 8);
7554 GetSession()->SendPacket(&data
);
7557 void Player::SendInitWorldStates()
7559 // data depends on zoneid/mapid...
7560 BattleGround
* bg
= GetBattleGround();
7561 uint16 NumberOfFields
= 0;
7562 uint32 mapid
= GetMapId();
7563 uint32 zoneid
= GetZoneId();
7564 uint32 areaid
= GetAreaId();
7565 sLog
.outDebug("Sending SMSG_INIT_WORLD_STATES to Map:%u, Zone: %u", mapid
, zoneid
);
7566 // may be exist better way to do this...
7589 NumberOfFields
= 41;
7592 NumberOfFields
= 15;
7595 NumberOfFields
= 83;
7598 NumberOfFields
= 16;
7602 NumberOfFields
= 40;
7605 NumberOfFields
= 27;
7608 NumberOfFields
= 39;
7611 NumberOfFields
= 38;
7614 NumberOfFields
= 37;
7619 NumberOfFields
= 11;
7622 NumberOfFields
= 11;
7625 NumberOfFields
= 12;
7629 WorldPacket
data(SMSG_INIT_WORLD_STATES
, (4+4+4+2+(NumberOfFields
*8)));
7630 data
<< uint32(mapid
); // mapid
7631 data
<< uint32(zoneid
); // zone id
7632 data
<< uint32(areaid
); // area id, new 2.1.0
7633 data
<< uint16(NumberOfFields
); // count of uint64 blocks
7634 data
<< uint32(0x8d8) << uint32(0x0); // 1
7635 data
<< uint32(0x8d7) << uint32(0x0); // 2
7636 data
<< uint32(0x8d6) << uint32(0x0); // 3
7637 data
<< uint32(0x8d5) << uint32(0x0); // 4
7638 data
<< uint32(0x8d4) << uint32(0x0); // 5
7639 data
<< uint32(0x8d3) << uint32(0x0); // 6
7640 // 7 1 - Arena season in progress, 0 - end of season
7641 data
<< uint32(0xC77) << uint32(sWorld
.getConfig(CONFIG_ARENA_SEASON_IN_PROGRESS
));
7642 // 8 Arena season id
7643 data
<< uint32(0xF3D) << uint32(sWorld
.getConfig(CONFIG_ARENA_SEASON_ID
));
7644 if(mapid
== 530) // Outland
7646 data
<< uint32(0x9bf) << uint32(0x0); // 7
7647 data
<< uint32(0x9bd) << uint32(0xF); // 8
7648 data
<< uint32(0x9bb) << uint32(0xF); // 9
7663 data
<< uint32(0x7ae) << uint32(0x1); // 7
7664 data
<< uint32(0x532) << uint32(0x1); // 8
7665 data
<< uint32(0x531) << uint32(0x0); // 9
7666 data
<< uint32(0x52e) << uint32(0x0); // 10
7667 data
<< uint32(0x571) << uint32(0x0); // 11
7668 data
<< uint32(0x570) << uint32(0x0); // 12
7669 data
<< uint32(0x567) << uint32(0x1); // 13
7670 data
<< uint32(0x566) << uint32(0x1); // 14
7671 data
<< uint32(0x550) << uint32(0x1); // 15
7672 data
<< uint32(0x544) << uint32(0x0); // 16
7673 data
<< uint32(0x536) << uint32(0x0); // 17
7674 data
<< uint32(0x535) << uint32(0x1); // 18
7675 data
<< uint32(0x518) << uint32(0x0); // 19
7676 data
<< uint32(0x517) << uint32(0x0); // 20
7677 data
<< uint32(0x574) << uint32(0x0); // 21
7678 data
<< uint32(0x573) << uint32(0x0); // 22
7679 data
<< uint32(0x572) << uint32(0x0); // 23
7680 data
<< uint32(0x56f) << uint32(0x0); // 24
7681 data
<< uint32(0x56e) << uint32(0x0); // 25
7682 data
<< uint32(0x56d) << uint32(0x0); // 26
7683 data
<< uint32(0x56c) << uint32(0x0); // 27
7684 data
<< uint32(0x56b) << uint32(0x0); // 28
7685 data
<< uint32(0x56a) << uint32(0x1); // 29
7686 data
<< uint32(0x569) << uint32(0x1); // 30
7687 data
<< uint32(0x568) << uint32(0x1); // 13
7688 data
<< uint32(0x565) << uint32(0x0); // 32
7689 data
<< uint32(0x564) << uint32(0x0); // 33
7690 data
<< uint32(0x563) << uint32(0x0); // 34
7691 data
<< uint32(0x562) << uint32(0x0); // 35
7692 data
<< uint32(0x561) << uint32(0x0); // 36
7693 data
<< uint32(0x560) << uint32(0x0); // 37
7694 data
<< uint32(0x55f) << uint32(0x0); // 38
7695 data
<< uint32(0x55e) << uint32(0x0); // 39
7696 data
<< uint32(0x55d) << uint32(0x0); // 40
7697 data
<< uint32(0x3c6) << uint32(0x4); // 41
7698 data
<< uint32(0x3c4) << uint32(0x6); // 42
7699 data
<< uint32(0x3c2) << uint32(0x4); // 43
7700 data
<< uint32(0x516) << uint32(0x1); // 44
7701 data
<< uint32(0x515) << uint32(0x0); // 45
7702 data
<< uint32(0x3b6) << uint32(0x6); // 46
7703 data
<< uint32(0x55c) << uint32(0x0); // 47
7704 data
<< uint32(0x55b) << uint32(0x0); // 48
7705 data
<< uint32(0x55a) << uint32(0x0); // 49
7706 data
<< uint32(0x559) << uint32(0x0); // 50
7707 data
<< uint32(0x558) << uint32(0x0); // 51
7708 data
<< uint32(0x557) << uint32(0x0); // 52
7709 data
<< uint32(0x556) << uint32(0x0); // 53
7710 data
<< uint32(0x555) << uint32(0x0); // 54
7711 data
<< uint32(0x554) << uint32(0x1); // 55
7712 data
<< uint32(0x553) << uint32(0x1); // 56
7713 data
<< uint32(0x552) << uint32(0x1); // 57
7714 data
<< uint32(0x551) << uint32(0x1); // 58
7715 data
<< uint32(0x54f) << uint32(0x0); // 59
7716 data
<< uint32(0x54e) << uint32(0x0); // 60
7717 data
<< uint32(0x54d) << uint32(0x1); // 61
7718 data
<< uint32(0x54c) << uint32(0x0); // 62
7719 data
<< uint32(0x54b) << uint32(0x0); // 63
7720 data
<< uint32(0x545) << uint32(0x0); // 64
7721 data
<< uint32(0x543) << uint32(0x1); // 65
7722 data
<< uint32(0x542) << uint32(0x0); // 66
7723 data
<< uint32(0x540) << uint32(0x0); // 67
7724 data
<< uint32(0x53f) << uint32(0x0); // 68
7725 data
<< uint32(0x53e) << uint32(0x0); // 69
7726 data
<< uint32(0x53d) << uint32(0x0); // 70
7727 data
<< uint32(0x53c) << uint32(0x0); // 71
7728 data
<< uint32(0x53b) << uint32(0x0); // 72
7729 data
<< uint32(0x53a) << uint32(0x1); // 73
7730 data
<< uint32(0x539) << uint32(0x0); // 74
7731 data
<< uint32(0x538) << uint32(0x0); // 75
7732 data
<< uint32(0x537) << uint32(0x0); // 76
7733 data
<< uint32(0x534) << uint32(0x0); // 77
7734 data
<< uint32(0x533) << uint32(0x0); // 78
7735 data
<< uint32(0x530) << uint32(0x0); // 79
7736 data
<< uint32(0x52f) << uint32(0x0); // 80
7737 data
<< uint32(0x52d) << uint32(0x1); // 81
7740 if (bg
&& bg
->GetTypeID() == BATTLEGROUND_WS
)
7741 bg
->FillInitialWorldStates(data
);
7744 data
<< uint32(0x62d) << uint32(0x0); // 7 1581 alliance flag captures
7745 data
<< uint32(0x62e) << uint32(0x0); // 8 1582 horde flag captures
7746 data
<< uint32(0x609) << uint32(0x0); // 9 1545 unk, set to 1 on alliance flag pickup...
7747 data
<< uint32(0x60a) << uint32(0x0); // 10 1546 unk, set to 1 on horde flag pickup, after drop it's -1
7748 data
<< uint32(0x60b) << uint32(0x2); // 11 1547 unk
7749 data
<< uint32(0x641) << uint32(0x3); // 12 1601 unk (max flag captures?)
7750 data
<< uint32(0x922) << uint32(0x1); // 13 2338 horde (0 - hide, 1 - flag ok, 2 - flag picked up (flashing), 3 - flag picked up (not flashing)
7751 data
<< uint32(0x923) << uint32(0x1); // 14 2339 alliance (0 - hide, 1 - flag ok, 2 - flag picked up (flashing), 3 - flag picked up (not flashing)
7755 if (bg
&& bg
->GetTypeID() == BATTLEGROUND_AB
)
7756 bg
->FillInitialWorldStates(data
);
7759 data
<< uint32(0x6e7) << uint32(0x0); // 7 1767 stables alliance
7760 data
<< uint32(0x6e8) << uint32(0x0); // 8 1768 stables horde
7761 data
<< uint32(0x6e9) << uint32(0x0); // 9 1769 unk, ST?
7762 data
<< uint32(0x6ea) << uint32(0x0); // 10 1770 stables (show/hide)
7763 data
<< uint32(0x6ec) << uint32(0x0); // 11 1772 farm (0 - horde controlled, 1 - alliance controlled)
7764 data
<< uint32(0x6ed) << uint32(0x0); // 12 1773 farm (show/hide)
7765 data
<< uint32(0x6ee) << uint32(0x0); // 13 1774 farm color
7766 data
<< uint32(0x6ef) << uint32(0x0); // 14 1775 gold mine color, may be FM?
7767 data
<< uint32(0x6f0) << uint32(0x0); // 15 1776 alliance resources
7768 data
<< uint32(0x6f1) << uint32(0x0); // 16 1777 horde resources
7769 data
<< uint32(0x6f2) << uint32(0x0); // 17 1778 horde bases
7770 data
<< uint32(0x6f3) << uint32(0x0); // 18 1779 alliance bases
7771 data
<< uint32(0x6f4) << uint32(0x7d0); // 19 1780 max resources (2000)
7772 data
<< uint32(0x6f6) << uint32(0x0); // 20 1782 blacksmith color
7773 data
<< uint32(0x6f7) << uint32(0x0); // 21 1783 blacksmith (show/hide)
7774 data
<< uint32(0x6f8) << uint32(0x0); // 22 1784 unk, bs?
7775 data
<< uint32(0x6f9) << uint32(0x0); // 23 1785 unk, bs?
7776 data
<< uint32(0x6fb) << uint32(0x0); // 24 1787 gold mine (0 - horde contr, 1 - alliance contr)
7777 data
<< uint32(0x6fc) << uint32(0x0); // 25 1788 gold mine (0 - conflict, 1 - horde)
7778 data
<< uint32(0x6fd) << uint32(0x0); // 26 1789 gold mine (1 - show/0 - hide)
7779 data
<< uint32(0x6fe) << uint32(0x0); // 27 1790 gold mine color
7780 data
<< uint32(0x700) << uint32(0x0); // 28 1792 gold mine color, wtf?, may be LM?
7781 data
<< uint32(0x701) << uint32(0x0); // 29 1793 lumber mill color (0 - conflict, 1 - horde contr)
7782 data
<< uint32(0x702) << uint32(0x0); // 30 1794 lumber mill (show/hide)
7783 data
<< uint32(0x703) << uint32(0x0); // 31 1795 lumber mill color color
7784 data
<< uint32(0x732) << uint32(0x1); // 32 1842 stables (1 - uncontrolled)
7785 data
<< uint32(0x733) << uint32(0x1); // 33 1843 gold mine (1 - uncontrolled)
7786 data
<< uint32(0x734) << uint32(0x1); // 34 1844 lumber mill (1 - uncontrolled)
7787 data
<< uint32(0x735) << uint32(0x1); // 35 1845 farm (1 - uncontrolled)
7788 data
<< uint32(0x736) << uint32(0x1); // 36 1846 blacksmith (1 - uncontrolled)
7789 data
<< uint32(0x745) << uint32(0x2); // 37 1861 unk
7790 data
<< uint32(0x7a3) << uint32(0x708); // 38 1955 warning limit (1800)
7794 if (bg
&& bg
->GetTypeID() == BATTLEGROUND_EY
)
7795 bg
->FillInitialWorldStates(data
);
7798 data
<< uint32(0xac1) << uint32(0x0); // 7 2753 Horde Bases
7799 data
<< uint32(0xac0) << uint32(0x0); // 8 2752 Alliance Bases
7800 data
<< uint32(0xab6) << uint32(0x0); // 9 2742 Mage Tower - Horde conflict
7801 data
<< uint32(0xab5) << uint32(0x0); // 10 2741 Mage Tower - Alliance conflict
7802 data
<< uint32(0xab4) << uint32(0x0); // 11 2740 Fel Reaver - Horde conflict
7803 data
<< uint32(0xab3) << uint32(0x0); // 12 2739 Fel Reaver - Alliance conflict
7804 data
<< uint32(0xab2) << uint32(0x0); // 13 2738 Draenei - Alliance conflict
7805 data
<< uint32(0xab1) << uint32(0x0); // 14 2737 Draenei - Horde conflict
7806 data
<< uint32(0xab0) << uint32(0x0); // 15 2736 unk // 0 at start
7807 data
<< uint32(0xaaf) << uint32(0x0); // 16 2735 unk // 0 at start
7808 data
<< uint32(0xaad) << uint32(0x0); // 17 2733 Draenei - Horde control
7809 data
<< uint32(0xaac) << uint32(0x0); // 18 2732 Draenei - Alliance control
7810 data
<< uint32(0xaab) << uint32(0x1); // 19 2731 Draenei uncontrolled (1 - yes, 0 - no)
7811 data
<< uint32(0xaaa) << uint32(0x0); // 20 2730 Mage Tower - Alliance control
7812 data
<< uint32(0xaa9) << uint32(0x0); // 21 2729 Mage Tower - Horde control
7813 data
<< uint32(0xaa8) << uint32(0x1); // 22 2728 Mage Tower uncontrolled (1 - yes, 0 - no)
7814 data
<< uint32(0xaa7) << uint32(0x0); // 23 2727 Fel Reaver - Horde control
7815 data
<< uint32(0xaa6) << uint32(0x0); // 24 2726 Fel Reaver - Alliance control
7816 data
<< uint32(0xaa5) << uint32(0x1); // 25 2725 Fel Reaver uncontrolled (1 - yes, 0 - no)
7817 data
<< uint32(0xaa4) << uint32(0x0); // 26 2724 Boold Elf - Horde control
7818 data
<< uint32(0xaa3) << uint32(0x0); // 27 2723 Boold Elf - Alliance control
7819 data
<< uint32(0xaa2) << uint32(0x1); // 28 2722 Boold Elf uncontrolled (1 - yes, 0 - no)
7820 data
<< uint32(0xac5) << uint32(0x1); // 29 2757 Flag (1 - show, 0 - hide) - doesn't work exactly this way!
7821 data
<< uint32(0xad2) << uint32(0x1); // 30 2770 Horde top-stats (1 - show, 0 - hide) // 02 -> horde picked up the flag
7822 data
<< uint32(0xad1) << uint32(0x1); // 31 2769 Alliance top-stats (1 - show, 0 - hide) // 02 -> alliance picked up the flag
7823 data
<< uint32(0xabe) << uint32(0x0); // 32 2750 Horde resources
7824 data
<< uint32(0xabd) << uint32(0x0); // 33 2749 Alliance resources
7825 data
<< uint32(0xa05) << uint32(0x8e); // 34 2565 unk, constant?
7826 data
<< uint32(0xaa0) << uint32(0x0); // 35 2720 Capturing progress-bar (100 -> empty (only grey), 0 -> blue|red (no grey), default 0)
7827 data
<< uint32(0xa9f) << uint32(0x0); // 36 2719 Capturing progress-bar (0 - left, 100 - right)
7828 data
<< uint32(0xa9e) << uint32(0x0); // 37 2718 Capturing progress-bar (1 - show, 0 - hide)
7829 data
<< uint32(0xc0d) << uint32(0x17b); // 38 3085 unk
7830 // and some more ... unknown
7833 case 3483: // Hellfire Peninsula
7834 data
<< uint32(0x9ba) << uint32(0x1); // 10
7835 data
<< uint32(0x9b9) << uint32(0x1); // 11
7836 data
<< uint32(0x9b5) << uint32(0x0); // 12
7837 data
<< uint32(0x9b4) << uint32(0x1); // 13
7838 data
<< uint32(0x9b3) << uint32(0x0); // 14
7839 data
<< uint32(0x9b2) << uint32(0x0); // 15
7840 data
<< uint32(0x9b1) << uint32(0x1); // 16
7841 data
<< uint32(0x9b0) << uint32(0x0); // 17
7842 data
<< uint32(0x9ae) << uint32(0x0); // 18 horde pvp objectives captured
7843 data
<< uint32(0x9ac) << uint32(0x0); // 19
7844 data
<< uint32(0x9a8) << uint32(0x0); // 20
7845 data
<< uint32(0x9a7) << uint32(0x0); // 21
7846 data
<< uint32(0x9a6) << uint32(0x1); // 22
7848 case 3519: // Terokkar Forest
7849 data
<< uint32(0xa41) << uint32(0x0); // 10
7850 data
<< uint32(0xa40) << uint32(0x14); // 11
7851 data
<< uint32(0xa3f) << uint32(0x0); // 12
7852 data
<< uint32(0xa3e) << uint32(0x0); // 13
7853 data
<< uint32(0xa3d) << uint32(0x5); // 14
7854 data
<< uint32(0xa3c) << uint32(0x0); // 15
7855 data
<< uint32(0xa87) << uint32(0x0); // 16
7856 data
<< uint32(0xa86) << uint32(0x0); // 17
7857 data
<< uint32(0xa85) << uint32(0x0); // 18
7858 data
<< uint32(0xa84) << uint32(0x0); // 19
7859 data
<< uint32(0xa83) << uint32(0x0); // 20
7860 data
<< uint32(0xa82) << uint32(0x0); // 21
7861 data
<< uint32(0xa81) << uint32(0x0); // 22
7862 data
<< uint32(0xa80) << uint32(0x0); // 23
7863 data
<< uint32(0xa7e) << uint32(0x0); // 24
7864 data
<< uint32(0xa7d) << uint32(0x0); // 25
7865 data
<< uint32(0xa7c) << uint32(0x0); // 26
7866 data
<< uint32(0xa7b) << uint32(0x0); // 27
7867 data
<< uint32(0xa7a) << uint32(0x0); // 28
7868 data
<< uint32(0xa79) << uint32(0x0); // 29
7869 data
<< uint32(0x9d0) << uint32(0x5); // 30
7870 data
<< uint32(0x9ce) << uint32(0x0); // 31
7871 data
<< uint32(0x9cd) << uint32(0x0); // 32
7872 data
<< uint32(0x9cc) << uint32(0x0); // 33
7873 data
<< uint32(0xa88) << uint32(0x0); // 34
7874 data
<< uint32(0xad0) << uint32(0x0); // 35
7875 data
<< uint32(0xacf) << uint32(0x1); // 36
7877 case 3521: // Zangarmarsh
7878 data
<< uint32(0x9e1) << uint32(0x0); // 10
7879 data
<< uint32(0x9e0) << uint32(0x0); // 11
7880 data
<< uint32(0x9df) << uint32(0x0); // 12
7881 data
<< uint32(0xa5d) << uint32(0x1); // 13
7882 data
<< uint32(0xa5c) << uint32(0x0); // 14
7883 data
<< uint32(0xa5b) << uint32(0x1); // 15
7884 data
<< uint32(0xa5a) << uint32(0x0); // 16
7885 data
<< uint32(0xa59) << uint32(0x1); // 17
7886 data
<< uint32(0xa58) << uint32(0x0); // 18
7887 data
<< uint32(0xa57) << uint32(0x0); // 19
7888 data
<< uint32(0xa56) << uint32(0x0); // 20
7889 data
<< uint32(0xa55) << uint32(0x1); // 21
7890 data
<< uint32(0xa54) << uint32(0x0); // 22
7891 data
<< uint32(0x9e7) << uint32(0x0); // 23
7892 data
<< uint32(0x9e6) << uint32(0x0); // 24
7893 data
<< uint32(0x9e5) << uint32(0x0); // 25
7894 data
<< uint32(0xa00) << uint32(0x0); // 26
7895 data
<< uint32(0x9ff) << uint32(0x1); // 27
7896 data
<< uint32(0x9fe) << uint32(0x0); // 28
7897 data
<< uint32(0x9fd) << uint32(0x0); // 29
7898 data
<< uint32(0x9fc) << uint32(0x1); // 30
7899 data
<< uint32(0x9fb) << uint32(0x0); // 31
7900 data
<< uint32(0xa62) << uint32(0x0); // 32
7901 data
<< uint32(0xa61) << uint32(0x1); // 33
7902 data
<< uint32(0xa60) << uint32(0x1); // 34
7903 data
<< uint32(0xa5f) << uint32(0x0); // 35
7905 case 3698: // Nagrand Arena
7906 if (bg
&& bg
->GetTypeID() == BATTLEGROUND_NA
)
7907 bg
->FillInitialWorldStates(data
);
7910 data
<< uint32(0xa0f) << uint32(0x0); // 7
7911 data
<< uint32(0xa10) << uint32(0x0); // 8
7912 data
<< uint32(0xa11) << uint32(0x0); // 9 show
7915 case 3702: // Blade's Edge Arena
7916 if (bg
&& bg
->GetTypeID() == BATTLEGROUND_BE
)
7917 bg
->FillInitialWorldStates(data
);
7920 data
<< uint32(0x9f0) << uint32(0x0); // 7 gold
7921 data
<< uint32(0x9f1) << uint32(0x0); // 8 green
7922 data
<< uint32(0x9f3) << uint32(0x0); // 9 show
7925 case 3968: // Ruins of Lordaeron
7926 if (bg
&& bg
->GetTypeID() == BATTLEGROUND_RL
)
7927 bg
->FillInitialWorldStates(data
);
7930 data
<< uint32(0xbb8) << uint32(0x0); // 7 gold
7931 data
<< uint32(0xbb9) << uint32(0x0); // 8 green
7932 data
<< uint32(0xbba) << uint32(0x0); // 9 show
7935 case 3703: // Shattrath City
7938 data
<< uint32(0x914) << uint32(0x0); // 7
7939 data
<< uint32(0x913) << uint32(0x0); // 8
7940 data
<< uint32(0x912) << uint32(0x0); // 9
7941 data
<< uint32(0x915) << uint32(0x0); // 10
7944 GetSession()->SendPacket(&data
);
7947 uint32
Player::GetXPRestBonus(uint32 xp
)
7949 uint32 rested_bonus
= (uint32
)GetRestBonus(); // xp for each rested bonus
7951 if(rested_bonus
> xp
) // max rested_bonus == xp or (r+x) = 200% xp
7954 SetRestBonus( GetRestBonus() - rested_bonus
);
7956 sLog
.outDetail("Player gain %u xp (+ %u Rested Bonus). Rested points=%f",xp
+rested_bonus
,rested_bonus
,GetRestBonus());
7957 return rested_bonus
;
7960 void Player::SetBindPoint(uint64 guid
)
7962 WorldPacket
data(SMSG_BINDER_CONFIRM
, 8);
7963 data
<< uint64(guid
);
7964 GetSession()->SendPacket( &data
);
7967 void Player::SendTalentWipeConfirm(uint64 guid
)
7969 WorldPacket
data(MSG_TALENT_WIPE_CONFIRM
, (8+4));
7970 data
<< uint64(guid
);
7971 data
<< uint32(resetTalentsCost());
7972 GetSession()->SendPacket( &data
);
7975 void Player::SendPetSkillWipeConfirm()
7977 Pet
* pet
= GetPet();
7980 WorldPacket
data(SMSG_PET_UNLEARN_CONFIRM
, (8+4));
7981 data
<< pet
->GetGUID();
7982 data
<< uint32(pet
->resetTalentsCost());
7983 GetSession()->SendPacket( &data
);
7986 /*********************************************************/
7987 /*** STORAGE SYSTEM ***/
7988 /*********************************************************/
7990 void Player::SetVirtualItemSlot( uint8 i
, Item
* item
)
7995 if(!item
->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT
))
7997 uint32 charges
= item
->GetEnchantmentCharges(TEMP_ENCHANTMENT_SLOT
);
8001 item
->SetEnchantmentCharges(TEMP_ENCHANTMENT_SLOT
,charges
-1);
8002 else if(charges
<= 1)
8004 ApplyEnchantment(item
,TEMP_ENCHANTMENT_SLOT
,false);
8005 item
->ClearEnchantment(TEMP_ENCHANTMENT_SLOT
);
8010 void Player::SetSheath( uint32 sheathed
)
8014 case SHEATH_STATE_UNARMED
: // no prepared weapon
8015 SetVirtualItemSlot(0,NULL
);
8016 SetVirtualItemSlot(1,NULL
);
8017 SetVirtualItemSlot(2,NULL
);
8019 case SHEATH_STATE_MELEE
: // prepared melee weapon
8021 SetVirtualItemSlot(0,GetWeaponForAttack(BASE_ATTACK
,true));
8022 SetVirtualItemSlot(1,GetWeaponForAttack(OFF_ATTACK
,true));
8023 SetVirtualItemSlot(2,NULL
);
8025 case SHEATH_STATE_RANGED
: // prepared ranged weapon
8026 SetVirtualItemSlot(0,NULL
);
8027 SetVirtualItemSlot(1,NULL
);
8028 SetVirtualItemSlot(2,GetWeaponForAttack(RANGED_ATTACK
,true));
8031 SetVirtualItemSlot(0,NULL
);
8032 SetVirtualItemSlot(1,NULL
);
8033 SetVirtualItemSlot(2,NULL
);
8036 SetByteValue(UNIT_FIELD_BYTES_2
, 0, sheathed
); // this must visualize Sheath changing for other players...
8039 uint8
Player::FindEquipSlot( ItemPrototype
const* proto
, uint32 slot
, bool swap
) const
8041 uint8 pClass
= getClass();
8044 slots
[0] = NULL_SLOT
;
8045 slots
[1] = NULL_SLOT
;
8046 slots
[2] = NULL_SLOT
;
8047 slots
[3] = NULL_SLOT
;
8048 switch( proto
->InventoryType
)
8051 slots
[0] = EQUIPMENT_SLOT_HEAD
;
8054 slots
[0] = EQUIPMENT_SLOT_NECK
;
8056 case INVTYPE_SHOULDERS
:
8057 slots
[0] = EQUIPMENT_SLOT_SHOULDERS
;
8060 slots
[0] = EQUIPMENT_SLOT_BODY
;
8063 slots
[0] = EQUIPMENT_SLOT_CHEST
;
8066 slots
[0] = EQUIPMENT_SLOT_CHEST
;
8069 slots
[0] = EQUIPMENT_SLOT_WAIST
;
8072 slots
[0] = EQUIPMENT_SLOT_LEGS
;
8075 slots
[0] = EQUIPMENT_SLOT_FEET
;
8077 case INVTYPE_WRISTS
:
8078 slots
[0] = EQUIPMENT_SLOT_WRISTS
;
8081 slots
[0] = EQUIPMENT_SLOT_HANDS
;
8083 case INVTYPE_FINGER
:
8084 slots
[0] = EQUIPMENT_SLOT_FINGER1
;
8085 slots
[1] = EQUIPMENT_SLOT_FINGER2
;
8087 case INVTYPE_TRINKET
:
8088 slots
[0] = EQUIPMENT_SLOT_TRINKET1
;
8089 slots
[1] = EQUIPMENT_SLOT_TRINKET2
;
8092 slots
[0] = EQUIPMENT_SLOT_BACK
;
8094 case INVTYPE_WEAPON
:
8096 slots
[0] = EQUIPMENT_SLOT_MAINHAND
;
8098 // suggest offhand slot only if know dual wielding
8099 // (this will be replace mainhand weapon at auto equip instead unwonted "you don't known dual wielding" ...
8101 slots
[1] = EQUIPMENT_SLOT_OFFHAND
;
8104 case INVTYPE_SHIELD
:
8105 slots
[0] = EQUIPMENT_SLOT_OFFHAND
;
8107 case INVTYPE_RANGED
:
8108 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8110 case INVTYPE_2HWEAPON
:
8111 slots
[0] = EQUIPMENT_SLOT_MAINHAND
;
8112 if (CanDualWield() && CanTitanGrip())
8113 slots
[1] = EQUIPMENT_SLOT_OFFHAND
;
8115 case INVTYPE_TABARD
:
8116 slots
[0] = EQUIPMENT_SLOT_TABARD
;
8118 case INVTYPE_WEAPONMAINHAND
:
8119 slots
[0] = EQUIPMENT_SLOT_MAINHAND
;
8121 case INVTYPE_WEAPONOFFHAND
:
8122 slots
[0] = EQUIPMENT_SLOT_OFFHAND
;
8124 case INVTYPE_HOLDABLE
:
8125 slots
[0] = EQUIPMENT_SLOT_OFFHAND
;
8127 case INVTYPE_THROWN
:
8128 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8130 case INVTYPE_RANGEDRIGHT
:
8131 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8134 slots
[0] = INVENTORY_SLOT_BAG_1
;
8135 slots
[1] = INVENTORY_SLOT_BAG_2
;
8136 slots
[2] = INVENTORY_SLOT_BAG_3
;
8137 slots
[3] = INVENTORY_SLOT_BAG_4
;
8141 switch(proto
->SubClass
)
8143 case ITEM_SUBCLASS_ARMOR_LIBRAM
:
8144 if (pClass
== CLASS_PALADIN
)
8145 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8147 case ITEM_SUBCLASS_ARMOR_IDOL
:
8148 if (pClass
== CLASS_DRUID
)
8149 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8151 case ITEM_SUBCLASS_ARMOR_TOTEM
:
8152 if (pClass
== CLASS_SHAMAN
)
8153 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8155 case ITEM_SUBCLASS_ARMOR_MISC
:
8156 if (pClass
== CLASS_WARLOCK
)
8157 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8159 case ITEM_SUBCLASS_ARMOR_SIGIL
:
8160 if (pClass
== CLASS_DEATH_KNIGHT
)
8161 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8170 if( slot
!= NULL_SLOT
)
8172 if( swap
|| !GetItemByPos( INVENTORY_SLOT_BAG_0
, slot
) )
8174 for (int i
= 0; i
< 4; i
++)
8176 if ( slots
[i
] == slot
)
8183 // search free slot at first
8184 for (int i
= 0; i
< 4; i
++)
8186 if ( slots
[i
] != NULL_SLOT
&& !GetItemByPos( INVENTORY_SLOT_BAG_0
, slots
[i
] ) )
8188 // in case 2hand equipped weapon (without titan grip) offhand slot empty but not free
8189 if(slots
[i
]!=EQUIPMENT_SLOT_OFFHAND
|| !IsTwoHandUsed())
8194 // if not found free and can swap return first appropriate from used
8195 for (int i
= 0; i
< 4; i
++)
8197 if ( slots
[i
] != NULL_SLOT
&& swap
)
8206 uint8
Player::CanUnequipItems( uint32 item
, uint32 count
) const
8209 uint32 tempcount
= 0;
8211 uint8 res
= EQUIP_ERR_OK
;
8213 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8215 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8216 if( pItem
&& pItem
->GetEntry() == item
)
8218 uint8 ires
= CanUnequipItem(INVENTORY_SLOT_BAG_0
<< 8 | i
, false);
8219 if(ires
==EQUIP_ERR_OK
)
8221 tempcount
+= pItem
->GetCount();
8222 if( tempcount
>= count
)
8223 return EQUIP_ERR_OK
;
8229 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8231 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8232 if( pItem
&& pItem
->GetEntry() == item
)
8234 tempcount
+= pItem
->GetCount();
8235 if( tempcount
>= count
)
8236 return EQUIP_ERR_OK
;
8239 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
8241 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8242 if( pItem
&& pItem
->GetEntry() == item
)
8244 tempcount
+= pItem
->GetCount();
8245 if( tempcount
>= count
)
8246 return EQUIP_ERR_OK
;
8250 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8252 pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8255 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8257 pItem
= GetItemByPos( i
, j
);
8258 if( pItem
&& pItem
->GetEntry() == item
)
8260 tempcount
+= pItem
->GetCount();
8261 if( tempcount
>= count
)
8262 return EQUIP_ERR_OK
;
8268 // not found req. item count and have unequippable items
8272 uint32
Player::GetItemCount( uint32 item
, bool inBankAlso
, Item
* skipItem
) const
8275 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8277 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8278 if( pItem
&& pItem
!= skipItem
&& pItem
->GetEntry() == item
)
8279 count
+= pItem
->GetCount();
8281 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
8283 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8284 if( pItem
&& pItem
!= skipItem
&& pItem
->GetEntry() == item
)
8285 count
+= pItem
->GetCount();
8287 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8289 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8291 count
+= pBag
->GetItemCount(item
,skipItem
);
8294 if(skipItem
&& skipItem
->GetProto()->GemProperties
)
8296 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8298 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8299 if( pItem
&& pItem
!= skipItem
&& pItem
->GetProto()->Socket
[0].Color
)
8300 count
+= pItem
->GetGemCountWithID(item
);
8306 for(int i
= BANK_SLOT_ITEM_START
; i
< BANK_SLOT_ITEM_END
; i
++)
8308 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8309 if( pItem
&& pItem
!= skipItem
&& pItem
->GetEntry() == item
)
8310 count
+= pItem
->GetCount();
8312 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
8314 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8316 count
+= pBag
->GetItemCount(item
,skipItem
);
8319 if(skipItem
&& skipItem
->GetProto()->GemProperties
)
8321 for(int i
= BANK_SLOT_ITEM_START
; i
< BANK_SLOT_ITEM_END
; i
++)
8323 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8324 if( pItem
&& pItem
!= skipItem
&& pItem
->GetProto()->Socket
[0].Color
)
8325 count
+= pItem
->GetGemCountWithID(item
);
8333 Item
* Player::GetItemByGuid( uint64 guid
) const
8335 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8337 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8338 if( pItem
&& pItem
->GetGUID() == guid
)
8341 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
8343 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8344 if( pItem
&& pItem
->GetGUID() == guid
)
8348 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8350 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8353 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8355 Item
* pItem
= pBag
->GetItemByPos( j
);
8356 if( pItem
&& pItem
->GetGUID() == guid
)
8361 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
8363 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8366 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8368 Item
* pItem
= pBag
->GetItemByPos( j
);
8369 if( pItem
&& pItem
->GetGUID() == guid
)
8378 Item
* Player::GetItemByPos( uint16 pos
) const
8380 uint8 bag
= pos
>> 8;
8381 uint8 slot
= pos
& 255;
8382 return GetItemByPos( bag
, slot
);
8385 Item
* Player::GetItemByPos( uint8 bag
, uint8 slot
) const
8387 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
< BANK_SLOT_BAG_END
|| slot
>= KEYRING_SLOT_START
&& slot
< QUESTBAG_SLOT_END
) )
8388 return m_items
[slot
];
8389 else if(bag
>= INVENTORY_SLOT_BAG_START
&& bag
< INVENTORY_SLOT_BAG_END
8390 || bag
>= BANK_SLOT_BAG_START
&& bag
< BANK_SLOT_BAG_END
)
8392 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
8394 return pBag
->GetItemByPos(slot
);
8399 Item
* Player::GetWeaponForAttack(WeaponAttackType attackType
, bool useable
) const
8404 case BASE_ATTACK
: slot
= EQUIPMENT_SLOT_MAINHAND
; break;
8405 case OFF_ATTACK
: slot
= EQUIPMENT_SLOT_OFFHAND
; break;
8406 case RANGED_ATTACK
: slot
= EQUIPMENT_SLOT_RANGED
; break;
8407 default: return NULL
;
8410 Item
* item
= GetItemByPos(INVENTORY_SLOT_BAG_0
, slot
);
8411 if (!item
|| item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
)
8417 if( item
->IsBroken() || !IsUseEquipedWeapon(attackType
==BASE_ATTACK
) )
8423 Item
* Player::GetShield(bool useable
) const
8425 Item
* item
= GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
8426 if (!item
|| item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
)
8432 if( item
->IsBroken())
8438 uint32
Player::GetAttackBySlot( uint8 slot
)
8442 case EQUIPMENT_SLOT_MAINHAND
: return BASE_ATTACK
;
8443 case EQUIPMENT_SLOT_OFFHAND
: return OFF_ATTACK
;
8444 case EQUIPMENT_SLOT_RANGED
: return RANGED_ATTACK
;
8445 default: return MAX_ATTACK
;
8449 bool Player::HasBankBagSlot( uint8 slot
) const
8451 uint32 maxslot
= GetByteValue(PLAYER_BYTES_2
, 2) + BANK_SLOT_BAG_START
;
8452 if( slot
< maxslot
)
8457 bool Player::IsInventoryPos( uint8 bag
, uint8 slot
)
8459 if( bag
== INVENTORY_SLOT_BAG_0
&& slot
== NULL_SLOT
)
8461 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= INVENTORY_SLOT_ITEM_START
&& slot
< INVENTORY_SLOT_ITEM_END
) )
8463 if( bag
>= INVENTORY_SLOT_BAG_START
&& bag
< INVENTORY_SLOT_BAG_END
)
8465 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= KEYRING_SLOT_START
&& slot
< QUESTBAG_SLOT_END
) )
8470 bool Player::IsEquipmentPos( uint8 bag
, uint8 slot
)
8472 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
< EQUIPMENT_SLOT_END
) )
8474 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= INVENTORY_SLOT_BAG_START
&& slot
< INVENTORY_SLOT_BAG_END
) )
8479 bool Player::IsBankPos( uint8 bag
, uint8 slot
)
8481 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= BANK_SLOT_ITEM_START
&& slot
< BANK_SLOT_ITEM_END
) )
8483 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
) )
8485 if( bag
>= BANK_SLOT_BAG_START
&& bag
< BANK_SLOT_BAG_END
)
8490 bool Player::IsBagPos( uint16 pos
)
8492 uint8 bag
= pos
>> 8;
8493 uint8 slot
= pos
& 255;
8494 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= INVENTORY_SLOT_BAG_START
&& slot
< INVENTORY_SLOT_BAG_END
) )
8496 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
) )
8501 bool Player::IsValidPos( uint8 bag
, uint8 slot
)
8507 if (bag
== INVENTORY_SLOT_BAG_0
)
8509 // any post selected
8510 if (slot
== NULL_SLOT
)
8514 if (slot
< EQUIPMENT_SLOT_END
)
8518 if (slot
>= INVENTORY_SLOT_BAG_START
&& slot
< INVENTORY_SLOT_BAG_END
)
8522 if (slot
>= INVENTORY_SLOT_ITEM_START
&& slot
< INVENTORY_SLOT_ITEM_END
)
8526 if (slot
>= KEYRING_SLOT_START
&& slot
< KEYRING_SLOT_END
)
8530 if (slot
>= BANK_SLOT_ITEM_START
&& slot
< BANK_SLOT_ITEM_END
)
8534 if (slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
)
8540 // bag content slots
8541 if (bag
>= INVENTORY_SLOT_BAG_START
&& bag
< INVENTORY_SLOT_BAG_END
)
8543 Bag
* pBag
= (Bag
*)GetItemByPos (INVENTORY_SLOT_BAG_0
, bag
);
8547 // any post selected
8548 if (slot
== NULL_SLOT
)
8551 return slot
< pBag
->GetBagSize();
8554 // bank bag content slots
8555 if( bag
>= BANK_SLOT_BAG_START
&& bag
< BANK_SLOT_BAG_END
)
8557 Bag
* pBag
= (Bag
*)GetItemByPos (INVENTORY_SLOT_BAG_0
, bag
);
8561 // any post selected
8562 if (slot
== NULL_SLOT
)
8565 return slot
< pBag
->GetBagSize();
8573 bool Player::HasItemCount( uint32 item
, uint32 count
, bool inBankAlso
) const
8575 uint32 tempcount
= 0;
8576 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8578 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8579 if( pItem
&& pItem
->GetEntry() == item
)
8581 tempcount
+= pItem
->GetCount();
8582 if( tempcount
>= count
)
8586 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
8588 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8589 if( pItem
&& pItem
->GetEntry() == item
)
8591 tempcount
+= pItem
->GetCount();
8592 if( tempcount
>= count
)
8596 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8598 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
8600 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8602 Item
* pItem
= GetItemByPos( i
, j
);
8603 if( pItem
&& pItem
->GetEntry() == item
)
8605 tempcount
+= pItem
->GetCount();
8606 if( tempcount
>= count
)
8615 for(int i
= BANK_SLOT_ITEM_START
; i
< BANK_SLOT_ITEM_END
; i
++)
8617 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8618 if( pItem
&& pItem
->GetEntry() == item
)
8620 tempcount
+= pItem
->GetCount();
8621 if( tempcount
>= count
)
8625 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
8627 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
8629 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8631 Item
* pItem
= GetItemByPos( i
, j
);
8632 if( pItem
&& pItem
->GetEntry() == item
)
8634 tempcount
+= pItem
->GetCount();
8635 if( tempcount
>= count
)
8646 Item
* Player::GetItemOrItemWithGemEquipped( uint32 item
) const
8649 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
8651 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8652 if( pItem
&& pItem
->GetEntry() == item
)
8656 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(item
);
8657 if (pProto
&& pProto
->GemProperties
)
8659 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
8661 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8662 if( pItem
&& pItem
->GetProto()->Socket
[0].Color
)
8664 if (pItem
->GetGemCountWithID(item
) > 0 )
8673 uint8
Player::_CanTakeMoreSimilarItems(uint32 entry
, uint32 count
, Item
* pItem
, uint32
* no_space_count
) const
8675 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(entry
);
8679 *no_space_count
= count
;
8680 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
8684 if(pProto
->MaxCount
<= 0)
8685 return EQUIP_ERR_OK
;
8687 uint32 curcount
= GetItemCount(pProto
->ItemId
,true,pItem
);
8689 if (curcount
+ count
> uint32(pProto
->MaxCount
))
8692 *no_space_count
= count
+curcount
- pProto
->MaxCount
;
8693 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
8696 return EQUIP_ERR_OK
;
8699 bool Player::HasItemTotemCategory( uint32 TotemCategory
) const
8702 for(uint8 i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; ++i
)
8704 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8705 if( pItem
&& IsTotemCategoryCompatiableWith(pItem
->GetProto()->TotemCategory
,TotemCategory
))
8708 for(uint8 i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; ++i
)
8710 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8711 if( pItem
&& IsTotemCategoryCompatiableWith(pItem
->GetProto()->TotemCategory
,TotemCategory
))
8714 for(uint8 i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; ++i
)
8716 if(Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
8718 for(uint32 j
= 0; j
< pBag
->GetBagSize(); ++j
)
8720 pItem
= GetItemByPos( i
, j
);
8721 if( pItem
&& IsTotemCategoryCompatiableWith(pItem
->GetProto()->TotemCategory
,TotemCategory
))
8729 uint8
Player::_CanStoreItem_InSpecificSlot( uint8 bag
, uint8 slot
, ItemPosCountVec
&dest
, ItemPrototype
const *pProto
, uint32
& count
, bool swap
, Item
* pSrcItem
) const
8731 Item
* pItem2
= GetItemByPos( bag
, slot
);
8733 // ignore move item (this slot will be empty at move)
8734 if(pItem2
==pSrcItem
)
8739 // empty specific slot - check item fit to slot
8740 if( !pItem2
|| swap
)
8742 if( bag
== INVENTORY_SLOT_BAG_0
)
8745 if(slot
>= KEYRING_SLOT_START
&& slot
< KEYRING_SLOT_START
+GetMaxKeyringSize() && !(pProto
->BagFamily
& BAG_FAMILY_MASK_KEYS
))
8746 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8748 // vanitypet case (disabled until proper implement)
8749 if(slot
>= VANITYPET_SLOT_START
&& slot
< VANITYPET_SLOT_END
&& !(false /*pProto->BagFamily & BAG_FAMILY_MASK_VANITY_PETS*/))
8750 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8752 // currencytoken case (disabled until proper implement)
8753 if(slot
>= CURRENCYTOKEN_SLOT_START
&& slot
< CURRENCYTOKEN_SLOT_END
&& !(false /*pProto->BagFamily & BAG_FAMILY_MASK_CURRENCY_TOKENS*/))
8754 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8756 // guestbag case (disabled until proper implement)
8757 if(slot
>= QUESTBAG_SLOT_START
&& slot
< QUESTBAG_SLOT_END
&& !(false /*pProto->BagFamily & BAG_FAMILY_MASK_QUEST_ITEMS*/))
8758 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8761 if(slot
>= BUYBACK_SLOT_START
&& slot
< BUYBACK_SLOT_END
|| slot
>= PLAYER_SLOT_END
)
8762 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8766 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
8768 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8770 ItemPrototype
const* pBagProto
= pBag
->GetProto();
8772 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8774 if( !ItemCanGoIntoBag(pProto
,pBagProto
) )
8775 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8778 // non empty stack with space
8779 need_space
= pProto
->GetMaxStackSize();
8781 // non empty slot, check item type
8785 if(pItem2
->GetEntry() != pProto
->ItemId
)
8786 return EQUIP_ERR_ITEM_CANT_STACK
;
8789 if(pItem2
->GetCount() >= pProto
->GetMaxStackSize())
8790 return EQUIP_ERR_ITEM_CANT_STACK
;
8792 // free stack space or infinity
8793 need_space
= pProto
->GetMaxStackSize() - pItem2
->GetCount();
8796 if(need_space
> count
)
8799 ItemPosCount newPosition
= ItemPosCount((bag
<< 8) | slot
, need_space
);
8800 if(!newPosition
.isContainedIn(dest
))
8802 dest
.push_back(newPosition
);
8803 count
-= need_space
;
8805 return EQUIP_ERR_OK
;
8808 uint8
Player::_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
8810 // skip specific bag already processed in first called _CanStoreItem_InBag
8812 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8814 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
8816 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8818 ItemPrototype
const* pBagProto
= pBag
->GetProto();
8820 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8822 // specialized bag mode or non-specilized
8823 if( non_specialized
!= (pBagProto
->Class
== ITEM_CLASS_CONTAINER
&& pBagProto
->SubClass
== ITEM_SUBCLASS_CONTAINER
) )
8824 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8826 if( !ItemCanGoIntoBag(pProto
,pBagProto
) )
8827 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8829 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8831 // skip specific slot already processed in first called _CanStoreItem_InSpecificSlot
8835 Item
* pItem2
= GetItemByPos( bag
, j
);
8837 // ignore move item (this slot will be empty at move)
8838 if(pItem2
==pSrcItem
)
8841 // if merge skip empty, if !merge skip non-empty
8842 if((pItem2
!=NULL
)!=merge
)
8847 if(pItem2
->GetEntry() == pProto
->ItemId
&& pItem2
->GetCount() < pProto
->GetMaxStackSize())
8849 uint32 need_space
= pProto
->GetMaxStackSize() - pItem2
->GetCount();
8850 if(need_space
> count
)
8853 ItemPosCount newPosition
= ItemPosCount((bag
<< 8) | j
, need_space
);
8854 if(!newPosition
.isContainedIn(dest
))
8856 dest
.push_back(newPosition
);
8857 count
-= need_space
;
8860 return EQUIP_ERR_OK
;
8866 uint32 need_space
= pProto
->GetMaxStackSize();
8867 if(need_space
> count
)
8870 ItemPosCount newPosition
= ItemPosCount((bag
<< 8) | j
, need_space
);
8871 if(!newPosition
.isContainedIn(dest
))
8873 dest
.push_back(newPosition
);
8874 count
-= need_space
;
8877 return EQUIP_ERR_OK
;
8881 return EQUIP_ERR_OK
;
8884 uint8
Player::_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
8886 for(uint32 j
= slot_begin
; j
< slot_end
; j
++)
8888 // skip specific slot already processed in first called _CanStoreItem_InSpecificSlot
8889 if(INVENTORY_SLOT_BAG_0
==skip_bag
&& j
==skip_slot
)
8892 Item
* pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, j
);
8894 // ignore move item (this slot will be empty at move)
8895 if(pItem2
==pSrcItem
)
8898 // if merge skip empty, if !merge skip non-empty
8899 if((pItem2
!=NULL
)!=merge
)
8904 if(pItem2
->GetEntry() == pProto
->ItemId
&& pItem2
->GetCount() < pProto
->GetMaxStackSize())
8906 uint32 need_space
= pProto
->GetMaxStackSize() - pItem2
->GetCount();
8907 if(need_space
> count
)
8909 ItemPosCount newPosition
= ItemPosCount((INVENTORY_SLOT_BAG_0
<< 8) | j
, need_space
);
8910 if(!newPosition
.isContainedIn(dest
))
8912 dest
.push_back(newPosition
);
8913 count
-= need_space
;
8916 return EQUIP_ERR_OK
;
8922 uint32 need_space
= pProto
->GetMaxStackSize();
8923 if(need_space
> count
)
8926 ItemPosCount newPosition
= ItemPosCount((INVENTORY_SLOT_BAG_0
<< 8) | j
, need_space
);
8927 if(!newPosition
.isContainedIn(dest
))
8929 dest
.push_back(newPosition
);
8930 count
-= need_space
;
8933 return EQUIP_ERR_OK
;
8937 return EQUIP_ERR_OK
;
8940 uint8
Player::_CanStoreItem( uint8 bag
, uint8 slot
, ItemPosCountVec
&dest
, uint32 entry
, uint32 count
, Item
*pItem
, bool swap
, uint32
* no_space_count
) const
8942 sLog
.outDebug( "STORAGE: CanStoreItem bag = %u, slot = %u, item = %u, count = %u", bag
, slot
, entry
, count
);
8944 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(entry
);
8948 *no_space_count
= count
;
8949 return swap
? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
:EQUIP_ERR_ITEM_NOT_FOUND
;
8952 if(pItem
&& pItem
->IsBindedNotWith(GetGUID()))
8955 *no_space_count
= count
;
8956 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
8959 // check count of items (skip for auto move for same player from bank)
8960 uint32 no_similar_count
= 0; // can't store this amount similar items
8961 uint8 res
= _CanTakeMoreSimilarItems(entry
,count
,pItem
,&no_similar_count
);
8962 if(res
!=EQUIP_ERR_OK
)
8964 if(count
==no_similar_count
)
8967 *no_space_count
= no_similar_count
;
8970 count
-= no_similar_count
;
8974 if( bag
!= NULL_BAG
&& slot
!= NULL_SLOT
)
8976 res
= _CanStoreItem_InSpecificSlot(bag
,slot
,dest
,pProto
,count
,swap
,pItem
);
8977 if(res
!=EQUIP_ERR_OK
)
8980 *no_space_count
= count
+ no_similar_count
;
8986 if(no_similar_count
==0)
8987 return EQUIP_ERR_OK
;
8990 *no_space_count
= count
+ no_similar_count
;
8991 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
8995 // not specific slot or have space for partly store only in specific slot
8998 if( bag
!= NULL_BAG
)
9000 // search stack in bag for merge to
9001 if( pProto
->Stackable
!= 1 )
9003 if( bag
== INVENTORY_SLOT_BAG_0
) // inventory
9005 res
= _CanStoreItem_InInventorySlots(KEYRING_SLOT_START
,QUESTBAG_SLOT_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
9006 if(res
!=EQUIP_ERR_OK
)
9009 *no_space_count
= count
+ no_similar_count
;
9015 if(no_similar_count
==0)
9016 return EQUIP_ERR_OK
;
9019 *no_space_count
= count
+ no_similar_count
;
9020 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9023 res
= _CanStoreItem_InInventorySlots(INVENTORY_SLOT_ITEM_START
,INVENTORY_SLOT_ITEM_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
9024 if(res
!=EQUIP_ERR_OK
)
9027 *no_space_count
= count
+ no_similar_count
;
9033 if(no_similar_count
==0)
9034 return EQUIP_ERR_OK
;
9037 *no_space_count
= count
+ no_similar_count
;
9038 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9041 else // equipped bag
9043 // we need check 2 time (specialized/non_specialized), use NULL_BAG to prevent skipping bag
9044 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,true,false,pItem
,NULL_BAG
,slot
);
9045 if(res
!=EQUIP_ERR_OK
)
9046 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,true,true,pItem
,NULL_BAG
,slot
);
9048 if(res
!=EQUIP_ERR_OK
)
9051 *no_space_count
= count
+ no_similar_count
;
9057 if(no_similar_count
==0)
9058 return EQUIP_ERR_OK
;
9061 *no_space_count
= count
+ no_similar_count
;
9062 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9067 // search free slot in bag for place to
9068 if( bag
== INVENTORY_SLOT_BAG_0
) // inventory
9070 // search free slot - keyring case
9071 if(pProto
->BagFamily
& BAG_FAMILY_MASK_KEYS
)
9073 uint32 keyringSize
= GetMaxKeyringSize();
9074 res
= _CanStoreItem_InInventorySlots(KEYRING_SLOT_START
,KEYRING_SLOT_START
+keyringSize
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9075 if(res
!=EQUIP_ERR_OK
)
9078 *no_space_count
= count
+ no_similar_count
;
9084 if(no_similar_count
==0)
9085 return EQUIP_ERR_OK
;
9088 *no_space_count
= count
+ no_similar_count
;
9089 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9092 /* until proper implementation
9093 else if(pProto->BagFamily & BAG_FAMILY_MASK_VANITY_PETS)
9095 res = _CanStoreItem_InInventorySlots(VANITYPET_SLOT_START,VANITYPET_SLOT_END,dest,pProto,count,false,pItem,bag,slot);
9096 if(res!=EQUIP_ERR_OK)
9099 *no_space_count = count + no_similar_count;
9105 if(no_similar_count==0)
9106 return EQUIP_ERR_OK;
9109 *no_space_count = count + no_similar_count;
9110 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS;
9114 /* until proper implementation
9115 else if(pProto->BagFamily & BAG_FAMILY_MASK_CURRENCY_TOKENS)
9117 res = _CanStoreItem_InInventorySlots(CURRENCYTOKEN_SLOT_START,CURRENCYTOKEN_SLOT_END,dest,pProto,count,false,pItem,bag,slot);
9118 if(res!=EQUIP_ERR_OK)
9121 *no_space_count = count + no_similar_count;
9127 if(no_similar_count==0)
9128 return EQUIP_ERR_OK;
9131 *no_space_count = count + no_similar_count;
9132 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS;
9136 /* until proper implementation
9137 else if(pProto->BagFamily & BAG_FAMILY_MASK_QUEST_ITEMS)
9139 res = _CanStoreItem_InInventorySlots(QUESTBAG_SLOT_START,QUESTBAG_SLOT_END,dest,pProto,count,false,pItem,bag,slot);
9140 if(res!=EQUIP_ERR_OK)
9143 *no_space_count = count + no_similar_count;
9149 if(no_similar_count==0)
9150 return EQUIP_ERR_OK;
9153 *no_space_count = count + no_similar_count;
9154 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS;
9159 res
= _CanStoreItem_InInventorySlots(INVENTORY_SLOT_ITEM_START
,INVENTORY_SLOT_ITEM_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9160 if(res
!=EQUIP_ERR_OK
)
9163 *no_space_count
= count
+ no_similar_count
;
9169 if(no_similar_count
==0)
9170 return EQUIP_ERR_OK
;
9173 *no_space_count
= count
+ no_similar_count
;
9174 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9177 else // equipped bag
9179 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,false,false,pItem
,NULL_BAG
,slot
);
9180 if(res
!=EQUIP_ERR_OK
)
9181 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,false,true,pItem
,NULL_BAG
,slot
);
9183 if(res
!=EQUIP_ERR_OK
)
9186 *no_space_count
= count
+ no_similar_count
;
9192 if(no_similar_count
==0)
9193 return EQUIP_ERR_OK
;
9196 *no_space_count
= count
+ no_similar_count
;
9197 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9202 // not specific bag or have space for partly store only in specific bag
9204 // search stack for merge to
9205 if( pProto
->Stackable
!= 1 )
9207 res
= _CanStoreItem_InInventorySlots(KEYRING_SLOT_START
,QUESTBAG_SLOT_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
9208 if(res
!=EQUIP_ERR_OK
)
9211 *no_space_count
= count
+ no_similar_count
;
9217 if(no_similar_count
==0)
9218 return EQUIP_ERR_OK
;
9221 *no_space_count
= count
+ no_similar_count
;
9222 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9225 res
= _CanStoreItem_InInventorySlots(INVENTORY_SLOT_ITEM_START
,INVENTORY_SLOT_ITEM_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
9226 if(res
!=EQUIP_ERR_OK
)
9229 *no_space_count
= count
+ no_similar_count
;
9235 if(no_similar_count
==0)
9236 return EQUIP_ERR_OK
;
9239 *no_space_count
= count
+ no_similar_count
;
9240 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9243 if( pProto
->BagFamily
)
9245 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9247 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,true,false,pItem
,bag
,slot
);
9248 if(res
!=EQUIP_ERR_OK
)
9253 if(no_similar_count
==0)
9254 return EQUIP_ERR_OK
;
9257 *no_space_count
= count
+ no_similar_count
;
9258 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9263 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9265 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,true,true,pItem
,bag
,slot
);
9266 if(res
!=EQUIP_ERR_OK
)
9271 if(no_similar_count
==0)
9272 return EQUIP_ERR_OK
;
9275 *no_space_count
= count
+ no_similar_count
;
9276 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9281 // search free slot - special bag case
9282 if( pProto
->BagFamily
)
9284 if(pProto
->BagFamily
& BAG_FAMILY_MASK_KEYS
)
9286 uint32 keyringSize
= GetMaxKeyringSize();
9287 res
= _CanStoreItem_InInventorySlots(KEYRING_SLOT_START
,KEYRING_SLOT_START
+keyringSize
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9288 if(res
!=EQUIP_ERR_OK
)
9291 *no_space_count
= count
+ no_similar_count
;
9297 if(no_similar_count
==0)
9298 return EQUIP_ERR_OK
;
9301 *no_space_count
= count
+ no_similar_count
;
9302 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9305 /* until proper implementation
9306 else if(false pProto->BagFamily & BAG_FAMILY_MASK_VANITY_PETS)
9308 res = _CanStoreItem_InInventorySlots(VANITYPET_SLOT_START,VANITYPET_SLOT_END,dest,pProto,count,false,pItem,bag,slot);
9309 if(res!=EQUIP_ERR_OK)
9312 *no_space_count = count + no_similar_count;
9318 if(no_similar_count==0)
9319 return EQUIP_ERR_OK;
9322 *no_space_count = count + no_similar_count;
9323 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS;
9327 /* until proper implementation
9328 else if(false pProto->BagFamily & BAG_FAMILY_MASK_CURRENCY_TOKENS)
9330 res = _CanStoreItem_InInventorySlots(CURRENCYTOKEN_SLOT_START,CURRENCYTOKEN_SLOT_END,dest,pProto,count,false,pItem,bag,slot);
9331 if(res!=EQUIP_ERR_OK)
9334 *no_space_count = count + no_similar_count;
9340 if(no_similar_count==0)
9341 return EQUIP_ERR_OK;
9344 *no_space_count = count + no_similar_count;
9345 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS;
9349 /* until proper implementation
9350 else if(false pProto->BagFamily & BAG_FAMILY_MASK_QUEST_ITEMS)
9352 res = _CanStoreItem_InInventorySlots(QUESTBAG_SLOT_START,QUESTBAG_SLOT_END,dest,pProto,count,false,pItem,bag,slot);
9353 if(res!=EQUIP_ERR_OK)
9356 *no_space_count = count + no_similar_count;
9362 if(no_similar_count==0)
9363 return EQUIP_ERR_OK;
9366 *no_space_count = count + no_similar_count;
9367 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS;
9372 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9374 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,false,false,pItem
,bag
,slot
);
9375 if(res
!=EQUIP_ERR_OK
)
9380 if(no_similar_count
==0)
9381 return EQUIP_ERR_OK
;
9384 *no_space_count
= count
+ no_similar_count
;
9385 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9391 res
= _CanStoreItem_InInventorySlots(INVENTORY_SLOT_ITEM_START
,INVENTORY_SLOT_ITEM_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9392 if(res
!=EQUIP_ERR_OK
)
9395 *no_space_count
= count
+ no_similar_count
;
9401 if(no_similar_count
==0)
9402 return EQUIP_ERR_OK
;
9405 *no_space_count
= count
+ no_similar_count
;
9406 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9409 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9411 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,false,true,pItem
,bag
,slot
);
9412 if(res
!=EQUIP_ERR_OK
)
9417 if(no_similar_count
==0)
9418 return EQUIP_ERR_OK
;
9421 *no_space_count
= count
+ no_similar_count
;
9422 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9427 *no_space_count
= count
+ no_similar_count
;
9429 return EQUIP_ERR_INVENTORY_FULL
;
9432 //////////////////////////////////////////////////////////////////////////
9433 uint8
Player::CanStoreItems( Item
**pItems
,int count
) const
9438 int inv_slot_items
[INVENTORY_SLOT_ITEM_END
-INVENTORY_SLOT_ITEM_START
];
9439 int inv_bags
[INVENTORY_SLOT_BAG_END
-INVENTORY_SLOT_BAG_START
][MAX_BAG_SIZE
];
9440 int inv_keys
[KEYRING_SLOT_END
-KEYRING_SLOT_START
];
9441 int inv_pets
[VANITYPET_SLOT_END
-VANITYPET_SLOT_START
];
9442 int inv_tokens
[CURRENCYTOKEN_SLOT_END
-CURRENCYTOKEN_SLOT_START
];
9443 int inv_quests
[QUESTBAG_SLOT_END
-QUESTBAG_SLOT_START
];
9445 memset(inv_slot_items
,0,sizeof(int)*(INVENTORY_SLOT_ITEM_END
-INVENTORY_SLOT_ITEM_START
));
9446 memset(inv_bags
,0,sizeof(int)*(INVENTORY_SLOT_BAG_END
-INVENTORY_SLOT_BAG_START
)*MAX_BAG_SIZE
);
9447 memset(inv_keys
,0,sizeof(int)*(KEYRING_SLOT_END
-KEYRING_SLOT_START
));
9448 memset(inv_pets
,0,sizeof(int)*(VANITYPET_SLOT_END
-VANITYPET_SLOT_START
));
9449 memset(inv_tokens
,0,sizeof(int)*(CURRENCYTOKEN_SLOT_END
-CURRENCYTOKEN_SLOT_START
));
9450 memset(inv_quests
,0,sizeof(int)*(QUESTBAG_SLOT_END
-QUESTBAG_SLOT_START
));
9452 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
9454 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9456 if (pItem2
&& !pItem2
->IsInTrade())
9458 inv_slot_items
[i
-INVENTORY_SLOT_ITEM_START
] = pItem2
->GetCount();
9462 for(int i
= KEYRING_SLOT_START
; i
< KEYRING_SLOT_END
; i
++)
9464 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9466 if (pItem2
&& !pItem2
->IsInTrade())
9468 inv_keys
[i
-KEYRING_SLOT_START
] = pItem2
->GetCount();
9472 for(int i
= VANITYPET_SLOT_START
; i
< VANITYPET_SLOT_END
; i
++)
9474 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9476 if (pItem2
&& !pItem2
->IsInTrade())
9478 inv_pets
[i
-VANITYPET_SLOT_START
] = pItem2
->GetCount();
9482 for(int i
= CURRENCYTOKEN_SLOT_START
; i
< CURRENCYTOKEN_SLOT_END
; i
++)
9484 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9486 if (pItem2
&& !pItem2
->IsInTrade())
9488 inv_tokens
[i
-CURRENCYTOKEN_SLOT_START
] = pItem2
->GetCount();
9492 for(int i
= QUESTBAG_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
9494 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9496 if (pItem2
&& !pItem2
->IsInTrade())
9498 inv_quests
[i
-QUESTBAG_SLOT_START
] = pItem2
->GetCount();
9502 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9504 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
9506 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
9508 pItem2
= GetItemByPos( i
, j
);
9509 if (pItem2
&& !pItem2
->IsInTrade())
9511 inv_bags
[i
-INVENTORY_SLOT_BAG_START
][j
] = pItem2
->GetCount();
9517 // check free space for all items
9518 for (int k
=0;k
<count
;k
++)
9520 Item
*pItem
= pItems
[k
];
9523 if (!pItem
) continue;
9525 sLog
.outDebug( "STORAGE: CanStoreItems %i. item = %u, count = %u", k
+1, pItem
->GetEntry(), pItem
->GetCount());
9526 ItemPrototype
const *pProto
= pItem
->GetProto();
9530 return EQUIP_ERR_ITEM_NOT_FOUND
;
9533 if(pItem
->IsBindedNotWith(GetGUID()))
9534 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
9537 ItemPrototype
const *pBagProto
;
9539 // item is 'one item only'
9540 uint8 res
= CanTakeMoreSimilarItems(pItem
);
9541 if(res
!= EQUIP_ERR_OK
)
9544 // search stack for merge to
9545 if( pProto
->Stackable
!= 1 )
9547 bool b_found
= false;
9549 for(int t
= KEYRING_SLOT_START
; t
< KEYRING_SLOT_END
; t
++)
9551 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9552 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_keys
[t
-KEYRING_SLOT_START
] + pItem
->GetCount() <= pProto
->GetMaxStackSize())
9554 inv_keys
[t
-KEYRING_SLOT_START
] += pItem
->GetCount();
9559 if (b_found
) continue;
9561 for(int t
= VANITYPET_SLOT_START
; t
< VANITYPET_SLOT_END
; t
++)
9563 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9564 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_pets
[t
-VANITYPET_SLOT_START
] + pItem
->GetCount() <= pProto
->GetMaxStackSize())
9566 inv_pets
[t
-VANITYPET_SLOT_START
] += pItem
->GetCount();
9571 if (b_found
) continue;
9573 for(int t
= CURRENCYTOKEN_SLOT_START
; t
< CURRENCYTOKEN_SLOT_END
; t
++)
9575 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9576 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_tokens
[t
-CURRENCYTOKEN_SLOT_START
] + pItem
->GetCount() <= pProto
->GetMaxStackSize())
9578 inv_tokens
[t
-CURRENCYTOKEN_SLOT_START
] += pItem
->GetCount();
9583 if (b_found
) continue;
9585 for(int t
= QUESTBAG_SLOT_START
; t
< QUESTBAG_SLOT_END
; t
++)
9587 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9588 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_quests
[t
-QUESTBAG_SLOT_START
] + pItem
->GetCount() <= pProto
->GetMaxStackSize())
9590 inv_quests
[t
-QUESTBAG_SLOT_START
] += pItem
->GetCount();
9595 if (b_found
) continue;
9597 for(int t
= INVENTORY_SLOT_ITEM_START
; t
< INVENTORY_SLOT_ITEM_END
; t
++)
9599 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9600 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_slot_items
[t
-INVENTORY_SLOT_ITEM_START
] + pItem
->GetCount() <= pProto
->GetMaxStackSize())
9602 inv_slot_items
[t
-INVENTORY_SLOT_ITEM_START
] += pItem
->GetCount();
9607 if (b_found
) continue;
9609 for(int t
= INVENTORY_SLOT_BAG_START
; !b_found
&& t
< INVENTORY_SLOT_BAG_END
; t
++)
9611 pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9614 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
9616 pItem2
= GetItemByPos( t
, j
);
9617 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] + pItem
->GetCount() <= pProto
->GetMaxStackSize())
9619 inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] += pItem
->GetCount();
9626 if (b_found
) continue;
9630 if( pProto
->BagFamily
)
9632 bool b_found
= false;
9633 if(pProto
->BagFamily
& BAG_FAMILY_MASK_KEYS
)
9635 uint32 keyringSize
= GetMaxKeyringSize();
9636 for(uint32 t
= KEYRING_SLOT_START
; t
< KEYRING_SLOT_START
+keyringSize
; ++t
)
9638 if( inv_keys
[t
-KEYRING_SLOT_START
] == 0 )
9640 inv_keys
[t
-KEYRING_SLOT_START
] = 1;
9647 if (b_found
) continue;
9649 /* until proper implementation
9650 if(pProto->BagFamily & BAG_FAMILY_MASK_VANITY_PETS)
9652 for(uint32 t = VANITYPET_SLOT_START; t < VANITYPET_SLOT_END; ++t)
9654 if( inv_pets[t-VANITYPET_SLOT_START] == 0 )
9656 inv_pets[t-VANITYPET_SLOT_START] = 1;
9663 if (b_found) continue;
9665 /* until proper implementation
9666 if(pProto->BagFamily & BAG_FAMILY_MASK_CURRENCY_TOKENS)
9668 for(uint32 t = CURRENCYTOKEN_SLOT_START; t < CURRENCYTOKEN_SLOT_END; ++t)
9670 if( inv_tokens[t-CURRENCYTOKEN_SLOT_START] == 0 )
9672 inv_tokens[t-CURRENCYTOKEN_SLOT_START] = 1;
9679 if (b_found) continue;
9681 /* until proper implementation
9682 if(pProto->BagFamily & BAG_FAMILY_MASK_QUEST_ITEMS)
9684 for(uint32 t = QUESTBAG_SLOT_START; t < QUESTBAG_SLOT_END; ++t)
9686 if( inv_quests[t-QUESTBAG_SLOT_START] == 0 )
9688 inv_quests[t-QUESTBAG_SLOT_START] = 1;
9695 if (b_found) continue;
9698 for(int t
= INVENTORY_SLOT_BAG_START
; !b_found
&& t
< INVENTORY_SLOT_BAG_END
; t
++)
9700 pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9703 pBagProto
= pBag
->GetProto();
9705 // not plain container check
9706 if( pBagProto
&& (pBagProto
->Class
!= ITEM_CLASS_CONTAINER
|| pBagProto
->SubClass
!= ITEM_SUBCLASS_CONTAINER
) &&
9707 ItemCanGoIntoBag(pProto
,pBagProto
) )
9709 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
9711 if( inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] == 0 )
9713 inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] = 1;
9721 if (b_found
) continue;
9725 bool b_found
= false;
9726 for(int t
= INVENTORY_SLOT_ITEM_START
; t
< INVENTORY_SLOT_ITEM_END
; t
++)
9728 if( inv_slot_items
[t
-INVENTORY_SLOT_ITEM_START
] == 0 )
9730 inv_slot_items
[t
-INVENTORY_SLOT_ITEM_START
] = 1;
9735 if (b_found
) continue;
9737 // search free slot in bags
9738 for(int t
= INVENTORY_SLOT_BAG_START
; !b_found
&& t
< INVENTORY_SLOT_BAG_END
; t
++)
9740 pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9743 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
9745 if( inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] == 0 )
9747 inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] = 1;
9755 // no free slot found?
9757 return EQUIP_ERR_INVENTORY_FULL
;
9760 return EQUIP_ERR_OK
;
9763 //////////////////////////////////////////////////////////////////////////
9764 uint8
Player::CanEquipNewItem( uint8 slot
, uint16
&dest
, uint32 item
, bool swap
) const
9767 Item
*pItem
= Item::CreateItem( item
, 1, this );
9770 uint8 result
= CanEquipItem(slot
, dest
, pItem
, swap
);
9775 return EQUIP_ERR_ITEM_NOT_FOUND
;
9778 uint8
Player::CanEquipItem( uint8 slot
, uint16
&dest
, Item
*pItem
, bool swap
, bool not_loading
) const
9783 sLog
.outDebug( "STORAGE: CanEquipItem slot = %u, item = %u, count = %u", slot
, pItem
->GetEntry(), pItem
->GetCount());
9784 ItemPrototype
const *pProto
= pItem
->GetProto();
9787 // May be here should be more stronger checks; STUNNED checked
9788 // ROOT, CONFUSED, DISTRACTED, FLEEING this needs to be checked.
9789 if (not_loading
&& hasUnitState(UNIT_STAT_STUNNED
))
9790 return EQUIP_ERR_YOU_ARE_STUNNED
;
9792 if(pItem
->IsBindedNotWith(GetGUID()))
9793 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
9795 // check count of items (skip for auto move for same player from bank)
9796 uint8 res
= CanTakeMoreSimilarItems(pItem
);
9797 if(res
!= EQUIP_ERR_OK
)
9800 // do not allow equipping gear except weapons, offhands, projectiles, relics in
9802 // - in-progress arenas
9803 if( !pProto
->CanChangeEquipStateInCombat() )
9806 return EQUIP_ERR_NOT_IN_COMBAT
;
9808 if(BattleGround
* bg
= GetBattleGround())
9809 if( bg
->isArena() && bg
->GetStatus() == STATUS_IN_PROGRESS
)
9810 return EQUIP_ERR_NOT_DURING_ARENA_MATCH
;
9813 if(isInCombat()&& pProto
->Class
== ITEM_CLASS_WEAPON
&& m_weaponChangeTimer
!= 0)
9814 return EQUIP_ERR_CANT_DO_RIGHT_NOW
; // maybe exist better err
9816 if(IsNonMeleeSpellCasted(false))
9817 return EQUIP_ERR_CANT_DO_RIGHT_NOW
;
9819 uint8 eslot
= FindEquipSlot( pProto
, slot
, swap
);
9820 if( eslot
== NULL_SLOT
)
9821 return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED
;
9823 uint8 msg
= CanUseItem( pItem
, not_loading
);
9824 if( msg
!= EQUIP_ERR_OK
)
9826 if( !swap
&& GetItemByPos( INVENTORY_SLOT_BAG_0
, eslot
) )
9827 return EQUIP_ERR_NO_EQUIPMENT_SLOT_AVAILABLE
;
9829 // check unique-equipped on item
9830 if (pProto
->Flags
& ITEM_FLAGS_UNIQUE_EQUIPPED
)
9832 // there is an equip limit on this item
9833 Item
* tItem
= GetItemOrItemWithGemEquipped(pProto
->ItemId
);
9834 if (tItem
&& (!swap
|| tItem
->GetSlot() != eslot
) )
9835 return EQUIP_ERR_ITEM_UNIQUE_EQUIPABLE
;
9838 // check unique-equipped on gems
9839 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
9841 uint32 enchant_id
= pItem
->GetEnchantmentId(EnchantmentSlot(enchant_slot
));
9844 SpellItemEnchantmentEntry
const* enchantEntry
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
9848 ItemPrototype
const* pGem
= objmgr
.GetItemPrototype(enchantEntry
->GemID
);
9849 if(pGem
&& (pGem
->Flags
& ITEM_FLAGS_UNIQUE_EQUIPPED
))
9851 Item
* tItem
= GetItemOrItemWithGemEquipped(enchantEntry
->GemID
);
9852 if(tItem
&& (!swap
|| tItem
->GetSlot() != eslot
))
9853 return EQUIP_ERR_ITEM_UNIQUE_EQUIPABLE
;
9857 // check unique-equipped special item classes
9858 if (pProto
->Class
== ITEM_CLASS_QUIVER
)
9860 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; ++i
)
9862 if( Item
* pBag
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
) )
9864 if( ItemPrototype
const* pBagProto
= pBag
->GetProto() )
9866 if( pBagProto
->Class
==pProto
->Class
&& pBagProto
->SubClass
==pProto
->SubClass
&&
9867 (!swap
|| pBag
->GetSlot() != eslot
) )
9869 if(pBagProto
->SubClass
== ITEM_SUBCLASS_AMMO_POUCH
)
9870 return EQUIP_ERR_CAN_EQUIP_ONLY1_AMMOPOUCH
;
9872 return EQUIP_ERR_CAN_EQUIP_ONLY1_QUIVER
;
9879 uint32 type
= pProto
->InventoryType
;
9881 if(eslot
== EQUIPMENT_SLOT_OFFHAND
)
9883 if (type
== INVTYPE_WEAPON
|| type
== INVTYPE_WEAPONOFFHAND
)
9886 return EQUIP_ERR_CANT_DUAL_WIELD
;
9888 else if (type
== INVTYPE_2HWEAPON
)
9890 if(!CanDualWield() || !CanTitanGrip())
9891 return EQUIP_ERR_CANT_DUAL_WIELD
;
9895 return EQUIP_ERR_CANT_EQUIP_WITH_TWOHANDED
;
9898 // equip two-hand weapon case (with possible unequip 2 items)
9899 if( type
== INVTYPE_2HWEAPON
)
9901 if (eslot
== EQUIPMENT_SLOT_OFFHAND
)
9903 if (!CanTitanGrip())
9904 return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED
;
9906 else if (eslot
!= EQUIPMENT_SLOT_MAINHAND
)
9907 return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED
;
9909 if (!CanTitanGrip())
9911 // offhand item must can be stored in inventory for offhand item and it also must be unequipped
9912 Item
*offItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
9913 ItemPosCountVec off_dest
;
9914 if( offItem
&& (!not_loading
||
9915 CanUnequipItem(uint16(INVENTORY_SLOT_BAG_0
) << 8 | EQUIPMENT_SLOT_OFFHAND
,false) != EQUIP_ERR_OK
||
9916 CanStoreItem( NULL_BAG
, NULL_SLOT
, off_dest
, offItem
, false ) != EQUIP_ERR_OK
) )
9917 return swap
? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
: EQUIP_ERR_INVENTORY_FULL
;
9920 dest
= ((INVENTORY_SLOT_BAG_0
<< 8) | eslot
);
9921 return EQUIP_ERR_OK
;
9925 return EQUIP_ERR_ITEM_NOT_FOUND
;
9927 return EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
;
9930 uint8
Player::CanUnequipItem( uint16 pos
, bool swap
) const
9932 // Applied only to equipped items and bank bags
9933 if(!IsEquipmentPos(pos
) && !IsBagPos(pos
))
9934 return EQUIP_ERR_OK
;
9936 Item
* pItem
= GetItemByPos(pos
);
9938 // Applied only to existed equipped item
9940 return EQUIP_ERR_OK
;
9942 sLog
.outDebug( "STORAGE: CanUnequipItem slot = %u, item = %u, count = %u", pos
, pItem
->GetEntry(), pItem
->GetCount());
9944 ItemPrototype
const *pProto
= pItem
->GetProto();
9946 return EQUIP_ERR_ITEM_NOT_FOUND
;
9948 // do not allow unequipping gear except weapons, offhands, projectiles, relics in
9950 // - in-progress arenas
9951 if( !pProto
->CanChangeEquipStateInCombat() )
9954 return EQUIP_ERR_NOT_IN_COMBAT
;
9956 if(BattleGround
* bg
= GetBattleGround())
9957 if( bg
->isArena() && bg
->GetStatus() == STATUS_IN_PROGRESS
)
9958 return EQUIP_ERR_NOT_DURING_ARENA_MATCH
;
9961 if(!swap
&& pItem
->IsBag() && !((Bag
*)pItem
)->IsEmpty())
9962 return EQUIP_ERR_CAN_ONLY_DO_WITH_EMPTY_BAGS
;
9964 return EQUIP_ERR_OK
;
9967 uint8
Player::CanBankItem( uint8 bag
, uint8 slot
, ItemPosCountVec
&dest
, Item
*pItem
, bool swap
, bool not_loading
) const
9970 return swap
? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
: EQUIP_ERR_ITEM_NOT_FOUND
;
9972 uint32 count
= pItem
->GetCount();
9974 sLog
.outDebug( "STORAGE: CanBankItem bag = %u, slot = %u, item = %u, count = %u", bag
, slot
, pItem
->GetEntry(), pItem
->GetCount());
9975 ItemPrototype
const *pProto
= pItem
->GetProto();
9977 return swap
? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
: EQUIP_ERR_ITEM_NOT_FOUND
;
9979 if( pItem
->IsBindedNotWith(GetGUID()) )
9980 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
9982 // check count of items (skip for auto move for same player from bank)
9983 uint8 res
= CanTakeMoreSimilarItems(pItem
);
9984 if(res
!= EQUIP_ERR_OK
)
9988 if( bag
!= NULL_BAG
&& slot
!= NULL_SLOT
)
9990 if( pProto
->InventoryType
== INVTYPE_BAG
)
9992 Bag
*pBag
= (Bag
*)pItem
;
9995 if( slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
)
9997 if( !HasBankBagSlot( slot
) )
9998 return EQUIP_ERR_MUST_PURCHASE_THAT_BAG_SLOT
;
9999 if( uint8 cantuse
= CanUseItem( pItem
, not_loading
) != EQUIP_ERR_OK
)
10004 if( !pBag
->IsEmpty() )
10005 return EQUIP_ERR_NONEMPTY_BAG_OVER_OTHER_BAG
;
10011 if( slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
)
10012 return EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT
;
10015 res
= _CanStoreItem_InSpecificSlot(bag
,slot
,dest
,pProto
,count
,swap
,pItem
);
10016 if(res
!=EQUIP_ERR_OK
)
10020 return EQUIP_ERR_OK
;
10023 // not specific slot or have space for partly store only in specific slot
10026 if( bag
!= NULL_BAG
)
10028 if( pProto
->InventoryType
== INVTYPE_BAG
)
10030 Bag
*pBag
= (Bag
*)pItem
;
10031 if( pBag
&& !pBag
->IsEmpty() )
10032 return EQUIP_ERR_NONEMPTY_BAG_OVER_OTHER_BAG
;
10035 // search stack in bag for merge to
10036 if( pProto
->Stackable
!= 1 )
10038 if( bag
== INVENTORY_SLOT_BAG_0
)
10040 res
= _CanStoreItem_InInventorySlots(BANK_SLOT_ITEM_START
,BANK_SLOT_ITEM_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
10041 if(res
!=EQUIP_ERR_OK
)
10045 return EQUIP_ERR_OK
;
10049 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,true,false,pItem
,NULL_BAG
,slot
);
10050 if(res
!=EQUIP_ERR_OK
)
10051 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,true,true,pItem
,NULL_BAG
,slot
);
10053 if(res
!=EQUIP_ERR_OK
)
10057 return EQUIP_ERR_OK
;
10061 // search free slot in bag
10062 if( bag
== INVENTORY_SLOT_BAG_0
)
10064 res
= _CanStoreItem_InInventorySlots(BANK_SLOT_ITEM_START
,BANK_SLOT_ITEM_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
10065 if(res
!=EQUIP_ERR_OK
)
10069 return EQUIP_ERR_OK
;
10073 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,false,false,pItem
,NULL_BAG
,slot
);
10074 if(res
!=EQUIP_ERR_OK
)
10075 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,false,true,pItem
,NULL_BAG
,slot
);
10077 if(res
!=EQUIP_ERR_OK
)
10081 return EQUIP_ERR_OK
;
10085 // not specific bag or have space for partly store only in specific bag
10087 // search stack for merge to
10088 if( pProto
->Stackable
!= 1 )
10091 res
= _CanStoreItem_InInventorySlots(BANK_SLOT_ITEM_START
,BANK_SLOT_ITEM_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
10092 if(res
!=EQUIP_ERR_OK
)
10096 return EQUIP_ERR_OK
;
10099 if( pProto
->BagFamily
)
10101 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
10103 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,true,false,pItem
,bag
,slot
);
10104 if(res
!=EQUIP_ERR_OK
)
10108 return EQUIP_ERR_OK
;
10112 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
10114 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,true,true,pItem
,bag
,slot
);
10115 if(res
!=EQUIP_ERR_OK
)
10119 return EQUIP_ERR_OK
;
10123 // search free place in special bag
10124 if( pProto
->BagFamily
)
10126 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
10128 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,false,false,pItem
,bag
,slot
);
10129 if(res
!=EQUIP_ERR_OK
)
10133 return EQUIP_ERR_OK
;
10137 // search free space
10138 res
= _CanStoreItem_InInventorySlots(BANK_SLOT_ITEM_START
,BANK_SLOT_ITEM_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
10139 if(res
!=EQUIP_ERR_OK
)
10143 return EQUIP_ERR_OK
;
10145 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
10147 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,false,true,pItem
,bag
,slot
);
10148 if(res
!=EQUIP_ERR_OK
)
10152 return EQUIP_ERR_OK
;
10154 return EQUIP_ERR_BANK_FULL
;
10157 uint8
Player::CanUseItem( Item
*pItem
, bool not_loading
) const
10161 sLog
.outDebug( "STORAGE: CanUseItem item = %u", pItem
->GetEntry());
10162 if( !isAlive() && not_loading
)
10163 return EQUIP_ERR_YOU_ARE_DEAD
;
10164 //if( isStunned() )
10165 // return EQUIP_ERR_YOU_ARE_STUNNED;
10166 ItemPrototype
const *pProto
= pItem
->GetProto();
10169 if( pItem
->IsBindedNotWith(GetGUID()) )
10170 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
10171 if( (pProto
->AllowableClass
& getClassMask()) == 0 || (pProto
->AllowableRace
& getRaceMask()) == 0 )
10172 return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM
;
10173 if( pItem
->GetSkill() != 0 )
10175 if( GetSkillValue( pItem
->GetSkill() ) == 0 )
10176 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10178 if( pProto
->RequiredSkill
!= 0 )
10180 if( GetSkillValue( pProto
->RequiredSkill
) == 0 )
10181 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10182 else if( GetSkillValue( pProto
->RequiredSkill
) < pProto
->RequiredSkillRank
)
10183 return EQUIP_ERR_ERR_CANT_EQUIP_SKILL
;
10185 if( pProto
->RequiredSpell
!= 0 && !HasSpell( pProto
->RequiredSpell
) )
10186 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10187 if( pProto
->RequiredReputationFaction
&& uint32(GetReputationRank(pProto
->RequiredReputationFaction
)) < pProto
->RequiredReputationRank
)
10188 return EQUIP_ERR_CANT_EQUIP_REPUTATION
;
10189 if( getLevel() < pProto
->RequiredLevel
)
10190 return EQUIP_ERR_CANT_EQUIP_LEVEL_I
;
10191 return EQUIP_ERR_OK
;
10194 return EQUIP_ERR_ITEM_NOT_FOUND
;
10197 bool Player::CanUseItem( ItemPrototype
const *pProto
)
10199 // Used by group, function NeedBeforeGreed, to know if a prototype can be used by a player
10203 if( (pProto
->AllowableClass
& getClassMask()) == 0 || (pProto
->AllowableRace
& getRaceMask()) == 0 )
10205 if( pProto
->RequiredSkill
!= 0 )
10207 if( GetSkillValue( pProto
->RequiredSkill
) == 0 )
10209 else if( GetSkillValue( pProto
->RequiredSkill
) < pProto
->RequiredSkillRank
)
10212 if( pProto
->RequiredSpell
!= 0 && !HasSpell( pProto
->RequiredSpell
) )
10214 if( getLevel() < pProto
->RequiredLevel
)
10221 uint8
Player::CanUseAmmo( uint32 item
) const
10223 sLog
.outDebug( "STORAGE: CanUseAmmo item = %u", item
);
10225 return EQUIP_ERR_YOU_ARE_DEAD
;
10226 //if( isStunned() )
10227 // return EQUIP_ERR_YOU_ARE_STUNNED;
10228 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( item
);
10231 if( pProto
->InventoryType
!= INVTYPE_AMMO
)
10232 return EQUIP_ERR_ONLY_AMMO_CAN_GO_HERE
;
10233 if( (pProto
->AllowableClass
& getClassMask()) == 0 || (pProto
->AllowableRace
& getRaceMask()) == 0 )
10234 return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM
;
10235 if( pProto
->RequiredSkill
!= 0 )
10237 if( GetSkillValue( pProto
->RequiredSkill
) == 0 )
10238 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10239 else if( GetSkillValue( pProto
->RequiredSkill
) < pProto
->RequiredSkillRank
)
10240 return EQUIP_ERR_ERR_CANT_EQUIP_SKILL
;
10242 if( pProto
->RequiredSpell
!= 0 && !HasSpell( pProto
->RequiredSpell
) )
10243 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10244 /*if( GetReputation() < pProto->RequiredReputation )
10245 return EQUIP_ERR_CANT_EQUIP_REPUTATION;
10247 if( getLevel() < pProto
->RequiredLevel
)
10248 return EQUIP_ERR_CANT_EQUIP_LEVEL_I
;
10250 // Requires No Ammo
10251 if(GetDummyAura(46699))
10252 return EQUIP_ERR_BAG_FULL6
;
10254 return EQUIP_ERR_OK
;
10256 return EQUIP_ERR_ITEM_NOT_FOUND
;
10259 void Player::SetAmmo( uint32 item
)
10265 if( GetUInt32Value(PLAYER_AMMO_ID
) == item
)
10271 uint8 msg
= CanUseAmmo( item
);
10272 if( msg
!= EQUIP_ERR_OK
)
10274 SendEquipError( msg
, NULL
, NULL
);
10279 SetUInt32Value(PLAYER_AMMO_ID
, item
);
10281 _ApplyAmmoBonuses();
10284 void Player::RemoveAmmo()
10286 SetUInt32Value(PLAYER_AMMO_ID
, 0);
10290 if(CanModifyStats())
10291 UpdateDamagePhysical(RANGED_ATTACK
);
10294 // Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case.
10295 Item
* Player::StoreNewItem( ItemPosCountVec
const& dest
, uint32 item
, bool update
,int32 randomPropertyId
)
10298 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
10299 count
+= itr
->count
;
10301 Item
*pItem
= Item::CreateItem( item
, count
, this );
10304 ItemAddedQuestCheck( item
, count
);
10305 if(randomPropertyId
)
10306 pItem
->SetItemRandomProperties(randomPropertyId
);
10307 pItem
= StoreItem( dest
, pItem
, update
);
10312 Item
* Player::StoreItem( ItemPosCountVec
const& dest
, Item
* pItem
, bool update
)
10317 Item
* lastItem
= pItem
;
10319 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); )
10321 uint16 pos
= itr
->pos
;
10322 uint32 count
= itr
->count
;
10326 if(itr
== dest
.end())
10328 lastItem
= _StoreItem(pos
,pItem
,count
,false,update
);
10332 lastItem
= _StoreItem(pos
,pItem
,count
,true,update
);
10338 // Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case.
10339 Item
* Player::_StoreItem( uint16 pos
, Item
*pItem
, uint32 count
, bool clone
, bool update
)
10344 uint8 bag
= pos
>> 8;
10345 uint8 slot
= pos
& 255;
10347 sLog
.outDebug( "STORAGE: StoreItem bag = %u, slot = %u, item = %u, count = %u", bag
, slot
, pItem
->GetEntry(), count
);
10349 Item
*pItem2
= GetItemByPos( bag
, slot
);
10354 pItem
= pItem
->CloneItem(count
,this);
10356 pItem
->SetCount(count
);
10361 if( pItem
->GetProto()->Bonding
== BIND_WHEN_PICKED_UP
||
10362 pItem
->GetProto()->Bonding
== BIND_QUEST_ITEM
||
10363 pItem
->GetProto()->Bonding
== BIND_WHEN_EQUIPED
&& IsBagPos(pos
) )
10364 pItem
->SetBinding( true );
10366 if( bag
== INVENTORY_SLOT_BAG_0
)
10368 m_items
[slot
] = pItem
;
10369 SetUInt64Value( (uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
* 2) ), pItem
->GetGUID() );
10370 pItem
->SetUInt64Value( ITEM_FIELD_CONTAINED
, GetGUID() );
10371 pItem
->SetUInt64Value( ITEM_FIELD_OWNER
, GetGUID() );
10373 pItem
->SetSlot( slot
);
10374 pItem
->SetContainer( NULL
);
10376 if( IsInWorld() && update
)
10378 pItem
->AddToWorld();
10379 pItem
->SendUpdateToPlayer( this );
10382 pItem
->SetState(ITEM_CHANGED
, this);
10386 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
10389 pBag
->StoreItem( slot
, pItem
, update
);
10390 if( IsInWorld() && update
)
10392 pItem
->AddToWorld();
10393 pItem
->SendUpdateToPlayer( this );
10395 pItem
->SetState(ITEM_CHANGED
, this);
10396 pBag
->SetState(ITEM_CHANGED
, this);
10400 AddEnchantmentDurations(pItem
);
10401 AddItemDurations(pItem
);
10407 if( pItem2
->GetProto()->Bonding
== BIND_WHEN_PICKED_UP
||
10408 pItem2
->GetProto()->Bonding
== BIND_QUEST_ITEM
||
10409 pItem2
->GetProto()->Bonding
== BIND_WHEN_EQUIPED
&& IsBagPos(pos
) )
10410 pItem2
->SetBinding( true );
10412 pItem2
->SetCount( pItem2
->GetCount() + count
);
10413 if( IsInWorld() && update
)
10414 pItem2
->SendUpdateToPlayer( this );
10418 // delete item (it not in any slot currently)
10419 if( IsInWorld() && update
)
10421 pItem
->RemoveFromWorld();
10422 pItem
->DestroyForPlayer( this );
10425 RemoveEnchantmentDurations(pItem
);
10426 RemoveItemDurations(pItem
);
10428 pItem
->SetOwnerGUID(GetGUID()); // prevent error at next SetState in case trade/mail/buy from vendor
10429 pItem
->SetState(ITEM_REMOVED
, this);
10431 // AddItemDurations(pItem2); - pItem2 already have duration listed for player
10432 AddEnchantmentDurations(pItem2
);
10434 pItem2
->SetState(ITEM_CHANGED
, this);
10440 Item
* Player::EquipNewItem( uint16 pos
, uint32 item
, bool update
)
10442 Item
*pItem
= Item::CreateItem( item
, 1, this );
10445 ItemAddedQuestCheck( item
, 1 );
10446 Item
* retItem
= EquipItem( pos
, pItem
, update
);
10453 Item
* Player::EquipItem( uint16 pos
, Item
*pItem
, bool update
)
10457 AddEnchantmentDurations(pItem
);
10458 AddItemDurations(pItem
);
10460 uint8 bag
= pos
>> 8;
10461 uint8 slot
= pos
& 255;
10463 Item
*pItem2
= GetItemByPos( bag
, slot
);
10467 VisualizeItem( slot
, pItem
);
10471 ItemPrototype
const *pProto
= pItem
->GetProto();
10473 // item set bonuses applied only at equip and removed at unequip, and still active for broken items
10474 if(pProto
&& pProto
->ItemSet
)
10475 AddItemsSetItem(this,pItem
);
10477 _ApplyItemMods(pItem
, slot
, true);
10479 if(pProto
&& isInCombat()&& pProto
->Class
== ITEM_CLASS_WEAPON
&& m_weaponChangeTimer
== 0)
10481 uint32 cooldownSpell
= SPELL_ID_WEAPON_SWITCH_COOLDOWN_1_5s
;
10483 if (getClass() == CLASS_ROGUE
)
10484 cooldownSpell
= SPELL_ID_WEAPON_SWITCH_COOLDOWN_1_0s
;
10486 SpellEntry
const* spellProto
= sSpellStore
.LookupEntry(cooldownSpell
);
10489 sLog
.outError("Weapon switch cooldown spell %u couldn't be found in Spell.dbc", cooldownSpell
);
10492 m_weaponChangeTimer
= spellProto
->StartRecoveryTime
;
10494 WorldPacket
data(SMSG_SPELL_COOLDOWN
, 8+1+4);
10495 data
<< uint64(GetGUID());
10497 data
<< uint32(cooldownSpell
);
10499 GetSession()->SendPacket(&data
);
10504 if( IsInWorld() && update
)
10506 pItem
->AddToWorld();
10507 pItem
->SendUpdateToPlayer( this );
10510 ApplyEquipCooldown(pItem
);
10512 if( slot
== EQUIPMENT_SLOT_MAINHAND
)
10513 UpdateExpertise(BASE_ATTACK
);
10514 else if( slot
== EQUIPMENT_SLOT_OFFHAND
)
10515 UpdateExpertise(OFF_ATTACK
);
10519 pItem2
->SetCount( pItem2
->GetCount() + pItem
->GetCount() );
10520 if( IsInWorld() && update
)
10521 pItem2
->SendUpdateToPlayer( this );
10523 // delete item (it not in any slot currently)
10524 //pItem->DeleteFromDB();
10525 if( IsInWorld() && update
)
10527 pItem
->RemoveFromWorld();
10528 pItem
->DestroyForPlayer( this );
10531 RemoveEnchantmentDurations(pItem
);
10532 RemoveItemDurations(pItem
);
10534 pItem
->SetOwnerGUID(GetGUID()); // prevent error at next SetState in case trade/mail/buy from vendor
10535 pItem
->SetState(ITEM_REMOVED
, this);
10536 pItem2
->SetState(ITEM_CHANGED
, this);
10538 ApplyEquipCooldown(pItem2
);
10547 void Player::QuickEquipItem( uint16 pos
, Item
*pItem
)
10551 AddEnchantmentDurations(pItem
);
10552 AddItemDurations(pItem
);
10554 uint8 slot
= pos
& 255;
10555 VisualizeItem( slot
, pItem
);
10559 pItem
->AddToWorld();
10560 pItem
->SendUpdateToPlayer( this );
10565 void Player::SetVisibleItemSlot(uint8 slot
, Item
*pItem
)
10567 // PLAYER_VISIBLE_ITEM_i_CREATOR // Size: 2
10568 // PLAYER_VISIBLE_ITEM_i_0 // Size: 12
10569 // entry // Size: 1
10570 // inspected enchantments // Size: 6
10572 // PLAYER_VISIBLE_ITEM_i_PROPERTIES // Size: 1 (property,suffix factor)
10573 // PLAYER_VISIBLE_ITEM_i_PAD // Size: 1
10578 SetUInt64Value(PLAYER_VISIBLE_ITEM_1_CREATOR
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
), pItem
->GetUInt64Value(ITEM_FIELD_CREATOR
));
10580 int VisibleBase
= PLAYER_VISIBLE_ITEM_1_0
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
);
10581 SetUInt32Value(VisibleBase
+ 0, pItem
->GetEntry());
10583 for(int i
= 0; i
< MAX_INSPECTED_ENCHANTMENT_SLOT
; ++i
)
10584 SetUInt32Value(VisibleBase
+ 1 + i
, pItem
->GetEnchantmentId(EnchantmentSlot(i
)));
10586 // Use SetInt16Value to prevent set high part to FFFF for negative value
10587 SetInt16Value( PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
), 0, pItem
->GetItemRandomPropertyId());
10588 SetUInt32Value(PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ 1 + (slot
* MAX_VISIBLE_ITEM_OFFSET
), pItem
->GetItemSuffixFactor());
10592 SetUInt64Value(PLAYER_VISIBLE_ITEM_1_CREATOR
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
), 0);
10594 int VisibleBase
= PLAYER_VISIBLE_ITEM_1_0
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
);
10595 SetUInt32Value(VisibleBase
+ 0, 0);
10597 for(int i
= 0; i
< MAX_INSPECTED_ENCHANTMENT_SLOT
; ++i
)
10598 SetUInt32Value(VisibleBase
+ 1 + i
, 0);
10600 SetUInt32Value(PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ 0 + (slot
* MAX_VISIBLE_ITEM_OFFSET
), 0);
10601 SetUInt32Value(PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ 1 + (slot
* MAX_VISIBLE_ITEM_OFFSET
), 0);
10605 void Player::VisualizeItem( uint8 slot
, Item
*pItem
)
10610 // check also BIND_WHEN_PICKED_UP and BIND_QUEST_ITEM for .additem or .additemset case by GM (not binded at adding to inventory)
10611 if( pItem
->GetProto()->Bonding
== BIND_WHEN_EQUIPED
|| pItem
->GetProto()->Bonding
== BIND_WHEN_PICKED_UP
|| pItem
->GetProto()->Bonding
== BIND_QUEST_ITEM
)
10612 pItem
->SetBinding( true );
10614 sLog
.outDebug( "STORAGE: EquipItem slot = %u, item = %u", slot
, pItem
->GetEntry());
10616 m_items
[slot
] = pItem
;
10617 SetUInt64Value( (uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
* 2) ), pItem
->GetGUID() );
10618 pItem
->SetUInt64Value( ITEM_FIELD_CONTAINED
, GetGUID() );
10619 pItem
->SetUInt64Value( ITEM_FIELD_OWNER
, GetGUID() );
10620 pItem
->SetSlot( slot
);
10621 pItem
->SetContainer( NULL
);
10623 if( slot
< EQUIPMENT_SLOT_END
)
10624 SetVisibleItemSlot(slot
,pItem
);
10626 pItem
->SetState(ITEM_CHANGED
, this);
10629 void Player::RemoveItem( uint8 bag
, uint8 slot
, bool update
)
10631 // note: removeitem does not actually change the item
10632 // it only takes the item out of storage temporarily
10633 // note2: if removeitem is to be used for delinking
10634 // the item must be removed from the player's updatequeue
10636 Item
*pItem
= GetItemByPos( bag
, slot
);
10639 sLog
.outDebug( "STORAGE: RemoveItem bag = %u, slot = %u, item = %u", bag
, slot
, pItem
->GetEntry());
10641 RemoveEnchantmentDurations(pItem
);
10642 RemoveItemDurations(pItem
);
10644 if( bag
== INVENTORY_SLOT_BAG_0
)
10646 if ( slot
< INVENTORY_SLOT_BAG_END
)
10648 ItemPrototype
const *pProto
= pItem
->GetProto();
10649 // item set bonuses applied only at equip and removed at unequip, and still active for broken items
10651 if(pProto
&& pProto
->ItemSet
)
10652 RemoveItemsSetItem(this,pProto
);
10654 _ApplyItemMods(pItem
, slot
, false);
10656 // remove item dependent auras and casts (only weapon and armor slots)
10657 if(slot
< EQUIPMENT_SLOT_END
)
10658 RemoveItemDependentAurasAndCasts(pItem
);
10660 // remove held enchantments
10661 if ( slot
== EQUIPMENT_SLOT_MAINHAND
)
10663 if (pItem
->GetItemSuffixFactor())
10665 pItem
->ClearEnchantment(PROP_ENCHANTMENT_SLOT_3
);
10666 pItem
->ClearEnchantment(PROP_ENCHANTMENT_SLOT_4
);
10670 pItem
->ClearEnchantment(PROP_ENCHANTMENT_SLOT_0
);
10671 pItem
->ClearEnchantment(PROP_ENCHANTMENT_SLOT_1
);
10676 m_items
[slot
] = NULL
;
10677 SetUInt64Value((uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
*2)), 0);
10679 if ( slot
< EQUIPMENT_SLOT_END
)
10680 SetVisibleItemSlot(slot
,NULL
);
10684 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
10686 pBag
->RemoveItem(slot
, update
);
10688 pItem
->SetUInt64Value( ITEM_FIELD_CONTAINED
, 0 );
10689 // pItem->SetUInt64Value( ITEM_FIELD_OWNER, 0 ); not clear owner at remove (it will be set at store). This used in mail and auction code
10690 pItem
->SetSlot( NULL_SLOT
);
10691 if( IsInWorld() && update
)
10692 pItem
->SendUpdateToPlayer( this );
10694 if( slot
== EQUIPMENT_SLOT_MAINHAND
)
10695 UpdateExpertise(BASE_ATTACK
);
10696 else if( slot
== EQUIPMENT_SLOT_OFFHAND
)
10697 UpdateExpertise(OFF_ATTACK
);
10701 // Common operation need to remove item from inventory without delete in trade, auction, guild bank, mail....
10702 void Player::MoveItemFromInventory(uint8 bag
, uint8 slot
, bool update
)
10704 if(Item
* it
= GetItemByPos(bag
,slot
))
10706 ItemRemovedQuestCheck(it
->GetEntry(),it
->GetCount());
10707 RemoveItem( bag
,slot
,update
);
10708 it
->RemoveFromUpdateQueueOf(this);
10709 if(it
->IsInWorld())
10711 it
->RemoveFromWorld();
10712 it
->DestroyForPlayer( this );
10717 // Common operation need to add item from inventory without delete in trade, guild bank, mail....
10718 void Player::MoveItemToInventory(ItemPosCountVec
const& dest
, Item
* pItem
, bool update
, bool in_characterInventoryDB
)
10720 // update quest counters
10721 ItemAddedQuestCheck(pItem
->GetEntry(),pItem
->GetCount());
10724 Item
* pLastItem
= StoreItem( dest
, pItem
, update
);
10726 // only set if not merged to existed stack (pItem can be deleted already but we can compare pointers any way)
10727 if(pLastItem
==pItem
)
10729 // update owner for last item (this can be original item with wrong owner
10730 if(pLastItem
->GetOwnerGUID() != GetGUID())
10731 pLastItem
->SetOwnerGUID(GetGUID());
10733 // if this original item then it need create record in inventory
10734 // in case trade we already have item in other player inventory
10735 pLastItem
->SetState(in_characterInventoryDB
? ITEM_CHANGED
: ITEM_NEW
, this);
10739 void Player::DestroyItem( uint8 bag
, uint8 slot
, bool update
)
10741 Item
*pItem
= GetItemByPos( bag
, slot
);
10744 sLog
.outDebug( "STORAGE: DestroyItem bag = %u, slot = %u, item = %u", bag
, slot
, pItem
->GetEntry());
10746 // start from destroy contained items (only equipped bag can have its)
10747 if (pItem
->IsBag() && pItem
->IsEquipped()) // this also prevent infinity loop if empty bag stored in bag==slot
10749 for (int i
= 0; i
< MAX_BAG_SIZE
; i
++)
10750 DestroyItem(slot
,i
,update
);
10753 if(pItem
->HasFlag(ITEM_FIELD_FLAGS
, ITEM_FLAGS_WRAPPED
))
10754 CharacterDatabase
.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", pItem
->GetGUIDLow());
10756 RemoveEnchantmentDurations(pItem
);
10757 RemoveItemDurations(pItem
);
10759 ItemRemovedQuestCheck( pItem
->GetEntry(), pItem
->GetCount() );
10761 if( bag
== INVENTORY_SLOT_BAG_0
)
10763 SetUInt64Value((uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
*2)), 0);
10765 // equipment and equipped bags can have applied bonuses
10766 if ( slot
< INVENTORY_SLOT_BAG_END
)
10768 ItemPrototype
const *pProto
= pItem
->GetProto();
10770 // item set bonuses applied only at equip and removed at unequip, and still active for broken items
10771 if(pProto
&& pProto
->ItemSet
)
10772 RemoveItemsSetItem(this,pProto
);
10774 _ApplyItemMods(pItem
, slot
, false);
10777 if ( slot
< EQUIPMENT_SLOT_END
)
10779 // remove item dependent auras and casts (only weapon and armor slots)
10780 RemoveItemDependentAurasAndCasts(pItem
);
10782 // equipment visual show
10783 SetVisibleItemSlot(slot
,NULL
);
10786 m_items
[slot
] = NULL
;
10788 else if(Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
))
10789 pBag
->RemoveItem(slot
, update
);
10791 if( IsInWorld() && update
)
10793 pItem
->RemoveFromWorld();
10794 pItem
->DestroyForPlayer(this);
10797 //pItem->SetOwnerGUID(0);
10798 pItem
->SetUInt64Value( ITEM_FIELD_CONTAINED
, 0 );
10799 pItem
->SetSlot( NULL_SLOT
);
10800 pItem
->SetState(ITEM_REMOVED
, this);
10804 void Player::DestroyItemCount( uint32 item
, uint32 count
, bool update
, bool unequip_check
)
10806 sLog
.outDebug( "STORAGE: DestroyItemCount item = %u, count = %u", item
, count
);
10808 ItemPrototype
const *pProto
;
10809 uint32 remcount
= 0;
10812 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
10814 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10815 if( pItem
&& pItem
->GetEntry() == item
)
10817 if( pItem
->GetCount() + remcount
<= count
)
10819 // all items in inventory can unequipped
10820 remcount
+= pItem
->GetCount();
10821 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10823 if(remcount
>=count
)
10828 pProto
= pItem
->GetProto();
10829 ItemRemovedQuestCheck( pItem
->GetEntry(), count
- remcount
);
10830 pItem
->SetCount( pItem
->GetCount() - count
+ remcount
);
10831 if( IsInWorld() & update
)
10832 pItem
->SendUpdateToPlayer( this );
10833 pItem
->SetState(ITEM_CHANGED
, this);
10838 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
10840 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10841 if( pItem
&& pItem
->GetEntry() == item
)
10843 if( pItem
->GetCount() + remcount
<= count
)
10845 // all keys can be unequipped
10846 remcount
+= pItem
->GetCount();
10847 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10849 if(remcount
>=count
)
10854 pProto
= pItem
->GetProto();
10855 ItemRemovedQuestCheck( pItem
->GetEntry(), count
- remcount
);
10856 pItem
->SetCount( pItem
->GetCount() - count
+ remcount
);
10857 if( IsInWorld() & update
)
10858 pItem
->SendUpdateToPlayer( this );
10859 pItem
->SetState(ITEM_CHANGED
, this);
10865 // in inventory bags
10866 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10868 if(Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
10870 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
10872 pItem
= pBag
->GetItemByPos(j
);
10873 if( pItem
&& pItem
->GetEntry() == item
)
10875 // all items in bags can be unequipped
10876 if( pItem
->GetCount() + remcount
<= count
)
10878 remcount
+= pItem
->GetCount();
10879 DestroyItem( i
, j
, update
);
10881 if(remcount
>=count
)
10886 pProto
= pItem
->GetProto();
10887 ItemRemovedQuestCheck( pItem
->GetEntry(), count
- remcount
);
10888 pItem
->SetCount( pItem
->GetCount() - count
+ remcount
);
10889 if( IsInWorld() && update
)
10890 pItem
->SendUpdateToPlayer( this );
10891 pItem
->SetState(ITEM_CHANGED
, this);
10899 // in equipment and bag list
10900 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10902 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10903 if( pItem
&& pItem
->GetEntry() == item
)
10905 if( pItem
->GetCount() + remcount
<= count
)
10907 if(!unequip_check
|| CanUnequipItem(INVENTORY_SLOT_BAG_0
<< 8 | i
,false) == EQUIP_ERR_OK
)
10909 remcount
+= pItem
->GetCount();
10910 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10912 if(remcount
>=count
)
10918 pProto
= pItem
->GetProto();
10919 ItemRemovedQuestCheck( pItem
->GetEntry(), count
- remcount
);
10920 pItem
->SetCount( pItem
->GetCount() - count
+ remcount
);
10921 if( IsInWorld() & update
)
10922 pItem
->SendUpdateToPlayer( this );
10923 pItem
->SetState(ITEM_CHANGED
, this);
10930 void Player::DestroyZoneLimitedItem( bool update
, uint32 new_zone
)
10932 sLog
.outDebug( "STORAGE: DestroyZoneLimitedItem in map %u and area %u", GetMapId(), new_zone
);
10935 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
10937 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10938 if( pItem
&& pItem
->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone
) )
10939 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10941 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
10943 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10944 if( pItem
&& pItem
->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone
) )
10945 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10948 // in inventory bags
10949 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10951 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10954 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
10956 Item
* pItem
= pBag
->GetItemByPos(j
);
10957 if( pItem
&& pItem
->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone
) )
10958 DestroyItem( i
, j
, update
);
10963 // in equipment and bag list
10964 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10966 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10967 if( pItem
&& pItem
->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone
) )
10968 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10972 void Player::DestroyConjuredItems( bool update
)
10974 // used when entering arena
10975 // destroys all conjured items
10976 sLog
.outDebug( "STORAGE: DestroyConjuredItems" );
10979 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
10981 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10982 if( pItem
&& pItem
->GetProto() &&
10983 (pItem
->GetProto()->Class
== ITEM_CLASS_CONSUMABLE
) &&
10984 (pItem
->GetProto()->Flags
& ITEM_FLAGS_CONJURED
) )
10985 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10988 // in inventory bags
10989 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10991 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10994 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
10996 Item
* pItem
= pBag
->GetItemByPos(j
);
10997 if( pItem
&& pItem
->GetProto() &&
10998 (pItem
->GetProto()->Class
== ITEM_CLASS_CONSUMABLE
) &&
10999 (pItem
->GetProto()->Flags
& ITEM_FLAGS_CONJURED
) )
11000 DestroyItem( i
, j
, update
);
11005 // in equipment and bag list
11006 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
11008 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
11009 if( pItem
&& pItem
->GetProto() &&
11010 (pItem
->GetProto()->Class
== ITEM_CLASS_CONSUMABLE
) &&
11011 (pItem
->GetProto()->Flags
& ITEM_FLAGS_CONJURED
) )
11012 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
11016 void Player::DestroyItemCount( Item
* pItem
, uint32
&count
, bool update
)
11021 sLog
.outDebug( "STORAGE: DestroyItemCount item (GUID: %u, Entry: %u) count = %u", pItem
->GetGUIDLow(),pItem
->GetEntry(), count
);
11023 if( pItem
->GetCount() <= count
)
11025 count
-= pItem
->GetCount();
11027 DestroyItem( pItem
->GetBagSlot(),pItem
->GetSlot(), update
);
11031 ItemRemovedQuestCheck( pItem
->GetEntry(), count
);
11032 pItem
->SetCount( pItem
->GetCount() - count
);
11034 if( IsInWorld() & update
)
11035 pItem
->SendUpdateToPlayer( this );
11036 pItem
->SetState(ITEM_CHANGED
, this);
11040 void Player::SplitItem( uint16 src
, uint16 dst
, uint32 count
)
11042 uint8 srcbag
= src
>> 8;
11043 uint8 srcslot
= src
& 255;
11045 uint8 dstbag
= dst
>> 8;
11046 uint8 dstslot
= dst
& 255;
11048 Item
*pSrcItem
= GetItemByPos( srcbag
, srcslot
);
11051 SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, pSrcItem
, NULL
);
11055 // not let split all items (can be only at cheating)
11056 if(pSrcItem
->GetCount() == count
)
11058 SendEquipError( EQUIP_ERR_COULDNT_SPLIT_ITEMS
, pSrcItem
, NULL
);
11062 // not let split more existed items (can be only at cheating)
11063 if(pSrcItem
->GetCount() < count
)
11065 SendEquipError( EQUIP_ERR_TRIED_TO_SPLIT_MORE_THAN_COUNT
, pSrcItem
, NULL
);
11069 if(pSrcItem
->m_lootGenerated
) // prevent split looting item (item
11071 //best error message found for attempting to split while looting
11072 SendEquipError( EQUIP_ERR_COULDNT_SPLIT_ITEMS
, pSrcItem
, NULL
);
11076 sLog
.outDebug( "STORAGE: SplitItem bag = %u, slot = %u, item = %u, count = %u", dstbag
, dstslot
, pSrcItem
->GetEntry(), count
);
11077 Item
*pNewItem
= pSrcItem
->CloneItem( count
, this );
11080 SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, pSrcItem
, NULL
);
11084 if( IsInventoryPos( dst
) )
11086 // change item amount before check (for unique max count check)
11087 pSrcItem
->SetCount( pSrcItem
->GetCount() - count
);
11089 ItemPosCountVec dest
;
11090 uint8 msg
= CanStoreItem( dstbag
, dstslot
, dest
, pNewItem
, false );
11091 if( msg
!= EQUIP_ERR_OK
)
11094 pSrcItem
->SetCount( pSrcItem
->GetCount() + count
);
11095 SendEquipError( msg
, pSrcItem
, NULL
);
11100 pSrcItem
->SendUpdateToPlayer( this );
11101 pSrcItem
->SetState(ITEM_CHANGED
, this);
11102 StoreItem( dest
, pNewItem
, true);
11104 else if( IsBankPos ( dst
) )
11106 // change item amount before check (for unique max count check)
11107 pSrcItem
->SetCount( pSrcItem
->GetCount() - count
);
11109 ItemPosCountVec dest
;
11110 uint8 msg
= CanBankItem( dstbag
, dstslot
, dest
, pNewItem
, false );
11111 if( msg
!= EQUIP_ERR_OK
)
11114 pSrcItem
->SetCount( pSrcItem
->GetCount() + count
);
11115 SendEquipError( msg
, pSrcItem
, NULL
);
11120 pSrcItem
->SendUpdateToPlayer( this );
11121 pSrcItem
->SetState(ITEM_CHANGED
, this);
11122 BankItem( dest
, pNewItem
, true);
11124 else if( IsEquipmentPos ( dst
) )
11126 // change item amount before check (for unique max count check), provide space for splitted items
11127 pSrcItem
->SetCount( pSrcItem
->GetCount() - count
);
11130 uint8 msg
= CanEquipItem( dstslot
, dest
, pNewItem
, false );
11131 if( msg
!= EQUIP_ERR_OK
)
11134 pSrcItem
->SetCount( pSrcItem
->GetCount() + count
);
11135 SendEquipError( msg
, pSrcItem
, NULL
);
11140 pSrcItem
->SendUpdateToPlayer( this );
11141 pSrcItem
->SetState(ITEM_CHANGED
, this);
11142 EquipItem( dest
, pNewItem
, true);
11143 AutoUnequipOffhandIfNeed();
11147 void Player::SwapItem( uint16 src
, uint16 dst
)
11149 uint8 srcbag
= src
>> 8;
11150 uint8 srcslot
= src
& 255;
11152 uint8 dstbag
= dst
>> 8;
11153 uint8 dstslot
= dst
& 255;
11155 Item
*pSrcItem
= GetItemByPos( srcbag
, srcslot
);
11156 Item
*pDstItem
= GetItemByPos( dstbag
, dstslot
);
11161 sLog
.outDebug( "STORAGE: SwapItem bag = %u, slot = %u, item = %u", dstbag
, dstslot
, pSrcItem
->GetEntry());
11165 SendEquipError( EQUIP_ERR_YOU_ARE_DEAD
, pSrcItem
, pDstItem
);
11169 if(pSrcItem
->m_lootGenerated
) // prevent swap looting item
11171 //best error message found for attempting to swap while looting
11172 SendEquipError( EQUIP_ERR_CANT_DO_RIGHT_NOW
, pSrcItem
, NULL
);
11176 // check unequip potability for equipped items and bank bags
11177 if(IsEquipmentPos ( src
) || IsBagPos ( src
))
11179 // bags can be swapped with empty bag slots
11180 uint8 msg
= CanUnequipItem( src
, !IsBagPos ( src
) || IsBagPos ( dst
));
11181 if(msg
!= EQUIP_ERR_OK
)
11183 SendEquipError( msg
, pSrcItem
, pDstItem
);
11188 // prevent put equipped/bank bag in self
11189 if( IsBagPos ( src
) && srcslot
== dstbag
)
11191 SendEquipError( EQUIP_ERR_NONEMPTY_BAG_OVER_OTHER_BAG
, pSrcItem
, pDstItem
);
11197 if( IsInventoryPos( dst
) )
11199 ItemPosCountVec dest
;
11200 uint8 msg
= CanStoreItem( dstbag
, dstslot
, dest
, pSrcItem
, false );
11201 if( msg
!= EQUIP_ERR_OK
)
11203 SendEquipError( msg
, pSrcItem
, NULL
);
11207 RemoveItem(srcbag
, srcslot
, true);
11208 StoreItem( dest
, pSrcItem
, true);
11210 else if( IsBankPos ( dst
) )
11212 ItemPosCountVec dest
;
11213 uint8 msg
= CanBankItem( dstbag
, dstslot
, dest
, pSrcItem
, false);
11214 if( msg
!= EQUIP_ERR_OK
)
11216 SendEquipError( msg
, pSrcItem
, NULL
);
11220 RemoveItem(srcbag
, srcslot
, true);
11221 BankItem( dest
, pSrcItem
, true);
11223 else if( IsEquipmentPos ( dst
) )
11226 uint8 msg
= CanEquipItem( dstslot
, dest
, pSrcItem
, false );
11227 if( msg
!= EQUIP_ERR_OK
)
11229 SendEquipError( msg
, pSrcItem
, NULL
);
11233 RemoveItem(srcbag
, srcslot
, true);
11234 EquipItem( dest
, pSrcItem
, true);
11235 AutoUnequipOffhandIfNeed();
11238 else // if (!pDstItem)
11240 if(pDstItem
->m_lootGenerated
) // prevent swap looting item
11242 //best error message found for attempting to swap while looting
11243 SendEquipError( EQUIP_ERR_CANT_DO_RIGHT_NOW
, pDstItem
, NULL
);
11247 // check unequip potability for equipped items and bank bags
11248 if(IsEquipmentPos ( dst
) || IsBagPos ( dst
))
11250 // bags can be swapped with empty bag slots
11251 uint8 msg
= CanUnequipItem( dst
, !IsBagPos ( dst
) || IsBagPos ( src
) );
11252 if(msg
!= EQUIP_ERR_OK
)
11254 SendEquipError( msg
, pSrcItem
, pDstItem
);
11259 // attempt merge to / fill target item
11262 ItemPosCountVec sDest
;
11264 if( IsInventoryPos( dst
) )
11265 msg
= CanStoreItem( dstbag
, dstslot
, sDest
, pSrcItem
, false );
11266 else if( IsBankPos ( dst
) )
11267 msg
= CanBankItem( dstbag
, dstslot
, sDest
, pSrcItem
, false );
11268 else if( IsEquipmentPos ( dst
) )
11269 msg
= CanEquipItem( dstslot
, eDest
, pSrcItem
, false );
11273 // can be merge/fill
11274 if(msg
== EQUIP_ERR_OK
)
11276 if( pSrcItem
->GetCount() + pDstItem
->GetCount() <= pSrcItem
->GetProto()->GetMaxStackSize())
11278 RemoveItem(srcbag
, srcslot
, true);
11280 if( IsInventoryPos( dst
) )
11281 StoreItem( sDest
, pSrcItem
, true);
11282 else if( IsBankPos ( dst
) )
11283 BankItem( sDest
, pSrcItem
, true);
11284 else if( IsEquipmentPos ( dst
) )
11286 EquipItem( eDest
, pSrcItem
, true);
11287 AutoUnequipOffhandIfNeed();
11292 pSrcItem
->SetCount( pSrcItem
->GetCount() + pDstItem
->GetCount() - pSrcItem
->GetProto()->GetMaxStackSize());
11293 pDstItem
->SetCount( pSrcItem
->GetProto()->GetMaxStackSize());
11294 pSrcItem
->SetState(ITEM_CHANGED
, this);
11295 pDstItem
->SetState(ITEM_CHANGED
, this);
11298 pSrcItem
->SendUpdateToPlayer( this );
11299 pDstItem
->SendUpdateToPlayer( this );
11306 // impossible merge/fill, do real swap
11309 // check src->dest move possibility
11310 ItemPosCountVec sDest
;
11312 if( IsInventoryPos( dst
) )
11313 msg
= CanStoreItem( dstbag
, dstslot
, sDest
, pSrcItem
, true );
11314 else if( IsBankPos( dst
) )
11315 msg
= CanBankItem( dstbag
, dstslot
, sDest
, pSrcItem
, true );
11316 else if( IsEquipmentPos( dst
) )
11318 msg
= CanEquipItem( dstslot
, eDest
, pSrcItem
, true );
11319 if( msg
== EQUIP_ERR_OK
)
11320 msg
= CanUnequipItem( eDest
, true );
11323 if( msg
!= EQUIP_ERR_OK
)
11325 SendEquipError( msg
, pSrcItem
, pDstItem
);
11329 // check dest->src move possibility
11330 ItemPosCountVec sDest2
;
11332 if( IsInventoryPos( src
) )
11333 msg
= CanStoreItem( srcbag
, srcslot
, sDest2
, pDstItem
, true );
11334 else if( IsBankPos( src
) )
11335 msg
= CanBankItem( srcbag
, srcslot
, sDest2
, pDstItem
, true );
11336 else if( IsEquipmentPos( src
) )
11338 msg
= CanEquipItem( srcslot
, eDest2
, pDstItem
, true);
11339 if( msg
== EQUIP_ERR_OK
)
11340 msg
= CanUnequipItem( eDest2
, true);
11343 if( msg
!= EQUIP_ERR_OK
)
11345 SendEquipError( msg
, pDstItem
, pSrcItem
);
11349 // now do moves, remove...
11350 RemoveItem(dstbag
, dstslot
, false);
11351 RemoveItem(srcbag
, srcslot
, false);
11354 if( IsInventoryPos( dst
) )
11355 StoreItem(sDest
, pSrcItem
, true);
11356 else if( IsBankPos( dst
) )
11357 BankItem(sDest
, pSrcItem
, true);
11358 else if( IsEquipmentPos( dst
) )
11359 EquipItem(eDest
, pSrcItem
, true);
11362 if( IsInventoryPos( src
) )
11363 StoreItem(sDest2
, pDstItem
, true);
11364 else if( IsBankPos( src
) )
11365 BankItem(sDest2
, pDstItem
, true);
11366 else if( IsEquipmentPos( src
) )
11367 EquipItem(eDest2
, pDstItem
, true);
11369 AutoUnequipOffhandIfNeed();
11373 void Player::AddItemToBuyBackSlot( Item
*pItem
)
11377 uint32 slot
= m_currentBuybackSlot
;
11378 // if current back slot non-empty search oldest or free
11381 uint32 oldest_time
= GetUInt32Value( PLAYER_FIELD_BUYBACK_TIMESTAMP_1
);
11382 uint32 oldest_slot
= BUYBACK_SLOT_START
;
11384 for(uint32 i
= BUYBACK_SLOT_START
+1; i
< BUYBACK_SLOT_END
; ++i
)
11393 uint32 i_time
= GetUInt32Value( PLAYER_FIELD_BUYBACK_TIMESTAMP_1
+ i
- BUYBACK_SLOT_START
);
11395 if(oldest_time
> i_time
)
11397 oldest_time
= i_time
;
11403 slot
= oldest_slot
;
11406 RemoveItemFromBuyBackSlot( slot
, true );
11407 sLog
.outDebug( "STORAGE: AddItemToBuyBackSlot item = %u, slot = %u", pItem
->GetEntry(), slot
);
11409 m_items
[slot
] = pItem
;
11410 time_t base
= time(NULL
);
11411 uint32 etime
= uint32(base
- m_logintime
+ (30 * 3600));
11412 uint32 eslot
= slot
- BUYBACK_SLOT_START
;
11414 SetUInt64Value( PLAYER_FIELD_VENDORBUYBACK_SLOT_1
+ eslot
* 2, pItem
->GetGUID() );
11415 ItemPrototype
const *pProto
= pItem
->GetProto();
11417 SetUInt32Value( PLAYER_FIELD_BUYBACK_PRICE_1
+ eslot
, pProto
->SellPrice
* pItem
->GetCount() );
11419 SetUInt32Value( PLAYER_FIELD_BUYBACK_PRICE_1
+ eslot
, 0 );
11420 SetUInt32Value( PLAYER_FIELD_BUYBACK_TIMESTAMP_1
+ eslot
, (uint32
)etime
);
11422 // move to next (for non filled list is move most optimized choice)
11423 if(m_currentBuybackSlot
< BUYBACK_SLOT_END
-1)
11424 ++m_currentBuybackSlot
;
11428 Item
* Player::GetItemFromBuyBackSlot( uint32 slot
)
11430 sLog
.outDebug( "STORAGE: GetItemFromBuyBackSlot slot = %u", slot
);
11431 if( slot
>= BUYBACK_SLOT_START
&& slot
< BUYBACK_SLOT_END
)
11432 return m_items
[slot
];
11436 void Player::RemoveItemFromBuyBackSlot( uint32 slot
, bool del
)
11438 sLog
.outDebug( "STORAGE: RemoveItemFromBuyBackSlot slot = %u", slot
);
11439 if( slot
>= BUYBACK_SLOT_START
&& slot
< BUYBACK_SLOT_END
)
11441 Item
*pItem
= m_items
[slot
];
11444 pItem
->RemoveFromWorld();
11445 if(del
) pItem
->SetState(ITEM_REMOVED
, this);
11448 m_items
[slot
] = NULL
;
11450 uint32 eslot
= slot
- BUYBACK_SLOT_START
;
11451 SetUInt64Value( PLAYER_FIELD_VENDORBUYBACK_SLOT_1
+ eslot
* 2, 0 );
11452 SetUInt32Value( PLAYER_FIELD_BUYBACK_PRICE_1
+ eslot
, 0 );
11453 SetUInt32Value( PLAYER_FIELD_BUYBACK_TIMESTAMP_1
+ eslot
, 0 );
11455 // if current backslot is filled set to now free slot
11456 if(m_items
[m_currentBuybackSlot
])
11457 m_currentBuybackSlot
= slot
;
11461 void Player::SendEquipError( uint8 msg
, Item
* pItem
, Item
*pItem2
)
11463 sLog
.outDebug( "WORLD: Sent SMSG_INVENTORY_CHANGE_FAILURE (%u)",msg
);
11464 WorldPacket
data( SMSG_INVENTORY_CHANGE_FAILURE
, (msg
== EQUIP_ERR_CANT_EQUIP_LEVEL_I
? 22 : 18) );
11465 data
<< uint8(msg
);
11469 data
<< uint64(pItem
? pItem
->GetGUID() : 0);
11470 data
<< uint64(pItem2
? pItem2
->GetGUID() : 0);
11471 data
<< uint8(0); // not 0 there...
11473 if(msg
== EQUIP_ERR_CANT_EQUIP_LEVEL_I
)
11478 if(ItemPrototype
const* proto
= pItem
->GetProto())
11479 level
= proto
->RequiredLevel
;
11481 data
<< uint32(level
); // new 2.4.0
11484 GetSession()->SendPacket(&data
);
11487 void Player::SendBuyError( uint8 msg
, Creature
* pCreature
, uint32 item
, uint32 param
)
11489 sLog
.outDebug( "WORLD: Sent SMSG_BUY_FAILED" );
11490 WorldPacket
data( SMSG_BUY_FAILED
, (8+4+4+1) );
11491 data
<< uint64(pCreature
? pCreature
->GetGUID() : 0);
11492 data
<< uint32(item
);
11494 data
<< uint32(param
);
11495 data
<< uint8(msg
);
11496 GetSession()->SendPacket(&data
);
11499 void Player::SendSellError( uint8 msg
, Creature
* pCreature
, uint64 guid
, uint32 param
)
11501 sLog
.outDebug( "WORLD: Sent SMSG_SELL_ITEM" );
11502 WorldPacket
data( SMSG_SELL_ITEM
,(8+8+(param
?4:0)+1)); // last check 2.0.10
11503 data
<< uint64(pCreature
? pCreature
->GetGUID() : 0);
11504 data
<< uint64(guid
);
11506 data
<< uint32(param
);
11507 data
<< uint8(msg
);
11508 GetSession()->SendPacket(&data
);
11511 void Player::ClearTrade()
11514 acceptTrade
= false;
11515 for(int i
= 0; i
< TRADE_SLOT_COUNT
; i
++)
11516 tradeItems
[i
] = NULL_SLOT
;
11519 void Player::TradeCancel(bool sendback
)
11523 // send yellow "Trade canceled" message to both traders
11527 ws
->SendCancelTrade();
11528 ws
= pTrader
->GetSession();
11529 if(!ws
->PlayerLogout())
11530 ws
->SendCancelTrade();
11534 pTrader
->ClearTrade();
11535 // prevent loss of reference
11536 pTrader
->pTrader
= NULL
;
11541 void Player::UpdateItemDuration(uint32 time
, bool realtimeonly
)
11543 if(m_itemDuration
.empty())
11546 sLog
.outDebug("Player::UpdateItemDuration(%u,%u)", time
,realtimeonly
);
11548 for(ItemDurationList::iterator itr
= m_itemDuration
.begin();itr
!= m_itemDuration
.end(); )
11551 ++itr
; // current element can be erased in UpdateDuration
11553 if (realtimeonly
&& item
->GetProto()->Duration
< 0 || !realtimeonly
)
11554 item
->UpdateDuration(this,time
);
11558 void Player::UpdateEnchantTime(uint32 time
)
11560 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin(),next
;itr
!= m_enchantDuration
.end();itr
=next
)
11564 if(!itr
->item
->GetEnchantmentId(itr
->slot
))
11566 next
= m_enchantDuration
.erase(itr
);
11568 else if(itr
->leftduration
<= time
)
11570 ApplyEnchantment(itr
->item
,itr
->slot
,false,false);
11571 itr
->item
->ClearEnchantment(itr
->slot
);
11572 next
= m_enchantDuration
.erase(itr
);
11574 else if(itr
->leftduration
> time
)
11576 itr
->leftduration
-= time
;
11582 void Player::AddEnchantmentDurations(Item
*item
)
11584 for(int x
=0;x
<MAX_ENCHANTMENT_SLOT
;++x
)
11586 if(!item
->GetEnchantmentId(EnchantmentSlot(x
)))
11589 uint32 duration
= item
->GetEnchantmentDuration(EnchantmentSlot(x
));
11591 AddEnchantmentDuration(item
,EnchantmentSlot(x
),duration
);
11595 void Player::RemoveEnchantmentDurations(Item
*item
)
11597 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin();itr
!= m_enchantDuration
.end();)
11599 if(itr
->item
== item
)
11601 // save duration in item
11602 item
->SetEnchantmentDuration(EnchantmentSlot(itr
->slot
),itr
->leftduration
);
11603 itr
= m_enchantDuration
.erase(itr
);
11610 void Player::RemoveAllEnchantments(EnchantmentSlot slot
)
11612 // remove enchantments from equipped items first to clean up the m_enchantDuration list
11613 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin(),next
;itr
!= m_enchantDuration
.end();itr
=next
)
11616 if(itr
->slot
==slot
)
11618 if(itr
->item
&& itr
->item
->GetEnchantmentId(slot
))
11620 // remove from stats
11621 ApplyEnchantment(itr
->item
,slot
,false,false);
11623 itr
->item
->ClearEnchantment(slot
);
11625 // remove from update list
11626 next
= m_enchantDuration
.erase(itr
);
11632 // remove enchants from inventory items
11633 // NOTE: no need to remove these from stats, since these aren't equipped
11635 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
11637 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
11638 if( pItem
&& pItem
->GetEnchantmentId(slot
) )
11639 pItem
->ClearEnchantment(slot
);
11642 // in inventory bags
11643 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
11645 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
11648 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
11650 Item
* pItem
= pBag
->GetItemByPos(j
);
11651 if( pItem
&& pItem
->GetEnchantmentId(slot
) )
11652 pItem
->ClearEnchantment(slot
);
11658 // duration == 0 will remove item enchant
11659 void Player::AddEnchantmentDuration(Item
*item
,EnchantmentSlot slot
,uint32 duration
)
11664 if(slot
>= MAX_ENCHANTMENT_SLOT
)
11667 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin();itr
!= m_enchantDuration
.end();++itr
)
11669 if(itr
->item
== item
&& itr
->slot
== slot
)
11671 itr
->item
->SetEnchantmentDuration(itr
->slot
,itr
->leftduration
);
11672 m_enchantDuration
.erase(itr
);
11676 if(item
&& duration
> 0 )
11678 GetSession()->SendItemEnchantTimeUpdate(GetGUID(), item
->GetGUID(),slot
,uint32(duration
/1000));
11679 m_enchantDuration
.push_back(EnchantDuration(item
,slot
,duration
));
11683 void Player::ApplyEnchantment(Item
*item
,bool apply
)
11685 for(uint32 slot
= 0; slot
< MAX_ENCHANTMENT_SLOT
; ++slot
)
11686 ApplyEnchantment(item
, EnchantmentSlot(slot
), apply
);
11689 void Player::ApplyEnchantment(Item
*item
,EnchantmentSlot slot
,bool apply
, bool apply_dur
, bool ignore_condition
)
11694 if(!item
->IsEquipped())
11697 if(slot
>= MAX_ENCHANTMENT_SLOT
)
11700 uint32 enchant_id
= item
->GetEnchantmentId(slot
);
11704 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
11708 if(!ignore_condition
&& pEnchant
->EnchantmentCondition
&& !((Player
*)this)->EnchantmentFitsRequirements(pEnchant
->EnchantmentCondition
, -1))
11711 for (int s
=0; s
<3; s
++)
11713 uint32 enchant_display_type
= pEnchant
->type
[s
];
11714 uint32 enchant_amount
= pEnchant
->amount
[s
];
11715 uint32 enchant_spell_id
= pEnchant
->spellid
[s
];
11717 switch(enchant_display_type
)
11719 case ITEM_ENCHANTMENT_TYPE_NONE
:
11721 case ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL
:
11722 // processed in Player::CastItemCombatSpell
11724 case ITEM_ENCHANTMENT_TYPE_DAMAGE
:
11725 if (item
->GetSlot() == EQUIPMENT_SLOT_MAINHAND
)
11726 HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11727 else if (item
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
11728 HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11729 else if (item
->GetSlot() == EQUIPMENT_SLOT_RANGED
)
11730 HandleStatModifier(UNIT_MOD_DAMAGE_RANGED
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11732 case ITEM_ENCHANTMENT_TYPE_EQUIP_SPELL
:
11733 if(enchant_spell_id
)
11737 int32 basepoints
= 0;
11738 // Random Property Exist - try found basepoints for spell (basepoints depends from item suffix factor)
11739 if (item
->GetItemRandomPropertyId())
11741 ItemRandomSuffixEntry
const *item_rand
= sItemRandomSuffixStore
.LookupEntry(abs(item
->GetItemRandomPropertyId()));
11744 // Search enchant_amount
11745 for (int k
=0; k
<3; k
++)
11747 if(item_rand
->enchant_id
[k
] == enchant_id
)
11749 basepoints
= int32((item_rand
->prefix
[k
]*item
->GetItemSuffixFactor()) / 10000 );
11755 // Cast custom spell vs all equal basepoints getted from enchant_amount
11757 CastCustomSpell(this,enchant_spell_id
,&basepoints
,&basepoints
,&basepoints
,true,item
);
11759 CastSpell(this,enchant_spell_id
,true,item
);
11762 RemoveAurasDueToItemSpell(item
,enchant_spell_id
);
11765 case ITEM_ENCHANTMENT_TYPE_RESISTANCE
:
11766 if (!enchant_amount
)
11768 ItemRandomSuffixEntry
const *item_rand
= sItemRandomSuffixStore
.LookupEntry(abs(item
->GetItemRandomPropertyId()));
11771 for (int k
=0; k
<3; k
++)
11773 if(item_rand
->enchant_id
[k
] == enchant_id
)
11775 enchant_amount
= uint32((item_rand
->prefix
[k
]*item
->GetItemSuffixFactor()) / 10000 );
11782 HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START
+ enchant_spell_id
), TOTAL_VALUE
, float(enchant_amount
), apply
);
11784 case ITEM_ENCHANTMENT_TYPE_STAT
:
11786 if (!enchant_amount
)
11788 ItemRandomSuffixEntry
const *item_rand_suffix
= sItemRandomSuffixStore
.LookupEntry(abs(item
->GetItemRandomPropertyId()));
11789 if(item_rand_suffix
)
11791 for (int k
=0; k
<3; k
++)
11793 if(item_rand_suffix
->enchant_id
[k
] == enchant_id
)
11795 enchant_amount
= uint32((item_rand_suffix
->prefix
[k
]*item
->GetItemSuffixFactor()) / 10000 );
11802 sLog
.outDebug("Adding %u to stat nb %u",enchant_amount
,enchant_spell_id
);
11803 switch (enchant_spell_id
)
11805 case ITEM_MOD_AGILITY
:
11806 sLog
.outDebug("+ %u AGILITY",enchant_amount
);
11807 HandleStatModifier(UNIT_MOD_STAT_AGILITY
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11808 ApplyStatBuffMod(STAT_AGILITY
, enchant_amount
, apply
);
11810 case ITEM_MOD_STRENGTH
:
11811 sLog
.outDebug("+ %u STRENGTH",enchant_amount
);
11812 HandleStatModifier(UNIT_MOD_STAT_STRENGTH
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11813 ApplyStatBuffMod(STAT_STRENGTH
, enchant_amount
, apply
);
11815 case ITEM_MOD_INTELLECT
:
11816 sLog
.outDebug("+ %u INTELLECT",enchant_amount
);
11817 HandleStatModifier(UNIT_MOD_STAT_INTELLECT
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11818 ApplyStatBuffMod(STAT_INTELLECT
, enchant_amount
, apply
);
11820 case ITEM_MOD_SPIRIT
:
11821 sLog
.outDebug("+ %u SPIRIT",enchant_amount
);
11822 HandleStatModifier(UNIT_MOD_STAT_SPIRIT
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11823 ApplyStatBuffMod(STAT_SPIRIT
, enchant_amount
, apply
);
11825 case ITEM_MOD_STAMINA
:
11826 sLog
.outDebug("+ %u STAMINA",enchant_amount
);
11827 HandleStatModifier(UNIT_MOD_STAT_STAMINA
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11828 ApplyStatBuffMod(STAT_STAMINA
, enchant_amount
, apply
);
11830 case ITEM_MOD_DEFENSE_SKILL_RATING
:
11831 ((Player
*)this)->ApplyRatingMod(CR_DEFENSE_SKILL
, enchant_amount
, apply
);
11832 sLog
.outDebug("+ %u DEFENCE", enchant_amount
);
11834 case ITEM_MOD_DODGE_RATING
:
11835 ((Player
*)this)->ApplyRatingMod(CR_DODGE
, enchant_amount
, apply
);
11836 sLog
.outDebug("+ %u DODGE", enchant_amount
);
11838 case ITEM_MOD_PARRY_RATING
:
11839 ((Player
*)this)->ApplyRatingMod(CR_PARRY
, enchant_amount
, apply
);
11840 sLog
.outDebug("+ %u PARRY", enchant_amount
);
11842 case ITEM_MOD_BLOCK_RATING
:
11843 ((Player
*)this)->ApplyRatingMod(CR_BLOCK
, enchant_amount
, apply
);
11844 sLog
.outDebug("+ %u SHIELD_BLOCK", enchant_amount
);
11846 case ITEM_MOD_HIT_MELEE_RATING
:
11847 ((Player
*)this)->ApplyRatingMod(CR_HIT_MELEE
, enchant_amount
, apply
);
11848 sLog
.outDebug("+ %u MELEE_HIT", enchant_amount
);
11850 case ITEM_MOD_HIT_RANGED_RATING
:
11851 ((Player
*)this)->ApplyRatingMod(CR_HIT_RANGED
, enchant_amount
, apply
);
11852 sLog
.outDebug("+ %u RANGED_HIT", enchant_amount
);
11854 case ITEM_MOD_HIT_SPELL_RATING
:
11855 ((Player
*)this)->ApplyRatingMod(CR_HIT_SPELL
, enchant_amount
, apply
);
11856 sLog
.outDebug("+ %u SPELL_HIT", enchant_amount
);
11858 case ITEM_MOD_CRIT_MELEE_RATING
:
11859 ((Player
*)this)->ApplyRatingMod(CR_CRIT_MELEE
, enchant_amount
, apply
);
11860 sLog
.outDebug("+ %u MELEE_CRIT", enchant_amount
);
11862 case ITEM_MOD_CRIT_RANGED_RATING
:
11863 ((Player
*)this)->ApplyRatingMod(CR_CRIT_RANGED
, enchant_amount
, apply
);
11864 sLog
.outDebug("+ %u RANGED_CRIT", enchant_amount
);
11866 case ITEM_MOD_CRIT_SPELL_RATING
:
11867 ((Player
*)this)->ApplyRatingMod(CR_CRIT_SPELL
, enchant_amount
, apply
);
11868 sLog
.outDebug("+ %u SPELL_CRIT", enchant_amount
);
11870 // Values from ITEM_STAT_MELEE_HA_RATING to ITEM_MOD_HASTE_RANGED_RATING are never used
11872 // case ITEM_MOD_HIT_TAKEN_MELEE_RATING:
11873 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_MELEE, enchant_amount, apply);
11875 // case ITEM_MOD_HIT_TAKEN_RANGED_RATING:
11876 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_RANGED, enchant_amount, apply);
11878 // case ITEM_MOD_HIT_TAKEN_SPELL_RATING:
11879 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_SPELL, enchant_amount, apply);
11881 // case ITEM_MOD_CRIT_TAKEN_MELEE_RATING:
11882 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply);
11884 // case ITEM_MOD_CRIT_TAKEN_RANGED_RATING:
11885 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply);
11887 // case ITEM_MOD_CRIT_TAKEN_SPELL_RATING:
11888 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply);
11890 // case ITEM_MOD_HASTE_MELEE_RATING:
11891 // ((Player*)this)->ApplyRatingMod(CR_HASTE_MELEE, enchant_amount, apply);
11893 // case ITEM_MOD_HASTE_RANGED_RATING:
11894 // ((Player*)this)->ApplyRatingMod(CR_HASTE_RANGED, enchant_amount, apply);
11896 case ITEM_MOD_HASTE_SPELL_RATING
:
11897 ((Player
*)this)->ApplyRatingMod(CR_HASTE_SPELL
, enchant_amount
, apply
);
11899 case ITEM_MOD_HIT_RATING
:
11900 ((Player
*)this)->ApplyRatingMod(CR_HIT_MELEE
, enchant_amount
, apply
);
11901 ((Player
*)this)->ApplyRatingMod(CR_HIT_RANGED
, enchant_amount
, apply
);
11902 ((Player
*)this)->ApplyRatingMod(CR_HIT_SPELL
, enchant_amount
, apply
);
11903 sLog
.outDebug("+ %u HIT", enchant_amount
);
11905 case ITEM_MOD_CRIT_RATING
:
11906 ((Player
*)this)->ApplyRatingMod(CR_CRIT_MELEE
, enchant_amount
, apply
);
11907 ((Player
*)this)->ApplyRatingMod(CR_CRIT_RANGED
, enchant_amount
, apply
);
11908 ((Player
*)this)->ApplyRatingMod(CR_CRIT_SPELL
, enchant_amount
, apply
);
11909 sLog
.outDebug("+ %u CRITICAL", enchant_amount
);
11911 // Values ITEM_MOD_HIT_TAKEN_RATING and ITEM_MOD_CRIT_TAKEN_RATING are never used in Enchantment
11912 // case ITEM_MOD_HIT_TAKEN_RATING:
11913 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_MELEE, enchant_amount, apply);
11914 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_RANGED, enchant_amount, apply);
11915 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_SPELL, enchant_amount, apply);
11917 // case ITEM_MOD_CRIT_TAKEN_RATING:
11918 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply);
11919 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply);
11920 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply);
11922 case ITEM_MOD_RESILIENCE_RATING
:
11923 ((Player
*)this)->ApplyRatingMod(CR_CRIT_TAKEN_MELEE
, enchant_amount
, apply
);
11924 ((Player
*)this)->ApplyRatingMod(CR_CRIT_TAKEN_RANGED
, enchant_amount
, apply
);
11925 ((Player
*)this)->ApplyRatingMod(CR_CRIT_TAKEN_SPELL
, enchant_amount
, apply
);
11926 sLog
.outDebug("+ %u RESILIENCE", enchant_amount
);
11928 case ITEM_MOD_HASTE_RATING
:
11929 ((Player
*)this)->ApplyRatingMod(CR_HASTE_MELEE
, enchant_amount
, apply
);
11930 ((Player
*)this)->ApplyRatingMod(CR_HASTE_RANGED
, enchant_amount
, apply
);
11931 ((Player
*)this)->ApplyRatingMod(CR_HASTE_SPELL
, enchant_amount
, apply
);
11932 sLog
.outDebug("+ %u HASTE", enchant_amount
);
11934 case ITEM_MOD_EXPERTISE_RATING
:
11935 ((Player
*)this)->ApplyRatingMod(CR_EXPERTISE
, enchant_amount
, apply
);
11936 sLog
.outDebug("+ %u EXPERTISE", enchant_amount
);
11938 case ITEM_MOD_ARMOR_PENETRATION_RATING
:
11939 ((Player
*)this)->ApplyRatingMod(CR_ARMOR_PENETRATION
, enchant_amount
, apply
);
11940 sLog
.outDebug("+ %u ARMOR PENETRATION", enchant_amount
);
11947 case ITEM_ENCHANTMENT_TYPE_TOTEM
: // Shaman Rockbiter Weapon
11949 if(getClass() == CLASS_SHAMAN
)
11951 float addValue
= 0.0f
;
11952 if(item
->GetSlot() == EQUIPMENT_SLOT_MAINHAND
)
11954 addValue
= float(enchant_amount
* item
->GetProto()->Delay
/1000.0f
);
11955 HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND
, TOTAL_VALUE
, addValue
, apply
);
11957 else if(item
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
11959 addValue
= float(enchant_amount
* item
->GetProto()->Delay
/1000.0f
);
11960 HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_VALUE
, addValue
, apply
);
11965 case ITEM_ENCHANTMENT_TYPE_USE_SPELL
:
11966 // processed in Player::CastItemUseSpell
11969 sLog
.outError("Unknown item enchantment display type: %d",enchant_display_type
);
11971 } /*switch(enchant_display_type)*/
11974 // visualize enchantment at player and equipped items
11975 if(slot
< MAX_INSPECTED_ENCHANTMENT_SLOT
)
11977 int VisibleBase
= PLAYER_VISIBLE_ITEM_1_0
+ (item
->GetSlot() * MAX_VISIBLE_ITEM_OFFSET
);
11978 SetUInt32Value(VisibleBase
+ 1 + slot
, apply
? item
->GetEnchantmentId(slot
) : 0);
11986 uint32 duration
= item
->GetEnchantmentDuration(slot
);
11988 AddEnchantmentDuration(item
,slot
,duration
);
11992 // duration == 0 will remove EnchantDuration
11993 AddEnchantmentDuration(item
,slot
,0);
11998 void Player::SendEnchantmentDurations()
12000 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin();itr
!= m_enchantDuration
.end();++itr
)
12002 GetSession()->SendItemEnchantTimeUpdate(GetGUID(), itr
->item
->GetGUID(),itr
->slot
,uint32(itr
->leftduration
)/1000);
12006 void Player::SendItemDurations()
12008 for(ItemDurationList::iterator itr
= m_itemDuration
.begin();itr
!= m_itemDuration
.end();++itr
)
12010 (*itr
)->SendTimeUpdate(this);
12014 void Player::SendNewItem(Item
*item
, uint32 count
, bool received
, bool created
, bool broadcast
)
12016 if(!item
) // prevent crash
12019 // last check 2.0.10
12020 WorldPacket
data( SMSG_ITEM_PUSH_RESULT
, (8+4+4+4+1+4+4+4+4+4) );
12021 data
<< GetGUID(); // player GUID
12022 data
<< uint32(received
); // 0=looted, 1=from npc
12023 data
<< uint32(created
); // 0=received, 1=created
12024 data
<< uint32(1); // always 0x01 (probably meant to be count of listed items)
12025 data
<< (uint8
)item
->GetBagSlot(); // bagslot
12026 // item slot, but when added to stack: 0xFFFFFFFF
12027 data
<< (uint32
) ((item
->GetCount()==count
) ? item
->GetSlot() : -1);
12028 data
<< uint32(item
->GetEntry()); // item id
12029 data
<< uint32(item
->GetItemSuffixFactor()); // SuffixFactor
12030 data
<< uint32(item
->GetItemRandomPropertyId()); // random item property id
12031 data
<< uint32(count
); // count of items
12032 data
<< GetItemCount(item
->GetEntry()); // count of items in inventory
12034 if (broadcast
&& GetGroup())
12035 GetGroup()->BroadcastPacket(&data
);
12037 GetSession()->SendPacket(&data
);
12040 /*********************************************************/
12041 /*** QUEST SYSTEM ***/
12042 /*********************************************************/
12044 void Player::PrepareQuestMenu( uint64 guid
)
12047 QuestRelations
* pObjectQR
;
12048 QuestRelations
* pObjectQIR
;
12049 Creature
*pCreature
= ObjectAccessor::GetCreature(*this, guid
);
12052 pObject
= (Object
*)pCreature
;
12053 pObjectQR
= &objmgr
.mCreatureQuestRelations
;
12054 pObjectQIR
= &objmgr
.mCreatureQuestInvolvedRelations
;
12058 GameObject
*pGameObject
= ObjectAccessor::GetGameObject(*this, guid
);
12061 pObject
= (Object
*)pGameObject
;
12062 pObjectQR
= &objmgr
.mGOQuestRelations
;
12063 pObjectQIR
= &objmgr
.mGOQuestInvolvedRelations
;
12069 QuestMenu
&qm
= PlayerTalkClass
->GetQuestMenu();
12072 for(QuestRelations::const_iterator i
= pObjectQIR
->lower_bound(pObject
->GetEntry()); i
!= pObjectQIR
->upper_bound(pObject
->GetEntry()); ++i
)
12074 uint32 quest_id
= i
->second
;
12075 QuestStatus status
= GetQuestStatus( quest_id
);
12076 if ( status
== QUEST_STATUS_COMPLETE
&& !GetQuestRewardStatus( quest_id
) )
12077 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_REWARD_REP
);
12078 else if ( status
== QUEST_STATUS_INCOMPLETE
)
12079 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_INCOMPLETE
);
12080 else if (status
== QUEST_STATUS_AVAILABLE
)
12081 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_CHAT
);
12084 for(QuestRelations::const_iterator i
= pObjectQR
->lower_bound(pObject
->GetEntry()); i
!= pObjectQR
->upper_bound(pObject
->GetEntry()); ++i
)
12086 uint32 quest_id
= i
->second
;
12087 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
12088 if(!pQuest
) continue;
12090 QuestStatus status
= GetQuestStatus( quest_id
);
12092 if (pQuest
->IsAutoComplete() && CanTakeQuest(pQuest
, false))
12093 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_REWARD_REP
);
12094 else if ( status
== QUEST_STATUS_NONE
&& CanTakeQuest( pQuest
, false ) )
12095 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_AVAILABLE
);
12099 void Player::SendPreparedQuest( uint64 guid
)
12101 QuestMenu
& questMenu
= PlayerTalkClass
->GetQuestMenu();
12102 if( questMenu
.Empty() )
12105 QuestMenuItem
const& qmi0
= questMenu
.GetItem( 0 );
12107 uint32 status
= qmi0
.m_qIcon
;
12109 // single element case
12110 if ( questMenu
.MenuItemCount() == 1 )
12112 // Auto open -- maybe also should verify there is no greeting
12113 uint32 quest_id
= qmi0
.m_qId
;
12114 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
12117 if( status
== DIALOG_STATUS_REWARD_REP
&& !GetQuestRewardStatus( quest_id
) )
12118 PlayerTalkClass
->SendQuestGiverRequestItems( pQuest
, guid
, CanRewardQuest(pQuest
,false), true );
12119 else if( status
== DIALOG_STATUS_INCOMPLETE
)
12120 PlayerTalkClass
->SendQuestGiverRequestItems( pQuest
, guid
, false, true );
12121 // Send completable on repeatable quest if player don't have quest
12122 else if( pQuest
->IsRepeatable() && !pQuest
->IsDaily() )
12123 PlayerTalkClass
->SendQuestGiverRequestItems( pQuest
, guid
, CanCompleteRepeatableQuest(pQuest
), true );
12125 PlayerTalkClass
->SendQuestGiverQuestDetails( pQuest
, guid
, true );
12128 // multiply entries
12134 std::string title
= "";
12135 Creature
*pCreature
= ObjectAccessor::GetCreature(*this, guid
);
12138 uint32 textid
= pCreature
->GetNpcTextId();
12139 GossipText
* gossiptext
= objmgr
.GetGossipText(textid
);
12142 qe
._Delay
= 0; //TEXTEMOTE_MESSAGE; //zyg: player emote
12143 qe
._Emote
= 0; //TEXTEMOTE_HELLO; //zyg: NPC emote
12148 qe
= gossiptext
->Options
[0].Emotes
[0];
12150 if(!gossiptext
->Options
[0].Text_0
.empty())
12152 title
= gossiptext
->Options
[0].Text_0
;
12154 int loc_idx
= GetSession()->GetSessionDbLocaleIndex();
12157 NpcTextLocale
const *nl
= objmgr
.GetNpcTextLocale(textid
);
12160 if (nl
->Text_0
[0].size() > loc_idx
&& !nl
->Text_0
[0][loc_idx
].empty())
12161 title
= nl
->Text_0
[0][loc_idx
];
12167 title
= gossiptext
->Options
[0].Text_1
;
12169 int loc_idx
= GetSession()->GetSessionDbLocaleIndex();
12172 NpcTextLocale
const *nl
= objmgr
.GetNpcTextLocale(textid
);
12175 if (nl
->Text_1
[0].size() > loc_idx
&& !nl
->Text_1
[0][loc_idx
].empty())
12176 title
= nl
->Text_1
[0][loc_idx
];
12182 PlayerTalkClass
->SendQuestGiverQuestList( qe
, title
, guid
);
12186 bool Player::IsActiveQuest( uint32 quest_id
) const
12188 QuestStatusMap::const_iterator itr
= mQuestStatus
.find(quest_id
);
12190 return itr
!= mQuestStatus
.end() && itr
->second
.m_status
!= QUEST_STATUS_NONE
;
12193 Quest
const * Player::GetNextQuest( uint64 guid
, Quest
const *pQuest
)
12196 QuestRelations
* pObjectQR
;
12197 QuestRelations
* pObjectQIR
;
12199 Creature
*pCreature
= ObjectAccessor::GetCreature(*this, guid
);
12202 pObject
= (Object
*)pCreature
;
12203 pObjectQR
= &objmgr
.mCreatureQuestRelations
;
12204 pObjectQIR
= &objmgr
.mCreatureQuestInvolvedRelations
;
12208 GameObject
*pGameObject
= ObjectAccessor::GetGameObject(*this, guid
);
12211 pObject
= (Object
*)pGameObject
;
12212 pObjectQR
= &objmgr
.mGOQuestRelations
;
12213 pObjectQIR
= &objmgr
.mGOQuestInvolvedRelations
;
12219 uint32 nextQuestID
= pQuest
->GetNextQuestInChain();
12220 for(QuestRelations::const_iterator itr
= pObjectQR
->lower_bound(pObject
->GetEntry()); itr
!= pObjectQR
->upper_bound(pObject
->GetEntry()); ++itr
)
12222 if (itr
->second
== nextQuestID
)
12223 return objmgr
.GetQuestTemplate(nextQuestID
);
12229 bool Player::CanSeeStartQuest( Quest
const *pQuest
)
12231 if( SatisfyQuestRace( pQuest
, false ) && SatisfyQuestSkillOrClass( pQuest
, false ) &&
12232 SatisfyQuestExclusiveGroup( pQuest
, false ) && SatisfyQuestReputation( pQuest
, false ) &&
12233 SatisfyQuestPreviousQuest( pQuest
, false ) && SatisfyQuestNextChain( pQuest
, false ) &&
12234 SatisfyQuestPrevChain( pQuest
, false ) && SatisfyQuestDay( pQuest
, false ) )
12236 return getLevel() + sWorld
.getConfig(CONFIG_QUEST_HIGH_LEVEL_HIDE_DIFF
) >= pQuest
->GetMinLevel();
12242 bool Player::CanTakeQuest( Quest
const *pQuest
, bool msg
)
12244 return SatisfyQuestStatus( pQuest
, msg
) && SatisfyQuestExclusiveGroup( pQuest
, msg
)
12245 && SatisfyQuestRace( pQuest
, msg
) && SatisfyQuestLevel( pQuest
, msg
)
12246 && SatisfyQuestSkillOrClass( pQuest
, msg
) && SatisfyQuestReputation( pQuest
, msg
)
12247 && SatisfyQuestPreviousQuest( pQuest
, msg
) && SatisfyQuestTimed( pQuest
, msg
)
12248 && SatisfyQuestNextChain( pQuest
, msg
) && SatisfyQuestPrevChain( pQuest
, msg
)
12249 && SatisfyQuestDay( pQuest
, msg
);
12252 bool Player::CanAddQuest( Quest
const *pQuest
, bool msg
)
12254 if( !SatisfyQuestLog( msg
) )
12257 uint32 srcitem
= pQuest
->GetSrcItemId();
12260 uint32 count
= pQuest
->GetSrcItemCount();
12261 ItemPosCountVec dest
;
12262 uint8 msg
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, srcitem
, count
);
12264 // player already have max number (in most case 1) source item, no additional item needed and quest can be added.
12265 if( msg
== EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
)
12267 else if( msg
!= EQUIP_ERR_OK
)
12269 SendEquipError( msg
, NULL
, NULL
);
12276 bool Player::CanCompleteQuest( uint32 quest_id
)
12280 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
12281 if( q_status
.m_status
== QUEST_STATUS_COMPLETE
)
12282 return false; // not allow re-complete quest
12284 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
12289 // auto complete quest
12290 if (qInfo
->IsAutoComplete() && CanTakeQuest(qInfo
, false))
12293 if ( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
12296 if ( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
12298 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12300 if( qInfo
->ReqItemCount
[i
]!= 0 && q_status
.m_itemcount
[i
] < qInfo
->ReqItemCount
[i
] )
12305 if ( qInfo
->HasFlag(QUEST_MANGOS_FLAGS_KILL_OR_CAST
| QUEST_MANGOS_FLAGS_SPEAKTO
) )
12307 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12309 if( qInfo
->ReqCreatureOrGOId
[i
] == 0 )
12312 if( qInfo
->ReqCreatureOrGOCount
[i
] != 0 && q_status
.m_creatureOrGOcount
[i
] < qInfo
->ReqCreatureOrGOCount
[i
] )
12317 if ( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
) && !q_status
.m_explored
)
12320 if ( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_TIMED
) && q_status
.m_timer
== 0 )
12323 if ( qInfo
->GetRewOrReqMoney() < 0 )
12325 if ( GetMoney() < uint32(-qInfo
->GetRewOrReqMoney()) )
12329 uint32 repFacId
= qInfo
->GetRepObjectiveFaction();
12330 if ( repFacId
&& GetReputation(repFacId
) < qInfo
->GetRepObjectiveValue() )
12339 bool Player::CanCompleteRepeatableQuest( Quest
const *pQuest
)
12341 // Solve problem that player don't have the quest and try complete it.
12342 // if repeatable she must be able to complete event if player don't have it.
12343 // Seem that all repeatable quest are DELIVER Flag so, no need to add more.
12344 if( !CanTakeQuest(pQuest
, false) )
12347 if (pQuest
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
12348 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12349 if( pQuest
->ReqItemId
[i
] && pQuest
->ReqItemCount
[i
] && !HasItemCount(pQuest
->ReqItemId
[i
],pQuest
->ReqItemCount
[i
]) )
12352 if( !CanRewardQuest(pQuest
, false) )
12358 bool Player::CanRewardQuest( Quest
const *pQuest
, bool msg
)
12360 // not auto complete quest and not completed quest (only cheating case, then ignore without message)
12361 if(!pQuest
->IsAutoComplete() && GetQuestStatus(pQuest
->GetQuestId()) != QUEST_STATUS_COMPLETE
)
12364 // daily quest can't be rewarded (25 daily quest already completed)
12365 if(!SatisfyQuestDay(pQuest
,true))
12368 // rewarded and not repeatable quest (only cheating case, then ignore without message)
12369 if(GetQuestRewardStatus(pQuest
->GetQuestId()))
12372 // prevent receive reward with quest items in bank
12373 if ( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
12375 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12377 if( pQuest
->ReqItemCount
[i
]!= 0 &&
12378 GetItemCount(pQuest
->ReqItemId
[i
]) < pQuest
->ReqItemCount
[i
] )
12381 SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, NULL
, NULL
);
12387 // prevent receive reward with low money and GetRewOrReqMoney() < 0
12388 if(pQuest
->GetRewOrReqMoney() < 0 && GetMoney() < uint32(-pQuest
->GetRewOrReqMoney()) )
12394 bool Player::CanRewardQuest( Quest
const *pQuest
, uint32 reward
, bool msg
)
12396 // prevent receive reward with quest items in bank or for not completed quest
12397 if(!CanRewardQuest(pQuest
,msg
))
12400 if ( pQuest
->GetRewChoiceItemsCount() > 0 )
12402 if( pQuest
->RewChoiceItemId
[reward
] )
12404 ItemPosCountVec dest
;
12405 uint8 res
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pQuest
->RewChoiceItemId
[reward
], pQuest
->RewChoiceItemCount
[reward
] );
12406 if( res
!= EQUIP_ERR_OK
)
12408 SendEquipError( res
, NULL
, NULL
);
12414 if ( pQuest
->GetRewItemsCount() > 0 )
12416 for (uint32 i
= 0; i
< pQuest
->GetRewItemsCount(); ++i
)
12418 if( pQuest
->RewItemId
[i
] )
12420 ItemPosCountVec dest
;
12421 uint8 res
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pQuest
->RewItemId
[i
], pQuest
->RewItemCount
[i
] );
12422 if( res
!= EQUIP_ERR_OK
)
12424 SendEquipError( res
, NULL
, NULL
);
12434 void Player::AddQuest( Quest
const *pQuest
, Object
*questGiver
)
12436 uint16 log_slot
= FindQuestSlot( 0 );
12437 assert(log_slot
< MAX_QUEST_LOG_SIZE
);
12439 uint32 quest_id
= pQuest
->GetQuestId();
12441 // if not exist then created with set uState==NEW and rewarded=false
12442 QuestStatusData
& questStatusData
= mQuestStatus
[quest_id
];
12443 if (questStatusData
.uState
!= QUEST_NEW
)
12444 questStatusData
.uState
= QUEST_CHANGED
;
12446 // check for repeatable quests status reset
12447 questStatusData
.m_status
= QUEST_STATUS_INCOMPLETE
;
12448 questStatusData
.m_explored
= false;
12450 if ( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
12452 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12453 questStatusData
.m_itemcount
[i
] = 0;
12456 if ( pQuest
->HasFlag(QUEST_MANGOS_FLAGS_KILL_OR_CAST
| QUEST_MANGOS_FLAGS_SPEAKTO
) )
12458 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12459 questStatusData
.m_creatureOrGOcount
[i
] = 0;
12462 GiveQuestSourceItem( pQuest
);
12463 AdjustQuestReqItemCount( pQuest
);
12465 if( pQuest
->GetRepObjectiveFaction() )
12466 SetFactionVisibleForFactionId(pQuest
->GetRepObjectiveFaction());
12469 if( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_TIMED
) )
12471 uint32 limittime
= pQuest
->GetLimitTime();
12473 // shared timed quest
12474 if(questGiver
&& questGiver
->GetTypeId()==TYPEID_PLAYER
)
12475 limittime
= ((Player
*)questGiver
)->getQuestStatusMap()[quest_id
].m_timer
/ 1000;
12477 AddTimedQuest( quest_id
);
12478 questStatusData
.m_timer
= limittime
* 1000;
12479 qtime
= static_cast<uint32
>(time(NULL
)) + limittime
;
12482 questStatusData
.m_timer
= 0;
12484 SetQuestSlot(log_slot
, quest_id
, qtime
);
12486 //starting initial quest script
12487 if(questGiver
&& pQuest
->GetQuestStartScript()!=0)
12488 sWorld
.ScriptsStart(sQuestStartScripts
, pQuest
->GetQuestStartScript(), questGiver
, this);
12490 UpdateForQuestsGO();
12493 void Player::CompleteQuest( uint32 quest_id
)
12497 SetQuestStatus( quest_id
, QUEST_STATUS_COMPLETE
);
12499 uint16 log_slot
= FindQuestSlot( quest_id
);
12500 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12501 SetQuestSlotState(log_slot
,QUEST_STATE_COMPLETE
);
12503 if(Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
))
12505 if( qInfo
->HasFlag(QUEST_FLAGS_AUTO_REWARDED
) )
12506 RewardQuest(qInfo
,0,this,false);
12508 SendQuestComplete( quest_id
);
12513 void Player::IncompleteQuest( uint32 quest_id
)
12517 SetQuestStatus( quest_id
, QUEST_STATUS_INCOMPLETE
);
12519 uint16 log_slot
= FindQuestSlot( quest_id
);
12520 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12521 RemoveQuestSlotState(log_slot
,QUEST_STATE_COMPLETE
);
12525 void Player::RewardQuest( Quest
const *pQuest
, uint32 reward
, Object
* questGiver
, bool announce
)
12527 uint32 quest_id
= pQuest
->GetQuestId();
12529 for (int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++ )
12531 if ( pQuest
->ReqItemId
[i
] )
12532 DestroyItemCount( pQuest
->ReqItemId
[i
], pQuest
->ReqItemCount
[i
], true);
12535 //if( qInfo->HasSpecialFlag( QUEST_FLAGS_TIMED ) )
12536 // SetTimedQuest( 0 );
12537 m_timedquests
.erase(pQuest
->GetQuestId());
12539 if ( pQuest
->GetRewChoiceItemsCount() > 0 )
12541 if( pQuest
->RewChoiceItemId
[reward
] )
12543 ItemPosCountVec dest
;
12544 if( CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pQuest
->RewChoiceItemId
[reward
], pQuest
->RewChoiceItemCount
[reward
] ) == EQUIP_ERR_OK
)
12546 Item
* item
= StoreNewItem( dest
, pQuest
->RewChoiceItemId
[reward
], true);
12547 SendNewItem(item
, pQuest
->RewChoiceItemCount
[reward
], true, false);
12552 if ( pQuest
->GetRewItemsCount() > 0 )
12554 for (uint32 i
=0; i
< pQuest
->GetRewItemsCount(); ++i
)
12556 if( pQuest
->RewItemId
[i
] )
12558 ItemPosCountVec dest
;
12559 if( CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pQuest
->RewItemId
[i
], pQuest
->RewItemCount
[i
] ) == EQUIP_ERR_OK
)
12561 Item
* item
= StoreNewItem( dest
, pQuest
->RewItemId
[i
], true);
12562 SendNewItem(item
, pQuest
->RewItemCount
[i
], true, false);
12568 RewardReputation( pQuest
);
12570 if( pQuest
->GetRewSpellCast() > 0 )
12571 CastSpell( this, pQuest
->GetRewSpellCast(), true);
12572 else if( pQuest
->GetRewSpell() > 0)
12573 CastSpell( this, pQuest
->GetRewSpell(), true);
12575 uint16 log_slot
= FindQuestSlot( quest_id
);
12576 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12577 SetQuestSlot(log_slot
,0);
12579 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
12581 // Not give XP in case already completed once repeatable quest
12582 uint32 XP
= q_status
.m_rewarded
? 0 : uint32(pQuest
->XPValue( this )*sWorld
.getRate(RATE_XP_QUEST
));
12584 if ( getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) )
12585 GiveXP( XP
, NULL
);
12587 ModifyMoney( int32(pQuest
->GetRewMoneyMaxLevel() * sWorld
.getRate(RATE_DROP_MONEY
)) );
12589 // Give player extra money if GetRewOrReqMoney > 0 and get ReqMoney if negative
12590 ModifyMoney( pQuest
->GetRewOrReqMoney() );
12593 if(pQuest
->GetRewHonorableKills())
12594 RewardHonor(NULL
, 0, MaNGOS::Honor::hk_honor_at_level(getLevel(), pQuest
->GetRewHonorableKills()));
12597 if(pQuest
->GetCharTitleId())
12599 if(CharTitlesEntry
const* titleEntry
= sCharTitlesStore
.LookupEntry(pQuest
->GetCharTitleId()))
12600 SetTitle(titleEntry
);
12603 // Send reward mail
12604 if(pQuest
->GetRewMailTemplateId())
12606 MailMessageType mailType
;
12607 uint32 senderGuidOrEntry
;
12608 switch(questGiver
->GetTypeId())
12611 mailType
= MAIL_CREATURE
;
12612 senderGuidOrEntry
= questGiver
->GetEntry();
12614 case TYPEID_GAMEOBJECT
:
12615 mailType
= MAIL_GAMEOBJECT
;
12616 senderGuidOrEntry
= questGiver
->GetEntry();
12619 mailType
= MAIL_ITEM
;
12620 senderGuidOrEntry
= questGiver
->GetEntry();
12622 case TYPEID_PLAYER
:
12623 mailType
= MAIL_NORMAL
;
12624 senderGuidOrEntry
= questGiver
->GetGUIDLow();
12627 mailType
= MAIL_NORMAL
;
12628 senderGuidOrEntry
= GetGUIDLow();
12632 Loot questMailLoot
;
12634 questMailLoot
.FillLoot(pQuest
->GetQuestId(), LootTemplates_QuestMail
, this);
12637 MailItemsInfo mi
; // item list preparing
12639 for(size_t i
= 0; mi
.size() < MAX_MAIL_ITEMS
&& i
< questMailLoot
.items
.size(); ++i
)
12641 if(LootItem
* lootitem
= questMailLoot
.LootItemInSlot(i
,this))
12643 if(Item
* item
= Item::CreateItem(lootitem
->itemid
,lootitem
->count
,this))
12645 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
12646 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
12651 for(size_t i
= 0; mi
.size() < MAX_MAIL_ITEMS
&& i
< questMailLoot
.quest_items
.size(); ++i
)
12653 if(LootItem
* lootitem
= questMailLoot
.LootItemInSlot(i
+questMailLoot
.items
.size(),this))
12655 if(Item
* item
= Item::CreateItem(lootitem
->itemid
,lootitem
->count
,this))
12657 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
12658 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
12663 WorldSession::SendMailTo(this, mailType
, MAIL_STATIONERY_NORMAL
, senderGuidOrEntry
, GetGUIDLow(), "", 0, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
,pQuest
->GetRewMailDelaySecs(),pQuest
->GetRewMailTemplateId());
12666 if(pQuest
->IsDaily())
12668 SetDailyQuestStatus(quest_id
);
12669 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_DAILY_QUEST
, 1);
12672 if ( !pQuest
->IsRepeatable() )
12673 SetQuestStatus(quest_id
, QUEST_STATUS_COMPLETE
);
12675 SetQuestStatus(quest_id
, QUEST_STATUS_NONE
);
12677 q_status
.m_rewarded
= true;
12680 SendQuestReward( pQuest
, XP
, questGiver
);
12682 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
12683 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST_COUNT
);
12684 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST
);
12687 void Player::FailQuest( uint32 quest_id
)
12691 IncompleteQuest( quest_id
);
12693 uint16 log_slot
= FindQuestSlot( quest_id
);
12694 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12696 SetQuestSlotTimer(log_slot
, 1 );
12697 SetQuestSlotState(log_slot
,QUEST_STATE_FAIL
);
12699 SendQuestFailed( quest_id
);
12703 void Player::FailTimedQuest( uint32 quest_id
)
12707 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
12709 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
12710 q_status
.m_timer
= 0;
12712 IncompleteQuest( quest_id
);
12714 uint16 log_slot
= FindQuestSlot( quest_id
);
12715 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12717 SetQuestSlotTimer(log_slot
, 1 );
12718 SetQuestSlotState(log_slot
,QUEST_STATE_FAIL
);
12720 SendQuestTimerFailed( quest_id
);
12724 bool Player::SatisfyQuestSkillOrClass( Quest
const* qInfo
, bool msg
)
12726 int32 zoneOrSort
= qInfo
->GetZoneOrSort();
12727 int32 skillOrClass
= qInfo
->GetSkillOrClass();
12729 // skip zone zoneOrSort and 0 case skillOrClass
12730 if( zoneOrSort
>= 0 && skillOrClass
== 0 )
12733 int32 questSort
= -zoneOrSort
;
12734 uint8 reqSortClass
= ClassByQuestSort(questSort
);
12736 // check class sort cases in zoneOrSort
12737 if( reqSortClass
!= 0 && getClass() != reqSortClass
)
12740 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12745 if( skillOrClass
< 0 )
12747 uint8 reqClass
= -int32(skillOrClass
);
12748 if(getClass() != reqClass
)
12751 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12756 else if( skillOrClass
> 0 )
12758 uint32 reqSkill
= skillOrClass
;
12759 if( GetSkillValue( reqSkill
) < qInfo
->GetRequiredSkillValue() )
12762 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12770 bool Player::SatisfyQuestLevel( Quest
const* qInfo
, bool msg
)
12772 if( getLevel() < qInfo
->GetMinLevel() )
12775 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12781 bool Player::SatisfyQuestLog( bool msg
)
12784 if( FindQuestSlot(0) < MAX_QUEST_LOG_SIZE
)
12789 WorldPacket
data( SMSG_QUESTLOG_FULL
, 0 );
12790 GetSession()->SendPacket( &data
);
12791 sLog
.outDebug( "WORLD: Sent QUEST_LOG_FULL_MESSAGE" );
12796 bool Player::SatisfyQuestPreviousQuest( Quest
const* qInfo
, bool msg
)
12798 // No previous quest (might be first quest in a series)
12799 if( qInfo
->prevQuests
.empty())
12802 for(Quest::PrevQuests::const_iterator iter
= qInfo
->prevQuests
.begin(); iter
!= qInfo
->prevQuests
.end(); ++iter
)
12804 uint32 prevId
= abs(*iter
);
12806 QuestStatusMap::iterator i_prevstatus
= mQuestStatus
.find( prevId
);
12807 Quest
const* qPrevInfo
= objmgr
.GetQuestTemplate(prevId
);
12809 if( qPrevInfo
&& i_prevstatus
!= mQuestStatus
.end() )
12811 // If any of the positive previous quests completed, return true
12812 if( *iter
> 0 && i_prevstatus
->second
.m_rewarded
)
12814 // skip one-from-all exclusive group
12815 if(qPrevInfo
->GetExclusiveGroup() >= 0)
12818 // each-from-all exclusive group ( < 0)
12819 // can be start if only all quests in prev quest exclusive group completed and rewarded
12820 ObjectMgr::ExclusiveQuestGroups::iterator iter
= objmgr
.mExclusiveQuestGroups
.lower_bound(qPrevInfo
->GetExclusiveGroup());
12821 ObjectMgr::ExclusiveQuestGroups::iterator end
= objmgr
.mExclusiveQuestGroups
.upper_bound(qPrevInfo
->GetExclusiveGroup());
12823 assert(iter
!=end
); // always must be found if qPrevInfo->ExclusiveGroup != 0
12825 for(; iter
!= end
; ++iter
)
12827 uint32 exclude_Id
= iter
->second
;
12829 // skip checked quest id, only state of other quests in group is interesting
12830 if(exclude_Id
== prevId
)
12833 QuestStatusMap::iterator i_exstatus
= mQuestStatus
.find( exclude_Id
);
12835 // alternative quest from group also must be completed and rewarded(reported)
12836 if( i_exstatus
== mQuestStatus
.end() || !i_exstatus
->second
.m_rewarded
)
12839 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12845 // If any of the negative previous quests active, return true
12846 if( *iter
< 0 && (i_prevstatus
->second
.m_status
== QUEST_STATUS_INCOMPLETE
12847 || (i_prevstatus
->second
.m_status
== QUEST_STATUS_COMPLETE
&& !GetQuestRewardStatus(prevId
))))
12849 // skip one-from-all exclusive group
12850 if(qPrevInfo
->GetExclusiveGroup() >= 0)
12853 // each-from-all exclusive group ( < 0)
12854 // can be start if only all quests in prev quest exclusive group active
12855 ObjectMgr::ExclusiveQuestGroups::iterator iter
= objmgr
.mExclusiveQuestGroups
.lower_bound(qPrevInfo
->GetExclusiveGroup());
12856 ObjectMgr::ExclusiveQuestGroups::iterator end
= objmgr
.mExclusiveQuestGroups
.upper_bound(qPrevInfo
->GetExclusiveGroup());
12858 assert(iter
!=end
); // always must be found if qPrevInfo->ExclusiveGroup != 0
12860 for(; iter
!= end
; ++iter
)
12862 uint32 exclude_Id
= iter
->second
;
12864 // skip checked quest id, only state of other quests in group is interesting
12865 if(exclude_Id
== prevId
)
12868 QuestStatusMap::iterator i_exstatus
= mQuestStatus
.find( exclude_Id
);
12870 // alternative quest from group also must be active
12871 if( i_exstatus
== mQuestStatus
.end() ||
12872 i_exstatus
->second
.m_status
!= QUEST_STATUS_INCOMPLETE
&&
12873 (i_prevstatus
->second
.m_status
!= QUEST_STATUS_COMPLETE
|| GetQuestRewardStatus(prevId
)) )
12876 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12885 // Has only positive prev. quests in non-rewarded state
12886 // and negative prev. quests in non-active state
12888 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12893 bool Player::SatisfyQuestRace( Quest
const* qInfo
, bool msg
)
12895 uint32 reqraces
= qInfo
->GetRequiredRaces();
12896 if ( reqraces
== 0 )
12898 if( (reqraces
& getRaceMask()) == 0 )
12901 SendCanTakeQuestResponse( INVALIDREASON_QUEST_FAILED_WRONG_RACE
);
12907 bool Player::SatisfyQuestReputation( Quest
const* qInfo
, bool msg
)
12909 uint32 fIdMin
= qInfo
->GetRequiredMinRepFaction(); //Min required rep
12910 if(fIdMin
&& GetReputation(fIdMin
) < qInfo
->GetRequiredMinRepValue())
12913 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12917 uint32 fIdMax
= qInfo
->GetRequiredMaxRepFaction(); //Max required rep
12918 if(fIdMax
&& GetReputation(fIdMax
) >= qInfo
->GetRequiredMaxRepValue())
12921 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12928 bool Player::SatisfyQuestStatus( Quest
const* qInfo
, bool msg
)
12930 QuestStatusMap::iterator itr
= mQuestStatus
.find( qInfo
->GetQuestId() );
12931 if ( itr
!= mQuestStatus
.end() && itr
->second
.m_status
!= QUEST_STATUS_NONE
)
12934 SendCanTakeQuestResponse( INVALIDREASON_QUEST_ALREADY_ON
);
12940 bool Player::SatisfyQuestTimed( Quest
const* qInfo
, bool msg
)
12942 if ( (find(m_timedquests
.begin(), m_timedquests
.end(), qInfo
->GetQuestId()) != m_timedquests
.end()) && qInfo
->HasFlag(QUEST_MANGOS_FLAGS_TIMED
) )
12945 SendCanTakeQuestResponse( INVALIDREASON_QUEST_ONLY_ONE_TIMED
);
12951 bool Player::SatisfyQuestExclusiveGroup( Quest
const* qInfo
, bool msg
)
12953 // non positive exclusive group, if > 0 then can be start if any other quest in exclusive group already started/completed
12954 if(qInfo
->GetExclusiveGroup() <= 0)
12957 ObjectMgr::ExclusiveQuestGroups::iterator iter
= objmgr
.mExclusiveQuestGroups
.lower_bound(qInfo
->GetExclusiveGroup());
12958 ObjectMgr::ExclusiveQuestGroups::iterator end
= objmgr
.mExclusiveQuestGroups
.upper_bound(qInfo
->GetExclusiveGroup());
12960 assert(iter
!=end
); // always must be found if qInfo->ExclusiveGroup != 0
12962 for(; iter
!= end
; ++iter
)
12964 uint32 exclude_Id
= iter
->second
;
12966 // skip checked quest id, only state of other quests in group is interesting
12967 if(exclude_Id
== qInfo
->GetQuestId())
12970 // not allow have daily quest if daily quest from exclusive group already recently completed
12971 Quest
const* Nquest
= objmgr
.GetQuestTemplate(exclude_Id
);
12972 if( !SatisfyQuestDay(Nquest
, false) )
12975 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12979 QuestStatusMap::iterator i_exstatus
= mQuestStatus
.find( exclude_Id
);
12981 // alternative quest already started or completed
12982 if( i_exstatus
!= mQuestStatus
.end()
12983 && (i_exstatus
->second
.m_status
== QUEST_STATUS_COMPLETE
|| i_exstatus
->second
.m_status
== QUEST_STATUS_INCOMPLETE
) )
12986 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12993 bool Player::SatisfyQuestNextChain( Quest
const* qInfo
, bool msg
)
12995 if(!qInfo
->GetNextQuestInChain())
12998 // next quest in chain already started or completed
12999 QuestStatusMap::iterator itr
= mQuestStatus
.find( qInfo
->GetNextQuestInChain() );
13000 if( itr
!= mQuestStatus
.end()
13001 && (itr
->second
.m_status
== QUEST_STATUS_COMPLETE
|| itr
->second
.m_status
== QUEST_STATUS_INCOMPLETE
) )
13004 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
13008 // check for all quests further up the chain
13009 // only necessary if there are quest chains with more than one quest that can be skipped
13010 //return SatisfyQuestNextChain( qInfo->GetNextQuestInChain(), msg );
13014 bool Player::SatisfyQuestPrevChain( Quest
const* qInfo
, bool msg
)
13016 // No previous quest in chain
13017 if( qInfo
->prevChainQuests
.empty())
13020 for(Quest::PrevChainQuests::const_iterator iter
= qInfo
->prevChainQuests
.begin(); iter
!= qInfo
->prevChainQuests
.end(); ++iter
)
13022 uint32 prevId
= *iter
;
13024 QuestStatusMap::iterator i_prevstatus
= mQuestStatus
.find( prevId
);
13026 if( i_prevstatus
!= mQuestStatus
.end() )
13028 // If any of the previous quests in chain active, return false
13029 if( i_prevstatus
->second
.m_status
== QUEST_STATUS_INCOMPLETE
13030 || (i_prevstatus
->second
.m_status
== QUEST_STATUS_COMPLETE
&& !GetQuestRewardStatus(prevId
)))
13033 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
13038 // check for all quests further down the chain
13039 // only necessary if there are quest chains with more than one quest that can be skipped
13040 //if( !SatisfyQuestPrevChain( prevId, msg ) )
13044 // No previous quest in chain active
13048 bool Player::SatisfyQuestDay( Quest
const* qInfo
, bool msg
)
13050 if(!qInfo
->IsDaily())
13053 bool have_slot
= false;
13054 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
13056 uint32 id
= GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
);
13057 if(qInfo
->GetQuestId()==id
)
13067 SendCanTakeQuestResponse( INVALIDREASON_DAILY_QUESTS_REMAINING
);
13074 bool Player::GiveQuestSourceItem( Quest
const *pQuest
)
13076 uint32 srcitem
= pQuest
->GetSrcItemId();
13079 uint32 count
= pQuest
->GetSrcItemCount();
13083 ItemPosCountVec dest
;
13084 uint8 msg
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, srcitem
, count
);
13085 if( msg
== EQUIP_ERR_OK
)
13087 Item
* item
= StoreNewItem(dest
, srcitem
, true);
13088 SendNewItem(item
, count
, true, false);
13091 // player already have max amount required item, just report success
13092 else if( msg
== EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
)
13095 SendEquipError( msg
, NULL
, NULL
);
13102 bool Player::TakeQuestSourceItem( uint32 quest_id
, bool msg
)
13104 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
13107 uint32 srcitem
= qInfo
->GetSrcItemId();
13110 uint32 count
= qInfo
->GetSrcItemCount();
13114 // exist one case when destroy source quest item not possible:
13115 // non un-equippable item (equipped non-empty bag, for example)
13116 uint8 res
= CanUnequipItems(srcitem
,count
);
13117 if(res
!= EQUIP_ERR_OK
)
13120 SendEquipError( res
, NULL
, NULL
);
13124 DestroyItemCount(srcitem
, count
, true, true);
13130 bool Player::GetQuestRewardStatus( uint32 quest_id
) const
13132 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
13135 // for repeatable quests: rewarded field is set after first reward only to prevent getting XP more than once
13136 QuestStatusMap::const_iterator itr
= mQuestStatus
.find( quest_id
);
13137 if( itr
!= mQuestStatus
.end() && itr
->second
.m_status
!= QUEST_STATUS_NONE
13138 && !qInfo
->IsRepeatable() )
13139 return itr
->second
.m_rewarded
;
13146 QuestStatus
Player::GetQuestStatus( uint32 quest_id
) const
13150 QuestStatusMap::const_iterator itr
= mQuestStatus
.find( quest_id
);
13151 if( itr
!= mQuestStatus
.end() )
13152 return itr
->second
.m_status
;
13154 return QUEST_STATUS_NONE
;
13157 bool Player::CanShareQuest(uint32 quest_id
) const
13159 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
13160 if( qInfo
&& qInfo
->HasFlag(QUEST_FLAGS_SHARABLE
) )
13162 QuestStatusMap::const_iterator itr
= mQuestStatus
.find( quest_id
);
13163 if( itr
!= mQuestStatus
.end() )
13164 return itr
->second
.m_status
== QUEST_STATUS_NONE
|| itr
->second
.m_status
== QUEST_STATUS_INCOMPLETE
;
13169 void Player::SetQuestStatus( uint32 quest_id
, QuestStatus status
)
13171 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
13174 if( status
== QUEST_STATUS_NONE
|| status
== QUEST_STATUS_INCOMPLETE
|| status
== QUEST_STATUS_COMPLETE
)
13176 if( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_TIMED
) )
13177 m_timedquests
.erase(qInfo
->GetQuestId());
13180 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
13182 q_status
.m_status
= status
;
13183 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13186 UpdateForQuestsGO();
13189 // not used in MaNGOS, but used in scripting code
13190 uint32
Player::GetReqKillOrCastCurrentCount(uint32 quest_id
, int32 entry
)
13192 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
13196 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13197 if ( qInfo
->ReqCreatureOrGOId
[j
] == entry
)
13198 return mQuestStatus
[quest_id
].m_creatureOrGOcount
[j
];
13203 void Player::AdjustQuestReqItemCount( Quest
const* pQuest
)
13205 if ( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
13207 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
13209 uint32 reqitemcount
= pQuest
->ReqItemCount
[i
];
13210 if( reqitemcount
!= 0 )
13212 uint32 quest_id
= pQuest
->GetQuestId();
13213 uint32 curitemcount
= GetItemCount(pQuest
->ReqItemId
[i
],true);
13215 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
13216 q_status
.m_itemcount
[i
] = std::min(curitemcount
, reqitemcount
);
13217 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13223 uint16
Player::FindQuestSlot( uint32 quest_id
) const
13225 for ( uint16 i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13226 if ( GetQuestSlotQuestId(i
) == quest_id
)
13229 return MAX_QUEST_LOG_SIZE
;
13232 void Player::AreaExploredOrEventHappens( uint32 questId
)
13236 uint16 log_slot
= FindQuestSlot( questId
);
13237 if( log_slot
< MAX_QUEST_LOG_SIZE
)
13239 QuestStatusData
& q_status
= mQuestStatus
[questId
];
13241 if(!q_status
.m_explored
)
13243 q_status
.m_explored
= true;
13244 if (q_status
.uState
!= QUEST_NEW
)
13245 q_status
.uState
= QUEST_CHANGED
;
13248 if( CanCompleteQuest( questId
) )
13249 CompleteQuest( questId
);
13253 //not used in mangosd, function for external script library
13254 void Player::GroupEventHappens( uint32 questId
, WorldObject
const* pEventObject
)
13256 if( Group
*pGroup
= GetGroup() )
13258 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
13260 Player
*pGroupGuy
= itr
->getSource();
13262 // for any leave or dead (with not released body) group member at appropriate distance
13263 if( pGroupGuy
&& pGroupGuy
->IsAtGroupRewardDistance(pEventObject
) && !pGroupGuy
->GetCorpse() )
13264 pGroupGuy
->AreaExploredOrEventHappens(questId
);
13268 AreaExploredOrEventHappens(questId
);
13271 void Player::ItemAddedQuestCheck( uint32 entry
, uint32 count
)
13273 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13275 uint32 questid
= GetQuestSlotQuestId(i
);
13276 if ( questid
== 0 )
13279 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13281 if ( q_status
.m_status
!= QUEST_STATUS_INCOMPLETE
)
13284 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13285 if( !qInfo
|| !qInfo
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
13288 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13290 uint32 reqitem
= qInfo
->ReqItemId
[j
];
13291 if ( reqitem
== entry
)
13293 uint32 reqitemcount
= qInfo
->ReqItemCount
[j
];
13294 uint32 curitemcount
= q_status
.m_itemcount
[j
];
13295 if ( curitemcount
< reqitemcount
)
13297 uint32 additemcount
= ( curitemcount
+ count
<= reqitemcount
? count
: reqitemcount
- curitemcount
);
13298 q_status
.m_itemcount
[j
] += additemcount
;
13299 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13301 SendQuestUpdateAddItem( qInfo
, j
, additemcount
);
13303 if ( CanCompleteQuest( questid
) )
13304 CompleteQuest( questid
);
13309 UpdateForQuestsGO();
13310 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM
, entry
);
13313 void Player::ItemRemovedQuestCheck( uint32 entry
, uint32 count
)
13315 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13317 uint32 questid
= GetQuestSlotQuestId(i
);
13320 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13323 if( !qInfo
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
13326 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13328 uint32 reqitem
= qInfo
->ReqItemId
[j
];
13329 if ( reqitem
== entry
)
13331 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13333 uint32 reqitemcount
= qInfo
->ReqItemCount
[j
];
13334 uint32 curitemcount
;
13335 if( q_status
.m_status
!= QUEST_STATUS_COMPLETE
)
13336 curitemcount
= q_status
.m_itemcount
[j
];
13338 curitemcount
= GetItemCount(entry
,true);
13339 if ( curitemcount
< reqitemcount
+ count
)
13341 uint32 remitemcount
= ( curitemcount
<= reqitemcount
? count
: count
+ reqitemcount
- curitemcount
);
13342 q_status
.m_itemcount
[j
] = curitemcount
- remitemcount
;
13343 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13345 IncompleteQuest( questid
);
13351 UpdateForQuestsGO();
13354 void Player::KilledMonster( uint32 entry
, uint64 guid
)
13356 uint32 addkillcount
= 1;
13357 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE
, entry
, addkillcount
);
13358 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13360 uint32 questid
= GetQuestSlotQuestId(i
);
13364 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13367 // just if !ingroup || !noraidgroup || raidgroup
13368 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13369 if( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
&& (!GetGroup() || !GetGroup()->isRaidGroup() || qInfo
->GetType() == QUEST_TYPE_RAID
))
13371 if( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_KILL_OR_CAST
) )
13373 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13375 // skip GO activate objective or none
13376 if(qInfo
->ReqCreatureOrGOId
[j
] <=0)
13379 // skip Cast at creature objective
13380 if(qInfo
->ReqSpell
[j
] !=0 )
13383 uint32 reqkill
= qInfo
->ReqCreatureOrGOId
[j
];
13385 if ( reqkill
== entry
)
13387 uint32 reqkillcount
= qInfo
->ReqCreatureOrGOCount
[j
];
13388 uint32 curkillcount
= q_status
.m_creatureOrGOcount
[j
];
13389 if ( curkillcount
< reqkillcount
)
13391 q_status
.m_creatureOrGOcount
[j
] = curkillcount
+ addkillcount
;
13392 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13394 SendQuestUpdateAddCreatureOrGo( qInfo
, guid
, j
, curkillcount
, addkillcount
);
13396 if ( CanCompleteQuest( questid
) )
13397 CompleteQuest( questid
);
13399 // same objective target can be in many active quests, but not in 2 objectives for single quest (code optimization).
13408 void Player::CastedCreatureOrGO( uint32 entry
, uint64 guid
, uint32 spell_id
)
13410 bool isCreature
= IS_CREATURE_GUID(guid
);
13412 uint32 addCastCount
= 1;
13413 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13415 uint32 questid
= GetQuestSlotQuestId(i
);
13419 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13423 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13425 if ( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
13427 if( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_KILL_OR_CAST
) )
13429 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13431 // skip kill creature objective (0) or wrong spell casts
13432 if(qInfo
->ReqSpell
[j
] != spell_id
)
13435 uint32 reqTarget
= 0;
13439 // creature activate objectives
13440 if(qInfo
->ReqCreatureOrGOId
[j
] > 0)
13441 // checked at quest_template loading
13442 reqTarget
= qInfo
->ReqCreatureOrGOId
[j
];
13446 // GO activate objective
13447 if(qInfo
->ReqCreatureOrGOId
[j
] < 0)
13448 // checked at quest_template loading
13449 reqTarget
= - qInfo
->ReqCreatureOrGOId
[j
];
13452 // other not this creature/GO related objectives
13453 if( reqTarget
!= entry
)
13456 uint32 reqCastCount
= qInfo
->ReqCreatureOrGOCount
[j
];
13457 uint32 curCastCount
= q_status
.m_creatureOrGOcount
[j
];
13458 if ( curCastCount
< reqCastCount
)
13460 q_status
.m_creatureOrGOcount
[j
] = curCastCount
+ addCastCount
;
13461 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13463 SendQuestUpdateAddCreatureOrGo( qInfo
, guid
, j
, curCastCount
, addCastCount
);
13466 if ( CanCompleteQuest( questid
) )
13467 CompleteQuest( questid
);
13469 // same objective target can be in many active quests, but not in 2 objectives for single quest (code optimization).
13477 void Player::TalkedToCreature( uint32 entry
, uint64 guid
)
13479 uint32 addTalkCount
= 1;
13480 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13482 uint32 questid
= GetQuestSlotQuestId(i
);
13486 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13490 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13492 if ( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
13494 if( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_KILL_OR_CAST
| QUEST_MANGOS_FLAGS_SPEAKTO
) )
13496 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13498 // skip spell casts and Gameobject objectives
13499 if(qInfo
->ReqSpell
[j
] > 0 || qInfo
->ReqCreatureOrGOId
[j
] < 0)
13502 uint32 reqTarget
= 0;
13504 if(qInfo
->ReqCreatureOrGOId
[j
] > 0) // creature activate objectives
13505 // checked at quest_template loading
13506 reqTarget
= qInfo
->ReqCreatureOrGOId
[j
];
13510 if ( reqTarget
== entry
)
13512 uint32 reqTalkCount
= qInfo
->ReqCreatureOrGOCount
[j
];
13513 uint32 curTalkCount
= q_status
.m_creatureOrGOcount
[j
];
13514 if ( curTalkCount
< reqTalkCount
)
13516 q_status
.m_creatureOrGOcount
[j
] = curTalkCount
+ addTalkCount
;
13517 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13519 SendQuestUpdateAddCreatureOrGo( qInfo
, guid
, j
, curTalkCount
, addTalkCount
);
13521 if ( CanCompleteQuest( questid
) )
13522 CompleteQuest( questid
);
13524 // same objective target can be in many active quests, but not in 2 objectives for single quest (code optimization).
13533 void Player::MoneyChanged( uint32 count
)
13535 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13537 uint32 questid
= GetQuestSlotQuestId(i
);
13541 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13542 if( qInfo
&& qInfo
->GetRewOrReqMoney() < 0 )
13544 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13546 if( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
13548 if(int32(count
) >= -qInfo
->GetRewOrReqMoney())
13550 if ( CanCompleteQuest( questid
) )
13551 CompleteQuest( questid
);
13554 else if( q_status
.m_status
== QUEST_STATUS_COMPLETE
)
13556 if(int32(count
) < -qInfo
->GetRewOrReqMoney())
13557 IncompleteQuest( questid
);
13563 bool Player::HasQuestForItem( uint32 itemid
) const
13565 for( QuestStatusMap::const_iterator i
= mQuestStatus
.begin( ); i
!= mQuestStatus
.end( ); ++i
)
13567 QuestStatusData
const& q_status
= i
->second
;
13569 if (q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
13571 Quest
const* qinfo
= objmgr
.GetQuestTemplate(i
->first
);
13575 // hide quest if player is in raid-group and quest is no raid quest
13576 if(GetGroup() && GetGroup()->isRaidGroup() && qinfo
->GetType() != QUEST_TYPE_RAID
)
13579 // There should be no mixed ReqItem/ReqSource drop
13580 // This part for ReqItem drop
13581 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13583 if(itemid
== qinfo
->ReqItemId
[j
] && q_status
.m_itemcount
[j
] < qinfo
->ReqItemCount
[j
] )
13586 // This part - for ReqSource
13587 for (int j
= 0; j
< QUEST_SOURCE_ITEM_IDS_COUNT
; j
++)
13589 // examined item is a source item
13590 if (qinfo
->ReqSourceId
[j
] == itemid
&& qinfo
->ReqSourceRef
[j
] > 0 && qinfo
->ReqSourceRef
[j
] <= QUEST_OBJECTIVES_COUNT
)
13592 uint32 idx
= qinfo
->ReqSourceRef
[j
]-1;
13594 // total count of created ReqItems and SourceItems is less than ReqItemCount
13595 if(qinfo
->ReqItemId
[idx
] != 0 &&
13596 q_status
.m_itemcount
[idx
] * qinfo
->ReqSourceCount
[j
] + GetItemCount(itemid
,true) < qinfo
->ReqItemCount
[idx
] * qinfo
->ReqSourceCount
[j
])
13599 // total count of casted ReqCreatureOrGOs and SourceItems is less than ReqCreatureOrGOCount
13600 if (qinfo
->ReqCreatureOrGOId
[idx
] != 0)
13602 if(q_status
.m_creatureOrGOcount
[idx
] * qinfo
->ReqSourceCount
[j
] + GetItemCount(itemid
,true) < qinfo
->ReqCreatureOrGOCount
[idx
] * qinfo
->ReqSourceCount
[j
])
13605 // spell with SPELL_EFFECT_QUEST_COMPLETE or SPELL_EFFECT_SEND_EVENT (with script) case
13606 else if(qinfo
->ReqSpell
[idx
] != 0)
13608 // not casted and need more reagents/item for use.
13609 if(!q_status
.m_explored
&& GetItemCount(itemid
,true) < qinfo
->ReqSourceCount
[j
])
13619 void Player::SendQuestComplete( uint32 quest_id
)
13623 WorldPacket
data( SMSG_QUESTUPDATE_COMPLETE
, 4 );
13624 data
<< uint32(quest_id
);
13625 GetSession()->SendPacket( &data
);
13626 sLog
.outDebug( "WORLD: Sent SMSG_QUESTUPDATE_COMPLETE quest = %u", quest_id
);
13630 void Player::SendQuestReward( Quest
const *pQuest
, uint32 XP
, Object
* questGiver
)
13632 uint32 questid
= pQuest
->GetQuestId();
13633 sLog
.outDebug( "WORLD: Sent SMSG_QUESTGIVER_QUEST_COMPLETE quest = %u", questid
);
13634 WorldPacket
data( SMSG_QUESTGIVER_QUEST_COMPLETE
, (4+4+4+4+4) );
13635 data
<< uint32(questid
);
13637 if ( getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) )
13639 data
<< uint32(XP
);
13640 data
<< uint32(pQuest
->GetRewOrReqMoney());
13645 data
<< uint32(pQuest
->GetRewOrReqMoney() + int32(pQuest
->GetRewMoneyMaxLevel() * sWorld
.getRate(RATE_DROP_MONEY
)));
13648 data
<< uint32(10*MaNGOS::Honor::hk_honor_at_level(getLevel(), pQuest
->GetRewHonorableKills()));
13649 data
<< uint32(pQuest
->GetBonusTalents()); // bonus talents
13650 GetSession()->SendPacket( &data
);
13652 if (pQuest
->GetQuestCompleteScript() != 0)
13653 sWorld
.ScriptsStart(sQuestEndScripts
, pQuest
->GetQuestCompleteScript(), questGiver
, this);
13656 void Player::SendQuestFailed( uint32 quest_id
)
13660 WorldPacket
data( SMSG_QUESTGIVER_QUEST_FAILED
, 4+4 );
13662 data
<< uint32(0); // failed reason (4 for inventory is full)
13663 GetSession()->SendPacket( &data
);
13664 sLog
.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_FAILED");
13668 void Player::SendQuestTimerFailed( uint32 quest_id
)
13672 WorldPacket
data( SMSG_QUESTUPDATE_FAILEDTIMER
, 4 );
13674 GetSession()->SendPacket( &data
);
13675 sLog
.outDebug("WORLD: Sent SMSG_QUESTUPDATE_FAILEDTIMER");
13679 void Player::SendCanTakeQuestResponse( uint32 msg
)
13681 WorldPacket
data( SMSG_QUESTGIVER_QUEST_INVALID
, 4 );
13682 data
<< uint32(msg
);
13683 GetSession()->SendPacket( &data
);
13684 sLog
.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_INVALID");
13687 void Player::SendPushToPartyResponse( Player
*pPlayer
, uint32 msg
)
13691 WorldPacket
data( MSG_QUEST_PUSH_RESULT
, (8+1) );
13692 data
<< uint64(pPlayer
->GetGUID());
13693 data
<< uint8(msg
); // valid values: 0-8
13694 GetSession()->SendPacket( &data
);
13695 sLog
.outDebug("WORLD: Sent MSG_QUEST_PUSH_RESULT");
13699 void Player::SendQuestUpdateAddItem( Quest
const* pQuest
, uint32 item_idx
, uint32 count
)
13701 WorldPacket
data( SMSG_QUESTUPDATE_ADD_ITEM
, 0 );
13702 sLog
.outDebug( "WORLD: Sent SMSG_QUESTUPDATE_ADD_ITEM" );
13703 //data << pQuest->ReqItemId[item_idx];
13705 GetSession()->SendPacket( &data
);
13708 void Player::SendQuestUpdateAddCreatureOrGo( Quest
const* pQuest
, uint64 guid
, uint32 creatureOrGO_idx
, uint32 old_count
, uint32 add_count
)
13710 assert(old_count
+ add_count
< 256 && "mob/GO count store in 8 bits 2^8 = 256 (0..256)");
13712 int32 entry
= pQuest
->ReqCreatureOrGOId
[ creatureOrGO_idx
];
13714 // client expected gameobject template id in form (id|0x80000000)
13715 entry
= (-entry
) | 0x80000000;
13717 WorldPacket
data( SMSG_QUESTUPDATE_ADD_KILL
, (4*4+8) );
13718 sLog
.outDebug( "WORLD: Sent SMSG_QUESTUPDATE_ADD_KILL" );
13719 data
<< uint32(pQuest
->GetQuestId());
13720 data
<< uint32(entry
);
13721 data
<< uint32(old_count
+ add_count
);
13722 data
<< uint32(pQuest
->ReqCreatureOrGOCount
[ creatureOrGO_idx
]);
13723 data
<< uint64(guid
);
13724 GetSession()->SendPacket(&data
);
13726 uint16 log_slot
= FindQuestSlot( pQuest
->GetQuestId() );
13727 if( log_slot
< MAX_QUEST_LOG_SIZE
)
13728 SetQuestSlotCounter(log_slot
,creatureOrGO_idx
,GetQuestSlotCounter(log_slot
,creatureOrGO_idx
)+add_count
);
13731 /*********************************************************/
13732 /*** LOAD SYSTEM ***/
13733 /*********************************************************/
13735 bool Player::MinimalLoadFromDB( QueryResult
*result
, uint32 guid
)
13737 bool delete_result
= true;
13740 // 0 1 2 3 4 5 6 7 8 9
13741 result
= CharacterDatabase
.PQuery("SELECT guid, data, name, position_x, position_y, position_z, map, totaltime, leveltime, at_login FROM characters WHERE guid = '%u'",guid
);
13742 if(!result
) return false;
13744 else delete_result
= false;
13746 Field
*fields
= result
->Fetch();
13748 if(!LoadValues( fields
[1].GetString()))
13750 sLog
.outError("ERROR: Player #%d have broken data in `data` field. Can't be loaded for character list.",GUID_LOPART(guid
));
13751 if(delete_result
) delete result
;
13755 // overwrite possible wrong/corrupted guid
13756 SetUInt64Value(OBJECT_FIELD_GUID
, MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
));
13758 m_name
= fields
[2].GetCppString();
13760 Relocate(fields
[3].GetFloat(),fields
[4].GetFloat(),fields
[5].GetFloat());
13761 SetMapId(fields
[6].GetUInt32());
13762 // the instance id is not needed at character enum
13764 m_Played_time
[0] = fields
[7].GetUInt32();
13765 m_Played_time
[1] = fields
[8].GetUInt32();
13767 m_atLoginFlags
= fields
[9].GetUInt32();
13769 // I don't see these used anywhere ..
13772 _LoadBoundInstances();*/
13774 if (delete_result
) delete result
;
13776 for (int i
= 0; i
< PLAYER_SLOTS_COUNT
; i
++)
13779 if( HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
) )
13780 m_deathState
= DEAD
;
13785 void Player::_LoadDeclinedNames(QueryResult
* result
)
13791 delete m_declinedname
;
13793 m_declinedname
= new DeclinedName
;
13794 Field
*fields
= result
->Fetch();
13795 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
13796 m_declinedname
->name
[i
] = fields
[i
].GetCppString();
13801 void Player::_LoadArenaTeamInfo(QueryResult
*result
)
13803 // arenateamid, played_week, played_season, personal_rating
13804 memset((void*)&m_uint32Values
[PLAYER_FIELD_ARENA_TEAM_INFO_1_1
], 0, sizeof(uint32
)*18);
13810 Field
*fields
= result
->Fetch();
13812 uint32 arenateamid
= fields
[0].GetUInt32();
13813 uint32 played_week
= fields
[1].GetUInt32();
13814 uint32 played_season
= fields
[2].GetUInt32();
13815 uint32 personal_rating
= fields
[3].GetUInt32();
13817 ArenaTeam
* aTeam
= objmgr
.GetArenaTeamById(arenateamid
);
13820 sLog
.outError("Player::_LoadArenaTeamInfo: couldn't load arenateam %u, week %u, season %u, rating %u", arenateamid
, played_week
, played_season
, personal_rating
);
13823 uint8 arenaSlot
= aTeam
->GetSlot();
13825 m_uint32Values
[PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ arenaSlot
* 6] = arenateamid
; // TeamID
13826 m_uint32Values
[PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ arenaSlot
* 6 + 1] = ((aTeam
->GetCaptain() == GetGUID()) ? (uint32
)0 : (uint32
)1); // Captain 0, member 1
13827 m_uint32Values
[PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ arenaSlot
* 6 + 2] = played_week
; // Played Week
13828 m_uint32Values
[PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ arenaSlot
* 6 + 3] = played_season
; // Played Season
13829 m_uint32Values
[PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ arenaSlot
* 6 + 4] = 0; // Unk
13830 m_uint32Values
[PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ arenaSlot
* 6 + 5] = personal_rating
; // Personal Rating
13832 }while (result
->NextRow());
13836 bool Player::LoadPositionFromDB(uint32
& mapid
, float& x
,float& y
,float& z
,float& o
, bool& in_flight
, uint64 guid
)
13838 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT position_x,position_y,position_z,orientation,map,taxi_path FROM characters WHERE guid = '%u'",GUID_LOPART(guid
));
13842 Field
*fields
= result
->Fetch();
13844 x
= fields
[0].GetFloat();
13845 y
= fields
[1].GetFloat();
13846 z
= fields
[2].GetFloat();
13847 o
= fields
[3].GetFloat();
13848 mapid
= fields
[4].GetUInt32();
13849 in_flight
= !fields
[5].GetCppString().empty();
13855 bool Player::LoadValuesArrayFromDB(Tokens
& data
, uint64 guid
)
13857 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT data FROM characters WHERE guid='%u'",GUID_LOPART(guid
));
13861 Field
*fields
= result
->Fetch();
13863 data
= StrSplit(fields
[0].GetCppString(), " ");
13870 uint32
Player::GetUInt32ValueFromArray(Tokens
const& data
, uint16 index
)
13872 if(index
>= data
.size())
13875 return (uint32
)atoi(data
[index
].c_str());
13878 float Player::GetFloatValueFromArray(Tokens
const& data
, uint16 index
)
13881 uint32 temp
= Player::GetUInt32ValueFromArray(data
,index
);
13882 memcpy(&result
, &temp
, sizeof(result
));
13887 uint32
Player::GetUInt32ValueFromDB(uint16 index
, uint64 guid
)
13890 if(!LoadValuesArrayFromDB(data
,guid
))
13893 return GetUInt32ValueFromArray(data
,index
);
13896 float Player::GetFloatValueFromDB(uint16 index
, uint64 guid
)
13899 uint32 temp
= Player::GetUInt32ValueFromDB(index
, guid
);
13900 memcpy(&result
, &temp
, sizeof(result
));
13905 bool Player::LoadFromDB( uint32 guid
, SqlQueryHolder
*holder
)
13907 //// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [28] [29] 30 31 32 33
13908 //QueryResult *result = CharacterDatabase.PQuery("SELECT guid, account, data, name, race, class, position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeon_difficulty, arena_pending_points FROM characters WHERE guid = '%u'", guid);
13909 QueryResult
*result
= holder
->GetResult(PLAYER_LOGIN_QUERY_LOADFROM
);
13913 sLog
.outError("ERROR: Player (GUID: %u) not found in table `characters`, can't load. ",guid
);
13917 Field
*fields
= result
->Fetch();
13919 uint32 dbAccountId
= fields
[1].GetUInt32();
13921 // check if the character's account in the db and the logged in account match.
13922 // player should be able to load/delete character only with correct account!
13923 if( dbAccountId
!= GetSession()->GetAccountId() )
13925 sLog
.outError("ERROR: Player (GUID: %u) loading from wrong account (is: %u, should be: %u)",guid
,GetSession()->GetAccountId(),dbAccountId
);
13930 Object::_Create( guid
, 0, HIGHGUID_PLAYER
);
13932 m_name
= fields
[3].GetCppString();
13934 // check name limitations
13935 if(!ObjectMgr::IsValidName(m_name
) || GetSession()->GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(m_name
))
13938 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid ='%u'", uint32(AT_LOGIN_RENAME
),guid
);
13942 if(!LoadValues( fields
[2].GetString()))
13944 sLog
.outError("ERROR: Player #%d have broken data in `data` field. Can't be loaded.",GUID_LOPART(guid
));
13949 // overwrite possible wrong/corrupted guid
13950 SetUInt64Value(OBJECT_FIELD_GUID
, MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
));
13952 // cleanup inventory related item value fields (its will be filled correctly in _LoadInventory)
13953 for(uint8 slot
= EQUIPMENT_SLOT_START
; slot
< EQUIPMENT_SLOT_END
; ++slot
)
13955 SetUInt64Value( (uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
* 2) ), 0 );
13956 SetVisibleItemSlot(slot
,NULL
);
13960 delete m_items
[slot
];
13961 m_items
[slot
] = NULL
;
13965 // update money limits
13966 if(GetMoney() > MAX_MONEY_AMOUNT
)
13967 SetMoney(MAX_MONEY_AMOUNT
);
13969 sLog
.outDebug("Load Basic value of player %s is: ", m_name
.c_str());
13972 m_race
= fields
[4].GetUInt8();
13973 //Need to call it to initialize m_team (m_team can be calculated from m_race)
13974 //Other way is to saves m_team into characters table.
13975 setFactionForRace(m_race
);
13978 m_class
= fields
[5].GetUInt8();
13980 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(m_race
, m_class
);
13983 sLog
.outError("Player have incorrect race/class pair. Can't be loaded.");
13988 InitPrimaryProffesions(); // to max set before any spell loaded
13990 uint32 transGUID
= fields
[24].GetUInt32();
13991 Relocate(fields
[6].GetFloat(),fields
[7].GetFloat(),fields
[8].GetFloat(),fields
[10].GetFloat());
13992 SetMapId(fields
[9].GetUInt32());
13993 SetDifficulty(fields
[32].GetUInt32()); // may be changed in _LoadGroup
13995 _LoadGroup(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADGROUP
));
13997 _LoadArenaTeamInfo(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADARENAINFO
));
13999 uint32 arena_currency
= GetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY
) + fields
[33].GetUInt32();
14000 if (arena_currency
> sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
))
14001 arena_currency
= sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
);
14003 SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY
, arena_currency
);
14005 // check arena teams integrity
14006 for(uint32 arena_slot
= 0; arena_slot
< MAX_ARENA_SLOT
; ++arena_slot
)
14008 uint32 arena_team_id
= GetArenaTeamId(arena_slot
);
14012 if(ArenaTeam
* at
= objmgr
.GetArenaTeamById(arena_team_id
))
14013 if(at
->HaveMember(GetGUID()))
14016 // arena team not exist or not member, cleanup fields
14017 for(int j
=0; j
< 6; ++j
)
14018 SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ arena_slot
* 6 + j
, 0);
14021 _LoadBoundInstances(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADBOUNDINSTANCES
));
14023 if(!IsPositionValid())
14025 sLog
.outError("ERROR: Player (guidlow %d) have invalid coordinates (X: %f Y: %f Z: %f O: %f). Teleport to default race/class locations.",guid
,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation());
14027 SetMapId(info
->mapId
);
14028 Relocate(info
->positionX
,info
->positionY
,info
->positionZ
,0.0f
);
14032 m_movementInfo
.t_x
= 0.0f
;
14033 m_movementInfo
.t_y
= 0.0f
;
14034 m_movementInfo
.t_z
= 0.0f
;
14035 m_movementInfo
.t_o
= 0.0f
;
14038 // load the player's map here if it's not already loaded
14039 Map
*map
= GetMap();
14040 // since the player may not be bound to the map yet, make sure subsequent
14041 // getmap calls won't create new maps
14042 SetInstanceId(map
->GetInstanceId());
14044 // if the player is in an instance and it has been reset in the meantime teleport him to the entrance
14045 if(GetInstanceId() && !sInstanceSaveManager
.GetInstanceSave(GetInstanceId()))
14047 AreaTrigger
const* at
= objmgr
.GetMapEntranceTrigger(GetMapId());
14049 Relocate(at
->target_X
, at
->target_Y
, at
->target_Z
, at
->target_Orientation
);
14051 sLog
.outError("Player %s(GUID: %u) logged in to a reset instance (map: %u) and there is no aretrigger leading to this map. Thus he can't be ported back to the entrance. This _might_ be an exploit attempt.", GetName(), GetGUIDLow(), GetMapId());
14054 SaveRecallPosition();
14056 if (transGUID
!= 0)
14058 m_movementInfo
.t_x
= fields
[20].GetFloat();
14059 m_movementInfo
.t_y
= fields
[21].GetFloat();
14060 m_movementInfo
.t_z
= fields
[22].GetFloat();
14061 m_movementInfo
.t_o
= fields
[23].GetFloat();
14063 if( !MaNGOS::IsValidMapCoord(
14064 GetPositionX()+m_movementInfo
.t_x
,GetPositionY()+m_movementInfo
.t_y
,
14065 GetPositionZ()+m_movementInfo
.t_z
,GetOrientation()+m_movementInfo
.t_o
) ||
14066 // transport size limited
14067 m_movementInfo
.t_x
> 50 || m_movementInfo
.t_y
> 50 || m_movementInfo
.t_z
> 50 )
14069 sLog
.outError("ERROR: Player (guidlow %d) have invalid transport coordinates (X: %f Y: %f Z: %f O: %f). Teleport to default race/class locations.",
14070 guid
,GetPositionX()+m_movementInfo
.t_x
,GetPositionY()+m_movementInfo
.t_y
,
14071 GetPositionZ()+m_movementInfo
.t_z
,GetOrientation()+m_movementInfo
.t_o
);
14073 SetMapId(info
->mapId
);
14074 Relocate(info
->positionX
,info
->positionY
,info
->positionZ
,0.0f
);
14076 m_movementInfo
.t_x
= 0.0f
;
14077 m_movementInfo
.t_y
= 0.0f
;
14078 m_movementInfo
.t_z
= 0.0f
;
14079 m_movementInfo
.t_o
= 0.0f
;
14085 if (transGUID
!= 0)
14087 for (MapManager::TransportSet::iterator iter
= MapManager::Instance().m_Transports
.begin(); iter
!= MapManager::Instance().m_Transports
.end(); ++iter
)
14089 if( (*iter
)->GetGUIDLow() == transGUID
)
14091 m_transport
= *iter
;
14092 m_transport
->AddPassenger(this);
14093 SetMapId(m_transport
->GetMapId());
14100 sLog
.outError("ERROR: Player (guidlow %d) have invalid transport guid (%u). Teleport to default race/class locations.",
14103 SetMapId(info
->mapId
);
14104 Relocate(info
->positionX
,info
->positionY
,info
->positionZ
,0.0f
);
14106 m_movementInfo
.t_x
= 0.0f
;
14107 m_movementInfo
.t_y
= 0.0f
;
14108 m_movementInfo
.t_z
= 0.0f
;
14109 m_movementInfo
.t_o
= 0.0f
;
14115 time_t now
= time(NULL
);
14116 time_t logoutTime
= time_t(fields
[16].GetUInt64());
14118 // since last logout (in seconds)
14119 uint64 time_diff
= uint64(now
- logoutTime
);
14121 // set value, including drunk invisibility detection
14122 // calculate sobering. after 15 minutes logged out, the player will be sober again
14124 if(time_diff
> 15*MINUTE
)
14127 soberFactor
= 1-time_diff
/(15.0f
*MINUTE
);
14128 uint16 newDrunkenValue
= uint16(soberFactor
*(GetUInt32Value(PLAYER_BYTES_3
) & 0xFFFE));
14129 SetDrunkValue(newDrunkenValue
);
14131 m_rest_bonus
= fields
[15].GetFloat();
14132 //speed collect rest bonus in offline, in logout, far from tavern, city (section/in hour)
14133 float bubble0
= 0.031;
14134 //speed collect rest bonus in offline, in logout, in tavern, city (section/in hour)
14135 float bubble1
= 0.125;
14137 if((int32
)fields
[16].GetUInt32() > 0)
14139 float bubble
= fields
[17].GetUInt32() > 0
14140 ? bubble1
*sWorld
.getRate(RATE_REST_OFFLINE_IN_TAVERN_OR_CITY
)
14141 : bubble0
*sWorld
.getRate(RATE_REST_OFFLINE_IN_WILDERNESS
);
14143 SetRestBonus(GetRestBonus()+ time_diff
*((float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP
)/72000)*bubble
);
14146 m_cinematic
= fields
[12].GetUInt32();
14147 m_Played_time
[0]= fields
[13].GetUInt32();
14148 m_Played_time
[1]= fields
[14].GetUInt32();
14150 m_resetTalentsCost
= fields
[18].GetUInt32();
14151 m_resetTalentsTime
= time_t(fields
[19].GetUInt64());
14153 // reserve some flags
14154 uint32 old_safe_flags
= GetUInt32Value(PLAYER_FLAGS
) & ( PLAYER_FLAGS_HIDE_CLOAK
| PLAYER_FLAGS_HIDE_HELM
);
14156 if( HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GM
) )
14157 SetUInt32Value(PLAYER_FLAGS
, 0 | old_safe_flags
);
14159 m_taxi
.LoadTaxiMask( fields
[11].GetString() ); // must be before InitTaxiNodesForLevel
14161 uint32 extraflags
= fields
[25].GetUInt32();
14163 m_stableSlots
= fields
[26].GetUInt32();
14164 if(m_stableSlots
> 4)
14166 sLog
.outError("Player can have not more 4 stable slots, but have in DB %u",uint32(m_stableSlots
));
14170 m_atLoginFlags
= fields
[27].GetUInt32();
14173 // Update Honor kills data
14174 m_lastHonorUpdateTime
= logoutTime
;
14175 UpdateHonorFields();
14177 m_deathExpireTime
= (time_t)fields
[30].GetUInt64();
14178 if(m_deathExpireTime
> now
+MAX_DEATH_COUNT
*DEATH_EXPIRE_STEP
)
14179 m_deathExpireTime
= now
+MAX_DEATH_COUNT
*DEATH_EXPIRE_STEP
-1;
14181 std::string taxi_nodes
= fields
[31].GetCppString();
14185 // clear channel spell data (if saved at channel spell casting)
14186 SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, 0);
14187 SetUInt32Value(UNIT_CHANNEL_SPELL
,0);
14189 // clear charm/summon related fields
14192 SetCharmerGUID(NULL
);
14193 SetOwnerGUID(NULL
);
14194 SetCreatorGUID(NULL
);
14196 // reset some aura modifiers before aura apply
14198 SetUInt32Value(PLAYER_TRACK_CREATURES
, 0 );
14199 SetUInt32Value(PLAYER_TRACK_RESOURCES
, 0 );
14201 // reset skill modifiers and set correct unlearn flags
14202 for (uint32 i
= 0; i
< PLAYER_MAX_SKILLS
; i
++)
14204 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),0);
14206 // set correct unlearn bit
14207 uint32 id
= GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF;
14210 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(id
);
14211 if(!pSkill
) continue;
14213 // enable unlearn button for primary professions only
14214 if (pSkill
->categoryId
== SKILL_CATEGORY_PROFESSION
)
14215 SetUInt32Value(PLAYER_SKILL_INDEX(i
), MAKE_PAIR32(id
,1));
14217 SetUInt32Value(PLAYER_SKILL_INDEX(i
), MAKE_PAIR32(id
,0));
14220 // make sure the unit is considered out of combat for proper loading
14223 // make sure the unit is considered not in duel for proper loading
14224 SetUInt64Value(PLAYER_DUEL_ARBITER
, 0);
14225 SetUInt32Value(PLAYER_DUEL_TEAM
, 0);
14227 // remember loaded power/health values to restore after stats initialization and modifier applying
14228 uint32 savedHealth
= GetHealth();
14229 uint32 savedPower
[MAX_POWERS
];
14230 for(uint32 i
= 0; i
< MAX_POWERS
; ++i
)
14231 savedPower
[i
] = GetPower(Powers(i
));
14233 // reset stats before loading any modifiers
14234 InitStatsForLevel();
14235 InitTaxiNodesForLevel();
14236 InitGlyphsForLevel();
14239 // apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()
14241 //mails are loaded only when needed ;-) - when player in game click on mailbox.
14244 _LoadAuras(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADAURAS
), time_diff
);
14246 // add ghost flag (must be after aura load: PLAYER_FLAGS_GHOST set in aura)
14247 if( HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
) )
14248 m_deathState
= DEAD
;
14250 _LoadSpells(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADSPELLS
));
14252 // after spell load
14253 InitTalentForLevel();
14254 learnSkillRewardedSpells();
14255 learnDefaultSpells();
14258 // after spell load, learn rewarded spell if need also
14259 _LoadQuestStatus(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS
));
14260 _LoadDailyQuestStatus(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS
));
14262 _LoadTutorials(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADTUTORIALS
));
14264 // must be before inventory (some items required reputation check)
14265 _LoadReputation(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADREPUTATION
));
14267 _LoadInventory(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADINVENTORY
), time_diff
);
14269 // update items with duration and realtime
14270 UpdateItemDuration(time_diff
, true);
14272 _LoadActions(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADACTIONS
));
14274 // unread mails and next delivery time, actual mails not loaded
14275 _LoadMailInit(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADMAILCOUNT
), holder
->GetResult(PLAYER_LOGIN_QUERY_LOADMAILDATE
));
14277 m_social
= sSocialMgr
.LoadFromDB(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADSOCIALLIST
), GetGUIDLow());
14279 if(!_LoadHomeBind(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADHOMEBIND
)))
14282 // check PLAYER_CHOSEN_TITLE compatibility with PLAYER__FIELD_KNOWN_TITLES
14283 // note: PLAYER__FIELD_KNOWN_TITLES updated at quest status loaded
14284 if(uint32 curTitle
= GetUInt32Value(PLAYER_CHOSEN_TITLE
))
14286 if(!HasTitle(curTitle
))
14287 SetUInt32Value(PLAYER_CHOSEN_TITLE
,0);
14290 // Not finish taxi flight path
14291 if(!m_taxi
.LoadTaxiDestinationsFromString(taxi_nodes
))
14293 // problems with taxi path loading
14294 TaxiNodesEntry
const* nodeEntry
= NULL
;
14295 if(uint32 node_id
= m_taxi
.GetTaxiSource())
14296 nodeEntry
= sTaxiNodesStore
.LookupEntry(node_id
);
14298 if(!nodeEntry
) // don't know taxi start node, to homebind
14300 sLog
.outError("Character %u have wrong data in taxi destination list, teleport to homebind.",GetGUIDLow());
14301 SetMapId(m_homebindMapId
);
14302 Relocate( m_homebindX
, m_homebindY
, m_homebindZ
,0.0f
);
14303 SaveRecallPosition(); // save as recall also to prevent recall and fall from sky
14305 else // have start node, to it
14307 sLog
.outError("Character %u have too short taxi destination list, teleport to original node.",GetGUIDLow());
14308 SetMapId(nodeEntry
->map_id
);
14309 Relocate(nodeEntry
->x
, nodeEntry
->y
, nodeEntry
->z
,0.0f
);
14310 SaveRecallPosition(); // save as recall also to prevent recall and fall from sky
14312 m_taxi
.ClearTaxiDestinations();
14314 else if(uint32 node_id
= m_taxi
.GetTaxiSource())
14316 // save source node as recall coord to prevent recall and fall from sky
14317 TaxiNodesEntry
const* nodeEntry
= sTaxiNodesStore
.LookupEntry(node_id
);
14318 assert(nodeEntry
); // checked in m_taxi.LoadTaxiDestinationsFromString
14319 m_recallMap
= nodeEntry
->map_id
;
14320 m_recallX
= nodeEntry
->x
;
14321 m_recallY
= nodeEntry
->y
;
14322 m_recallZ
= nodeEntry
->z
;
14324 // flight will started later
14327 // has to be called after last Relocate() in Player::LoadFromDB
14328 SetFallInformation(0, GetPositionZ());
14330 _LoadSpellCooldowns(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS
));
14332 // Spell code allow apply any auras to dead character in load time in aura/spell/item loading
14333 // Do now before stats re-calculation cleanup for ghost state unexpected auras
14335 RemoveAllAurasOnDeath();
14337 //apply all stat bonuses from items and auras
14338 SetCanModifyStats(true);
14341 // restore remembered power/health values (but not more max values)
14342 SetHealth(savedHealth
> GetMaxHealth() ? GetMaxHealth() : savedHealth
);
14343 for(uint32 i
= 0; i
< MAX_POWERS
; ++i
)
14344 SetPower(Powers(i
),savedPower
[i
] > GetMaxPower(Powers(i
)) ? GetMaxPower(Powers(i
)) : savedPower
[i
]);
14346 sLog
.outDebug("The value of player %s after load item and aura is: ", m_name
.c_str());
14350 if(GetSession()->GetSecurity() > SEC_PLAYER
)
14352 switch(sWorld
.getConfig(CONFIG_GM_LOGIN_STATE
))
14355 case 0: break; // disable
14356 case 1: SetGameMaster(true); break; // enable
14357 case 2: // save state
14358 if(extraflags
& PLAYER_EXTRA_GM_ON
)
14359 SetGameMaster(true);
14363 switch(sWorld
.getConfig(CONFIG_GM_ACCEPT_TICKETS
))
14366 case 0: break; // disable
14367 case 1: SetAcceptTicket(true); break; // enable
14368 case 2: // save state
14369 if(extraflags
& PLAYER_EXTRA_GM_ACCEPT_TICKETS
)
14370 SetAcceptTicket(true);
14374 switch(sWorld
.getConfig(CONFIG_GM_CHAT
))
14377 case 0: break; // disable
14378 case 1: SetGMChat(true); break; // enable
14379 case 2: // save state
14380 if(extraflags
& PLAYER_EXTRA_GM_CHAT
)
14385 switch(sWorld
.getConfig(CONFIG_GM_WISPERING_TO
))
14388 case 0: break; // disable
14389 case 1: SetAcceptWhispers(true); break; // enable
14390 case 2: // save state
14391 if(extraflags
& PLAYER_EXTRA_ACCEPT_WHISPERS
)
14392 SetAcceptWhispers(true);
14397 _LoadDeclinedNames(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES
));
14399 m_achievementMgr
.LoadFromDB(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADACHIEVEMENTS
), holder
->GetResult(PLAYER_LOGIN_QUERY_LOADCRITERIAPROGRESS
));
14400 m_achievementMgr
.CheckAllAchievementCriteria();
14404 bool Player::isAllowedToLoot(Creature
* creature
)
14406 if(Player
* recipient
= creature
->GetLootRecipient())
14408 if (recipient
== this)
14410 if( Group
* otherGroup
= recipient
->GetGroup())
14412 Group
* thisGroup
= GetGroup();
14415 return thisGroup
== otherGroup
;
14420 // prevent other players from looting if the recipient got disconnected
14421 return !creature
->hasLootRecipient();
14424 void Player::_LoadActions(QueryResult
*result
)
14426 m_actionButtons
.clear();
14428 //QueryResult *result = CharacterDatabase.PQuery("SELECT button,action,type,misc FROM character_action WHERE guid = '%u' ORDER BY button",GetGUIDLow());
14434 Field
*fields
= result
->Fetch();
14436 uint8 button
= fields
[0].GetUInt8();
14438 addActionButton(button
, fields
[1].GetUInt16(), fields
[2].GetUInt8(), fields
[3].GetUInt8());
14440 m_actionButtons
[button
].uState
= ACTIONBUTTON_UNCHANGED
;
14442 while( result
->NextRow() );
14448 void Player::_LoadAuras(QueryResult
*result
, uint32 timediff
)
14451 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
14452 m_modAuras
[i
].clear();
14454 //QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'",GetGUIDLow());
14460 Field
*fields
= result
->Fetch();
14461 uint64 caster_guid
= fields
[0].GetUInt64();
14462 uint32 spellid
= fields
[1].GetUInt32();
14463 uint32 effindex
= fields
[2].GetUInt32();
14464 uint32 stackcount
= fields
[3].GetUInt32();
14465 int32 damage
= (int32
)fields
[4].GetUInt32();
14466 int32 maxduration
= (int32
)fields
[5].GetUInt32();
14467 int32 remaintime
= (int32
)fields
[6].GetUInt32();
14468 int32 remaincharges
= (int32
)fields
[7].GetUInt32();
14470 SpellEntry
const* spellproto
= sSpellStore
.LookupEntry(spellid
);
14473 sLog
.outError("Unknown aura (spellid %u, effindex %u), ignore.",spellid
,effindex
);
14479 sLog
.outError("Invalid effect index (spellid %u, effindex %u), ignore.",spellid
,effindex
);
14483 // negative effects should continue counting down after logout
14484 if (remaintime
!= -1 && !IsPositiveEffect(spellid
, effindex
))
14486 if(remaintime
<= int32(timediff
))
14489 remaintime
-= timediff
;
14492 // prevent wrong values of remaincharges
14493 if(spellproto
->procCharges
)
14495 if(remaincharges
<= 0 || remaincharges
> spellproto
->procCharges
)
14496 remaincharges
= spellproto
->procCharges
;
14501 //do not load single target auras (unless they were cast by the player)
14502 if (caster_guid
!= GetGUID() && IsSingleTargetSpell(spellproto
))
14505 for(uint32 i
=0; i
<stackcount
; i
++)
14507 Aura
* aura
= CreateAura(spellproto
, effindex
, NULL
, this, NULL
);
14509 damage
= aura
->GetModifier()->m_amount
;
14510 aura
->SetLoadedState(caster_guid
,damage
,maxduration
,remaintime
,remaincharges
);
14512 sLog
.outString("Added aura spellid %u, effect %u", spellproto
->Id
, effindex
);
14515 while( result
->NextRow() );
14520 if(m_class
== CLASS_WARRIOR
)
14521 CastSpell(this,SPELL_ID_PASSIVE_BATTLE_STANCE
,true);
14524 void Player::LoadCorpse()
14528 ObjectAccessor::Instance().ConvertCorpseForPlayer(GetGUID());
14532 if(Corpse
*corpse
= GetCorpse())
14534 ApplyModFlag(PLAYER_FIELD_BYTES
, PLAYER_FIELD_BYTE_RELEASE_TIMER
, corpse
&& !sMapStore
.LookupEntry(corpse
->GetMapId())->Instanceable() );
14538 //Prevent Dead Player login without corpse
14539 ResurrectPlayer(0.5f
);
14544 void Player::_LoadInventory(QueryResult
*result
, uint32 timediff
)
14546 //QueryResult *result = CharacterDatabase.PQuery("SELECT data,bag,slot,item,item_template FROM character_inventory JOIN item_instance ON character_inventory.item = item_instance.guid WHERE character_inventory.guid = '%u' ORDER BY bag,slot", GetGUIDLow());
14547 std::map
<uint64
, Bag
*> bagMap
; // fast guid lookup for bags
14548 //NOTE: the "order by `bag`" is important because it makes sure
14549 //the bagMap is filled before items in the bags are loaded
14550 //NOTE2: the "order by `slot`" is needed because mainhand weapons are (wrongly?)
14551 //expected to be equipped before offhand items (TODO: fixme)
14553 uint32 zone
= GetZoneId();
14557 std::list
<Item
*> problematicItems
;
14559 // prevent items from being added to the queue when stored
14560 m_itemUpdateQueueBlocked
= true;
14563 Field
*fields
= result
->Fetch();
14564 uint32 bag_guid
= fields
[1].GetUInt32();
14565 uint8 slot
= fields
[2].GetUInt8();
14566 uint32 item_guid
= fields
[3].GetUInt32();
14567 uint32 item_id
= fields
[4].GetUInt32();
14569 ItemPrototype
const * proto
= objmgr
.GetItemPrototype(item_id
);
14573 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14574 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", item_guid
);
14575 sLog
.outError( "Player::_LoadInventory: Player %s has an unknown item (id: #%u) in inventory, deleted.", GetName(),item_id
);
14579 Item
*item
= NewItemOrBag(proto
);
14581 if(!item
->LoadFromDB(item_guid
, GetGUID(), result
))
14583 sLog
.outError( "Player::_LoadInventory: Player %s has broken item (id: #%u) in inventory, deleted.", GetName(),item_id
);
14584 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14585 item
->FSetState(ITEM_REMOVED
);
14586 item
->SaveToDB(); // it also deletes item object !
14590 // not allow have in alive state item limited to another map/zone
14591 if(isAlive() && item
->IsLimitedToAnotherMapOrZone(GetMapId(),zone
) )
14593 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14594 item
->FSetState(ITEM_REMOVED
);
14595 item
->SaveToDB(); // it also deletes item object !
14599 // "Conjured items disappear if you are logged out for more than 15 minutes"
14600 if ((timediff
> 15*60) && (item
->HasFlag(ITEM_FIELD_FLAGS
, ITEM_FLAGS_CONJURED
)))
14602 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14603 item
->FSetState(ITEM_REMOVED
);
14604 item
->SaveToDB(); // it also deletes item object !
14608 bool success
= true;
14612 // the item is not in a bag
14613 item
->SetContainer( NULL
);
14614 item
->SetSlot(slot
);
14616 if( IsInventoryPos( INVENTORY_SLOT_BAG_0
, slot
) )
14618 ItemPosCountVec dest
;
14619 if( CanStoreItem( INVENTORY_SLOT_BAG_0
, slot
, dest
, item
, false ) == EQUIP_ERR_OK
)
14620 item
= StoreItem(dest
, item
, true);
14624 else if( IsEquipmentPos( INVENTORY_SLOT_BAG_0
, slot
) )
14627 if( CanEquipItem( slot
, dest
, item
, false, false ) == EQUIP_ERR_OK
)
14628 QuickEquipItem(dest
, item
);
14632 else if( IsBankPos( INVENTORY_SLOT_BAG_0
, slot
) )
14634 ItemPosCountVec dest
;
14635 if( CanBankItem( INVENTORY_SLOT_BAG_0
, slot
, dest
, item
, false, false ) == EQUIP_ERR_OK
)
14636 item
= BankItem(dest
, item
, true);
14643 // store bags that may contain items in them
14644 if(item
->IsBag() && IsBagPos(item
->GetPos()))
14645 bagMap
[item_guid
] = (Bag
*)item
;
14650 item
->SetSlot(NULL_SLOT
);
14651 // the item is in a bag, find the bag
14652 std::map
<uint64
, Bag
*>::iterator itr
= bagMap
.find(bag_guid
);
14653 if(itr
!= bagMap
.end())
14654 itr
->second
->StoreItem(slot
, item
, true );
14659 // item's state may have changed after stored
14661 item
->SetState(ITEM_UNCHANGED
, this);
14664 sLog
.outError("Player::_LoadInventory: Player %s has item (GUID: %u Entry: %u) can't be loaded to inventory (Bag GUID: %u Slot: %u) by some reason, will send by mail.", GetName(),item_guid
, item_id
, bag_guid
, slot
);
14665 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14666 problematicItems
.push_back(item
);
14668 } while (result
->NextRow());
14671 m_itemUpdateQueueBlocked
= false;
14673 // send by mail problematic items
14674 while(!problematicItems
.empty())
14677 MailItemsInfo mi
; // item list preparing
14679 for(int i
= 0; !problematicItems
.empty() && i
< MAX_MAIL_ITEMS
; ++i
)
14681 Item
* item
= problematicItems
.front();
14682 problematicItems
.pop_front();
14684 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
14687 std::string subject
= GetSession()->GetMangosString(LANG_NOT_EQUIPPED_ITEM
);
14689 WorldSession::SendMailTo(this, MAIL_NORMAL
, MAIL_STATIONERY_GM
, GetGUIDLow(), GetGUIDLow(), subject
, 0, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
14693 _ApplyAllItemMods();
14696 // load mailed item which should receive current player
14697 void Player::_LoadMailedItems(Mail
*mail
)
14699 // data needs to be at first place for Item::LoadFromDB
14700 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT data, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail
->messageID
);
14706 Field
*fields
= result
->Fetch();
14707 uint32 item_guid_low
= fields
[1].GetUInt32();
14708 uint32 item_template
= fields
[2].GetUInt32();
14710 mail
->AddItem(item_guid_low
, item_template
);
14712 ItemPrototype
const *proto
= objmgr
.GetItemPrototype(item_template
);
14716 sLog
.outError( "Player %u have unknown item_template (ProtoType) in mailed items(GUID: %u template: %u) in mail (%u), deleted.", GetGUIDLow(), item_guid_low
, item_template
,mail
->messageID
);
14717 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", item_guid_low
);
14718 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", item_guid_low
);
14722 Item
*item
= NewItemOrBag(proto
);
14724 if(!item
->LoadFromDB(item_guid_low
, 0, result
))
14726 sLog
.outError( "Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail
->messageID
, item_guid_low
);
14727 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", item_guid_low
);
14728 item
->FSetState(ITEM_REMOVED
);
14729 item
->SaveToDB(); // it also deletes item object !
14734 } while (result
->NextRow());
14739 void Player::_LoadMailInit(QueryResult
*resultUnread
, QueryResult
*resultDelivery
)
14741 //set a count of unread mails
14742 //QueryResult *resultMails = CharacterDatabase.PQuery("SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" I64FMTD "'", GUID_LOPART(playerGuid),(uint64)cTime);
14745 Field
*fieldMail
= resultUnread
->Fetch();
14746 unReadMails
= fieldMail
[0].GetUInt8();
14747 delete resultUnread
;
14750 // store nearest delivery time (it > 0 and if it < current then at next player update SendNewMaill will be called)
14751 //resultMails = CharacterDatabase.PQuery("SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(playerGuid));
14752 if (resultDelivery
)
14754 Field
*fieldMail
= resultDelivery
->Fetch();
14755 m_nextMailDelivereTime
= (time_t)fieldMail
[0].GetUInt64();
14756 delete resultDelivery
;
14760 void Player::_LoadMail()
14763 //mails are in right order 0 1 2 3 4 5 6 7 8 9 10 11 12 13
14764 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT id,messageType,sender,receiver,subject,itemTextId,has_items,expire_time,deliver_time,money,cod,checked,stationery,mailTemplateId FROM mail WHERE receiver = '%u' ORDER BY id DESC",GetGUIDLow());
14769 Field
*fields
= result
->Fetch();
14770 Mail
*m
= new Mail
;
14771 m
->messageID
= fields
[0].GetUInt32();
14772 m
->messageType
= fields
[1].GetUInt8();
14773 m
->sender
= fields
[2].GetUInt32();
14774 m
->receiver
= fields
[3].GetUInt32();
14775 m
->subject
= fields
[4].GetCppString();
14776 m
->itemTextId
= fields
[5].GetUInt32();
14777 bool has_items
= fields
[6].GetBool();
14778 m
->expire_time
= (time_t)fields
[7].GetUInt64();
14779 m
->deliver_time
= (time_t)fields
[8].GetUInt64();
14780 m
->money
= fields
[9].GetUInt32();
14781 m
->COD
= fields
[10].GetUInt32();
14782 m
->checked
= fields
[11].GetUInt32();
14783 m
->stationery
= fields
[12].GetUInt8();
14784 m
->mailTemplateId
= fields
[13].GetInt16();
14786 if(m
->mailTemplateId
&& !sMailTemplateStore
.LookupEntry(m
->mailTemplateId
))
14788 sLog
.outError( "Player::_LoadMail - Mail (%u) have not existed MailTemplateId (%u), remove at load", m
->messageID
, m
->mailTemplateId
);
14789 m
->mailTemplateId
= 0;
14792 m
->state
= MAIL_STATE_UNCHANGED
;
14795 _LoadMailedItems(m
);
14797 m_mail
.push_back(m
);
14798 } while( result
->NextRow() );
14801 m_mailsLoaded
= true;
14804 void Player::LoadPet()
14806 //fixme: the pet should still be loaded if the player is not in world
14807 // just not added to the map
14810 Pet
*pet
= new Pet
;
14811 if(!pet
->LoadPetFromDB(this,0,0,true))
14816 void Player::_LoadQuestStatus(QueryResult
*result
)
14818 mQuestStatus
.clear();
14822 //// 0 1 2 3 4 5 6 7 8 9 10 11 12
14823 //QueryResult *result = CharacterDatabase.PQuery("SELECT quest, status, rewarded, explored, timer, mobcount1, mobcount2, mobcount3, mobcount4, itemcount1, itemcount2, itemcount3, itemcount4 FROM character_queststatus WHERE guid = '%u'", GetGUIDLow());
14829 Field
*fields
= result
->Fetch();
14831 uint32 quest_id
= fields
[0].GetUInt32();
14832 // used to be new, no delete?
14833 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
14837 QuestStatusData
& questStatusData
= mQuestStatus
[quest_id
];
14839 uint32 qstatus
= fields
[1].GetUInt32();
14840 if(qstatus
< MAX_QUEST_STATUS
)
14841 questStatusData
.m_status
= QuestStatus(qstatus
);
14844 questStatusData
.m_status
= QUEST_STATUS_NONE
;
14845 sLog
.outError("Player %s have invalid quest %d status (%d), replaced by QUEST_STATUS_NONE(0).",GetName(),quest_id
,qstatus
);
14848 questStatusData
.m_rewarded
= ( fields
[2].GetUInt8() > 0 );
14849 questStatusData
.m_explored
= ( fields
[3].GetUInt8() > 0 );
14851 time_t quest_time
= time_t(fields
[4].GetUInt64());
14853 if( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_TIMED
) && !GetQuestRewardStatus(quest_id
) && questStatusData
.m_status
!= QUEST_STATUS_NONE
)
14855 AddTimedQuest( quest_id
);
14857 if (quest_time
<= sWorld
.GetGameTime())
14858 questStatusData
.m_timer
= 1;
14860 questStatusData
.m_timer
= (quest_time
- sWorld
.GetGameTime()) * 1000;
14865 questStatusData
.m_creatureOrGOcount
[0] = fields
[5].GetUInt32();
14866 questStatusData
.m_creatureOrGOcount
[1] = fields
[6].GetUInt32();
14867 questStatusData
.m_creatureOrGOcount
[2] = fields
[7].GetUInt32();
14868 questStatusData
.m_creatureOrGOcount
[3] = fields
[8].GetUInt32();
14869 questStatusData
.m_itemcount
[0] = fields
[9].GetUInt32();
14870 questStatusData
.m_itemcount
[1] = fields
[10].GetUInt32();
14871 questStatusData
.m_itemcount
[2] = fields
[11].GetUInt32();
14872 questStatusData
.m_itemcount
[3] = fields
[12].GetUInt32();
14874 questStatusData
.uState
= QUEST_UNCHANGED
;
14876 // add to quest log
14877 if( slot
< MAX_QUEST_LOG_SIZE
&&
14878 ( questStatusData
.m_status
==QUEST_STATUS_INCOMPLETE
||
14879 questStatusData
.m_status
==QUEST_STATUS_COMPLETE
&&
14880 (!questStatusData
.m_rewarded
|| pQuest
->IsDaily()) ) )
14882 SetQuestSlot(slot
,quest_id
,quest_time
);
14884 if(questStatusData
.m_status
== QUEST_STATUS_COMPLETE
)
14885 SetQuestSlotState(slot
,QUEST_STATE_COMPLETE
);
14887 for(uint8 idx
= 0; idx
< QUEST_OBJECTIVES_COUNT
; ++idx
)
14888 if(questStatusData
.m_creatureOrGOcount
[idx
])
14889 SetQuestSlotCounter(slot
,idx
,questStatusData
.m_creatureOrGOcount
[idx
]);
14894 if(questStatusData
.m_rewarded
)
14896 // learn rewarded spell if unknown
14897 learnQuestRewardedSpells(pQuest
);
14899 // set rewarded title if any
14900 if(pQuest
->GetCharTitleId())
14902 if(CharTitlesEntry
const* titleEntry
= sCharTitlesStore
.LookupEntry(pQuest
->GetCharTitleId()))
14903 SetTitle(titleEntry
);
14907 sLog
.outDebug("Quest status is {%u} for quest {%u} for player (GUID: %u)", questStatusData
.m_status
, quest_id
, GetGUIDLow());
14910 while( result
->NextRow() );
14915 // clear quest log tail
14916 for ( uint16 i
= slot
; i
< MAX_QUEST_LOG_SIZE
; ++i
)
14920 void Player::_LoadDailyQuestStatus(QueryResult
*result
)
14922 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
14923 SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
,0);
14925 //QueryResult *result = CharacterDatabase.PQuery("SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GetGUIDLow());
14929 uint32 quest_daily_idx
= 0;
14933 if(quest_daily_idx
>= PLAYER_MAX_DAILY_QUESTS
) // max amount with exist data in query
14935 sLog
.outError("Player (GUID: %u) have more 25 daily quest records in `charcter_queststatus_daily`",GetGUIDLow());
14939 Field
*fields
= result
->Fetch();
14941 uint32 quest_id
= fields
[0].GetUInt32();
14943 // save _any_ from daily quest times (it must be after last reset anyway)
14944 m_lastDailyQuestTime
= (time_t)fields
[1].GetUInt64();
14946 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
14950 SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
,quest_id
);
14953 sLog
.outDebug("Daily quest {%u} cooldown for player (GUID: %u)", quest_id
, GetGUIDLow());
14955 while( result
->NextRow() );
14960 m_DailyQuestChanged
= false;
14963 void Player::_LoadReputation(QueryResult
*result
)
14965 m_factions
.clear();
14967 // Set initial reputations (so everything is nifty before DB data load)
14968 SetInitialFactions();
14970 //QueryResult *result = CharacterDatabase.PQuery("SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'",GetGUIDLow());
14976 Field
*fields
= result
->Fetch();
14978 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(fields
[0].GetUInt32());
14979 if( factionEntry
&& (factionEntry
->reputationListID
>= 0))
14981 FactionState
* faction
= &m_factions
[factionEntry
->reputationListID
];
14983 // update standing to current
14984 faction
->Standing
= int32(fields
[1].GetUInt32());
14986 uint32 dbFactionFlags
= fields
[2].GetUInt32();
14988 if( dbFactionFlags
& FACTION_FLAG_VISIBLE
)
14989 SetFactionVisible(faction
); // have internal checks for forced invisibility
14991 if( dbFactionFlags
& FACTION_FLAG_INACTIVE
)
14992 SetFactionInactive(faction
,true); // have internal checks for visibility requirement
14994 if( dbFactionFlags
& FACTION_FLAG_AT_WAR
) // DB at war
14995 SetFactionAtWar(faction
,true); // have internal checks for FACTION_FLAG_PEACE_FORCED
14996 else // DB not at war
14998 // allow remove if visible (and then not FACTION_FLAG_INVISIBLE_FORCED or FACTION_FLAG_HIDDEN)
14999 if( faction
->Flags
& FACTION_FLAG_VISIBLE
)
15000 SetFactionAtWar(faction
,false); // have internal checks for FACTION_FLAG_PEACE_FORCED
15003 // set atWar for hostile
15004 if(GetReputationRank(factionEntry
) <= REP_HOSTILE
)
15005 SetFactionAtWar(faction
,true);
15007 // reset changed flag if values similar to saved in DB
15008 if(faction
->Flags
==dbFactionFlags
)
15009 faction
->Changed
= false;
15012 while( result
->NextRow() );
15018 void Player::_LoadSpells(QueryResult
*result
)
15020 for (PlayerSpellMap::iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
15021 delete itr
->second
;
15024 //QueryResult *result = CharacterDatabase.PQuery("SELECT spell,active,disabled FROM character_spell WHERE guid = '%u'",GetGUIDLow());
15030 Field
*fields
= result
->Fetch();
15032 addSpell(fields
[0].GetUInt16(), fields
[1].GetBool(), false, fields
[2].GetBool());
15034 while( result
->NextRow() );
15040 void Player::_LoadTutorials(QueryResult
*result
)
15042 //QueryResult *result = CharacterDatabase.PQuery("SELECT tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7 FROM character_tutorial WHERE account = '%u' AND realmid = '%u'", GetAccountId(), realmid);
15048 Field
*fields
= result
->Fetch();
15050 for (int iI
=0; iI
<8; iI
++)
15051 m_Tutorials
[iI
] = fields
[iI
].GetUInt32();
15053 while( result
->NextRow() );
15058 m_TutorialsChanged
= false;
15061 void Player::_LoadGroup(QueryResult
*result
)
15063 //QueryResult *result = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", GetGUIDLow());
15066 uint64 leaderGuid
= MAKE_NEW_GUID((*result
)[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
15068 Group
* group
= objmgr
.GetGroupByLeader(leaderGuid
);
15071 uint8 subgroup
= group
->GetMemberGroup(GetGUID());
15072 SetGroup(group
, subgroup
);
15073 if(getLevel() >= LEVELREQUIREMENT_HEROIC
)
15075 // the group leader may change the instance difficulty while the player is offline
15076 SetDifficulty(group
->GetDifficulty());
15082 void Player::_LoadBoundInstances(QueryResult
*result
)
15084 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15085 m_boundInstances
[i
].clear();
15087 Group
*group
= GetGroup();
15089 //QueryResult *result = CharacterDatabase.PQuery("SELECT id, permanent, map, difficulty, resettime FROM character_instance LEFT JOIN instance ON instance = id WHERE guid = '%u'", GUID_LOPART(m_guid));
15094 Field
*fields
= result
->Fetch();
15095 bool perm
= fields
[1].GetBool();
15096 uint32 mapId
= fields
[2].GetUInt32();
15097 uint32 instanceId
= fields
[0].GetUInt32();
15098 uint8 difficulty
= fields
[3].GetUInt8();
15099 time_t resetTime
= (time_t)fields
[4].GetUInt64();
15100 // the resettime for normal instances is only saved when the InstanceSave is unloaded
15101 // so the value read from the DB may be wrong here but only if the InstanceSave is loaded
15102 // and in that case it is not used
15106 sLog
.outError("_LoadBoundInstances: player %s(%d) is in group %d but has a non-permanent character bind to map %d,%d,%d", GetName(), GetGUIDLow(), GUID_LOPART(group
->GetLeaderGUID()), mapId
, instanceId
, difficulty
);
15107 CharacterDatabase
.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId
);
15111 // since non permanent binds are always solo bind, they can always be reset
15112 InstanceSave
*save
= sInstanceSaveManager
.AddInstanceSave(mapId
, instanceId
, difficulty
, resetTime
, !perm
, true);
15113 if(save
) BindToInstance(save
, perm
, true);
15114 } while(result
->NextRow());
15119 InstancePlayerBind
* Player::GetBoundInstance(uint32 mapid
, uint8 difficulty
)
15121 // some instances only have one difficulty
15122 const MapEntry
* entry
= sMapStore
.LookupEntry(mapid
);
15123 if(!entry
|| !entry
->SupportsHeroicMode()) difficulty
= DIFFICULTY_NORMAL
;
15125 BoundInstancesMap::iterator itr
= m_boundInstances
[difficulty
].find(mapid
);
15126 if(itr
!= m_boundInstances
[difficulty
].end())
15127 return &itr
->second
;
15132 void Player::UnbindInstance(uint32 mapid
, uint8 difficulty
, bool unload
)
15134 BoundInstancesMap::iterator itr
= m_boundInstances
[difficulty
].find(mapid
);
15135 UnbindInstance(itr
, difficulty
, unload
);
15138 void Player::UnbindInstance(BoundInstancesMap::iterator
&itr
, uint8 difficulty
, bool unload
)
15140 if(itr
!= m_boundInstances
[difficulty
].end())
15142 if(!unload
) CharacterDatabase
.PExecute("DELETE FROM character_instance WHERE guid = '%u' AND instance = '%u'", GetGUIDLow(), itr
->second
.save
->GetInstanceId());
15143 itr
->second
.save
->RemovePlayer(this); // save can become invalid
15144 m_boundInstances
[difficulty
].erase(itr
++);
15148 InstancePlayerBind
* Player::BindToInstance(InstanceSave
*save
, bool permanent
, bool load
)
15152 InstancePlayerBind
& bind
= m_boundInstances
[save
->GetDifficulty()][save
->GetMapId()];
15155 // update the save when the group kills a boss
15156 if(permanent
!= bind
.perm
|| save
!= bind
.save
)
15157 if(!load
) CharacterDatabase
.PExecute("UPDATE character_instance SET instance = '%u', permanent = '%u' WHERE guid = '%u' AND instance = '%u'", save
->GetInstanceId(), permanent
, GetGUIDLow(), bind
.save
->GetInstanceId());
15160 if(!load
) CharacterDatabase
.PExecute("INSERT INTO character_instance (guid, instance, permanent) VALUES ('%u', '%u', '%u')", GetGUIDLow(), save
->GetInstanceId(), permanent
);
15162 if(bind
.save
!= save
)
15164 if(bind
.save
) bind
.save
->RemovePlayer(this);
15165 save
->AddPlayer(this);
15168 if(permanent
) save
->SetCanReset(false);
15171 bind
.perm
= permanent
;
15172 if(!load
) sLog
.outDebug("Player::BindToInstance: %s(%d) is now bound to map %d, instance %d, difficulty %d", GetName(), GetGUIDLow(), save
->GetMapId(), save
->GetInstanceId(), save
->GetDifficulty());
15179 void Player::SendRaidInfo()
15181 WorldPacket
data(SMSG_RAID_INSTANCE_INFO
, 4);
15183 uint32 counter
= 0, i
;
15184 for(i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15185 for (BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); ++itr
)
15186 if(itr
->second
.perm
) counter
++;
15189 for(i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15191 for (BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); ++itr
)
15193 if(itr
->second
.perm
)
15195 InstanceSave
*save
= itr
->second
.save
;
15196 data
<< (save
->GetMapId());
15197 data
<< (uint32
)(save
->GetResetTime() - time(NULL
));
15198 data
<< save
->GetInstanceId();
15199 data
<< uint32(counter
);
15204 GetSession()->SendPacket(&data
);
15208 - called on every successful teleportation to a map
15210 void Player::SendSavedInstances()
15212 bool hasBeenSaved
= false;
15215 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15217 for (BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); ++itr
)
15219 if(itr
->second
.perm
) // only permanent binds are sent
15221 hasBeenSaved
= true;
15227 //Send opcode 811. true or false means, whether you have current raid/heroic instances
15228 data
.Initialize(SMSG_UPDATE_INSTANCE_OWNERSHIP
);
15229 data
<< uint32(hasBeenSaved
);
15230 GetSession()->SendPacket(&data
);
15235 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15237 for (BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); ++itr
)
15239 if(itr
->second
.perm
)
15241 data
.Initialize(SMSG_UPDATE_LAST_INSTANCE
);
15242 data
<< uint32(itr
->second
.save
->GetMapId());
15243 GetSession()->SendPacket(&data
);
15249 /// convert the player's binds to the group
15250 void Player::ConvertInstancesToGroup(Player
*player
, Group
*group
, uint64 player_guid
)
15252 bool has_binds
= false;
15253 bool has_solo
= false;
15255 if(player
) { player_guid
= player
->GetGUID(); if(!group
) group
= player
->GetGroup(); }
15256 assert(player_guid
);
15258 // copy all binds to the group, when changing leader it's assumed the character
15259 // will not have any solo binds
15263 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15265 for (BoundInstancesMap::iterator itr
= player
->m_boundInstances
[i
].begin(); itr
!= player
->m_boundInstances
[i
].end();)
15268 if(group
) group
->BindToInstance(itr
->second
.save
, itr
->second
.perm
, true);
15269 // permanent binds are not removed
15270 if(!itr
->second
.perm
)
15272 player
->UnbindInstance(itr
, i
, true); // increments itr
15281 // if the player's not online we don't know what binds it has
15282 if(!player
|| !group
|| has_binds
) CharacterDatabase
.PExecute("INSERT INTO group_instance SELECT guid, instance, permanent FROM character_instance WHERE guid = '%u'", GUID_LOPART(player_guid
));
15283 // the following should not get executed when changing leaders
15284 if(!player
|| has_solo
) CharacterDatabase
.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND permanent = 0", GUID_LOPART(player_guid
));
15287 bool Player::_LoadHomeBind(QueryResult
*result
)
15290 //QueryResult *result = CharacterDatabase.PQuery("SELECT map,zone,position_x,position_y,position_z FROM character_homebind WHERE guid = '%u'", GUID_LOPART(playerGuid));
15293 Field
*fields
= result
->Fetch();
15294 m_homebindMapId
= fields
[0].GetUInt32();
15295 m_homebindZoneId
= fields
[1].GetUInt16();
15296 m_homebindX
= fields
[2].GetFloat();
15297 m_homebindY
= fields
[3].GetFloat();
15298 m_homebindZ
= fields
[4].GetFloat();
15301 // accept saved data only for valid position (and non instanceable)
15302 if( MapManager::IsValidMapCoord(m_homebindMapId
,m_homebindX
,m_homebindY
,m_homebindZ
) &&
15303 !sMapStore
.LookupEntry(m_homebindMapId
)->Instanceable() )
15308 CharacterDatabase
.PExecute("DELETE FROM character_homebind WHERE guid = '%u'", GetGUIDLow());
15313 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(getRace(), getClass());
15314 if(!info
) return false;
15316 m_homebindMapId
= info
->mapId
;
15317 m_homebindZoneId
= info
->zoneId
;
15318 m_homebindX
= info
->positionX
;
15319 m_homebindY
= info
->positionY
;
15320 m_homebindZ
= info
->positionZ
;
15322 CharacterDatabase
.PExecute("INSERT INTO character_homebind (guid,map,zone,position_x,position_y,position_z) VALUES ('%u', '%u', '%u', '%f', '%f', '%f')", GetGUIDLow(), m_homebindMapId
, (uint32
)m_homebindZoneId
, m_homebindX
, m_homebindY
, m_homebindZ
);
15325 DEBUG_LOG("Setting player home position: mapid is: %u, zoneid is %u, X is %f, Y is %f, Z is %f\n",
15326 m_homebindMapId
, m_homebindZoneId
, m_homebindX
, m_homebindY
, m_homebindZ
);
15331 /*********************************************************/
15332 /*** SAVE SYSTEM ***/
15333 /*********************************************************/
15335 void Player::SaveToDB()
15337 // delay auto save at any saves (manual, in code, or autosave)
15338 m_nextSave
= sWorld
.getConfig(CONFIG_INTERVAL_SAVE
);
15340 // first save/honor gain after midnight will also update the player's honor fields
15341 UpdateHonorFields();
15343 // players aren't saved on battleground maps
15344 uint32 mapid
= IsBeingTeleported() ? GetTeleportDest().mapid
: GetMapId();
15345 const MapEntry
* me
= sMapStore
.LookupEntry(mapid
);
15346 if(!me
|| me
->IsBattleGroundOrArena())
15349 int is_save_resting
= HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
) ? 1 : 0;
15350 //save, far from tavern/city
15351 //save, but in tavern/city
15352 sLog
.outDebug("The value of player %s at save: ", m_name
.c_str());
15355 // save state (after auras removing), if aura remove some flags then it must set it back by self)
15356 uint32 tmp_bytes
= GetUInt32Value(UNIT_FIELD_BYTES_1
);
15357 uint32 tmp_bytes2
= GetUInt32Value(UNIT_FIELD_BYTES_2
);
15358 uint32 tmp_flags
= GetUInt32Value(UNIT_FIELD_FLAGS
);
15359 uint32 tmp_pflags
= GetUInt32Value(PLAYER_FLAGS
);
15360 uint32 tmp_displayid
= GetDisplayId();
15362 // Set player sit state to standing on save, also stealth and shifted form
15363 SetByteValue(UNIT_FIELD_BYTES_1
, 0, 0); // stand state
15364 SetByteValue(UNIT_FIELD_BYTES_2
, 3, 0); // shapeshift
15365 SetByteValue(UNIT_FIELD_BYTES_1
, 3, 0); // stand flags?
15366 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_STUNNED
);
15367 SetDisplayId(GetNativeDisplayId());
15369 bool inworld
= IsInWorld();
15371 CharacterDatabase
.BeginTransaction();
15373 CharacterDatabase
.PExecute("DELETE FROM characters WHERE guid = '%u'",GetGUIDLow());
15375 std::string sql_name
= m_name
;
15376 CharacterDatabase
.escape_string(sql_name
);
15378 std::ostringstream ss
;
15379 ss
<< "INSERT INTO characters (guid,account,name,race,class,"
15380 "map, dungeon_difficulty, position_x, position_y, position_z, orientation, data, "
15381 "taximask, online, cinematic, "
15382 "totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, "
15383 "trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, "
15384 "death_expire_time, taxi_path, arena_pending_points) VALUES ("
15385 << GetGUIDLow() << ", "
15386 << GetSession()->GetAccountId() << ", '"
15387 << sql_name
<< "', "
15389 << m_class
<< ", ";
15391 bool save_to_dest
= false;
15392 if(IsBeingTeleported())
15394 // don't save to battlegrounds or arenas
15395 const MapEntry
*entry
= sMapStore
.LookupEntry(GetTeleportDest().mapid
);
15396 if(entry
&& entry
->map_type
!= MAP_BATTLEGROUND
&& entry
->map_type
!= MAP_ARENA
)
15397 save_to_dest
= true;
15402 ss
<< GetMapId() << ", "
15403 << (uint32
)GetDifficulty() << ", "
15404 << finiteAlways(GetPositionX()) << ", "
15405 << finiteAlways(GetPositionY()) << ", "
15406 << finiteAlways(GetPositionZ()) << ", "
15407 << finiteAlways(GetOrientation()) << ", '";
15411 ss
<< GetTeleportDest().mapid
<< ", "
15412 << (uint32
)GetDifficulty() << ", "
15413 << finiteAlways(GetTeleportDest().x
) << ", "
15414 << finiteAlways(GetTeleportDest().y
) << ", "
15415 << finiteAlways(GetTeleportDest().z
) << ", "
15416 << finiteAlways(GetTeleportDest().o
) << ", '";
15420 for( i
= 0; i
< m_valuesCount
; i
++ )
15422 ss
<< GetUInt32Value(i
) << " ";
15427 ss
<< m_taxi
; // string with TaxiMaskSize numbers
15430 ss
<< (inworld
? 1 : 0);
15436 ss
<< m_Played_time
[0];
15438 ss
<< m_Played_time
[1];
15441 ss
<< finiteAlways(m_rest_bonus
);
15443 ss
<< (uint64
)time(NULL
);
15445 ss
<< is_save_resting
;
15447 ss
<< m_resetTalentsCost
;
15449 ss
<< (uint64
)m_resetTalentsTime
;
15452 ss
<< finiteAlways(m_movementInfo
.t_x
);
15454 ss
<< finiteAlways(m_movementInfo
.t_y
);
15456 ss
<< finiteAlways(m_movementInfo
.t_z
);
15458 ss
<< finiteAlways(m_movementInfo
.t_o
);
15461 ss
<< m_transport
->GetGUIDLow();
15466 ss
<< m_ExtraFlags
;
15469 ss
<< uint32(m_stableSlots
); // to prevent save uint8 as char
15472 ss
<< uint32(m_atLoginFlags
);
15478 ss
<< (uint64
)m_deathExpireTime
;
15481 ss
<< m_taxi
.SaveTaxiDestinationsToString();
15484 CharacterDatabase
.Execute( ss
.str().c_str() );
15486 if(m_mailsUpdated
) //save mails only when needed
15490 _SaveQuestStatus();
15491 _SaveDailyQuestStatus();
15494 _SaveSpellCooldowns();
15499 CharacterDatabase
.CommitTransaction();
15501 // restore state (before aura apply, if aura remove flag then aura must set it ack by self)
15502 SetDisplayId(tmp_displayid
);
15503 SetUInt32Value(UNIT_FIELD_BYTES_1
, tmp_bytes
);
15504 SetUInt32Value(UNIT_FIELD_BYTES_2
, tmp_bytes2
);
15505 SetUInt32Value(UNIT_FIELD_FLAGS
, tmp_flags
);
15506 SetUInt32Value(PLAYER_FLAGS
, tmp_pflags
);
15508 // save pet (hunter pet level and experience and all type pets health/mana).
15509 if(Pet
* pet
= GetPet())
15510 pet
->SavePetToDB(PET_SAVE_AS_CURRENT
);
15511 m_achievementMgr
.SaveToDB();
15514 // fast save function for item/money cheating preventing - save only inventory and money state
15515 void Player::SaveInventoryAndGoldToDB()
15518 //money is in data field
15519 SaveDataFieldToDB();
15522 void Player::_SaveActions()
15524 for(ActionButtonList::iterator itr
= m_actionButtons
.begin(); itr
!= m_actionButtons
.end(); )
15526 switch (itr
->second
.uState
)
15528 case ACTIONBUTTON_NEW
:
15529 CharacterDatabase
.PExecute("INSERT INTO character_action (guid,button,action,type,misc) VALUES ('%u', '%u', '%u', '%u', '%u')",
15530 GetGUIDLow(), (uint32
)itr
->first
, (uint32
)itr
->second
.action
, (uint32
)itr
->second
.type
, (uint32
)itr
->second
.misc
);
15531 itr
->second
.uState
= ACTIONBUTTON_UNCHANGED
;
15534 case ACTIONBUTTON_CHANGED
:
15535 CharacterDatabase
.PExecute("UPDATE character_action SET action = '%u', type = '%u', misc= '%u' WHERE guid= '%u' AND button= '%u' ",
15536 (uint32
)itr
->second
.action
, (uint32
)itr
->second
.type
, (uint32
)itr
->second
.misc
, GetGUIDLow(), (uint32
)itr
->first
);
15537 itr
->second
.uState
= ACTIONBUTTON_UNCHANGED
;
15540 case ACTIONBUTTON_DELETED
:
15541 CharacterDatabase
.PExecute("DELETE FROM character_action WHERE guid = '%u' and button = '%u'", GetGUIDLow(), (uint32
)itr
->first
);
15542 m_actionButtons
.erase(itr
++);
15551 void Player::_SaveAuras()
15553 CharacterDatabase
.PExecute("DELETE FROM character_aura WHERE guid = '%u'",GetGUIDLow());
15555 AuraMap
const& auras
= GetAuras();
15560 spellEffectPair lastEffectPair
= auras
.begin()->first
;
15561 uint32 stackCounter
= 1;
15563 for(AuraMap::const_iterator itr
= auras
.begin(); ; ++itr
)
15565 if(itr
== auras
.end() || lastEffectPair
!= itr
->first
)
15567 AuraMap::const_iterator itr2
= itr
;
15568 // save previous spellEffectPair to db
15570 SpellEntry
const *spellInfo
= itr2
->second
->GetSpellProto();
15572 //skip all auras from spells that are passive or need a shapeshift
15573 if (!(itr2
->second
->IsPassive() || itr2
->second
->IsRemovedOnShapeLost()))
15575 //do not save single target auras (unless they were cast by the player)
15576 if (!(itr2
->second
->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo
)))
15579 // or apply at cast SPELL_AURA_MOD_SHAPESHIFT or SPELL_AURA_MOD_STEALTH auras
15580 for (i
= 0; i
< 3; i
++)
15581 if (spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MOD_SHAPESHIFT
||
15582 spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MOD_STEALTH
)
15587 CharacterDatabase
.PExecute("INSERT INTO character_aura (guid,caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges) "
15588 "VALUES ('%u', '" I64FMTD
"' ,'%u', '%u', '%u', '%d', '%d', '%d', '%d')",
15589 GetGUIDLow(), itr2
->second
->GetCasterGUID(), (uint32
)itr2
->second
->GetId(), (uint32
)itr2
->second
->GetEffIndex(), stackCounter
, itr2
->second
->GetModifier()->m_amount
,int(itr2
->second
->GetAuraMaxDuration()),int(itr2
->second
->GetAuraDuration()),int(itr2
->second
->GetAuraCharges()));
15594 if(itr
== auras
.end())
15598 if (lastEffectPair
== itr
->first
)
15602 lastEffectPair
= itr
->first
;
15608 void Player::_SaveInventory()
15610 // force items in buyback slots to new state
15611 // and remove those that aren't already
15612 for (uint8 i
= BUYBACK_SLOT_START
; i
< BUYBACK_SLOT_END
; i
++)
15614 Item
*item
= m_items
[i
];
15615 if (!item
|| item
->GetState() == ITEM_NEW
) continue;
15616 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item
->GetGUIDLow());
15617 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", item
->GetGUIDLow());
15618 m_items
[i
]->FSetState(ITEM_NEW
);
15621 // update enchantment durations
15622 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin();itr
!= m_enchantDuration
.end();++itr
)
15624 itr
->item
->SetEnchantmentDuration(itr
->slot
,itr
->leftduration
);
15628 if (m_itemUpdateQueue
.empty()) return;
15630 // do not save if the update queue is corrupt
15631 bool error
= false;
15632 for(size_t i
= 0; i
< m_itemUpdateQueue
.size(); i
++)
15634 Item
*item
= m_itemUpdateQueue
[i
];
15635 if(!item
|| item
->GetState() == ITEM_REMOVED
) continue;
15636 Item
*test
= GetItemByPos( item
->GetBagSlot(), item
->GetSlot());
15640 sLog
.outError("Player(GUID: %u Name: %s)::_SaveInventory - the bag(%d) and slot(%d) values for the item with guid %d are incorrect, the player doesn't have an item at that position!", GetGUIDLow(), GetName(), item
->GetBagSlot(), item
->GetSlot(), item
->GetGUIDLow());
15643 else if (test
!= item
)
15645 sLog
.outError("Player(GUID: %u Name: %s)::_SaveInventory - the bag(%d) and slot(%d) values for the item with guid %d are incorrect, the item with guid %d is there instead!", GetGUIDLow(), GetName(), item
->GetBagSlot(), item
->GetSlot(), item
->GetGUIDLow(), test
->GetGUIDLow());
15652 sLog
.outError("Player::_SaveInventory - one or more errors occurred save aborted!");
15653 ChatHandler(this).SendSysMessage(LANG_ITEM_SAVE_FAILED
);
15657 for(size_t i
= 0; i
< m_itemUpdateQueue
.size(); i
++)
15659 Item
*item
= m_itemUpdateQueue
[i
];
15660 if(!item
) continue;
15662 Bag
*container
= item
->GetContainer();
15663 uint32 bag_guid
= container
? container
->GetGUIDLow() : 0;
15665 switch(item
->GetState())
15668 CharacterDatabase
.PExecute("INSERT INTO character_inventory (guid,bag,slot,item,item_template) VALUES ('%u', '%u', '%u', '%u', '%u')", GetGUIDLow(), bag_guid
, item
->GetSlot(), item
->GetGUIDLow(), item
->GetEntry());
15671 CharacterDatabase
.PExecute("UPDATE character_inventory SET guid='%u', bag='%u', slot='%u', item_template='%u' WHERE item='%u'", GetGUIDLow(), bag_guid
, item
->GetSlot(), item
->GetEntry(), item
->GetGUIDLow());
15674 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item
->GetGUIDLow());
15676 case ITEM_UNCHANGED
:
15680 item
->SaveToDB(); // item have unchanged inventory record and can be save standalone
15682 m_itemUpdateQueue
.clear();
15685 void Player::_SaveMail()
15687 if (!m_mailsLoaded
)
15690 for (PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end(); ++itr
)
15693 if (m
->state
== MAIL_STATE_CHANGED
)
15695 CharacterDatabase
.PExecute("UPDATE mail SET itemTextId = '%u',has_items = '%u',expire_time = '" I64FMTD
"', deliver_time = '" I64FMTD
"',money = '%u',cod = '%u',checked = '%u' WHERE id = '%u'",
15696 m
->itemTextId
, m
->HasItems() ? 1 : 0, (uint64
)m
->expire_time
, (uint64
)m
->deliver_time
, m
->money
, m
->COD
, m
->checked
, m
->messageID
);
15697 if(m
->removedItems
.size())
15699 for(std::vector
<uint32
>::iterator itr2
= m
->removedItems
.begin(); itr2
!= m
->removedItems
.end(); ++itr2
)
15700 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", *itr2
);
15701 m
->removedItems
.clear();
15703 m
->state
= MAIL_STATE_UNCHANGED
;
15705 else if (m
->state
== MAIL_STATE_DELETED
)
15708 for(std::vector
<MailItemInfo
>::iterator itr2
= m
->items
.begin(); itr2
!= m
->items
.end(); ++itr2
)
15709 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", itr2
->item_guid
);
15711 CharacterDatabase
.PExecute("DELETE FROM item_text WHERE id = '%u'", m
->itemTextId
);
15712 CharacterDatabase
.PExecute("DELETE FROM mail WHERE id = '%u'", m
->messageID
);
15713 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE mail_id = '%u'", m
->messageID
);
15717 //deallocate deleted mails...
15718 for (PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end(); )
15720 if ((*itr
)->state
== MAIL_STATE_DELETED
)
15725 itr
= m_mail
.begin();
15731 m_mailsUpdated
= false;
15734 void Player::_SaveQuestStatus()
15736 // we don't need transactions here.
15737 for( QuestStatusMap::iterator i
= mQuestStatus
.begin( ); i
!= mQuestStatus
.end( ); ++i
)
15739 switch (i
->second
.uState
)
15742 CharacterDatabase
.PExecute("INSERT INTO character_queststatus (guid,quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4) "
15743 "VALUES ('%u', '%u', '%u', '%u', '%u', '" I64FMTD
"', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u')",
15744 GetGUIDLow(), i
->first
, i
->second
.m_status
, i
->second
.m_rewarded
, i
->second
.m_explored
, uint64(i
->second
.m_timer
/ 1000 + sWorld
.GetGameTime()), i
->second
.m_creatureOrGOcount
[0], i
->second
.m_creatureOrGOcount
[1], i
->second
.m_creatureOrGOcount
[2], i
->second
.m_creatureOrGOcount
[3], i
->second
.m_itemcount
[0], i
->second
.m_itemcount
[1], i
->second
.m_itemcount
[2], i
->second
.m_itemcount
[3]);
15746 case QUEST_CHANGED
:
15747 CharacterDatabase
.PExecute("UPDATE character_queststatus SET status = '%u',rewarded = '%u',explored = '%u',timer = '" I64FMTD
"',mobcount1 = '%u',mobcount2 = '%u',mobcount3 = '%u',mobcount4 = '%u',itemcount1 = '%u',itemcount2 = '%u',itemcount3 = '%u',itemcount4 = '%u' WHERE guid = '%u' AND quest = '%u' ",
15748 i
->second
.m_status
, i
->second
.m_rewarded
, i
->second
.m_explored
, uint64(i
->second
.m_timer
/ 1000 + sWorld
.GetGameTime()), i
->second
.m_creatureOrGOcount
[0], i
->second
.m_creatureOrGOcount
[1], i
->second
.m_creatureOrGOcount
[2], i
->second
.m_creatureOrGOcount
[3], i
->second
.m_itemcount
[0], i
->second
.m_itemcount
[1], i
->second
.m_itemcount
[2], i
->second
.m_itemcount
[3], GetGUIDLow(), i
->first
);
15750 case QUEST_UNCHANGED
:
15753 i
->second
.uState
= QUEST_UNCHANGED
;
15757 void Player::_SaveDailyQuestStatus()
15759 if(!m_DailyQuestChanged
)
15762 m_DailyQuestChanged
= false;
15764 // save last daily quest time for all quests: we need only mostly reset time for reset check anyway
15766 // we don't need transactions here.
15767 CharacterDatabase
.PExecute("DELETE FROM character_queststatus_daily WHERE guid = '%u'",GetGUIDLow());
15768 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
15769 if(GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
))
15770 CharacterDatabase
.PExecute("INSERT INTO character_queststatus_daily (guid,quest,time) VALUES ('%u', '%u','" I64FMTD
"')",
15771 GetGUIDLow(), GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
),uint64(m_lastDailyQuestTime
));
15774 void Player::_SaveReputation()
15776 for(FactionStateList::iterator itr
= m_factions
.begin(); itr
!= m_factions
.end(); ++itr
)
15778 if (itr
->second
.Changed
)
15780 CharacterDatabase
.PExecute("DELETE FROM character_reputation WHERE guid = '%u' AND faction='%u'", GetGUIDLow(), itr
->second
.ID
);
15781 CharacterDatabase
.PExecute("INSERT INTO character_reputation (guid,faction,standing,flags) VALUES ('%u', '%u', '%i', '%u')", GetGUIDLow(), itr
->second
.ID
, itr
->second
.Standing
, itr
->second
.Flags
);
15782 itr
->second
.Changed
= false;
15787 void Player::_SaveSpells()
15789 for (PlayerSpellMap::const_iterator itr
= m_spells
.begin(), next
= m_spells
.begin(); itr
!= m_spells
.end(); itr
= next
)
15792 if (itr
->second
->state
== PLAYERSPELL_REMOVED
|| itr
->second
->state
== PLAYERSPELL_CHANGED
)
15793 CharacterDatabase
.PExecute("DELETE FROM character_spell WHERE guid = '%u' and spell = '%u'", GetGUIDLow(), itr
->first
);
15794 if (itr
->second
->state
== PLAYERSPELL_NEW
|| itr
->second
->state
== PLAYERSPELL_CHANGED
)
15795 CharacterDatabase
.PExecute("INSERT INTO character_spell (guid,spell,active,disabled) VALUES ('%u', '%u', '%u', '%u')", GetGUIDLow(), itr
->first
, itr
->second
->active
? 1 : 0,itr
->second
->disabled
? 1 : 0);
15797 if (itr
->second
->state
== PLAYERSPELL_REMOVED
)
15798 _removeSpell(itr
->first
);
15800 itr
->second
->state
= PLAYERSPELL_UNCHANGED
;
15804 void Player::_SaveTutorials()
15806 if(!m_TutorialsChanged
)
15810 // it's better than rebuilding indexes multiple times
15811 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT count(*) AS r FROM character_tutorial WHERE account = '%u' AND realmid = '%u'", GetSession()->GetAccountId(), realmID
);
15814 Rows
= result
->Fetch()[0].GetUInt32();
15820 CharacterDatabase
.PExecute("UPDATE character_tutorial SET tut0='%u', tut1='%u', tut2='%u', tut3='%u', tut4='%u', tut5='%u', tut6='%u', tut7='%u' WHERE account = '%u' AND realmid = '%u'",
15821 m_Tutorials
[0], m_Tutorials
[1], m_Tutorials
[2], m_Tutorials
[3], m_Tutorials
[4], m_Tutorials
[5], m_Tutorials
[6], m_Tutorials
[7], GetSession()->GetAccountId(), realmID
);
15825 CharacterDatabase
.PExecute("INSERT INTO character_tutorial (account,realmid,tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7) VALUES ('%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u')", GetSession()->GetAccountId(), realmID
, m_Tutorials
[0], m_Tutorials
[1], m_Tutorials
[2], m_Tutorials
[3], m_Tutorials
[4], m_Tutorials
[5], m_Tutorials
[6], m_Tutorials
[7]);
15828 m_TutorialsChanged
= false;
15831 void Player::outDebugValues() const
15833 if(!sLog
.IsOutDebug()) // optimize disabled debug output
15836 sLog
.outDebug("HP is: \t\t\t%u\t\tMP is: \t\t\t%u",GetMaxHealth(), GetMaxPower(POWER_MANA
));
15837 sLog
.outDebug("AGILITY is: \t\t%f\t\tSTRENGTH is: \t\t%f",GetStat(STAT_AGILITY
), GetStat(STAT_STRENGTH
));
15838 sLog
.outDebug("INTELLECT is: \t\t%f\t\tSPIRIT is: \t\t%f",GetStat(STAT_INTELLECT
), GetStat(STAT_SPIRIT
));
15839 sLog
.outDebug("STAMINA is: \t\t%f\t\tSPIRIT is: \t\t%f",GetStat(STAT_STAMINA
), GetStat(STAT_SPIRIT
));
15840 sLog
.outDebug("Armor is: \t\t%u\t\tBlock is: \t\t%f",GetArmor(), GetFloatValue(PLAYER_BLOCK_PERCENTAGE
));
15841 sLog
.outDebug("HolyRes is: \t\t%u\t\tFireRes is: \t\t%u",GetResistance(SPELL_SCHOOL_HOLY
), GetResistance(SPELL_SCHOOL_FIRE
));
15842 sLog
.outDebug("NatureRes is: \t\t%u\t\tFrostRes is: \t\t%u",GetResistance(SPELL_SCHOOL_NATURE
), GetResistance(SPELL_SCHOOL_FROST
));
15843 sLog
.outDebug("ShadowRes is: \t\t%u\t\tArcaneRes is: \t\t%u",GetResistance(SPELL_SCHOOL_SHADOW
), GetResistance(SPELL_SCHOOL_ARCANE
));
15844 sLog
.outDebug("MIN_DAMAGE is: \t\t%f\tMAX_DAMAGE is: \t\t%f",GetFloatValue(UNIT_FIELD_MINDAMAGE
), GetFloatValue(UNIT_FIELD_MAXDAMAGE
));
15845 sLog
.outDebug("MIN_OFFHAND_DAMAGE is: \t%f\tMAX_OFFHAND_DAMAGE is: \t%f",GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
), GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
));
15846 sLog
.outDebug("MIN_RANGED_DAMAGE is: \t%f\tMAX_RANGED_DAMAGE is: \t%f",GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
), GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
));
15847 sLog
.outDebug("ATTACK_TIME is: \t%u\t\tRANGE_ATTACK_TIME is: \t%u",GetAttackTime(BASE_ATTACK
), GetAttackTime(RANGED_ATTACK
));
15850 /*********************************************************/
15851 /*** FLOOD FILTER SYSTEM ***/
15852 /*********************************************************/
15854 void Player::UpdateSpeakTime()
15856 // ignore chat spam protection for GMs in any mode
15857 if(GetSession()->GetSecurity() > SEC_PLAYER
)
15860 time_t current
= time (NULL
);
15861 if(m_speakTime
> current
)
15863 uint32 max_count
= sWorld
.getConfig(CONFIG_CHATFLOOD_MESSAGE_COUNT
);
15868 if(m_speakCount
>= max_count
)
15870 // prevent overwrite mute time, if message send just before mutes set, for example.
15871 time_t new_mute
= current
+ sWorld
.getConfig(CONFIG_CHATFLOOD_MUTE_TIME
);
15872 if(GetSession()->m_muteTime
< new_mute
)
15873 GetSession()->m_muteTime
= new_mute
;
15881 m_speakTime
= current
+ sWorld
.getConfig(CONFIG_CHATFLOOD_MESSAGE_DELAY
);
15884 bool Player::CanSpeak() const
15886 return GetSession()->m_muteTime
<= time (NULL
);
15889 /*********************************************************/
15890 /*** LOW LEVEL FUNCTIONS:Notifiers ***/
15891 /*********************************************************/
15893 void Player::SendAttackSwingNotInRange()
15895 WorldPacket
data(SMSG_ATTACKSWING_NOTINRANGE
, 0);
15896 GetSession()->SendPacket( &data
);
15899 void Player::SavePositionInDB(uint32 mapid
, float x
,float y
,float z
,float o
,uint32 zone
,uint64 guid
)
15901 std::ostringstream ss
;
15902 ss
<< "UPDATE characters SET position_x='"<<x
<<"',position_y='"<<y
15903 << "',position_z='"<<z
<<"',orientation='"<<o
<<"',map='"<<mapid
15904 << "',zone='"<<zone
<<"',trans_x='0',trans_y='0',trans_z='0',"
15905 << "transguid='0',taxi_path='' WHERE guid='"<< GUID_LOPART(guid
) <<"'";
15906 sLog
.outDebug(ss
.str().c_str());
15907 CharacterDatabase
.Execute(ss
.str().c_str());
15910 void Player::SaveDataFieldToDB()
15912 std::ostringstream ss
;
15913 ss
<<"UPDATE characters SET data='";
15915 for(uint16 i
= 0; i
< m_valuesCount
; i
++ )
15917 ss
<< GetUInt32Value(i
) << " ";
15919 ss
<<"' WHERE guid='"<< GUID_LOPART(GetGUIDLow()) <<"'";
15921 CharacterDatabase
.Execute(ss
.str().c_str());
15924 bool Player::SaveValuesArrayInDB(Tokens
const& tokens
, uint64 guid
)
15926 std::ostringstream ss2
;
15927 ss2
<<"UPDATE characters SET data='";
15929 for (Tokens::const_iterator iter
= tokens
.begin(); iter
!= tokens
.end(); ++iter
, ++i
)
15931 ss2
<<tokens
[i
]<<" ";
15933 ss2
<<"' WHERE guid='"<< GUID_LOPART(guid
) <<"'";
15935 return CharacterDatabase
.Execute(ss2
.str().c_str());
15938 void Player::SetUInt32ValueInArray(Tokens
& tokens
,uint16 index
, uint32 value
)
15941 snprintf(buf
,11,"%u",value
);
15943 if(index
>= tokens
.size())
15946 tokens
[index
] = buf
;
15949 void Player::SetUInt32ValueInDB(uint16 index
, uint32 value
, uint64 guid
)
15952 if(!LoadValuesArrayFromDB(tokens
,guid
))
15955 if(index
>= tokens
.size())
15959 snprintf(buf
,11,"%u",value
);
15960 tokens
[index
] = buf
;
15962 SaveValuesArrayInDB(tokens
,guid
);
15965 void Player::SetFloatValueInDB(uint16 index
, float value
, uint64 guid
)
15968 memcpy(&temp
, &value
, sizeof(value
));
15969 Player::SetUInt32ValueInDB(index
, temp
, guid
);
15972 void Player::Customize(uint64 guid
, uint8 gender
, uint8 skin
, uint8 face
, uint8 hairStyle
, uint8 hairColor
, uint8 facialHair
)
15975 if(!LoadValuesArrayFromDB(tokens
, guid
))
15978 uint32 unit_bytes0
= GetUInt32ValueFromArray(tokens
, UNIT_FIELD_BYTES_0
);
15979 uint8 race
= unit_bytes0
& 0xFF;
15980 uint8 class_
= (unit_bytes0
>> 8) & 0xFF;
15982 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(race
, class_
);
15986 unit_bytes0
&= ~(0xFF << 16);
15987 unit_bytes0
|= (gender
<< 16);
15988 SetUInt32ValueInArray(tokens
, UNIT_FIELD_BYTES_0
, unit_bytes0
);
15990 SetUInt32ValueInArray(tokens
, UNIT_FIELD_DISPLAYID
, gender
? info
->displayId_f
: info
->displayId_m
);
15991 SetUInt32ValueInArray(tokens
, UNIT_FIELD_NATIVEDISPLAYID
, gender
? info
->displayId_f
: info
->displayId_m
);
15993 SetUInt32ValueInArray(tokens
, PLAYER_BYTES
, (skin
| (face
<< 8) | (hairStyle
<< 16) | (hairColor
<< 24)));
15995 uint32 player_bytes2
= GetUInt32ValueFromArray(tokens
, PLAYER_BYTES_2
);
15996 player_bytes2
&= ~0xFF;
15997 player_bytes2
|= facialHair
;
15998 SetUInt32ValueInArray(tokens
, PLAYER_BYTES_2
, player_bytes2
);
16000 uint32 player_bytes3
= GetUInt32ValueFromArray(tokens
, PLAYER_BYTES_3
);
16001 player_bytes3
&= ~0xFF;
16002 player_bytes3
|= gender
;
16003 SetUInt32ValueInArray(tokens
, PLAYER_BYTES_3
, player_bytes3
);
16005 SaveValuesArrayInDB(tokens
, guid
);
16008 void Player::SendAttackSwingNotStanding()
16010 WorldPacket
data(SMSG_ATTACKSWING_NOTSTANDING
, 0);
16011 GetSession()->SendPacket( &data
);
16014 void Player::SendAttackSwingDeadTarget()
16016 WorldPacket
data(SMSG_ATTACKSWING_DEADTARGET
, 0);
16017 GetSession()->SendPacket( &data
);
16020 void Player::SendAttackSwingCantAttack()
16022 WorldPacket
data(SMSG_ATTACKSWING_CANT_ATTACK
, 0);
16023 GetSession()->SendPacket( &data
);
16026 void Player::SendAttackSwingCancelAttack()
16028 WorldPacket
data(SMSG_CANCEL_COMBAT
, 0);
16029 GetSession()->SendPacket( &data
);
16032 void Player::SendAttackSwingBadFacingAttack()
16034 WorldPacket
data(SMSG_ATTACKSWING_BADFACING
, 0);
16035 GetSession()->SendPacket( &data
);
16038 void Player::SendAutoRepeatCancel()
16040 WorldPacket
data(SMSG_CANCEL_AUTO_REPEAT
, GetPackGUID().size());
16041 data
.append(GetPackGUID()); // may be it's target guid
16042 GetSession()->SendPacket( &data
);
16045 void Player::PlaySound(uint32 Sound
, bool OnlySelf
)
16047 WorldPacket
data(SMSG_PLAY_SOUND
, 4);
16050 GetSession()->SendPacket( &data
);
16052 SendMessageToSet( &data
, true );
16055 void Player::SendExplorationExperience(uint32 Area
, uint32 Experience
)
16057 WorldPacket
data( SMSG_EXPLORATION_EXPERIENCE
, 8 );
16059 data
<< Experience
;
16060 GetSession()->SendPacket(&data
);
16063 void Player::SendDungeonDifficulty(bool IsInGroup
)
16065 uint8 val
= 0x00000001;
16066 WorldPacket
data(MSG_SET_DUNGEON_DIFFICULTY
, 12);
16067 data
<< (uint32
)GetDifficulty();
16068 data
<< uint32(val
);
16069 data
<< uint32(IsInGroup
);
16070 GetSession()->SendPacket(&data
);
16073 void Player::SendResetFailedNotify(uint32 mapid
)
16075 WorldPacket
data(SMSG_RESET_FAILED_NOTIFY
, 4);
16076 data
<< uint32(mapid
);
16077 GetSession()->SendPacket(&data
);
16080 /// Reset all solo instances and optionally send a message on success for each
16081 void Player::ResetInstances(uint8 method
)
16083 // method can be INSTANCE_RESET_ALL, INSTANCE_RESET_CHANGE_DIFFICULTY, INSTANCE_RESET_GROUP_JOIN
16085 // we assume that when the difficulty changes, all instances that can be reset will be
16086 uint8 dif
= GetDifficulty();
16088 for (BoundInstancesMap::iterator itr
= m_boundInstances
[dif
].begin(); itr
!= m_boundInstances
[dif
].end();)
16090 InstanceSave
*p
= itr
->second
.save
;
16091 const MapEntry
*entry
= sMapStore
.LookupEntry(itr
->first
);
16092 if(!entry
|| !p
->CanReset())
16098 if(method
== INSTANCE_RESET_ALL
)
16100 // the "reset all instances" method can only reset normal maps
16101 if(dif
== DIFFICULTY_HEROIC
|| entry
->map_type
== MAP_RAID
)
16108 // if the map is loaded, reset it
16109 Map
*map
= MapManager::Instance().FindMap(p
->GetMapId(), p
->GetInstanceId());
16110 if(map
&& map
->IsDungeon())
16111 ((InstanceMap
*)map
)->Reset(method
);
16113 // since this is a solo instance there should not be any players inside
16114 if(method
== INSTANCE_RESET_ALL
|| method
== INSTANCE_RESET_CHANGE_DIFFICULTY
)
16115 SendResetInstanceSuccess(p
->GetMapId());
16118 m_boundInstances
[dif
].erase(itr
++);
16120 // the following should remove the instance save from the manager and delete it as well
16121 p
->RemovePlayer(this);
16125 void Player::SendResetInstanceSuccess(uint32 MapId
)
16127 WorldPacket
data(SMSG_INSTANCE_RESET
, 4);
16129 GetSession()->SendPacket(&data
);
16132 void Player::SendResetInstanceFailed(uint32 reason
, uint32 MapId
)
16134 // TODO: find what other fail reasons there are besides players in the instance
16135 WorldPacket
data(SMSG_INSTANCE_RESET_FAILED
, 4);
16138 GetSession()->SendPacket(&data
);
16141 /*********************************************************/
16142 /*** Update timers ***/
16143 /*********************************************************/
16145 ///checks the 15 afk reports per 5 minutes limit
16146 void Player::UpdateAfkReport(time_t currTime
)
16148 if(m_bgAfkReportedTimer
<= currTime
)
16150 m_bgAfkReportedCount
= 0;
16151 m_bgAfkReportedTimer
= currTime
+5*MINUTE
;
16155 void Player::UpdateContestedPvP(uint32 diff
)
16157 if(!m_contestedPvPTimer
||isInCombat())
16159 if(m_contestedPvPTimer
<= diff
)
16161 ResetContestedPvP();
16164 m_contestedPvPTimer
-= diff
;
16167 void Player::UpdatePvPFlag(time_t currTime
)
16171 if(pvpInfo
.endTimer
== 0 || currTime
< (pvpInfo
.endTimer
+ 300))
16177 void Player::UpdateDuelFlag(time_t currTime
)
16179 if(!duel
|| duel
->startTimer
== 0 ||currTime
< duel
->startTimer
+ 3)
16182 SetUInt32Value(PLAYER_DUEL_TEAM
, 1);
16183 duel
->opponent
->SetUInt32Value(PLAYER_DUEL_TEAM
, 2);
16185 duel
->startTimer
= 0;
16186 duel
->startTime
= currTime
;
16187 duel
->opponent
->duel
->startTimer
= 0;
16188 duel
->opponent
->duel
->startTime
= currTime
;
16191 void Player::RemovePet(Pet
* pet
, PetSaveMode mode
, bool returnreagent
)
16196 if(returnreagent
&& (pet
|| m_temporaryUnsummonedPetNumber
))
16198 //returning of reagents only for players, so best done here
16199 uint32 spellId
= pet
? pet
->GetUInt32Value(UNIT_CREATED_BY_SPELL
) : m_oldpetspell
;
16200 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
16204 for(uint32 i
= 0; i
< 7; ++i
)
16206 if(spellInfo
->Reagent
[i
] > 0)
16208 ItemPosCountVec dest
; //for succubus, voidwalker, felhunter and felguard credit soulshard when despawn reason other than death (out of range, logout)
16209 uint8 msg
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, spellInfo
->Reagent
[i
], spellInfo
->ReagentCount
[i
] );
16210 if( msg
== EQUIP_ERR_OK
)
16212 Item
* item
= StoreNewItem( dest
, spellInfo
->Reagent
[i
], true);
16214 SendNewItem(item
,spellInfo
->ReagentCount
[i
],true,false);
16219 m_temporaryUnsummonedPetNumber
= 0;
16222 if(!pet
|| pet
->GetOwnerGUID()!=GetGUID())
16225 // only if current pet in slot
16226 switch(pet
->getPetType())
16232 m_guardianPets
.erase(pet
->GetGUID());
16235 if(GetPetGUID() == pet
->GetGUID())
16244 switch(pet
->GetEntry())
16246 //warlock pets except imp are removed(?) when logging out
16251 mode
= PET_SAVE_NOT_IN_SLOT
;
16256 pet
->SavePetToDB(mode
);
16258 pet
->CleanupsBeforeDelete();
16259 pet
->AddObjectToRemoveList();
16260 pet
->m_removed
= true;
16262 if(pet
->isControlled())
16264 WorldPacket
data(SMSG_PET_SPELLS
, 8);
16267 GetSession()->SendPacket(&data
);
16270 SetGroupUpdateFlag(GROUP_UPDATE_PET
);
16274 void Player::RemoveMiniPet()
16276 if(Pet
* pet
= GetMiniPet())
16278 pet
->Remove(PET_SAVE_AS_DELETED
);
16283 Pet
* Player::GetMiniPet()
16287 return ObjectAccessor::GetPet(m_miniPet
);
16290 void Player::RemoveGuardians()
16292 while(!m_guardianPets
.empty())
16294 uint64 guid
= *m_guardianPets
.begin();
16295 if(Pet
* pet
= ObjectAccessor::GetPet(guid
))
16296 pet
->Remove(PET_SAVE_AS_DELETED
);
16298 m_guardianPets
.erase(guid
);
16302 bool Player::HasGuardianWithEntry(uint32 entry
)
16304 // pet guid middle part is entry (and creature also)
16305 // and in guardian list must be guardians with same entry _always_
16306 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
16307 if(GUID_ENPART(*itr
)==entry
)
16313 void Player::Uncharm()
16315 Unit
* charm
= GetCharm();
16319 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM
);
16320 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS
);
16323 void Player::BuildPlayerChat(WorldPacket
*data
, uint8 msgtype
, const std::string
& text
, uint32 language
) const
16325 *data
<< (uint8
)msgtype
;
16326 *data
<< (uint32
)language
;
16327 *data
<< (uint64
)GetGUID();
16328 *data
<< (uint32
)language
; //language 2.1.0 ?
16329 *data
<< (uint64
)GetGUID();
16330 *data
<< (uint32
)(text
.length()+1);
16332 *data
<< (uint8
)chatTag();
16335 void Player::Say(const std::string
& text
, const uint32 language
)
16337 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
16338 BuildPlayerChat(&data
, CHAT_MSG_SAY
, text
, language
);
16339 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_SAY
),true);
16342 void Player::Yell(const std::string
& text
, const uint32 language
)
16344 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
16345 BuildPlayerChat(&data
, CHAT_MSG_YELL
, text
, language
);
16346 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_YELL
),true);
16349 void Player::TextEmote(const std::string
& text
)
16351 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
16352 BuildPlayerChat(&data
, CHAT_MSG_EMOTE
, text
, LANG_UNIVERSAL
);
16353 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE
),true, !sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT
) );
16356 void Player::Whisper(const std::string
& text
, uint32 language
,uint64 receiver
)
16358 if (language
!= LANG_ADDON
) // if not addon data
16359 language
= LANG_UNIVERSAL
; // whispers should always be readable
16361 Player
*rPlayer
= objmgr
.GetPlayer(receiver
);
16363 // when player you are whispering to is dnd, he cannot receive your message, unless you are in gm mode
16364 if(!rPlayer
->isDND() || isGameMaster())
16366 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
16367 BuildPlayerChat(&data
, CHAT_MSG_WHISPER
, text
, language
);
16368 rPlayer
->GetSession()->SendPacket(&data
);
16370 data
.Initialize(SMSG_MESSAGECHAT
, 200);
16371 rPlayer
->BuildPlayerChat(&data
, CHAT_MSG_REPLY
, text
, language
);
16372 GetSession()->SendPacket(&data
);
16376 // announce to player that player he is whispering to is dnd and cannot receive his message
16377 ChatHandler(this).PSendSysMessage(LANG_PLAYER_DND
, rPlayer
->GetName(), rPlayer
->dndMsg
.c_str());
16380 if(!isAcceptWhispers())
16382 SetAcceptWhispers(true);
16383 ChatHandler(this).SendSysMessage(LANG_COMMAND_WHISPERON
);
16386 // announce to player that player he is whispering to is afk
16387 if(rPlayer
->isAFK())
16388 ChatHandler(this).PSendSysMessage(LANG_PLAYER_AFK
, rPlayer
->GetName(), rPlayer
->afkMsg
.c_str());
16390 // if player whisper someone, auto turn of dnd to be able to receive an answer
16391 if(isDND() && !rPlayer
->isGameMaster())
16395 void Player::PetSpellInitialize()
16397 Pet
* pet
= GetPet();
16402 sLog
.outDebug("Pet Spells Groups");
16404 CharmInfo
*charmInfo
= pet
->GetCharmInfo();
16406 WorldPacket
data(SMSG_PET_SPELLS
, 8+4+4+4+10*4);
16407 data
<< uint64(pet
->GetGUID());
16408 data
<< uint32(pet
->GetCreatureInfo()->family
); // creature family (required for pet talents)
16410 data
<< uint8(charmInfo
->GetReactState()) << uint8(charmInfo
->GetCommandState()) << uint16(0);
16413 for(uint32 i
= 0; i
< 10; i
++)
16415 data
<< uint32(charmInfo
->GetActionBarEntry(i
)->Raw
);
16418 size_t spellsCountPos
= data
.wpos();
16422 data
<< uint8(addlist
); // placeholder
16424 if(pet
->isControlled() && ((pet
->getPetType() == HUNTER_PET
) || ((pet
->GetCreatureInfo()->type
== CREATURE_TYPE_DEMON
) && (getClass() == CLASS_WARLOCK
))))
16427 for (PetSpellMap::iterator itr
= pet
->m_spells
.begin(); itr
!= pet
->m_spells
.end(); ++itr
)
16429 if(itr
->second
->state
== PETSPELL_REMOVED
)
16432 data
<< uint16(itr
->first
);
16433 data
<< uint16(itr
->second
->active
); // pet spell active state isn't boolean
16438 data
.put
<uint8
>(spellsCountPos
, addlist
);
16440 uint8 cooldownsCount
= pet
->m_CreatureSpellCooldowns
.size() + pet
->m_CreatureCategoryCooldowns
.size();
16441 data
<< uint8(cooldownsCount
);
16443 time_t curTime
= time(NULL
);
16445 for(CreatureSpellCooldowns::const_iterator itr
= pet
->m_CreatureSpellCooldowns
.begin(); itr
!= pet
->m_CreatureSpellCooldowns
.end(); ++itr
)
16447 time_t cooldown
= 0;
16449 if(itr
->second
> curTime
)
16450 cooldown
= (itr
->second
- curTime
) * 1000;
16452 data
<< uint16(itr
->first
); // spellid
16453 data
<< uint16(0); // spell category?
16454 data
<< uint32(itr
->second
); // cooldown
16455 data
<< uint32(0); // category cooldown
16458 for(CreatureSpellCooldowns::const_iterator itr
= pet
->m_CreatureCategoryCooldowns
.begin(); itr
!= pet
->m_CreatureCategoryCooldowns
.end(); ++itr
)
16460 time_t cooldown
= 0;
16462 if(itr
->second
> curTime
)
16463 cooldown
= (itr
->second
- curTime
) * 1000;
16465 data
<< uint16(itr
->first
); // spellid
16466 data
<< uint16(0); // spell category?
16467 data
<< uint32(0); // cooldown
16468 data
<< uint32(itr
->second
); // category cooldown
16471 GetSession()->SendPacket(&data
);
16474 void Player::PossessSpellInitialize()
16476 Unit
* charm
= GetCharm();
16481 CharmInfo
*charmInfo
= charm
->GetCharmInfo();
16485 sLog
.outError("Player::PossessSpellInitialize(): charm ("I64FMTD
") has no charminfo!", charm
->GetGUID());
16490 WorldPacket
data(SMSG_PET_SPELLS
, 16+40+1+4*addlist
+25);// first line + actionbar + spellcount + spells + last adds
16493 data
<< uint64(charm
->GetGUID());
16494 data
<< uint32(0x00000000);
16496 data
<< uint8(0) << uint8(0) << uint16(0);
16498 for(uint32 i
= 0; i
< 10; i
++) //40
16500 data
<< uint16(charmInfo
->GetActionBarEntry(i
)->SpellOrAction
) << uint16(charmInfo
->GetActionBarEntry(i
)->Type
);
16503 data
<< uint8(addlist
); //1
16506 data
<< uint8(count
); // cooldowns count
16508 GetSession()->SendPacket(&data
);
16511 void Player::CharmSpellInitialize()
16513 Unit
* charm
= GetCharm();
16518 CharmInfo
*charmInfo
= charm
->GetCharmInfo();
16521 sLog
.outError("Player::CharmSpellInitialize(): the player's charm ("I64FMTD
") has no charminfo!", charm
->GetGUID());
16527 if(charm
->GetTypeId() != TYPEID_PLAYER
)
16529 CreatureInfo
const *cinfo
= ((Creature
*)charm
)->GetCreatureInfo();
16531 if(cinfo
&& cinfo
->type
== CREATURE_TYPE_DEMON
&& getClass() == CLASS_WARLOCK
)
16533 for(uint32 i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
16535 if(charmInfo
->GetCharmSpell(i
)->spellId
)
16541 WorldPacket
data(SMSG_PET_SPELLS
, 16+40+1+4*addlist
+25);// first line + actionbar + spellcount + spells + last adds
16543 data
<< uint64(charm
->GetGUID());
16544 data
<< uint32(0x00000000);
16546 if(charm
->GetTypeId() != TYPEID_PLAYER
)
16547 data
<< uint8(charmInfo
->GetReactState()) << uint8(charmInfo
->GetCommandState());
16549 data
<< uint8(0) << uint8(0);
16552 for(uint32 i
= 0; i
< 10; i
++) //40
16554 data
<< uint16(charmInfo
->GetActionBarEntry(i
)->SpellOrAction
) << uint16(charmInfo
->GetActionBarEntry(i
)->Type
);
16557 data
<< uint8(addlist
); //1
16561 for(uint32 i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
16563 CharmSpellEntry
*cspell
= charmInfo
->GetCharmSpell(i
);
16564 if(cspell
->spellId
)
16566 data
<< uint16(cspell
->spellId
);
16567 data
<< uint16(cspell
->active
);
16573 data
<< uint8(count
); // cooldowns count
16575 GetSession()->SendPacket(&data
);
16578 bool Player::IsAffectedBySpellmod(SpellEntry
const *spellInfo
, SpellModifier
*mod
, Spell
const* spell
)
16580 if (!mod
|| !spellInfo
)
16583 if(mod
->charges
== -1 && mod
->lastAffected
) // marked as expired but locked until spell casting finish
16585 // prevent apply to any spell except spell that trigger expire
16588 if(mod
->lastAffected
!= spell
)
16591 else if(mod
->lastAffected
!= FindCurrentSpellBySpellId(spellInfo
->Id
))
16595 return spellmgr
.IsAffectedByMod(spellInfo
, mod
);
16598 void Player::AddSpellMod(SpellModifier
* mod
, bool apply
)
16600 uint16 Opcode
= (mod
->type
== SPELLMOD_FLAT
) ? SMSG_SET_FLAT_SPELL_MODIFIER
: SMSG_SET_PCT_SPELL_MODIFIER
;
16602 for(int eff
=0;eff
<96;++eff
)
16606 if (eff
<64) _mask
= uint64(1) << (eff
- 0);
16607 else _mask2
= uint64(1) << (eff
-64);
16608 if ( mod
->mask
& _mask
|| mod
->mask2
& _mask2
)
16611 for (SpellModList::iterator itr
= m_spellMods
[mod
->op
].begin(); itr
!= m_spellMods
[mod
->op
].end(); ++itr
)
16613 if ((*itr
)->type
== mod
->type
&& ((*itr
)->mask
& _mask
|| (*itr
)->mask2
& _mask2
))
16614 val
+= (*itr
)->value
;
16616 val
+= apply
? mod
->value
: -(mod
->value
);
16617 WorldPacket
data(Opcode
, (1+1+4));
16618 data
<< uint8(eff
);
16619 data
<< uint8(mod
->op
);
16620 data
<< int32(val
);
16621 SendDirectMessage(&data
);
16626 m_spellMods
[mod
->op
].push_back(mod
);
16629 if (mod
->charges
== -1)
16630 --m_SpellModRemoveCount
;
16631 m_spellMods
[mod
->op
].remove(mod
);
16636 void Player::RemoveSpellMods(Spell
const* spell
)
16638 if(!spell
|| (m_SpellModRemoveCount
== 0))
16641 for(int i
=0;i
<MAX_SPELLMOD
;++i
)
16643 for (SpellModList::iterator itr
= m_spellMods
[i
].begin(); itr
!= m_spellMods
[i
].end();)
16645 SpellModifier
*mod
= *itr
;
16648 if (mod
&& mod
->charges
== -1 && (mod
->lastAffected
== spell
|| mod
->lastAffected
==NULL
))
16650 RemoveAurasDueToSpell(mod
->spellId
);
16651 if (m_spellMods
[i
].empty())
16654 itr
= m_spellMods
[i
].begin();
16660 // send Proficiency
16661 void Player::SendProficiency(uint8 pr1
, uint32 pr2
)
16663 WorldPacket
data(SMSG_SET_PROFICIENCY
, 8);
16664 data
<< pr1
<< pr2
;
16665 GetSession()->SendPacket (&data
);
16668 void Player::RemovePetitionsAndSigns(uint64 guid
, uint32 type
)
16670 QueryResult
*result
= NULL
;
16672 result
= CharacterDatabase
.PQuery("SELECT ownerguid,petitionguid FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid
));
16674 result
= CharacterDatabase
.PQuery("SELECT ownerguid,petitionguid FROM petition_sign WHERE playerguid = '%u' AND type = '%u'", GUID_LOPART(guid
), type
);
16677 do // this part effectively does nothing, since the deletion / modification only takes place _after_ the PetitionQuery. Though I don't know if the result remains intact if I execute the delete query beforehand.
16678 { // and SendPetitionQueryOpcode reads data from the DB
16679 Field
*fields
= result
->Fetch();
16680 uint64 ownerguid
= MAKE_NEW_GUID(fields
[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
16681 uint64 petitionguid
= MAKE_NEW_GUID(fields
[1].GetUInt32(), 0, HIGHGUID_ITEM
);
16683 // send update if charter owner in game
16684 Player
* owner
= objmgr
.GetPlayer(ownerguid
);
16686 owner
->GetSession()->SendPetitionQueryOpcode(petitionguid
);
16688 } while ( result
->NextRow() );
16693 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid
));
16695 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u' AND type = '%u'", GUID_LOPART(guid
), type
);
16698 CharacterDatabase
.BeginTransaction();
16701 CharacterDatabase
.PExecute("DELETE FROM petition WHERE ownerguid = '%u'", GUID_LOPART(guid
));
16702 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE ownerguid = '%u'", GUID_LOPART(guid
));
16706 CharacterDatabase
.PExecute("DELETE FROM petition WHERE ownerguid = '%u' AND type = '%u'", GUID_LOPART(guid
), type
);
16707 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE ownerguid = '%u' AND type = '%u'", GUID_LOPART(guid
), type
);
16709 CharacterDatabase
.CommitTransaction();
16712 void Player::LeaveAllArenaTeams(uint64 guid
)
16714 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT arena_team_member.arenateamid FROM arena_team_member JOIN arena_team ON arena_team_member.arenateamid = arena_team.arenateamid WHERE guid='%u'", GUID_LOPART(guid
));
16720 Field
*fields
= result
->Fetch();
16721 uint32 at_id
= fields
[0].GetUInt32();
16724 ArenaTeam
* at
= objmgr
.GetArenaTeamById(at_id
);
16726 at
->DelMember(guid
);
16728 } while (result
->NextRow());
16733 void Player::SetRestBonus (float rest_bonus_new
)
16735 // Prevent resting on max level
16736 if(getLevel() >= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
16737 rest_bonus_new
= 0;
16739 if(rest_bonus_new
< 0)
16740 rest_bonus_new
= 0;
16742 float rest_bonus_max
= (float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP
)*1.5/2;
16744 if(rest_bonus_new
> rest_bonus_max
)
16745 m_rest_bonus
= rest_bonus_max
;
16747 m_rest_bonus
= rest_bonus_new
;
16749 // update data for client
16750 if(m_rest_bonus
>10)
16751 SetByteValue(PLAYER_BYTES_2
, 3, 0x01); // Set Reststate = Rested
16752 else if(m_rest_bonus
<=1)
16753 SetByteValue(PLAYER_BYTES_2
, 3, 0x02); // Set Reststate = Normal
16756 SetUInt32Value(PLAYER_REST_STATE_EXPERIENCE
, uint32(m_rest_bonus
));
16759 void Player::HandleStealthedUnitsDetection()
16761 std::list
<Unit
*> stealthedUnits
;
16763 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(),GetPositionY()));
16765 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
16766 cell
.SetNoCreate();
16768 MaNGOS::AnyStealthedCheck u_check
;
16769 MaNGOS::UnitListSearcher
<MaNGOS::AnyStealthedCheck
> searcher(stealthedUnits
, u_check
);
16771 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyStealthedCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
16772 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyStealthedCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
16774 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
16775 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *GetMap());
16776 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *GetMap());
16778 for (std::list
<Unit
*>::iterator i
= stealthedUnits
.begin(); i
!= stealthedUnits
.end();)
16782 i
= stealthedUnits
.erase(i
);
16786 if ((*i
)->isVisibleForOrDetect(this,true))
16789 (*i
)->SendUpdateToPlayer(this);
16790 m_clientGUIDs
.insert((*i
)->GetGUID());
16792 #ifdef MANGOS_DEBUG
16793 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
16794 sLog
.outDebug("Object %u (Type: %u) is detected in stealth by player %u. Distance = %f",(*i
)->GetGUIDLow(),(*i
)->GetTypeId(),GetGUIDLow(),GetDistance(*i
));
16797 // target aura duration for caster show only if target exist at caster client
16798 // send data at target visibility change (adding to client)
16799 if((*i
)!=this && (*i
)->isType(TYPEMASK_UNIT
))
16800 SendAurasForTarget(*i
);
16802 i
= stealthedUnits
.erase(i
);
16810 bool Player::ActivateTaxiPathTo(std::vector
<uint32
> const& nodes
, uint32 mount_id
, Creature
* npc
)
16812 if(nodes
.size() < 2)
16815 // not let cheating with start flight mounted
16818 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16819 data
<< uint32(ERR_TAXIPLAYERALREADYMOUNTED
);
16820 GetSession()->SendPacket(&data
);
16824 if( m_ShapeShiftFormSpellId
&& m_form
!= FORM_BATTLESTANCE
&& m_form
!= FORM_BERSERKERSTANCE
&& m_form
!= FORM_DEFENSIVESTANCE
&& m_form
!= FORM_SHADOW
)
16826 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16827 data
<< uint32(ERR_TAXIPLAYERSHAPESHIFTED
);
16828 GetSession()->SendPacket(&data
);
16832 // not let cheating with start flight in time of logout process || if casting not finished || while in combat || if not use Spell's with EffectSendTaxi
16833 if(GetSession()->isLogingOut() ||
16834 (!m_currentSpells
[CURRENT_GENERIC_SPELL
] ||
16835 m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Effect
[0] != SPELL_EFFECT_SEND_TAXI
)&&
16836 IsNonMeleeSpellCasted(false) ||
16839 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16840 data
<< uint32(ERR_TAXIPLAYERBUSY
);
16841 GetSession()->SendPacket(&data
);
16845 if(HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_DISABLE_MOVE
))
16848 uint32 sourcenode
= nodes
[0];
16850 // starting node too far away (cheat?)
16851 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(sourcenode
);
16852 if( !node
|| node
->map_id
!= GetMapId() ||
16853 (node
->x
- GetPositionX())*(node
->x
- GetPositionX())+
16854 (node
->y
- GetPositionY())*(node
->y
- GetPositionY())+
16855 (node
->z
- GetPositionZ())*(node
->z
- GetPositionZ()) >
16856 (2*INTERACTION_DISTANCE
)*(2*INTERACTION_DISTANCE
)*(2*INTERACTION_DISTANCE
) )
16858 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16859 data
<< uint32(ERR_TAXIUNSPECIFIEDSERVERERROR
);
16860 GetSession()->SendPacket(&data
);
16864 // Prepare to flight start now
16866 // stop combat at start taxi flight if any
16869 // stop trade (client cancel trade at taxi map open but cheating tools can be used for reopen it)
16872 // clean not finished taxi path if any
16873 m_taxi
.ClearTaxiDestinations();
16875 // 0 element current node
16876 m_taxi
.AddTaxiDestination(sourcenode
);
16878 // fill destinations path tail
16879 uint32 sourcepath
= 0;
16880 uint32 totalcost
= 0;
16882 uint32 prevnode
= sourcenode
;
16883 uint32 lastnode
= 0;
16885 for(uint32 i
= 1; i
< nodes
.size(); ++i
)
16889 lastnode
= nodes
[i
];
16890 objmgr
.GetTaxiPath(prevnode
, lastnode
, path
, cost
);
16894 m_taxi
.ClearTaxiDestinations();
16900 if(prevnode
== sourcenode
)
16903 m_taxi
.AddTaxiDestination(lastnode
);
16905 prevnode
= lastnode
;
16908 if(!mount_id
) // if not provide then attempt use default.
16909 mount_id
= objmgr
.GetTaxiMount(sourcenode
, GetTeam());
16911 if (mount_id
== 0 || sourcepath
== 0)
16913 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16914 data
<< uint32(ERR_TAXIUNSPECIFIEDSERVERERROR
);
16915 GetSession()->SendPacket(&data
);
16916 m_taxi
.ClearTaxiDestinations();
16920 uint32 money
= GetMoney();
16924 totalcost
= (uint32
)ceil(totalcost
*GetReputationPriceDiscount(npc
));
16927 if(money
< totalcost
)
16929 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16930 data
<< uint32(ERR_TAXINOTENOUGHMONEY
);
16931 GetSession()->SendPacket(&data
);
16932 m_taxi
.ClearTaxiDestinations();
16936 //Checks and preparations done, DO FLIGHT
16937 ModifyMoney(-(int32
)totalcost
);
16939 // prevent stealth flight
16940 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
16942 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16943 data
<< uint32(ERR_TAXIOK
);
16944 GetSession()->SendPacket(&data
);
16946 sLog
.outDebug("WORLD: Sent SMSG_ACTIVATETAXIREPLY");
16948 GetSession()->SendDoFlight(mount_id
, sourcepath
);
16953 void Player::ProhibitSpellScholl(SpellSchoolMask idSchoolMask
, uint32 unTimeMs
)
16955 // last check 2.0.10
16956 WorldPacket
data(SMSG_SPELL_COOLDOWN
, 8+1+m_spells
.size()*8);
16958 data
<< uint8(0x0); // flags (0x1, 0x2)
16959 time_t curTime
= time(NULL
);
16960 for(PlayerSpellMap::const_iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
16962 if (itr
->second
->state
== PLAYERSPELL_REMOVED
)
16964 uint32 unSpellId
= itr
->first
;
16965 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(unSpellId
);
16972 // Not send cooldown for this spells
16973 if (spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
16976 if((idSchoolMask
& GetSpellSchoolMask(spellInfo
)) && GetSpellCooldownDelay(unSpellId
) < unTimeMs
)
16979 data
<< unTimeMs
; // in m.secs
16980 AddSpellCooldown(unSpellId
, 0, curTime
+ unTimeMs
/1000);
16983 GetSession()->SendPacket(&data
);
16986 void Player::InitDataForForm(bool reapplyMods
)
16988 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
16989 if(ssEntry
&& ssEntry
->attackSpeed
)
16991 SetAttackTime(BASE_ATTACK
,ssEntry
->attackSpeed
);
16992 SetAttackTime(OFF_ATTACK
,ssEntry
->attackSpeed
);
16993 SetAttackTime(RANGED_ATTACK
, BASE_ATTACK_TIME
);
16996 SetRegularAttackTime();
17002 if(getPowerType()!=POWER_ENERGY
)
17003 setPowerType(POWER_ENERGY
);
17007 case FORM_DIREBEAR
:
17009 if(getPowerType()!=POWER_RAGE
)
17010 setPowerType(POWER_RAGE
);
17013 default: // 0, for example
17015 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(getClass());
17016 if(cEntry
&& cEntry
->powerType
< MAX_POWERS
&& uint32(getPowerType()) != cEntry
->powerType
)
17017 setPowerType(Powers(cEntry
->powerType
));
17022 // update auras at form change, ignore this at mods reapply (.reset stats/etc) when form not change.
17024 UpdateEquipSpellsAtFormChange();
17026 UpdateAttackPowerAndDamage();
17027 UpdateAttackPowerAndDamage(true);
17030 // Return true is the bought item has a max count to force refresh of window by caller
17031 bool Player::BuyItemFromVendor(uint64 vendorguid
, uint32 item
, uint8 count
, uint64 bagguid
, uint8 slot
)
17033 // cheating attempt
17034 if(count
< 1) count
= 1;
17039 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( item
);
17042 SendBuyError( BUY_ERR_CANT_FIND_ITEM
, NULL
, item
, 0);
17046 Creature
*pCreature
= ObjectAccessor::GetNPCIfCanInteractWith(*this, vendorguid
,UNIT_NPC_FLAG_VENDOR
);
17049 sLog
.outDebug( "WORLD: BuyItemFromVendor - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid
)) );
17050 SendBuyError( BUY_ERR_DISTANCE_TOO_FAR
, NULL
, item
, 0);
17054 VendorItemData
const* vItems
= pCreature
->GetVendorItems();
17055 if(!vItems
|| vItems
->Empty())
17057 SendBuyError( BUY_ERR_CANT_FIND_ITEM
, pCreature
, item
, 0);
17061 size_t vendor_slot
= vItems
->FindItemSlot(item
);
17062 if(vendor_slot
>= vItems
->GetItemCount())
17064 SendBuyError( BUY_ERR_CANT_FIND_ITEM
, pCreature
, item
, 0);
17068 VendorItem
const* crItem
= vItems
->m_items
[vendor_slot
];
17070 // check current item amount if it limited
17071 if( crItem
->maxcount
!= 0 )
17073 if(pCreature
->GetVendorItemCurrentCount(crItem
) < pProto
->BuyCount
* count
)
17075 SendBuyError( BUY_ERR_ITEM_ALREADY_SOLD
, pCreature
, item
, 0);
17080 if( uint32(GetReputationRank(pProto
->RequiredReputationFaction
)) < pProto
->RequiredReputationRank
)
17082 SendBuyError( BUY_ERR_REPUTATION_REQUIRE
, pCreature
, item
, 0);
17086 if(crItem
->ExtendedCost
)
17088 ItemExtendedCostEntry
const* iece
= sItemExtendedCostStore
.LookupEntry(crItem
->ExtendedCost
);
17091 sLog
.outError("Item %u have wrong ExtendedCost field value %u", pProto
->ItemId
, crItem
->ExtendedCost
);
17095 // honor points price
17096 if(GetHonorPoints() < (iece
->reqhonorpoints
* count
))
17098 SendEquipError(EQUIP_ERR_NOT_ENOUGH_HONOR_POINTS
, NULL
, NULL
);
17102 // arena points price
17103 if(GetArenaPoints() < (iece
->reqarenapoints
* count
))
17105 SendEquipError(EQUIP_ERR_NOT_ENOUGH_ARENA_POINTS
, NULL
, NULL
);
17110 for (uint8 i
= 0; i
< 5; ++i
)
17112 if(iece
->reqitem
[i
] && !HasItemCount(iece
->reqitem
[i
], (iece
->reqitemcount
[i
] * count
)))
17114 SendEquipError(EQUIP_ERR_VENDOR_MISSING_TURNINS
, NULL
, NULL
);
17119 // check for personal arena rating requirement
17120 if( GetMaxPersonalArenaRatingRequirement() < iece
->reqpersonalarenarating
)
17122 // probably not the proper equip err
17123 SendEquipError(EQUIP_ERR_CANT_EQUIP_RANK
,NULL
,NULL
);
17128 uint32 price
= pProto
->BuyPrice
* count
;
17130 // reputation discount
17131 price
= uint32(floor(price
* GetReputationPriceDiscount(pCreature
)));
17133 if( GetMoney() < price
)
17135 SendBuyError( BUY_ERR_NOT_ENOUGHT_MONEY
, pCreature
, item
, 0);
17139 uint8 bag
= 0; // init for case invalid bagGUID
17141 if (bagguid
!= NULL_BAG
&& slot
!= NULL_SLOT
)
17144 if( bagguid
== GetGUID() )
17146 bag
= INVENTORY_SLOT_BAG_0
;
17150 for (int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
;i
++)
17152 pBag
= (Bag
*)GetItemByPos(INVENTORY_SLOT_BAG_0
,i
);
17155 if( bagguid
== pBag
->GetGUID() )
17165 if( IsInventoryPos( bag
, slot
) || (bagguid
== NULL_BAG
&& slot
== NULL_SLOT
) )
17167 ItemPosCountVec dest
;
17168 uint8 msg
= CanStoreNewItem( bag
, slot
, dest
, item
, pProto
->BuyCount
* count
);
17169 if( msg
!= EQUIP_ERR_OK
)
17171 SendEquipError( msg
, NULL
, NULL
);
17175 ModifyMoney( -(int32
)price
);
17176 if(crItem
->ExtendedCost
) // case for new honor system
17178 ItemExtendedCostEntry
const* iece
= sItemExtendedCostStore
.LookupEntry(crItem
->ExtendedCost
);
17179 if(iece
->reqhonorpoints
)
17180 ModifyHonorPoints( - int32(iece
->reqhonorpoints
* count
));
17181 if(iece
->reqarenapoints
)
17182 ModifyArenaPoints( - int32(iece
->reqarenapoints
* count
));
17183 for (uint8 i
= 0; i
< 5; ++i
)
17185 if(iece
->reqitem
[i
])
17186 DestroyItemCount(iece
->reqitem
[i
], (iece
->reqitemcount
[i
] * count
), true);
17190 if(Item
*it
= StoreNewItem( dest
, item
, true ))
17192 uint32 new_count
= pCreature
->UpdateVendorItemCurrentCount(crItem
,pProto
->BuyCount
* count
);
17194 WorldPacket
data(SMSG_BUY_ITEM
, (8+4+4+4));
17195 data
<< pCreature
->GetGUID();
17196 data
<< (uint32
)(vendor_slot
+1); // numbered from 1 at client
17197 data
<< (uint32
)(crItem
->maxcount
> 0 ? new_count
: 0xFFFFFFFF);
17198 data
<< (uint32
)count
;
17199 GetSession()->SendPacket(&data
);
17201 SendNewItem(it
, pProto
->BuyCount
*count
, true, false, false);
17204 else if( IsEquipmentPos( bag
, slot
) )
17206 if(pProto
->BuyCount
* count
!= 1)
17208 SendEquipError( EQUIP_ERR_ITEM_CANT_BE_EQUIPPED
, NULL
, NULL
);
17213 uint8 msg
= CanEquipNewItem( slot
, dest
, item
, false );
17214 if( msg
!= EQUIP_ERR_OK
)
17216 SendEquipError( msg
, NULL
, NULL
);
17220 ModifyMoney( -(int32
)price
);
17221 if(crItem
->ExtendedCost
) // case for new honor system
17223 ItemExtendedCostEntry
const* iece
= sItemExtendedCostStore
.LookupEntry(crItem
->ExtendedCost
);
17224 if(iece
->reqhonorpoints
)
17225 ModifyHonorPoints( - int32(iece
->reqhonorpoints
));
17226 if(iece
->reqarenapoints
)
17227 ModifyArenaPoints( - int32(iece
->reqarenapoints
));
17228 for (uint8 i
= 0; i
< 5; ++i
)
17230 if(iece
->reqitem
[i
])
17231 DestroyItemCount(iece
->reqitem
[i
], iece
->reqitemcount
[i
], true);
17235 if(Item
*it
= EquipNewItem( dest
, item
, true ))
17237 uint32 new_count
= pCreature
->UpdateVendorItemCurrentCount(crItem
,pProto
->BuyCount
* count
);
17239 WorldPacket
data(SMSG_BUY_ITEM
, (8+4+4+4));
17240 data
<< pCreature
->GetGUID();
17241 data
<< (uint32
)(vendor_slot
+1); // numbered from 1 at client
17242 data
<< (uint32
)(crItem
->maxcount
> 0 ? new_count
: 0xFFFFFFFF);
17243 data
<< (uint32
)count
;
17244 GetSession()->SendPacket(&data
);
17246 SendNewItem(it
, pProto
->BuyCount
*count
, true, false, false);
17248 AutoUnequipOffhandIfNeed();
17253 SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT
, NULL
, NULL
);
17257 return crItem
->maxcount
!=0;
17260 uint32
Player::GetMaxPersonalArenaRatingRequirement()
17262 // returns the maximal personal arena rating that can be used to purchase items requiring this condition
17263 // the personal rating of the arena team must match the required limit as well
17264 // so return max[in arenateams](min(personalrating[teamtype], teamrating[teamtype]))
17265 uint32 max_personal_rating
= 0;
17266 for(int i
= 0; i
< MAX_ARENA_SLOT
; ++i
)
17268 if(ArenaTeam
* at
= objmgr
.GetArenaTeamById(GetArenaTeamId(i
)))
17270 uint32 p_rating
= GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ (i
* 6) + 5);
17271 uint32 t_rating
= at
->GetRating();
17272 p_rating
= p_rating
<t_rating
? p_rating
: t_rating
;
17273 if(max_personal_rating
< p_rating
)
17274 max_personal_rating
= p_rating
;
17277 return max_personal_rating
;
17280 void Player::UpdateHomebindTime(uint32 time
)
17282 // GMs never get homebind timer online
17283 if (m_InstanceValid
|| isGameMaster())
17285 if(m_HomebindTimer
) // instance valid, but timer not reset
17288 WorldPacket
data(SMSG_RAID_GROUP_ONLY
, 4+4);
17291 GetSession()->SendPacket(&data
);
17293 // instance is valid, reset homebind timer
17294 m_HomebindTimer
= 0;
17296 else if (m_HomebindTimer
> 0)
17298 if (time
>= m_HomebindTimer
)
17300 // teleport to homebind location
17301 TeleportTo(m_homebindMapId
, m_homebindX
, m_homebindY
, m_homebindZ
, GetOrientation());
17304 m_HomebindTimer
-= time
;
17308 // instance is invalid, start homebind timer
17309 m_HomebindTimer
= 60000;
17310 // send message to player
17311 WorldPacket
data(SMSG_RAID_GROUP_ONLY
, 4+4);
17312 data
<< m_HomebindTimer
;
17314 GetSession()->SendPacket(&data
);
17315 sLog
.outDebug("PLAYER: Player '%s' (GUID: %u) will be teleported to homebind in 60 seconds", GetName(),GetGUIDLow());
17319 void Player::UpdatePvP(bool state
, bool ovrride
)
17321 if(!state
|| ovrride
)
17324 if(Pet
* pet
= GetPet())
17325 pet
->SetPvP(state
);
17326 if(Unit
* charmed
= GetCharm())
17327 charmed
->SetPvP(state
);
17329 pvpInfo
.endTimer
= 0;
17333 if(pvpInfo
.endTimer
!= 0)
17334 pvpInfo
.endTimer
= time(NULL
);
17339 if(Pet
* pet
= GetPet())
17340 pet
->SetPvP(state
);
17341 if(Unit
* charmed
= GetCharm())
17342 charmed
->SetPvP(state
);
17347 void Player::AddSpellCooldown(uint32 spellid
, uint32 itemid
, time_t end_time
)
17351 sc
.itemid
= itemid
;
17352 m_spellCooldowns
[spellid
] = sc
;
17355 void Player::SendCooldownEvent(SpellEntry
const *spellInfo
)
17357 if ( !(spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
) )
17360 // Get spell cooldown
17361 int32 cooldown
= GetSpellRecoveryTime(spellInfo
);
17363 ApplySpellMod(spellInfo
->Id
, SPELLMOD_COOLDOWN
, cooldown
);
17367 AddSpellCooldown(spellInfo
->Id
, 0, time(NULL
) + cooldown
/ 1000);
17369 WorldPacket
data(SMSG_COOLDOWN_EVENT
, (4+8));
17370 data
<< spellInfo
->Id
;
17372 SendDirectMessage(&data
);
17374 //slot to be excluded while counting
17375 bool Player::EnchantmentFitsRequirements(uint32 enchantmentcondition
, int8 slot
)
17377 if(!enchantmentcondition
)
17380 SpellItemEnchantmentConditionEntry
const *Condition
= sSpellItemEnchantmentConditionStore
.LookupEntry(enchantmentcondition
);
17385 uint8 curcount
[4] = {0, 0, 0, 0};
17387 //counting current equipped gem colors
17388 for(uint8 i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; ++i
)
17392 Item
*pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
17393 if(pItem2
&& pItem2
->GetProto()->Socket
[0].Color
)
17395 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
17397 uint32 enchant_id
= pItem2
->GetEnchantmentId(EnchantmentSlot(enchant_slot
));
17401 SpellItemEnchantmentEntry
const* enchantEntry
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
17405 uint32 gemid
= enchantEntry
->GemID
;
17409 ItemPrototype
const* gemProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(gemid
);
17413 GemPropertiesEntry
const* gemProperty
= sGemPropertiesStore
.LookupEntry(gemProto
->GemProperties
);
17417 uint8 GemColor
= gemProperty
->color
;
17419 for(uint8 b
= 0, tmpcolormask
= 1; b
< 4; b
++, tmpcolormask
<<= 1)
17421 if(tmpcolormask
& GemColor
)
17428 bool activate
= true;
17430 for(int i
= 0; i
< 5; i
++)
17432 if(!Condition
->Color
[i
])
17435 uint32 _cur_gem
= curcount
[Condition
->Color
[i
] - 1];
17437 // if have <CompareColor> use them as count, else use <value> from Condition
17438 uint32 _cmp_gem
= Condition
->CompareColor
[i
] ? curcount
[Condition
->CompareColor
[i
] - 1]: Condition
->Value
[i
];
17440 switch(Condition
->Comparator
[i
])
17442 case 2: // requires less <color> than (<value> || <comparecolor>) gems
17443 activate
&= (_cur_gem
< _cmp_gem
) ? true : false;
17445 case 3: // requires more <color> than (<value> || <comparecolor>) gems
17446 activate
&= (_cur_gem
> _cmp_gem
) ? true : false;
17448 case 5: // requires at least <color> than (<value> || <comparecolor>) gems
17449 activate
&= (_cur_gem
>= _cmp_gem
) ? true : false;
17454 sLog
.outDebug("Checking Condition %u, there are %u Meta Gems, %u Red Gems, %u Yellow Gems and %u Blue Gems, Activate:%s", enchantmentcondition
, curcount
[0], curcount
[1], curcount
[2], curcount
[3], activate
? "yes" : "no");
17459 void Player::CorrectMetaGemEnchants(uint8 exceptslot
, bool apply
)
17461 //cycle all equipped items
17462 for(uint32 slot
= EQUIPMENT_SLOT_START
; slot
< EQUIPMENT_SLOT_END
; ++slot
)
17464 //enchants for the slot being socketed are handled by Player::ApplyItemMods
17465 if(slot
== exceptslot
)
17468 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, slot
);
17470 if(!pItem
|| !pItem
->GetProto()->Socket
[0].Color
)
17473 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
17475 uint32 enchant_id
= pItem
->GetEnchantmentId(EnchantmentSlot(enchant_slot
));
17479 SpellItemEnchantmentEntry
const* enchantEntry
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
17483 uint32 condition
= enchantEntry
->EnchantmentCondition
;
17486 //was enchant active with/without item?
17487 bool wasactive
= EnchantmentFitsRequirements(condition
, apply
? exceptslot
: -1);
17488 //should it now be?
17489 if(wasactive
^ EnchantmentFitsRequirements(condition
, apply
? -1 : exceptslot
))
17491 // ignore item gem conditions
17492 //if state changed, (dis)apply enchant
17493 ApplyEnchantment(pItem
,EnchantmentSlot(enchant_slot
),!wasactive
,true,true);
17500 //if false -> then toggled off if was on| if true -> toggled on if was off AND meets requirements
17501 void Player::ToggleMetaGemsActive(uint8 exceptslot
, bool apply
)
17503 //cycle all equipped items
17504 for(int slot
= EQUIPMENT_SLOT_START
; slot
< EQUIPMENT_SLOT_END
; ++slot
)
17506 //enchants for the slot being socketed are handled by WorldSession::HandleSocketOpcode(WorldPacket& recv_data)
17507 if(slot
== exceptslot
)
17510 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, slot
);
17512 if(!pItem
|| !pItem
->GetProto()->Socket
[0].Color
) //if item has no sockets or no item is equipped go to next item
17515 //cycle all (gem)enchants
17516 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
17518 uint32 enchant_id
= pItem
->GetEnchantmentId(EnchantmentSlot(enchant_slot
));
17519 if(!enchant_id
) //if no enchant go to next enchant(slot)
17522 SpellItemEnchantmentEntry
const* enchantEntry
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
17526 //only metagems to be (de)activated, so only enchants with condition
17527 uint32 condition
= enchantEntry
->EnchantmentCondition
;
17529 ApplyEnchantment(pItem
,EnchantmentSlot(enchant_slot
), apply
);
17534 void Player::LeaveBattleground(bool teleportToEntryPoint
)
17536 if(BattleGround
*bg
= GetBattleGround())
17538 bool need_debuf
= bg
->isBattleGround() && (bg
->GetStatus() == STATUS_IN_PROGRESS
) && sWorld
.getConfig(CONFIG_BATTLEGROUND_CAST_DESERTER
);
17540 bg
->RemovePlayerAtLeave(GetGUID(), teleportToEntryPoint
, true);
17542 // call after remove to be sure that player resurrected for correct cast
17544 CastSpell(this, 26013, true); // Deserter
17548 bool Player::CanJoinToBattleground() const
17550 // check Deserter debuff
17551 if(GetDummyAura(26013))
17557 bool Player::CanReportAfkDueToLimit()
17559 // a player can complain about 15 people per 5 minutes
17560 if(m_bgAfkReportedCount
>= 15)
17562 ++m_bgAfkReportedCount
;
17566 ///This player has been blamed to be inactive in a battleground
17567 void Player::ReportedAfkBy(Player
* reporter
)
17569 BattleGround
*bg
= GetBattleGround();
17570 if(!bg
|| bg
!= reporter
->GetBattleGround() || GetTeam() != reporter
->GetTeam())
17573 // check if player has 'Idle' or 'Inactive' debuff
17574 if(m_bgAfkReporter
.find(reporter
->GetGUIDLow())==m_bgAfkReporter
.end() && !HasAura(43680,0) && !HasAura(43681,0) && reporter
->CanReportAfkDueToLimit())
17576 m_bgAfkReporter
.insert(reporter
->GetGUIDLow());
17577 // 3 players have to complain to apply debuff
17578 if(m_bgAfkReporter
.size() >= 3)
17580 // cast 'Idle' spell
17581 CastSpell(this, 43680, true);
17582 m_bgAfkReporter
.clear();
17587 bool Player::IsVisibleInGridForPlayer( Player
* pl
) const
17589 // gamemaster in GM mode see all, including ghosts
17590 if(pl
->isGameMaster() && GetSession()->GetSecurity() <= pl
->GetSession()->GetSecurity())
17593 // It seems in battleground everyone sees everyone, except the enemy-faction ghosts
17594 if (InBattleGround())
17596 if (!(isAlive() || m_deathTimer
> 0) && !IsFriendlyTo(pl
) )
17601 // Live player see live player or dead player with not realized corpse
17602 if(pl
->isAlive() || pl
->m_deathTimer
> 0)
17604 return isAlive() || m_deathTimer
> 0;
17607 // Ghost see other friendly ghosts, that's for sure
17608 if(!(isAlive() || m_deathTimer
> 0) && IsFriendlyTo(pl
))
17611 // Dead player see live players near own corpse
17614 Corpse
*corpse
= pl
->GetCorpse();
17617 // 20 - aggro distance for same level, 25 - max additional distance if player level less that creature level
17618 if(corpse
->IsWithinDistInMap(this,(20+25)*sWorld
.getRate(RATE_CREATURE_AGGRO
)))
17623 // and not see any other
17627 bool Player::IsVisibleGloballyFor( Player
* u
) const
17632 // Always can see self
17636 // Visible units, always are visible for all players
17637 if (GetVisibility() == VISIBILITY_ON
)
17640 // GMs are visible for higher gms (or players are visible for gms)
17641 if (u
->GetSession()->GetSecurity() > SEC_PLAYER
)
17642 return GetSession()->GetSecurity() <= u
->GetSession()->GetSecurity();
17644 // non faction visibility non-breakable for non-GMs
17645 if (GetVisibility() == VISIBILITY_OFF
)
17648 // non-gm stealth/invisibility not hide from global player lists
17652 void Player::UpdateVisibilityOf(WorldObject
* target
)
17654 if(HaveAtClient(target
))
17656 if(!target
->isVisibleForInState(this,true))
17658 target
->DestroyForPlayer(this);
17659 m_clientGUIDs
.erase(target
->GetGUID());
17661 #ifdef MANGOS_DEBUG
17662 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
17663 sLog
.outDebug("Object %u (Type: %u) out of range for player %u. Distance = %f",target
->GetGUIDLow(),target
->GetTypeId(),GetGUIDLow(),GetDistance(target
));
17669 if(target
->isVisibleForInState(this,false))
17671 target
->SendUpdateToPlayer(this);
17672 if(target
->GetTypeId()!=TYPEID_GAMEOBJECT
||!((GameObject
*)target
)->IsTransport())
17673 m_clientGUIDs
.insert(target
->GetGUID());
17675 #ifdef MANGOS_DEBUG
17676 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
17677 sLog
.outDebug("Object %u (Type: %u) is visible now for player %u. Distance = %f",target
->GetGUIDLow(),target
->GetTypeId(),GetGUIDLow(),GetDistance(target
));
17680 // target aura duration for caster show only if target exist at caster client
17681 // send data at target visibility change (adding to client)
17682 if(target
!=this && target
->isType(TYPEMASK_UNIT
))
17683 SendAurasForTarget((Unit
*)target
);
17685 if(target
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)target
)->isAlive())
17686 ((Creature
*)target
)->SendMonsterMoveWithSpeedToCurrentDestination(this);
17692 inline void UpdateVisibilityOf_helper(std::set
<uint64
>& s64
, T
* target
)
17694 s64
.insert(target
->GetGUID());
17698 inline void UpdateVisibilityOf_helper(std::set
<uint64
>& s64
, GameObject
* target
)
17700 if(!target
->IsTransport())
17701 s64
.insert(target
->GetGUID());
17705 void Player::UpdateVisibilityOf(T
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
)
17707 if(HaveAtClient(target
))
17709 if(!target
->isVisibleForInState(this,true))
17711 target
->BuildOutOfRangeUpdateBlock(&data
);
17712 m_clientGUIDs
.erase(target
->GetGUID());
17714 #ifdef MANGOS_DEBUG
17715 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
17716 sLog
.outDebug("Object %u (Type: %u, Entry: %u) is out of range for player %u. Distance = %f",target
->GetGUIDLow(),target
->GetTypeId(),target
->GetEntry(),GetGUIDLow(),GetDistance(target
));
17722 if(target
->isVisibleForInState(this,false))
17724 visibleNow
.insert(target
);
17725 target
->BuildUpdate(data_updates
);
17726 target
->BuildCreateUpdateBlockForPlayer(&data
, this);
17727 UpdateVisibilityOf_helper(m_clientGUIDs
,target
);
17729 #ifdef MANGOS_DEBUG
17730 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
17731 sLog
.outDebug("Object %u (Type: %u, Entry: %u) is visible now for player %u. Distance = %f",target
->GetGUIDLow(),target
->GetTypeId(),target
->GetEntry(),GetGUIDLow(),GetDistance(target
));
17737 template void Player::UpdateVisibilityOf(Player
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17738 template void Player::UpdateVisibilityOf(Creature
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17739 template void Player::UpdateVisibilityOf(Corpse
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17740 template void Player::UpdateVisibilityOf(GameObject
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17741 template void Player::UpdateVisibilityOf(DynamicObject
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17743 void Player::InitPrimaryProffesions()
17745 SetFreePrimaryProffesions(sWorld
.getConfig(CONFIG_MAX_PRIMARY_TRADE_SKILL
));
17748 void Player::SendComboPoints()
17750 Unit
*combotarget
= ObjectAccessor::GetUnit(*this, m_comboTarget
);
17753 WorldPacket
data(SMSG_UPDATE_COMBO_POINTS
, combotarget
->GetPackGUID().size()+1);
17754 data
.append(combotarget
->GetPackGUID());
17755 data
<< uint8(m_comboPoints
);
17756 GetSession()->SendPacket(&data
);
17760 void Player::AddComboPoints(Unit
* target
, int8 count
)
17765 // without combo points lost (duration checked in aura)
17766 RemoveSpellsCausingAura(SPELL_AURA_RETAIN_COMBO_POINTS
);
17768 if(target
->GetGUID() == m_comboTarget
)
17770 m_comboPoints
+= count
;
17775 if(Unit
* target
= ObjectAccessor::GetUnit(*this,m_comboTarget
))
17776 target
->RemoveComboPointHolder(GetGUIDLow());
17778 m_comboTarget
= target
->GetGUID();
17779 m_comboPoints
= count
;
17781 target
->AddComboPointHolder(GetGUIDLow());
17784 if (m_comboPoints
> 5) m_comboPoints
= 5;
17785 if (m_comboPoints
< 0) m_comboPoints
= 0;
17790 void Player::ClearComboPoints()
17795 // without combopoints lost (duration checked in aura)
17796 RemoveSpellsCausingAura(SPELL_AURA_RETAIN_COMBO_POINTS
);
17802 if(Unit
* target
= ObjectAccessor::GetUnit(*this,m_comboTarget
))
17803 target
->RemoveComboPointHolder(GetGUIDLow());
17808 void Player::SetGroup(Group
*group
, int8 subgroup
)
17810 if(group
== NULL
) m_group
.unlink();
17813 // never use SetGroup without a subgroup unless you specify NULL for group
17814 assert(subgroup
>= 0);
17815 m_group
.link(group
, this);
17816 m_group
.setSubGroup((uint8
)subgroup
);
17820 void Player::SendInitialPacketsBeforeAddToMap()
17822 WorldPacket
data(SMSG_SET_REST_START_OBSOLETE
, 4);
17823 data
<< uint32(0); // unknown, may be rest state time or experience
17824 GetSession()->SendPacket(&data
);
17827 data
.Initialize(SMSG_BINDPOINTUPDATE
, 5*4);
17828 data
<< m_homebindX
<< m_homebindY
<< m_homebindZ
;
17829 data
<< (uint32
) m_homebindMapId
;
17830 data
<< (uint32
) m_homebindZoneId
;
17831 GetSession()->SendPacket(&data
);
17833 // SMSG_SET_PROFICIENCY
17834 // SMSG_UPDATE_AURA_DURATION
17837 data
.Initialize(SMSG_TUTORIAL_FLAGS
, 8*4);
17838 for (int i
= 0; i
< 8; ++i
)
17839 data
<< uint32( GetTutorialInt(i
) );
17840 GetSession()->SendPacket(&data
);
17842 SendInitialSpells();
17844 data
.Initialize(SMSG_SEND_UNLEARN_SPELLS
, 4);
17845 data
<< uint32(0); // count, for(count) uint32;
17846 GetSession()->SendPacket(&data
);
17848 SendInitialActionButtons();
17849 SendInitialReputations();
17850 m_achievementMgr
.SendAllAchievementData();
17851 UpdateZone(GetZoneId());
17852 SendInitWorldStates();
17854 // SMSG_SET_AURA_SINGLE
17856 data
.Initialize(SMSG_LOGIN_SETTIMESPEED
, 8);
17857 data
<< uint32(secsToTimeBitFields(sWorld
.GetGameTime()));
17858 data
<< (float)0.01666667f
; // game speed
17859 GetSession()->SendPacket( &data
);
17861 data
.Initialize(SMSG_TIME_SYNC_REQ
, 4); // new 2.0.x, enable movement
17862 data
<< uint32(0x00000000); // on blizz it increments periodically
17863 GetSession()->SendPacket(&data
);
17865 // set fly flag if in fly form or taxi flight to prevent visually drop at ground in showup moment
17866 if(HasAuraType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
) || isInFlight())
17867 AddUnitMovementFlag(MOVEMENTFLAG_FLYING2
);
17872 void Player::SendInitialPacketsAfterAddToMap()
17874 WorldPacket
data(SMSG_TIME_SYNC_REQ
, 4); // new 2.0.x, enable movement
17875 data
<< uint32(0x00000000); // on blizz it increments periodically
17876 GetSession()->SendPacket(&data
);
17878 CastSpell(this, 836, true); // LOGINEFFECT
17880 // set some aura effects that send packet to player client after add player to map
17881 // SendMessageToSet not send it to player not it map, only for aura that not changed anything at re-apply
17882 // same auras state lost at far teleport, send it one more time in this case also
17883 static const AuraType auratypes
[] =
17885 SPELL_AURA_MOD_FEAR
, SPELL_AURA_TRANSFORM
, SPELL_AURA_WATER_WALK
,
17886 SPELL_AURA_FEATHER_FALL
, SPELL_AURA_HOVER
, SPELL_AURA_SAFE_FALL
,
17887 SPELL_AURA_FLY
, SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
, SPELL_AURA_NONE
17889 for(AuraType
const* itr
= &auratypes
[0]; itr
&& itr
[0] != SPELL_AURA_NONE
; ++itr
)
17891 Unit::AuraList
const& auraList
= GetAurasByType(*itr
);
17892 if(!auraList
.empty())
17893 auraList
.front()->ApplyModifier(true,true);
17896 if(HasAuraType(SPELL_AURA_MOD_STUN
))
17897 SetMovement(MOVE_ROOT
);
17899 // manual send package (have code in ApplyModifier(true,true); that don't must be re-applied.
17900 if(HasAuraType(SPELL_AURA_MOD_ROOT
))
17902 WorldPacket
data(SMSG_FORCE_MOVE_ROOT
, 10);
17903 data
.append(GetPackGUID());
17905 SendMessageToSet(&data
,true);
17908 SendAurasForTarget(this);
17909 SendEnchantmentDurations(); // must be after add to map
17910 SendItemDurations(); // must be after add to map
17913 void Player::SendUpdateToOutOfRangeGroupMembers()
17915 if (m_groupUpdateMask
== GROUP_UPDATE_FLAG_NONE
)
17917 if(Group
* group
= GetGroup())
17918 group
->UpdatePlayerOutOfRange(this);
17920 m_groupUpdateMask
= GROUP_UPDATE_FLAG_NONE
;
17921 m_auraUpdateMask
= 0;
17922 if(Pet
*pet
= GetPet())
17923 pet
->ResetAuraUpdateMask();
17926 void Player::SendTransferAborted(uint32 mapid
, uint8 reason
, uint8 arg
)
17928 WorldPacket
data(SMSG_TRANSFER_ABORTED
, 4+2);
17929 data
<< uint32(mapid
);
17930 data
<< uint8(reason
); // transfer abort reason
17933 case TRANSFER_ABORT_INSUF_EXPAN_LVL
:
17934 case TRANSFER_ABORT_DIFFICULTY
:
17935 case TRANSFER_ABORT_UNIQUE_MESSAGE
:
17936 data
<< uint8(arg
);
17939 GetSession()->SendPacket(&data
);
17942 void Player::SendInstanceResetWarning(uint32 mapid
, uint32 time
)
17944 // type of warning, based on the time remaining until reset
17947 type
= RAID_INSTANCE_WELCOME
;
17948 else if(time
> 900 && time
<= 3600)
17949 type
= RAID_INSTANCE_WARNING_HOURS
;
17950 else if(time
> 300 && time
<= 900)
17951 type
= RAID_INSTANCE_WARNING_MIN
;
17953 type
= RAID_INSTANCE_WARNING_MIN_SOON
;
17954 WorldPacket
data(SMSG_RAID_INSTANCE_MESSAGE
, 4+4+4);
17955 data
<< uint32(type
);
17956 data
<< uint32(mapid
);
17957 data
<< uint32(time
);
17958 GetSession()->SendPacket(&data
);
17961 void Player::ApplyEquipCooldown( Item
* pItem
)
17963 for(int i
= 0; i
<5; ++i
)
17965 _Spell
const& spellData
= pItem
->GetProto()->Spells
[i
];
17968 if( !spellData
.SpellId
)
17971 // wrong triggering type (note: ITEM_SPELLTRIGGER_ON_NO_DELAY_USE not have cooldown)
17972 if( spellData
.SpellTrigger
!= ITEM_SPELLTRIGGER_ON_USE
)
17975 AddSpellCooldown(spellData
.SpellId
, pItem
->GetEntry(), time(NULL
) + 30);
17977 WorldPacket
data(SMSG_ITEM_COOLDOWN
, 12);
17978 data
<< pItem
->GetGUID();
17979 data
<< uint32(spellData
.SpellId
);
17980 GetSession()->SendPacket(&data
);
17984 void Player::resetSpells()
17986 // not need after this call
17987 if(HasAtLoginFlag(AT_LOGIN_RESET_SPELLS
))
17989 m_atLoginFlags
= m_atLoginFlags
& ~AT_LOGIN_RESET_SPELLS
;
17990 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login & ~ %u WHERE guid ='%u'", uint32(AT_LOGIN_RESET_SPELLS
), GetGUIDLow());
17993 // make full copy of map (spells removed and marked as deleted at another spell remove
17994 // and we can't use original map for safe iterative with visit each spell at loop end
17995 PlayerSpellMap smap
= GetSpellMap();
17997 for(PlayerSpellMap::const_iterator iter
= smap
.begin();iter
!= smap
.end(); ++iter
)
17998 removeSpell(iter
->first
); // only iter->first can be accessed, object by iter->second can be deleted already
18000 learnDefaultSpells();
18001 learnQuestRewardedSpells();
18004 void Player::learnDefaultSpells()
18006 // learn default race/class spells
18007 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(getRace(),getClass());
18008 for (PlayerCreateInfoSpells::const_iterator itr
= info
->spell
.begin(); itr
!=info
->spell
.end(); ++itr
)
18010 uint32 tspell
= *itr
;
18011 sLog
.outDebug("PLAYER (Class: %u Race: %u): Adding initial spell, id = %u",uint32(getClass()),uint32(getRace()), tspell
);
18012 if(!IsInWorld()) // will send in INITIAL_SPELLS in list anyway at map add
18013 addSpell(tspell
,true,true,false);
18014 else // but send in normal spell in game learn case
18015 learnSpell(tspell
);
18019 void Player::learnQuestRewardedSpells(Quest
const* quest
)
18021 uint32 spell_id
= quest
->GetRewSpellCast();
18023 // skip quests without rewarded spell
18027 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spell_id
);
18031 // check learned spells state
18032 bool found
= false;
18033 for(int i
=0; i
< 3; ++i
)
18035 if(spellInfo
->Effect
[i
] == SPELL_EFFECT_LEARN_SPELL
&& !HasSpell(spellInfo
->EffectTriggerSpell
[i
]))
18042 // skip quests with not teaching spell or already known spell
18046 // prevent learn non first rank unknown profession and second specialization for same profession)
18047 uint32 learned_0
= spellInfo
->EffectTriggerSpell
[0];
18048 if( spellmgr
.GetSpellRank(learned_0
) > 1 && !HasSpell(learned_0
) )
18050 // not have first rank learned (unlearned prof?)
18051 uint32 first_spell
= spellmgr
.GetFirstSpellInChain(learned_0
);
18052 if( !HasSpell(first_spell
) )
18055 SpellEntry
const *learnedInfo
= sSpellStore
.LookupEntry(learned_0
);
18060 if(learnedInfo
->Effect
[0]==SPELL_EFFECT_TRADE_SKILL
&& learnedInfo
->Effect
[1]==0)
18062 // search other specialization for same prof
18063 for(PlayerSpellMap::const_iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
18065 if(itr
->second
->state
== PLAYERSPELL_REMOVED
|| itr
->first
==learned_0
)
18068 SpellEntry
const *itrInfo
= sSpellStore
.LookupEntry(itr
->first
);
18072 // compare only specializations
18073 if(itrInfo
->Effect
[0]!=SPELL_EFFECT_TRADE_SKILL
|| itrInfo
->Effect
[1]!=0)
18076 // compare same chain spells
18077 if(spellmgr
.GetFirstSpellInChain(itr
->first
) != first_spell
)
18080 // now we have 2 specialization, learn possible only if found is lesser specialization rank
18081 if(!spellmgr
.IsHighRankOfSpell(learned_0
,itr
->first
))
18087 CastSpell( this, spell_id
, true);
18090 void Player::learnQuestRewardedSpells()
18092 // learn spells received from quest completing
18093 for(QuestStatusMap::const_iterator itr
= mQuestStatus
.begin(); itr
!= mQuestStatus
.end(); ++itr
)
18095 // skip no rewarded quests
18096 if(!itr
->second
.m_rewarded
)
18099 Quest
const* quest
= objmgr
.GetQuestTemplate(itr
->first
);
18103 learnQuestRewardedSpells(quest
);
18107 void Player::learnSkillRewardedSpells(uint32 skill_id
)
18109 uint32 raceMask
= getRaceMask();
18110 uint32 classMask
= getClassMask();
18111 for (uint32 j
=0; j
<sSkillLineAbilityStore
.GetNumRows(); ++j
)
18113 SkillLineAbilityEntry
const *pAbility
= sSkillLineAbilityStore
.LookupEntry(j
);
18114 if (!pAbility
|| pAbility
->skillId
!=skill_id
|| pAbility
->learnOnGetSkill
!= ABILITY_LEARNED_ON_GET_PROFESSION_SKILL
)
18116 // Check race if set
18117 if (pAbility
->racemask
&& !(pAbility
->racemask
& raceMask
))
18119 // Check class if set
18120 if (pAbility
->classmask
&& !(pAbility
->classmask
& classMask
))
18123 if (sSpellStore
.LookupEntry(pAbility
->spellId
))
18125 // Ok need learn spell
18126 learnSpell(pAbility
->spellId
);
18131 void Player::learnSkillRewardedSpells()
18133 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
18135 if(!GetUInt32Value(PLAYER_SKILL_INDEX(i
)))
18138 uint32 pskill
= GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF;
18140 learnSkillRewardedSpells(pskill
);
18144 void Player::SendAurasForTarget(Unit
*target
)
18146 if(target
->GetVisibleAuras()->empty()) // speedup things
18149 WorldPacket
data(SMSG_AURA_UPDATE_ALL
);
18150 data
.append(target
->GetPackGUID());
18152 Unit::VisibleAuraMap
const *visibleAuras
= target
->GetVisibleAuras();
18153 for(Unit::VisibleAuraMap::const_iterator itr
= visibleAuras
->begin(); itr
!= visibleAuras
->end(); ++itr
)
18155 for(uint32 j
= 0; j
< 3; ++j
)
18157 if(Aura
*aura
= target
->GetAura(itr
->second
, j
))
18159 data
<< uint8(aura
->GetAuraSlot());
18160 data
<< uint32(aura
->GetId());
18164 uint8 auraFlags
= aura
->GetAuraFlags();
18166 data
<< uint8(auraFlags
);
18168 data
<< uint8(aura
->GetAuraLevel());
18170 data
<< uint8(aura
->GetAuraCharges());
18172 if(!(auraFlags
& AFLAG_NOT_CASTER
))
18174 data
<< uint8(0); // packed GUID of someone (caster?)
18177 if(auraFlags
& AFLAG_DURATION
) // include aura duration
18179 data
<< uint32(aura
->GetAuraMaxDuration());
18180 data
<< uint32(aura
->GetAuraDuration());
18188 GetSession()->SendPacket(&data
);
18191 void Player::SetDailyQuestStatus( uint32 quest_id
)
18193 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
18195 if(!GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
))
18197 SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
,quest_id
);
18198 m_lastDailyQuestTime
= time(NULL
); // last daily quest time
18199 m_DailyQuestChanged
= true;
18205 void Player::ResetDailyQuestStatus()
18207 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
18208 SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
,0);
18210 // DB data deleted in caller
18211 m_DailyQuestChanged
= false;
18212 m_lastDailyQuestTime
= 0;
18215 BattleGround
* Player::GetBattleGround() const
18217 if(GetBattleGroundId()==0)
18220 return sBattleGroundMgr
.GetBattleGround(GetBattleGroundId());
18223 bool Player::InArena() const
18225 BattleGround
*bg
= GetBattleGround();
18226 if(!bg
|| !bg
->isArena())
18232 bool Player::GetBGAccessByLevel(uint32 bgTypeId
) const
18234 // get a template bg instead of running one
18235 BattleGround
*bg
= sBattleGroundMgr
.GetBattleGroundTemplate(bgTypeId
);
18239 if(getLevel() < bg
->GetMinLevel() || getLevel() > bg
->GetMaxLevel())
18245 uint32
Player::GetMinLevelForBattleGroundQueueId(uint32 queue_id
)
18253 return 10*(queue_id
+1);
18256 uint32
Player::GetMaxLevelForBattleGroundQueueId(uint32 queue_id
)
18259 return 255; // hardcoded max level
18261 return 10*(queue_id
+2)-1;
18264 uint32
Player::GetBattleGroundQueueIdFromLevel() const
18266 uint32 level
= getLevel();
18269 else if (level
> 79)
18272 return level
/10 - 1; // 20..29 -> 1, 30-39 -> 2, ...
18274 assert(bgTypeId < MAX_BATTLEGROUND_TYPES);
18275 BattleGround *bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId);
18277 return (getLevel() - bg->GetMinLevel()) / 10;*/
18280 float Player::GetReputationPriceDiscount( Creature
const* pCreature
) const
18282 FactionTemplateEntry
const* vendor_faction
= pCreature
->getFactionTemplateEntry();
18283 if(!vendor_faction
)
18286 ReputationRank rank
= GetReputationRank(vendor_faction
->faction
);
18287 if(rank
<= REP_NEUTRAL
)
18290 return 1.0f
- 0.05f
* (rank
- REP_NEUTRAL
);
18293 bool Player::IsSpellFitByClassAndRace( uint32 spell_id
) const
18295 uint32 racemask
= getRaceMask();
18296 uint32 classmask
= getClassMask();
18298 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(spell_id
);
18299 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(spell_id
);
18303 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
18305 // skip wrong race skills
18306 if( _spell_idx
->second
->racemask
&& (_spell_idx
->second
->racemask
& racemask
) == 0)
18309 // skip wrong class skills
18310 if( _spell_idx
->second
->classmask
&& (_spell_idx
->second
->classmask
& classmask
) == 0)
18319 bool Player::HasQuestForGO(int32 GOId
)
18321 for( QuestStatusMap::iterator i
= mQuestStatus
.begin( ); i
!= mQuestStatus
.end( ); ++i
)
18323 QuestStatusData qs
=i
->second
;
18324 if (qs
.m_status
== QUEST_STATUS_INCOMPLETE
)
18326 Quest
const* qinfo
= objmgr
.GetQuestTemplate(i
->first
);
18330 if(GetGroup() && GetGroup()->isRaidGroup() && qinfo
->GetType() != QUEST_TYPE_RAID
)
18333 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
18335 if (qinfo
->ReqCreatureOrGOId
[j
]>=0) //skip non GO case
18338 if((-1)*GOId
== qinfo
->ReqCreatureOrGOId
[j
] && qs
.m_creatureOrGOcount
[j
] < qinfo
->ReqCreatureOrGOCount
[j
])
18346 void Player::UpdateForQuestsGO()
18348 if(m_clientGUIDs
.empty())
18352 WorldPacket packet
;
18353 for(ClientGUIDs::iterator itr
=m_clientGUIDs
.begin(); itr
!=m_clientGUIDs
.end(); ++itr
)
18355 if(IS_GAMEOBJECT_GUID(*itr
))
18357 GameObject
*obj
= HashMapHolder
<GameObject
>::Find(*itr
);
18359 obj
->BuildValuesUpdateBlockForPlayer(&udata
,this);
18362 udata
.BuildPacket(&packet
);
18363 GetSession()->SendPacket(&packet
);
18366 void Player::SummonIfPossible(bool agree
)
18370 m_summon_expire
= 0;
18374 // expire and auto declined
18375 if(m_summon_expire
< time(NULL
))
18378 // stop taxi flight at summon
18381 GetMotionMaster()->MovementExpired();
18382 m_taxi
.ClearTaxiDestinations();
18385 // drop flag at summon
18386 if(BattleGround
*bg
= GetBattleGround())
18387 bg
->EventPlayerDroppedFlag(this);
18389 m_summon_expire
= 0;
18391 TeleportTo(m_summon_mapid
, m_summon_x
, m_summon_y
, m_summon_z
,GetOrientation());
18394 void Player::RemoveItemDurations( Item
*item
)
18396 for(ItemDurationList::iterator itr
= m_itemDuration
.begin();itr
!= m_itemDuration
.end(); ++itr
)
18400 m_itemDuration
.erase(itr
);
18406 void Player::AddItemDurations( Item
*item
)
18408 if(item
->GetUInt32Value(ITEM_FIELD_DURATION
))
18410 m_itemDuration
.push_back(item
);
18411 item
->SendTimeUpdate(this);
18415 void Player::AutoUnequipOffhandIfNeed()
18417 Item
*offItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
18421 // need unequip for 2h-weapon without TitanGrip
18422 if (!IsTwoHandUsed())
18425 ItemPosCountVec off_dest
;
18426 uint8 off_msg
= CanStoreItem( NULL_BAG
, NULL_SLOT
, off_dest
, offItem
, false );
18427 if( off_msg
== EQUIP_ERR_OK
)
18429 RemoveItem(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
, true);
18430 StoreItem( off_dest
, offItem
, true );
18434 sLog
.outError("Player::EquipItem: Can's store offhand item at 2hand item equip for player (GUID: %u).",GetGUIDLow());
18438 bool Player::HasItemFitToSpellReqirements(SpellEntry
const* spellInfo
, Item
const* ignoreItem
)
18440 if(spellInfo
->EquippedItemClass
< 0)
18443 // scan other equipped items for same requirements (mostly 2 daggers/etc)
18444 // for optimize check 2 used cases only
18445 switch(spellInfo
->EquippedItemClass
)
18447 case ITEM_CLASS_WEAPON
:
18449 for(int i
= EQUIPMENT_SLOT_MAINHAND
; i
< EQUIPMENT_SLOT_TABARD
; ++i
)
18450 if(Item
*item
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
18451 if(item
!=ignoreItem
&& item
->IsFitToSpellRequirements(spellInfo
))
18455 case ITEM_CLASS_ARMOR
:
18457 // tabard not have dependent spells
18458 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_MAINHAND
; ++i
)
18459 if(Item
*item
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
18460 if(item
!=ignoreItem
&& item
->IsFitToSpellRequirements(spellInfo
))
18463 // shields can be equipped to offhand slot
18464 if(Item
*item
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
))
18465 if(item
!=ignoreItem
&& item
->IsFitToSpellRequirements(spellInfo
))
18468 // ranged slot can have some armor subclasses
18469 if(Item
*item
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
))
18470 if(item
!=ignoreItem
&& item
->IsFitToSpellRequirements(spellInfo
))
18476 sLog
.outError("HasItemFitToSpellReqirements: Not handled spell requirement for item class %u",spellInfo
->EquippedItemClass
);
18483 bool Player::CanNoReagentCast(SpellEntry
const* spellInfo
) const
18485 // don't take reagents for spells with SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
18486 if (spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
&&
18487 HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PREPARATION
))
18490 // Check no reagent use mask
18491 uint64 noReagentMask_0_1
= GetUInt64Value(PLAYER_NO_REAGENT_COST_1
);
18492 uint32 noReagentMask_2
= GetUInt64Value(PLAYER_NO_REAGENT_COST_1
+2);
18493 if (spellInfo
->SpellFamilyFlags
& noReagentMask_0_1
||
18494 spellInfo
->SpellFamilyFlags2
& noReagentMask_2
)
18500 void Player::RemoveItemDependentAurasAndCasts( Item
* pItem
)
18502 AuraMap
& auras
= GetAuras();
18503 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
18505 Aura
* aura
= itr
->second
;
18507 // skip passive (passive item dependent spells work in another way) and not self applied auras
18508 SpellEntry
const* spellInfo
= aura
->GetSpellProto();
18509 if(aura
->IsPassive() || aura
->GetCasterGUID()!=GetGUID())
18515 // skip if not item dependent or have alternative item
18516 if(HasItemFitToSpellReqirements(spellInfo
,pItem
))
18522 // no alt item, remove aura, restart check
18523 RemoveAurasDueToSpell(aura
->GetId());
18524 itr
= auras
.begin();
18527 // currently casted spells can be dependent from item
18528 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
18530 if( m_currentSpells
[i
] && m_currentSpells
[i
]->getState()!=SPELL_STATE_DELAYED
&&
18531 !HasItemFitToSpellReqirements(m_currentSpells
[i
]->m_spellInfo
,pItem
) )
18536 uint32
Player::GetResurrectionSpellId()
18538 // search priceless resurrection possibilities
18540 uint32 spell_id
= 0;
18541 AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
18542 for(AuraList::const_iterator itr
= dummyAuras
.begin(); itr
!= dummyAuras
.end(); ++itr
)
18544 // Soulstone Resurrection // prio: 3 (max, non death persistent)
18545 if( prio
< 2 && (*itr
)->GetSpellProto()->SpellVisual
[0] == 99 && (*itr
)->GetSpellProto()->SpellIconID
== 92 )
18547 switch((*itr
)->GetId())
18549 case 20707: spell_id
= 3026; break; // rank 1
18550 case 20762: spell_id
= 20758; break; // rank 2
18551 case 20763: spell_id
= 20759; break; // rank 3
18552 case 20764: spell_id
= 20760; break; // rank 4
18553 case 20765: spell_id
= 20761; break; // rank 5
18554 case 27239: spell_id
= 27240; break; // rank 6
18556 sLog
.outError("Unhandled spell %%u: S.Resurrection",(*itr
)->GetId());
18562 // Twisting Nether // prio: 2 (max)
18563 else if((*itr
)->GetId()==23701 && roll_chance_i(10))
18570 // Reincarnation (passive spell) // prio: 1
18571 if(prio
< 1 && HasSpell(20608) && !HasSpellCooldown(21169) && HasItemCount(17030,1))
18577 // Used in triggers for check "Only to targets that grant experience or honor" req
18578 bool Player::isHonorOrXPTarget(Unit
* pVictim
)
18580 uint32 v_level
= pVictim
->getLevel();
18581 uint32 k_grey
= MaNGOS::XP::GetGrayLevel(getLevel());
18583 // Victim level less gray level
18584 if(v_level
<=k_grey
)
18587 if(pVictim
->GetTypeId() == TYPEID_UNIT
)
18589 if (((Creature
*)pVictim
)->isTotem() ||
18590 ((Creature
*)pVictim
)->isPet() ||
18591 ((Creature
*)pVictim
)->GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_NO_XP_AT_KILL
)
18597 bool Player::RewardPlayerAndGroupAtKill(Unit
* pVictim
)
18599 bool PvP
= pVictim
->isCharmedOwnedByPlayerOrPlayer();
18601 // prepare data for near group iteration (PvP and !PvP cases)
18603 bool honored_kill
= false;
18605 if(Group
*pGroup
= GetGroup())
18608 uint32 sum_level
= 0;
18609 Player
* member_with_max_level
= NULL
;
18610 Player
* not_gray_member_with_max_level
= NULL
;
18612 pGroup
->GetDataForXPAtKill(pVictim
,count
,sum_level
,member_with_max_level
,not_gray_member_with_max_level
);
18614 if(member_with_max_level
)
18616 /// not get Xp in PvP or no not gray players in group
18617 xp
= (PvP
|| !not_gray_member_with_max_level
) ? 0 : MaNGOS::XP::Gain(not_gray_member_with_max_level
, pVictim
);
18619 /// skip in check PvP case (for speed, not used)
18620 bool is_raid
= PvP
? false : sMapStore
.LookupEntry(GetMapId())->IsRaid() && pGroup
->isRaidGroup();
18621 bool is_dungeon
= PvP
? false : sMapStore
.LookupEntry(GetMapId())->IsDungeon();
18622 float group_rate
= MaNGOS::XP::xp_in_group_rate(count
,is_raid
);
18624 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
18626 Player
* pGroupGuy
= itr
->getSource();
18630 if(!pGroupGuy
->IsAtGroupRewardDistance(pVictim
))
18631 continue; // member (alive or dead) or his corpse at req. distance
18633 // honor can be in PvP and !PvP (racial leader) cases (for alive)
18634 if(pGroupGuy
->isAlive() && pGroupGuy
->RewardHonor(pVictim
,count
) && pGroupGuy
==this)
18635 honored_kill
= true;
18637 // xp and reputation only in !PvP case
18640 float rate
= group_rate
* float(pGroupGuy
->getLevel()) / sum_level
;
18642 // if is in dungeon then all receive full reputation at kill
18643 // rewarded any alive/dead/near_corpse group member
18644 pGroupGuy
->RewardReputation(pVictim
,is_dungeon
? 1.0f
: rate
);
18646 // XP updated only for alive group member
18647 if(pGroupGuy
->isAlive() && not_gray_member_with_max_level
&&
18648 pGroupGuy
->getLevel() <= not_gray_member_with_max_level
->getLevel())
18650 uint32 itr_xp
= (member_with_max_level
== not_gray_member_with_max_level
) ? uint32(xp
*rate
) : uint32((xp
*rate
/2)+1);
18652 pGroupGuy
->GiveXP(itr_xp
, pVictim
);
18653 if(Pet
* pet
= pGroupGuy
->GetPet())
18654 pet
->GivePetXP(itr_xp
/2);
18657 // quest objectives updated only for alive group member or dead but with not released body
18658 if(pGroupGuy
->isAlive()|| !pGroupGuy
->GetCorpse())
18660 // normal creature (not pet/etc) can be only in !PvP case
18661 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
18662 pGroupGuy
->KilledMonster(pVictim
->GetEntry(), pVictim
->GetGUID());
18668 else // if (!pGroup)
18670 xp
= PvP
? 0 : MaNGOS::XP::Gain(this, pVictim
);
18672 // honor can be in PvP and !PvP (racial leader) cases
18673 if(RewardHonor(pVictim
,1))
18674 honored_kill
= true;
18676 // xp and reputation only in !PvP case
18679 RewardReputation(pVictim
,1);
18680 GiveXP(xp
, pVictim
);
18682 if(Pet
* pet
= GetPet())
18683 pet
->GivePetXP(xp
);
18685 // normal creature (not pet/etc) can be only in !PvP case
18686 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
18687 KilledMonster(pVictim
->GetEntry(),pVictim
->GetGUID());
18690 return xp
|| honored_kill
;
18693 bool Player::IsAtGroupRewardDistance(WorldObject
const* pRewardSource
) const
18695 if(pRewardSource
->GetDistance(this) <= sWorld
.getConfig(CONFIG_GROUP_XP_DISTANCE
))
18701 Corpse
* corpse
= GetCorpse();
18705 return pRewardSource
->GetDistance(corpse
) <= sWorld
.getConfig(CONFIG_GROUP_XP_DISTANCE
);
18708 uint32
Player::GetBaseWeaponSkillValue (WeaponAttackType attType
) const
18710 Item
* item
= GetWeaponForAttack(attType
,true);
18712 // unarmed only with base attack
18713 if(attType
!= BASE_ATTACK
&& !item
)
18716 // weapon skill or (unarmed for base attack)
18717 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
18718 return GetBaseSkillValue(skill
);
18721 void Player::ResurectUsingRequestData()
18723 /// Teleport before resurrecting, otherwise the player might get attacked from creatures near his corpse
18724 TeleportTo(m_resurrectMap
, m_resurrectX
, m_resurrectY
, m_resurrectZ
, GetOrientation());
18726 ResurrectPlayer(0.0f
,false);
18728 if(GetMaxHealth() > m_resurrectHealth
)
18729 SetHealth( m_resurrectHealth
);
18731 SetHealth( GetMaxHealth() );
18733 if(GetMaxPower(POWER_MANA
) > m_resurrectMana
)
18734 SetPower(POWER_MANA
, m_resurrectMana
);
18736 SetPower(POWER_MANA
, GetMaxPower(POWER_MANA
) );
18738 SetPower(POWER_RAGE
, 0 );
18740 SetPower(POWER_ENERGY
, GetMaxPower(POWER_ENERGY
) );
18742 SpawnCorpseBones();
18745 void Player::SetClientControl(Unit
* target
, uint8 allowMove
)
18747 WorldPacket
data(SMSG_CLIENT_CONTROL_UPDATE
, target
->GetPackGUID().size()+1);
18748 data
.append(target
->GetPackGUID());
18749 data
<< uint8(allowMove
);
18750 GetSession()->SendPacket(&data
);
18753 void Player::UpdateZoneDependentAuras( uint32 newZone
)
18755 // remove new continent flight forms
18756 uint32 v_map
= GetVirtualMapForMapAndZone(GetMapId(), newZone
);
18757 if( !isGameMaster() && v_map
!= 530 && v_map
!= 571)
18759 RemoveSpellsCausingAura(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
);
18760 RemoveSpellsCausingAura(SPELL_AURA_FLY
);
18763 // Some spells applied at enter into zone (with subzones)
18765 // NOTE: these are removed by RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_CHANGE_MAP);
18766 if ( newZone
== 2367 ) // Old Hillsbrad Foothills
18768 uint32 spellid
= 0;
18770 if( GetTeam() == HORDE
)
18771 spellid
= getGender() == GENDER_FEMALE
? 35481 : 35480;
18772 // and some alliance races
18773 else if( getRace() == RACE_NIGHTELF
|| getRace() == RACE_DRAENEI
)
18774 spellid
= getGender() == GENDER_FEMALE
? 35483 : 35482;
18776 if(spellid
&& !HasAura(spellid
,0) )
18777 CastSpell(this,spellid
,true);
18781 void Player::UpdateAreaDependentAuras( uint32 newArea
)
18783 // remove auras from spells with area limitations
18784 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
18786 // use m_zoneUpdateId for speed: UpdateArea called from UpdateZone or instead UpdateZone in both cases m_zoneUpdateId up-to-date
18787 if(GetSpellAllowedInLocationError(iter
->second
->GetSpellProto(),GetMapId(),m_zoneUpdateId
,newArea
)!=0)
18793 // some auras applied at subzone enter
18796 // Dragonmaw Illusion
18797 case 3759: // Netherwing Ledge
18798 case 3939: // Dragonmaw Fortress
18799 case 3966: // Dragonmaw Base Camp
18800 if( GetDummyAura(40214) )
18802 if( !HasAura(40216,0) )
18803 CastSpell(this,40216,true);
18804 if( !HasAura(42016,0) )
18805 CastSpell(this,42016,true);
18808 // Dominion Over Acherus
18809 case 4281: // Acherus: The Ebon Hold
18810 case 4342: // Acherus: The Ebon Hold
18811 if( HasSpell(51721) )
18812 if( !HasAura(51721,0) )
18813 CastSpell(this,51721,true);
18818 uint32
Player::GetCorpseReclaimDelay(bool pvp
) const
18820 if( pvp
&& !sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVP
) ||
18821 !pvp
&& !sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE
) )
18823 return copseReclaimDelay
[0];
18826 time_t now
= time(NULL
);
18827 // 0..2 full period
18828 uint32 count
= (now
< m_deathExpireTime
) ? (m_deathExpireTime
- now
)/DEATH_EXPIRE_STEP
: 0;
18829 return copseReclaimDelay
[count
];
18832 void Player::UpdateCorpseReclaimDelay()
18834 bool pvp
= m_ExtraFlags
& PLAYER_EXTRA_PVP_DEATH
;
18836 if( pvp
&& !sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVP
) ||
18837 !pvp
&& !sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE
) )
18840 time_t now
= time(NULL
);
18841 if(now
< m_deathExpireTime
)
18843 // full and partly periods 1..3
18844 uint32 count
= (m_deathExpireTime
- now
)/DEATH_EXPIRE_STEP
+1;
18845 if(count
< MAX_DEATH_COUNT
)
18846 m_deathExpireTime
= now
+(count
+1)*DEATH_EXPIRE_STEP
;
18848 m_deathExpireTime
= now
+MAX_DEATH_COUNT
*DEATH_EXPIRE_STEP
;
18851 m_deathExpireTime
= now
+DEATH_EXPIRE_STEP
;
18854 void Player::SendCorpseReclaimDelay(bool load
)
18856 Corpse
* corpse
= GetCorpse();
18863 if(corpse
->GetGhostTime() > m_deathExpireTime
)
18866 bool pvp
= corpse
->GetType()==CORPSE_RESURRECTABLE_PVP
;
18869 if( pvp
&& sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVP
) ||
18870 !pvp
&& sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE
) )
18872 count
= (m_deathExpireTime
-corpse
->GetGhostTime())/DEATH_EXPIRE_STEP
;
18873 if(count
>=MAX_DEATH_COUNT
)
18874 count
= MAX_DEATH_COUNT
-1;
18879 time_t expected_time
= corpse
->GetGhostTime()+copseReclaimDelay
[count
];
18881 time_t now
= time(NULL
);
18882 if(now
>= expected_time
)
18885 delay
= expected_time
-now
;
18888 delay
= GetCorpseReclaimDelay(corpse
->GetType()==CORPSE_RESURRECTABLE_PVP
);
18890 //! corpse reclaim delay 30 * 1000ms or longer at often deaths
18891 WorldPacket
data(SMSG_CORPSE_RECLAIM_DELAY
, 4);
18892 data
<< uint32(delay
*1000);
18893 GetSession()->SendPacket( &data
);
18896 Player
* Player::GetNextRandomRaidMember(float radius
)
18898 Group
*pGroup
= GetGroup();
18902 std::vector
<Player
*> nearMembers
;
18903 nearMembers
.reserve(pGroup
->GetMembersCount());
18905 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
18907 Player
* Target
= itr
->getSource();
18909 // IsHostileTo check duel and controlled by enemy
18910 if( Target
&& Target
!= this && IsWithinDistInMap(Target
, radius
) &&
18911 !Target
->HasInvisibilityAura() && !IsHostileTo(Target
) )
18912 nearMembers
.push_back(Target
);
18915 if (nearMembers
.empty())
18918 uint32 randTarget
= urand(0,nearMembers
.size()-1);
18919 return nearMembers
[randTarget
];
18922 PartyResult
Player::CanUninviteFromGroup() const
18924 const Group
* grp
= GetGroup();
18926 return PARTY_RESULT_YOU_NOT_IN_GROUP
;
18928 if(!grp
->IsLeader(GetGUID()) && !grp
->IsAssistant(GetGUID()))
18929 return PARTY_RESULT_YOU_NOT_LEADER
;
18931 if(InBattleGround())
18932 return PARTY_RESULT_INVITE_RESTRICTED
;
18934 return PARTY_RESULT_OK
;
18937 void Player::UpdateUnderwaterState( Map
* m
, float x
, float y
, float z
)
18939 float water_z
= m
->GetWaterLevel(x
,y
);
18940 float terrain_z
= m
->GetHeight(x
,y
,z
, false); // use .map base surface height
18941 uint8 flag1
= m
->GetTerrainType(x
,y
);
18943 //!Underwater check, not in water if underground or above water level - take UC royal quater for example
18944 if (terrain_z
<= INVALID_HEIGHT
|| z
< (terrain_z
-2) || z
> (water_z
- 2) )
18945 m_isunderwater
&= ~UNDERWATER_INWATER
;
18946 else if ((z
< (water_z
- 2)) && (flag1
& 0x01))
18947 m_isunderwater
|= UNDERWATER_INWATER
;
18949 //!in lava check, anywhere under lava level
18950 if ((terrain_z
<= INVALID_HEIGHT
|| z
< (terrain_z
- 0)) && (flag1
== 0x00) && IsInWater())
18951 m_isunderwater
|= UNDERWATER_INLAVA
;
18953 m_isunderwater
&= ~UNDERWATER_INLAVA
;
18956 void Player::SetCanParry( bool value
)
18958 if(m_canParry
==value
)
18961 m_canParry
= value
;
18962 UpdateParryPercentage();
18965 void Player::SetCanBlock( bool value
)
18967 if(m_canBlock
==value
)
18970 m_canBlock
= value
;
18971 UpdateBlockPercentage();
18974 bool ItemPosCount::isContainedIn(ItemPosCountVec
const& vec
) const
18976 for(ItemPosCountVec::const_iterator itr
= vec
.begin(); itr
!= vec
.end();++itr
)
18977 if(itr
->pos
== pos
)
18983 bool Player::isAllowUseBattleGroundObject()
18985 return ( //InBattleGround() && // in battleground - not need, check in other cases
18986 !IsMounted() && // not mounted
18987 !HasStealthAura() && // not stealthed
18988 !HasInvisibilityAura() && // not invisible
18989 !HasAura(SPELL_RECENTLY_DROPPED_FLAG
, 0) && // can't pickup
18990 isAlive() // live player
18994 uint32
Player::GetBarberShopCost(uint8 newhairstyle
, uint8 newhaircolor
, uint8 newfacialhair
)
18996 uint32 level
= getLevel();
18998 if(level
> GT_MAX_LEVEL
)
18999 level
= GT_MAX_LEVEL
; // max level in this dbc
19001 uint8 hairstyle
= GetByteValue(PLAYER_BYTES
, 2);
19002 uint8 haircolor
= GetByteValue(PLAYER_BYTES
, 3);
19003 uint8 facialhair
= GetByteValue(PLAYER_BYTES_2
, 0);
19005 if((hairstyle
== newhairstyle
) && (haircolor
== newhaircolor
) && (facialhair
== newfacialhair
))
19008 GtBarberShopCostBaseEntry
const *bsc
= sGtBarberShopCostBaseStore
.LookupEntry(level
- 1);
19010 if(!bsc
) // shouldn't happen
19015 if(hairstyle
!= newhairstyle
)
19016 cost
+= bsc
->cost
; // full price
19018 if((haircolor
!= newhaircolor
) && (hairstyle
== newhairstyle
))
19019 cost
+= bsc
->cost
* 0.5f
; // +1/2 of price
19021 if(facialhair
!= newfacialhair
)
19022 cost
+= bsc
->cost
* 0.75f
; // +3/4 of price
19024 return uint32(cost
);
19027 void Player::InitGlyphsForLevel()
19029 for(uint32 i
= 0; i
< sGlyphSlotStore
.GetNumRows(); ++i
)
19030 if(GlyphSlotEntry
const * gs
= sGlyphSlotStore
.LookupEntry(i
))
19032 SetGlyphSlot(gs
->Order
- 1, gs
->Id
);
19034 uint32 level
= getLevel();
19037 // 0x3F = 0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 for 80 level
19039 value
|= (0x01 | 0x02);
19049 SetUInt32Value(PLAYER_GLYPHS_ENABLED
, value
);
19052 void Player::EnterVehicle(Vehicle
*vehicle
)
19054 VehicleEntry
const *ve
= sVehicleStore
.LookupEntry(vehicle
->GetVehicleId());
19058 VehicleSeatEntry
const *veSeat
= sVehicleSeatStore
.LookupEntry(ve
->m_seatID
[0]);
19062 vehicle
->SetCharmerGUID(GetGUID());
19063 vehicle
->RemoveFlag(UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPELLCLICK
);
19064 vehicle
->SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_24
);
19065 vehicle
->setFaction(getFaction());
19067 SetCharm(vehicle
); // charm
19068 SetFarSight(vehicle
->GetGUID()); // set view
19070 SetClientControl(vehicle
, 1); // redirect controls to vehicle
19072 WorldPacket
data(SMSG_ON_CANCEL_EXPECTED_RIDE_VEHICLE_AURA
, 0);
19073 GetSession()->SendPacket(&data
);
19075 data
.Initialize(MSG_MOVE_TELEPORT_ACK
, 30);
19076 data
.append(GetPackGUID());
19077 data
<< uint32(0); // counter?
19078 data
<< uint32(MOVEMENTFLAG_ONTRANSPORT
); // transport
19079 data
<< uint16(0); // special flags
19080 data
<< uint32(getMSTime()); // time
19081 data
<< vehicle
->GetPositionX(); // x
19082 data
<< vehicle
->GetPositionY(); // y
19083 data
<< vehicle
->GetPositionZ(); // z
19084 data
<< vehicle
->GetOrientation(); // o
19085 // transport part, TODO: load/calculate seat offsets
19086 data
<< uint64(vehicle
->GetGUID()); // transport guid
19087 data
<< float(veSeat
->m_attachmentOffsetX
); // transport offsetX
19088 data
<< float(veSeat
->m_attachmentOffsetY
); // transport offsetY
19089 data
<< float(veSeat
->m_attachmentOffsetZ
); // transport offsetZ
19090 data
<< float(0); // transport orientation
19091 data
<< uint32(getMSTime()); // transport time
19092 data
<< uint8(0); // seat
19093 // end of transport part
19094 data
<< uint32(0); // fall time
19095 GetSession()->SendPacket(&data
);
19097 data
.Initialize(SMSG_PET_SPELLS
, 8+4+4+4+4*10+1+1);
19098 data
<< uint64(vehicle
->GetGUID());
19099 data
<< uint32(0x00000000);
19100 data
<< uint32(0x00000000);
19101 data
<< uint32(0x00000101);
19103 for(uint32 i
= 0; i
< 10; ++i
)
19104 data
<< uint16(0) << uint8(0) << uint8(i
+8);
19108 GetSession()->SendPacket(&data
);
19111 void Player::ExitVehicle(Vehicle
*vehicle
)
19113 vehicle
->SetCharmerGUID(0);
19114 vehicle
->SetFlag(UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPELLCLICK
);
19115 vehicle
->RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNK_24
);
19116 vehicle
->setFaction((GetTeam() == ALLIANCE
) ? vehicle
->GetCreatureInfo()->faction_A
: vehicle
->GetCreatureInfo()->faction_H
);
19121 SetClientControl(vehicle
, 0);
19123 WorldPacket
data(MSG_MOVE_TELEPORT_ACK
, 30);
19124 data
.append(GetPackGUID());
19125 data
<< uint32(0); // counter?
19126 data
<< uint32(MOVEMENTFLAG_FLY_UNK1
); // fly unk
19127 data
<< uint16(0x40); // special flags
19128 data
<< uint32(getMSTime()); // time
19129 data
<< vehicle
->GetPositionX(); // x
19130 data
<< vehicle
->GetPositionY(); // y
19131 data
<< vehicle
->GetPositionZ(); // z
19132 data
<< vehicle
->GetOrientation(); // o
19133 data
<< uint32(0); // fall time
19134 GetSession()->SendPacket(&data
);
19136 data
.Initialize(SMSG_PET_SPELLS
, 8+4);
19139 GetSession()->SendPacket(&data
);
19141 // only for flyable vehicles?
19142 CastSpell(this, 45472, true); // Parachute
19145 bool Player::HasTitle(uint32 bitIndex
)
19147 if (bitIndex
> 128)
19150 uint32 fieldIndexOffset
= bitIndex
/32;
19151 uint32 flag
= 1 << (bitIndex
%32);
19152 return HasFlag(PLAYER__FIELD_KNOWN_TITLES
+fieldIndexOffset
, flag
);
19155 void Player::SetTitle(CharTitlesEntry
const* title
)
19157 uint32 fieldIndexOffset
= title
->bit_index
/32;
19158 uint32 flag
= 1 << (title
->bit_index
%32);
19159 SetFlag(PLAYER__FIELD_KNOWN_TITLES
+fieldIndexOffset
, flag
);
19162 void Player::ConvertRune(uint8 index
, uint8 newType
)
19164 SetCurrentRune(index
, newType
);
19166 WorldPacket
data(SMSG_CONVERT_RUNE
, 2);
19167 data
<< uint8(index
);
19168 data
<< uint8(newType
);
19169 GetSession()->SendPacket(&data
);
19172 void Player::ResyncRunes(uint8 count
)
19174 WorldPacket
data(SMSG_RESYNC_RUNES
, count
* 2);
19175 for(uint32 i
= 0; i
< count
; ++i
)
19177 data
<< uint8(GetCurrentRune(i
)); // rune type
19178 data
<< uint8(255 - (GetRuneCooldown(i
) * 51)); // passed cooldown time (0-255)
19180 GetSession()->SendPacket(&data
);
19183 void Player::AddRunePower(uint8 index
)
19185 WorldPacket
data(SMSG_ADD_RUNE_POWER
, 4);
19186 data
<< uint32(1 << index
); // mask (0x00-0x3F probably)
19187 GetSession()->SendPacket(&data
);
19190 void Player::InitRunes()
19192 if(getClass() != CLASS_DEATH_KNIGHT
)
19195 m_runes
= new Runes
;
19197 m_runes
->runeState
= 0;
19199 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
19201 SetBaseRune(i
, i
/ 2); // init base types
19202 SetCurrentRune(i
, i
/ 2); // init current types
19203 SetRuneCooldown(i
, 0); // reset cooldowns
19204 m_runes
->SetRuneState(i
);
19207 for(uint32 i
= 0; i
< NUM_RUNE_TYPES
; ++i
)
19208 SetFloatValue(PLAYER_RUNE_REGEN_1
+ i
, 0.1f
);