2 * Copyright (C) 2005-2008 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( 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 //== Player ====================================================
252 const int32
Player::ReputationRank_Length
[MAX_REPUTATION_RANK
] = {36000, 3000, 3000, 3000, 6000, 12000, 21000, 1000};
254 UpdateMask
Player::updateVisualBits
;
256 Player::Player (WorldSession
*session
): Unit(), m_achievementMgr(this)
263 m_objectType
|= TYPEMASK_PLAYER
;
264 m_objectTypeId
= TYPEID_PLAYER
;
266 m_valuesCount
= PLAYER_END
;
273 if(GetSession()->GetSecurity() >= SEC_GAMEMASTER
)
274 SetAcceptTicket(true);
276 // players always accept
277 if(GetSession()->GetSecurity() == SEC_PLAYER
)
278 SetAcceptWhispers(true);
286 m_usedTalentCount
= 0;
289 m_weaponChangeTimer
= 0;
292 m_zoneUpdateTimer
= 0;
296 m_nextSave
= sWorld
.getConfig(CONFIG_INTERVAL_SAVE
);
298 // randomize first save time in range [CONFIG_INTERVAL_SAVE] around [CONFIG_INTERVAL_SAVE]
299 // this must help in case next save after mass player load after server startup
300 m_nextSave
= urand(m_nextSave
/2,m_nextSave
*3/2);
302 clearResurrectRequestData();
304 m_SpellModRemoveCount
= 0;
306 memset(m_items
, 0, sizeof(Item
*)*PLAYER_SLOTS_COUNT
);
310 // group is initialized in the reference constructor
311 SetGroupInvite(NULL
);
312 m_groupUpdateMask
= 0;
313 m_auraUpdateMask
= 0;
317 m_GuildIdInvited
= 0;
318 m_ArenaTeamIdInvited
= 0;
320 m_atLoginFlags
= AT_LOGIN_NONE
;
329 PlayerTalkClass
= new PlayerMenu( GetSession() );
330 m_currentBuybackSlot
= BUYBACK_SLOT_START
;
332 for ( int aX
= 0 ; aX
< 8 ; aX
++ )
333 m_Tutorials
[ aX
] = 0x00;
334 m_TutorialsChanged
= false;
336 m_DailyQuestChanged
= false;
337 m_lastDailyQuestTime
= 0;
340 m_weaponChangeTimer
= 0;
348 m_deathExpireTime
= 0;
352 m_DetectInvTimer
= 1000;
354 m_bgBattleGroundID
= 0;
355 for (int j
=0; j
< PLAYER_MAX_BATTLEGROUND_QUEUES
; j
++)
357 m_bgBattleGroundQueueID
[j
].bgType
= 0;
358 m_bgBattleGroundQueueID
[j
].invited
= false;
362 m_logintime
= time(NULL
);
363 m_Last_tick
= m_logintime
;
364 m_WeaponProficiency
= 0;
365 m_ArmorProficiency
= 0;
368 m_canDualWield
= false;
371 m_temporaryUnsummonedPetNumber
= 0;
372 //cache for UNIT_CREATED_BY_SPELL to allow
373 //returning reagents for temporarily removed pets
374 //when dying/logging out
377 ////////////////////Rest System/////////////////////
384 rest_type
=REST_TYPE_NO
;
385 ////////////////////Rest System/////////////////////
387 m_mailsLoaded
= false;
388 m_mailsUpdated
= false;
390 m_nextMailDelivereTime
= 0;
392 m_resetTalentsCost
= 0;
393 m_resetTalentsTime
= 0;
394 m_itemUpdateQueueBlocked
= false;
396 for (int i
= 0; i
< MAX_MOVE_TYPE
; ++i
)
397 m_forced_speed_changes
[i
] = 0;
401 /////////////////// Instance System /////////////////////
404 m_InstanceValid
= true;
405 m_dungeonDifficulty
= DIFFICULTY_NORMAL
;
407 for (int i
= 0; i
< BASEMOD_END
; i
++)
409 m_auraBaseMod
[i
][FLAT_MOD
] = 0.0f
;
410 m_auraBaseMod
[i
][PCT_MOD
] = 1.0f
;
414 m_lastHonorUpdateTime
= time(NULL
);
423 //Default movement to run mode
424 m_unit_movement_flags
= 0;
429 m_bgAfkReportedTimer
= 0;
430 m_contestedPvPTimer
= 0;
432 m_declinedname
= NULL
;
438 CleanupsBeforeDelete();
440 // it must be unloaded already in PlayerLogout and accessed only for loggined player
443 // Note: buy back item already deleted from DB when player was saved
444 for(int i
= 0; i
< PLAYER_SLOTS_COUNT
; ++i
)
451 for (PlayerSpellMap::const_iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
454 //all mailed items should be deleted, also all mail should be deallocated
455 for (PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end();++itr
)
458 for (ItemMap::iterator iter
= mMitems
.begin(); iter
!= mMitems
.end(); ++iter
)
459 delete iter
->second
; //if item is duplicated... then server may crash ... but that item should be deallocated
461 delete PlayerTalkClass
;
465 m_transport
->RemovePassenger(this);
468 for(size_t x
= 0; x
< ItemSetEff
.size(); x
++)
470 delete ItemSetEff
[x
];
472 // clean up player-instance binds, may unload some instance saves
473 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
474 for(BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); ++itr
)
475 itr
->second
.save
->RemovePlayer(this);
477 delete m_declinedname
;
481 void Player::CleanupsBeforeDelete()
483 if(m_uint32Values
) // only for fully created Object
486 DuelComplete(DUEL_INTERUPTED
);
488 Unit::CleanupsBeforeDelete();
491 bool Player::Create( uint32 guidlow
, std::string name
, uint8 race
, uint8 class_
, uint8 gender
, uint8 skin
, uint8 face
, uint8 hairStyle
, uint8 hairColor
, uint8 facialHair
, uint8 outfitId
)
493 //FIXME: outfitId not used in player creating
495 Object::_Create(guidlow
, 0, HIGHGUID_PLAYER
);
499 PlayerInfo
const* info
= objmgr
.GetPlayerInfo(race
, class_
);
502 sLog
.outError("Player have incorrect race/class pair. Can't be loaded.");
506 for (int i
= 0; i
< PLAYER_SLOTS_COUNT
; i
++)
512 SetMapId(info
->mapId
);
513 Relocate(info
->positionX
,info
->positionY
,info
->positionZ
);
515 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(class_
);
518 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",class_
);
522 uint8 powertype
= cEntry
->powerType
;
530 unitfield = 0x00000000;
533 unitfield = 0x00110000;
535 case POWER_RUNIC_POWER:
536 unitfield = 0x0000EE00; //TODO: find correct unitfield here
539 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,class_);
543 SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
544 SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
549 SetDisplayId(info
->displayId_f
);
550 SetNativeDisplayId(info
->displayId_f
);
553 SetDisplayId(info
->displayId_m
);
554 SetNativeDisplayId(info
->displayId_m
);
557 sLog
.outError("Invalid gender %u for player",gender
);
562 setFactionForRace(m_race
);
564 uint32 RaceClassGender
= ( race
) | ( class_
<< 8 ) | ( gender
<< 16 );
566 SetUInt32Value(UNIT_FIELD_BYTES_0
, ( RaceClassGender
| ( powertype
<< 24 ) ) );
567 //SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
568 SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_PVP
);
569 SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
570 SetFloatValue(UNIT_MOD_CAST_SPEED
, 1.0f
); // fix cast time showed in spell tooltip on client
572 // -1 is default value
573 SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
575 SetUInt32Value(PLAYER_BYTES
, (skin
| (face
<< 8) | (hairStyle
<< 16) | (hairColor
<< 24)));
576 SetUInt32Value(PLAYER_BYTES_2
, (facialHair
| (0x00 << 8) | (0x00 << 16) | (0x02 << 24)));
577 SetByteValue(PLAYER_BYTES_3
, 0, gender
);
579 SetUInt32Value( PLAYER_GUILDID
, 0 );
580 SetUInt32Value( PLAYER_GUILDRANK
, 0 );
581 SetUInt32Value( PLAYER_GUILD_TIMESTAMP
, 0 );
583 SetUInt64Value( PLAYER__FIELD_KNOWN_TITLES
, 0 ); // 0=disabled
584 SetUInt64Value( PLAYER__FIELD_KNOWN_TITLES1
, 0 ); // 0=disabled
585 SetUInt32Value( PLAYER_CHOSEN_TITLE
, 0 );
586 SetUInt32Value( PLAYER_FIELD_KILLS
, 0 );
587 SetUInt32Value( PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0 );
588 SetUInt32Value( PLAYER_FIELD_TODAY_CONTRIBUTION
, 0 );
589 SetUInt32Value( PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0 );
591 for(uint32 i
= 0; i
< sGlyphSlotStore
.GetNumRows(); ++i
)
593 GlyphSlotEntry
const * gs
= sGlyphSlotStore
.LookupEntry(i
);
595 SetGlyphSlot(gs
->Order
- 1, gs
->Id
);
598 // set starting level
599 if(getClass() == CLASS_DEATH_KNIGHT
)
600 SetUInt32Value(UNIT_FIELD_LEVEL
, 55);
602 SetUInt32Value( UNIT_FIELD_LEVEL
, sWorld
.getConfig(CONFIG_START_PLAYER_LEVEL
) );
607 m_Last_tick
= time(NULL
);
608 m_Played_time
[0] = 0;
609 m_Played_time
[1] = 0;
611 // base stats and related field values
613 InitTaxiNodesForLevel();
614 InitGlyphsForLevel();
615 InitTalentForLevel();
616 InitPrimaryProffesions(); // to max set before any spell added
618 // apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()
619 UpdateMaxHealth(); // Update max Health (for add bonus from stamina)
620 SetHealth(GetMaxHealth());
621 if (getPowerType()==POWER_MANA
)
623 UpdateMaxPower(POWER_MANA
); // Update max Mana (for add bonus from intellect)
624 SetPower(POWER_MANA
,GetMaxPower(POWER_MANA
));
627 if(getPowerType() == POWER_RUNIC_POWER
)
629 SetPower(POWER_RUNE
, 8);
630 SetMaxPower(POWER_RUNE
, 8);
631 SetPower(POWER_RUNIC_POWER
, 0);
632 SetMaxPower(POWER_RUNIC_POWER
, 1000);
636 learnDefaultSpells(true);
638 // original action bar
639 std::list
<uint16
>::const_iterator action_itr
[4];
640 for(int i
=0; i
<4; i
++)
641 action_itr
[i
] = info
->action
[i
].begin();
643 for (; action_itr
[0]!=info
->action
[0].end() && action_itr
[1]!=info
->action
[1].end();)
646 for(int i
=0; i
<4 ;i
++)
647 taction
[i
] = (*action_itr
[i
]);
649 addActionButton((uint8
)taction
[0], taction
[1], (uint8
)taction
[2], (uint8
)taction
[3]);
651 for(int i
=0; i
<4 ;i
++)
656 CharStartOutfitEntry
const* oEntry
= NULL
;
657 for (uint32 i
= 1; i
< sCharStartOutfitStore
.GetNumRows(); ++i
)
659 if(CharStartOutfitEntry
const* entry
= sCharStartOutfitStore
.LookupEntry(i
))
661 if(entry
->RaceClassGender
== RaceClassGender
)
671 for(int j
= 0; j
< MAX_OUTFIT_ITEMS
; ++j
)
673 if(oEntry
->ItemId
[j
] <= 0)
676 uint32 item_id
= oEntry
->ItemId
[j
];
678 ItemPrototype
const* iProto
= objmgr
.GetItemPrototype(item_id
);
681 sLog
.outErrorDb("Initial item id %u (race %u class %u) from CharStartOutfit.dbc not listed in `item_template`, ignoring.",item_id
,getRace(),getClass());
685 uint32 count
= iProto
->Stackable
; // max stack by default (mostly 1)
686 if(iProto
->Class
==ITEM_CLASS_CONSUMABLE
&& iProto
->SubClass
==ITEM_SUBCLASS_FOOD
)
688 switch(iProto
->Spells
[0].SpellCategory
)
691 if(iProto
->Stackable
> 4)
695 if(iProto
->Stackable
> 2)
701 StoreNewItemInBestSlot(item_id
, count
);
705 for (PlayerCreateInfoItems::const_iterator item_id_itr
= info
->item
.begin(); item_id_itr
!=info
->item
.end(); ++item_id_itr
++)
706 StoreNewItemInBestSlot(item_id_itr
->item_id
, item_id_itr
->item_amount
);
708 // bags and main-hand weapon must equipped at this moment
709 // now second pass for not equipped (offhand weapon/shield if it attempt equipped before main-hand weapon)
710 // or ammo not equipped in special bag
711 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
713 if(Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
716 // equip offhand weapon/shield if it attempt equipped before main-hand weapon
717 uint8 msg
= CanEquipItem( NULL_SLOT
, eDest
, pItem
, false );
718 if( msg
== EQUIP_ERR_OK
)
720 RemoveItem(INVENTORY_SLOT_BAG_0
, i
,true);
721 EquipItem( eDest
, pItem
, true);
723 // move other items to more appropriate slots (ammo not equipped in special bag)
726 ItemPosCountVec sDest
;
727 msg
= CanStoreItem( NULL_BAG
, NULL_SLOT
, sDest
, pItem
, false );
728 if( msg
== EQUIP_ERR_OK
)
730 RemoveItem(INVENTORY_SLOT_BAG_0
, i
,true);
731 pItem
= StoreItem( sDest
, pItem
, true);
734 // if this is ammo then use it
735 uint8 msg
= CanUseAmmo( pItem
->GetProto()->ItemId
);
736 if( msg
== EQUIP_ERR_OK
)
737 SetAmmo( pItem
->GetProto()->ItemId
);
741 // all item positions resolved
746 bool Player::StoreNewItemInBestSlot(uint32 titem_id
, uint32 titem_amount
)
748 sLog
.outDebug("STORAGE: Creating initial item, itemId = %u, count = %u",titem_id
, titem_amount
);
752 uint8 msg
= CanEquipNewItem( NULL_SLOT
, eDest
, titem_id
, titem_amount
, false );
753 if( msg
== EQUIP_ERR_OK
)
755 EquipNewItem( eDest
, titem_id
, titem_amount
, true);
756 AutoUnequipOffhandIfNeed();
757 return true; // equipped
761 ItemPosCountVec sDest
;
762 // store in main bag to simplify second pass (special bags can be not equipped yet at this moment)
763 msg
= CanStoreNewItem( INVENTORY_SLOT_BAG_0
, NULL_SLOT
, sDest
, titem_id
, titem_amount
);
764 if( msg
== EQUIP_ERR_OK
)
766 StoreNewItem( sDest
, titem_id
, true, Item::GenerateItemRandomPropertyId(titem_id
) );
767 return true; // stored
770 // item can't be added
771 sLog
.outError("STORAGE: Can't equip or store initial item %u for race %u class %u , error msg = %u",titem_id
,getRace(),getClass(),msg
);
775 void Player::StartMirrorTimer(MirrorTimerType Type
, uint32 MaxValue
)
777 uint32 BreathRegen
= (uint32
)-1;
779 WorldPacket
data(SMSG_START_MIRROR_TIMER
, (21));
780 data
<< (uint32
)Type
;
785 data
<< (uint32
)0; // spell id
786 GetSession()->SendPacket(&data
);
789 void Player::ModifyMirrorTimer(MirrorTimerType Type
, uint32 MaxValue
, uint32 CurrentValue
, uint32 Regen
)
791 if(Type
==BREATH_TIMER
)
792 m_breathTimer
= ((MaxValue
+ 1000) - CurrentValue
) / Regen
;
794 WorldPacket
data(SMSG_START_MIRROR_TIMER
, (21));
795 data
<< (uint32
)Type
;
796 data
<< CurrentValue
;
800 data
<< (uint32
)0; // spell id
801 GetSession()->SendPacket( &data
);
804 void Player::StopMirrorTimer(MirrorTimerType Type
)
806 if(Type
==BREATH_TIMER
)
809 WorldPacket
data(SMSG_STOP_MIRROR_TIMER
, 4);
810 data
<< (uint32
)Type
;
811 GetSession()->SendPacket( &data
);
814 void Player::EnvironmentalDamage(uint64 guid
, EnviromentalDamage type
, uint32 damage
)
816 WorldPacket
data(SMSG_ENVIRONMENTALDAMAGELOG
, (21));
817 data
<< (uint64
)guid
;
818 data
<< (uint8
)(type
!=DAMAGE_FALL_TO_VOID
? type
: DAMAGE_FALL
);
819 data
<< (uint32
)damage
;
822 SendMessageToSet(&data
, true);
824 DealDamage(this, damage
, NULL
, SELF_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
826 if(type
==DAMAGE_FALL
&& !isAlive()) // DealDamage not apply item durability loss at self damage
828 DEBUG_LOG("We are fall to death, loosing 10 percents durability");
829 DurabilityLossAll(0.10f
,false);
830 // durability lost message
831 WorldPacket
data(SMSG_DURABILITY_DAMAGE_DEATH
, 0);
832 GetSession()->SendPacket(&data
);
836 void Player::HandleDrowning()
841 //if have water breath , then remove bar
842 if(waterbreath
|| isGameMaster() || !isAlive())
844 StopMirrorTimer(BREATH_TIMER
);
849 uint32 UnderWaterTime
= 1*MINUTE
*1000; // default length 1 min
851 AuraList
const& mModWaterBreathing
= GetAurasByType(SPELL_AURA_MOD_WATER_BREATHING
);
852 for(AuraList::const_iterator i
= mModWaterBreathing
.begin(); i
!= mModWaterBreathing
.end(); ++i
)
853 UnderWaterTime
= uint32(UnderWaterTime
* (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
);
855 if ((m_isunderwater
& 0x01) && !(m_isunderwater
& 0x80) && isAlive())
857 //single trigger timer
858 if (!(m_isunderwater
& 0x02))
860 m_isunderwater
|= 0x02;
861 m_breathTimer
= UnderWaterTime
+ 1000;
863 //single trigger "Breathbar"
864 if ( m_breathTimer
<= UnderWaterTime
&& !(m_isunderwater
& 0x04))
866 m_isunderwater
|= 0x04;
867 StartMirrorTimer(BREATH_TIMER
, UnderWaterTime
);
869 //continuous trigger drowning "Damage"
870 if ((m_breathTimer
== 0) && (m_isunderwater
& 0x01))
872 //TODO: Check this formula
873 uint64 guid
= GetGUID();
874 uint32 damage
= GetMaxHealth() / 5 + urand(0, getLevel()-1);
876 EnvironmentalDamage(guid
, DAMAGE_DROWNING
,damage
);
877 m_breathTimer
= 2000;
880 //single trigger retract bar
881 else if (!(m_isunderwater
& 0x01) && !(m_isunderwater
& 0x08) && (m_isunderwater
& 0x02) && (m_breathTimer
> 0) && isAlive())
883 m_isunderwater
= 0x08;
885 uint32 BreathRegen
= 10;
886 ModifyMirrorTimer(BREATH_TIMER
, UnderWaterTime
, m_breathTimer
,BreathRegen
);
887 m_isunderwater
= 0x10;
890 else if ((m_breathTimer
< 50) && !(m_isunderwater
& 0x01) && (m_isunderwater
== 0x10))
892 StopMirrorTimer(BREATH_TIMER
);
897 void Player::HandleLava()
899 bool ValidArea
= false;
901 if ((m_isunderwater
& 0x80) && isAlive())
903 //Single trigger Set BreathTimer
904 if (!(m_isunderwater
& 0x80))
906 m_isunderwater
|= 0x04;
907 m_breathTimer
= 1000;
909 //Reset BreathTimer and still in the lava
912 uint64 guid
= GetGUID();
913 uint32 damage
= urand(600, 700); // TODO: Get more detailed information about lava damage
914 uint32 dmgZone
= GetZoneId(); // TODO: Find correct "lava dealing zone" flag in Area Table
916 // Deal lava damage only in lava zones.
932 if (dmgZone
/ 5 & 0x408)
936 // if is valid area and is not gamemaster then deal damage
937 if ( ValidArea
&& !isGameMaster() )
938 EnvironmentalDamage(guid
, DAMAGE_LAVA
, damage
);
940 m_breathTimer
= 1000;
944 //Death timer disabled and WaterFlags reset
945 else if (m_deathState
== DEAD
)
952 ///The player sobers by 256 every 10 seconds
953 void Player::HandleSobering()
957 uint32 drunk
= (m_drunk
<= 256) ? 0 : (m_drunk
- 256);
958 SetDrunkValue(drunk
);
961 DrunkenState
Player::GetDrunkenstateByValue(uint16 value
)
964 return DRUNKEN_SMASHED
;
966 return DRUNKEN_DRUNK
;
968 return DRUNKEN_TIPSY
;
969 return DRUNKEN_SOBER
;
972 void Player::SetDrunkValue(uint16 newDrunkenValue
, uint32 itemId
)
974 uint32 oldDrunkenState
= Player::GetDrunkenstateByValue(m_drunk
);
976 m_drunk
= newDrunkenValue
;
977 SetUInt32Value(PLAYER_BYTES_3
,(GetUInt32Value(PLAYER_BYTES_3
) & 0xFFFF0001) | (m_drunk
& 0xFFFE));
979 uint32 newDrunkenState
= Player::GetDrunkenstateByValue(m_drunk
);
981 // special drunk invisibility detection
982 if(newDrunkenState
>= DRUNKEN_DRUNK
)
983 m_detectInvisibilityMask
|= (1<<6);
985 m_detectInvisibilityMask
&= ~(1<<6);
987 if(newDrunkenState
== oldDrunkenState
)
990 WorldPacket
data(SMSG_CROSSED_INEBRIATION_THRESHOLD
, (8+4+4));
991 data
<< uint64(GetGUID());
992 data
<< uint32(newDrunkenState
);
993 data
<< uint32(itemId
);
995 SendMessageToSet(&data
, true);
998 void Player::Update( uint32 p_time
)
1004 if(m_nextMailDelivereTime
&& m_nextMailDelivereTime
<= time(NULL
))
1009 // It will be recalculate at mailbox open (for unReadMails important non-0 until mailbox open, it also will be recalculated)
1010 m_nextMailDelivereTime
= 0;
1013 Unit::Update( p_time
);
1015 // update player only attacks
1016 if(uint32 ranged_att
= getAttackTimer(RANGED_ATTACK
))
1018 setAttackTimer(RANGED_ATTACK
, (p_time
>= ranged_att
? 0 : ranged_att
- p_time
) );
1021 if(uint32 off_att
= getAttackTimer(OFF_ATTACK
))
1023 setAttackTimer(OFF_ATTACK
, (p_time
>= off_att
? 0 : off_att
- p_time
) );
1026 time_t now
= time (NULL
);
1030 UpdateContestedPvP(p_time
);
1032 UpdateDuelFlag(now
);
1034 CheckDuelDistance(now
);
1036 UpdateAfkReport(now
);
1038 CheckExploreSystem();
1040 // Update items that have just a limited lifetime
1041 if (now
>m_Last_tick
)
1042 UpdateItemDuration(uint32(now
- m_Last_tick
));
1044 if (!m_timedquests
.empty())
1046 std::set
<uint32
>::iterator iter
= m_timedquests
.begin();
1047 while (iter
!= m_timedquests
.end())
1049 QuestStatusData
& q_status
= mQuestStatus
[*iter
];
1050 if( q_status
.m_timer
<= p_time
)
1052 uint32 quest_id
= *iter
;
1053 ++iter
; // current iter will be removed in FailTimedQuest
1054 FailTimedQuest( quest_id
);
1058 q_status
.m_timer
-= p_time
;
1059 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
1065 if (hasUnitState(UNIT_STAT_MELEE_ATTACKING
))
1067 Unit
*pVictim
= getVictim();
1068 if( !IsNonMeleeSpellCasted(false) && pVictim
)
1070 // default combat reach 10
1071 // TODO add weapon,skill check
1073 float pldistance
= ATTACK_DISTANCE
;
1075 if (isAttackReady(BASE_ATTACK
))
1077 if(!IsWithinDistInMap(pVictim
, pldistance
))
1079 setAttackTimer(BASE_ATTACK
,100);
1080 if(m_swingErrorMsg
!= 1) // send single time (client auto repeat)
1082 SendAttackSwingNotInRange();
1083 m_swingErrorMsg
= 1;
1086 //120 degrees of radiant range
1087 else if( !HasInArc( 2*M_PI
/3, pVictim
))
1089 setAttackTimer(BASE_ATTACK
,100);
1090 if(m_swingErrorMsg
!= 2) // send single time (client auto repeat)
1092 SendAttackSwingBadFacingAttack();
1093 m_swingErrorMsg
= 2;
1098 m_swingErrorMsg
= 0; // reset swing error state
1100 // prevent base and off attack in same time, delay attack at 0.2 sec
1101 if(haveOffhandWeapon())
1103 uint32 off_att
= getAttackTimer(OFF_ATTACK
);
1104 if(off_att
< ATTACK_DISPLAY_DELAY
)
1105 setAttackTimer(OFF_ATTACK
,ATTACK_DISPLAY_DELAY
);
1107 AttackerStateUpdate(pVictim
, BASE_ATTACK
);
1108 resetAttackTimer(BASE_ATTACK
);
1112 if ( haveOffhandWeapon() && isAttackReady(OFF_ATTACK
))
1114 if(!IsWithinDistInMap(pVictim
, pldistance
))
1116 setAttackTimer(OFF_ATTACK
,100);
1118 else if( !HasInArc( 2*M_PI
/3, pVictim
))
1120 setAttackTimer(OFF_ATTACK
,100);
1124 // prevent base and off attack in same time, delay attack at 0.2 sec
1125 uint32 base_att
= getAttackTimer(BASE_ATTACK
);
1126 if(base_att
< ATTACK_DISPLAY_DELAY
)
1127 setAttackTimer(BASE_ATTACK
,ATTACK_DISPLAY_DELAY
);
1129 AttackerStateUpdate(pVictim
, OFF_ATTACK
);
1130 resetAttackTimer(OFF_ATTACK
);
1134 Unit
*owner
= pVictim
->GetOwner();
1135 Unit
*u
= owner
? owner
: pVictim
;
1136 if(u
->IsPvP() && (!duel
|| duel
->opponent
!= u
))
1139 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
1144 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
))
1146 if(roll_chance_i(3) && GetTimeInnEnter() > 0) //freeze update
1148 int time_inn
= time(NULL
)-GetTimeInnEnter();
1149 if (time_inn
>= 10) //freeze update
1151 float bubble
= 0.125*sWorld
.getRate(RATE_REST_INGAME
);
1152 //speed collect rest bonus (section/in hour)
1153 SetRestBonus( GetRestBonus()+ time_inn
*((float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP
)/72000)*bubble
);
1154 UpdateInnerTime(time(NULL
));
1159 if(m_regenTimer
> 0)
1161 if(p_time
>= m_regenTimer
)
1164 m_regenTimer
-= p_time
;
1167 if (m_weaponChangeTimer
> 0)
1169 if(p_time
>= m_weaponChangeTimer
)
1170 m_weaponChangeTimer
= 0;
1172 m_weaponChangeTimer
-= p_time
;
1175 if (m_zoneUpdateTimer
> 0)
1177 if(p_time
>= m_zoneUpdateTimer
)
1179 uint32 newzone
= GetZoneId();
1180 if( m_zoneUpdateId
!= newzone
)
1181 UpdateZone(newzone
); // also update area
1184 // use area updates as well
1185 // needed for free far all arenas for example
1186 uint32 newarea
= GetAreaId();
1187 if( m_areaUpdateId
!= newarea
)
1188 UpdateArea(newarea
);
1190 m_zoneUpdateTimer
= ZONE_UPDATE_INTERVAL
;
1194 m_zoneUpdateTimer
-= p_time
;
1202 if (m_deathState
== JUST_DIED
)
1209 if(p_time
>= m_nextSave
)
1211 // m_nextSave reseted in SaveToDB call
1213 sLog
.outDetail("Player '%s' (GUID: %u) saved", GetName(), GetGUIDLow());
1217 m_nextSave
-= p_time
;
1222 if(m_breathTimer
> 0)
1224 if(p_time
>= m_breathTimer
)
1227 m_breathTimer
-= p_time
;
1231 //Handle Water/drowning
1237 //Handle detect stealth players
1238 if (m_DetectInvTimer
> 0)
1240 if (p_time
>= m_DetectInvTimer
)
1242 m_DetectInvTimer
= 3000;
1243 HandleStealthedUnitsDetection();
1246 m_DetectInvTimer
-= p_time
;
1250 if (now
> m_Last_tick
)
1252 uint32 elapsed
= uint32(now
- m_Last_tick
);
1253 m_Played_time
[0] += elapsed
; // Total played time
1254 m_Played_time
[1] += elapsed
; // Level played time
1260 m_drunkTimer
+= p_time
;
1262 if (m_drunkTimer
> 10000)
1266 // not auto-free ghost from body in instances
1267 if(m_deathTimer
> 0 && !GetBaseMap()->Instanceable())
1269 if(p_time
>= m_deathTimer
)
1276 m_deathTimer
-= p_time
;
1279 UpdateEnchantTime(p_time
);
1280 UpdateHomebindTime(p_time
);
1283 SendUpdateToOutOfRangeGroupMembers();
1285 Pet
* pet
= GetPet();
1286 if(pet
&& !IsWithinDistInMap(pet
, OWNER_MAX_DISTANCE
) && (GetCharmGUID() && (pet
->GetGUID() != GetCharmGUID())))
1288 RemovePet(pet
, PET_SAVE_NOT_IN_SLOT
, true);
1293 void Player::setDeathState(DeathState s
)
1295 uint32 ressSpellId
= 0;
1297 bool cur
= isAlive();
1299 if(s
== JUST_DIED
&& cur
)
1301 // drunken state is cleared on death
1303 // lost combo points at any target (targeted combo points clear in Unit::setDeathState)
1306 clearResurrectRequestData();
1308 // remove form before other mods to prevent incorrect stats calculation
1309 RemoveAurasDueToSpell(m_ShapeShiftFormSpellId
);
1311 //FIXME: is pet dismissed at dying or releasing spirit? if second, add setDeathState(DEAD) to HandleRepopRequestOpcode and define pet unsummon here with (s == DEAD)
1312 RemovePet(NULL
, PET_SAVE_NOT_IN_SLOT
, true);
1314 // remove uncontrolled pets
1318 // save value before aura remove in Unit::setDeathState
1319 ressSpellId
= GetUInt32Value(PLAYER_SELF_RES_SPELL
);
1323 ressSpellId
= GetResurrectionSpellId();
1324 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DEATH_AT_MAP
, 1);
1326 Unit::setDeathState(s
);
1328 // restore resurrection spell id for player after aura remove
1329 if(s
== JUST_DIED
&& cur
&& ressSpellId
)
1330 SetUInt32Value(PLAYER_SELF_RES_SPELL
, ressSpellId
);
1332 if(isAlive() && !cur
)
1334 //clear aura case after resurrection by another way (spells will be applied before next death)
1335 SetUInt32Value(PLAYER_SELF_RES_SPELL
, 0);
1337 // restore default warrior stance
1338 if(getClass()== CLASS_WARRIOR
)
1339 CastSpell(this,SPELL_ID_PASSIVE_BATTLE_STANCE
,true);
1343 void Player::BuildEnumData( QueryResult
* result
, WorldPacket
* p_data
)
1345 *p_data
<< GetGUID();
1348 *p_data
<< getRace();
1349 uint8 pClass
= getClass();
1351 *p_data
<< getGender();
1353 uint32 bytes
= GetUInt32Value(PLAYER_BYTES
);
1354 *p_data
<< uint8(bytes
);
1355 *p_data
<< uint8(bytes
>> 8);
1356 *p_data
<< uint8(bytes
>> 16);
1357 *p_data
<< uint8(bytes
>> 24);
1359 bytes
= GetUInt32Value(PLAYER_BYTES_2
);
1360 *p_data
<< uint8(bytes
);
1362 *p_data
<< uint8(getLevel()); // player level
1363 // do not use GetMap! it will spawn a new instance since the bound instances are not loaded
1364 uint32 zoneId
= MapManager::Instance().GetZoneId(GetMapId(), GetPositionX(),GetPositionY());
1365 sLog
.outDebug("Player::BuildEnumData: m:%u, x:%f, y:%f, z:%f zone:%u", GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ(), zoneId
);
1367 *p_data
<< GetMapId();
1369 *p_data
<< GetPositionX();
1370 *p_data
<< GetPositionY();
1371 *p_data
<< GetPositionZ();
1373 *p_data
<< GetUInt32Value(PLAYER_GUILDID
); // guild id
1375 uint32 char_flags
= 0;
1376 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_HELM
))
1377 char_flags
|= CHARACTER_FLAG_HIDE_HELM
;
1378 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_CLOAK
))
1379 char_flags
|= CHARACTER_FLAG_HIDE_CLOAK
;
1380 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
))
1381 char_flags
|= CHARACTER_FLAG_GHOST
;
1382 if(HasAtLoginFlag(AT_LOGIN_RENAME
))
1383 char_flags
|= CHARACTER_FLAG_RENAME
;
1384 // always send the flag if declined names aren't used
1385 // to let the client select a default method of declining the name
1386 if(!sWorld
.getConfig(CONFIG_DECLINED_NAMES_USED
) || (result
&& result
->Fetch()[13].GetCppString() != ""))
1387 char_flags
|= CHARACTER_FLAG_DECLINED
;
1389 *p_data
<< (uint32
)char_flags
; // character flags
1390 *p_data
<< (uint32
)0; // new wotlk
1391 *p_data
<< (uint8
)1; // unknown
1395 uint32 petDisplayId
= 0;
1396 uint32 petLevel
= 0;
1397 uint32 petFamily
= 0;
1399 // show pet at selection character in character list only for non-ghost character
1400 if(result
&& isAlive() && (pClass
== CLASS_WARLOCK
|| pClass
== CLASS_HUNTER
))
1402 Field
* fields
= result
->Fetch();
1404 uint32 entry
= fields
[10].GetUInt32();
1405 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
>(entry
);
1408 petDisplayId
= fields
[11].GetUInt32();
1409 petLevel
= fields
[12].GetUInt32();
1410 petFamily
= cInfo
->family
;
1414 *p_data
<< (uint32
)petDisplayId
;
1415 *p_data
<< (uint32
)petLevel
;
1416 *p_data
<< (uint32
)petFamily
;
1419 /*ItemPrototype const *items[EQUIPMENT_SLOT_END];
1420 for (int i = 0; i < EQUIPMENT_SLOT_END; i++)
1423 QueryResult *result = CharacterDatabase.PQuery("SELECT slot,item_template FROM character_inventory WHERE guid = '%u' AND bag = 0",GetGUIDLow());
1428 Field *fields = result->Fetch();
1429 uint8 slot = fields[0].GetUInt8() & 255;
1430 uint32 item_id = fields[1].GetUInt32();
1431 if( slot >= EQUIPMENT_SLOT_END )
1434 items[slot] = objmgr.GetItemPrototype(item_id);
1437 sLog.outError( "Player::BuildEnumData: Player %s have unknown item (id: #%u) in inventory, skipped.", GetName(),item_id );
1440 } while (result->NextRow());
1444 for (uint8 slot
= 0; slot
< EQUIPMENT_SLOT_END
; slot
++)
1446 uint32 visualbase
= PLAYER_VISIBLE_ITEM_1_0
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
);
1447 uint32 item_id
= GetUInt32Value(visualbase
);
1448 const ItemPrototype
* proto
= objmgr
.GetItemPrototype(item_id
);
1449 SpellItemEnchantmentEntry
const *enchant
= NULL
;
1451 for(uint8 enchantSlot
= PERM_ENCHANTMENT_SLOT
; enchantSlot
<=TEMP_ENCHANTMENT_SLOT
; enchantSlot
++)
1453 uint32 enchantId
= GetUInt32Value(visualbase
+1+enchantSlot
);
1454 if(enchant
= sSpellItemEnchantmentStore
.LookupEntry(enchantId
))
1460 *p_data
<< (uint32
)proto
->DisplayInfoID
;
1461 *p_data
<< (uint8
)proto
->InventoryType
;
1462 *p_data
<< (uint32
)(enchant
?enchant
->aura_id
:0);
1466 *p_data
<< (uint32
)0;
1467 *p_data
<< (uint8
)0;
1468 *p_data
<< (uint32
)0; // enchant?
1471 *p_data
<< (uint32
)0; // first bag display id
1472 *p_data
<< (uint8
)0; // first bag inventory type
1473 *p_data
<< (uint32
)0; // enchant?
1476 bool Player::ToggleAFK()
1478 ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_AFK
);
1480 bool state
= HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_AFK
);
1482 // afk player not allowed in battleground
1483 if(state
&& InBattleGround())
1484 LeaveBattleground();
1489 bool Player::ToggleDND()
1491 ToggleFlag(PLAYER_FLAGS
, PLAYER_FLAGS_DND
);
1493 return HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_DND
);
1496 uint8
Player::chatTag() const
1513 bool Player::TeleportTo(uint32 mapid
, float x
, float y
, float z
, float orientation
, uint32 options
)
1515 if(!MapManager::IsValidMapCoord(mapid
, x
, y
, z
, orientation
))
1517 sLog
.outError("TeleportTo: invalid map %d or absent instance template.", mapid
);
1521 // preparing unsummon pet if lost (we must get pet before teleportation or will not find it later)
1522 Pet
* pet
= GetPet();
1524 MapEntry
const* mEntry
= sMapStore
.LookupEntry(mapid
);
1526 // don't let enter battlegrounds without assigned battleground id (for example through areatrigger)...
1527 if(!InBattleGround() && mEntry
->IsBattleGround() && !GetSession()->GetSecurity())
1530 // client without expansion support
1531 if(GetSession()->Expansion() < mEntry
->Expansion())
1533 sLog
.outDebug("Player %s using client without required expansion tried teleport to non accessible map %u", GetName(), mapid
);
1536 RepopAtGraveyard(); // teleport to near graveyard if on transport, looks blizz like :)
1538 SendTransferAborted(mapid
, TRANSFER_ABORT_INSUF_EXPAN_LVL
, mEntry
->Expansion());
1540 return false; // normal client can't teleport to this map...
1544 sLog
.outDebug("Player %s will teleported to map %u", GetName(), mapid
);
1547 // if we were on a transport, leave
1548 if (!(options
& TELE_TO_NOT_LEAVE_TRANSPORT
) && m_transport
)
1550 m_transport
->RemovePassenger(this);
1552 m_movementInfo
.t_x
= 0.0f
;
1553 m_movementInfo
.t_y
= 0.0f
;
1554 m_movementInfo
.t_z
= 0.0f
;
1555 m_movementInfo
.t_o
= 0.0f
;
1556 m_movementInfo
.t_time
= 0;
1559 SetSemaphoreTeleport(true);
1561 // The player was ported to another map and looses the duel immediately.
1562 // We have to perform this check before the teleport, otherwise the
1563 // ObjectAccessor won't find the flag.
1564 if (duel
&& GetMapId()!=mapid
)
1566 GameObject
* obj
= ObjectAccessor::GetGameObject(*this, GetUInt64Value(PLAYER_DUEL_ARBITER
));
1568 DuelComplete(DUEL_FLED
);
1571 // reset movement flags at teleport, because player will continue move with these flags after teleport
1572 SetUnitMovementFlags(0);
1574 if ((GetMapId() == mapid
) && (!m_transport
))
1576 // prepare zone change detect
1577 uint32 old_zone
= GetZoneId();
1580 if(!GetSession()->PlayerLogout())
1583 BuildTeleportAckMsg(&data
, x
, y
, z
, orientation
);
1584 GetSession()->SendPacket(&data
);
1585 SetPosition( x
, y
, z
, orientation
, true);
1588 // this will be used instead of the current location in SaveToDB
1589 m_teleport_dest
= WorldLocation(mapid
, x
, y
, z
, orientation
);
1591 //BuildHeartBeatMsg(&data);
1592 //SendMessageToSet(&data, true);
1593 if (!(options
& TELE_TO_NOT_UNSUMMON_PET
))
1595 //same map, only remove pet if out of range
1596 if(pet
&& !IsWithinDistInMap(pet
, OWNER_MAX_DISTANCE
))
1598 if(pet
->isControlled() && !pet
->isTemporarySummoned() )
1599 m_temporaryUnsummonedPetNumber
= pet
->GetCharmInfo()->GetPetNumber();
1601 m_temporaryUnsummonedPetNumber
= 0;
1603 RemovePet(pet
, PET_SAVE_NOT_IN_SLOT
);
1607 if(!(options
& TELE_TO_NOT_LEAVE_COMBAT
))
1610 if (!(options
& TELE_TO_NOT_UNSUMMON_PET
))
1613 if(pet
&& m_temporaryUnsummonedPetNumber
)
1615 Pet
* NewPet
= new Pet
;
1616 if(!NewPet
->LoadPetFromDB(this, 0, m_temporaryUnsummonedPetNumber
, true))
1619 m_temporaryUnsummonedPetNumber
= 0;
1623 if(!GetSession()->PlayerLogout())
1625 // don't reset teleport semaphore while logging out, otherwise m_teleport_dest won't be used in Player::SaveToDB
1626 SetSemaphoreTeleport(false);
1628 UpdateZone(GetZoneId());
1632 if(old_zone
!= GetZoneId())
1635 if(pvpInfo
.inHostileArea
)
1636 CastSpell(this, 2479, true);
1641 // far teleport to another map
1642 Map
* oldmap
= IsInWorld() ? GetMap() : NULL
;
1643 // check if we can enter before stopping combat / removing pet / totems / interrupting spells
1645 // Check enter rights before map getting to avoid creating instance copy for player
1646 // this check not dependent from map instance copy and same for all instance copies of selected map
1647 if (!MapManager::Instance().CanPlayerEnter(mapid
, this))
1649 SetSemaphoreTeleport(false);
1653 // If the map is not created, assume it is possible to enter it.
1654 // It will be created in the WorldPortAck.
1655 Map
*map
= MapManager::Instance().FindMap(mapid
);
1656 if (!map
|| map
->CanEnter(this))
1662 ResetContestedPvP();
1664 // remove player from battleground on far teleport (when changing maps)
1665 if(BattleGround
const* bg
= GetBattleGround())
1667 // Note: at battleground join battleground id set before teleport
1668 // and we already will found "current" battleground
1669 // just need check that this is targeted map or leave
1670 if(bg
->GetMapId() != mapid
)
1671 LeaveBattleground(false); // don't teleport to entry point
1674 // remove pet on map change
1677 //leaving map -> delete pet right away (doing this later will cause problems)
1678 if(pet
->isControlled() && !pet
->isTemporarySummoned())
1679 m_temporaryUnsummonedPetNumber
= pet
->GetCharmInfo()->GetPetNumber();
1681 m_temporaryUnsummonedPetNumber
= 0;
1683 RemovePet(pet
, PET_SAVE_NOT_IN_SLOT
);
1686 // remove all dyn objects
1687 RemoveAllDynObjects();
1689 // stop spellcasting
1690 // not attempt interrupt teleportation spell at caster teleport
1691 if(!(options
& TELE_TO_SPELL
))
1692 if(IsNonMeleeSpellCasted(true))
1693 InterruptNonMeleeSpells(true);
1695 if(!GetSession()->PlayerLogout())
1697 // send transfer packets
1698 WorldPacket
data(SMSG_TRANSFER_PENDING
, (4+4+4));
1699 data
<< uint32(mapid
);
1702 data
<< m_transport
->GetEntry() << GetMapId();
1704 GetSession()->SendPacket(&data
);
1706 data
.Initialize(SMSG_NEW_WORLD
, (20));
1709 data
<< (uint32
)mapid
<< m_movementInfo
.t_x
<< m_movementInfo
.t_y
<< m_movementInfo
.t_z
<< m_movementInfo
.t_o
;
1713 data
<< (uint32
)mapid
<< (float)x
<< (float)y
<< (float)z
<< (float)orientation
;
1715 GetSession()->SendPacket( &data
);
1716 SendSavedInstances();
1718 // remove from old map now
1719 if(oldmap
) oldmap
->Remove(this, false);
1722 // new final coordinates
1726 float final_o
= orientation
;
1730 final_x
+= m_movementInfo
.t_x
;
1731 final_y
+= m_movementInfo
.t_y
;
1732 final_z
+= m_movementInfo
.t_z
;
1733 final_o
+= m_movementInfo
.t_o
;
1736 m_teleport_dest
= WorldLocation(mapid
, final_x
, final_y
, final_z
, final_o
);
1737 // if the player is saved before worldportack (at logout for example)
1738 // this will be used instead of the current location in SaveToDB
1740 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_CHANGE_MAP
);
1742 // move packet sent by client always after far teleport
1743 // SetPosition(final_x, final_y, final_z, final_o, true);
1746 // code for finish transfer to new map called in WorldSession::HandleMoveWorldportAckOpcode at client packet
1754 void Player::AddToWorld()
1756 ///- Do not add/remove the player from the object storage
1757 ///- It will crash when updating the ObjectAccessor
1758 ///- The player should only be added when logging in
1761 for(int i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
1764 m_items
[i
]->AddToWorld();
1768 void Player::RemoveFromWorld()
1773 ///- Release charmed creatures, unsummon totems and remove pets/guardians
1775 UnsummonAllTotems();
1780 for(int i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
1783 m_items
[i
]->RemoveFromWorld();
1786 ///- Do not add/remove the player from the object storage
1787 ///- It will crash when updating the ObjectAccessor
1788 ///- The player should only be removed when logging out
1789 Unit::RemoveFromWorld();
1792 void Player::RewardRage( uint32 damage
, uint32 weaponSpeedHitFactor
, bool attacker
)
1796 float rageconversion
= ((0.0091107836 * getLevel()*getLevel())+3.225598133*getLevel())+4.2652911;
1800 addRage
= ((damage
/rageconversion
*7.5 + weaponSpeedHitFactor
)/2);
1802 // talent who gave more rage on attack
1803 addRage
*= 1.0f
+ GetTotalAuraModifier(SPELL_AURA_MOD_RAGE_FROM_DAMAGE_DEALT
) / 100.0f
;
1807 addRage
= damage
/rageconversion
*2.5;
1809 // Berserker Rage effect
1810 if(HasAura(18499,0))
1814 addRage
*= sWorld
.getRate(RATE_POWER_RAGE_INCOME
);
1816 ModifyPower(POWER_RAGE
, uint32(addRage
*10));
1819 void Player::RegenerateAll()
1821 if (m_regenTimer
!= 0)
1823 uint32 regenDelay
= 2000;
1825 // Not in combat or they have regeneration
1826 if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT
) ||
1827 HasAuraType(SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT
) || IsPolymorphed() )
1830 if (!isInCombat() && !HasAuraType(SPELL_AURA_INTERRUPT_REGEN
))
1832 Regenerate(POWER_RAGE
);
1833 Regenerate(POWER_RUNIC_POWER
);
1837 Regenerate( POWER_ENERGY
);
1839 Regenerate( POWER_MANA
);
1841 Regenerate( POWER_RUNE
);
1843 m_regenTimer
= regenDelay
;
1846 void Player::Regenerate(Powers power
)
1848 uint32 curValue
= GetPower(power
);
1849 uint32 maxValue
= GetMaxPower(power
);
1851 float addvalue
= 0.0f
;
1857 bool recentCast
= IsUnderLastManaUseEffect();
1858 float ManaIncreaseRate
= sWorld
.getRate(RATE_POWER_MANA
);
1861 // Mangos Updates Mana in intervals of 2s, which is correct
1862 addvalue
= GetFloatValue(UNIT_FIELD_POWER_REGEN_INTERRUPTED_FLAT_MODIFIER
) * ManaIncreaseRate
* 2.00f
;
1866 addvalue
= GetFloatValue(UNIT_FIELD_POWER_REGEN_FLAT_MODIFIER
) * ManaIncreaseRate
* 2.00f
;
1869 case POWER_RAGE
: // Regenerate rage
1871 float RageDecreaseRate
= sWorld
.getRate(RATE_POWER_RAGE_LOSS
);
1872 addvalue
= 30 * RageDecreaseRate
; // 3 rage by tick
1874 case POWER_ENERGY
: // Regenerate energy (rogue)
1877 case POWER_RUNIC_POWER
:
1879 float RunicPowerDecreaseRate
= sWorld
.getRate(RATE_POWER_RUNICPOWER_LOSS
);
1880 addvalue
= 30 * RunicPowerDecreaseRate
; // 3 RunicPower by tick
1884 for(uint32 i
= 0; i
< 6; ++i
)
1885 if(uint8 cd
= GetRuneCooldown(i
)) // if we have cooldown, reduce it...
1886 SetRuneCooldown(i
, cd
- 1); // by 2 sec (because update is every 2 sec)
1889 case POWER_HAPPINESS
:
1893 // Mana regen calculated in Player::UpdateManaRegen()
1894 // Exist only for POWER_MANA, POWER_ENERGY, POWER_FOCUS auras
1895 if(power
!= POWER_MANA
)
1897 AuraList
const& ModPowerRegenPCTAuras
= GetAurasByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT
);
1898 for(AuraList::const_iterator i
= ModPowerRegenPCTAuras
.begin(); i
!= ModPowerRegenPCTAuras
.end(); ++i
)
1899 if ((*i
)->GetModifier()->m_miscvalue
== power
)
1900 addvalue
*= ((*i
)->GetModifier()->m_amount
+ 100) / 100.0f
;
1903 if (power
!= POWER_RAGE
&& power
!= POWER_RUNIC_POWER
)
1905 curValue
+= uint32(addvalue
);
1906 if (curValue
> maxValue
)
1907 curValue
= maxValue
;
1911 if(curValue
<= uint32(addvalue
))
1914 curValue
-= uint32(addvalue
);
1916 SetPower(power
, curValue
);
1919 void Player::RegenerateHealth()
1921 uint32 curValue
= GetHealth();
1922 uint32 maxValue
= GetMaxHealth();
1924 if (curValue
>= maxValue
) return;
1926 float HealthIncreaseRate
= sWorld
.getRate(RATE_HEALTH
);
1928 float addvalue
= 0.0f
;
1931 if ( IsPolymorphed() )
1932 addvalue
= GetMaxHealth()/3;
1933 // normal regen case (maybe partly in combat case)
1934 else if (!isInCombat() || HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT
) )
1936 addvalue
= OCTRegenHPPerSpirit()* HealthIncreaseRate
;
1939 AuraList
const& mModHealthRegenPct
= GetAurasByType(SPELL_AURA_MOD_HEALTH_REGEN_PERCENT
);
1940 for(AuraList::const_iterator i
= mModHealthRegenPct
.begin(); i
!= mModHealthRegenPct
.end(); ++i
)
1941 addvalue
*= (100.0f
+ (*i
)->GetModifier()->m_amount
) / 100.0f
;
1943 else if(HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT
))
1944 addvalue
*= GetTotalAuraModifier(SPELL_AURA_MOD_REGEN_DURING_COMBAT
) / 100.0f
;
1950 // always regeneration bonus (including combat)
1951 addvalue
+= GetTotalAuraModifier(SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT
);
1956 ModifyHealth(int32(addvalue
));
1959 bool Player::CanInteractWithNPCs(bool alive
) const
1961 if(alive
&& !isAlive())
1969 bool Player::IsUnderWater() const
1971 return IsInWater() &&
1972 GetPositionZ() < (MapManager::Instance().GetBaseMap(GetMapId())->GetWaterLevel(GetPositionX(),GetPositionY())-2);
1975 void Player::SetInWater(bool apply
)
1977 if(m_isInWater
==apply
)
1980 //define player in water by opcodes
1981 //move player's guid into HateOfflineList of those mobs
1982 //which can't swim and move guid back into ThreatList when
1984 //TODO: exist also swimming mobs, and function must be symmetric to enter/leave water
1985 m_isInWater
= apply
;
1987 // remove auras that need water/land
1988 RemoveAurasWithInterruptFlags(apply
? AURA_INTERRUPT_FLAG_NOT_ABOVEWATER
: AURA_INTERRUPT_FLAG_NOT_UNDERWATER
);
1990 getHostilRefManager().updateThreatTables();
1993 void Player::SetGameMaster(bool on
)
1997 m_ExtraFlags
|= PLAYER_EXTRA_GM_ON
;
1999 SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GM
);
2001 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_FFA_PVP
);
2002 ResetContestedPvP();
2004 getHostilRefManager().setOnlineOfflineState(false);
2009 m_ExtraFlags
&= ~ PLAYER_EXTRA_GM_ON
;
2010 setFactionForRace(getRace());
2011 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GM
);
2013 // restore FFA PvP Server state
2014 if(sWorld
.IsFFAPvPRealm())
2015 SetFlag(PLAYER_FLAGS
,PLAYER_FLAGS_FFA_PVP
);
2017 // restore FFA PvP area state, remove not allowed for GM mounts
2018 UpdateArea(m_areaUpdateId
);
2020 getHostilRefManager().setOnlineOfflineState(true);
2023 ObjectAccessor::UpdateVisibilityForPlayer(this);
2026 void Player::SetGMVisible(bool on
)
2030 m_ExtraFlags
&= ~PLAYER_EXTRA_GM_INVISIBLE
; //remove flag
2032 // Reapply stealth/invisibility if active or show if not any
2033 if(HasAuraType(SPELL_AURA_MOD_STEALTH
))
2034 SetVisibility(VISIBILITY_GROUP_STEALTH
);
2035 else if(HasAuraType(SPELL_AURA_MOD_INVISIBILITY
))
2036 SetVisibility(VISIBILITY_GROUP_INVISIBILITY
);
2038 SetVisibility(VISIBILITY_ON
);
2042 m_ExtraFlags
|= PLAYER_EXTRA_GM_INVISIBLE
; //add flag
2044 SetAcceptWhispers(false);
2045 SetGameMaster(true);
2047 SetVisibility(VISIBILITY_OFF
);
2051 bool Player::IsGroupVisibleFor(Player
* p
) const
2053 switch(sWorld
.getConfig(CONFIG_GROUP_VISIBILITY
))
2055 default: return IsInSameGroupWith(p
);
2056 case 1: return IsInSameRaidWith(p
);
2057 case 2: return GetTeam()==p
->GetTeam();
2061 bool Player::IsInSameGroupWith(Player
const* p
) const
2063 return p
==this || GetGroup() != NULL
&&
2064 GetGroup() == p
->GetGroup() &&
2065 GetGroup()->SameSubGroup((Player
*)this, (Player
*)p
);
2068 ///- If the player is invited, remove him. If the group if then only 1 person, disband the group.
2069 /// \todo Shouldn't we also check if there is no other invitees before disbanding the group?
2070 void Player::UninviteFromGroup()
2072 if(GetGroupInvite()) // uninvited invitee
2074 Group
* group
= GetGroupInvite();
2075 group
->RemoveInvite(this);
2077 if(group
->GetMembersCount() <= 1) // group has just 1 member => disband
2079 if(group
->IsCreated())
2081 group
->Disband(true);
2082 objmgr
.RemoveGroup(group
);
2085 group
->RemoveAllInvites();
2092 void Player::RemoveFromGroup(Group
* group
, uint64 guid
)
2096 if (group
->RemoveMember(guid
, 0) <= 1)
2098 // group->Disband(); already disbanded in RemoveMember
2099 objmgr
.RemoveGroup(group
);
2101 // removemember sets the player's group pointer to NULL
2106 void Player::SendLogXPGain(uint32 GivenXP
, Unit
* victim
, uint32 RestXP
)
2108 WorldPacket
data(SMSG_LOG_XPGAIN
, 21);
2109 data
<< uint64(victim
? victim
->GetGUID() : 0); // guid
2110 data
<< uint32(GivenXP
+RestXP
); // given experience
2111 data
<< uint8(victim
? 0 : 1); // 00-kill_xp type, 01-non_kill_xp type
2114 data
<< uint32(GivenXP
); // experience without rested bonus
2115 data
<< float(1); // 1 - none 0 - 100% group bonus output
2117 data
<< uint8(0); // new 2.4.0
2118 GetSession()->SendPacket(&data
);
2121 void Player::GiveXP(uint32 xp
, Unit
* victim
)
2129 uint32 level
= getLevel();
2131 // XP to money conversion processed in Player::RewardQuest
2132 if(level
>= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
2135 // handle SPELL_AURA_MOD_XP_PCT auras
2136 Unit::AuraList
const& ModXPPctAuras
= GetAurasByType(SPELL_AURA_MOD_XP_PCT
);
2137 for(Unit::AuraList::const_iterator i
= ModXPPctAuras
.begin();i
!= ModXPPctAuras
.end(); ++i
)
2138 xp
= uint32(xp
*(1.0f
+ (*i
)->GetModifier()->m_amount
/ 100.0f
));
2140 // XP resting bonus for kill
2141 uint32 rested_bonus_xp
= victim
? GetXPRestBonus(xp
) : 0;
2143 SendLogXPGain(xp
,victim
,rested_bonus_xp
);
2145 uint32 curXP
= GetUInt32Value(PLAYER_XP
);
2146 uint32 nextLvlXP
= GetUInt32Value(PLAYER_NEXT_LEVEL_XP
);
2147 uint32 newXP
= curXP
+ xp
+ rested_bonus_xp
;
2149 while( newXP
>= nextLvlXP
&& level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) )
2153 if ( level
< sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) )
2154 GiveLevel(level
+ 1);
2157 nextLvlXP
= GetUInt32Value(PLAYER_NEXT_LEVEL_XP
);
2160 SetUInt32Value(PLAYER_XP
, newXP
);
2163 // Update player to next level
2164 // Current player experience not update (must be update by caller)
2165 void Player::GiveLevel(uint32 level
)
2167 if ( level
== getLevel() )
2170 PlayerLevelInfo info
;
2171 objmgr
.GetPlayerLevelInfo(getRace(),getClass(),level
,&info
);
2173 PlayerClassLevelInfo classInfo
;
2174 objmgr
.GetPlayerClassLevelInfo(getClass(),level
,&classInfo
);
2176 // send levelup info to client
2177 WorldPacket
data(SMSG_LEVELUP_INFO
, (4+4+MAX_POWERS
*4+MAX_STATS
*4));
2178 data
<< uint32(level
);
2179 data
<< uint32(int32(classInfo
.basehealth
) - int32(GetCreateHealth()));
2180 // for(int i = 0; i < MAX_POWERS; ++i) // Powers loop (0-6)
2181 data
<< uint32(int32(classInfo
.basemana
) - int32(GetCreateMana()));
2189 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
) // Stats loop (0-4)
2190 data
<< uint32(int32(info
.stats
[i
]) - GetCreateStat(Stats(i
)));
2192 GetSession()->SendPacket(&data
);
2194 SetUInt32Value(PLAYER_NEXT_LEVEL_XP
, MaNGOS::XP::xp_to_level(level
));
2196 //update level, max level of skills
2197 if(getLevel()!= level
)
2198 m_Played_time
[1] = 0; // Level Played Time reset
2202 // save base values (bonuses already included in stored stats
2203 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
)
2204 SetCreateStat(Stats(i
), info
.stats
[i
]);
2206 SetCreateHealth(classInfo
.basehealth
);
2207 SetCreateMana(classInfo
.basemana
);
2209 InitTalentForLevel();
2210 InitTaxiNodesForLevel();
2211 InitGlyphsForLevel();
2215 // set current level health and mana/energy to maximum after applying all mods.
2216 SetHealth(GetMaxHealth());
2217 SetPower(POWER_MANA
, GetMaxPower(POWER_MANA
));
2218 SetPower(POWER_ENERGY
, GetMaxPower(POWER_ENERGY
));
2219 if(GetPower(POWER_RAGE
) > GetMaxPower(POWER_RAGE
))
2220 SetPower(POWER_RAGE
, GetMaxPower(POWER_RAGE
));
2221 SetPower(POWER_FOCUS
, 0);
2222 SetPower(POWER_HAPPINESS
, 0);
2224 // give level to summoned pet
2225 Pet
* pet
= GetPet();
2226 if(pet
&& pet
->getPetType()==SUMMON_PET
)
2227 pet
->GivePetLevel(level
);
2228 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_LEVEL
);
2231 void Player::InitTalentForLevel()
2233 uint32 level
= getLevel();
2234 // talents base at level diff ( talents = level - 9 but some can be used already)
2237 // Remove all talent points
2238 if(m_usedTalentCount
> 0) // Free any used talents
2241 SetFreeTalentPoints(0);
2246 uint32 talentPointsForLevel
= uint32((level
-9)*sWorld
.getRate(RATE_TALENT
));
2247 // if used more that have then reset
2248 if(m_usedTalentCount
> talentPointsForLevel
)
2250 if (GetSession()->GetSecurity() < SEC_ADMINISTRATOR
)
2253 SetFreeTalentPoints(0);
2255 // else update amount of free points
2257 SetFreeTalentPoints(talentPointsForLevel
-m_usedTalentCount
);
2261 void Player::InitStatsForLevel(bool reapplyMods
)
2263 if(reapplyMods
) //reapply stats values only on .reset stats (level) command
2264 _RemoveAllStatBonuses();
2266 PlayerClassLevelInfo classInfo
;
2267 objmgr
.GetPlayerClassLevelInfo(getClass(),getLevel(),&classInfo
);
2269 PlayerLevelInfo info
;
2270 objmgr
.GetPlayerLevelInfo(getRace(),getClass(),getLevel(),&info
);
2272 SetUInt32Value(PLAYER_FIELD_MAX_LEVEL
, sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) );
2273 SetUInt32Value(PLAYER_NEXT_LEVEL_XP
, MaNGOS::XP::xp_to_level(getLevel()));
2277 // set default cast time multiplier
2278 SetFloatValue(UNIT_MOD_CAST_SPEED
, 1.0f
);
2280 // reset size before reapply auras
2281 SetFloatValue(OBJECT_FIELD_SCALE_X
,1.0f
);
2283 // save base values (bonuses already included in stored stats
2284 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
)
2285 SetCreateStat(Stats(i
), info
.stats
[i
]);
2287 for(int i
= STAT_STRENGTH
; i
< MAX_STATS
; ++i
)
2288 SetStat(Stats(i
), info
.stats
[i
]);
2290 SetCreateHealth(classInfo
.basehealth
);
2293 SetCreateMana(classInfo
.basemana
);
2295 SetArmor(int32(m_createStats
[STAT_AGILITY
]*2));
2299 //reset rating fields values
2300 for(uint16 index
= PLAYER_FIELD_COMBAT_RATING_1
; index
< PLAYER_FIELD_COMBAT_RATING_1
+ MAX_COMBAT_RATING
; ++index
)
2301 SetUInt32Value(index
, 0);
2303 SetUInt32Value(PLAYER_FIELD_MOD_HEALING_DONE_POS
,0);
2304 for (int i
= 0; i
< 7; i
++)
2306 SetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_NEG
+i
, 0);
2307 SetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS
+i
, 0);
2308 SetFloatValue(PLAYER_FIELD_MOD_DAMAGE_DONE_PCT
+i
, 1.00f
);
2311 //reset attack power, damage and attack speed fields
2312 SetFloatValue(UNIT_FIELD_BASEATTACKTIME
, 2000.0f
);
2313 SetFloatValue(UNIT_FIELD_BASEATTACKTIME
+ 1, 2000.0f
); // offhand attack time
2314 SetFloatValue(UNIT_FIELD_RANGEDATTACKTIME
, 2000.0f
);
2316 SetFloatValue(UNIT_FIELD_MINDAMAGE
, 0.0f
);
2317 SetFloatValue(UNIT_FIELD_MAXDAMAGE
, 0.0f
);
2318 SetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
, 0.0f
);
2319 SetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
, 0.0f
);
2320 SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
, 0.0f
);
2321 SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
, 0.0f
);
2323 SetUInt32Value(UNIT_FIELD_ATTACK_POWER
, 0 );
2324 SetUInt32Value(UNIT_FIELD_ATTACK_POWER_MODS
, 0 );
2325 SetFloatValue(UNIT_FIELD_ATTACK_POWER_MULTIPLIER
,0.0f
);
2326 SetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER
, 0 );
2327 SetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER_MODS
,0 );
2328 SetFloatValue(UNIT_FIELD_RANGED_ATTACK_POWER_MULTIPLIER
,0.0f
);
2330 // Base crit values (will be recalculated in UpdateAllStats() at loading and in _ApplyAllStatBonuses() at reset
2331 SetFloatValue(PLAYER_CRIT_PERCENTAGE
,0.0f
);
2332 SetFloatValue(PLAYER_OFFHAND_CRIT_PERCENTAGE
,0.0f
);
2333 SetFloatValue(PLAYER_RANGED_CRIT_PERCENTAGE
,0.0f
);
2335 // Init spell schools (will be recalculated in UpdateAllStats() at loading and in _ApplyAllStatBonuses() at reset
2336 for (uint8 i
= 0; i
< 7; ++i
)
2337 SetFloatValue(PLAYER_SPELL_CRIT_PERCENTAGE1
+i
, 0.0f
);
2339 SetFloatValue(PLAYER_PARRY_PERCENTAGE
, 0.0f
);
2340 SetFloatValue(PLAYER_BLOCK_PERCENTAGE
, 0.0f
);
2341 SetUInt32Value(PLAYER_SHIELD_BLOCK
, 0);
2344 SetFloatValue(PLAYER_DODGE_PERCENTAGE
, 0.0f
);
2346 // set armor (resistance 0) to original value (create_agility*2)
2347 SetArmor(int32(m_createStats
[STAT_AGILITY
]*2));
2348 SetResistanceBuffMods(SpellSchools(0), true, 0.0f
);
2349 SetResistanceBuffMods(SpellSchools(0), false, 0.0f
);
2350 // set other resistance to original value (0)
2351 for (int i
= 1; i
< MAX_SPELL_SCHOOL
; i
++)
2353 SetResistance(SpellSchools(i
), 0);
2354 SetResistanceBuffMods(SpellSchools(i
), true, 0.0f
);
2355 SetResistanceBuffMods(SpellSchools(i
), false, 0.0f
);
2358 SetUInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE
,0);
2359 SetUInt32Value(PLAYER_FIELD_MOD_TARGET_PHYSICAL_RESISTANCE
,0);
2360 for(int i
= 0; i
< MAX_SPELL_SCHOOL
; ++i
)
2362 SetFloatValue(UNIT_FIELD_POWER_COST_MODIFIER
+i
,0.0f
);
2363 SetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+i
,0.0f
);
2365 // Init data for form but skip reapply item mods for form
2366 InitDataForForm(reapplyMods
);
2369 for (int i
= POWER_MANA
; i
< MAX_POWERS
; i
++)
2370 SetMaxPower(Powers(i
), uint32(GetCreatePowers(Powers(i
))));
2372 SetMaxHealth(classInfo
.basehealth
); // stamina bonus will applied later
2374 // cleanup mounted state (it will set correctly at aura loading if player saved at mount.
2375 SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID
, 0);
2377 // cleanup unit flags (will be re-applied if need at aura load).
2378 RemoveFlag( UNIT_FIELD_FLAGS
,
2379 UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_DISABLE_MOVE
| UNIT_FLAG_NOT_ATTACKABLE_1
|
2380 UNIT_FLAG_PET_IN_COMBAT
| UNIT_FLAG_SILENCED
| UNIT_FLAG_PACIFIED
|
2381 UNIT_FLAG_STUNNED
| UNIT_FLAG_IN_COMBAT
| UNIT_FLAG_DISARMED
|
2382 UNIT_FLAG_CONFUSED
| UNIT_FLAG_FLEEING
| UNIT_FLAG_NOT_SELECTABLE
|
2383 UNIT_FLAG_SKINNABLE
| UNIT_FLAG_MOUNT
| UNIT_FLAG_TAXI_FLIGHT
);
2384 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
); // must be set
2386 // cleanup player flags (will be re-applied if need at aura load), to avoid have ghost flag without ghost aura, for example.
2387 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_AFK
| PLAYER_FLAGS_DND
| PLAYER_FLAGS_GM
| PLAYER_FLAGS_GHOST
| PLAYER_FLAGS_FFA_PVP
);
2389 SetByteValue(UNIT_FIELD_BYTES_1
, 2, 0x00); // one form stealth modified bytes
2391 // restore if need some important flags
2392 SetUInt32Value(PLAYER_FIELD_BYTES2
, 0 ); // flags empty by default
2394 if(reapplyMods
) //reapply stats values only on .reset stats (level) command
2395 _ApplyAllStatBonuses();
2397 // set current level health and mana/energy to maximum after applying all mods.
2398 SetHealth(GetMaxHealth());
2399 SetPower(POWER_MANA
, GetMaxPower(POWER_MANA
));
2400 SetPower(POWER_ENERGY
, GetMaxPower(POWER_ENERGY
));
2401 if(GetPower(POWER_RAGE
) > GetMaxPower(POWER_RAGE
))
2402 SetPower(POWER_RAGE
, GetMaxPower(POWER_RAGE
));
2403 SetPower(POWER_FOCUS
, 0);
2404 SetPower(POWER_HAPPINESS
, 0);
2405 SetPower(POWER_RUNIC_POWER
, 0);
2408 void Player::SendInitialSpells()
2410 uint16 spellCount
= 0;
2412 WorldPacket
data(SMSG_INITIAL_SPELLS
, (1+2+4*m_spells
.size()+2+m_spellCooldowns
.size()*(2+2+2+4+4)));
2415 size_t countPos
= data
.wpos();
2416 data
<< uint16(spellCount
); // spell count placeholder
2418 for (PlayerSpellMap::const_iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
2420 if(itr
->second
->state
== PLAYERSPELL_REMOVED
)
2423 if(!itr
->second
->active
|| itr
->second
->disabled
)
2426 data
<< uint16(itr
->first
);
2427 data
<< uint16(0); // it's not slot id
2432 data
.put
<uint16
>(countPos
,spellCount
); // write real count value
2434 uint16 spellCooldowns
= m_spellCooldowns
.size();
2435 data
<< uint16(spellCooldowns
);
2436 for(SpellCooldowns::const_iterator itr
=m_spellCooldowns
.begin(); itr
!=m_spellCooldowns
.end(); itr
++)
2438 SpellEntry
const *sEntry
= sSpellStore
.LookupEntry(itr
->first
);
2442 data
<< uint16(itr
->first
);
2444 time_t cooldown
= 0;
2445 time_t curTime
= time(NULL
);
2446 if(itr
->second
.end
> curTime
)
2447 cooldown
= (itr
->second
.end
-curTime
)*1000;
2449 data
<< uint16(itr
->second
.itemid
); // cast item id
2450 data
<< uint16(sEntry
->Category
); // spell category
2451 if(sEntry
->Category
) // may be wrong, but anyway better than nothing...
2453 data
<< uint32(0); // cooldown
2454 data
<< uint32(cooldown
); // category cooldown
2458 data
<< uint32(cooldown
); // cooldown
2459 data
<< uint32(0); // category cooldown
2463 GetSession()->SendPacket(&data
);
2465 sLog
.outDetail( "CHARACTER: Sent Initial Spells" );
2468 void Player::RemoveMail(uint32 id
)
2470 for(PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end();++itr
)
2472 if ((*itr
)->messageID
== id
)
2474 //do not delete item, because Player::removeMail() is called when returning mail to sender.
2481 void Player::SendMailResult(uint32 mailId
, uint32 mailAction
, uint32 mailError
, uint32 equipError
, uint32 item_guid
, uint32 item_count
)
2483 WorldPacket
data(SMSG_SEND_MAIL_RESULT
, (4+4+4+(mailError
== MAIL_ERR_BAG_FULL
?4:(mailAction
== MAIL_ITEM_TAKEN
?4+4:0))));
2484 data
<< (uint32
) mailId
;
2485 data
<< (uint32
) mailAction
;
2486 data
<< (uint32
) mailError
;
2487 if ( mailError
== MAIL_ERR_BAG_FULL
)
2488 data
<< (uint32
) equipError
;
2489 else if( mailAction
== MAIL_ITEM_TAKEN
)
2491 data
<< (uint32
) item_guid
; // item guid low?
2492 data
<< (uint32
) item_count
; // item count?
2494 GetSession()->SendPacket(&data
);
2497 void Player::SendNewMail()
2499 // deliver undelivered mail
2500 WorldPacket
data(SMSG_RECEIVED_MAIL
, 4);
2502 GetSession()->SendPacket(&data
);
2505 void Player::UpdateNextMailTimeAndUnreads()
2507 // calculate next delivery time (min. from non-delivered mails
2508 // and recalculate unReadMail
2509 time_t cTime
= time(NULL
);
2510 m_nextMailDelivereTime
= 0;
2512 for(PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end(); ++itr
)
2514 if((*itr
)->deliver_time
> cTime
)
2516 if(!m_nextMailDelivereTime
|| m_nextMailDelivereTime
> (*itr
)->deliver_time
)
2517 m_nextMailDelivereTime
= (*itr
)->deliver_time
;
2519 else if(((*itr
)->checked
& MAIL_CHECK_MASK_READ
) == 0)
2524 void Player::AddNewMailDeliverTime(time_t deliver_time
)
2526 if(deliver_time
<= time(NULL
)) // ready now
2531 else // not ready and no have ready mails
2533 if(!m_nextMailDelivereTime
|| m_nextMailDelivereTime
> deliver_time
)
2534 m_nextMailDelivereTime
= deliver_time
;
2538 bool Player::addSpell(uint32 spell_id
, bool active
, bool learning
, bool loading
, uint16 slot_id
, bool disabled
)
2540 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spell_id
);
2543 // do character spell book cleanup (all characters)
2544 if(loading
&& !learning
) // spell load case
2546 sLog
.outError("Player::addSpell: Non-existed in SpellStore spell #%u request, deleting for all characters in `character_spell`.",spell_id
);
2547 CharacterDatabase
.PExecute("DELETE FROM character_spell WHERE spell = '%u'",spell_id
);
2550 sLog
.outError("Player::addSpell: Non-existed in SpellStore spell #%u request.",spell_id
);
2555 if(!SpellMgr::IsSpellValid(spellInfo
,this,false))
2557 // do character spell book cleanup (all characters)
2558 if(loading
&& !learning
) // spell load case
2560 sLog
.outError("Player::addSpell: Broken spell #%u learning not allowed, deleting for all characters in `character_spell`.",spell_id
);
2561 CharacterDatabase
.PExecute("DELETE FROM character_spell WHERE spell = '%u'",spell_id
);
2564 sLog
.outError("Player::addSpell: Broken spell #%u learning not allowed.",spell_id
);
2569 PlayerSpellState state
= learning
? PLAYERSPELL_NEW
: PLAYERSPELL_UNCHANGED
;
2571 bool disabled_case
= false;
2572 bool superceded_old
= false;
2574 PlayerSpellMap::iterator itr
= m_spells
.find(spell_id
);
2575 if (itr
!= m_spells
.end())
2577 // update active state for known spell
2578 if(itr
->second
->active
!= active
&& itr
->second
->state
!= PLAYERSPELL_REMOVED
&& !itr
->second
->disabled
)
2580 itr
->second
->active
= active
;
2582 // loading && !learning == explicitly load from DB and then exist in it already and set correctly
2583 if(loading
&& !learning
)
2584 itr
->second
->state
= PLAYERSPELL_UNCHANGED
;
2585 else if(itr
->second
->state
!= PLAYERSPELL_NEW
)
2586 itr
->second
->state
= PLAYERSPELL_CHANGED
;
2590 WorldPacket
data(SMSG_REMOVED_SPELL
, 4);
2591 data
<< uint16(spell_id
);
2592 GetSession()->SendPacket(&data
);
2594 return active
; // learn (show in spell book if active now)
2597 if(itr
->second
->disabled
!= disabled
&& itr
->second
->state
!= PLAYERSPELL_REMOVED
)
2599 if(itr
->second
->state
!= PLAYERSPELL_NEW
)
2600 itr
->second
->state
= PLAYERSPELL_CHANGED
;
2601 itr
->second
->disabled
= disabled
;
2606 disabled_case
= true;
2608 else switch(itr
->second
->state
)
2610 case PLAYERSPELL_UNCHANGED
: // known saved spell
2612 case PLAYERSPELL_REMOVED
: // re-learning removed not saved spell
2615 m_spells
.erase(itr
);
2616 state
= PLAYERSPELL_CHANGED
;
2617 break; // need re-add
2619 default: // known not saved yet spell (new or modified)
2621 // can be in case spell loading but learned at some previous spell loading
2622 if(loading
&& !learning
)
2623 itr
->second
->state
= PLAYERSPELL_UNCHANGED
;
2630 if(!disabled_case
) // skip new spell adding if spell already known (disabled spells case)
2632 // talent: unlearn all other talent ranks (high and low)
2633 if(TalentSpellPos
const* talentPos
= GetTalentSpellPos(spell_id
))
2635 if(TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry( talentPos
->talent_id
))
2637 for(int i
=0; i
<5; ++i
)
2639 // skip learning spell and no rank spell case
2640 uint32 rankSpellId
= talentInfo
->RankID
[i
];
2641 if(!rankSpellId
|| rankSpellId
==spell_id
)
2644 // skip unknown ranks
2645 if(!HasSpell(rankSpellId
))
2648 removeSpell(rankSpellId
);
2652 // non talent spell: learn low ranks (recursive call)
2653 else if(uint32 prev_spell
= spellmgr
.GetPrevSpellInChain(spell_id
))
2655 if(loading
) // at spells loading, no output, but allow save
2656 addSpell(prev_spell
,active
,true,loading
,SPELL_WITHOUT_SLOT_ID
,disabled
);
2657 else // at normal learning
2658 learnSpell(prev_spell
);
2661 PlayerSpell
*newspell
= new PlayerSpell
;
2662 newspell
->active
= active
;
2663 newspell
->state
= state
;
2664 newspell
->disabled
= disabled
;
2666 // replace spells in action bars and spellbook to bigger rank if only one spell rank must be accessible
2667 if(newspell
->active
&& !newspell
->disabled
&& !SpellMgr::canStackSpellRanks(spellInfo
) && spellmgr
.GetSpellRank(spellInfo
->Id
) != 0)
2669 for( PlayerSpellMap::iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
2671 if(itr
->second
->state
== PLAYERSPELL_REMOVED
) continue;
2672 SpellEntry
const *i_spellInfo
= sSpellStore
.LookupEntry(itr
->first
);
2673 if(!i_spellInfo
) continue;
2675 if( spellmgr
.IsRankSpellDueToSpell(spellInfo
,itr
->first
) )
2677 if(itr
->second
->active
)
2679 if(spellmgr
.IsHighRankOfSpell(spell_id
,itr
->first
))
2681 if(!loading
) // not send spell (re-/over-)learn packets at loading
2683 WorldPacket
data(SMSG_SUPERCEDED_SPELL
, (4));
2684 data
<< uint16(itr
->first
);
2685 data
<< uint16(spell_id
);
2686 GetSession()->SendPacket( &data
);
2689 // mark old spell as disable (SMSG_SUPERCEDED_SPELL replace it in client by new)
2690 itr
->second
->active
= false;
2691 itr
->second
->state
= PLAYERSPELL_CHANGED
;
2692 superceded_old
= true; // new spell replace old in action bars and spell book.
2694 else if(spellmgr
.IsHighRankOfSpell(itr
->first
,spell_id
))
2696 if(!loading
) // not send spell (re-/over-)learn packets at loading
2698 WorldPacket
data(SMSG_SUPERCEDED_SPELL
, (4));
2699 data
<< uint16(spell_id
);
2700 data
<< uint16(itr
->first
);
2701 GetSession()->SendPacket( &data
);
2704 // mark new spell as disable (not learned yet for client and will not learned)
2705 newspell
->active
= false;
2706 if(newspell
->state
!= PLAYERSPELL_NEW
)
2707 newspell
->state
= PLAYERSPELL_CHANGED
;
2714 uint16 tmpslot
=slot_id
;
2716 if (tmpslot
== SPELL_WITHOUT_SLOT_ID
)
2719 PlayerSpellMap::iterator itr
;
2720 for (itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
2722 if(itr
->second
->state
== PLAYERSPELL_REMOVED
)
2724 if (itr
->second
->slotId
> maxid
)
2725 maxid
= itr
->second
->slotId
;
2727 tmpslot
= maxid
+ 1;
2730 newspell
->slotId
= tmpslot
;
2731 m_spells
[spell_id
] = newspell
;
2733 // return false if spell disabled
2734 if (newspell
->disabled
)
2738 uint32 talentCost
= GetTalentSpellCost(spell_id
);
2740 // cast talents with SPELL_EFFECT_LEARN_SPELL (other dependent spells will learned later as not auto-learned)
2741 // note: all spells with SPELL_EFFECT_LEARN_SPELL isn't passive
2742 if( talentCost
> 0 && IsSpellHaveEffect(spellInfo
,SPELL_EFFECT_LEARN_SPELL
) )
2744 // ignore stance requirement for talent learn spell (stance set for spell only for client spell description show)
2745 CastSpell(this, spell_id
, true);
2747 // also cast passive spells (including all talents without SPELL_EFFECT_LEARN_SPELL) with additional checks
2748 else if (IsPassiveSpell(spell_id
))
2750 // if spell doesn't require a stance or the player is in the required stance
2751 if( ( !spellInfo
->Stances
&&
2752 spell_id
!= 5420 && spell_id
!= 5419 && spell_id
!= 7376 &&
2753 spell_id
!= 7381 && spell_id
!= 21156 && spell_id
!= 21009 &&
2754 spell_id
!= 21178 && spell_id
!= 33948 && spell_id
!= 40121 ) ||
2755 m_form
!= 0 && (spellInfo
->Stances
& (1<<(m_form
-1))) ||
2756 (spell_id
== 5420 && m_form
== FORM_TREE
) ||
2757 (spell_id
== 5419 && m_form
== FORM_TRAVEL
) ||
2758 (spell_id
== 7376 && m_form
== FORM_DEFENSIVESTANCE
) ||
2759 (spell_id
== 7381 && m_form
== FORM_BERSERKERSTANCE
) ||
2760 (spell_id
== 21156 && m_form
== FORM_BATTLESTANCE
)||
2761 (spell_id
== 21178 && (m_form
== FORM_BEAR
|| m_form
== FORM_DIREBEAR
) ) ||
2762 (spell_id
== 33948 && m_form
== FORM_FLIGHT
) ||
2763 (spell_id
== 40121 && m_form
== FORM_FLIGHT_EPIC
) )
2764 //Check CasterAuraStates
2765 if (!spellInfo
->CasterAuraState
|| HasAuraState(AuraState(spellInfo
->CasterAuraState
)))
2766 CastSpell(this, spell_id
, true);
2768 else if( IsSpellHaveEffect(spellInfo
,SPELL_EFFECT_SKILL_STEP
) )
2770 CastSpell(this, spell_id
, true);
2774 // update used talent points count
2775 m_usedTalentCount
+= talentCost
;
2777 // update free primary prof.points (if any, can be none in case GM .learn prof. learning)
2778 if(uint32 freeProfs
= GetFreePrimaryProffesionPoints())
2780 if(spellmgr
.IsPrimaryProfessionFirstRankSpell(spell_id
))
2781 SetFreePrimaryProffesions(freeProfs
-1);
2784 // add dependent skills
2785 uint16 maxskill
= GetMaxSkillValueForLevel();
2787 SpellLearnSkillNode
const* spellLearnSkill
= spellmgr
.GetSpellLearnSkill(spell_id
);
2791 uint32 skill_value
= GetPureSkillValue(spellLearnSkill
->skill
);
2792 uint32 skill_max_value
= GetPureMaxSkillValue(spellLearnSkill
->skill
);
2794 if(skill_value
< spellLearnSkill
->value
)
2795 skill_value
= spellLearnSkill
->value
;
2797 uint32 new_skill_max_value
= spellLearnSkill
->maxvalue
== 0 ? maxskill
: spellLearnSkill
->maxvalue
;
2799 if(skill_max_value
< new_skill_max_value
)
2800 skill_max_value
= new_skill_max_value
;
2802 SetSkill(spellLearnSkill
->skill
,skill_value
,skill_max_value
);
2806 // not ranked skills
2807 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(spell_id
);
2808 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(spell_id
);
2810 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
2812 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(_spell_idx
->second
->skillId
);
2816 if(HasSkill(pSkill
->id
))
2819 if(_spell_idx
->second
->learnOnGetSkill
== ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
||
2820 // lockpicking special case, not have ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
2821 pSkill
->id
==SKILL_LOCKPICKING
&& _spell_idx
->second
->max_value
==0 )
2823 switch(GetSkillRangeType(pSkill
,_spell_idx
->second
->racemask
!=0))
2825 case SKILL_RANGE_LANGUAGE
:
2826 SetSkill(pSkill
->id
, 300, 300 );
2828 case SKILL_RANGE_LEVEL
:
2829 SetSkill(pSkill
->id
, 1, GetMaxSkillValueForLevel() );
2831 case SKILL_RANGE_MONO
:
2832 SetSkill(pSkill
->id
, 1, 1 );
2841 // learn dependent spells
2842 SpellLearnSpellMap::const_iterator spell_begin
= spellmgr
.GetBeginSpellLearnSpell(spell_id
);
2843 SpellLearnSpellMap::const_iterator spell_end
= spellmgr
.GetEndSpellLearnSpell(spell_id
);
2845 for(SpellLearnSpellMap::const_iterator itr
= spell_begin
; itr
!= spell_end
; ++itr
)
2847 if(!itr
->second
.autoLearned
)
2849 if(loading
) // at spells loading, no output, but allow save
2850 addSpell(itr
->second
.spell
,true,true,loading
);
2851 else // at normal learning
2852 learnSpell(itr
->second
.spell
);
2858 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL
);
2859 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS
);
2862 // return true (for send learn packet) only if spell active (in case ranked spells) and not replace old spell
2863 return active
&& !disabled
&& !superceded_old
;
2866 void Player::learnSpell(uint32 spell_id
)
2868 PlayerSpellMap::iterator itr
= m_spells
.find(spell_id
);
2870 bool disabled
= (itr
!= m_spells
.end()) ? itr
->second
->disabled
: false;
2871 bool active
= disabled
? itr
->second
->active
: true;
2873 bool learning
= addSpell(spell_id
,active
);
2875 // learn all disabled higher ranks (recursive)
2876 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
2877 for(SpellChainMapNext::const_iterator i
= nextMap
.lower_bound(spell_id
); i
!= nextMap
.upper_bound(spell_id
); ++i
)
2879 PlayerSpellMap::iterator iter
= m_spells
.find(i
->second
);
2880 if (disabled
&& iter
!= m_spells
.end() && iter
->second
->disabled
)
2881 learnSpell(i
->second
);
2884 // prevent duplicated entires in spell book
2888 WorldPacket
data(SMSG_LEARNED_SPELL
, 4);
2889 data
<< uint32(spell_id
);
2890 GetSession()->SendPacket(&data
);
2893 void Player::removeSpell(uint32 spell_id
, bool disabled
)
2895 PlayerSpellMap::iterator itr
= m_spells
.find(spell_id
);
2896 if (itr
== m_spells
.end())
2899 if(itr
->second
->state
== PLAYERSPELL_REMOVED
|| disabled
&& itr
->second
->disabled
)
2902 // unlearn non talent higher ranks (recursive)
2903 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
2904 for(SpellChainMapNext::const_iterator itr2
= nextMap
.lower_bound(spell_id
); itr2
!= nextMap
.upper_bound(spell_id
); ++itr2
)
2905 if(HasSpell(itr2
->second
) && !GetTalentSpellPos(itr2
->second
))
2906 removeSpell(itr2
->second
,disabled
);
2909 WorldPacket
data(SMSG_REMOVED_SPELL
, 4);
2910 data
<< uint16(spell_id
);
2911 GetSession()->SendPacket(&data
);
2915 itr
->second
->disabled
= disabled
;
2916 if(itr
->second
->state
!= PLAYERSPELL_NEW
)
2917 itr
->second
->state
= PLAYERSPELL_CHANGED
;
2921 if(itr
->second
->state
== PLAYERSPELL_NEW
)
2924 m_spells
.erase(itr
);
2927 itr
->second
->state
= PLAYERSPELL_REMOVED
;
2930 RemoveAurasDueToSpell(spell_id
);
2933 if(PetAura
const* petSpell
= spellmgr
.GetPetAura(spell_id
))
2934 RemovePetAura(petSpell
);
2936 // free talent points
2937 uint32 talentCosts
= GetTalentSpellCost(spell_id
);
2940 if(talentCosts
< m_usedTalentCount
)
2941 m_usedTalentCount
-= talentCosts
;
2943 m_usedTalentCount
= 0;
2946 // update free primary prof.points (if not overflow setting, can be in case GM use before .learn prof. learning)
2947 if(spellmgr
.IsPrimaryProfessionFirstRankSpell(spell_id
))
2949 uint32 freeProfs
= GetFreePrimaryProffesionPoints()+1;
2950 if(freeProfs
<= sWorld
.getConfig(CONFIG_MAX_PRIMARY_TRADE_SKILL
))
2951 SetFreePrimaryProffesions(freeProfs
);
2954 // remove dependent skill
2955 SpellLearnSkillNode
const* spellLearnSkill
= spellmgr
.GetSpellLearnSkill(spell_id
);
2958 uint32 prev_spell
= spellmgr
.GetPrevSpellInChain(spell_id
);
2959 if(!prev_spell
) // first rank, remove skill
2960 SetSkill(spellLearnSkill
->skill
,0,0);
2963 // search prev. skill setting by spell ranks chain
2964 SpellLearnSkillNode
const* prevSkill
= spellmgr
.GetSpellLearnSkill(prev_spell
);
2965 while(!prevSkill
&& prev_spell
)
2967 prev_spell
= spellmgr
.GetPrevSpellInChain(prev_spell
);
2968 prevSkill
= spellmgr
.GetSpellLearnSkill(spellmgr
.GetFirstSpellInChain(prev_spell
));
2971 if(!prevSkill
) // not found prev skill setting, remove skill
2972 SetSkill(spellLearnSkill
->skill
,0,0);
2973 else // set to prev. skill setting values
2975 uint32 skill_value
= GetPureSkillValue(prevSkill
->skill
);
2976 uint32 skill_max_value
= GetPureMaxSkillValue(prevSkill
->skill
);
2978 if(skill_value
> prevSkill
->value
)
2979 skill_value
= prevSkill
->value
;
2981 uint32 new_skill_max_value
= prevSkill
->maxvalue
== 0 ? GetMaxSkillValueForLevel() : prevSkill
->maxvalue
;
2983 if(skill_max_value
> new_skill_max_value
)
2984 skill_max_value
= new_skill_max_value
;
2986 SetSkill(prevSkill
->skill
,skill_value
,skill_max_value
);
2993 // not ranked skills
2994 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(spell_id
);
2995 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(spell_id
);
2997 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
2999 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(_spell_idx
->second
->skillId
);
3003 if(_spell_idx
->second
->learnOnGetSkill
== ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
||
3004 // lockpicking special case, not have ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL
3005 pSkill
->id
==SKILL_LOCKPICKING
&& _spell_idx
->second
->max_value
==0 )
3007 // not reset skills for professions and racial abilities
3008 if( (pSkill
->categoryId
==SKILL_CATEGORY_SECONDARY
|| pSkill
->categoryId
==SKILL_CATEGORY_PROFESSION
) &&
3009 (IsProfessionSkill(pSkill
->id
) || _spell_idx
->second
->racemask
!=0) )
3012 SetSkill(pSkill
->id
, 0, 0 );
3017 // remove dependent spells
3018 SpellLearnSpellMap::const_iterator spell_begin
= spellmgr
.GetBeginSpellLearnSpell(spell_id
);
3019 SpellLearnSpellMap::const_iterator spell_end
= spellmgr
.GetEndSpellLearnSpell(spell_id
);
3021 for(SpellLearnSpellMap::const_iterator itr2
= spell_begin
; itr2
!= spell_end
; ++itr2
)
3022 removeSpell(itr2
->second
.spell
, disabled
);
3025 void Player::RemoveArenaSpellCooldowns()
3027 // remove cooldowns on spells that has < 15 min CD
3028 SpellCooldowns::iterator itr
, next
;
3029 // iterate spell cooldowns
3030 for(itr
= m_spellCooldowns
.begin();itr
!= m_spellCooldowns
.end(); itr
= next
)
3034 SpellEntry
const * entry
= sSpellStore
.LookupEntry(itr
->first
);
3035 // check if spellentry is present and if the cooldown is less than 15 mins
3037 entry
->RecoveryTime
<= 15 * MINUTE
* 1000 &&
3038 entry
->CategoryRecoveryTime
<= 15 * MINUTE
* 1000 )
3041 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
3042 data
<< uint32(itr
->first
);
3044 GetSession()->SendPacket(&data
);
3046 m_spellCooldowns
.erase(itr
);
3051 void Player::RemoveAllSpellCooldown()
3053 if(!m_spellCooldowns
.empty())
3055 for(SpellCooldowns::const_iterator itr
= m_spellCooldowns
.begin();itr
!= m_spellCooldowns
.end(); ++itr
)
3057 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
3058 data
<< uint32(itr
->first
);
3059 data
<< uint64(GetGUID());
3060 GetSession()->SendPacket(&data
);
3062 m_spellCooldowns
.clear();
3066 void Player::_LoadSpellCooldowns(QueryResult
*result
)
3068 m_spellCooldowns
.clear();
3070 //QueryResult *result = CharacterDatabase.PQuery("SELECT spell,item,time FROM character_spell_cooldown WHERE guid = '%u'",GetGUIDLow());
3074 time_t curTime
= time(NULL
);
3078 Field
*fields
= result
->Fetch();
3080 uint32 spell_id
= fields
[0].GetUInt32();
3081 uint32 item_id
= fields
[1].GetUInt32();
3082 time_t db_time
= (time_t)fields
[2].GetUInt64();
3084 if(!sSpellStore
.LookupEntry(spell_id
))
3086 sLog
.outError("Player %u have unknown spell %u in `character_spell_cooldown`, skipping.",GetGUIDLow(),spell_id
);
3090 // skip outdated cooldown
3091 if(db_time
<= curTime
)
3094 AddSpellCooldown(spell_id
, item_id
, db_time
);
3096 sLog
.outDebug("Player (GUID: %u) spell %u, item %u cooldown loaded (%u secs).", GetGUIDLow(), spell_id
, item_id
, uint32(db_time
-curTime
));
3098 while( result
->NextRow() );
3104 void Player::_SaveSpellCooldowns()
3106 CharacterDatabase
.PExecute("DELETE FROM character_spell_cooldown WHERE guid = '%u'", GetGUIDLow());
3108 time_t curTime
= time(NULL
);
3110 // remove outdated and save active
3111 for(SpellCooldowns::iterator itr
= m_spellCooldowns
.begin();itr
!= m_spellCooldowns
.end();)
3113 if(itr
->second
.end
<= curTime
)
3114 m_spellCooldowns
.erase(itr
++);
3117 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
));
3123 uint32
Player::resetTalentsCost() const
3125 // The first time reset costs 1 gold
3126 if(m_resetTalentsCost
< 1*GOLD
)
3129 else if(m_resetTalentsCost
< 5*GOLD
)
3131 // After that it increases in increments of 5 gold
3132 else if(m_resetTalentsCost
< 10*GOLD
)
3136 uint32 months
= (sWorld
.GetGameTime() - m_resetTalentsTime
)/MONTH
;
3139 // This cost will be reduced by a rate of 5 gold per month
3140 int32 new_cost
= int32(m_resetTalentsCost
) - 5*GOLD
*months
;
3141 // to a minimum of 10 gold.
3142 return (new_cost
< 10*GOLD
? 10*GOLD
: new_cost
);
3146 // After that it increases in increments of 5 gold
3147 int32 new_cost
= m_resetTalentsCost
+ 5*GOLD
;
3148 // until it hits a cap of 50 gold.
3149 if(new_cost
> 50*GOLD
)
3156 bool Player::resetTalents(bool no_cost
)
3158 // not need after this call
3159 if(HasAtLoginFlag(AT_LOGIN_RESET_TALENTS
))
3161 m_atLoginFlags
= m_atLoginFlags
& ~AT_LOGIN_RESET_TALENTS
;
3162 CharacterDatabase
.PExecute("UPDATE characters set at_login = at_login & ~ %u WHERE guid ='%u'", uint32(AT_LOGIN_RESET_TALENTS
), GetGUIDLow());
3165 uint32 level
= getLevel();
3166 uint32 talentPointsForLevel
= level
< 10 ? 0 : uint32((level
-9)*sWorld
.getRate(RATE_TALENT
));
3168 if (m_usedTalentCount
== 0)
3170 SetFreeTalentPoints(talentPointsForLevel
);
3178 cost
= resetTalentsCost();
3180 if (GetMoney() < cost
)
3182 SendBuyError( BUY_ERR_NOT_ENOUGHT_MONEY
, 0, 0, 0);
3187 for (unsigned int i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
3189 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
3191 if (!talentInfo
) continue;
3193 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
3198 // unlearn only talents for character class
3199 // some spell learned by one class as normal spells or know at creation but another class learn it as talent,
3200 // to prevent unexpected lost normal learned spell skip another class talents
3201 if( (getClassMask() & talentTabInfo
->ClassMask
) == 0 )
3204 for (int j
= 0; j
< 5; j
++)
3206 for(PlayerSpellMap::iterator itr
= GetSpellMap().begin(); itr
!= GetSpellMap().end();)
3208 if(itr
->second
->state
== PLAYERSPELL_REMOVED
|| itr
->second
->disabled
)
3214 // remove learned spells (all ranks)
3215 uint32 itrFirstId
= spellmgr
.GetFirstSpellInChain(itr
->first
);
3217 // unlearn if first rank is talent or learned by talent
3218 if (itrFirstId
== talentInfo
->RankID
[j
] || spellmgr
.IsSpellLearnToSpell(talentInfo
->RankID
[j
],itrFirstId
))
3220 removeSpell(itr
->first
,!IsPassiveSpell(itr
->first
));
3221 itr
= GetSpellMap().begin();
3230 SetFreeTalentPoints(talentPointsForLevel
);
3234 ModifyMoney(-(int32
)cost
);
3236 m_resetTalentsCost
= cost
;
3237 m_resetTalentsTime
= time(NULL
);
3240 //FIXME: remove pet before or after unlearn spells? for now after unlearn to allow removing of talent related, pet affecting auras
3241 RemovePet(NULL
,PET_SAVE_NOT_IN_SLOT
, true);
3246 bool Player::_removeSpell(uint16 spell_id
)
3248 PlayerSpellMap::iterator itr
= m_spells
.find(spell_id
);
3249 if (itr
!= m_spells
.end())
3252 m_spells
.erase(itr
);
3258 Mail
* Player::GetMail(uint32 id
)
3260 for(PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end(); itr
++)
3262 if ((*itr
)->messageID
== id
)
3270 void Player::_SetCreateBits(UpdateMask
*updateMask
, Player
*target
) const
3274 Object::_SetCreateBits(updateMask
, target
);
3278 for(uint16 index
= 0; index
< m_valuesCount
; index
++)
3280 if(GetUInt32Value(index
) != 0 && updateVisualBits
.GetBit(index
))
3281 updateMask
->SetBit(index
);
3286 void Player::_SetUpdateBits(UpdateMask
*updateMask
, Player
*target
) const
3290 Object::_SetUpdateBits(updateMask
, target
);
3294 Object::_SetUpdateBits(updateMask
, target
);
3295 *updateMask
&= updateVisualBits
;
3299 void Player::InitVisibleBits()
3301 updateVisualBits
.SetCount(PLAYER_END
);
3303 updateVisualBits
.SetBit(OBJECT_FIELD_GUID
);
3304 updateVisualBits
.SetBit(OBJECT_FIELD_TYPE
);
3305 updateVisualBits
.SetBit(OBJECT_FIELD_ENTRY
);
3306 updateVisualBits
.SetBit(OBJECT_FIELD_SCALE_X
);
3307 updateVisualBits
.SetBit(UNIT_FIELD_CHARM
+ 0);
3308 updateVisualBits
.SetBit(UNIT_FIELD_CHARM
+ 1);
3309 updateVisualBits
.SetBit(UNIT_FIELD_SUMMON
+ 0);
3310 updateVisualBits
.SetBit(UNIT_FIELD_SUMMON
+ 1);
3311 updateVisualBits
.SetBit(UNIT_FIELD_CHARMEDBY
+ 0);
3312 updateVisualBits
.SetBit(UNIT_FIELD_CHARMEDBY
+ 1);
3313 updateVisualBits
.SetBit(UNIT_FIELD_TARGET
+ 0);
3314 updateVisualBits
.SetBit(UNIT_FIELD_TARGET
+ 1);
3315 updateVisualBits
.SetBit(UNIT_FIELD_CHANNEL_OBJECT
+ 0);
3316 updateVisualBits
.SetBit(UNIT_FIELD_CHANNEL_OBJECT
+ 1);
3317 updateVisualBits
.SetBit(UNIT_FIELD_BYTES_0
);
3318 updateVisualBits
.SetBit(UNIT_FIELD_HEALTH
);
3319 updateVisualBits
.SetBit(UNIT_FIELD_POWER1
);
3320 updateVisualBits
.SetBit(UNIT_FIELD_POWER2
);
3321 updateVisualBits
.SetBit(UNIT_FIELD_POWER3
);
3322 updateVisualBits
.SetBit(UNIT_FIELD_POWER4
);
3323 updateVisualBits
.SetBit(UNIT_FIELD_POWER5
);
3324 updateVisualBits
.SetBit(UNIT_FIELD_POWER6
);
3325 updateVisualBits
.SetBit(UNIT_FIELD_POWER7
);
3326 updateVisualBits
.SetBit(UNIT_FIELD_MAXHEALTH
);
3327 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER1
);
3328 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER2
);
3329 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER3
);
3330 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER4
);
3331 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER5
);
3332 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER6
);
3333 updateVisualBits
.SetBit(UNIT_FIELD_MAXPOWER7
);
3334 updateVisualBits
.SetBit(UNIT_FIELD_LEVEL
);
3335 updateVisualBits
.SetBit(UNIT_FIELD_FACTIONTEMPLATE
);
3336 updateVisualBits
.SetBit(UNIT_VIRTUAL_ITEM_SLOT_ID
+ 0);
3337 updateVisualBits
.SetBit(UNIT_VIRTUAL_ITEM_SLOT_ID
+ 1);
3338 updateVisualBits
.SetBit(UNIT_VIRTUAL_ITEM_SLOT_ID
+ 2);
3339 updateVisualBits
.SetBit(UNIT_FIELD_FLAGS
);
3340 updateVisualBits
.SetBit(UNIT_FIELD_FLAGS_2
);
3341 updateVisualBits
.SetBit(UNIT_FIELD_AURASTATE
);
3342 updateVisualBits
.SetBit(UNIT_FIELD_BASEATTACKTIME
+ 0);
3343 updateVisualBits
.SetBit(UNIT_FIELD_BASEATTACKTIME
+ 1);
3344 updateVisualBits
.SetBit(UNIT_FIELD_BOUNDINGRADIUS
);
3345 updateVisualBits
.SetBit(UNIT_FIELD_COMBATREACH
);
3346 updateVisualBits
.SetBit(UNIT_FIELD_DISPLAYID
);
3347 updateVisualBits
.SetBit(UNIT_FIELD_NATIVEDISPLAYID
);
3348 updateVisualBits
.SetBit(UNIT_FIELD_MOUNTDISPLAYID
);
3349 updateVisualBits
.SetBit(UNIT_FIELD_BYTES_1
);
3350 updateVisualBits
.SetBit(UNIT_FIELD_PETNUMBER
);
3351 updateVisualBits
.SetBit(UNIT_FIELD_PET_NAME_TIMESTAMP
);
3352 updateVisualBits
.SetBit(UNIT_DYNAMIC_FLAGS
);
3353 updateVisualBits
.SetBit(UNIT_CHANNEL_SPELL
);
3354 updateVisualBits
.SetBit(UNIT_MOD_CAST_SPEED
);
3355 updateVisualBits
.SetBit(UNIT_FIELD_BASE_MANA
);
3356 updateVisualBits
.SetBit(UNIT_FIELD_BYTES_2
);
3357 updateVisualBits
.SetBit(UNIT_FIELD_HOVERHEIGHT
);
3359 updateVisualBits
.SetBit(PLAYER_DUEL_ARBITER
+ 0);
3360 updateVisualBits
.SetBit(PLAYER_DUEL_ARBITER
+ 1);
3361 updateVisualBits
.SetBit(PLAYER_FLAGS
);
3362 updateVisualBits
.SetBit(PLAYER_GUILDID
);
3363 updateVisualBits
.SetBit(PLAYER_GUILDRANK
);
3364 updateVisualBits
.SetBit(PLAYER_BYTES
);
3365 updateVisualBits
.SetBit(PLAYER_BYTES_2
);
3366 updateVisualBits
.SetBit(PLAYER_BYTES_3
);
3367 updateVisualBits
.SetBit(PLAYER_DUEL_TEAM
);
3368 updateVisualBits
.SetBit(PLAYER_GUILD_TIMESTAMP
);
3370 // PLAYER_QUEST_LOG_x also visible bit on official (but only on party/raid)...
3371 for(uint16 i
= PLAYER_QUEST_LOG_1_1
; i
< PLAYER_QUEST_LOG_25_2
; i
+= 4)
3372 updateVisualBits
.SetBit(i
);
3374 // Players visible items are not inventory stuff
3375 for(uint16 i
= 0; i
< EQUIPMENT_SLOT_END
; ++i
)
3377 uint32 offset
= i
* MAX_VISIBLE_ITEM_OFFSET
;
3380 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_CREATOR
+ 0 + offset
);
3381 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_CREATOR
+ 1 + offset
);
3384 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_0
+ 0 + offset
);
3386 // item enchantments
3387 for(uint8 j
= 0; j
< MAX_ENCHANTMENT_SLOT
; ++j
)
3388 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_0
+ 1 + j
+ offset
);
3390 // random properties
3391 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ offset
);
3392 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_SEED
+ offset
);
3393 updateVisualBits
.SetBit(PLAYER_VISIBLE_ITEM_1_PAD
+ offset
);
3396 updateVisualBits
.SetBit(PLAYER_CHOSEN_TITLE
);
3399 void Player::BuildCreateUpdateBlockForPlayer( UpdateData
*data
, Player
*target
) const
3401 for(int i
= 0; i
< EQUIPMENT_SLOT_END
; i
++)
3403 if(m_items
[i
] == NULL
)
3406 m_items
[i
]->BuildCreateUpdateBlockForPlayer( data
, target
);
3411 for(int i
= INVENTORY_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
3413 if(m_items
[i
] == NULL
)
3416 m_items
[i
]->BuildCreateUpdateBlockForPlayer( data
, target
);
3418 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
3420 if(m_items
[i
] == NULL
)
3423 m_items
[i
]->BuildCreateUpdateBlockForPlayer( data
, target
);
3427 Unit::BuildCreateUpdateBlockForPlayer( data
, target
);
3430 void Player::DestroyForPlayer( Player
*target
) const
3432 Unit::DestroyForPlayer( target
);
3434 for(int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
3436 if(m_items
[i
] == NULL
)
3439 m_items
[i
]->DestroyForPlayer( target
);
3444 for(int i
= INVENTORY_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
3446 if(m_items
[i
] == NULL
)
3449 m_items
[i
]->DestroyForPlayer( target
);
3451 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
3453 if(m_items
[i
] == NULL
)
3456 m_items
[i
]->DestroyForPlayer( target
);
3461 bool Player::HasSpell(uint32 spell
) const
3463 PlayerSpellMap::const_iterator itr
= m_spells
.find((uint16
)spell
);
3464 return (itr
!= m_spells
.end() && itr
->second
->state
!= PLAYERSPELL_REMOVED
&& !itr
->second
->disabled
);
3467 TrainerSpellState
Player::GetTrainerSpellState(TrainerSpell
const* trainer_spell
) const
3470 return TRAINER_SPELL_RED
;
3472 if (!trainer_spell
->spell
)
3473 return TRAINER_SPELL_RED
;
3476 if(HasSpell(trainer_spell
->spell
))
3477 return TRAINER_SPELL_GRAY
;
3479 // check race/class requirement
3480 if(!IsSpellFitByClassAndRace(trainer_spell
->spell
))
3481 return TRAINER_SPELL_RED
;
3483 // check level requirement
3484 if(getLevel() < trainer_spell
->reqlevel
)
3485 return TRAINER_SPELL_RED
;
3487 if(SpellChainNode
const* spell_chain
= spellmgr
.GetSpellChainNode(trainer_spell
->spell
))
3489 // check prev.rank requirement
3490 if(spell_chain
->prev
&& !HasSpell(spell_chain
->prev
))
3491 return TRAINER_SPELL_RED
;
3493 // check additional spell requirement
3494 if(spell_chain
->req
&& !HasSpell(spell_chain
->req
))
3495 return TRAINER_SPELL_RED
;
3498 // check skill requirement
3499 if(trainer_spell
->reqskill
&& GetBaseSkillValue(trainer_spell
->reqskill
) < trainer_spell
->reqskillvalue
)
3500 return TRAINER_SPELL_RED
;
3502 // exist, already checked at loading
3503 SpellEntry
const* spell
= sSpellStore
.LookupEntry(trainer_spell
->spell
);
3505 // secondary prof. or not prof. spell
3506 uint32 skill
= spell
->EffectMiscValue
[1];
3508 if(spell
->Effect
[1] != SPELL_EFFECT_SKILL
|| !IsPrimaryProfessionSkill(skill
))
3509 return TRAINER_SPELL_GREEN
;
3511 // check primary prof. limit
3512 if(spellmgr
.IsPrimaryProfessionFirstRankSpell(spell
->Id
) && GetFreePrimaryProffesionPoints() == 0)
3513 return TRAINER_SPELL_RED
;
3515 return TRAINER_SPELL_GREEN
;
3518 void Player::DeleteFromDB(uint64 playerguid
, uint32 accountId
, bool updateRealmChars
)
3520 uint32 guid
= GUID_LOPART(playerguid
);
3522 // convert corpse to bones if exist (to prevent exiting Corpse in World without DB entry)
3523 // bones will be deleted by corpse/bones deleting thread shortly
3524 ObjectAccessor::Instance().ConvertCorpseForPlayer(playerguid
);
3526 // remove from guild
3527 uint32 guildId
= GetGuildIdFromDB(playerguid
);
3530 Guild
* guild
= objmgr
.GetGuildById(guildId
);
3532 guild
->DelMember(guid
);
3535 // the player was uninvited already on logout so just remove from group
3536 QueryResult
*resultGroup
= CharacterDatabase
.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", guid
);
3539 uint64 leaderGuid
= MAKE_NEW_GUID((*resultGroup
)[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
3541 Group
* group
= objmgr
.GetGroupByLeader(leaderGuid
);
3544 RemoveFromGroup(group
, playerguid
);
3548 // remove signs from petitions (also remove petitions if owner);
3549 RemovePetitionsAndSigns(playerguid
, 10);
3551 // return back all mails with COD and Item 0 1 2 3 4 5 6
3552 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
);
3557 Field
*fields
= resultMail
->Fetch();
3559 uint32 mail_id
= fields
[0].GetUInt32();
3560 uint16 mailTemplateId
= fields
[1].GetUInt16();
3561 uint32 sender
= fields
[2].GetUInt32();
3562 std::string subject
= fields
[3].GetCppString();
3563 uint32 itemTextId
= fields
[4].GetUInt32();
3564 uint32 money
= fields
[5].GetUInt32();
3565 bool has_items
= fields
[6].GetBool();
3567 //we can return mail now
3568 //so firstly delete the old one
3569 CharacterDatabase
.PExecute("DELETE FROM mail WHERE id = '%u'", mail_id
);
3574 QueryResult
*resultItems
= CharacterDatabase
.PQuery("SELECT item_guid,item_template FROM mail_items WHERE mail_id='%u'", mail_id
);
3579 Field
*fields2
= resultItems
->Fetch();
3581 uint32 item_guidlow
= fields2
[0].GetUInt32();
3582 uint32 item_template
= fields2
[1].GetUInt32();
3584 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_template
);
3587 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", item_guidlow
);
3591 Item
*pItem
= NewItemOrBag(itemProto
);
3592 if(!pItem
->LoadFromDB(item_guidlow
, MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
)))
3594 pItem
->FSetState(ITEM_REMOVED
);
3595 pItem
->SaveToDB(); // it also deletes item object !
3599 mi
.AddItem(item_guidlow
, item_template
, pItem
);
3601 while (resultItems
->NextRow());
3607 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE mail_id = '%u'", mail_id
);
3609 uint32 pl_account
= objmgr
.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
));
3611 WorldSession::SendReturnToSender(MAIL_NORMAL
, pl_account
, guid
, sender
, subject
, itemTextId
, &mi
, money
, mailTemplateId
);
3613 while (resultMail
->NextRow());
3618 // unsummon and delete for pets in world is not required: player deleted from CLI or character list with not loaded pet.
3619 // Get guids of character's pets, will deleted in transaction
3620 QueryResult
*resultPets
= CharacterDatabase
.PQuery("SELECT id FROM character_pet WHERE owner = '%u'",guid
);
3622 // NOW we can finally clear other DB data related to character
3623 CharacterDatabase
.BeginTransaction();
3628 Field
*fields3
= resultPets
->Fetch();
3629 uint32 petguidlow
= fields3
[0].GetUInt32();
3630 Pet::DeleteFromDB(petguidlow
);
3631 } while (resultPets
->NextRow());
3635 CharacterDatabase
.PExecute("DELETE FROM characters WHERE guid = '%u'",guid
);
3636 CharacterDatabase
.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'",guid
);
3637 CharacterDatabase
.PExecute("DELETE FROM character_action WHERE guid = '%u'",guid
);
3638 CharacterDatabase
.PExecute("DELETE FROM character_aura WHERE guid = '%u'",guid
);
3639 CharacterDatabase
.PExecute("DELETE FROM character_gifts WHERE guid = '%u'",guid
);
3640 CharacterDatabase
.PExecute("DELETE FROM character_homebind WHERE guid = '%u'",guid
);
3641 CharacterDatabase
.PExecute("DELETE FROM character_instance WHERE guid = '%u'",guid
);
3642 CharacterDatabase
.PExecute("DELETE FROM group_instance WHERE leaderGuid = '%u'",guid
);
3643 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE guid = '%u'",guid
);
3644 CharacterDatabase
.PExecute("DELETE FROM character_queststatus WHERE guid = '%u'",guid
);
3645 CharacterDatabase
.PExecute("DELETE FROM character_reputation WHERE guid = '%u'",guid
);
3646 CharacterDatabase
.PExecute("DELETE FROM character_spell WHERE guid = '%u'",guid
);
3647 CharacterDatabase
.PExecute("DELETE FROM character_spell_cooldown WHERE guid = '%u'",guid
);
3648 CharacterDatabase
.PExecute("DELETE FROM character_ticket WHERE guid = '%u'",guid
);
3649 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE owner_guid = '%u'",guid
);
3650 CharacterDatabase
.PExecute("DELETE FROM character_social WHERE guid = '%u' OR friend='%u'",guid
,guid
);
3651 CharacterDatabase
.PExecute("DELETE FROM mail WHERE receiver = '%u'",guid
);
3652 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE receiver = '%u'",guid
);
3653 CharacterDatabase
.PExecute("DELETE FROM character_pet WHERE owner = '%u'",guid
);
3654 CharacterDatabase
.PExecute("DELETE FROM character_pet_declinedname WHERE owner = '%u'",guid
);
3655 CharacterDatabase
.PExecute("DELETE FROM character_achievement WHERE guid = '%u'",guid
);
3656 CharacterDatabase
.PExecute("DELETE FROM character_achievement_progress WHERE guid = '%u'",guid
);
3657 CharacterDatabase
.CommitTransaction();
3659 //loginDatabase.PExecute("UPDATE realmcharacters SET numchars = numchars - 1 WHERE acctid = %d AND realmid = %d", accountId, realmID);
3660 if(updateRealmChars
) sWorld
.UpdateRealmCharCount(accountId
);
3663 void Player::SetMovement(PlayerMovementType pType
)
3668 case MOVE_ROOT
: data
.Initialize(SMSG_FORCE_MOVE_ROOT
, GetPackGUID().size()+4); break;
3669 case MOVE_UNROOT
: data
.Initialize(SMSG_FORCE_MOVE_UNROOT
, GetPackGUID().size()+4); break;
3670 case MOVE_WATER_WALK
: data
.Initialize(SMSG_MOVE_WATER_WALK
, GetPackGUID().size()+4); break;
3671 case MOVE_LAND_WALK
: data
.Initialize(SMSG_MOVE_LAND_WALK
, GetPackGUID().size()+4); break;
3673 sLog
.outError("Player::SetMovement: Unsupported move type (%d), data not sent to client.",pType
);
3676 data
.append(GetPackGUID());
3678 GetSession()->SendPacket( &data
);
3682 - a resurrectable corpse must not be loaded for the player (only bones)
3683 - the player must be in world
3685 void Player::BuildPlayerRepop()
3687 WorldPacket
data(SMSG_PRE_RESURRECT
, GetPackGUID().size());
3688 data
.append(GetPackGUID());
3689 GetSession()->SendPacket(&data
);
3691 if(getRace() == RACE_NIGHTELF
)
3692 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)
3693 CastSpell(this, 8326, true); // auras SPELL_AURA_GHOST, SPELL_AURA_INCREASE_SPEED(why?), SPELL_AURA_INCREASE_SWIM_SPEED(why?)
3695 // there must be SMSG.FORCE_RUN_SPEED_CHANGE, SMSG.FORCE_SWIM_SPEED_CHANGE, SMSG.MOVE_WATER_WALK
3696 // there must be SMSG.STOP_MIRROR_TIMER
3697 // there we must send 888 opcode
3699 // the player cannot have a corpse already, only bones which are not returned by GetCorpse
3702 sLog
.outError("BuildPlayerRepop: player %s(%d) already has a corpse", GetName(), GetGUIDLow());
3706 // create a corpse and place it at the player's location
3708 Corpse
*corpse
= GetCorpse();
3711 sLog
.outError("Error creating corpse for Player %s [%u]", GetName(), GetGUIDLow());
3714 GetMap()->Add(corpse
);
3716 // convert player body to ghost
3719 SetMovement(MOVE_WATER_WALK
);
3720 if(!GetSession()->isLogingOut())
3721 SetMovement(MOVE_UNROOT
);
3723 // BG - remove insignia related
3724 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
);
3726 SendCorpseReclaimDelay();
3728 // to prevent cheating
3729 corpse
->ResetGhostTime();
3731 StopMirrorTimers(); //disable timers(bars)
3733 SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, (float)1.0); //see radius of death player?
3735 SetByteValue(UNIT_FIELD_BYTES_1
, 3, PLAYER_STATE_FLAG_ALWAYS_STAND
);
3738 void Player::SendDelayResponse(const uint32 ml_seconds
)
3740 //FIXME: is this delay time arg really need? 50msec by default in code
3741 WorldPacket
data( SMSG_QUERY_TIME_RESPONSE
, 4+4 );
3742 data
<< (uint32
)time(NULL
);
3744 GetSession()->SendPacket( &data
);
3747 void Player::ResurrectPlayer(float restore_percent
, bool applySickness
)
3749 WorldPacket
data(SMSG_DEATH_RELEASE_LOC
, 4*4); // remove spirit healer position
3754 GetSession()->SendPacket(&data
);
3756 // speed change, land walk
3758 // remove death flag + set aura
3759 SetByteValue(UNIT_FIELD_BYTES_1
, 3, 0x00);
3760 if(getRace() == RACE_NIGHTELF
)
3761 RemoveAurasDueToSpell(20584); // speed bonuses
3762 RemoveAurasDueToSpell(8326); // SPELL_AURA_GHOST
3764 setDeathState(ALIVE
);
3766 SetMovement(MOVE_LAND_WALK
);
3767 SetMovement(MOVE_UNROOT
);
3771 // set health/powers (0- will be set in caller)
3772 if(restore_percent
>0.0f
)
3774 SetHealth(uint32(GetMaxHealth()*restore_percent
));
3775 SetPower(POWER_MANA
, uint32(GetMaxPower(POWER_MANA
)*restore_percent
));
3776 SetPower(POWER_RAGE
, 0);
3777 SetPower(POWER_ENERGY
, uint32(GetMaxPower(POWER_ENERGY
)*restore_percent
));
3780 // update visibility
3781 ObjectAccessor::UpdateVisibilityForPlayer(this);
3783 // some items limited to specific map
3784 DestroyZoneLimitedItem( true, GetZoneId());
3786 if(!applySickness
|| getLevel() <= 10)
3789 //Characters from level 1-10 are not affected by resurrection sickness.
3790 //Characters from level 11-19 will suffer from one minute of sickness
3791 //for each level they are above 10.
3792 //Characters level 20 and up suffer from ten minutes of sickness.
3793 int32 startLevel
= sWorld
.getConfig(CONFIG_DEATH_SICKNESS_LEVEL
);
3795 if(int32(getLevel()) >= startLevel
)
3797 // set resurrection sickness
3798 CastSpell(this,SPELL_ID_PASSIVE_RESURRECTION_SICKNESS
,true);
3800 // not full duration
3801 if(int32(getLevel()) < startLevel
+9)
3803 int32 delta
= (int32(getLevel()) - startLevel
+ 1)*MINUTE
;
3805 for(int i
=0; i
< 3; ++i
)
3807 if(Aura
* Aur
= GetAura(SPELL_ID_PASSIVE_RESURRECTION_SICKNESS
,i
))
3809 Aur
->SetAuraDuration(delta
*1000);
3810 Aur
->SendAuraUpdate(false);
3817 void Player::KillPlayer()
3819 SetMovement(MOVE_ROOT
);
3821 StopMirrorTimers(); //disable timers(bars)
3823 setDeathState(CORPSE
);
3824 //SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_IN_PVP );
3826 SetFlag(UNIT_DYNAMIC_FLAGS
, 0x00);
3827 ApplyModFlag(PLAYER_FIELD_BYTES
, PLAYER_FIELD_BYTE_RELEASE_TIMER
, !sMapStore
.LookupEntry(GetMapId())->Instanceable());
3829 // 6 minutes until repop at graveyard
3830 m_deathTimer
= 6*MINUTE
*1000;
3832 UpdateCorpseReclaimDelay(); // dependent at use SetDeathPvP() call before kill
3834 // don't create corpse at this moment, player might be falling
3836 // update visibility
3837 ObjectAccessor::UpdateObjectVisibility(this);
3840 void Player::CreateCorpse()
3842 // prevent existence 2 corpse for player
3845 uint32 _uf
, _pb
, _pb2
, _cfb1
, _cfb2
;
3847 Corpse
*corpse
= new Corpse( (m_ExtraFlags
& PLAYER_EXTRA_PVP_DEATH
) ? CORPSE_RESURRECTABLE_PVP
: CORPSE_RESURRECTABLE_PVE
);
3850 if(!corpse
->Create(objmgr
.GenerateLowGuid(HIGHGUID_CORPSE
), this, GetMapId(), GetPositionX(),
3851 GetPositionY(), GetPositionZ(), GetOrientation()))
3857 _uf
= GetUInt32Value(UNIT_FIELD_BYTES_0
);
3858 _pb
= GetUInt32Value(PLAYER_BYTES
);
3859 _pb2
= GetUInt32Value(PLAYER_BYTES_2
);
3861 uint8 race
= (uint8
)(_uf
);
3862 uint8 skin
= (uint8
)(_pb
);
3863 uint8 face
= (uint8
)(_pb
>> 8);
3864 uint8 hairstyle
= (uint8
)(_pb
>> 16);
3865 uint8 haircolor
= (uint8
)(_pb
>> 24);
3866 uint8 facialhair
= (uint8
)(_pb2
);
3868 _cfb1
= ((0x00) | (race
<< 8) | (getGender() << 16) | (skin
<< 24));
3869 _cfb2
= ((face
) | (hairstyle
<< 8) | (haircolor
<< 16) | (facialhair
<< 24));
3871 corpse
->SetUInt32Value( CORPSE_FIELD_BYTES_1
, _cfb1
);
3872 corpse
->SetUInt32Value( CORPSE_FIELD_BYTES_2
, _cfb2
);
3874 uint32 flags
= CORPSE_FLAG_UNK2
;
3875 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_HELM
))
3876 flags
|= CORPSE_FLAG_HIDE_HELM
;
3877 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_HIDE_CLOAK
))
3878 flags
|= CORPSE_FLAG_HIDE_CLOAK
;
3879 if(InBattleGround())
3880 flags
|= CORPSE_FLAG_LOOTABLE
; // to be able to remove insignia
3881 corpse
->SetUInt32Value( CORPSE_FIELD_FLAGS
, flags
);
3883 corpse
->SetUInt32Value( CORPSE_FIELD_DISPLAY_ID
, GetNativeDisplayId() );
3885 corpse
->SetUInt32Value( CORPSE_FIELD_GUILD
, GetGuildId() );
3888 uint16 iIventoryType
;
3890 for (int i
= 0; i
< EQUIPMENT_SLOT_END
; i
++)
3894 iDisplayID
= m_items
[i
]->GetProto()->DisplayInfoID
;
3895 iIventoryType
= (uint16
)m_items
[i
]->GetProto()->InventoryType
;
3897 _cfi
= (uint16(iDisplayID
)) | (iIventoryType
)<< 24;
3898 corpse
->SetUInt32Value(CORPSE_FIELD_ITEM
+ i
,_cfi
);
3902 // we don't SaveToDB for players in battlegrounds so don't do it for corpses either
3903 const MapEntry
*entry
= sMapStore
.LookupEntry(corpse
->GetMapId());
3905 if(entry
->map_type
!= MAP_BATTLEGROUND
)
3908 // register for player, but not show
3909 ObjectAccessor::Instance().AddCorpse(corpse
);
3912 void Player::SpawnCorpseBones()
3914 if(ObjectAccessor::Instance().ConvertCorpseForPlayer(GetGUID()))
3915 SaveToDB(); // prevent loading as ghost without corpse
3918 Corpse
* Player::GetCorpse() const
3920 return ObjectAccessor::Instance().GetCorpseForPlayerGUID(GetGUID());
3923 void Player::DurabilityLossAll(double percent
, bool inventory
)
3925 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
3926 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3927 DurabilityLoss(pItem
,percent
);
3931 // bags not have durability
3932 // for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
3934 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
3935 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3936 DurabilityLoss(pItem
,percent
);
3938 // keys not have durability
3939 //for(int i = KEYRING_SLOT_START; i < KEYRING_SLOT_END; i++)
3941 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
3942 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3943 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
3944 if(Item
* pItem
= GetItemByPos( i
, j
))
3945 DurabilityLoss(pItem
,percent
);
3949 void Player::DurabilityLoss(Item
* item
, double percent
)
3954 uint32 pMaxDurability
= item
->GetUInt32Value(ITEM_FIELD_MAXDURABILITY
);
3959 uint32 pDurabilityLoss
= uint32(pMaxDurability
*percent
);
3961 if(pDurabilityLoss
< 1 )
3962 pDurabilityLoss
= 1;
3964 DurabilityPointsLoss(item
,pDurabilityLoss
);
3967 void Player::DurabilityPointsLossAll(int32 points
, bool inventory
)
3969 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
3970 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3971 DurabilityPointsLoss(pItem
,points
);
3975 // bags not have durability
3976 // for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
3978 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
3979 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3980 DurabilityPointsLoss(pItem
,points
);
3982 // keys not have durability
3983 //for(int i = KEYRING_SLOT_START; i < KEYRING_SLOT_END; i++)
3985 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
3986 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
3987 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
3988 if(Item
* pItem
= GetItemByPos( i
, j
))
3989 DurabilityPointsLoss(pItem
,points
);
3993 void Player::DurabilityPointsLoss(Item
* item
, int32 points
)
3995 int32 pMaxDurability
= item
->GetUInt32Value(ITEM_FIELD_MAXDURABILITY
);
3996 int32 pOldDurability
= item
->GetUInt32Value(ITEM_FIELD_DURABILITY
);
3997 int32 pNewDurability
= pOldDurability
- points
;
3999 if (pNewDurability
< 0)
4001 else if (pNewDurability
> pMaxDurability
)
4002 pNewDurability
= pMaxDurability
;
4004 if (pOldDurability
!= pNewDurability
)
4006 // modify item stats _before_ Durability set to 0 to pass _ApplyItemMods internal check
4007 if ( pNewDurability
== 0 && pOldDurability
> 0 && item
->IsEquipped())
4008 _ApplyItemMods(item
,item
->GetSlot(), false);
4010 item
->SetUInt32Value(ITEM_FIELD_DURABILITY
, pNewDurability
);
4012 // modify item stats _after_ restore durability to pass _ApplyItemMods internal check
4013 if ( pNewDurability
> 0 && pOldDurability
== 0 && item
->IsEquipped())
4014 _ApplyItemMods(item
,item
->GetSlot(), true);
4016 item
->SetState(ITEM_CHANGED
, this);
4020 void Player::DurabilityPointLossForEquipSlot(EquipmentSlots slot
)
4022 if(Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, slot
))
4023 DurabilityPointsLoss(pItem
,1);
4026 uint32
Player::DurabilityRepairAll(bool cost
, float discountMod
, bool guildBank
)
4028 uint32 TotalCost
= 0;
4029 // equipped, backpack, bags itself
4030 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
4031 TotalCost
+= DurabilityRepair(( (INVENTORY_SLOT_BAG_0
<< 8) | i
),cost
,discountMod
, guildBank
);
4033 // bank, buyback and keys not repaired
4035 // items in inventory bags
4036 for(int j
= INVENTORY_SLOT_BAG_START
; j
< INVENTORY_SLOT_BAG_END
; j
++)
4037 for(int i
= 0; i
< MAX_BAG_SIZE
; i
++)
4038 TotalCost
+= DurabilityRepair(( (j
<< 8) | i
),cost
,discountMod
, guildBank
);
4042 uint32
Player::DurabilityRepair(uint16 pos
, bool cost
, float discountMod
, bool guildBank
)
4044 Item
* item
= GetItemByPos(pos
);
4046 uint32 TotalCost
= 0;
4050 uint32 maxDurability
= item
->GetUInt32Value(ITEM_FIELD_MAXDURABILITY
);
4054 uint32 curDurability
= item
->GetUInt32Value(ITEM_FIELD_DURABILITY
);
4058 uint32 LostDurability
= maxDurability
- curDurability
;
4059 if(LostDurability
>0)
4061 ItemPrototype
const *ditemProto
= item
->GetProto();
4063 DurabilityCostsEntry
const *dcost
= sDurabilityCostsStore
.LookupEntry(ditemProto
->ItemLevel
);
4066 sLog
.outError("ERROR: RepairDurability: Wrong item lvl %u", ditemProto
->ItemLevel
);
4070 uint32 dQualitymodEntryId
= (ditemProto
->Quality
+1)*2;
4071 DurabilityQualityEntry
const *dQualitymodEntry
= sDurabilityQualityStore
.LookupEntry(dQualitymodEntryId
);
4072 if(!dQualitymodEntry
)
4074 sLog
.outError("ERROR: RepairDurability: Wrong dQualityModEntry %u", dQualitymodEntryId
);
4078 uint32 dmultiplier
= dcost
->multiplier
[ItemSubClassToDurabilityMultiplierId(ditemProto
->Class
,ditemProto
->SubClass
)];
4079 uint32 costs
= uint32(LostDurability
*dmultiplier
*double(dQualitymodEntry
->quality_mod
));
4081 costs
= uint32(costs
* discountMod
);
4083 if (costs
==0) //fix for ITEM_QUALITY_ARTIFACT
4088 if (GetGuildId()==0)
4090 DEBUG_LOG("You are not member of a guild");
4094 Guild
*pGuild
= objmgr
.GetGuildById(GetGuildId());
4098 if (!pGuild
->HasRankRight(GetRank(), GR_RIGHT_WITHDRAW_REPAIR
))
4100 DEBUG_LOG("You do not have rights to withdraw for repairs");
4104 if (pGuild
->GetMemberMoneyWithdrawRem(GetGUIDLow()) < costs
)
4106 DEBUG_LOG("You do not have enough money withdraw amount remaining");
4110 if (pGuild
->GetGuildBankMoney() < costs
)
4112 DEBUG_LOG("There is not enough money in bank");
4116 pGuild
->MemberMoneyWithdraw(costs
, GetGUIDLow());
4119 else if (GetMoney() < costs
)
4121 DEBUG_LOG("You do not have enough money");
4125 ModifyMoney( -int32(costs
) );
4129 item
->SetUInt32Value(ITEM_FIELD_DURABILITY
, maxDurability
);
4130 item
->SetState(ITEM_CHANGED
, this);
4132 // reapply mods for total broken and repaired item if equipped
4133 if(IsEquipmentPos(pos
) && !curDurability
)
4134 _ApplyItemMods(item
,pos
& 255, true);
4138 void Player::RepopAtGraveyard()
4140 // note: this can be called also when the player is alive
4141 // for example from WorldSession::HandleMovementOpcodes
4143 AreaTableEntry
const *zone
= GetAreaEntryByAreaID(GetAreaId());
4145 // Such zones are considered unreachable as a ghost and the player must be automatically revived
4146 if(!isAlive() && zone
&& zone
->flags
& AREA_FLAG_NEED_FLY
|| GetTransport())
4148 ResurrectPlayer(0.5f
);
4152 WorldSafeLocsEntry
const *ClosestGrave
= NULL
;
4154 // Special handle for battleground maps
4155 BattleGround
*bg
= sBattleGroundMgr
.GetBattleGround(GetBattleGroundId());
4157 if(bg
&& (bg
->GetTypeID() == BATTLEGROUND_AB
|| bg
->GetTypeID() == BATTLEGROUND_EY
))
4158 ClosestGrave
= bg
->GetClosestGraveYard(GetPositionX(), GetPositionY(), GetPositionZ(), GetTeam());
4160 ClosestGrave
= objmgr
.GetClosestGraveYard( GetPositionX(), GetPositionY(), GetPositionZ(), GetMapId(), GetTeam() );
4162 // stop countdown until repop
4165 // if no grave found, stay at the current location
4166 // and don't show spirit healer location
4169 TeleportTo(ClosestGrave
->map_id
, ClosestGrave
->x
, ClosestGrave
->y
, ClosestGrave
->z
, GetOrientation());
4170 if(isDead()) // not send if alive, because it used in TeleportTo()
4172 WorldPacket
data(SMSG_DEATH_RELEASE_LOC
, 4*4); // show spirit healer position on minimap
4173 data
<< ClosestGrave
->map_id
;
4174 data
<< ClosestGrave
->x
;
4175 data
<< ClosestGrave
->y
;
4176 data
<< ClosestGrave
->z
;
4177 GetSession()->SendPacket(&data
);
4182 void Player::JoinedChannel(Channel
*c
)
4184 m_channels
.push_back(c
);
4187 void Player::LeftChannel(Channel
*c
)
4189 m_channels
.remove(c
);
4192 void Player::CleanupChannels()
4194 while(!m_channels
.empty())
4196 Channel
* ch
= *m_channels
.begin();
4197 m_channels
.erase(m_channels
.begin()); // remove from player's channel list
4198 ch
->Leave(GetGUID(), false); // not send to client, not remove from player's channel list
4199 if (ChannelMgr
* cMgr
= channelMgr(GetTeam()))
4200 cMgr
->LeftChannel(ch
->GetName()); // deleted channel if empty
4203 sLog
.outDebug("Player: channels cleaned up!");
4206 void Player::UpdateLocalChannels(uint32 newZone
)
4208 if(m_channels
.empty())
4211 AreaTableEntry
const* current_zone
= GetAreaEntryByAreaID(newZone
);
4215 ChannelMgr
* cMgr
= channelMgr(GetTeam());
4219 std::string current_zone_name
= current_zone
->area_name
[GetSession()->GetSessionDbcLocale()];
4221 for(JoinedChannelsList::iterator i
= m_channels
.begin(), next
; i
!= m_channels
.end(); i
= next
)
4225 // skip non built-in channels
4226 if(!(*i
)->IsConstant())
4229 ChatChannelsEntry
const* ch
= GetChannelEntryFor((*i
)->GetChannelId());
4233 if((ch
->flags
& 4) == 4) // global channel without zone name in pattern
4237 char new_channel_name_buf
[100];
4238 snprintf(new_channel_name_buf
,100,ch
->pattern
[m_session
->GetSessionDbcLocale()],current_zone_name
.c_str());
4239 Channel
* new_channel
= cMgr
->GetJoinChannel(new_channel_name_buf
,ch
->ChannelID
);
4241 if((*i
)!=new_channel
)
4243 new_channel
->Join(GetGUID(),""); // will output Changed Channel: N. Name
4245 // leave old channel
4246 (*i
)->Leave(GetGUID(),false); // not send leave channel, it already replaced at client
4247 std::string name
= (*i
)->GetName(); // store name, (*i)erase in LeftChannel
4248 LeftChannel(*i
); // remove from player's channel list
4249 cMgr
->LeftChannel(name
); // delete if empty
4252 sLog
.outDebug("Player: channels cleaned up!");
4255 void Player::LeaveLFGChannel()
4257 for(JoinedChannelsList::iterator i
= m_channels
.begin(); i
!= m_channels
.end(); ++i
)
4261 (*i
)->Leave(GetGUID());
4267 void Player::UpdateDefense()
4269 uint32 defense_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_DEFENSE
);
4271 if(UpdateSkill(SKILL_DEFENSE
,defense_skill_gain
))
4273 // update dependent from defense skill part
4274 UpdateDefenseBonusesMod();
4278 void Player::HandleBaseModValue(BaseModGroup modGroup
, BaseModType modType
, float amount
, bool apply
)
4280 if(modGroup
>= BASEMOD_END
|| modType
>= MOD_END
)
4282 sLog
.outError("ERROR in HandleBaseModValue(): non existed BaseModGroup of wrong BaseModType!");
4291 m_auraBaseMod
[modGroup
][modType
] += apply
? amount
: -amount
;
4294 if(amount
<= -100.0f
)
4297 val
= (100.0f
+ amount
) / 100.0f
;
4298 m_auraBaseMod
[modGroup
][modType
] *= apply
? val
: (1.0f
/val
);
4302 if(!CanModifyStats())
4307 case CRIT_PERCENTAGE
: UpdateCritPercentage(BASE_ATTACK
); break;
4308 case RANGED_CRIT_PERCENTAGE
: UpdateCritPercentage(RANGED_ATTACK
); break;
4309 case OFFHAND_CRIT_PERCENTAGE
: UpdateCritPercentage(OFF_ATTACK
); break;
4310 case SHIELD_BLOCK_VALUE
: UpdateShieldBlockValue(); break;
4315 float Player::GetBaseModValue(BaseModGroup modGroup
, BaseModType modType
) const
4317 if(modGroup
>= BASEMOD_END
|| modType
> MOD_END
)
4319 sLog
.outError("ERROR: trial to access non existed BaseModGroup or wrong BaseModType!");
4323 if(modType
== PCT_MOD
&& m_auraBaseMod
[modGroup
][PCT_MOD
] <= 0.0f
)
4326 return m_auraBaseMod
[modGroup
][modType
];
4329 float Player::GetTotalBaseModValue(BaseModGroup modGroup
) const
4331 if(modGroup
>= BASEMOD_END
)
4333 sLog
.outError("ERROR: wrong BaseModGroup in GetTotalBaseModValue()!");
4337 if(m_auraBaseMod
[modGroup
][PCT_MOD
] <= 0.0f
)
4340 return m_auraBaseMod
[modGroup
][FLAT_MOD
] * m_auraBaseMod
[modGroup
][PCT_MOD
];
4343 uint32
Player::GetShieldBlockValue() const
4345 BaseModGroup modGroup
= SHIELD_BLOCK_VALUE
;
4347 float value
= GetTotalBaseModValue(modGroup
) + GetStat(STAT_STRENGTH
)/20 - 1;
4349 value
= (value
< 0) ? 0 : value
;
4351 return uint32(value
);
4354 float Player::GetMeleeCritFromAgility()
4356 uint32 level
= getLevel();
4357 uint32 pclass
= getClass();
4359 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4361 GtChanceToMeleeCritBaseEntry
const *critBase
= sGtChanceToMeleeCritBaseStore
.LookupEntry(pclass
-1);
4362 GtChanceToMeleeCritEntry
const *critRatio
= sGtChanceToMeleeCritStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4363 if (critBase
==NULL
|| critRatio
==NULL
)
4366 float crit
=critBase
->base
+ GetStat(STAT_AGILITY
)*critRatio
->ratio
;
4370 float Player::GetDodgeFromAgility()
4372 // Table for base dodge values
4373 float dodge_base
[MAX_CLASSES
] = {
4375 0.00652f
, // Paladin
4382 0.02011f
, // Warlock
4386 // Crit/agility to dodge/agility coefficient multipliers
4387 float crit_to_dodge
[MAX_CLASSES
] = {
4401 uint32 level
= getLevel();
4402 uint32 pclass
= getClass();
4404 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4406 // Dodge per agility for most classes equal crit per agility (but for some classes need apply some multiplier)
4407 GtChanceToMeleeCritEntry
const *dodgeRatio
= sGtChanceToMeleeCritStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4408 if (dodgeRatio
==NULL
|| pclass
> MAX_CLASSES
)
4411 float dodge
=dodge_base
[pclass
-1] + GetStat(STAT_AGILITY
) * dodgeRatio
->ratio
* crit_to_dodge
[pclass
-1];
4412 return dodge
*100.0f
;
4415 float Player::GetSpellCritFromIntellect()
4417 uint32 level
= getLevel();
4418 uint32 pclass
= getClass();
4420 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4422 GtChanceToSpellCritBaseEntry
const *critBase
= sGtChanceToSpellCritBaseStore
.LookupEntry(pclass
-1);
4423 GtChanceToSpellCritEntry
const *critRatio
= sGtChanceToSpellCritStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4424 if (critBase
==NULL
|| critRatio
==NULL
)
4427 float crit
=critBase
->base
+ GetStat(STAT_INTELLECT
)*critRatio
->ratio
;
4431 float Player::GetRatingCoefficient(CombatRating cr
) const
4433 uint32 level
= getLevel();
4435 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4437 GtCombatRatingsEntry
const *Rating
= sGtCombatRatingsStore
.LookupEntry(cr
*GT_MAX_LEVEL
+level
-1);
4439 return 1.0f
; // By default use minimum coefficient (not must be called)
4441 return Rating
->ratio
;
4444 float Player::GetRatingBonusValue(CombatRating cr
) const
4446 return float(GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1
+ cr
)) / GetRatingCoefficient(cr
);
4449 uint32
Player::GetMeleeCritDamageReduction(uint32 damage
) const
4451 float melee
= GetRatingBonusValue(CR_CRIT_TAKEN_MELEE
)*2.0f
;
4452 if (melee
>25.0f
) melee
= 25.0f
;
4453 return uint32 (melee
* damage
/100.0f
);
4456 uint32
Player::GetRangedCritDamageReduction(uint32 damage
) const
4458 float ranged
= GetRatingBonusValue(CR_CRIT_TAKEN_RANGED
)*2.0f
;
4459 if (ranged
>25.0f
) ranged
=25.0f
;
4460 return uint32 (ranged
* damage
/100.0f
);
4463 uint32
Player::GetSpellCritDamageReduction(uint32 damage
) const
4465 float spell
= GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
)*2.0f
;
4466 // In wow script resilience limited to 25%
4469 return uint32 (spell
* damage
/ 100.0f
);
4472 uint32
Player::GetDotDamageReduction(uint32 damage
) const
4474 float spellDot
= GetRatingBonusValue(CR_CRIT_TAKEN_SPELL
);
4475 // Dot resilience not limited (limit it by 100%)
4476 if (spellDot
> 100.0f
)
4478 return uint32 (spellDot
* damage
/ 100.0f
);
4481 float Player::GetExpertiseDodgeOrParryReduction(WeaponAttackType attType
) const
4486 return GetUInt32Value(PLAYER_EXPERTISE
) / 4.0f
;
4488 return GetUInt32Value(PLAYER_OFFHAND_EXPERTISE
) / 4.0f
;
4495 float Player::OCTRegenHPPerSpirit()
4497 uint32 level
= getLevel();
4498 uint32 pclass
= getClass();
4500 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4502 GtOCTRegenHPEntry
const *baseRatio
= sGtOCTRegenHPStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4503 GtRegenHPPerSptEntry
const *moreRatio
= sGtRegenHPPerSptStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4504 if (baseRatio
==NULL
|| moreRatio
==NULL
)
4507 // Formula from PaperDollFrame script
4508 float spirit
= GetStat(STAT_SPIRIT
);
4509 float baseSpirit
= spirit
;
4510 if (baseSpirit
>50) baseSpirit
= 50;
4511 float moreSpirit
= spirit
- baseSpirit
;
4512 float regen
= baseSpirit
* baseRatio
->ratio
+ moreSpirit
* moreRatio
->ratio
;
4516 float Player::OCTRegenMPPerSpirit()
4518 uint32 level
= getLevel();
4519 uint32 pclass
= getClass();
4521 if (level
>GT_MAX_LEVEL
) level
= GT_MAX_LEVEL
;
4523 // GtOCTRegenMPEntry const *baseRatio = sGtOCTRegenMPStore.LookupEntry((pclass-1)*GT_MAX_LEVEL + level-1);
4524 GtRegenMPPerSptEntry
const *moreRatio
= sGtRegenMPPerSptStore
.LookupEntry((pclass
-1)*GT_MAX_LEVEL
+ level
-1);
4525 if (moreRatio
==NULL
)
4528 // Formula get from PaperDollFrame script
4529 float spirit
= GetStat(STAT_SPIRIT
);
4530 float regen
= spirit
* moreRatio
->ratio
;
4534 void Player::ApplyRatingMod(CombatRating cr
, int32 value
, bool apply
)
4536 ApplyModUInt32Value(PLAYER_FIELD_COMBAT_RATING_1
+ cr
, value
, apply
);
4538 float RatingCoeffecient
= GetRatingCoefficient(cr
);
4539 float RatingChange
= 0.0f
;
4541 bool affectStats
= CanModifyStats();
4545 case CR_WEAPON_SKILL
: // Implemented in Unit::RollMeleeOutcomeAgainst
4546 case CR_DEFENSE_SKILL
:
4547 UpdateDefenseBonusesMod();
4550 UpdateDodgePercentage();
4553 UpdateParryPercentage();
4556 UpdateBlockPercentage();
4559 RatingChange
= value
/ RatingCoeffecient
;
4560 m_modMeleeHitChance
+= apply
? RatingChange
: -RatingChange
;
4563 RatingChange
= value
/ RatingCoeffecient
;
4564 m_modRangedHitChance
+= apply
? RatingChange
: -RatingChange
;
4567 RatingChange
= value
/ RatingCoeffecient
;
4568 m_modSpellHitChance
+= apply
? RatingChange
: -RatingChange
;
4573 UpdateCritPercentage(BASE_ATTACK
);
4574 UpdateCritPercentage(OFF_ATTACK
);
4577 case CR_CRIT_RANGED
:
4579 UpdateCritPercentage(RANGED_ATTACK
);
4583 UpdateAllSpellCritChances();
4585 case CR_HIT_TAKEN_MELEE
: // Implemented in Unit::MeleeMissChanceCalc
4586 case CR_HIT_TAKEN_RANGED
:
4588 case CR_HIT_TAKEN_SPELL
: // Implemented in Unit::MagicSpellHitResult
4590 case CR_CRIT_TAKEN_MELEE
: // Implemented in Unit::RollMeleeOutcomeAgainst (only for chance to crit)
4591 case CR_CRIT_TAKEN_RANGED
:
4593 case CR_CRIT_TAKEN_SPELL
: // Implemented in Unit::SpellCriticalBonus (only for chance to crit)
4595 case CR_HASTE_MELEE
:
4596 RatingChange
= value
/ RatingCoeffecient
;
4597 ApplyAttackTimePercentMod(BASE_ATTACK
,RatingChange
,apply
);
4598 ApplyAttackTimePercentMod(OFF_ATTACK
,RatingChange
,apply
);
4600 case CR_HASTE_RANGED
:
4601 RatingChange
= value
/ RatingCoeffecient
;
4602 ApplyAttackTimePercentMod(RANGED_ATTACK
, RatingChange
, apply
);
4604 case CR_HASTE_SPELL
:
4605 RatingChange
= value
/ RatingCoeffecient
;
4606 ApplyCastTimePercentMod(RatingChange
,apply
);
4608 case CR_WEAPON_SKILL_MAINHAND
: // Implemented in Unit::RollMeleeOutcomeAgainst
4609 case CR_WEAPON_SKILL_OFFHAND
:
4610 case CR_WEAPON_SKILL_RANGED
:
4615 UpdateExpertise(BASE_ATTACK
);
4616 UpdateExpertise(OFF_ATTACK
);
4622 void Player::SetRegularAttackTime()
4624 for(int i
= 0; i
< MAX_ATTACK
; ++i
)
4626 Item
*tmpitem
= GetWeaponForAttack(WeaponAttackType(i
));
4627 if(tmpitem
&& !tmpitem
->IsBroken())
4629 ItemPrototype
const *proto
= tmpitem
->GetProto();
4631 SetAttackTime(WeaponAttackType(i
), proto
->Delay
);
4633 SetAttackTime(WeaponAttackType(i
), BASE_ATTACK_TIME
);
4638 //skill+step, checking for max value
4639 bool Player::UpdateSkill(uint32 skill_id
, uint32 step
)
4645 for (; i
< PLAYER_MAX_SKILLS
; i
++)
4646 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill_id
)
4649 if(i
>=PLAYER_MAX_SKILLS
)
4652 uint32 data
= GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
));
4653 uint32 value
= SKILL_VALUE(data
);
4654 uint32 max
= SKILL_MAX(data
);
4656 if ((!max
) || (!value
) || (value
>= max
))
4659 if (value
*512 < max
*urand(0,512))
4661 uint32 new_value
= value
+step
;
4665 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(new_value
,max
));
4666 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
);
4673 inline int SkillGainChance(uint32 SkillValue
, uint32 GrayLevel
, uint32 GreenLevel
, uint32 YellowLevel
)
4675 if ( SkillValue
>= GrayLevel
)
4676 return sWorld
.getConfig(CONFIG_SKILL_CHANCE_GREY
)*10;
4677 if ( SkillValue
>= GreenLevel
)
4678 return sWorld
.getConfig(CONFIG_SKILL_CHANCE_GREEN
)*10;
4679 if ( SkillValue
>= YellowLevel
)
4680 return sWorld
.getConfig(CONFIG_SKILL_CHANCE_YELLOW
)*10;
4681 return sWorld
.getConfig(CONFIG_SKILL_CHANCE_ORANGE
)*10;
4684 bool Player::UpdateCraftSkill(uint32 spellid
)
4686 sLog
.outDebug("UpdateCraftSkill spellid %d", spellid
);
4688 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(spellid
);
4689 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(spellid
);
4691 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
4693 if(_spell_idx
->second
->skillId
)
4695 uint32 SkillValue
= GetPureSkillValue(_spell_idx
->second
->skillId
);
4697 // Alchemy Discoveries here
4698 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellid
);
4699 if(spellEntry
&& spellEntry
->Mechanic
==MECHANIC_DISCOVERY
)
4701 if(uint32 discoveredSpell
= GetSkillDiscoverySpell(_spell_idx
->second
->skillId
, spellid
, this))
4702 learnSpell(discoveredSpell
);
4705 uint32 craft_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_CRAFTING
);
4707 return UpdateSkillPro(_spell_idx
->second
->skillId
, SkillGainChance(SkillValue
,
4708 _spell_idx
->second
->max_value
,
4709 (_spell_idx
->second
->max_value
+ _spell_idx
->second
->min_value
)/2,
4710 _spell_idx
->second
->min_value
),
4717 bool Player::UpdateGatherSkill(uint32 SkillId
, uint32 SkillValue
, uint32 RedLevel
, uint32 Multiplicator
)
4719 sLog
.outDebug("UpdateGatherSkill(SkillId %d SkillLevel %d RedLevel %d)", SkillId
, SkillValue
, RedLevel
);
4721 uint32 gathering_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_GATHERING
);
4723 // For skinning and Mining chance decrease with level. 1-74 - no decrease, 75-149 - 2 times, 225-299 - 8 times
4726 case SKILL_HERBALISM
:
4727 case SKILL_LOCKPICKING
:
4728 case SKILL_JEWELCRAFTING
:
4729 case SKILL_INSCRIPTION
:
4730 return UpdateSkillPro(SkillId
, SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
,gathering_skill_gain
);
4731 case SKILL_SKINNING
:
4732 if( sWorld
.getConfig(CONFIG_SKILL_CHANCE_SKINNING_STEPS
)==0)
4733 return UpdateSkillPro(SkillId
, SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
,gathering_skill_gain
);
4735 return UpdateSkillPro(SkillId
, (SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
) >> (SkillValue
/sWorld
.getConfig(CONFIG_SKILL_CHANCE_SKINNING_STEPS
)), gathering_skill_gain
);
4737 if (sWorld
.getConfig(CONFIG_SKILL_CHANCE_MINING_STEPS
)==0)
4738 return UpdateSkillPro(SkillId
, SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
,gathering_skill_gain
);
4740 return UpdateSkillPro(SkillId
, (SkillGainChance(SkillValue
, RedLevel
+100, RedLevel
+50, RedLevel
+25)*Multiplicator
) >> (SkillValue
/sWorld
.getConfig(CONFIG_SKILL_CHANCE_MINING_STEPS
)),gathering_skill_gain
);
4745 bool Player::UpdateFishingSkill()
4747 sLog
.outDebug("UpdateFishingSkill");
4749 uint32 SkillValue
= GetPureSkillValue(SKILL_FISHING
);
4751 int32 chance
= SkillValue
< 75 ? 100 : 2500/(SkillValue
-50);
4753 uint32 gathering_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_GATHERING
);
4755 return UpdateSkillPro(SKILL_FISHING
,chance
*10,gathering_skill_gain
);
4758 bool Player::UpdateSkillPro(uint16 SkillId
, int32 Chance
, uint32 step
)
4760 sLog
.outDebug("UpdateSkillPro(SkillId %d, Chance %3.1f%%)", SkillId
, Chance
/10.0);
4764 if(Chance
<= 0) // speedup in 0 chance case
4766 sLog
.outDebug("Player::UpdateSkillPro Chance=%3.1f%% missed", Chance
/10.0);
4771 for (; i
< PLAYER_MAX_SKILLS
; i
++)
4772 if ( SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_INDEX(i
))) == SkillId
) break;
4773 if ( i
>= PLAYER_MAX_SKILLS
)
4776 uint32 data
= GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
));
4777 uint16 SkillValue
= SKILL_VALUE(data
);
4778 uint16 MaxValue
= SKILL_MAX(data
);
4780 if ( !MaxValue
|| !SkillValue
|| SkillValue
>= MaxValue
)
4783 int32 Roll
= irand(1,1000);
4785 if ( Roll
<= Chance
)
4787 uint32 new_value
= SkillValue
+step
;
4788 if(new_value
> MaxValue
)
4789 new_value
= MaxValue
;
4791 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(new_value
,MaxValue
));
4792 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
);
4793 sLog
.outDebug("Player::UpdateSkillPro Chance=%3.1f%% taken", Chance
/10.0);
4797 sLog
.outDebug("Player::UpdateSkillPro Chance=%3.1f%% missed", Chance
/10.0);
4801 void Player::UpdateWeaponSkill (WeaponAttackType attType
)
4803 // no skill gain in pvp
4804 Unit
*pVictim
= getVictim();
4805 if(pVictim
&& pVictim
->GetTypeId() == TYPEID_PLAYER
)
4809 return; // always maximized SKILL_FERAL_COMBAT in fact
4811 if(m_form
== FORM_TREE
)
4812 return; // use weapon but not skill up
4814 uint32 weapon_skill_gain
= sWorld
.getConfig(CONFIG_SKILL_GAIN_WEAPON
);
4820 Item
*tmpitem
= GetWeaponForAttack(attType
,true);
4823 UpdateSkill(SKILL_UNARMED
,weapon_skill_gain
);
4824 else if(tmpitem
->GetProto()->SubClass
!= ITEM_SUBCLASS_WEAPON_FISHING_POLE
)
4825 UpdateSkill(tmpitem
->GetSkill(),weapon_skill_gain
);
4831 Item
*tmpitem
= GetWeaponForAttack(attType
,true);
4833 UpdateSkill(tmpitem
->GetSkill(),weapon_skill_gain
);
4837 UpdateAllCritPercentages();
4840 void Player::UpdateCombatSkills(Unit
*pVictim
, WeaponAttackType attType
, MeleeHitOutcome outcome
, bool defence
)
4844 case MELEE_HIT_CRIT
:
4845 case MELEE_HIT_DODGE
:
4846 case MELEE_HIT_PARRY
:
4847 case MELEE_HIT_BLOCK
:
4848 case MELEE_HIT_BLOCK_CRIT
:
4855 uint32 plevel
= getLevel(); // if defense than pVictim == attacker
4856 uint32 greylevel
= MaNGOS::XP::GetGrayLevel(plevel
);
4857 uint32 moblevel
= pVictim
->getLevelForTarget(this);
4858 if(moblevel
< greylevel
)
4861 if (moblevel
> plevel
+ 5)
4862 moblevel
= plevel
+ 5;
4864 uint32 lvldif
= moblevel
- greylevel
;
4868 uint32 skilldif
= 5 * plevel
- (defence
? GetBaseDefenseSkillValue() : GetBaseWeaponSkillValue(attType
));
4872 float chance
= float(3 * lvldif
* skilldif
) / plevel
;
4875 if(getClass() == CLASS_WARRIOR
|| getClass() == CLASS_ROGUE
)
4876 chance
*= 0.1f
* GetStat(STAT_INTELLECT
);
4879 chance
= chance
< 1.0f
? 1.0f
: chance
; //minimum chance to increase skill is 1%
4881 if(roll_chance_f(chance
))
4886 UpdateWeaponSkill(attType
);
4892 void Player::ModifySkillBonus(uint32 skillid
,int32 val
, bool talent
)
4894 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
4895 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skillid
)
4897 uint32 bonus_val
= GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
));
4898 int16 temp_bonus
= SKILL_TEMP_BONUS(bonus_val
);
4899 int16 perm_bonus
= SKILL_PERM_BONUS(bonus_val
);
4901 if(talent
) // permanent bonus stored in high part
4902 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),MAKE_SKILL_BONUS(temp_bonus
,perm_bonus
+val
));
4903 else // temporary/item bonus stored in low part
4904 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),MAKE_SKILL_BONUS(temp_bonus
+val
,perm_bonus
));
4909 void Player::UpdateMaxSkills()
4911 uint16 maxconfskill
= sWorld
.GetConfigMaxSkillValue();
4913 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
4914 if (GetUInt32Value(PLAYER_SKILL_INDEX(i
)))
4916 uint32 pskill
= GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF;
4918 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(pskill
);
4922 if(GetSkillRangeType(pSkill
,false) != SKILL_RANGE_LEVEL
)
4925 uint32 data
= GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
));
4926 uint32 max
= SKILL_MAX(data
);
4927 uint32 val
= SKILL_VALUE(data
);
4929 // update only level dependent max skill values
4930 if(max
!=1 && max
!= maxconfskill
)
4932 uint32 max_Skill
= GetMaxSkillValueForLevel();
4933 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(val
,max_Skill
));
4938 void Player::UpdateSkillsToMaxSkillsForLevel()
4940 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
4941 if (GetUInt32Value(PLAYER_SKILL_INDEX(i
)))
4943 uint32 pskill
= GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF;
4944 if( IsProfessionSkill(pskill
) || pskill
== SKILL_RIDING
)
4946 uint32 data
= GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
));
4948 uint32 max
= SKILL_MAX(data
);
4951 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(max
,max
));
4953 if(pskill
== SKILL_DEFENSE
)
4954 UpdateDefenseBonusesMod();
4958 // This functions sets a skill line value (and adds if doesn't exist yet)
4959 // To "remove" a skill line, set it's values to zero
4960 void Player::SetSkill(uint32 id
, uint16 currVal
, uint16 maxVal
)
4966 for (; i
< PLAYER_MAX_SKILLS
; i
++)
4967 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == id
) break;
4969 if(i
<PLAYER_MAX_SKILLS
) //has skill
4973 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(currVal
,maxVal
));
4974 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
);
4978 // clear skill fields
4979 SetUInt32Value(PLAYER_SKILL_INDEX(i
),0);
4980 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),0);
4981 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),0);
4983 // remove spells that depend on this skill when removing the skill
4984 for (PlayerSpellMap::const_iterator itr
= m_spells
.begin(), next
= m_spells
.begin(); itr
!= m_spells
.end(); itr
= next
)
4987 if(itr
->second
->state
== PLAYERSPELL_REMOVED
)
4990 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(itr
->first
);
4991 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(itr
->first
);
4993 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
4995 if (_spell_idx
->second
->skillId
== id
)
4997 // this may remove more than one spell (dependents)
4998 removeSpell(itr
->first
);
4999 next
= m_spells
.begin();
5006 else if(currVal
) //add
5008 for (i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5009 if (!GetUInt32Value(PLAYER_SKILL_INDEX(i
)))
5011 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(id
);
5014 sLog
.outError("Skill not found in SkillLineStore: skill #%u", id
);
5017 // enable unlearn button for primary professions only
5018 if (pSkill
->categoryId
== SKILL_CATEGORY_PROFESSION
)
5019 SetUInt32Value(PLAYER_SKILL_INDEX(i
), MAKE_PAIR32(id
,1));
5021 SetUInt32Value(PLAYER_SKILL_INDEX(i
), MAKE_PAIR32(id
,0));
5022 SetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
),MAKE_SKILL_VALUE(currVal
,maxVal
));
5023 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
);
5025 // apply skill bonuses
5026 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),0);
5028 // temporary bonuses
5029 AuraList
const& mModSkill
= GetAurasByType(SPELL_AURA_MOD_SKILL
);
5030 for(AuraList::const_iterator i
= mModSkill
.begin(); i
!= mModSkill
.end(); ++i
)
5031 if ((*i
)->GetModifier()->m_miscvalue
== int32(id
))
5032 (*i
)->ApplyModifier(true);
5034 // permanent bonuses
5035 AuraList
const& mModSkillTalent
= GetAurasByType(SPELL_AURA_MOD_SKILL_TALENT
);
5036 for(AuraList::const_iterator i
= mModSkillTalent
.begin(); i
!= mModSkillTalent
.end(); ++i
)
5037 if ((*i
)->GetModifier()->m_miscvalue
== int32(id
))
5038 (*i
)->ApplyModifier(true);
5040 // Learn all spells for skill
5041 learnSkillRewardedSpells(id
);
5047 bool Player::HasSkill(uint32 skill
) const
5049 if(!skill
)return false;
5050 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5052 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5060 uint16
Player::GetSkillValue(uint32 skill
) const
5065 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5067 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5069 uint32 bonus
= GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
));
5071 int32 result
= int32(SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
))));
5072 result
+= SKILL_TEMP_BONUS(bonus
);
5073 result
+= SKILL_PERM_BONUS(bonus
);
5074 return result
< 0 ? 0 : result
;
5080 uint16
Player::GetMaxSkillValue(uint32 skill
) const
5083 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5085 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5087 uint32 bonus
= GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
));
5089 int32 result
= int32(SKILL_MAX(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
))));
5090 result
+= SKILL_TEMP_BONUS(bonus
);
5091 result
+= SKILL_PERM_BONUS(bonus
);
5092 return result
< 0 ? 0 : result
;
5098 uint16
Player::GetPureMaxSkillValue(uint32 skill
) const
5101 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5103 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5105 return SKILL_MAX(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
)));
5111 uint16
Player::GetBaseSkillValue(uint32 skill
) const
5114 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5116 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5118 int32 result
= int32(SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
))));
5119 result
+= SKILL_PERM_BONUS(GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
)));
5120 return result
< 0 ? 0 : result
;
5126 uint16
Player::GetPureSkillValue(uint32 skill
) const
5129 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
5131 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5133 return SKILL_VALUE(GetUInt32Value(PLAYER_SKILL_VALUE_INDEX(i
)));
5139 int16
Player::GetSkillTempBonusValue(uint32 skill
) const
5144 for (int i
= 0; i
< PLAYER_MAX_SKILLS
; i
++)
5146 if ((GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF) == skill
)
5148 return SKILL_TEMP_BONUS(GetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
)));
5155 void Player::SendInitialActionButtons()
5157 sLog
.outDetail( "Initializing Action Buttons for '%u'", GetGUIDLow() );
5159 WorldPacket
data(SMSG_ACTION_BUTTONS
, (MAX_ACTION_BUTTONS
*4));
5160 for(int button
= 0; button
< MAX_ACTION_BUTTONS
; ++button
)
5162 ActionButtonList::const_iterator itr
= m_actionButtons
.find(button
);
5163 if(itr
!= m_actionButtons
.end() && itr
->second
.uState
!= ACTIONBUTTON_DELETED
)
5165 data
<< uint16(itr
->second
.action
);
5166 data
<< uint8(itr
->second
.misc
);
5167 data
<< uint8(itr
->second
.type
);
5175 GetSession()->SendPacket( &data
);
5176 sLog
.outDetail( "Action Buttons for '%u' Initialized", GetGUIDLow() );
5179 void Player::addActionButton(const uint8 button
, const uint16 action
, const uint8 type
, const uint8 misc
)
5181 if(button
>= MAX_ACTION_BUTTONS
)
5183 sLog
.outError( "Action %u not added into button %u for player %s: button must be < 132", action
, button
, GetName() );
5187 // check cheating with adding non-known spells to action bar
5188 if(type
==ACTION_BUTTON_SPELL
)
5190 if(!sSpellStore
.LookupEntry(action
))
5192 sLog
.outError( "Action %u not added into button %u for player %s: spell not exist", action
, button
, GetName() );
5196 if(!HasSpell(action
))
5198 sLog
.outError( "Action %u not added into button %u for player %s: player don't known this spell", action
, button
, GetName() );
5203 ActionButtonList::iterator buttonItr
= m_actionButtons
.find(button
);
5205 if (buttonItr
==m_actionButtons
.end())
5206 { // just add new button
5207 m_actionButtons
[button
] = ActionButton(action
,type
,misc
);
5210 { // change state of current button
5211 ActionButtonUpdateState uState
= buttonItr
->second
.uState
;
5212 buttonItr
->second
= ActionButton(action
,type
,misc
);
5213 if (uState
!= ACTIONBUTTON_NEW
) buttonItr
->second
.uState
= ACTIONBUTTON_CHANGED
;
5216 sLog
.outDetail( "Player '%u' Added Action '%u' to Button '%u'", GetGUIDLow(), action
, button
);
5219 void Player::removeActionButton(uint8 button
)
5221 ActionButtonList::iterator buttonItr
= m_actionButtons
.find(button
);
5222 if (buttonItr
==m_actionButtons
.end())
5225 if(buttonItr
->second
.uState
==ACTIONBUTTON_NEW
)
5226 m_actionButtons
.erase(buttonItr
); // new and not saved
5228 buttonItr
->second
.uState
= ACTIONBUTTON_DELETED
; // saved, will deleted at next save
5230 sLog
.outDetail( "Action Button '%u' Removed from Player '%u'", button
, GetGUIDLow() );
5233 void Player::SetDontMove(bool dontMove
)
5235 m_dontMove
= dontMove
;
5238 bool Player::SetPosition(float x
, float y
, float z
, float orientation
, bool teleport
)
5240 // prevent crash when a bad coord is sent by the client
5241 if(!MaNGOS::IsValidMapCoord(x
,y
,z
,orientation
))
5243 sLog
.outDebug("Player::SetPosition(%f, %f, %f, %f, %d) .. bad coordinates for player %d!",x
,y
,z
,orientation
,teleport
,GetGUIDLow());
5249 const float old_x
= GetPositionX();
5250 const float old_y
= GetPositionY();
5251 const float old_z
= GetPositionZ();
5252 const float old_r
= GetOrientation();
5254 if( teleport
|| old_x
!= x
|| old_y
!= y
|| old_z
!= z
|| old_r
!= orientation
)
5256 if (teleport
|| old_x
!= x
|| old_y
!= y
|| old_z
!= z
)
5257 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOVE
| AURA_INTERRUPT_FLAG_TURNING
);
5259 RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_TURNING
);
5261 // move and update visible state if need
5262 m
->PlayerRelocation(this, x
, y
, z
, orientation
);
5264 // reread after Map::Relocation
5271 if(GetGroup() && (old_x
!= x
|| old_y
!= y
))
5272 SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POSITION
);
5275 // code block for underwater state update
5276 UpdateUnderwaterState(m
, x
, y
, z
);
5278 CheckExploreSystem();
5283 void Player::SaveRecallPosition()
5285 m_recallMap
= GetMapId();
5286 m_recallX
= GetPositionX();
5287 m_recallY
= GetPositionY();
5288 m_recallZ
= GetPositionZ();
5289 m_recallO
= GetOrientation();
5292 void Player::SendMessageToSet(WorldPacket
*data
, bool self
)
5294 GetMap()->MessageBroadcast(this, data
, self
);
5297 void Player::SendMessageToSetInRange(WorldPacket
*data
, float dist
, bool self
)
5299 GetMap()->MessageDistBroadcast(this, data
, dist
, self
);
5302 void Player::SendMessageToSetInRange(WorldPacket
*data
, float dist
, bool self
, bool own_team_only
)
5304 GetMap()->MessageDistBroadcast(this, data
, dist
, self
,own_team_only
);
5307 void Player::SendDirectMessage(WorldPacket
*data
)
5309 GetSession()->SendPacket(data
);
5312 void Player::CheckExploreSystem()
5320 uint16 areaFlag
=MapManager::Instance().GetBaseMap(GetMapId())->GetAreaFlag(GetPositionX(),GetPositionY());
5321 if(areaFlag
==0xffff)
5323 int offset
= areaFlag
/ 32;
5327 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
);
5331 uint32 val
= (uint32
)(1 << (areaFlag
% 32));
5332 uint32 currFields
= GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
5334 if( !(currFields
& val
) )
5336 SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
5338 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EXPLORE_AREA
);
5340 AreaTableEntry
const *p
= GetAreaEntryByAreaFlagAndMap(areaFlag
,GetMapId());
5343 sLog
.outError("PLAYER: Player %u discovered unknown area (x: %f y: %f map: %u", GetGUIDLow(), GetPositionX(),GetPositionY(),GetMapId());
5345 else if(p
->area_level
> 0)
5347 uint32 area
= p
->ID
;
5348 if (getLevel() >= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
5350 SendExplorationExperience(area
,0);
5354 int32 diff
= int32(getLevel()) - p
->area_level
;
5358 XP
= uint32(objmgr
.GetBaseXP(getLevel()+5)*sWorld
.getRate(RATE_XP_EXPLORE
));
5362 int32 exploration_percent
= (100-((diff
-5)*5));
5363 if (exploration_percent
> 100)
5364 exploration_percent
= 100;
5365 else if (exploration_percent
< 0)
5366 exploration_percent
= 0;
5368 XP
= uint32(objmgr
.GetBaseXP(p
->area_level
)*exploration_percent
/100*sWorld
.getRate(RATE_XP_EXPLORE
));
5372 XP
= uint32(objmgr
.GetBaseXP(p
->area_level
)*sWorld
.getRate(RATE_XP_EXPLORE
));
5376 SendExplorationExperience(area
,XP
);
5378 sLog
.outDetail("PLAYER: Player %u discovered a new area: %u", GetGUIDLow(), area
);
5383 uint32
Player::TeamForRace(uint8 race
)
5385 ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(race
);
5388 sLog
.outError("Race %u not found in DBC: wrong DBC files?",uint32(race
));
5392 switch(rEntry
->TeamID
)
5394 case 7: return ALLIANCE
;
5395 case 1: return HORDE
;
5398 sLog
.outError("Race %u have wrong team id in DBC: wrong DBC files?",uint32(race
),rEntry
->TeamID
);
5402 uint32
Player::getFactionForRace(uint8 race
)
5404 ChrRacesEntry
const* rEntry
= sChrRacesStore
.LookupEntry(race
);
5407 sLog
.outError("Race %u not found in DBC: wrong DBC files?",uint32(race
));
5411 return rEntry
->FactionID
;
5414 void Player::setFactionForRace(uint8 race
)
5416 m_team
= TeamForRace(race
);
5417 setFaction( getFactionForRace(race
) );
5420 void Player::UpdateReputation() const
5422 sLog
.outDetail( "WORLD: Player::UpdateReputation" );
5424 for(FactionStateList::const_iterator itr
= m_factions
.begin(); itr
!= m_factions
.end(); ++itr
)
5426 SendFactionState(&(itr
->second
));
5430 void Player::SendFactionState(FactionState
const* faction
) const
5432 if(faction
->Flags
& FACTION_FLAG_VISIBLE
) //If faction is visible then update it
5434 WorldPacket
data(SMSG_SET_FACTION_STANDING
, (16)); // last check 2.4.0
5435 data
<< (float) 0; // unk 2.4.0
5436 data
<< (uint8
) 0; // wotlk 8634
5437 data
<< (uint32
) 1; // count
5439 data
<< (uint32
) faction
->ReputationListID
;
5440 data
<< (uint32
) faction
->Standing
;
5442 GetSession()->SendPacket(&data
);
5446 void Player::SendInitialReputations()
5448 WorldPacket
data(SMSG_INITIALIZE_FACTIONS
, (4+128*5));
5449 data
<< uint32 (0x00000080);
5453 for (FactionStateList::const_iterator itr
= m_factions
.begin(); itr
!= m_factions
.end(); itr
++)
5455 // fill in absent fields
5456 for (; a
!= itr
->first
; a
++)
5458 data
<< uint8 (0x00);
5459 data
<< uint32 (0x00000000);
5462 // fill in encountered data
5463 data
<< uint8 (itr
->second
.Flags
);
5464 data
<< uint32 (itr
->second
.Standing
);
5469 // fill in absent fields
5470 for (; a
!= 128; a
++)
5472 data
<< uint8 (0x00);
5473 data
<< uint32 (0x00000000);
5476 GetSession()->SendPacket(&data
);
5479 FactionState
const* Player::GetFactionState( FactionEntry
const* factionEntry
) const
5481 FactionStateList::const_iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5482 if (itr
!= m_factions
.end())
5483 return &itr
->second
;
5488 void Player::SetFactionAtWar(FactionState
* faction
, bool atWar
)
5490 // not allow declare war to own faction
5491 if(atWar
&& (faction
->Flags
& FACTION_FLAG_PEACE_FORCED
) )
5495 if(((faction
->Flags
& FACTION_FLAG_AT_WAR
) != 0) == atWar
)
5499 faction
->Flags
|= FACTION_FLAG_AT_WAR
;
5501 faction
->Flags
&= ~FACTION_FLAG_AT_WAR
;
5503 faction
->Changed
= true;
5506 void Player::SetFactionInactive(FactionState
* faction
, bool inactive
)
5508 // always invisible or hidden faction can't be inactive
5509 if(inactive
&& ((faction
->Flags
& (FACTION_FLAG_INVISIBLE_FORCED
|FACTION_FLAG_HIDDEN
)) || !(faction
->Flags
& FACTION_FLAG_VISIBLE
) ) )
5513 if(((faction
->Flags
& FACTION_FLAG_INACTIVE
) != 0) == inactive
)
5517 faction
->Flags
|= FACTION_FLAG_INACTIVE
;
5519 faction
->Flags
&= ~FACTION_FLAG_INACTIVE
;
5521 faction
->Changed
= true;
5524 void Player::SetFactionVisibleForFactionTemplateId(uint32 FactionTemplateId
)
5526 FactionTemplateEntry
const*factionTemplateEntry
= sFactionTemplateStore
.LookupEntry(FactionTemplateId
);
5528 if(!factionTemplateEntry
)
5531 SetFactionVisibleForFactionId(factionTemplateEntry
->faction
);
5534 void Player::SetFactionVisibleForFactionId(uint32 FactionId
)
5536 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(FactionId
);
5540 if(factionEntry
->reputationListID
< 0)
5543 FactionStateList::iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5544 if (itr
== m_factions
.end())
5547 SetFactionVisible(&itr
->second
);
5550 void Player::SetFactionVisible(FactionState
* faction
)
5552 // always invisible or hidden faction can't be make visible
5553 if(faction
->Flags
& (FACTION_FLAG_INVISIBLE_FORCED
|FACTION_FLAG_HIDDEN
))
5557 if(faction
->Flags
& FACTION_FLAG_VISIBLE
)
5560 faction
->Flags
|= FACTION_FLAG_VISIBLE
;
5561 faction
->Changed
= true;
5563 if(!m_session
->PlayerLoading())
5565 // make faction visible in reputation list at client
5566 WorldPacket
data(SMSG_SET_FACTION_VISIBLE
, 4);
5567 data
<< faction
->ReputationListID
;
5568 GetSession()->SendPacket(&data
);
5572 void Player::SetInitialFactions()
5574 for(unsigned int i
= 1; i
< sFactionStore
.GetNumRows(); i
++)
5576 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(i
);
5578 if( factionEntry
&& (factionEntry
->reputationListID
>= 0))
5580 FactionState newFaction
;
5581 newFaction
.ID
= factionEntry
->ID
;
5582 newFaction
.ReputationListID
= factionEntry
->reputationListID
;
5583 newFaction
.Standing
= 0;
5584 newFaction
.Flags
= GetDefaultReputationFlags(factionEntry
);
5585 newFaction
.Changed
= true;
5587 m_factions
[newFaction
.ReputationListID
] = newFaction
;
5592 uint32
Player::GetDefaultReputationFlags(const FactionEntry
*factionEntry
) const
5597 uint32 raceMask
= getRaceMask();
5598 uint32 classMask
= getClassMask();
5599 for (int i
=0; i
< 4; i
++)
5601 if( (factionEntry
->BaseRepRaceMask
[i
] & raceMask
) &&
5602 (factionEntry
->BaseRepClassMask
[i
]==0 ||
5603 (factionEntry
->BaseRepClassMask
[i
] & classMask
) ) )
5604 return factionEntry
->ReputationFlags
[i
];
5609 int32
Player::GetBaseReputation(const FactionEntry
*factionEntry
) const
5614 uint32 raceMask
= getRaceMask();
5615 uint32 classMask
= getClassMask();
5616 for (int i
=0; i
< 4; i
++)
5618 if( (factionEntry
->BaseRepRaceMask
[i
] & raceMask
) &&
5619 (factionEntry
->BaseRepClassMask
[i
]==0 ||
5620 (factionEntry
->BaseRepClassMask
[i
] & classMask
) ) )
5621 return factionEntry
->BaseRepValue
[i
];
5624 // in faction.dbc exist factions with (RepListId >=0, listed in character reputation list) with all BaseRepRaceMask[i]==0
5628 int32
Player::GetReputation(uint32 faction_id
) const
5630 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(faction_id
);
5634 sLog
.outError("Player::GetReputation: Can't get reputation of %s for unknown faction (faction template id) #%u.",GetName(), faction_id
);
5638 return GetReputation(factionEntry
);
5641 int32
Player::GetReputation(const FactionEntry
*factionEntry
) const
5643 // Faction without recorded reputation. Just ignore.
5647 FactionStateList::const_iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5648 if (itr
!= m_factions
.end())
5649 return GetBaseReputation(factionEntry
) + itr
->second
.Standing
;
5654 ReputationRank
Player::GetReputationRank(uint32 faction
) const
5656 FactionEntry
const*factionEntry
= sFactionStore
.LookupEntry(faction
);
5658 return MIN_REPUTATION_RANK
;
5660 return GetReputationRank(factionEntry
);
5663 ReputationRank
Player::ReputationToRank(int32 standing
) const
5665 int32 Limit
= Reputation_Cap
+ 1;
5666 for (int i
= MAX_REPUTATION_RANK
-1; i
>= MIN_REPUTATION_RANK
; --i
)
5668 Limit
-= ReputationRank_Length
[i
];
5669 if (standing
>= Limit
)
5670 return ReputationRank(i
);
5672 return MIN_REPUTATION_RANK
;
5675 ReputationRank
Player::GetReputationRank(const FactionEntry
*factionEntry
) const
5677 int32 Reputation
= GetReputation(factionEntry
);
5678 return ReputationToRank(Reputation
);
5681 ReputationRank
Player::GetBaseReputationRank(const FactionEntry
*factionEntry
) const
5683 int32 Reputation
= GetBaseReputation(factionEntry
);
5684 return ReputationToRank(Reputation
);
5687 bool Player::ModifyFactionReputation(uint32 FactionTemplateId
, int32 DeltaReputation
)
5689 FactionTemplateEntry
const* factionTemplateEntry
= sFactionTemplateStore
.LookupEntry(FactionTemplateId
);
5691 if(!factionTemplateEntry
)
5693 sLog
.outError("Player::ModifyFactionReputation: Can't update reputation of %s for unknown faction (faction template id) #%u.", GetName(), FactionTemplateId
);
5697 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(factionTemplateEntry
->faction
);
5699 // Faction without recorded reputation. Just ignore.
5703 return ModifyFactionReputation(factionEntry
, DeltaReputation
);
5706 bool Player::ModifyFactionReputation(FactionEntry
const* factionEntry
, int32 standing
)
5708 SimpleFactionsList
const* flist
= GetFactionTeamList(factionEntry
->ID
);
5712 for (SimpleFactionsList::const_iterator itr
= flist
->begin();itr
!= flist
->end();++itr
)
5714 FactionEntry
const *factionEntryCalc
= sFactionStore
.LookupEntry(*itr
);
5715 if(factionEntryCalc
)
5716 res
= ModifyOneFactionReputation(factionEntryCalc
, standing
);
5721 return ModifyOneFactionReputation(factionEntry
, standing
);
5724 bool Player::ModifyOneFactionReputation(FactionEntry
const* factionEntry
, int32 standing
)
5726 FactionStateList::iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5727 if (itr
!= m_factions
.end())
5729 int32 BaseRep
= GetBaseReputation(factionEntry
);
5730 int32 new_rep
= BaseRep
+ itr
->second
.Standing
+ standing
;
5732 if (new_rep
> Reputation_Cap
)
5733 new_rep
= Reputation_Cap
;
5735 if (new_rep
< Reputation_Bottom
)
5736 new_rep
= Reputation_Bottom
;
5738 if(ReputationToRank(new_rep
) <= REP_HOSTILE
)
5739 SetFactionAtWar(&itr
->second
,true);
5741 itr
->second
.Standing
= new_rep
- BaseRep
;
5742 itr
->second
.Changed
= true;
5744 SetFactionVisible(&itr
->second
);
5746 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
5748 if(uint32 questid
= GetQuestSlotQuestId(i
))
5750 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
5751 if( qInfo
&& qInfo
->GetRepObjectiveFaction() == factionEntry
->ID
)
5753 QuestStatusData
& q_status
= mQuestStatus
[questid
];
5754 if( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
5756 if(GetReputation(factionEntry
) >= qInfo
->GetRepObjectiveValue())
5757 if ( CanCompleteQuest( questid
) )
5758 CompleteQuest( questid
);
5760 else if( q_status
.m_status
== QUEST_STATUS_COMPLETE
)
5762 if(GetReputation(factionEntry
) < qInfo
->GetRepObjectiveValue())
5763 IncompleteQuest( questid
);
5768 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION
);
5769 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION
);
5770 SendFactionState(&(itr
->second
));
5777 bool Player::SetFactionReputation(uint32 FactionTemplateId
, int32 standing
)
5779 FactionTemplateEntry
const* factionTemplateEntry
= sFactionTemplateStore
.LookupEntry(FactionTemplateId
);
5781 if(!factionTemplateEntry
)
5783 sLog
.outError("Player::SetFactionReputation: Can't set reputation of %s for unknown faction (faction template id) #%u.", GetName(), FactionTemplateId
);
5787 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(factionTemplateEntry
->faction
);
5789 // Faction without recorded reputation. Just ignore.
5793 return SetFactionReputation(factionEntry
, standing
);
5796 bool Player::SetFactionReputation(FactionEntry
const* factionEntry
, int32 standing
)
5798 SimpleFactionsList
const* flist
= GetFactionTeamList(factionEntry
->ID
);
5802 for (SimpleFactionsList::const_iterator itr
= flist
->begin();itr
!= flist
->end();++itr
)
5804 FactionEntry
const *factionEntryCalc
= sFactionStore
.LookupEntry(*itr
);
5805 if(factionEntryCalc
)
5806 res
= SetOneFactionReputation(factionEntryCalc
, standing
);
5811 return SetOneFactionReputation(factionEntry
, standing
);
5814 bool Player::SetOneFactionReputation(FactionEntry
const* factionEntry
, int32 standing
)
5816 FactionStateList::iterator itr
= m_factions
.find(factionEntry
->reputationListID
);
5817 if (itr
!= m_factions
.end())
5819 if (standing
> Reputation_Cap
)
5820 standing
= Reputation_Cap
;
5822 if (standing
< Reputation_Bottom
)
5823 standing
= Reputation_Bottom
;
5825 int32 BaseRep
= GetBaseReputation(factionEntry
);
5826 itr
->second
.Standing
= standing
- BaseRep
;
5827 itr
->second
.Changed
= true;
5829 SetFactionVisible(&itr
->second
);
5831 if(ReputationToRank(standing
) <= REP_HOSTILE
)
5832 SetFactionAtWar(&itr
->second
,true);
5834 SendFactionState(&(itr
->second
));
5835 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION
);
5836 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION
);
5842 //Calculate total reputation percent player gain with quest/creature level
5843 int32
Player::CalculateReputationGain(uint32 creatureOrQuestLevel
, int32 rep
, bool for_quest
)
5845 // for grey creature kill received 20%, in other case 100.
5846 int32 percent
= (!for_quest
&& (creatureOrQuestLevel
<= MaNGOS::XP::GetGrayLevel(getLevel()))) ? 20 : 100;
5848 int32 repMod
= GetTotalAuraModifier(SPELL_AURA_MOD_REPUTATION_GAIN
);
5850 percent
+= rep
> 0 ? repMod
: -repMod
;
5855 return int32(sWorld
.getRate(RATE_REPUTATION_GAIN
)*rep
*percent
/100);
5858 //Calculates how many reputation points player gains in victim's enemy factions
5859 void Player::RewardReputation(Unit
*pVictim
, float rate
)
5861 if(!pVictim
|| pVictim
->GetTypeId() == TYPEID_PLAYER
)
5864 ReputationOnKillEntry
const* Rep
= objmgr
.GetReputationOnKilEntry(((Creature
*)pVictim
)->GetCreatureInfo()->Entry
);
5869 if(Rep
->repfaction1
&& (!Rep
->team_dependent
|| GetTeam()==ALLIANCE
))
5871 int32 donerep1
= CalculateReputationGain(pVictim
->getLevel(),Rep
->repvalue1
,false);
5872 donerep1
= int32(donerep1
*rate
);
5873 FactionEntry
const *factionEntry1
= sFactionStore
.LookupEntry(Rep
->repfaction1
);
5874 uint32 current_reputation_rank1
= GetReputationRank(factionEntry1
);
5875 if(factionEntry1
&& current_reputation_rank1
<= Rep
->reputation_max_cap1
)
5876 ModifyFactionReputation(factionEntry1
, donerep1
);
5878 // Wiki: Team factions value divided by 2
5879 if(Rep
->is_teamaward1
)
5881 FactionEntry
const *team1_factionEntry
= sFactionStore
.LookupEntry(factionEntry1
->team
);
5882 if(team1_factionEntry
)
5883 ModifyFactionReputation(team1_factionEntry
, donerep1
/ 2);
5887 if(Rep
->repfaction2
&& (!Rep
->team_dependent
|| GetTeam()==HORDE
))
5889 int32 donerep2
= CalculateReputationGain(pVictim
->getLevel(),Rep
->repvalue2
,false);
5890 donerep2
= int32(donerep2
*rate
);
5891 FactionEntry
const *factionEntry2
= sFactionStore
.LookupEntry(Rep
->repfaction2
);
5892 uint32 current_reputation_rank2
= GetReputationRank(factionEntry2
);
5893 if(factionEntry2
&& current_reputation_rank2
<= Rep
->reputation_max_cap2
)
5894 ModifyFactionReputation(factionEntry2
, donerep2
);
5896 // Wiki: Team factions value divided by 2
5897 if(Rep
->is_teamaward2
)
5899 FactionEntry
const *team2_factionEntry
= sFactionStore
.LookupEntry(factionEntry2
->team
);
5900 if(team2_factionEntry
)
5901 ModifyFactionReputation(team2_factionEntry
, donerep2
/ 2);
5906 //Calculate how many reputation points player gain with the quest
5907 void Player::RewardReputation(Quest
const *pQuest
)
5909 // quest reputation reward/loss
5910 for(int i
= 0; i
< QUEST_REPUTATIONS_COUNT
; ++i
)
5912 if(pQuest
->RewRepFaction
[i
] && pQuest
->RewRepValue
[i
] )
5914 int32 rep
= CalculateReputationGain(pQuest
->GetQuestLevel(),pQuest
->RewRepValue
[i
],true);
5915 FactionEntry
const* factionEntry
= sFactionStore
.LookupEntry(pQuest
->RewRepFaction
[i
]);
5917 ModifyFactionReputation(factionEntry
, rep
);
5921 // TODO: implement reputation spillover
5924 void Player::UpdateArenaFields(void)
5926 /* arena calcs go here */
5929 void Player::UpdateHonorFields()
5931 /// called when rewarding honor and at each save
5932 uint64 now
= time(NULL
);
5933 uint64 today
= uint64(time(NULL
) / DAY
) * DAY
;
5935 if(m_lastHonorUpdateTime
< today
)
5937 uint64 yesterday
= today
- DAY
;
5939 uint16 kills_today
= PAIR32_LOPART(GetUInt32Value(PLAYER_FIELD_KILLS
));
5941 // update yesterday's contribution
5942 if(m_lastHonorUpdateTime
>= yesterday
)
5944 SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, GetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
));
5946 // this is the first update today, reset today's contribution
5947 SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
5948 SetUInt32Value(PLAYER_FIELD_KILLS
, MAKE_PAIR32(0,kills_today
));
5952 // no honor/kills yesterday or today, reset
5953 SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
5954 SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
5958 m_lastHonorUpdateTime
= now
;
5961 ///Calculate the amount of honor gained based on the victim
5962 ///and the size of the group for which the honor is divided
5963 ///An exact honor value can also be given (overriding the calcs)
5964 bool Player::RewardHonor(Unit
*uVictim
, uint32 groupsize
, float honor
)
5966 // 'Inactive' this aura prevents the player from gaining honor points and battleground tokens
5967 if(GetDummyAura(SPELL_AURA_PLAYER_INACTIVE
))
5970 uint64 victim_guid
= 0;
5971 uint32 victim_rank
= 0;
5973 // need call before fields update to have chance move yesterday data to appropriate fields before today data change.
5974 UpdateHonorFields();
5978 if(!uVictim
|| uVictim
== this || uVictim
->HasAuraType(SPELL_AURA_NO_PVP_CREDIT
))
5981 victim_guid
= uVictim
->GetGUID();
5983 if( uVictim
->GetTypeId() == TYPEID_PLAYER
)
5985 Player
*pVictim
= (Player
*)uVictim
;
5987 if( GetTeam() == pVictim
->GetTeam() && !sWorld
.IsFFAPvPRealm() )
5990 float f
= 1; //need for total kills (?? need more info)
5992 uint32 k_level
= getLevel();
5993 uint32 v_level
= pVictim
->getLevel();
5996 // PLAYER_CHOSEN_TITLE VALUES DESCRIPTION
5998 // [1..14] Alliance honor titles and player name
5999 // [15..28] Horde honor titles and player name
6000 // [29..38] Other title and player name
6002 uint32 victim_title
= pVictim
->GetUInt32Value(PLAYER_CHOSEN_TITLE
);
6003 // Get Killer titles, CharTitlesEntry::bit_index
6005 // title[1..14] -> rank[5..18]
6006 // title[15..28] -> rank[5..18]
6007 // title[other] -> 0
6008 if (victim_title
== 0)
6009 victim_guid
= 0; // Don't show HK: <rank> message, only log.
6010 else if (victim_title
< 15)
6011 victim_rank
= victim_title
+ 4;
6012 else if (victim_title
< 29)
6013 victim_rank
= victim_title
- 14 + 4;
6015 victim_guid
= 0; // Don't show HK: <rank> message, only log.
6020 else if( k_level
<= 39 )
6021 k_grey
= k_level
- 5 - k_level
/10;
6023 k_grey
= k_level
- 1 - k_level
/5;
6028 float diff_level
= (k_level
== k_grey
) ? 1 : ((float(v_level
) - float(k_grey
)) / (float(k_level
) - float(k_grey
)));
6030 int32 v_rank
=1; //need more info
6032 honor
= ((f
* diff_level
* (190 + v_rank
*10))/6);
6033 honor
*= ((float)k_level
) / 70.0f
; //factor of dependence on levels of the killer
6035 // count the number of playerkills in one day
6036 ApplyModUInt32Value(PLAYER_FIELD_KILLS
, 1, true);
6037 // and those in a lifetime
6038 ApplyModUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 1, true);
6042 Creature
*cVictim
= (Creature
*)uVictim
;
6044 if (!cVictim
->isRacialLeader())
6047 honor
= 100; // ??? need more info
6048 victim_rank
= 19; // HK: Leader
6052 if (uVictim
!= NULL
)
6054 honor
*= sWorld
.getRate(RATE_HONOR
);
6059 honor
*= (((float)urand(8,12))/10); // approx honor: 80% - 120% of real honor
6062 // honor - for show honor points in log
6063 // victim_guid - for show victim name in log
6064 // victim_rank [1..4] HK: <dishonored rank>
6065 // victim_rank [5..19] HK: <alliance\horde rank>
6066 // victim_rank [0,20+] HK: <>
6067 WorldPacket
data(SMSG_PVP_CREDIT
,4+8+4);
6068 data
<< (uint32
) honor
;
6069 data
<< (uint64
) victim_guid
;
6070 data
<< (uint32
) victim_rank
;
6072 GetSession()->SendPacket(&data
);
6075 ModifyHonorPoints(int32(honor
));
6077 ApplyModUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, uint32(honor
), true);
6081 void Player::ModifyHonorPoints( int32 value
)
6085 if (GetHonorPoints() > sWorld
.getConfig(CONFIG_MAX_HONOR_POINTS
))
6086 SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, sWorld
.getConfig(CONFIG_MAX_HONOR_POINTS
) + value
);
6088 SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, GetHonorPoints() > uint32(-value
) ? GetHonorPoints() + value
: 0);
6091 SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, GetHonorPoints() < sWorld
.getConfig(CONFIG_MAX_HONOR_POINTS
) - value
? GetHonorPoints() + value
: sWorld
.getConfig(CONFIG_MAX_HONOR_POINTS
));
6094 void Player::ModifyArenaPoints( int32 value
)
6098 if (GetArenaPoints() > sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
))
6099 SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY
, sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
) + value
);
6101 SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY
, GetArenaPoints() > uint32(-value
) ? GetArenaPoints() + value
: 0);
6104 SetUInt32Value(PLAYER_FIELD_ARENA_CURRENCY
, GetArenaPoints() < sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
) - value
? GetArenaPoints() + value
: sWorld
.getConfig(CONFIG_MAX_ARENA_POINTS
));
6107 uint32
Player::GetGuildIdFromDB(uint64 guid
)
6109 std::ostringstream ss
;
6110 ss
<<"SELECT guildid FROM guild_member WHERE guid='"<<guid
<<"'";
6111 QueryResult
*result
= CharacterDatabase
.Query( ss
.str().c_str() );
6114 uint32 v
= result
->Fetch()[0].GetUInt32();
6122 uint32
Player::GetRankFromDB(uint64 guid
)
6124 std::ostringstream ss
;
6125 ss
<<"SELECT rank FROM guild_member WHERE guid='"<<guid
<<"'";
6126 QueryResult
*result
= CharacterDatabase
.Query( ss
.str().c_str() );
6129 uint32 v
= result
->Fetch()[0].GetUInt32();
6137 uint32
Player::GetArenaTeamIdFromDB(uint64 guid
, uint8 type
)
6139 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
);
6143 uint32 id
= (*result
)[0].GetUInt32();
6148 uint32
Player::GetZoneIdFromDB(uint64 guid
)
6150 std::ostringstream ss
;
6152 ss
<<"SELECT zone FROM characters WHERE guid='"<<GUID_LOPART(guid
)<<"'";
6153 QueryResult
*result
= CharacterDatabase
.Query( ss
.str().c_str() );
6156 Field
* fields
= result
->Fetch();
6157 uint32 zone
= fields
[0].GetUInt32();
6162 // stored zone is zero, use generic and slow zone detection
6164 ss
<<"SELECT map,position_x,position_y FROM characters WHERE guid='"<<GUID_LOPART(guid
)<<"'";
6165 result
= CharacterDatabase
.Query(ss
.str().c_str());
6168 fields
= result
->Fetch();
6169 uint32 map
= fields
[0].GetUInt32();
6170 float posx
= fields
[1].GetFloat();
6171 float posy
= fields
[2].GetFloat();
6174 zone
= MapManager::Instance().GetZoneId(map
,posx
,posy
);
6177 ss
<< "UPDATE characters SET zone='"<<zone
<<"' WHERE guid='"<<GUID_LOPART(guid
)<<"'";
6178 CharacterDatabase
.Execute(ss
.str().c_str());
6184 void Player::UpdateArea(uint32 newArea
)
6186 // FFA_PVP flags are area and not zone id dependent
6187 // so apply them accordingly
6188 m_areaUpdateId
= newArea
;
6190 AreaTableEntry
const* area
= GetAreaEntryByAreaID(newArea
);
6192 if(area
&& (area
->flags
& AREA_FLAG_ARENA
))
6195 SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_FFA_PVP
);
6199 // remove ffa flag only if not ffapvp realm
6200 // removal in sanctuaries and capitals is handled in zone update
6201 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_FFA_PVP
) && !sWorld
.IsFFAPvPRealm())
6202 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_FFA_PVP
);
6205 UpdateAreaDependentAuras(newArea
);
6208 void Player::UpdateZone(uint32 newZone
)
6210 m_zoneUpdateId
= newZone
;
6211 m_zoneUpdateTimer
= ZONE_UPDATE_INTERVAL
;
6213 // zone changed, so area changed as well, update it
6214 UpdateArea(GetAreaId());
6216 AreaTableEntry
const* zone
= GetAreaEntryByAreaID(newZone
);
6220 if (sWorld
.getConfig(CONFIG_WEATHER
))
6222 Weather
*wth
= sWorld
.FindWeather(zone
->ID
);
6225 wth
->SendWeatherUpdateToPlayer(this);
6229 if(!sWorld
.AddWeather(zone
->ID
))
6231 // send fine weather packet to remove old zone's weather
6232 Weather::SendFineWeatherUpdateToPlayer(this);
6237 pvpInfo
.inHostileArea
=
6238 GetTeam() == ALLIANCE
&& zone
->team
== AREATEAM_HORDE
||
6239 GetTeam() == HORDE
&& zone
->team
== AREATEAM_ALLY
||
6240 sWorld
.IsPvPRealm() && zone
->team
== AREATEAM_NONE
||
6241 InBattleGround(); // overwrite for battlegrounds, maybe batter some zone flags but current known not 100% fit to this
6243 if(pvpInfo
.inHostileArea
) // in hostile area
6245 if(!IsPvP() || pvpInfo
.endTimer
!= 0)
6246 UpdatePvP(true, true);
6248 else // in friendly area
6250 if(IsPvP() && !HasFlag(PLAYER_FLAGS
,PLAYER_FLAGS_IN_PVP
) && pvpInfo
.endTimer
== 0)
6251 pvpInfo
.endTimer
= time(0); // start toggle-off
6254 if(zone
->flags
& AREA_FLAG_SANCTUARY
) // in sanctuary
6256 SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_SANCTUARY
);
6257 if(sWorld
.IsFFAPvPRealm())
6258 RemoveFlag(PLAYER_FLAGS
,PLAYER_FLAGS_FFA_PVP
);
6262 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_SANCTUARY
);
6265 if(zone
->flags
& AREA_FLAG_CAPITAL
) // in capital city
6267 SetFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
);
6268 SetRestType(REST_TYPE_IN_CITY
);
6269 InnEnter(time(0),GetMapId(),0,0,0);
6271 if(sWorld
.IsFFAPvPRealm())
6272 RemoveFlag(PLAYER_FLAGS
,PLAYER_FLAGS_FFA_PVP
);
6274 else // anywhere else
6276 if(HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
)) // but resting (walk from city or maybe in tavern or leave tavern recently)
6278 if(GetRestType()==REST_TYPE_IN_TAVERN
) // has been in tavern. Is still in?
6280 if(GetMapId()!=GetInnPosMapId() || sqrt((GetPositionX()-GetInnPosX())*(GetPositionX()-GetInnPosX())+(GetPositionY()-GetInnPosY())*(GetPositionY()-GetInnPosY())+(GetPositionZ()-GetInnPosZ())*(GetPositionZ()-GetInnPosZ()))>40)
6282 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
);
6283 SetRestType(REST_TYPE_NO
);
6285 if(sWorld
.IsFFAPvPRealm())
6286 SetFlag(PLAYER_FLAGS
,PLAYER_FLAGS_FFA_PVP
);
6289 else // not in tavern (leave city then)
6291 RemoveFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
);
6292 SetRestType(REST_TYPE_NO
);
6294 // Set player to FFA PVP when not in rested environment.
6295 if(sWorld
.IsFFAPvPRealm())
6296 SetFlag(PLAYER_FLAGS
,PLAYER_FLAGS_FFA_PVP
);
6301 // remove items with area/map limitations (delete only for alive player to allow back in ghost mode)
6302 // if player resurrected at teleport this will be applied in resurrect code
6304 DestroyZoneLimitedItem( true, newZone
);
6306 // recent client version not send leave/join channel packets for built-in local channels
6307 UpdateLocalChannels( newZone
);
6311 SetGroupUpdateFlag(GROUP_UPDATE_FLAG_ZONE
);
6313 UpdateZoneDependentAuras(newZone
);
6316 //If players are too far way of duel flag... then player loose the duel
6317 void Player::CheckDuelDistance(time_t currTime
)
6322 uint64 duelFlagGUID
= GetUInt64Value(PLAYER_DUEL_ARBITER
);
6323 GameObject
* obj
= ObjectAccessor::GetGameObject(*this, duelFlagGUID
);
6327 if(duel
->outOfBound
== 0)
6329 if(!IsWithinDistInMap(obj
, 50))
6331 duel
->outOfBound
= currTime
;
6333 WorldPacket
data(SMSG_DUEL_OUTOFBOUNDS
, 0);
6334 GetSession()->SendPacket(&data
);
6339 if(IsWithinDistInMap(obj
, 40))
6341 duel
->outOfBound
= 0;
6343 WorldPacket
data(SMSG_DUEL_INBOUNDS
, 0);
6344 GetSession()->SendPacket(&data
);
6346 else if(currTime
>= (duel
->outOfBound
+10))
6348 DuelComplete(DUEL_FLED
);
6353 void Player::DuelComplete(DuelCompleteType type
)
6355 // duel not requested
6359 WorldPacket
data(SMSG_DUEL_COMPLETE
, (1));
6360 data
<< (uint8
)((type
!= DUEL_INTERUPTED
) ? 1 : 0);
6361 GetSession()->SendPacket(&data
);
6362 duel
->opponent
->GetSession()->SendPacket(&data
);
6364 if(type
!= DUEL_INTERUPTED
)
6366 data
.Initialize(SMSG_DUEL_WINNER
, (1+20)); // we guess size
6367 data
<< (uint8
)((type
==DUEL_WON
) ? 0 : 1); // 0 = just won; 1 = fled
6368 data
<< duel
->opponent
->GetName();
6370 SendMessageToSet(&data
,true);
6373 // cool-down duel spell
6374 /*data.Initialize(SMSG_SPELL_COOLDOWN, 17);
6381 GetSession()->SendPacket(&data);
6382 data.Initialize(SMSG_SPELL_COOLDOWN, 17);
6383 data<<duel->opponent->GetGUID();
6387 duel->opponent->GetSession()->SendPacket(&data);*/
6389 //Remove Duel Flag object
6390 GameObject
* obj
= ObjectAccessor::GetGameObject(*this, GetUInt64Value(PLAYER_DUEL_ARBITER
));
6392 duel
->initiator
->RemoveGameObject(obj
,true);
6395 std::vector
<uint32
> auras2remove
;
6396 AuraMap
const& vAuras
= duel
->opponent
->GetAuras();
6397 for (AuraMap::const_iterator i
= vAuras
.begin(); i
!= vAuras
.end(); i
++)
6399 if (!i
->second
->IsPositive() && i
->second
->GetCasterGUID() == GetGUID() && i
->second
->GetAuraApplyTime() >= duel
->startTime
)
6400 auras2remove
.push_back(i
->second
->GetId());
6403 for(size_t i
=0; i
<auras2remove
.size(); i
++)
6404 duel
->opponent
->RemoveAurasDueToSpell(auras2remove
[i
]);
6406 auras2remove
.clear();
6407 AuraMap
const& auras
= GetAuras();
6408 for (AuraMap::const_iterator i
= auras
.begin(); i
!= auras
.end(); i
++)
6410 if (!i
->second
->IsPositive() && i
->second
->GetCasterGUID() == duel
->opponent
->GetGUID() && i
->second
->GetAuraApplyTime() >= duel
->startTime
)
6411 auras2remove
.push_back(i
->second
->GetId());
6413 for(size_t i
=0; i
<auras2remove
.size(); i
++)
6414 RemoveAurasDueToSpell(auras2remove
[i
]);
6416 // cleanup combo points
6417 if(GetComboTarget()==duel
->opponent
->GetGUID())
6419 else if(GetComboTarget()==duel
->opponent
->GetPetGUID())
6422 if(duel
->opponent
->GetComboTarget()==GetGUID())
6423 duel
->opponent
->ClearComboPoints();
6424 else if(duel
->opponent
->GetComboTarget()==GetPetGUID())
6425 duel
->opponent
->ClearComboPoints();
6428 SetUInt64Value(PLAYER_DUEL_ARBITER
, 0);
6429 SetUInt32Value(PLAYER_DUEL_TEAM
, 0);
6430 duel
->opponent
->SetUInt64Value(PLAYER_DUEL_ARBITER
, 0);
6431 duel
->opponent
->SetUInt32Value(PLAYER_DUEL_TEAM
, 0);
6433 delete duel
->opponent
->duel
;
6434 duel
->opponent
->duel
= NULL
;
6439 //---------------------------------------------------------//
6441 void Player::_ApplyItemMods(Item
*item
, uint8 slot
,bool apply
)
6443 if(slot
>= INVENTORY_SLOT_BAG_END
|| !item
)
6446 // not apply/remove mods for broken item
6447 if(item
->IsBroken())
6450 ItemPrototype
const *proto
= item
->GetProto();
6455 sLog
.outDetail("applying mods for item %u ",item
->GetGUIDLow());
6457 uint32 attacktype
= Player::GetAttackBySlot(slot
);
6458 if(attacktype
< MAX_ATTACK
)
6459 _ApplyWeaponDependentAuraMods(item
,WeaponAttackType(attacktype
),apply
);
6461 _ApplyItemBonuses(proto
,slot
,apply
);
6463 if( slot
==EQUIPMENT_SLOT_RANGED
)
6464 _ApplyAmmoBonuses();
6466 ApplyItemEquipSpell(item
,apply
);
6467 ApplyEnchantment(item
, apply
);
6469 if(proto
->Socket
[0].Color
) //only (un)equipping of items with sockets can influence metagems, so no need to waste time with normal items
6470 CorrectMetaGemEnchants(slot
, apply
);
6472 sLog
.outDebug("_ApplyItemMods complete.");
6475 void Player::_ApplyItemBonuses(ItemPrototype
const *proto
, uint8 slot
, bool apply
)
6477 if(slot
>= INVENTORY_SLOT_BAG_END
|| !proto
)
6480 for (int i
= 0; i
< 10; i
++)
6482 uint32 statType
= 0;
6485 if(proto
->ScalingStatDistribution
)
6487 if(ScalingStatDistributionEntry
const *ssd
= sScalingStatDistributionStore
.LookupEntry(proto
->ScalingStatDistribution
))
6489 statType
= ssd
->StatMod
[i
];
6491 if(uint32 modifier
= ssd
->Modifier
[i
])
6493 uint32 level
= ((getLevel() > ssd
->MaxLevel
) ? ssd
->MaxLevel
: getLevel());
6494 if(ScalingStatValuesEntry
const *ssv
= sScalingStatValuesStore
.LookupEntry(level
))
6496 int multiplier
= ssv
->Multiplier
[proto
->GetScalingStatValuesColumn()];
6497 val
= (multiplier
* modifier
) / 10000;
6504 statType
= proto
->ItemStat
[i
].ItemStatType
;
6505 val
= float(proto
->ItemStat
[i
].ItemStatValue
);
6514 HandleStatModifier(UNIT_MOD_MANA
, BASE_VALUE
, float(val
), apply
);
6516 case ITEM_MOD_HEALTH
: // modify HP
6517 HandleStatModifier(UNIT_MOD_HEALTH
, BASE_VALUE
, float(val
), apply
);
6519 case ITEM_MOD_AGILITY
: // modify agility
6520 HandleStatModifier(UNIT_MOD_STAT_AGILITY
, BASE_VALUE
, float(val
), apply
);
6521 ApplyStatBuffMod(STAT_AGILITY
, float(val
), apply
);
6523 case ITEM_MOD_STRENGTH
: //modify strength
6524 HandleStatModifier(UNIT_MOD_STAT_STRENGTH
, BASE_VALUE
, float(val
), apply
);
6525 ApplyStatBuffMod(STAT_STRENGTH
, float(val
), apply
);
6527 case ITEM_MOD_INTELLECT
: //modify intellect
6528 HandleStatModifier(UNIT_MOD_STAT_INTELLECT
, BASE_VALUE
, float(val
), apply
);
6529 ApplyStatBuffMod(STAT_INTELLECT
, float(val
), apply
);
6531 case ITEM_MOD_SPIRIT
: //modify spirit
6532 HandleStatModifier(UNIT_MOD_STAT_SPIRIT
, BASE_VALUE
, float(val
), apply
);
6533 ApplyStatBuffMod(STAT_SPIRIT
, float(val
), apply
);
6535 case ITEM_MOD_STAMINA
: //modify stamina
6536 HandleStatModifier(UNIT_MOD_STAT_STAMINA
, BASE_VALUE
, float(val
), apply
);
6537 ApplyStatBuffMod(STAT_STAMINA
, float(val
), apply
);
6539 case ITEM_MOD_DEFENSE_SKILL_RATING
:
6540 ApplyRatingMod(CR_DEFENSE_SKILL
, int32(val
), apply
);
6542 case ITEM_MOD_DODGE_RATING
:
6543 ApplyRatingMod(CR_DODGE
, int32(val
), apply
);
6545 case ITEM_MOD_PARRY_RATING
:
6546 ApplyRatingMod(CR_PARRY
, int32(val
), apply
);
6548 case ITEM_MOD_BLOCK_RATING
:
6549 ApplyRatingMod(CR_BLOCK
, int32(val
), apply
);
6551 case ITEM_MOD_HIT_MELEE_RATING
:
6552 ApplyRatingMod(CR_HIT_MELEE
, int32(val
), apply
);
6554 case ITEM_MOD_HIT_RANGED_RATING
:
6555 ApplyRatingMod(CR_HIT_RANGED
, int32(val
), apply
);
6557 case ITEM_MOD_HIT_SPELL_RATING
:
6558 ApplyRatingMod(CR_HIT_SPELL
, int32(val
), apply
);
6560 case ITEM_MOD_CRIT_MELEE_RATING
:
6561 ApplyRatingMod(CR_CRIT_MELEE
, int32(val
), apply
);
6563 case ITEM_MOD_CRIT_RANGED_RATING
:
6564 ApplyRatingMod(CR_CRIT_RANGED
, int32(val
), apply
);
6566 case ITEM_MOD_CRIT_SPELL_RATING
:
6567 ApplyRatingMod(CR_CRIT_SPELL
, int32(val
), apply
);
6569 case ITEM_MOD_HIT_TAKEN_MELEE_RATING
:
6570 ApplyRatingMod(CR_HIT_TAKEN_MELEE
, int32(val
), apply
);
6572 case ITEM_MOD_HIT_TAKEN_RANGED_RATING
:
6573 ApplyRatingMod(CR_HIT_TAKEN_RANGED
, int32(val
), apply
);
6575 case ITEM_MOD_HIT_TAKEN_SPELL_RATING
:
6576 ApplyRatingMod(CR_HIT_TAKEN_SPELL
, int32(val
), apply
);
6578 case ITEM_MOD_CRIT_TAKEN_MELEE_RATING
:
6579 ApplyRatingMod(CR_CRIT_TAKEN_MELEE
, int32(val
), apply
);
6581 case ITEM_MOD_CRIT_TAKEN_RANGED_RATING
:
6582 ApplyRatingMod(CR_CRIT_TAKEN_RANGED
, int32(val
), apply
);
6584 case ITEM_MOD_CRIT_TAKEN_SPELL_RATING
:
6585 ApplyRatingMod(CR_CRIT_TAKEN_SPELL
, int32(val
), apply
);
6587 case ITEM_MOD_HASTE_MELEE_RATING
:
6588 ApplyRatingMod(CR_HASTE_MELEE
, int32(val
), apply
);
6590 case ITEM_MOD_HASTE_RANGED_RATING
:
6591 ApplyRatingMod(CR_HASTE_RANGED
, int32(val
), apply
);
6593 case ITEM_MOD_HASTE_SPELL_RATING
:
6594 ApplyRatingMod(CR_HASTE_SPELL
, int32(val
), apply
);
6596 case ITEM_MOD_HIT_RATING
:
6597 ApplyRatingMod(CR_HIT_MELEE
, int32(val
), apply
);
6598 ApplyRatingMod(CR_HIT_RANGED
, int32(val
), apply
);
6599 ApplyRatingMod(CR_HIT_SPELL
, int32(val
), apply
);
6601 case ITEM_MOD_CRIT_RATING
:
6602 ApplyRatingMod(CR_CRIT_MELEE
, int32(val
), apply
);
6603 ApplyRatingMod(CR_CRIT_RANGED
, int32(val
), apply
);
6604 ApplyRatingMod(CR_CRIT_SPELL
, int32(val
), apply
);
6606 case ITEM_MOD_HIT_TAKEN_RATING
:
6607 ApplyRatingMod(CR_HIT_TAKEN_MELEE
, int32(val
), apply
);
6608 ApplyRatingMod(CR_HIT_TAKEN_RANGED
, int32(val
), apply
);
6609 ApplyRatingMod(CR_HIT_TAKEN_SPELL
, int32(val
), apply
);
6611 case ITEM_MOD_CRIT_TAKEN_RATING
:
6612 ApplyRatingMod(CR_CRIT_TAKEN_MELEE
, int32(val
), apply
);
6613 ApplyRatingMod(CR_CRIT_TAKEN_RANGED
, int32(val
), apply
);
6614 ApplyRatingMod(CR_CRIT_TAKEN_SPELL
, int32(val
), apply
);
6616 case ITEM_MOD_RESILIENCE_RATING
:
6617 ApplyRatingMod(CR_CRIT_TAKEN_MELEE
, int32(val
), apply
);
6618 ApplyRatingMod(CR_CRIT_TAKEN_RANGED
, int32(val
), apply
);
6619 ApplyRatingMod(CR_CRIT_TAKEN_SPELL
, int32(val
), apply
);
6621 case ITEM_MOD_HASTE_RATING
:
6622 ApplyRatingMod(CR_HASTE_MELEE
, int32(val
), apply
);
6623 ApplyRatingMod(CR_HASTE_RANGED
, int32(val
), apply
);
6624 ApplyRatingMod(CR_HASTE_SPELL
, int32(val
), apply
);
6626 case ITEM_MOD_EXPERTISE_RATING
:
6627 ApplyRatingMod(CR_EXPERTISE
, int32(val
), apply
);
6629 case ITEM_MOD_ARMOR_PENETRATION_RATING
:
6630 ApplyRatingMod(CR_ARMOR_PENETRATION
, int32(val
), apply
);
6636 HandleStatModifier(UNIT_MOD_ARMOR
, BASE_VALUE
, float(proto
->Armor
), apply
);
6639 HandleBaseModValue(SHIELD_BLOCK_VALUE
, FLAT_MOD
, float(proto
->Block
), apply
);
6642 HandleStatModifier(UNIT_MOD_RESISTANCE_HOLY
, BASE_VALUE
, float(proto
->HolyRes
), apply
);
6645 HandleStatModifier(UNIT_MOD_RESISTANCE_FIRE
, BASE_VALUE
, float(proto
->FireRes
), apply
);
6647 if (proto
->NatureRes
)
6648 HandleStatModifier(UNIT_MOD_RESISTANCE_NATURE
, BASE_VALUE
, float(proto
->NatureRes
), apply
);
6650 if (proto
->FrostRes
)
6651 HandleStatModifier(UNIT_MOD_RESISTANCE_FROST
, BASE_VALUE
, float(proto
->FrostRes
), apply
);
6653 if (proto
->ShadowRes
)
6654 HandleStatModifier(UNIT_MOD_RESISTANCE_SHADOW
, BASE_VALUE
, float(proto
->ShadowRes
), apply
);
6656 if (proto
->ArcaneRes
)
6657 HandleStatModifier(UNIT_MOD_RESISTANCE_ARCANE
, BASE_VALUE
, float(proto
->ArcaneRes
), apply
);
6659 WeaponAttackType attType
= BASE_ATTACK
;
6660 float damage
= 0.0f
;
6662 if( slot
== EQUIPMENT_SLOT_RANGED
&& (
6663 proto
->InventoryType
== INVTYPE_RANGED
|| proto
->InventoryType
== INVTYPE_THROWN
||
6664 proto
->InventoryType
== INVTYPE_RANGEDRIGHT
))
6666 attType
= RANGED_ATTACK
;
6668 else if(slot
==EQUIPMENT_SLOT_OFFHAND
)
6670 attType
= OFF_ATTACK
;
6673 if (proto
->Damage
[0].DamageMin
> 0 )
6675 damage
= apply
? proto
->Damage
[0].DamageMin
: BASE_MINDAMAGE
;
6676 SetBaseWeaponDamage(attType
, MINDAMAGE
, damage
);
6677 //sLog.outError("applying mindam: assigning %f to weapon mindamage, now is: %f", damage, GetWeaponDamageRange(attType, MINDAMAGE));
6680 if (proto
->Damage
[0].DamageMax
> 0 )
6682 damage
= apply
? proto
->Damage
[0].DamageMax
: BASE_MAXDAMAGE
;
6683 SetBaseWeaponDamage(attType
, MAXDAMAGE
, damage
);
6686 if(!IsUseEquipedWeapon(slot
==EQUIPMENT_SLOT_MAINHAND
))
6691 if(slot
== EQUIPMENT_SLOT_RANGED
)
6692 SetAttackTime(RANGED_ATTACK
, apply
? proto
->Delay
: BASE_ATTACK_TIME
);
6693 else if(slot
==EQUIPMENT_SLOT_MAINHAND
)
6694 SetAttackTime(BASE_ATTACK
, apply
? proto
->Delay
: BASE_ATTACK_TIME
);
6695 else if(slot
==EQUIPMENT_SLOT_OFFHAND
)
6696 SetAttackTime(OFF_ATTACK
, apply
? proto
->Delay
: BASE_ATTACK_TIME
);
6699 if(CanModifyStats() && (damage
|| proto
->Delay
))
6700 UpdateDamagePhysical(attType
);
6703 void Player::_ApplyWeaponDependentAuraMods(Item
*item
,WeaponAttackType attackType
,bool apply
)
6705 AuraList
const& auraCritList
= GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT
);
6706 for(AuraList::const_iterator itr
= auraCritList
.begin(); itr
!=auraCritList
.end();++itr
)
6707 _ApplyWeaponDependentAuraCritMod(item
,attackType
,*itr
,apply
);
6709 AuraList
const& auraDamageFlatList
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE
);
6710 for(AuraList::const_iterator itr
= auraDamageFlatList
.begin(); itr
!=auraDamageFlatList
.end();++itr
)
6711 _ApplyWeaponDependentAuraDamageMod(item
,attackType
,*itr
,apply
);
6713 AuraList
const& auraDamagePCTList
= GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
);
6714 for(AuraList::const_iterator itr
= auraDamagePCTList
.begin(); itr
!=auraDamagePCTList
.end();++itr
)
6715 _ApplyWeaponDependentAuraDamageMod(item
,attackType
,*itr
,apply
);
6718 void Player::_ApplyWeaponDependentAuraCritMod(Item
*item
, WeaponAttackType attackType
, Aura
* aura
, bool apply
)
6720 // generic not weapon specific case processes in aura code
6721 if(aura
->GetSpellProto()->EquippedItemClass
== -1)
6724 BaseModGroup mod
= BASEMOD_END
;
6727 case BASE_ATTACK
: mod
= CRIT_PERCENTAGE
; break;
6728 case OFF_ATTACK
: mod
= OFFHAND_CRIT_PERCENTAGE
;break;
6729 case RANGED_ATTACK
: mod
= RANGED_CRIT_PERCENTAGE
; break;
6733 if (item
->IsFitToSpellRequirements(aura
->GetSpellProto()))
6735 HandleBaseModValue(mod
, FLAT_MOD
, float (aura
->GetModifier()->m_amount
), apply
);
6739 void Player::_ApplyWeaponDependentAuraDamageMod(Item
*item
, WeaponAttackType attackType
, Aura
* aura
, bool apply
)
6741 // ignore spell mods for not wands
6742 Modifier
const* modifier
= aura
->GetModifier();
6743 if((modifier
->m_miscvalue
& SPELL_SCHOOL_MASK_NORMAL
)==0 && (getClassMask() & CLASSMASK_WAND_USERS
)==0)
6746 // generic not weapon specific case processes in aura code
6747 if(aura
->GetSpellProto()->EquippedItemClass
== -1)
6750 UnitMods unitMod
= UNIT_MOD_END
;
6753 case BASE_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_MAINHAND
; break;
6754 case OFF_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_OFFHAND
; break;
6755 case RANGED_ATTACK
: unitMod
= UNIT_MOD_DAMAGE_RANGED
; break;
6759 UnitModifierType unitModType
= TOTAL_VALUE
;
6760 switch(modifier
->m_auraname
)
6762 case SPELL_AURA_MOD_DAMAGE_DONE
: unitModType
= TOTAL_VALUE
; break;
6763 case SPELL_AURA_MOD_DAMAGE_PERCENT_DONE
: unitModType
= TOTAL_PCT
; break;
6767 if (item
->IsFitToSpellRequirements(aura
->GetSpellProto()))
6769 HandleStatModifier(unitMod
, unitModType
, float(modifier
->m_amount
),apply
);
6773 void Player::ApplyItemEquipSpell(Item
*item
, bool apply
, bool form_change
)
6778 ItemPrototype
const *proto
= item
->GetProto();
6782 for (int i
= 0; i
< 5; i
++)
6784 _Spell
const& spellData
= proto
->Spells
[i
];
6787 if(!spellData
.SpellId
)
6790 // wrong triggering type
6791 if(apply
&& spellData
.SpellTrigger
!= ITEM_SPELLTRIGGER_ON_EQUIP
)
6794 // check if it is valid spell
6795 SpellEntry
const* spellproto
= sSpellStore
.LookupEntry(spellData
.SpellId
);
6799 ApplyEquipSpell(spellproto
,item
,apply
,form_change
);
6803 void Player::ApplyEquipSpell(SpellEntry
const* spellInfo
, Item
* item
, bool apply
, bool form_change
)
6807 // Cannot be used in this stance/form
6808 if(GetErrorAtShapeshiftedCast(spellInfo
, m_form
)!=0)
6811 if(form_change
) // check aura active state from other form
6814 for (int k
=0; k
< 3; ++k
)
6816 spellEffectPair spair
= spellEffectPair(spellInfo
->Id
, k
);
6817 for (AuraMap::iterator iter
= m_Auras
.lower_bound(spair
); iter
!= m_Auras
.upper_bound(spair
); ++iter
)
6819 if(!item
|| iter
->second
->GetCastItemGUID() == item
->GetGUID())
6829 if(found
) // and skip re-cast already active aura at form change
6833 DEBUG_LOG("WORLD: cast %s Equip spellId - %i", (item
? "item" : "itemset"), spellInfo
->Id
);
6835 CastSpell(this,spellInfo
,true,item
);
6839 if(form_change
) // check aura compatibility
6841 // Cannot be used in this stance/form
6842 if(GetErrorAtShapeshiftedCast(spellInfo
, m_form
)==0)
6843 return; // and remove only not compatible at form change
6847 RemoveAurasDueToItemSpell(item
,spellInfo
->Id
); // un-apply all spells , not only at-equipped
6849 RemoveAurasDueToSpell(spellInfo
->Id
); // un-apply spell (item set case)
6853 void Player::UpdateEquipSpellsAtFormChange()
6855 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
6857 if(m_items
[i
] && !m_items
[i
]->IsBroken())
6859 ApplyItemEquipSpell(m_items
[i
],false,true); // remove spells that not fit to form
6860 ApplyItemEquipSpell(m_items
[i
],true,true); // add spells that fit form but not active
6864 // item set bonuses not dependent from item broken state
6865 for(size_t setindex
= 0; setindex
< ItemSetEff
.size(); ++setindex
)
6867 ItemSetEffect
* eff
= ItemSetEff
[setindex
];
6871 for(uint32 y
=0;y
<8; ++y
)
6873 SpellEntry
const* spellInfo
= eff
->spells
[y
];
6877 ApplyEquipSpell(spellInfo
,NULL
,false,true); // remove spells that not fit to form
6878 ApplyEquipSpell(spellInfo
,NULL
,true,true); // add spells that fit form but not active
6883 void Player::CastItemCombatSpell(Item
*item
,Unit
* Target
, WeaponAttackType attType
)
6885 if(!item
|| item
->IsBroken())
6888 ItemPrototype
const *proto
= item
->GetProto();
6892 if (!Target
|| Target
== this )
6895 for (int i
= 0; i
< 5; i
++)
6897 _Spell
const& spellData
= proto
->Spells
[i
];
6900 if(!spellData
.SpellId
)
6903 // wrong triggering type
6904 if(spellData
.SpellTrigger
!= ITEM_SPELLTRIGGER_CHANCE_ON_HIT
)
6907 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellData
.SpellId
);
6910 sLog
.outError("WORLD: unknown Item spellid %i", spellData
.SpellId
);
6914 // not allow proc extra attack spell at extra attack
6915 if( m_extraAttacks
&& IsSpellHaveEffect(spellInfo
,SPELL_EFFECT_ADD_EXTRA_ATTACKS
) )
6918 float chance
= spellInfo
->procChance
;
6920 if(spellData
.SpellPPMRate
)
6922 uint32 WeaponSpeed
= GetAttackTime(attType
);
6923 chance
= GetPPMProcChance(WeaponSpeed
, spellData
.SpellPPMRate
);
6925 else if(chance
> 100.0f
)
6927 chance
= GetWeaponProcChance();
6930 if (roll_chance_f(chance
))
6931 CastSpell(Target
, spellInfo
->Id
, true, item
);
6934 // item combat enchantments
6935 for(int e_slot
= 0; e_slot
< MAX_ENCHANTMENT_SLOT
; ++e_slot
)
6937 uint32 enchant_id
= item
->GetEnchantmentId(EnchantmentSlot(e_slot
));
6938 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
6939 if(!pEnchant
) continue;
6940 for (int s
=0;s
<3;s
++)
6942 if(pEnchant
->type
[s
]!=ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL
)
6945 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(pEnchant
->spellid
[s
]);
6948 sLog
.outError("Player::CastItemCombatSpell Enchant %i, cast unknown spell %i", pEnchant
->ID
, pEnchant
->spellid
[s
]);
6952 float chance
= pEnchant
->amount
[s
] != 0 ? float(pEnchant
->amount
[s
]) : GetWeaponProcChance();
6953 if (roll_chance_f(chance
))
6955 if(IsPositiveSpell(pEnchant
->spellid
[s
]))
6956 CastSpell(this, pEnchant
->spellid
[s
], true, item
);
6958 CastSpell(Target
, pEnchant
->spellid
[s
], true, item
);
6964 void Player::_RemoveAllItemMods()
6966 sLog
.outDebug("_RemoveAllItemMods start.");
6968 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
6972 ItemPrototype
const *proto
= m_items
[i
]->GetProto();
6976 // item set bonuses not dependent from item broken state
6978 RemoveItemsSetItem(this,proto
);
6980 if(m_items
[i
]->IsBroken())
6983 ApplyItemEquipSpell(m_items
[i
],false);
6984 ApplyEnchantment(m_items
[i
], false);
6988 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
6992 if(m_items
[i
]->IsBroken())
6994 ItemPrototype
const *proto
= m_items
[i
]->GetProto();
6998 uint32 attacktype
= Player::GetAttackBySlot(i
);
6999 if(attacktype
< MAX_ATTACK
)
7000 _ApplyWeaponDependentAuraMods(m_items
[i
],WeaponAttackType(attacktype
),false);
7002 _ApplyItemBonuses(proto
,i
, false);
7004 if( i
== EQUIPMENT_SLOT_RANGED
)
7005 _ApplyAmmoBonuses();
7009 sLog
.outDebug("_RemoveAllItemMods complete.");
7012 void Player::_ApplyAllItemMods()
7014 sLog
.outDebug("_ApplyAllItemMods start.");
7016 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
7020 if(m_items
[i
]->IsBroken())
7023 ItemPrototype
const *proto
= m_items
[i
]->GetProto();
7027 uint32 attacktype
= Player::GetAttackBySlot(i
);
7028 if(attacktype
< MAX_ATTACK
)
7029 _ApplyWeaponDependentAuraMods(m_items
[i
],WeaponAttackType(attacktype
),true);
7031 _ApplyItemBonuses(proto
,i
, true);
7033 if( i
== EQUIPMENT_SLOT_RANGED
)
7034 _ApplyAmmoBonuses();
7038 for (int i
= 0; i
< INVENTORY_SLOT_BAG_END
; i
++)
7042 ItemPrototype
const *proto
= m_items
[i
]->GetProto();
7046 // item set bonuses not dependent from item broken state
7048 AddItemsSetItem(this,m_items
[i
]);
7050 if(m_items
[i
]->IsBroken())
7053 ApplyItemEquipSpell(m_items
[i
],true);
7054 ApplyEnchantment(m_items
[i
], true);
7058 sLog
.outDebug("_ApplyAllItemMods complete.");
7061 void Player::_ApplyAmmoBonuses()
7064 uint32 ammo_id
= GetUInt32Value(PLAYER_AMMO_ID
);
7068 float currentAmmoDPS
;
7070 ItemPrototype
const *ammo_proto
= objmgr
.GetItemPrototype( ammo_id
);
7071 if( !ammo_proto
|| ammo_proto
->Class
!=ITEM_CLASS_PROJECTILE
|| !CheckAmmoCompatibility(ammo_proto
))
7072 currentAmmoDPS
= 0.0f
;
7074 currentAmmoDPS
= ammo_proto
->Damage
[0].DamageMin
;
7076 if(currentAmmoDPS
== GetAmmoDPS())
7079 m_ammoDPS
= currentAmmoDPS
;
7081 if(CanModifyStats())
7082 UpdateDamagePhysical(RANGED_ATTACK
);
7085 bool Player::CheckAmmoCompatibility(const ItemPrototype
*ammo_proto
) const
7090 // check ranged weapon
7091 Item
*weapon
= GetWeaponForAttack( RANGED_ATTACK
);
7092 if(!weapon
|| weapon
->IsBroken() )
7095 ItemPrototype
const* weapon_proto
= weapon
->GetProto();
7096 if(!weapon_proto
|| weapon_proto
->Class
!=ITEM_CLASS_WEAPON
)
7099 // check ammo ws. weapon compatibility
7100 switch(weapon_proto
->SubClass
)
7102 case ITEM_SUBCLASS_WEAPON_BOW
:
7103 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
7104 if(ammo_proto
->SubClass
!=ITEM_SUBCLASS_ARROW
)
7107 case ITEM_SUBCLASS_WEAPON_GUN
:
7108 if(ammo_proto
->SubClass
!=ITEM_SUBCLASS_BULLET
)
7118 /* If in a battleground a player dies, and an enemy removes the insignia, the player's bones is lootable
7119 Called by remove insignia spell effect */
7120 void Player::RemovedInsignia(Player
* looterPlr
)
7122 if (!GetBattleGroundId())
7125 // If not released spirit, do it !
7126 if(m_deathTimer
> 0)
7133 Corpse
*corpse
= GetCorpse();
7137 // We have to convert player corpse to bones, not to be able to resurrect there
7138 // SpawnCorpseBones isn't handy, 'cos it saves player while he in BG
7139 Corpse
*bones
= ObjectAccessor::Instance().ConvertCorpseForPlayer(GetGUID());
7143 // Now we must make bones lootable, and send player loot
7144 bones
->SetFlag(CORPSE_FIELD_DYNAMIC_FLAGS
, CORPSE_DYNFLAG_LOOTABLE
);
7146 // We store the level of our player in the gold field
7147 // We retrieve this information at Player::SendLoot()
7148 bones
->loot
.gold
= getLevel();
7149 bones
->lootRecipient
= looterPlr
;
7150 looterPlr
->SendLoot(bones
->GetGUID(), LOOT_INSIGNIA
);
7159 void Player::SendLootRelease( uint64 guid
)
7161 WorldPacket
data( SMSG_LOOT_RELEASE_RESPONSE
, (8+1) );
7162 data
<< uint64(guid
) << uint8(1);
7163 SendDirectMessage( &data
);
7166 void Player::SendLoot(uint64 guid
, LootType loot_type
)
7169 PermissionTypes permission
= ALL_PERMISSION
;
7171 sLog
.outDebug("Player::SendLoot");
7172 if (IS_GAMEOBJECT_GUID(guid
))
7174 sLog
.outDebug(" IS_GAMEOBJECT_GUID(guid)");
7176 ObjectAccessor::GetGameObject(*this, guid
);
7178 // not check distance for GO in case owned GO (fishing bobber case, for example)
7179 // And permit out of range GO with no owner in case fishing hole
7180 if (!go
|| (loot_type
!= LOOT_FISHINGHOLE
&& (loot_type
!= LOOT_FISHING
|| go
->GetOwnerGUID() != GetGUID()) && !go
->IsWithinDistInMap(this,INTERACTION_DISTANCE
)))
7182 SendLootRelease(guid
);
7188 if(go
->getLootState() == GO_READY
)
7190 uint32 lootid
= go
->GetLootId();
7194 sLog
.outDebug(" if(lootid)");
7196 loot
->FillLoot(lootid
, LootTemplates_Gameobject
, this);
7199 if(loot_type
== LOOT_FISHING
)
7200 go
->getFishLoot(loot
);
7202 go
->SetLootState(GO_ACTIVATED
);
7205 else if (IS_ITEM_GUID(guid
))
7207 Item
*item
= GetItemByGuid( guid
);
7211 SendLootRelease(guid
);
7215 if(loot_type
== LOOT_DISENCHANTING
)
7219 if(!item
->m_lootGenerated
)
7221 item
->m_lootGenerated
= true;
7223 loot
->FillLoot(item
->GetProto()->DisenchantID
, LootTemplates_Disenchant
, this);
7226 else if(loot_type
== LOOT_PROSPECTING
)
7230 if(!item
->m_lootGenerated
)
7232 item
->m_lootGenerated
= true;
7234 loot
->FillLoot(item
->GetEntry(), LootTemplates_Prospecting
, this);
7237 else if(loot_type
== LOOT_MILLING
)
7241 if(!item
->m_lootGenerated
)
7243 item
->m_lootGenerated
= true;
7245 loot
->FillLoot(item
->GetEntry(), LootTemplates_Milling
, this);
7252 if(!item
->m_lootGenerated
)
7254 item
->m_lootGenerated
= true;
7256 loot
->FillLoot(item
->GetEntry(), LootTemplates_Item
, this);
7258 loot
->generateMoneyLoot(item
->GetProto()->MinMoneyLoot
,item
->GetProto()->MaxMoneyLoot
);
7262 else if (IS_CORPSE_GUID(guid
)) // remove insignia
7264 Corpse
*bones
= ObjectAccessor::GetCorpse(*this, guid
);
7266 if (!bones
|| !((loot_type
== LOOT_CORPSE
) || (loot_type
== LOOT_INSIGNIA
)) || (bones
->GetType() != CORPSE_BONES
) )
7268 SendLootRelease(guid
);
7272 loot
= &bones
->loot
;
7274 if (!bones
->lootForBody
)
7276 bones
->lootForBody
= true;
7277 uint32 pLevel
= bones
->loot
.gold
;
7278 bones
->loot
.clear();
7279 // It may need a better formula
7280 // Now it works like this: lvl10: ~6copper, lvl70: ~9silver
7281 bones
->loot
.gold
= (uint32
)( urand(50, 150) * 0.016f
* pow( ((float)pLevel
)/5.76f
, 2.5f
) * sWorld
.getRate(RATE_DROP_MONEY
) );
7284 if (bones
->lootRecipient
!= this)
7285 permission
= NONE_PERMISSION
;
7289 Creature
*creature
= ObjectAccessor::GetCreature(*this, guid
);
7291 // must be in range and creature must be alive for pickpocket and must be dead for another loot
7292 if (!creature
|| creature
->isAlive()!=(loot_type
== LOOT_PICKPOCKETING
) || !creature
->IsWithinDistInMap(this,INTERACTION_DISTANCE
))
7294 SendLootRelease(guid
);
7298 if(loot_type
== LOOT_PICKPOCKETING
&& IsFriendlyTo(creature
))
7300 SendLootRelease(guid
);
7304 loot
= &creature
->loot
;
7306 if(loot_type
== LOOT_PICKPOCKETING
)
7308 if ( !creature
->lootForPickPocketed
)
7310 creature
->lootForPickPocketed
= true;
7313 if (uint32 lootid
= creature
->GetCreatureInfo()->pickpocketLootId
)
7314 loot
->FillLoot(lootid
, LootTemplates_Pickpocketing
, this);
7316 // Generate extra money for pick pocket loot
7317 const uint32 a
= urand(0, creature
->getLevel()/2);
7318 const uint32 b
= urand(0, getLevel()/2);
7319 loot
->gold
= uint32(10 * (a
+ b
) * sWorld
.getRate(RATE_DROP_MONEY
));
7324 // the player whose group may loot the corpse
7325 Player
*recipient
= creature
->GetLootRecipient();
7328 creature
->SetLootRecipient(this);
7332 if (creature
->lootForPickPocketed
)
7334 creature
->lootForPickPocketed
= false;
7338 if(!creature
->lootForBody
)
7340 creature
->lootForBody
= true;
7343 if (uint32 lootid
= creature
->GetCreatureInfo()->lootid
)
7344 loot
->FillLoot(lootid
, LootTemplates_Creature
, recipient
);
7346 loot
->generateMoneyLoot(creature
->GetCreatureInfo()->mingold
,creature
->GetCreatureInfo()->maxgold
);
7348 if(Group
* group
= recipient
->GetGroup())
7350 group
->UpdateLooterGuid(creature
,true);
7352 switch (group
->GetLootMethod())
7355 // GroupLoot delete items over threshold (threshold even not implemented), and roll them. Items with quality<threshold, round robin
7356 group
->GroupLoot(recipient
->GetGUID(), loot
, creature
);
7358 case NEED_BEFORE_GREED
:
7359 group
->NeedBeforeGreed(recipient
->GetGUID(), loot
, creature
);
7362 group
->MasterLoot(recipient
->GetGUID(), loot
, creature
);
7370 // possible only if creature->lootForBody && loot->empty() at spell cast check
7371 if (loot_type
== LOOT_SKINNING
)
7374 loot
->FillLoot(creature
->GetCreatureInfo()->SkinLootId
, LootTemplates_Skinning
, this);
7376 // set group rights only for loot_type != LOOT_SKINNING
7379 if(Group
* group
= GetGroup())
7381 if( group
== recipient
->GetGroup() )
7383 if(group
->GetLootMethod() == FREE_FOR_ALL
)
7384 permission
= ALL_PERMISSION
;
7385 else if(group
->GetLooterGuid() == GetGUID())
7387 if(group
->GetLootMethod() == MASTER_LOOT
)
7388 permission
= MASTER_PERMISSION
;
7390 permission
= ALL_PERMISSION
;
7393 permission
= GROUP_PERMISSION
;
7396 permission
= NONE_PERMISSION
;
7398 else if(recipient
== this)
7399 permission
= ALL_PERMISSION
;
7401 permission
= NONE_PERMISSION
;
7408 QuestItemList
*q_list
= 0;
7409 if (permission
!= NONE_PERMISSION
)
7411 QuestItemMap
const& lootPlayerQuestItems
= loot
->GetPlayerQuestItems();
7412 QuestItemMap::const_iterator itr
= lootPlayerQuestItems
.find(GetGUIDLow());
7413 if (itr
== lootPlayerQuestItems
.end())
7414 q_list
= loot
->FillQuestLoot(this);
7416 q_list
= itr
->second
;
7419 QuestItemList
*ffa_list
= 0;
7420 if (permission
!= NONE_PERMISSION
)
7422 QuestItemMap
const& lootPlayerFFAItems
= loot
->GetPlayerFFAItems();
7423 QuestItemMap::const_iterator itr
= lootPlayerFFAItems
.find(GetGUIDLow());
7424 if (itr
== lootPlayerFFAItems
.end())
7425 ffa_list
= loot
->FillFFALoot(this);
7427 ffa_list
= itr
->second
;
7430 QuestItemList
*conditional_list
= 0;
7431 if (permission
!= NONE_PERMISSION
)
7433 QuestItemMap
const& lootPlayerNonQuestNonFFAConditionalItems
= loot
->GetPlayerNonQuestNonFFAConditionalItems();
7434 QuestItemMap::const_iterator itr
= lootPlayerNonQuestNonFFAConditionalItems
.find(GetGUIDLow());
7435 if (itr
== lootPlayerNonQuestNonFFAConditionalItems
.end())
7436 conditional_list
= loot
->FillNonQuestNonFFAConditionalLoot(this);
7438 conditional_list
= itr
->second
;
7441 // LOOT_PICKPOCKETING, LOOT_PROSPECTING, LOOT_DISENCHANTING, LOOT_INSIGNIA and LOOT_MILLING unsupported by client, sending LOOT_SKINNING instead
7442 if(loot_type
== LOOT_PICKPOCKETING
|| loot_type
== LOOT_DISENCHANTING
|| loot_type
== LOOT_PROSPECTING
|| loot_type
== LOOT_INSIGNIA
|| loot_type
== LOOT_MILLING
)
7443 loot_type
= LOOT_SKINNING
;
7445 if(loot_type
== LOOT_FISHINGHOLE
)
7446 loot_type
= LOOT_FISHING
;
7448 WorldPacket
data(SMSG_LOOT_RESPONSE
, (9+50)); // we guess size
7450 data
<< uint64(guid
);
7451 data
<< uint8(loot_type
);
7452 data
<< LootView(*loot
, q_list
, ffa_list
, conditional_list
, this, permission
);
7454 SendDirectMessage(&data
);
7456 // add 'this' player as one of the players that are looting 'loot'
7457 if (permission
!= NONE_PERMISSION
)
7458 loot
->AddLooter(GetGUID());
7460 if ( loot_type
== LOOT_CORPSE
&& !IS_ITEM_GUID(guid
) )
7461 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_LOOTING
);
7464 void Player::SendNotifyLootMoneyRemoved()
7466 WorldPacket
data(SMSG_LOOT_CLEAR_MONEY
, 0);
7467 GetSession()->SendPacket( &data
);
7470 void Player::SendNotifyLootItemRemoved(uint8 lootSlot
)
7472 WorldPacket
data(SMSG_LOOT_REMOVED
, 1);
7473 data
<< uint8(lootSlot
);
7474 GetSession()->SendPacket( &data
);
7477 void Player::SendUpdateWorldState(uint32 Field
, uint32 Value
)
7479 WorldPacket
data(SMSG_UPDATE_WORLD_STATE
, 8);
7482 GetSession()->SendPacket(&data
);
7485 void Player::SendInitWorldStates()
7487 // data depends on zoneid/mapid...
7488 BattleGround
* bg
= GetBattleGround();
7489 uint16 NumberOfFields
= 0;
7490 uint32 mapid
= GetMapId();
7491 uint32 zoneid
= GetZoneId();
7492 uint32 areaid
= GetAreaId();
7493 sLog
.outDebug("Sending SMSG_INIT_WORLD_STATES to Map:%u, Zone: %u", mapid
, zoneid
);
7494 // may be exist better way to do this...
7517 NumberOfFields
= 81;
7520 NumberOfFields
= 14;
7524 NumberOfFields
= 38;
7527 NumberOfFields
= 22;
7530 NumberOfFields
= 36;
7533 NumberOfFields
= 35;
7544 NumberOfFields
= 10;
7548 WorldPacket
data(SMSG_INIT_WORLD_STATES
, (4+4+4+2+(NumberOfFields
*8)));
7549 data
<< uint32(mapid
); // mapid
7550 data
<< uint32(zoneid
); // zone id
7551 data
<< uint32(areaid
); // area id, new 2.1.0
7552 data
<< uint16(NumberOfFields
); // count of uint64 blocks
7553 data
<< uint32(0x8d8) << uint32(0x0); // 1
7554 data
<< uint32(0x8d7) << uint32(0x0); // 2
7555 data
<< uint32(0x8d6) << uint32(0x0); // 3
7556 data
<< uint32(0x8d5) << uint32(0x0); // 4
7557 data
<< uint32(0x8d4) << uint32(0x0); // 5
7558 data
<< uint32(0x8d3) << uint32(0x0); // 6
7559 if(mapid
== 530) // Outland
7561 data
<< uint32(0x9bf) << uint32(0x0); // 7
7562 data
<< uint32(0x9bd) << uint32(0xF); // 8
7563 data
<< uint32(0x9bb) << uint32(0xF); // 9
7578 data
<< uint32(0x7ae) << uint32(0x1); // 7
7579 data
<< uint32(0x532) << uint32(0x1); // 8
7580 data
<< uint32(0x531) << uint32(0x0); // 9
7581 data
<< uint32(0x52e) << uint32(0x0); // 10
7582 data
<< uint32(0x571) << uint32(0x0); // 11
7583 data
<< uint32(0x570) << uint32(0x0); // 12
7584 data
<< uint32(0x567) << uint32(0x1); // 13
7585 data
<< uint32(0x566) << uint32(0x1); // 14
7586 data
<< uint32(0x550) << uint32(0x1); // 15
7587 data
<< uint32(0x544) << uint32(0x0); // 16
7588 data
<< uint32(0x536) << uint32(0x0); // 17
7589 data
<< uint32(0x535) << uint32(0x1); // 18
7590 data
<< uint32(0x518) << uint32(0x0); // 19
7591 data
<< uint32(0x517) << uint32(0x0); // 20
7592 data
<< uint32(0x574) << uint32(0x0); // 21
7593 data
<< uint32(0x573) << uint32(0x0); // 22
7594 data
<< uint32(0x572) << uint32(0x0); // 23
7595 data
<< uint32(0x56f) << uint32(0x0); // 24
7596 data
<< uint32(0x56e) << uint32(0x0); // 25
7597 data
<< uint32(0x56d) << uint32(0x0); // 26
7598 data
<< uint32(0x56c) << uint32(0x0); // 27
7599 data
<< uint32(0x56b) << uint32(0x0); // 28
7600 data
<< uint32(0x56a) << uint32(0x1); // 29
7601 data
<< uint32(0x569) << uint32(0x1); // 30
7602 data
<< uint32(0x568) << uint32(0x1); // 13
7603 data
<< uint32(0x565) << uint32(0x0); // 32
7604 data
<< uint32(0x564) << uint32(0x0); // 33
7605 data
<< uint32(0x563) << uint32(0x0); // 34
7606 data
<< uint32(0x562) << uint32(0x0); // 35
7607 data
<< uint32(0x561) << uint32(0x0); // 36
7608 data
<< uint32(0x560) << uint32(0x0); // 37
7609 data
<< uint32(0x55f) << uint32(0x0); // 38
7610 data
<< uint32(0x55e) << uint32(0x0); // 39
7611 data
<< uint32(0x55d) << uint32(0x0); // 40
7612 data
<< uint32(0x3c6) << uint32(0x4); // 41
7613 data
<< uint32(0x3c4) << uint32(0x6); // 42
7614 data
<< uint32(0x3c2) << uint32(0x4); // 43
7615 data
<< uint32(0x516) << uint32(0x1); // 44
7616 data
<< uint32(0x515) << uint32(0x0); // 45
7617 data
<< uint32(0x3b6) << uint32(0x6); // 46
7618 data
<< uint32(0x55c) << uint32(0x0); // 47
7619 data
<< uint32(0x55b) << uint32(0x0); // 48
7620 data
<< uint32(0x55a) << uint32(0x0); // 49
7621 data
<< uint32(0x559) << uint32(0x0); // 50
7622 data
<< uint32(0x558) << uint32(0x0); // 51
7623 data
<< uint32(0x557) << uint32(0x0); // 52
7624 data
<< uint32(0x556) << uint32(0x0); // 53
7625 data
<< uint32(0x555) << uint32(0x0); // 54
7626 data
<< uint32(0x554) << uint32(0x1); // 55
7627 data
<< uint32(0x553) << uint32(0x1); // 56
7628 data
<< uint32(0x552) << uint32(0x1); // 57
7629 data
<< uint32(0x551) << uint32(0x1); // 58
7630 data
<< uint32(0x54f) << uint32(0x0); // 59
7631 data
<< uint32(0x54e) << uint32(0x0); // 60
7632 data
<< uint32(0x54d) << uint32(0x1); // 61
7633 data
<< uint32(0x54c) << uint32(0x0); // 62
7634 data
<< uint32(0x54b) << uint32(0x0); // 63
7635 data
<< uint32(0x545) << uint32(0x0); // 64
7636 data
<< uint32(0x543) << uint32(0x1); // 65
7637 data
<< uint32(0x542) << uint32(0x0); // 66
7638 data
<< uint32(0x540) << uint32(0x0); // 67
7639 data
<< uint32(0x53f) << uint32(0x0); // 68
7640 data
<< uint32(0x53e) << uint32(0x0); // 69
7641 data
<< uint32(0x53d) << uint32(0x0); // 70
7642 data
<< uint32(0x53c) << uint32(0x0); // 71
7643 data
<< uint32(0x53b) << uint32(0x0); // 72
7644 data
<< uint32(0x53a) << uint32(0x1); // 73
7645 data
<< uint32(0x539) << uint32(0x0); // 74
7646 data
<< uint32(0x538) << uint32(0x0); // 75
7647 data
<< uint32(0x537) << uint32(0x0); // 76
7648 data
<< uint32(0x534) << uint32(0x0); // 77
7649 data
<< uint32(0x533) << uint32(0x0); // 78
7650 data
<< uint32(0x530) << uint32(0x0); // 79
7651 data
<< uint32(0x52f) << uint32(0x0); // 80
7652 data
<< uint32(0x52d) << uint32(0x1); // 81
7655 if (bg
&& bg
->GetTypeID() == BATTLEGROUND_WS
)
7656 bg
->FillInitialWorldStates(data
);
7659 data
<< uint32(0x62d) << uint32(0x0); // 7 1581 alliance flag captures
7660 data
<< uint32(0x62e) << uint32(0x0); // 8 1582 horde flag captures
7661 data
<< uint32(0x609) << uint32(0x0); // 9 1545 unk, set to 1 on alliance flag pickup...
7662 data
<< uint32(0x60a) << uint32(0x0); // 10 1546 unk, set to 1 on horde flag pickup, after drop it's -1
7663 data
<< uint32(0x60b) << uint32(0x2); // 11 1547 unk
7664 data
<< uint32(0x641) << uint32(0x3); // 12 1601 unk (max flag captures?)
7665 data
<< uint32(0x922) << uint32(0x1); // 13 2338 horde (0 - hide, 1 - flag ok, 2 - flag picked up (flashing), 3 - flag picked up (not flashing)
7666 data
<< uint32(0x923) << uint32(0x1); // 14 2339 alliance (0 - hide, 1 - flag ok, 2 - flag picked up (flashing), 3 - flag picked up (not flashing)
7670 if (bg
&& bg
->GetTypeID() == BATTLEGROUND_AB
)
7671 bg
->FillInitialWorldStates(data
);
7674 data
<< uint32(0x6e7) << uint32(0x0); // 7 1767 stables alliance
7675 data
<< uint32(0x6e8) << uint32(0x0); // 8 1768 stables horde
7676 data
<< uint32(0x6e9) << uint32(0x0); // 9 1769 unk, ST?
7677 data
<< uint32(0x6ea) << uint32(0x0); // 10 1770 stables (show/hide)
7678 data
<< uint32(0x6ec) << uint32(0x0); // 11 1772 farm (0 - horde controlled, 1 - alliance controlled)
7679 data
<< uint32(0x6ed) << uint32(0x0); // 12 1773 farm (show/hide)
7680 data
<< uint32(0x6ee) << uint32(0x0); // 13 1774 farm color
7681 data
<< uint32(0x6ef) << uint32(0x0); // 14 1775 gold mine color, may be FM?
7682 data
<< uint32(0x6f0) << uint32(0x0); // 15 1776 alliance resources
7683 data
<< uint32(0x6f1) << uint32(0x0); // 16 1777 horde resources
7684 data
<< uint32(0x6f2) << uint32(0x0); // 17 1778 horde bases
7685 data
<< uint32(0x6f3) << uint32(0x0); // 18 1779 alliance bases
7686 data
<< uint32(0x6f4) << uint32(0x7d0); // 19 1780 max resources (2000)
7687 data
<< uint32(0x6f6) << uint32(0x0); // 20 1782 blacksmith color
7688 data
<< uint32(0x6f7) << uint32(0x0); // 21 1783 blacksmith (show/hide)
7689 data
<< uint32(0x6f8) << uint32(0x0); // 22 1784 unk, bs?
7690 data
<< uint32(0x6f9) << uint32(0x0); // 23 1785 unk, bs?
7691 data
<< uint32(0x6fb) << uint32(0x0); // 24 1787 gold mine (0 - horde contr, 1 - alliance contr)
7692 data
<< uint32(0x6fc) << uint32(0x0); // 25 1788 gold mine (0 - conflict, 1 - horde)
7693 data
<< uint32(0x6fd) << uint32(0x0); // 26 1789 gold mine (1 - show/0 - hide)
7694 data
<< uint32(0x6fe) << uint32(0x0); // 27 1790 gold mine color
7695 data
<< uint32(0x700) << uint32(0x0); // 28 1792 gold mine color, wtf?, may be LM?
7696 data
<< uint32(0x701) << uint32(0x0); // 29 1793 lumber mill color (0 - conflict, 1 - horde contr)
7697 data
<< uint32(0x702) << uint32(0x0); // 30 1794 lumber mill (show/hide)
7698 data
<< uint32(0x703) << uint32(0x0); // 31 1795 lumber mill color color
7699 data
<< uint32(0x732) << uint32(0x1); // 32 1842 stables (1 - uncontrolled)
7700 data
<< uint32(0x733) << uint32(0x1); // 33 1843 gold mine (1 - uncontrolled)
7701 data
<< uint32(0x734) << uint32(0x1); // 34 1844 lumber mill (1 - uncontrolled)
7702 data
<< uint32(0x735) << uint32(0x1); // 35 1845 farm (1 - uncontrolled)
7703 data
<< uint32(0x736) << uint32(0x1); // 36 1846 blacksmith (1 - uncontrolled)
7704 data
<< uint32(0x745) << uint32(0x2); // 37 1861 unk
7705 data
<< uint32(0x7a3) << uint32(0x708); // 38 1955 warning limit (1800)
7709 if (bg
&& bg
->GetTypeID() == BATTLEGROUND_EY
)
7710 bg
->FillInitialWorldStates(data
);
7713 data
<< uint32(0xac1) << uint32(0x0); // 7 2753 Horde Bases
7714 data
<< uint32(0xac0) << uint32(0x0); // 8 2752 Alliance Bases
7715 data
<< uint32(0xab6) << uint32(0x0); // 9 2742 Mage Tower - Horde conflict
7716 data
<< uint32(0xab5) << uint32(0x0); // 10 2741 Mage Tower - Alliance conflict
7717 data
<< uint32(0xab4) << uint32(0x0); // 11 2740 Fel Reaver - Horde conflict
7718 data
<< uint32(0xab3) << uint32(0x0); // 12 2739 Fel Reaver - Alliance conflict
7719 data
<< uint32(0xab2) << uint32(0x0); // 13 2738 Draenei - Alliance conflict
7720 data
<< uint32(0xab1) << uint32(0x0); // 14 2737 Draenei - Horde conflict
7721 data
<< uint32(0xab0) << uint32(0x0); // 15 2736 unk // 0 at start
7722 data
<< uint32(0xaaf) << uint32(0x0); // 16 2735 unk // 0 at start
7723 data
<< uint32(0xaad) << uint32(0x0); // 17 2733 Draenei - Horde control
7724 data
<< uint32(0xaac) << uint32(0x0); // 18 2732 Draenei - Alliance control
7725 data
<< uint32(0xaab) << uint32(0x1); // 19 2731 Draenei uncontrolled (1 - yes, 0 - no)
7726 data
<< uint32(0xaaa) << uint32(0x0); // 20 2730 Mage Tower - Alliance control
7727 data
<< uint32(0xaa9) << uint32(0x0); // 21 2729 Mage Tower - Horde control
7728 data
<< uint32(0xaa8) << uint32(0x1); // 22 2728 Mage Tower uncontrolled (1 - yes, 0 - no)
7729 data
<< uint32(0xaa7) << uint32(0x0); // 23 2727 Fel Reaver - Horde control
7730 data
<< uint32(0xaa6) << uint32(0x0); // 24 2726 Fel Reaver - Alliance control
7731 data
<< uint32(0xaa5) << uint32(0x1); // 25 2725 Fel Reaver uncontrolled (1 - yes, 0 - no)
7732 data
<< uint32(0xaa4) << uint32(0x0); // 26 2724 Boold Elf - Horde control
7733 data
<< uint32(0xaa3) << uint32(0x0); // 27 2723 Boold Elf - Alliance control
7734 data
<< uint32(0xaa2) << uint32(0x1); // 28 2722 Boold Elf uncontrolled (1 - yes, 0 - no)
7735 data
<< uint32(0xac5) << uint32(0x1); // 29 2757 Flag (1 - show, 0 - hide) - doesn't work exactly this way!
7736 data
<< uint32(0xad2) << uint32(0x1); // 30 2770 Horde top-stats (1 - show, 0 - hide) // 02 -> horde picked up the flag
7737 data
<< uint32(0xad1) << uint32(0x1); // 31 2769 Alliance top-stats (1 - show, 0 - hide) // 02 -> alliance picked up the flag
7738 data
<< uint32(0xabe) << uint32(0x0); // 32 2750 Horde resources
7739 data
<< uint32(0xabd) << uint32(0x0); // 33 2749 Alliance resources
7740 data
<< uint32(0xa05) << uint32(0x8e); // 34 2565 unk, constant?
7741 data
<< uint32(0xaa0) << uint32(0x0); // 35 2720 Capturing progress-bar (100 -> empty (only grey), 0 -> blue|red (no grey), default 0)
7742 data
<< uint32(0xa9f) << uint32(0x0); // 36 2719 Capturing progress-bar (0 - left, 100 - right)
7743 data
<< uint32(0xa9e) << uint32(0x0); // 37 2718 Capturing progress-bar (1 - show, 0 - hide)
7744 data
<< uint32(0xc0d) << uint32(0x17b); // 38 3085 unk
7745 // and some more ... unknown
7748 case 3483: // Hellfire Peninsula
7749 data
<< uint32(0x9ba) << uint32(0x1); // 10
7750 data
<< uint32(0x9b9) << uint32(0x1); // 11
7751 data
<< uint32(0x9b5) << uint32(0x0); // 12
7752 data
<< uint32(0x9b4) << uint32(0x1); // 13
7753 data
<< uint32(0x9b3) << uint32(0x0); // 14
7754 data
<< uint32(0x9b2) << uint32(0x0); // 15
7755 data
<< uint32(0x9b1) << uint32(0x1); // 16
7756 data
<< uint32(0x9b0) << uint32(0x0); // 17
7757 data
<< uint32(0x9ae) << uint32(0x0); // 18 horde pvp objectives captured
7758 data
<< uint32(0x9ac) << uint32(0x0); // 19
7759 data
<< uint32(0x9a8) << uint32(0x0); // 20
7760 data
<< uint32(0x9a7) << uint32(0x0); // 21
7761 data
<< uint32(0x9a6) << uint32(0x1); // 22
7763 case 3519: // Terokkar Forest
7764 data
<< uint32(0xa41) << uint32(0x0); // 10
7765 data
<< uint32(0xa40) << uint32(0x14); // 11
7766 data
<< uint32(0xa3f) << uint32(0x0); // 12
7767 data
<< uint32(0xa3e) << uint32(0x0); // 13
7768 data
<< uint32(0xa3d) << uint32(0x5); // 14
7769 data
<< uint32(0xa3c) << uint32(0x0); // 15
7770 data
<< uint32(0xa87) << uint32(0x0); // 16
7771 data
<< uint32(0xa86) << uint32(0x0); // 17
7772 data
<< uint32(0xa85) << uint32(0x0); // 18
7773 data
<< uint32(0xa84) << uint32(0x0); // 19
7774 data
<< uint32(0xa83) << uint32(0x0); // 20
7775 data
<< uint32(0xa82) << uint32(0x0); // 21
7776 data
<< uint32(0xa81) << uint32(0x0); // 22
7777 data
<< uint32(0xa80) << uint32(0x0); // 23
7778 data
<< uint32(0xa7e) << uint32(0x0); // 24
7779 data
<< uint32(0xa7d) << uint32(0x0); // 25
7780 data
<< uint32(0xa7c) << uint32(0x0); // 26
7781 data
<< uint32(0xa7b) << uint32(0x0); // 27
7782 data
<< uint32(0xa7a) << uint32(0x0); // 28
7783 data
<< uint32(0xa79) << uint32(0x0); // 29
7784 data
<< uint32(0x9d0) << uint32(0x5); // 30
7785 data
<< uint32(0x9ce) << uint32(0x0); // 31
7786 data
<< uint32(0x9cd) << uint32(0x0); // 32
7787 data
<< uint32(0x9cc) << uint32(0x0); // 33
7788 data
<< uint32(0xa88) << uint32(0x0); // 34
7789 data
<< uint32(0xad0) << uint32(0x0); // 35
7790 data
<< uint32(0xacf) << uint32(0x1); // 36
7792 case 3521: // Zangarmarsh
7793 data
<< uint32(0x9e1) << uint32(0x0); // 10
7794 data
<< uint32(0x9e0) << uint32(0x0); // 11
7795 data
<< uint32(0x9df) << uint32(0x0); // 12
7796 data
<< uint32(0xa5d) << uint32(0x1); // 13
7797 data
<< uint32(0xa5c) << uint32(0x0); // 14
7798 data
<< uint32(0xa5b) << uint32(0x1); // 15
7799 data
<< uint32(0xa5a) << uint32(0x0); // 16
7800 data
<< uint32(0xa59) << uint32(0x1); // 17
7801 data
<< uint32(0xa58) << uint32(0x0); // 18
7802 data
<< uint32(0xa57) << uint32(0x0); // 19
7803 data
<< uint32(0xa56) << uint32(0x0); // 20
7804 data
<< uint32(0xa55) << uint32(0x1); // 21
7805 data
<< uint32(0xa54) << uint32(0x0); // 22
7806 data
<< uint32(0x9e7) << uint32(0x0); // 23
7807 data
<< uint32(0x9e6) << uint32(0x0); // 24
7808 data
<< uint32(0x9e5) << uint32(0x0); // 25
7809 data
<< uint32(0xa00) << uint32(0x0); // 26
7810 data
<< uint32(0x9ff) << uint32(0x1); // 27
7811 data
<< uint32(0x9fe) << uint32(0x0); // 28
7812 data
<< uint32(0x9fd) << uint32(0x0); // 29
7813 data
<< uint32(0x9fc) << uint32(0x1); // 30
7814 data
<< uint32(0x9fb) << uint32(0x0); // 31
7815 data
<< uint32(0xa62) << uint32(0x0); // 32
7816 data
<< uint32(0xa61) << uint32(0x1); // 33
7817 data
<< uint32(0xa60) << uint32(0x1); // 34
7818 data
<< uint32(0xa5f) << uint32(0x0); // 35
7820 case 3698: // Nagrand Arena
7821 data
<< uint32(0xa0f) << uint32(0x0); // 7
7822 data
<< uint32(0xa10) << uint32(0x0); // 8
7823 data
<< uint32(0xa11) << uint32(0x0); // 9
7825 case 3702: // Blade's Edge Arena
7826 data
<< uint32(0x9f0) << uint32(0x0); // 7
7827 data
<< uint32(0x9f1) << uint32(0x0); // 8
7828 data
<< uint32(0x9f3) << uint32(0x0); // 9
7830 case 3968: // Ruins of Lordaeron
7831 data
<< uint32(0xbb8) << uint32(0x0); // 7
7832 data
<< uint32(0xbb9) << uint32(0x0); // 8
7833 data
<< uint32(0xbba) << uint32(0x0); // 9
7835 case 3703: // Shattrath City
7838 data
<< uint32(0x914) << uint32(0x0); // 7
7839 data
<< uint32(0x913) << uint32(0x0); // 8
7840 data
<< uint32(0x912) << uint32(0x0); // 9
7841 data
<< uint32(0x915) << uint32(0x0); // 10
7844 GetSession()->SendPacket(&data
);
7847 uint32
Player::GetXPRestBonus(uint32 xp
)
7849 uint32 rested_bonus
= (uint32
)GetRestBonus(); // xp for each rested bonus
7851 if(rested_bonus
> xp
) // max rested_bonus == xp or (r+x) = 200% xp
7854 SetRestBonus( GetRestBonus() - rested_bonus
);
7856 sLog
.outDetail("Player gain %u xp (+ %u Rested Bonus). Rested points=%f",xp
+rested_bonus
,rested_bonus
,GetRestBonus());
7857 return rested_bonus
;
7860 void Player::SetBindPoint(uint64 guid
)
7862 WorldPacket
data(SMSG_BINDER_CONFIRM
, 8);
7863 data
<< uint64(guid
);
7864 GetSession()->SendPacket( &data
);
7867 void Player::SendTalentWipeConfirm(uint64 guid
)
7869 WorldPacket
data(MSG_TALENT_WIPE_CONFIRM
, (8+4));
7870 data
<< uint64(guid
);
7871 data
<< uint32(resetTalentsCost());
7872 GetSession()->SendPacket( &data
);
7875 void Player::SendPetSkillWipeConfirm()
7877 Pet
* pet
= GetPet();
7880 WorldPacket
data(SMSG_PET_UNLEARN_CONFIRM
, (8+4));
7881 data
<< pet
->GetGUID();
7882 data
<< uint32(pet
->resetTalentsCost());
7883 GetSession()->SendPacket( &data
);
7886 /*********************************************************/
7887 /*** STORAGE SYSTEM ***/
7888 /*********************************************************/
7890 void Player::SetVirtualItemSlot( uint8 i
, Item
* item
)
7895 if(!item
->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT
))
7897 uint32 charges
= item
->GetEnchantmentCharges(TEMP_ENCHANTMENT_SLOT
);
7901 item
->SetEnchantmentCharges(TEMP_ENCHANTMENT_SLOT
,charges
-1);
7902 else if(charges
<= 1)
7904 ApplyEnchantment(item
,TEMP_ENCHANTMENT_SLOT
,false);
7905 item
->ClearEnchantment(TEMP_ENCHANTMENT_SLOT
);
7910 void Player::SetSheath( uint32 sheathed
)
7914 case SHEATH_STATE_UNARMED
: // no prepared weapon
7915 SetVirtualItemSlot(0,NULL
);
7916 SetVirtualItemSlot(1,NULL
);
7917 SetVirtualItemSlot(2,NULL
);
7919 case SHEATH_STATE_MELEE
: // prepared melee weapon
7921 SetVirtualItemSlot(0,GetWeaponForAttack(BASE_ATTACK
,true));
7922 SetVirtualItemSlot(1,GetWeaponForAttack(OFF_ATTACK
,true));
7923 SetVirtualItemSlot(2,NULL
);
7925 case SHEATH_STATE_RANGED
: // prepared ranged weapon
7926 SetVirtualItemSlot(0,NULL
);
7927 SetVirtualItemSlot(1,NULL
);
7928 SetVirtualItemSlot(2,GetWeaponForAttack(RANGED_ATTACK
,true));
7931 SetVirtualItemSlot(0,NULL
);
7932 SetVirtualItemSlot(1,NULL
);
7933 SetVirtualItemSlot(2,NULL
);
7936 SetByteValue(UNIT_FIELD_BYTES_2
, 0, sheathed
); // this must visualize Sheath changing for other players...
7939 uint8
Player::FindEquipSlot( ItemPrototype
const* proto
, uint32 slot
, bool swap
) const
7941 uint8 pClass
= getClass();
7944 slots
[0] = NULL_SLOT
;
7945 slots
[1] = NULL_SLOT
;
7946 slots
[2] = NULL_SLOT
;
7947 slots
[3] = NULL_SLOT
;
7948 switch( proto
->InventoryType
)
7951 slots
[0] = EQUIPMENT_SLOT_HEAD
;
7954 slots
[0] = EQUIPMENT_SLOT_NECK
;
7956 case INVTYPE_SHOULDERS
:
7957 slots
[0] = EQUIPMENT_SLOT_SHOULDERS
;
7960 slots
[0] = EQUIPMENT_SLOT_BODY
;
7963 slots
[0] = EQUIPMENT_SLOT_CHEST
;
7966 slots
[0] = EQUIPMENT_SLOT_CHEST
;
7969 slots
[0] = EQUIPMENT_SLOT_WAIST
;
7972 slots
[0] = EQUIPMENT_SLOT_LEGS
;
7975 slots
[0] = EQUIPMENT_SLOT_FEET
;
7977 case INVTYPE_WRISTS
:
7978 slots
[0] = EQUIPMENT_SLOT_WRISTS
;
7981 slots
[0] = EQUIPMENT_SLOT_HANDS
;
7983 case INVTYPE_FINGER
:
7984 slots
[0] = EQUIPMENT_SLOT_FINGER1
;
7985 slots
[1] = EQUIPMENT_SLOT_FINGER2
;
7987 case INVTYPE_TRINKET
:
7988 slots
[0] = EQUIPMENT_SLOT_TRINKET1
;
7989 slots
[1] = EQUIPMENT_SLOT_TRINKET2
;
7992 slots
[0] = EQUIPMENT_SLOT_BACK
;
7994 case INVTYPE_WEAPON
:
7996 slots
[0] = EQUIPMENT_SLOT_MAINHAND
;
7998 // suggest offhand slot only if know dual wielding
7999 // (this will be replace mainhand weapon at auto equip instead unwonted "you don't known dual wielding" ...
8001 slots
[1] = EQUIPMENT_SLOT_OFFHAND
;
8003 case INVTYPE_SHIELD
:
8004 slots
[0] = EQUIPMENT_SLOT_OFFHAND
;
8006 case INVTYPE_RANGED
:
8007 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8009 case INVTYPE_2HWEAPON
:
8010 slots
[0] = EQUIPMENT_SLOT_MAINHAND
;
8012 case INVTYPE_TABARD
:
8013 slots
[0] = EQUIPMENT_SLOT_TABARD
;
8015 case INVTYPE_WEAPONMAINHAND
:
8016 slots
[0] = EQUIPMENT_SLOT_MAINHAND
;
8018 case INVTYPE_WEAPONOFFHAND
:
8019 slots
[0] = EQUIPMENT_SLOT_OFFHAND
;
8021 case INVTYPE_HOLDABLE
:
8022 slots
[0] = EQUIPMENT_SLOT_OFFHAND
;
8024 case INVTYPE_THROWN
:
8025 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8027 case INVTYPE_RANGEDRIGHT
:
8028 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8031 slots
[0] = INVENTORY_SLOT_BAG_1
;
8032 slots
[1] = INVENTORY_SLOT_BAG_2
;
8033 slots
[2] = INVENTORY_SLOT_BAG_3
;
8034 slots
[3] = INVENTORY_SLOT_BAG_4
;
8038 switch(proto
->SubClass
)
8040 case ITEM_SUBCLASS_ARMOR_LIBRAM
:
8041 if (pClass
== CLASS_PALADIN
)
8042 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8044 case ITEM_SUBCLASS_ARMOR_IDOL
:
8045 if (pClass
== CLASS_DRUID
)
8046 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8048 case ITEM_SUBCLASS_ARMOR_TOTEM
:
8049 if (pClass
== CLASS_SHAMAN
)
8050 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8052 case ITEM_SUBCLASS_ARMOR_MISC
:
8053 if (pClass
== CLASS_WARLOCK
)
8054 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8056 case ITEM_SUBCLASS_ARMOR_SIGIL
:
8057 if (pClass
== CLASS_DEATH_KNIGHT
)
8058 slots
[0] = EQUIPMENT_SLOT_RANGED
;
8067 if( slot
!= NULL_SLOT
)
8069 if( swap
|| !GetItemByPos( INVENTORY_SLOT_BAG_0
, slot
) )
8071 for (int i
= 0; i
< 4; i
++)
8073 if ( slots
[i
] == slot
)
8080 // search free slot at first
8081 for (int i
= 0; i
< 4; i
++)
8083 if ( slots
[i
] != NULL_SLOT
&& !GetItemByPos( INVENTORY_SLOT_BAG_0
, slots
[i
] ) )
8085 // in case 2hand equipped weapon offhand slot empty but not free
8086 if(slots
[i
]==EQUIPMENT_SLOT_OFFHAND
)
8088 Item
* mainItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
8089 if(!mainItem
|| mainItem
->GetProto()->InventoryType
!= INVTYPE_2HWEAPON
)
8097 // if not found free and can swap return first appropriate from used
8098 for (int i
= 0; i
< 4; i
++)
8100 if ( slots
[i
] != NULL_SLOT
&& swap
)
8109 uint8
Player::CanUnequipItems( uint32 item
, uint32 count
) const
8112 uint32 tempcount
= 0;
8114 uint8 res
= EQUIP_ERR_OK
;
8116 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8118 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8119 if( pItem
&& pItem
->GetEntry() == item
)
8121 uint8 ires
= CanUnequipItem(INVENTORY_SLOT_BAG_0
<< 8 | i
, false);
8122 if(ires
==EQUIP_ERR_OK
)
8124 tempcount
+= pItem
->GetCount();
8125 if( tempcount
>= count
)
8126 return EQUIP_ERR_OK
;
8132 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8134 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8135 if( pItem
&& pItem
->GetEntry() == item
)
8137 tempcount
+= pItem
->GetCount();
8138 if( tempcount
>= count
)
8139 return EQUIP_ERR_OK
;
8142 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
8144 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8145 if( pItem
&& pItem
->GetEntry() == item
)
8147 tempcount
+= pItem
->GetCount();
8148 if( tempcount
>= count
)
8149 return EQUIP_ERR_OK
;
8153 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8155 pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8158 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8160 pItem
= GetItemByPos( i
, j
);
8161 if( pItem
&& pItem
->GetEntry() == item
)
8163 tempcount
+= pItem
->GetCount();
8164 if( tempcount
>= count
)
8165 return EQUIP_ERR_OK
;
8171 // not found req. item count and have unequippable items
8175 uint32
Player::GetItemCount( uint32 item
, bool inBankAlso
, Item
* skipItem
) const
8178 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8180 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8181 if( pItem
&& pItem
!= skipItem
&& pItem
->GetEntry() == item
)
8182 count
+= pItem
->GetCount();
8184 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
8186 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8187 if( pItem
&& pItem
!= skipItem
&& pItem
->GetEntry() == item
)
8188 count
+= pItem
->GetCount();
8190 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8192 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8194 count
+= pBag
->GetItemCount(item
,skipItem
);
8197 if(skipItem
&& skipItem
->GetProto()->GemProperties
)
8199 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8201 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8202 if( pItem
&& pItem
!= skipItem
&& pItem
->GetProto()->Socket
[0].Color
)
8203 count
+= pItem
->GetGemCountWithID(item
);
8209 for(int i
= BANK_SLOT_ITEM_START
; i
< BANK_SLOT_ITEM_END
; i
++)
8211 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8212 if( pItem
&& pItem
!= skipItem
&& pItem
->GetEntry() == item
)
8213 count
+= pItem
->GetCount();
8215 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
8217 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8219 count
+= pBag
->GetItemCount(item
,skipItem
);
8222 if(skipItem
&& skipItem
->GetProto()->GemProperties
)
8224 for(int i
= BANK_SLOT_ITEM_START
; i
< BANK_SLOT_ITEM_END
; i
++)
8226 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8227 if( pItem
&& pItem
!= skipItem
&& pItem
->GetProto()->Socket
[0].Color
)
8228 count
+= pItem
->GetGemCountWithID(item
);
8236 Item
* Player::GetItemByGuid( uint64 guid
) const
8238 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8240 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8241 if( pItem
&& pItem
->GetGUID() == guid
)
8244 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
8246 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8247 if( pItem
&& pItem
->GetGUID() == guid
)
8251 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8253 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8256 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8258 Item
* pItem
= pBag
->GetItemByPos( j
);
8259 if( pItem
&& pItem
->GetGUID() == guid
)
8264 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
8266 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8269 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8271 Item
* pItem
= pBag
->GetItemByPos( j
);
8272 if( pItem
&& pItem
->GetGUID() == guid
)
8281 Item
* Player::GetItemByPos( uint16 pos
) const
8283 uint8 bag
= pos
>> 8;
8284 uint8 slot
= pos
& 255;
8285 return GetItemByPos( bag
, slot
);
8288 Item
* Player::GetItemByPos( uint8 bag
, uint8 slot
) const
8290 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
< BANK_SLOT_BAG_END
|| slot
>= KEYRING_SLOT_START
&& slot
< QUESTBAG_SLOT_END
) )
8291 return m_items
[slot
];
8292 else if(bag
>= INVENTORY_SLOT_BAG_START
&& bag
< INVENTORY_SLOT_BAG_END
8293 || bag
>= BANK_SLOT_BAG_START
&& bag
< BANK_SLOT_BAG_END
)
8295 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
8297 return pBag
->GetItemByPos(slot
);
8302 Item
* Player::GetWeaponForAttack(WeaponAttackType attackType
, bool useable
) const
8307 case BASE_ATTACK
: slot
= EQUIPMENT_SLOT_MAINHAND
; break;
8308 case OFF_ATTACK
: slot
= EQUIPMENT_SLOT_OFFHAND
; break;
8309 case RANGED_ATTACK
: slot
= EQUIPMENT_SLOT_RANGED
; break;
8310 default: return NULL
;
8313 Item
* item
= GetItemByPos(INVENTORY_SLOT_BAG_0
, slot
);
8314 if (!item
|| item
->GetProto()->Class
!= ITEM_CLASS_WEAPON
)
8320 if( item
->IsBroken() || !IsUseEquipedWeapon(attackType
==BASE_ATTACK
) )
8326 Item
* Player::GetShield(bool useable
) const
8328 Item
* item
= GetItemByPos(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
8329 if (!item
|| item
->GetProto()->Class
!= ITEM_CLASS_ARMOR
)
8335 if( item
->IsBroken())
8341 uint32
Player::GetAttackBySlot( uint8 slot
)
8345 case EQUIPMENT_SLOT_MAINHAND
: return BASE_ATTACK
;
8346 case EQUIPMENT_SLOT_OFFHAND
: return OFF_ATTACK
;
8347 case EQUIPMENT_SLOT_RANGED
: return RANGED_ATTACK
;
8348 default: return MAX_ATTACK
;
8352 bool Player::HasBankBagSlot( uint8 slot
) const
8354 uint32 maxslot
= GetByteValue(PLAYER_BYTES_2
, 2) + BANK_SLOT_BAG_START
;
8355 if( slot
< maxslot
)
8360 bool Player::IsInventoryPos( uint8 bag
, uint8 slot
)
8362 if( bag
== INVENTORY_SLOT_BAG_0
&& slot
== NULL_SLOT
)
8364 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= INVENTORY_SLOT_ITEM_START
&& slot
< INVENTORY_SLOT_ITEM_END
) )
8366 if( bag
>= INVENTORY_SLOT_BAG_START
&& bag
< INVENTORY_SLOT_BAG_END
)
8368 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= KEYRING_SLOT_START
&& slot
< QUESTBAG_SLOT_END
) )
8373 bool Player::IsEquipmentPos( uint8 bag
, uint8 slot
)
8375 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
< EQUIPMENT_SLOT_END
) )
8377 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= INVENTORY_SLOT_BAG_START
&& slot
< INVENTORY_SLOT_BAG_END
) )
8382 bool Player::IsBankPos( uint8 bag
, uint8 slot
)
8384 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= BANK_SLOT_ITEM_START
&& slot
< BANK_SLOT_ITEM_END
) )
8386 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
) )
8388 if( bag
>= BANK_SLOT_BAG_START
&& bag
< BANK_SLOT_BAG_END
)
8393 bool Player::IsBagPos( uint16 pos
)
8395 uint8 bag
= pos
>> 8;
8396 uint8 slot
= pos
& 255;
8397 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= INVENTORY_SLOT_BAG_START
&& slot
< INVENTORY_SLOT_BAG_END
) )
8399 if( bag
== INVENTORY_SLOT_BAG_0
&& ( slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
) )
8404 bool Player::IsValidPos( uint8 bag
, uint8 slot
)
8410 if (bag
== INVENTORY_SLOT_BAG_0
)
8412 // any post selected
8413 if (slot
== NULL_SLOT
)
8417 if (slot
< EQUIPMENT_SLOT_END
)
8421 if (slot
>= INVENTORY_SLOT_BAG_START
&& slot
< INVENTORY_SLOT_BAG_END
)
8425 if (slot
>= INVENTORY_SLOT_ITEM_START
&& slot
< INVENTORY_SLOT_ITEM_END
)
8429 if (slot
>= KEYRING_SLOT_START
&& slot
< KEYRING_SLOT_END
)
8433 if (slot
>= BANK_SLOT_ITEM_START
&& slot
< BANK_SLOT_ITEM_END
)
8437 if (slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
)
8443 // bag content slots
8444 if (bag
>= INVENTORY_SLOT_BAG_START
&& bag
< INVENTORY_SLOT_BAG_END
)
8446 Bag
* pBag
= (Bag
*)GetItemByPos (INVENTORY_SLOT_BAG_0
, bag
);
8450 // any post selected
8451 if (slot
== NULL_SLOT
)
8454 return slot
< pBag
->GetBagSize();
8457 // bank bag content slots
8458 if( bag
>= BANK_SLOT_BAG_START
&& bag
< BANK_SLOT_BAG_END
)
8460 Bag
* pBag
= (Bag
*)GetItemByPos (INVENTORY_SLOT_BAG_0
, bag
);
8464 // any post selected
8465 if (slot
== NULL_SLOT
)
8468 return slot
< pBag
->GetBagSize();
8476 bool Player::HasItemCount( uint32 item
, uint32 count
, bool inBankAlso
) const
8478 uint32 tempcount
= 0;
8479 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
8481 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8482 if( pItem
&& pItem
->GetEntry() == item
)
8484 tempcount
+= pItem
->GetCount();
8485 if( tempcount
>= count
)
8489 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
8491 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8492 if( pItem
&& pItem
->GetEntry() == item
)
8494 tempcount
+= pItem
->GetCount();
8495 if( tempcount
>= count
)
8499 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
8501 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
8503 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8505 Item
* pItem
= GetItemByPos( i
, j
);
8506 if( pItem
&& pItem
->GetEntry() == item
)
8508 tempcount
+= pItem
->GetCount();
8509 if( tempcount
>= count
)
8518 for(int i
= BANK_SLOT_ITEM_START
; i
< BANK_SLOT_ITEM_END
; i
++)
8520 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8521 if( pItem
&& pItem
->GetEntry() == item
)
8523 tempcount
+= pItem
->GetCount();
8524 if( tempcount
>= count
)
8528 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
8530 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
8532 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8534 Item
* pItem
= GetItemByPos( i
, j
);
8535 if( pItem
&& pItem
->GetEntry() == item
)
8537 tempcount
+= pItem
->GetCount();
8538 if( tempcount
>= count
)
8549 Item
* Player::GetItemOrItemWithGemEquipped( uint32 item
) const
8552 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
8554 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8555 if( pItem
&& pItem
->GetEntry() == item
)
8559 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(item
);
8560 if (pProto
&& pProto
->GemProperties
)
8562 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; i
++)
8564 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8565 if( pItem
&& pItem
->GetProto()->Socket
[0].Color
)
8567 if (pItem
->GetGemCountWithID(item
) > 0 )
8576 uint8
Player::_CanTakeMoreSimilarItems(uint32 entry
, uint32 count
, Item
* pItem
, uint32
* no_space_count
) const
8578 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(entry
);
8582 *no_space_count
= count
;
8583 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
8587 if(pProto
->MaxCount
== 0)
8588 return EQUIP_ERR_OK
;
8590 uint32 curcount
= GetItemCount(pProto
->ItemId
,true,pItem
);
8592 if( curcount
+ count
> pProto
->MaxCount
)
8595 *no_space_count
= count
+curcount
- pProto
->MaxCount
;
8596 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
8599 return EQUIP_ERR_OK
;
8602 bool Player::HasItemTotemCategory( uint32 TotemCategory
) const
8605 for(uint8 i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_ITEM_END
; ++i
)
8607 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8608 if( pItem
&& IsTotemCategoryCompatiableWith(pItem
->GetProto()->TotemCategory
,TotemCategory
))
8611 for(uint8 i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; ++i
)
8613 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
8614 if( pItem
&& IsTotemCategoryCompatiableWith(pItem
->GetProto()->TotemCategory
,TotemCategory
))
8617 for(uint8 i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; ++i
)
8619 if(Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
8621 for(uint32 j
= 0; j
< pBag
->GetBagSize(); ++j
)
8623 pItem
= GetItemByPos( i
, j
);
8624 if( pItem
&& IsTotemCategoryCompatiableWith(pItem
->GetProto()->TotemCategory
,TotemCategory
))
8632 uint8
Player::_CanStoreItem_InSpecificSlot( uint8 bag
, uint8 slot
, ItemPosCountVec
&dest
, ItemPrototype
const *pProto
, uint32
& count
, bool swap
, Item
* pSrcItem
) const
8634 Item
* pItem2
= GetItemByPos( bag
, slot
);
8636 // ignore move item (this slot will be empty at move)
8637 if(pItem2
==pSrcItem
)
8642 // empty specific slot - check item fit to slot
8643 if( !pItem2
|| swap
)
8645 if( bag
== INVENTORY_SLOT_BAG_0
)
8648 if(slot
>= KEYRING_SLOT_START
&& slot
< KEYRING_SLOT_START
+GetMaxKeyringSize() && !(pProto
->BagFamily
& BAG_FAMILY_MASK_KEYS
))
8649 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8652 if(slot
>= VANITYPET_SLOT_START
&& slot
< VANITYPET_SLOT_END
&& !(pProto
->BagFamily
& BAG_FAMILY_MASK_VANITY_PETS
))
8653 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8655 // currencytoken case
8656 if(slot
>= CURRENCYTOKEN_SLOT_START
&& slot
< CURRENCYTOKEN_SLOT_END
&& !(pProto
->BagFamily
& BAG_FAMILY_MASK_CURRENCY_TOKENS
))
8657 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8660 if(slot
>= QUESTBAG_SLOT_START
&& slot
< QUESTBAG_SLOT_END
&& !(pProto
->BagFamily
& BAG_FAMILY_MASK_QUEST_ITEMS
))
8661 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8664 if(slot
>= BUYBACK_SLOT_START
&& slot
< BUYBACK_SLOT_END
|| slot
>= PLAYER_SLOT_END
)
8665 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8669 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
8671 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8673 ItemPrototype
const* pBagProto
= pBag
->GetProto();
8675 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8677 if( !ItemCanGoIntoBag(pProto
,pBagProto
) )
8678 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8681 // non empty stack with space
8682 need_space
= pProto
->Stackable
;
8684 // non empty slot, check item type
8688 if(pItem2
->GetEntry() != pProto
->ItemId
)
8689 return EQUIP_ERR_ITEM_CANT_STACK
;
8692 if(pItem2
->GetCount() >= pProto
->Stackable
)
8693 return EQUIP_ERR_ITEM_CANT_STACK
;
8695 need_space
= pProto
->Stackable
- pItem2
->GetCount();
8698 if(need_space
> count
)
8701 ItemPosCount newPosition
= ItemPosCount((bag
<< 8) | slot
, need_space
);
8702 if(!newPosition
.isContainedIn(dest
))
8704 dest
.push_back(newPosition
);
8705 count
-= need_space
;
8707 return EQUIP_ERR_OK
;
8710 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
8712 // skip specific bag already processed in first called _CanStoreItem_InBag
8714 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8716 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
8718 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8720 ItemPrototype
const* pBagProto
= pBag
->GetProto();
8722 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8724 // specialized bag mode or non-specilized
8725 if( non_specialized
!= (pBagProto
->Class
== ITEM_CLASS_CONTAINER
&& pBagProto
->SubClass
== ITEM_SUBCLASS_CONTAINER
) )
8726 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8728 if( !ItemCanGoIntoBag(pProto
,pBagProto
) )
8729 return EQUIP_ERR_ITEM_DOESNT_GO_INTO_BAG
;
8731 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
8733 // skip specific slot already processed in first called _CanStoreItem_InSpecificSlot
8737 Item
* pItem2
= GetItemByPos( bag
, j
);
8739 // ignore move item (this slot will be empty at move)
8740 if(pItem2
==pSrcItem
)
8743 // if merge skip empty, if !merge skip non-empty
8744 if((pItem2
!=NULL
)!=merge
)
8749 if(pItem2
->GetEntry() == pProto
->ItemId
&& pItem2
->GetCount() < pProto
->Stackable
)
8751 uint32 need_space
= pProto
->Stackable
- pItem2
->GetCount();
8752 if(need_space
> count
)
8755 ItemPosCount newPosition
= ItemPosCount((bag
<< 8) | j
, need_space
);
8756 if(!newPosition
.isContainedIn(dest
))
8758 dest
.push_back(newPosition
);
8759 count
-= need_space
;
8762 return EQUIP_ERR_OK
;
8768 uint32 need_space
= pProto
->Stackable
;
8769 if(need_space
> count
)
8772 ItemPosCount newPosition
= ItemPosCount((bag
<< 8) | j
, need_space
);
8773 if(!newPosition
.isContainedIn(dest
))
8775 dest
.push_back(newPosition
);
8776 count
-= need_space
;
8779 return EQUIP_ERR_OK
;
8783 return EQUIP_ERR_OK
;
8786 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
8788 for(uint32 j
= slot_begin
; j
< slot_end
; j
++)
8790 // skip specific slot already processed in first called _CanStoreItem_InSpecificSlot
8791 if(INVENTORY_SLOT_BAG_0
==skip_bag
&& j
==skip_slot
)
8794 Item
* pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, j
);
8796 // ignore move item (this slot will be empty at move)
8797 if(pItem2
==pSrcItem
)
8800 // if merge skip empty, if !merge skip non-empty
8801 if((pItem2
!=NULL
)!=merge
)
8806 if(pItem2
->GetEntry() == pProto
->ItemId
&& pItem2
->GetCount() < pProto
->Stackable
)
8808 uint32 need_space
= pProto
->Stackable
- pItem2
->GetCount();
8809 if(need_space
> count
)
8811 ItemPosCount newPosition
= ItemPosCount((INVENTORY_SLOT_BAG_0
<< 8) | j
, need_space
);
8812 if(!newPosition
.isContainedIn(dest
))
8814 dest
.push_back(newPosition
);
8815 count
-= need_space
;
8818 return EQUIP_ERR_OK
;
8824 uint32 need_space
= pProto
->Stackable
;
8825 if(need_space
> count
)
8828 ItemPosCount newPosition
= ItemPosCount((INVENTORY_SLOT_BAG_0
<< 8) | j
, need_space
);
8829 if(!newPosition
.isContainedIn(dest
))
8831 dest
.push_back(newPosition
);
8832 count
-= need_space
;
8835 return EQUIP_ERR_OK
;
8839 return EQUIP_ERR_OK
;
8842 uint8
Player::_CanStoreItem( uint8 bag
, uint8 slot
, ItemPosCountVec
&dest
, uint32 entry
, uint32 count
, Item
*pItem
, bool swap
, uint32
* no_space_count
) const
8844 sLog
.outDebug( "STORAGE: CanStoreItem bag = %u, slot = %u, item = %u, count = %u", bag
, slot
, entry
, count
);
8846 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(entry
);
8850 *no_space_count
= count
;
8851 return swap
? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
:EQUIP_ERR_ITEM_NOT_FOUND
;
8854 if(pItem
&& pItem
->IsBindedNotWith(GetGUID()))
8857 *no_space_count
= count
;
8858 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
8861 // check count of items (skip for auto move for same player from bank)
8862 uint32 no_similar_count
= 0; // can't store this amount similar items
8863 uint8 res
= _CanTakeMoreSimilarItems(entry
,count
,pItem
,&no_similar_count
);
8864 if(res
!=EQUIP_ERR_OK
)
8866 if(count
==no_similar_count
)
8869 *no_space_count
= no_similar_count
;
8872 count
-= no_similar_count
;
8876 if( bag
!= NULL_BAG
&& slot
!= NULL_SLOT
)
8878 res
= _CanStoreItem_InSpecificSlot(bag
,slot
,dest
,pProto
,count
,swap
,pItem
);
8879 if(res
!=EQUIP_ERR_OK
)
8882 *no_space_count
= count
+ no_similar_count
;
8888 if(no_similar_count
==0)
8889 return EQUIP_ERR_OK
;
8892 *no_space_count
= count
+ no_similar_count
;
8893 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
8897 // not specific slot or have space for partly store only in specific slot
8900 if( bag
!= NULL_BAG
)
8902 // search stack in bag for merge to
8903 if( pProto
->Stackable
> 1 )
8905 if( bag
== INVENTORY_SLOT_BAG_0
) // inventory
8907 res
= _CanStoreItem_InInventorySlots(KEYRING_SLOT_START
,QUESTBAG_SLOT_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
8908 if(res
!=EQUIP_ERR_OK
)
8911 *no_space_count
= count
+ no_similar_count
;
8917 if(no_similar_count
==0)
8918 return EQUIP_ERR_OK
;
8921 *no_space_count
= count
+ no_similar_count
;
8922 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
8925 res
= _CanStoreItem_InInventorySlots(INVENTORY_SLOT_ITEM_START
,INVENTORY_SLOT_ITEM_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
8926 if(res
!=EQUIP_ERR_OK
)
8929 *no_space_count
= count
+ no_similar_count
;
8935 if(no_similar_count
==0)
8936 return EQUIP_ERR_OK
;
8939 *no_space_count
= count
+ no_similar_count
;
8940 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
8943 else // equipped bag
8945 // we need check 2 time (specialized/non_specialized), use NULL_BAG to prevent skipping bag
8946 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,true,false,pItem
,NULL_BAG
,slot
);
8947 if(res
!=EQUIP_ERR_OK
)
8948 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,true,true,pItem
,NULL_BAG
,slot
);
8950 if(res
!=EQUIP_ERR_OK
)
8953 *no_space_count
= count
+ no_similar_count
;
8959 if(no_similar_count
==0)
8960 return EQUIP_ERR_OK
;
8963 *no_space_count
= count
+ no_similar_count
;
8964 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
8969 // search free slot in bag for place to
8970 if( bag
== INVENTORY_SLOT_BAG_0
) // inventory
8972 // search free slot - keyring case
8973 if(pProto
->BagFamily
& BAG_FAMILY_MASK_KEYS
)
8975 uint32 keyringSize
= GetMaxKeyringSize();
8976 res
= _CanStoreItem_InInventorySlots(KEYRING_SLOT_START
,KEYRING_SLOT_START
+keyringSize
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
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
;
8994 else if(pProto
->BagFamily
& BAG_FAMILY_MASK_VANITY_PETS
)
8996 res
= _CanStoreItem_InInventorySlots(VANITYPET_SLOT_START
,VANITYPET_SLOT_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
8997 if(res
!=EQUIP_ERR_OK
)
9000 *no_space_count
= count
+ no_similar_count
;
9006 if(no_similar_count
==0)
9007 return EQUIP_ERR_OK
;
9010 *no_space_count
= count
+ no_similar_count
;
9011 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9014 else if(pProto
->BagFamily
& BAG_FAMILY_MASK_CURRENCY_TOKENS
)
9016 res
= _CanStoreItem_InInventorySlots(CURRENCYTOKEN_SLOT_START
,CURRENCYTOKEN_SLOT_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9017 if(res
!=EQUIP_ERR_OK
)
9020 *no_space_count
= count
+ no_similar_count
;
9026 if(no_similar_count
==0)
9027 return EQUIP_ERR_OK
;
9030 *no_space_count
= count
+ no_similar_count
;
9031 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9034 else if(pProto
->BagFamily
& BAG_FAMILY_MASK_QUEST_ITEMS
)
9036 res
= _CanStoreItem_InInventorySlots(QUESTBAG_SLOT_START
,QUESTBAG_SLOT_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9037 if(res
!=EQUIP_ERR_OK
)
9040 *no_space_count
= count
+ no_similar_count
;
9046 if(no_similar_count
==0)
9047 return EQUIP_ERR_OK
;
9050 *no_space_count
= count
+ no_similar_count
;
9051 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9055 res
= _CanStoreItem_InInventorySlots(INVENTORY_SLOT_ITEM_START
,INVENTORY_SLOT_ITEM_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9056 if(res
!=EQUIP_ERR_OK
)
9059 *no_space_count
= count
+ no_similar_count
;
9065 if(no_similar_count
==0)
9066 return EQUIP_ERR_OK
;
9069 *no_space_count
= count
+ no_similar_count
;
9070 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9073 else // equipped bag
9075 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,false,false,pItem
,NULL_BAG
,slot
);
9076 if(res
!=EQUIP_ERR_OK
)
9077 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,false,true,pItem
,NULL_BAG
,slot
);
9079 if(res
!=EQUIP_ERR_OK
)
9082 *no_space_count
= count
+ no_similar_count
;
9088 if(no_similar_count
==0)
9089 return EQUIP_ERR_OK
;
9092 *no_space_count
= count
+ no_similar_count
;
9093 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9098 // not specific bag or have space for partly store only in specific bag
9100 // search stack for merge to
9101 if( pProto
->Stackable
> 1 )
9103 res
= _CanStoreItem_InInventorySlots(KEYRING_SLOT_START
,QUESTBAG_SLOT_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
9104 if(res
!=EQUIP_ERR_OK
)
9107 *no_space_count
= count
+ no_similar_count
;
9113 if(no_similar_count
==0)
9114 return EQUIP_ERR_OK
;
9117 *no_space_count
= count
+ no_similar_count
;
9118 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9121 res
= _CanStoreItem_InInventorySlots(INVENTORY_SLOT_ITEM_START
,INVENTORY_SLOT_ITEM_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
9122 if(res
!=EQUIP_ERR_OK
)
9125 *no_space_count
= count
+ no_similar_count
;
9131 if(no_similar_count
==0)
9132 return EQUIP_ERR_OK
;
9135 *no_space_count
= count
+ no_similar_count
;
9136 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9139 if( pProto
->BagFamily
)
9141 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9143 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,true,false,pItem
,bag
,slot
);
9144 if(res
!=EQUIP_ERR_OK
)
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 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9161 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,true,true,pItem
,bag
,slot
);
9162 if(res
!=EQUIP_ERR_OK
)
9167 if(no_similar_count
==0)
9168 return EQUIP_ERR_OK
;
9171 *no_space_count
= count
+ no_similar_count
;
9172 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9177 // search free slot - special bag case
9178 if( pProto
->BagFamily
)
9180 if(pProto
->BagFamily
& BAG_FAMILY_MASK_KEYS
)
9182 uint32 keyringSize
= GetMaxKeyringSize();
9183 res
= _CanStoreItem_InInventorySlots(KEYRING_SLOT_START
,KEYRING_SLOT_START
+keyringSize
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9184 if(res
!=EQUIP_ERR_OK
)
9187 *no_space_count
= count
+ no_similar_count
;
9193 if(no_similar_count
==0)
9194 return EQUIP_ERR_OK
;
9197 *no_space_count
= count
+ no_similar_count
;
9198 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9201 else if(pProto
->BagFamily
& BAG_FAMILY_MASK_VANITY_PETS
)
9203 res
= _CanStoreItem_InInventorySlots(VANITYPET_SLOT_START
,VANITYPET_SLOT_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9204 if(res
!=EQUIP_ERR_OK
)
9207 *no_space_count
= count
+ no_similar_count
;
9213 if(no_similar_count
==0)
9214 return EQUIP_ERR_OK
;
9217 *no_space_count
= count
+ no_similar_count
;
9218 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9221 else if(pProto
->BagFamily
& BAG_FAMILY_MASK_CURRENCY_TOKENS
)
9223 res
= _CanStoreItem_InInventorySlots(CURRENCYTOKEN_SLOT_START
,CURRENCYTOKEN_SLOT_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9224 if(res
!=EQUIP_ERR_OK
)
9227 *no_space_count
= count
+ no_similar_count
;
9233 if(no_similar_count
==0)
9234 return EQUIP_ERR_OK
;
9237 *no_space_count
= count
+ no_similar_count
;
9238 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9241 else if(pProto
->BagFamily
& BAG_FAMILY_MASK_QUEST_ITEMS
)
9243 res
= _CanStoreItem_InInventorySlots(QUESTBAG_SLOT_START
,QUESTBAG_SLOT_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9244 if(res
!=EQUIP_ERR_OK
)
9247 *no_space_count
= count
+ no_similar_count
;
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
;
9262 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9264 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,false,false,pItem
,bag
,slot
);
9265 if(res
!=EQUIP_ERR_OK
)
9270 if(no_similar_count
==0)
9271 return EQUIP_ERR_OK
;
9274 *no_space_count
= count
+ no_similar_count
;
9275 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9281 res
= _CanStoreItem_InInventorySlots(INVENTORY_SLOT_ITEM_START
,INVENTORY_SLOT_ITEM_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9282 if(res
!=EQUIP_ERR_OK
)
9285 *no_space_count
= count
+ no_similar_count
;
9291 if(no_similar_count
==0)
9292 return EQUIP_ERR_OK
;
9295 *no_space_count
= count
+ no_similar_count
;
9296 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9299 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9301 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,false,true,pItem
,bag
,slot
);
9302 if(res
!=EQUIP_ERR_OK
)
9307 if(no_similar_count
==0)
9308 return EQUIP_ERR_OK
;
9311 *no_space_count
= count
+ no_similar_count
;
9312 return EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
;
9317 *no_space_count
= count
+ no_similar_count
;
9319 return EQUIP_ERR_INVENTORY_FULL
;
9322 //////////////////////////////////////////////////////////////////////////
9323 uint8
Player::CanStoreItems( Item
**pItems
,int count
) const
9328 int inv_slot_items
[INVENTORY_SLOT_ITEM_END
-INVENTORY_SLOT_ITEM_START
];
9329 int inv_bags
[INVENTORY_SLOT_BAG_END
-INVENTORY_SLOT_BAG_START
][MAX_BAG_SIZE
];
9330 int inv_keys
[KEYRING_SLOT_END
-KEYRING_SLOT_START
];
9331 int inv_pets
[VANITYPET_SLOT_END
-VANITYPET_SLOT_START
];
9332 int inv_tokens
[CURRENCYTOKEN_SLOT_END
-CURRENCYTOKEN_SLOT_START
];
9333 int inv_quests
[QUESTBAG_SLOT_END
-QUESTBAG_SLOT_START
];
9335 memset(inv_slot_items
,0,sizeof(int)*(INVENTORY_SLOT_ITEM_END
-INVENTORY_SLOT_ITEM_START
));
9336 memset(inv_bags
,0,sizeof(int)*(INVENTORY_SLOT_BAG_END
-INVENTORY_SLOT_BAG_START
)*MAX_BAG_SIZE
);
9337 memset(inv_keys
,0,sizeof(int)*(KEYRING_SLOT_END
-KEYRING_SLOT_START
));
9338 memset(inv_pets
,0,sizeof(int)*(VANITYPET_SLOT_END
-VANITYPET_SLOT_START
));
9339 memset(inv_tokens
,0,sizeof(int)*(CURRENCYTOKEN_SLOT_END
-CURRENCYTOKEN_SLOT_START
));
9340 memset(inv_quests
,0,sizeof(int)*(QUESTBAG_SLOT_END
-QUESTBAG_SLOT_START
));
9342 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
9344 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9346 if (pItem2
&& !pItem2
->IsInTrade())
9348 inv_slot_items
[i
-INVENTORY_SLOT_ITEM_START
] = pItem2
->GetCount();
9352 for(int i
= KEYRING_SLOT_START
; i
< KEYRING_SLOT_END
; i
++)
9354 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9356 if (pItem2
&& !pItem2
->IsInTrade())
9358 inv_keys
[i
-KEYRING_SLOT_START
] = pItem2
->GetCount();
9362 for(int i
= VANITYPET_SLOT_START
; i
< VANITYPET_SLOT_END
; i
++)
9364 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9366 if (pItem2
&& !pItem2
->IsInTrade())
9368 inv_pets
[i
-VANITYPET_SLOT_START
] = pItem2
->GetCount();
9372 for(int i
= CURRENCYTOKEN_SLOT_START
; i
< CURRENCYTOKEN_SLOT_END
; i
++)
9374 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9376 if (pItem2
&& !pItem2
->IsInTrade())
9378 inv_tokens
[i
-CURRENCYTOKEN_SLOT_START
] = pItem2
->GetCount();
9382 for(int i
= QUESTBAG_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
9384 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
9386 if (pItem2
&& !pItem2
->IsInTrade())
9388 inv_quests
[i
-QUESTBAG_SLOT_START
] = pItem2
->GetCount();
9392 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
9394 if(Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
9396 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
9398 pItem2
= GetItemByPos( i
, j
);
9399 if (pItem2
&& !pItem2
->IsInTrade())
9401 inv_bags
[i
-INVENTORY_SLOT_BAG_START
][j
] = pItem2
->GetCount();
9407 // check free space for all items
9408 for (int k
=0;k
<count
;k
++)
9410 Item
*pItem
= pItems
[k
];
9413 if (!pItem
) continue;
9415 sLog
.outDebug( "STORAGE: CanStoreItems %i. item = %u, count = %u", k
+1, pItem
->GetEntry(), pItem
->GetCount());
9416 ItemPrototype
const *pProto
= pItem
->GetProto();
9420 return EQUIP_ERR_ITEM_NOT_FOUND
;
9423 if(pItem
->IsBindedNotWith(GetGUID()))
9424 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
9427 ItemPrototype
const *pBagProto
;
9429 // item is 'one item only'
9430 uint8 res
= CanTakeMoreSimilarItems(pItem
);
9431 if(res
!= EQUIP_ERR_OK
)
9434 // search stack for merge to
9435 if( pProto
->Stackable
> 1 )
9437 bool b_found
= false;
9439 for(int t
= KEYRING_SLOT_START
; t
< KEYRING_SLOT_END
; t
++)
9441 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9442 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_keys
[t
-KEYRING_SLOT_START
] + pItem
->GetCount() <= pProto
->Stackable
)
9444 inv_keys
[t
-KEYRING_SLOT_START
] += pItem
->GetCount();
9449 if (b_found
) continue;
9451 for(int t
= VANITYPET_SLOT_START
; t
< VANITYPET_SLOT_END
; t
++)
9453 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9454 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_pets
[t
-VANITYPET_SLOT_START
] + pItem
->GetCount() <= pProto
->Stackable
)
9456 inv_pets
[t
-VANITYPET_SLOT_START
] += pItem
->GetCount();
9461 if (b_found
) continue;
9463 for(int t
= CURRENCYTOKEN_SLOT_START
; t
< CURRENCYTOKEN_SLOT_END
; t
++)
9465 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9466 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_tokens
[t
-CURRENCYTOKEN_SLOT_START
] + pItem
->GetCount() <= pProto
->Stackable
)
9468 inv_tokens
[t
-CURRENCYTOKEN_SLOT_START
] += pItem
->GetCount();
9473 if (b_found
) continue;
9475 for(int t
= QUESTBAG_SLOT_START
; t
< QUESTBAG_SLOT_END
; t
++)
9477 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9478 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_quests
[t
-QUESTBAG_SLOT_START
] + pItem
->GetCount() <= pProto
->Stackable
)
9480 inv_quests
[t
-QUESTBAG_SLOT_START
] += pItem
->GetCount();
9485 if (b_found
) continue;
9487 for(int t
= INVENTORY_SLOT_ITEM_START
; t
< INVENTORY_SLOT_ITEM_END
; t
++)
9489 pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9490 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_slot_items
[t
-INVENTORY_SLOT_ITEM_START
] + pItem
->GetCount() <= pProto
->Stackable
)
9492 inv_slot_items
[t
-INVENTORY_SLOT_ITEM_START
] += pItem
->GetCount();
9497 if (b_found
) continue;
9499 for(int t
= INVENTORY_SLOT_BAG_START
; !b_found
&& t
< INVENTORY_SLOT_BAG_END
; t
++)
9501 pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9504 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
9506 pItem2
= GetItemByPos( t
, j
);
9507 if( pItem2
&& pItem2
->GetEntry() == pItem
->GetEntry() && inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] + pItem
->GetCount() <= pProto
->Stackable
)
9509 inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] += pItem
->GetCount();
9516 if (b_found
) continue;
9520 if( pProto
->BagFamily
)
9522 bool b_found
= false;
9523 if(pProto
->BagFamily
& BAG_FAMILY_MASK_KEYS
)
9525 uint32 keyringSize
= GetMaxKeyringSize();
9526 for(uint32 t
= KEYRING_SLOT_START
; t
< KEYRING_SLOT_START
+keyringSize
; ++t
)
9528 if( inv_keys
[t
-KEYRING_SLOT_START
] == 0 )
9530 inv_keys
[t
-KEYRING_SLOT_START
] = 1;
9537 if (b_found
) continue;
9539 if(pProto
->BagFamily
& BAG_FAMILY_MASK_VANITY_PETS
)
9541 for(uint32 t
= VANITYPET_SLOT_START
; t
< VANITYPET_SLOT_END
; ++t
)
9543 if( inv_pets
[t
-VANITYPET_SLOT_START
] == 0 )
9545 inv_pets
[t
-VANITYPET_SLOT_START
] = 1;
9552 if (b_found
) continue;
9554 if(pProto
->BagFamily
& BAG_FAMILY_MASK_CURRENCY_TOKENS
)
9556 for(uint32 t
= CURRENCYTOKEN_SLOT_START
; t
< CURRENCYTOKEN_SLOT_END
; ++t
)
9558 if( inv_tokens
[t
-CURRENCYTOKEN_SLOT_START
] == 0 )
9560 inv_tokens
[t
-CURRENCYTOKEN_SLOT_START
] = 1;
9567 if (b_found
) continue;
9569 if(pProto
->BagFamily
& BAG_FAMILY_MASK_QUEST_ITEMS
)
9571 for(uint32 t
= QUESTBAG_SLOT_START
; t
< QUESTBAG_SLOT_END
; ++t
)
9573 if( inv_quests
[t
-QUESTBAG_SLOT_START
] == 0 )
9575 inv_quests
[t
-QUESTBAG_SLOT_START
] = 1;
9582 if (b_found
) continue;
9584 for(int t
= INVENTORY_SLOT_BAG_START
; !b_found
&& t
< INVENTORY_SLOT_BAG_END
; t
++)
9586 pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9589 pBagProto
= pBag
->GetProto();
9591 // not plain container check
9592 if( pBagProto
&& (pBagProto
->Class
!= ITEM_CLASS_CONTAINER
|| pBagProto
->SubClass
!= ITEM_SUBCLASS_CONTAINER
) &&
9593 ItemCanGoIntoBag(pProto
,pBagProto
) )
9595 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
9597 if( inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] == 0 )
9599 inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] = 1;
9607 if (b_found
) continue;
9611 bool b_found
= false;
9612 for(int t
= INVENTORY_SLOT_ITEM_START
; t
< INVENTORY_SLOT_ITEM_END
; t
++)
9614 if( inv_slot_items
[t
-INVENTORY_SLOT_ITEM_START
] == 0 )
9616 inv_slot_items
[t
-INVENTORY_SLOT_ITEM_START
] = 1;
9621 if (b_found
) continue;
9623 // search free slot in bags
9624 for(int t
= INVENTORY_SLOT_BAG_START
; !b_found
&& t
< INVENTORY_SLOT_BAG_END
; t
++)
9626 pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, t
);
9629 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
9631 if( inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] == 0 )
9633 inv_bags
[t
-INVENTORY_SLOT_BAG_START
][j
] = 1;
9641 // no free slot found?
9643 return EQUIP_ERR_INVENTORY_FULL
;
9646 return EQUIP_ERR_OK
;
9649 //////////////////////////////////////////////////////////////////////////
9650 uint8
Player::CanEquipNewItem( uint8 slot
, uint16
&dest
, uint32 item
, uint32 count
, bool swap
) const
9653 Item
*pItem
= Item::CreateItem( item
, count
, this );
9656 uint8 result
= CanEquipItem(slot
, dest
, pItem
, swap
);
9661 return EQUIP_ERR_ITEM_NOT_FOUND
;
9664 uint8
Player::CanEquipItem( uint8 slot
, uint16
&dest
, Item
*pItem
, bool swap
, bool not_loading
) const
9669 sLog
.outDebug( "STORAGE: CanEquipItem slot = %u, item = %u, count = %u", slot
, pItem
->GetEntry(), pItem
->GetCount());
9670 ItemPrototype
const *pProto
= pItem
->GetProto();
9673 // May be here should be more stronger checks; STUNNED checked
9674 // ROOT, CONFUSED, DISTRACTED, FLEEING this needs to be checked.
9675 if (not_loading
&& hasUnitState(UNIT_STAT_STUNNED
))
9676 return EQUIP_ERR_YOU_ARE_STUNNED
;
9678 if(pItem
->IsBindedNotWith(GetGUID()))
9679 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
9681 // check count of items (skip for auto move for same player from bank)
9682 uint8 res
= CanTakeMoreSimilarItems(pItem
);
9683 if(res
!= EQUIP_ERR_OK
)
9686 // do not allow equipping gear except weapons, offhands, projectiles, relics in
9688 // - in-progress arenas
9689 if( !pProto
->CanChangeEquipStateInCombat() )
9692 return EQUIP_ERR_NOT_IN_COMBAT
;
9694 if(BattleGround
* bg
= GetBattleGround())
9695 if( bg
->isArena() && bg
->GetStatus() == STATUS_IN_PROGRESS
)
9696 return EQUIP_ERR_NOT_DURING_ARENA_MATCH
;
9699 if(isInCombat()&& pProto
->Class
== ITEM_CLASS_WEAPON
&& m_weaponChangeTimer
!= 0)
9700 return EQUIP_ERR_CANT_DO_RIGHT_NOW
; // maybe exist better err
9702 if(IsNonMeleeSpellCasted(false))
9703 return EQUIP_ERR_CANT_DO_RIGHT_NOW
;
9705 uint8 eslot
= FindEquipSlot( pProto
, slot
, swap
);
9706 if( eslot
== NULL_SLOT
)
9707 return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED
;
9709 uint8 msg
= CanUseItem( pItem
, not_loading
);
9710 if( msg
!= EQUIP_ERR_OK
)
9712 if( !swap
&& GetItemByPos( INVENTORY_SLOT_BAG_0
, eslot
) )
9713 return EQUIP_ERR_NO_EQUIPMENT_SLOT_AVAILABLE
;
9715 // check unique-equipped on item
9716 if (pProto
->Flags
& ITEM_FLAGS_UNIQUE_EQUIPPED
)
9718 // there is an equip limit on this item
9719 Item
* tItem
= GetItemOrItemWithGemEquipped(pProto
->ItemId
);
9720 if (tItem
&& (!swap
|| tItem
->GetSlot() != eslot
) )
9721 return EQUIP_ERR_ITEM_UNIQUE_EQUIPABLE
;
9724 // check unique-equipped on gems
9725 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
9727 uint32 enchant_id
= pItem
->GetEnchantmentId(EnchantmentSlot(enchant_slot
));
9730 SpellItemEnchantmentEntry
const* enchantEntry
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
9734 ItemPrototype
const* pGem
= objmgr
.GetItemPrototype(enchantEntry
->GemID
);
9735 if(pGem
&& (pGem
->Flags
& ITEM_FLAGS_UNIQUE_EQUIPPED
))
9737 Item
* tItem
= GetItemOrItemWithGemEquipped(enchantEntry
->GemID
);
9738 if(tItem
&& (!swap
|| tItem
->GetSlot() != eslot
))
9739 return EQUIP_ERR_ITEM_UNIQUE_EQUIPABLE
;
9743 // check unique-equipped special item classes
9744 if (pProto
->Class
== ITEM_CLASS_QUIVER
)
9746 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; ++i
)
9748 if( Item
* pBag
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
) )
9750 if( ItemPrototype
const* pBagProto
= pBag
->GetProto() )
9752 if( pBagProto
->Class
==pProto
->Class
&& pBagProto
->SubClass
==pProto
->SubClass
&&
9753 (!swap
|| pBag
->GetSlot() != eslot
) )
9755 if(pBagProto
->SubClass
== ITEM_SUBCLASS_AMMO_POUCH
)
9756 return EQUIP_ERR_CAN_EQUIP_ONLY1_AMMOPOUCH
;
9758 return EQUIP_ERR_CAN_EQUIP_ONLY1_QUIVER
;
9765 uint32 type
= pProto
->InventoryType
;
9767 if(eslot
== EQUIPMENT_SLOT_OFFHAND
)
9769 if( type
== INVTYPE_WEAPON
|| type
== INVTYPE_WEAPONOFFHAND
)
9772 return EQUIP_ERR_CANT_DUAL_WIELD
;
9775 Item
*mainItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
9778 if(mainItem
->GetProto()->InventoryType
== INVTYPE_2HWEAPON
)
9779 return EQUIP_ERR_CANT_EQUIP_WITH_TWOHANDED
;
9783 // equip two-hand weapon case (with possible unequip 2 items)
9784 if( type
== INVTYPE_2HWEAPON
)
9786 if(eslot
!= EQUIPMENT_SLOT_MAINHAND
)
9787 return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED
;
9789 // offhand item must can be stored in inventory for offhand item and it also must be unequipped
9790 Item
*offItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
9791 ItemPosCountVec off_dest
;
9792 if( offItem
&& (!not_loading
||
9793 CanUnequipItem(uint16(INVENTORY_SLOT_BAG_0
) << 8 | EQUIPMENT_SLOT_OFFHAND
,false) != EQUIP_ERR_OK
||
9794 CanStoreItem( NULL_BAG
, NULL_SLOT
, off_dest
, offItem
, false ) != EQUIP_ERR_OK
) )
9795 return swap
? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
: EQUIP_ERR_INVENTORY_FULL
;
9797 dest
= ((INVENTORY_SLOT_BAG_0
<< 8) | eslot
);
9798 return EQUIP_ERR_OK
;
9802 return EQUIP_ERR_ITEM_NOT_FOUND
;
9804 return EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
;
9807 uint8
Player::CanUnequipItem( uint16 pos
, bool swap
) const
9809 // Applied only to equipped items and bank bags
9810 if(!IsEquipmentPos(pos
) && !IsBagPos(pos
))
9811 return EQUIP_ERR_OK
;
9813 Item
* pItem
= GetItemByPos(pos
);
9815 // Applied only to existed equipped item
9817 return EQUIP_ERR_OK
;
9819 sLog
.outDebug( "STORAGE: CanUnequipItem slot = %u, item = %u, count = %u", pos
, pItem
->GetEntry(), pItem
->GetCount());
9821 ItemPrototype
const *pProto
= pItem
->GetProto();
9823 return EQUIP_ERR_ITEM_NOT_FOUND
;
9825 // do not allow unequipping gear except weapons, offhands, projectiles, relics in
9827 // - in-progress arenas
9828 if( !pProto
->CanChangeEquipStateInCombat() )
9831 return EQUIP_ERR_NOT_IN_COMBAT
;
9833 if(BattleGround
* bg
= GetBattleGround())
9834 if( bg
->isArena() && bg
->GetStatus() == STATUS_IN_PROGRESS
)
9835 return EQUIP_ERR_NOT_DURING_ARENA_MATCH
;
9838 if(!swap
&& pItem
->IsBag() && !((Bag
*)pItem
)->IsEmpty())
9839 return EQUIP_ERR_CAN_ONLY_DO_WITH_EMPTY_BAGS
;
9841 return EQUIP_ERR_OK
;
9844 uint8
Player::CanBankItem( uint8 bag
, uint8 slot
, ItemPosCountVec
&dest
, Item
*pItem
, bool swap
, bool not_loading
) const
9847 return swap
? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
: EQUIP_ERR_ITEM_NOT_FOUND
;
9849 uint32 count
= pItem
->GetCount();
9851 sLog
.outDebug( "STORAGE: CanBankItem bag = %u, slot = %u, item = %u, count = %u", bag
, slot
, pItem
->GetEntry(), pItem
->GetCount());
9852 ItemPrototype
const *pProto
= pItem
->GetProto();
9854 return swap
? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED
: EQUIP_ERR_ITEM_NOT_FOUND
;
9856 if( pItem
->IsBindedNotWith(GetGUID()) )
9857 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
9859 // check count of items (skip for auto move for same player from bank)
9860 uint8 res
= CanTakeMoreSimilarItems(pItem
);
9861 if(res
!= EQUIP_ERR_OK
)
9865 if( bag
!= NULL_BAG
&& slot
!= NULL_SLOT
)
9867 if( pProto
->InventoryType
== INVTYPE_BAG
)
9869 Bag
*pBag
= (Bag
*)pItem
;
9872 if( slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
)
9874 if( !HasBankBagSlot( slot
) )
9875 return EQUIP_ERR_MUST_PURCHASE_THAT_BAG_SLOT
;
9876 if( uint8 cantuse
= CanUseItem( pItem
, not_loading
) != EQUIP_ERR_OK
)
9881 if( !pBag
->IsEmpty() )
9882 return EQUIP_ERR_NONEMPTY_BAG_OVER_OTHER_BAG
;
9888 if( slot
>= BANK_SLOT_BAG_START
&& slot
< BANK_SLOT_BAG_END
)
9889 return EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT
;
9892 res
= _CanStoreItem_InSpecificSlot(bag
,slot
,dest
,pProto
,count
,swap
,pItem
);
9893 if(res
!=EQUIP_ERR_OK
)
9897 return EQUIP_ERR_OK
;
9900 // not specific slot or have space for partly store only in specific slot
9903 if( bag
!= NULL_BAG
)
9905 if( pProto
->InventoryType
== INVTYPE_BAG
)
9907 Bag
*pBag
= (Bag
*)pItem
;
9908 if( pBag
&& !pBag
->IsEmpty() )
9909 return EQUIP_ERR_NONEMPTY_BAG_OVER_OTHER_BAG
;
9912 // search stack in bag for merge to
9913 if( pProto
->Stackable
> 1 )
9915 if( bag
== INVENTORY_SLOT_BAG_0
)
9917 res
= _CanStoreItem_InInventorySlots(BANK_SLOT_ITEM_START
,BANK_SLOT_ITEM_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
9918 if(res
!=EQUIP_ERR_OK
)
9922 return EQUIP_ERR_OK
;
9926 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,true,false,pItem
,NULL_BAG
,slot
);
9927 if(res
!=EQUIP_ERR_OK
)
9928 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,true,true,pItem
,NULL_BAG
,slot
);
9930 if(res
!=EQUIP_ERR_OK
)
9934 return EQUIP_ERR_OK
;
9938 // search free slot in bag
9939 if( bag
== INVENTORY_SLOT_BAG_0
)
9941 res
= _CanStoreItem_InInventorySlots(BANK_SLOT_ITEM_START
,BANK_SLOT_ITEM_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
9942 if(res
!=EQUIP_ERR_OK
)
9946 return EQUIP_ERR_OK
;
9950 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,false,false,pItem
,NULL_BAG
,slot
);
9951 if(res
!=EQUIP_ERR_OK
)
9952 res
= _CanStoreItem_InBag(bag
,dest
,pProto
,count
,false,true,pItem
,NULL_BAG
,slot
);
9954 if(res
!=EQUIP_ERR_OK
)
9958 return EQUIP_ERR_OK
;
9962 // not specific bag or have space for partly store only in specific bag
9964 // search stack for merge to
9965 if( pProto
->Stackable
> 1 )
9968 res
= _CanStoreItem_InInventorySlots(BANK_SLOT_ITEM_START
,BANK_SLOT_ITEM_END
,dest
,pProto
,count
,true,pItem
,bag
,slot
);
9969 if(res
!=EQUIP_ERR_OK
)
9973 return EQUIP_ERR_OK
;
9976 if( pProto
->BagFamily
)
9978 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
9980 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,true,false,pItem
,bag
,slot
);
9981 if(res
!=EQUIP_ERR_OK
)
9985 return EQUIP_ERR_OK
;
9989 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
9991 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,true,true,pItem
,bag
,slot
);
9992 if(res
!=EQUIP_ERR_OK
)
9996 return EQUIP_ERR_OK
;
10000 // search free place in special bag
10001 if( pProto
->BagFamily
)
10003 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
10005 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,false,false,pItem
,bag
,slot
);
10006 if(res
!=EQUIP_ERR_OK
)
10010 return EQUIP_ERR_OK
;
10014 // search free space
10015 res
= _CanStoreItem_InInventorySlots(BANK_SLOT_ITEM_START
,BANK_SLOT_ITEM_END
,dest
,pProto
,count
,false,pItem
,bag
,slot
);
10016 if(res
!=EQUIP_ERR_OK
)
10020 return EQUIP_ERR_OK
;
10022 for(int i
= BANK_SLOT_BAG_START
; i
< BANK_SLOT_BAG_END
; i
++)
10024 res
= _CanStoreItem_InBag(i
,dest
,pProto
,count
,false,true,pItem
,bag
,slot
);
10025 if(res
!=EQUIP_ERR_OK
)
10029 return EQUIP_ERR_OK
;
10031 return EQUIP_ERR_BANK_FULL
;
10034 uint8
Player::CanUseItem( Item
*pItem
, bool not_loading
) const
10038 sLog
.outDebug( "STORAGE: CanUseItem item = %u", pItem
->GetEntry());
10039 if( !isAlive() && not_loading
)
10040 return EQUIP_ERR_YOU_ARE_DEAD
;
10041 //if( isStunned() )
10042 // return EQUIP_ERR_YOU_ARE_STUNNED;
10043 ItemPrototype
const *pProto
= pItem
->GetProto();
10046 if( pItem
->IsBindedNotWith(GetGUID()) )
10047 return EQUIP_ERR_DONT_OWN_THAT_ITEM
;
10048 if( (pProto
->AllowableClass
& getClassMask()) == 0 || (pProto
->AllowableRace
& getRaceMask()) == 0 )
10049 return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM
;
10050 if( pItem
->GetSkill() != 0 )
10052 if( GetSkillValue( pItem
->GetSkill() ) == 0 )
10053 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10055 if( pProto
->RequiredSkill
!= 0 )
10057 if( GetSkillValue( pProto
->RequiredSkill
) == 0 )
10058 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10059 else if( GetSkillValue( pProto
->RequiredSkill
) < pProto
->RequiredSkillRank
)
10060 return EQUIP_ERR_ERR_CANT_EQUIP_SKILL
;
10062 if( pProto
->RequiredSpell
!= 0 && !HasSpell( pProto
->RequiredSpell
) )
10063 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10064 if( pProto
->RequiredReputationFaction
&& uint32(GetReputationRank(pProto
->RequiredReputationFaction
)) < pProto
->RequiredReputationRank
)
10065 return EQUIP_ERR_CANT_EQUIP_REPUTATION
;
10066 if( getLevel() < pProto
->RequiredLevel
)
10067 return EQUIP_ERR_CANT_EQUIP_LEVEL_I
;
10068 return EQUIP_ERR_OK
;
10071 return EQUIP_ERR_ITEM_NOT_FOUND
;
10074 bool Player::CanUseItem( ItemPrototype
const *pProto
)
10076 // Used by group, function NeedBeforeGreed, to know if a prototype can be used by a player
10080 if( (pProto
->AllowableClass
& getClassMask()) == 0 || (pProto
->AllowableRace
& getRaceMask()) == 0 )
10082 if( pProto
->RequiredSkill
!= 0 )
10084 if( GetSkillValue( pProto
->RequiredSkill
) == 0 )
10086 else if( GetSkillValue( pProto
->RequiredSkill
) < pProto
->RequiredSkillRank
)
10089 if( pProto
->RequiredSpell
!= 0 && !HasSpell( pProto
->RequiredSpell
) )
10091 if( getLevel() < pProto
->RequiredLevel
)
10098 uint8
Player::CanUseAmmo( uint32 item
) const
10100 sLog
.outDebug( "STORAGE: CanUseAmmo item = %u", item
);
10102 return EQUIP_ERR_YOU_ARE_DEAD
;
10103 //if( isStunned() )
10104 // return EQUIP_ERR_YOU_ARE_STUNNED;
10105 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( item
);
10108 if( pProto
->InventoryType
!= INVTYPE_AMMO
)
10109 return EQUIP_ERR_ONLY_AMMO_CAN_GO_HERE
;
10110 if( (pProto
->AllowableClass
& getClassMask()) == 0 || (pProto
->AllowableRace
& getRaceMask()) == 0 )
10111 return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM
;
10112 if( pProto
->RequiredSkill
!= 0 )
10114 if( GetSkillValue( pProto
->RequiredSkill
) == 0 )
10115 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10116 else if( GetSkillValue( pProto
->RequiredSkill
) < pProto
->RequiredSkillRank
)
10117 return EQUIP_ERR_ERR_CANT_EQUIP_SKILL
;
10119 if( pProto
->RequiredSpell
!= 0 && !HasSpell( pProto
->RequiredSpell
) )
10120 return EQUIP_ERR_NO_REQUIRED_PROFICIENCY
;
10121 /*if( GetReputation() < pProto->RequiredReputation )
10122 return EQUIP_ERR_CANT_EQUIP_REPUTATION;
10124 if( getLevel() < pProto
->RequiredLevel
)
10125 return EQUIP_ERR_CANT_EQUIP_LEVEL_I
;
10127 // Requires No Ammo
10128 if(GetDummyAura(46699))
10129 return EQUIP_ERR_BAG_FULL6
;
10131 return EQUIP_ERR_OK
;
10133 return EQUIP_ERR_ITEM_NOT_FOUND
;
10136 void Player::SetAmmo( uint32 item
)
10142 if( GetUInt32Value(PLAYER_AMMO_ID
) == item
)
10148 uint8 msg
= CanUseAmmo( item
);
10149 if( msg
!= EQUIP_ERR_OK
)
10151 SendEquipError( msg
, NULL
, NULL
);
10156 SetUInt32Value(PLAYER_AMMO_ID
, item
);
10158 _ApplyAmmoBonuses();
10161 void Player::RemoveAmmo()
10163 SetUInt32Value(PLAYER_AMMO_ID
, 0);
10167 if(CanModifyStats())
10168 UpdateDamagePhysical(RANGED_ATTACK
);
10171 // Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case.
10172 Item
* Player::StoreNewItem( ItemPosCountVec
const& dest
, uint32 item
, bool update
,int32 randomPropertyId
)
10175 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
10176 count
+= itr
->count
;
10178 Item
*pItem
= Item::CreateItem( item
, count
, this );
10181 ItemAddedQuestCheck( item
, count
);
10182 if(randomPropertyId
)
10183 pItem
->SetItemRandomProperties(randomPropertyId
);
10184 pItem
= StoreItem( dest
, pItem
, update
);
10189 Item
* Player::StoreItem( ItemPosCountVec
const& dest
, Item
* pItem
, bool update
)
10194 Item
* lastItem
= pItem
;
10196 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); )
10198 uint16 pos
= itr
->pos
;
10199 uint32 count
= itr
->count
;
10203 if(itr
== dest
.end())
10205 lastItem
= _StoreItem(pos
,pItem
,count
,false,update
);
10209 lastItem
= _StoreItem(pos
,pItem
,count
,true,update
);
10215 // Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case.
10216 Item
* Player::_StoreItem( uint16 pos
, Item
*pItem
, uint32 count
, bool clone
, bool update
)
10221 uint8 bag
= pos
>> 8;
10222 uint8 slot
= pos
& 255;
10224 sLog
.outDebug( "STORAGE: StoreItem bag = %u, slot = %u, item = %u, count = %u", bag
, slot
, pItem
->GetEntry(), count
);
10226 Item
*pItem2
= GetItemByPos( bag
, slot
);
10231 pItem
= pItem
->CloneItem(count
,this);
10233 pItem
->SetCount(count
);
10238 if( pItem
->GetProto()->Bonding
== BIND_WHEN_PICKED_UP
||
10239 pItem
->GetProto()->Bonding
== BIND_QUEST_ITEM
||
10240 pItem
->GetProto()->Bonding
== BIND_WHEN_EQUIPED
&& IsBagPos(pos
) )
10241 pItem
->SetBinding( true );
10243 if( bag
== INVENTORY_SLOT_BAG_0
)
10245 m_items
[slot
] = pItem
;
10246 SetUInt64Value( (uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
* 2) ), pItem
->GetGUID() );
10247 pItem
->SetUInt64Value( ITEM_FIELD_CONTAINED
, GetGUID() );
10248 pItem
->SetUInt64Value( ITEM_FIELD_OWNER
, GetGUID() );
10250 pItem
->SetSlot( slot
);
10251 pItem
->SetContainer( NULL
);
10253 if( IsInWorld() && update
)
10255 pItem
->AddToWorld();
10256 pItem
->SendUpdateToPlayer( this );
10259 pItem
->SetState(ITEM_CHANGED
, this);
10263 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
10266 pBag
->StoreItem( slot
, pItem
, update
);
10267 if( IsInWorld() && update
)
10269 pItem
->AddToWorld();
10270 pItem
->SendUpdateToPlayer( this );
10272 pItem
->SetState(ITEM_CHANGED
, this);
10273 pBag
->SetState(ITEM_CHANGED
, this);
10277 AddEnchantmentDurations(pItem
);
10278 AddItemDurations(pItem
);
10284 if( pItem2
->GetProto()->Bonding
== BIND_WHEN_PICKED_UP
||
10285 pItem2
->GetProto()->Bonding
== BIND_QUEST_ITEM
||
10286 pItem2
->GetProto()->Bonding
== BIND_WHEN_EQUIPED
&& IsBagPos(pos
) )
10287 pItem2
->SetBinding( true );
10289 pItem2
->SetCount( pItem2
->GetCount() + count
);
10290 if( IsInWorld() && update
)
10291 pItem2
->SendUpdateToPlayer( this );
10295 // delete item (it not in any slot currently)
10296 if( IsInWorld() && update
)
10298 pItem
->RemoveFromWorld();
10299 pItem
->DestroyForPlayer( this );
10302 RemoveEnchantmentDurations(pItem
);
10303 RemoveItemDurations(pItem
);
10305 pItem
->SetOwnerGUID(GetGUID()); // prevent error at next SetState in case trade/mail/buy from vendor
10306 pItem
->SetState(ITEM_REMOVED
, this);
10308 // AddItemDurations(pItem2); - pItem2 already have duration listed for player
10309 AddEnchantmentDurations(pItem2
);
10311 pItem2
->SetState(ITEM_CHANGED
, this);
10317 Item
* Player::EquipNewItem( uint16 pos
, uint32 item
, uint32 count
, bool update
)
10319 Item
*pItem
= Item::CreateItem( item
, count
, this );
10322 ItemAddedQuestCheck( item
, count
);
10323 Item
* retItem
= EquipItem( pos
, pItem
, update
);
10330 Item
* Player::EquipItem( uint16 pos
, Item
*pItem
, bool update
)
10334 AddEnchantmentDurations(pItem
);
10335 AddItemDurations(pItem
);
10337 uint8 bag
= pos
>> 8;
10338 uint8 slot
= pos
& 255;
10340 Item
*pItem2
= GetItemByPos( bag
, slot
);
10344 VisualizeItem( slot
, pItem
);
10348 ItemPrototype
const *pProto
= pItem
->GetProto();
10350 // item set bonuses applied only at equip and removed at unequip, and still active for broken items
10351 if(pProto
&& pProto
->ItemSet
)
10352 AddItemsSetItem(this,pItem
);
10354 _ApplyItemMods(pItem
, slot
, true);
10356 if(pProto
&& isInCombat()&& pProto
->Class
== ITEM_CLASS_WEAPON
&& m_weaponChangeTimer
== 0)
10358 uint32 cooldownSpell
= SPELL_ID_WEAPON_SWITCH_COOLDOWN_1_5s
;
10360 if (getClass() == CLASS_ROGUE
)
10361 cooldownSpell
= SPELL_ID_WEAPON_SWITCH_COOLDOWN_1_0s
;
10363 SpellEntry
const* spellProto
= sSpellStore
.LookupEntry(cooldownSpell
);
10366 sLog
.outError("Weapon switch cooldown spell %u couldn't be found in Spell.dbc", cooldownSpell
);
10369 m_weaponChangeTimer
= spellProto
->StartRecoveryTime
;
10371 WorldPacket
data(SMSG_SPELL_COOLDOWN
, 8+1+4);
10372 data
<< uint64(GetGUID());
10374 data
<< uint32(cooldownSpell
);
10376 GetSession()->SendPacket(&data
);
10381 if( IsInWorld() && update
)
10383 pItem
->AddToWorld();
10384 pItem
->SendUpdateToPlayer( this );
10387 ApplyEquipCooldown(pItem
);
10389 if( slot
== EQUIPMENT_SLOT_MAINHAND
)
10390 UpdateExpertise(BASE_ATTACK
);
10391 else if( slot
== EQUIPMENT_SLOT_OFFHAND
)
10392 UpdateExpertise(OFF_ATTACK
);
10396 pItem2
->SetCount( pItem2
->GetCount() + pItem
->GetCount() );
10397 if( IsInWorld() && update
)
10398 pItem2
->SendUpdateToPlayer( this );
10400 // delete item (it not in any slot currently)
10401 //pItem->DeleteFromDB();
10402 if( IsInWorld() && update
)
10404 pItem
->RemoveFromWorld();
10405 pItem
->DestroyForPlayer( this );
10408 RemoveEnchantmentDurations(pItem
);
10409 RemoveItemDurations(pItem
);
10411 pItem
->SetOwnerGUID(GetGUID()); // prevent error at next SetState in case trade/mail/buy from vendor
10412 pItem
->SetState(ITEM_REMOVED
, this);
10413 pItem2
->SetState(ITEM_CHANGED
, this);
10415 ApplyEquipCooldown(pItem2
);
10424 void Player::QuickEquipItem( uint16 pos
, Item
*pItem
)
10428 AddEnchantmentDurations(pItem
);
10429 AddItemDurations(pItem
);
10431 uint8 slot
= pos
& 255;
10432 VisualizeItem( slot
, pItem
);
10436 pItem
->AddToWorld();
10437 pItem
->SendUpdateToPlayer( this );
10442 void Player::SetVisibleItemSlot(uint8 slot
, Item
*pItem
)
10444 // PLAYER_VISIBLE_ITEM_i_CREATOR // Size: 2
10445 // PLAYER_VISIBLE_ITEM_i_0 // Size: 12
10446 // entry // Size: 1
10447 // inspected enchantments // Size: 6
10449 // PLAYER_VISIBLE_ITEM_i_PROPERTIES // Size: 1 (property,suffix factor)
10450 // PLAYER_VISIBLE_ITEM_i_PAD // Size: 1
10455 SetUInt64Value(PLAYER_VISIBLE_ITEM_1_CREATOR
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
), pItem
->GetUInt64Value(ITEM_FIELD_CREATOR
));
10457 int VisibleBase
= PLAYER_VISIBLE_ITEM_1_0
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
);
10458 SetUInt32Value(VisibleBase
+ 0, pItem
->GetEntry());
10460 for(int i
= 0; i
< MAX_INSPECTED_ENCHANTMENT_SLOT
; ++i
)
10461 SetUInt32Value(VisibleBase
+ 1 + i
, pItem
->GetEnchantmentId(EnchantmentSlot(i
)));
10463 // Use SetInt16Value to prevent set high part to FFFF for negative value
10464 SetInt16Value( PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
), 0, pItem
->GetItemRandomPropertyId());
10465 SetUInt32Value(PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ 1 + (slot
* MAX_VISIBLE_ITEM_OFFSET
), pItem
->GetItemSuffixFactor());
10469 SetUInt64Value(PLAYER_VISIBLE_ITEM_1_CREATOR
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
), 0);
10471 int VisibleBase
= PLAYER_VISIBLE_ITEM_1_0
+ (slot
* MAX_VISIBLE_ITEM_OFFSET
);
10472 SetUInt32Value(VisibleBase
+ 0, 0);
10474 for(int i
= 0; i
< MAX_INSPECTED_ENCHANTMENT_SLOT
; ++i
)
10475 SetUInt32Value(VisibleBase
+ 1 + i
, 0);
10477 SetUInt32Value(PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ 0 + (slot
* MAX_VISIBLE_ITEM_OFFSET
), 0);
10478 SetUInt32Value(PLAYER_VISIBLE_ITEM_1_PROPERTIES
+ 1 + (slot
* MAX_VISIBLE_ITEM_OFFSET
), 0);
10482 void Player::VisualizeItem( uint8 slot
, Item
*pItem
)
10487 // check also BIND_WHEN_PICKED_UP and BIND_QUEST_ITEM for .additem or .additemset case by GM (not binded at adding to inventory)
10488 if( pItem
->GetProto()->Bonding
== BIND_WHEN_EQUIPED
|| pItem
->GetProto()->Bonding
== BIND_WHEN_PICKED_UP
|| pItem
->GetProto()->Bonding
== BIND_QUEST_ITEM
)
10489 pItem
->SetBinding( true );
10491 sLog
.outDebug( "STORAGE: EquipItem slot = %u, item = %u", slot
, pItem
->GetEntry());
10493 m_items
[slot
] = pItem
;
10494 SetUInt64Value( (uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
* 2) ), pItem
->GetGUID() );
10495 pItem
->SetUInt64Value( ITEM_FIELD_CONTAINED
, GetGUID() );
10496 pItem
->SetUInt64Value( ITEM_FIELD_OWNER
, GetGUID() );
10497 pItem
->SetSlot( slot
);
10498 pItem
->SetContainer( NULL
);
10500 if( slot
< EQUIPMENT_SLOT_END
)
10501 SetVisibleItemSlot(slot
,pItem
);
10503 pItem
->SetState(ITEM_CHANGED
, this);
10506 void Player::RemoveItem( uint8 bag
, uint8 slot
, bool update
)
10508 // note: removeitem does not actually change the item
10509 // it only takes the item out of storage temporarily
10510 // note2: if removeitem is to be used for delinking
10511 // the item must be removed from the player's updatequeue
10513 Item
*pItem
= GetItemByPos( bag
, slot
);
10516 sLog
.outDebug( "STORAGE: RemoveItem bag = %u, slot = %u, item = %u", bag
, slot
, pItem
->GetEntry());
10518 RemoveEnchantmentDurations(pItem
);
10519 RemoveItemDurations(pItem
);
10521 if( bag
== INVENTORY_SLOT_BAG_0
)
10523 if ( slot
< INVENTORY_SLOT_BAG_END
)
10525 ItemPrototype
const *pProto
= pItem
->GetProto();
10526 // item set bonuses applied only at equip and removed at unequip, and still active for broken items
10528 if(pProto
&& pProto
->ItemSet
)
10529 RemoveItemsSetItem(this,pProto
);
10531 _ApplyItemMods(pItem
, slot
, false);
10533 // remove item dependent auras and casts (only weapon and armor slots)
10534 if(slot
< EQUIPMENT_SLOT_END
)
10535 RemoveItemDependentAurasAndCasts(pItem
);
10537 // remove held enchantments
10538 if ( slot
== EQUIPMENT_SLOT_MAINHAND
)
10540 if (pItem
->GetItemSuffixFactor())
10542 pItem
->ClearEnchantment(PROP_ENCHANTMENT_SLOT_3
);
10543 pItem
->ClearEnchantment(PROP_ENCHANTMENT_SLOT_4
);
10547 pItem
->ClearEnchantment(PROP_ENCHANTMENT_SLOT_0
);
10548 pItem
->ClearEnchantment(PROP_ENCHANTMENT_SLOT_1
);
10553 m_items
[slot
] = NULL
;
10554 SetUInt64Value((uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
*2)), 0);
10556 if ( slot
< EQUIPMENT_SLOT_END
)
10557 SetVisibleItemSlot(slot
,NULL
);
10561 Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
);
10563 pBag
->RemoveItem(slot
, update
);
10565 pItem
->SetUInt64Value( ITEM_FIELD_CONTAINED
, 0 );
10566 // pItem->SetUInt64Value( ITEM_FIELD_OWNER, 0 ); not clear owner at remove (it will be set at store). This used in mail and auction code
10567 pItem
->SetSlot( NULL_SLOT
);
10568 if( IsInWorld() && update
)
10569 pItem
->SendUpdateToPlayer( this );
10571 if( slot
== EQUIPMENT_SLOT_MAINHAND
)
10572 UpdateExpertise(BASE_ATTACK
);
10573 else if( slot
== EQUIPMENT_SLOT_OFFHAND
)
10574 UpdateExpertise(OFF_ATTACK
);
10578 // Common operation need to remove item from inventory without delete in trade, auction, guild bank, mail....
10579 void Player::MoveItemFromInventory(uint8 bag
, uint8 slot
, bool update
)
10581 if(Item
* it
= GetItemByPos(bag
,slot
))
10583 ItemRemovedQuestCheck(it
->GetEntry(),it
->GetCount());
10584 RemoveItem( bag
,slot
,update
);
10585 it
->RemoveFromUpdateQueueOf(this);
10586 if(it
->IsInWorld())
10588 it
->RemoveFromWorld();
10589 it
->DestroyForPlayer( this );
10594 // Common operation need to add item from inventory without delete in trade, guild bank, mail....
10595 void Player::MoveItemToInventory(ItemPosCountVec
const& dest
, Item
* pItem
, bool update
, bool in_characterInventoryDB
)
10597 // update quest counters
10598 ItemAddedQuestCheck(pItem
->GetEntry(),pItem
->GetCount());
10601 Item
* pLastItem
= StoreItem( dest
, pItem
, update
);
10603 // only set if not merged to existed stack (pItem can be deleted already but we can compare pointers any way)
10604 if(pLastItem
==pItem
)
10606 // update owner for last item (this can be original item with wrong owner
10607 if(pLastItem
->GetOwnerGUID() != GetGUID())
10608 pLastItem
->SetOwnerGUID(GetGUID());
10610 // if this original item then it need create record in inventory
10611 // in case trade we already have item in other player inventory
10612 pLastItem
->SetState(in_characterInventoryDB
? ITEM_CHANGED
: ITEM_NEW
, this);
10616 void Player::DestroyItem( uint8 bag
, uint8 slot
, bool update
)
10618 Item
*pItem
= GetItemByPos( bag
, slot
);
10621 sLog
.outDebug( "STORAGE: DestroyItem bag = %u, slot = %u, item = %u", bag
, slot
, pItem
->GetEntry());
10623 // start from destroy contained items (only equipped bag can have its)
10624 if (pItem
->IsBag() && pItem
->IsEquipped()) // this also prevent infinity loop if empty bag stored in bag==slot
10626 for (int i
= 0; i
< MAX_BAG_SIZE
; i
++)
10627 DestroyItem(slot
,i
,update
);
10630 if(pItem
->HasFlag(ITEM_FIELD_FLAGS
, ITEM_FLAGS_WRAPPED
))
10631 CharacterDatabase
.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", pItem
->GetGUIDLow());
10633 RemoveEnchantmentDurations(pItem
);
10634 RemoveItemDurations(pItem
);
10636 ItemRemovedQuestCheck( pItem
->GetEntry(), pItem
->GetCount() );
10638 if( bag
== INVENTORY_SLOT_BAG_0
)
10640 SetUInt64Value((uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
*2)), 0);
10642 // equipment and equipped bags can have applied bonuses
10643 if ( slot
< INVENTORY_SLOT_BAG_END
)
10645 ItemPrototype
const *pProto
= pItem
->GetProto();
10647 // item set bonuses applied only at equip and removed at unequip, and still active for broken items
10648 if(pProto
&& pProto
->ItemSet
)
10649 RemoveItemsSetItem(this,pProto
);
10651 _ApplyItemMods(pItem
, slot
, false);
10654 if ( slot
< EQUIPMENT_SLOT_END
)
10656 // remove item dependent auras and casts (only weapon and armor slots)
10657 RemoveItemDependentAurasAndCasts(pItem
);
10659 // equipment visual show
10660 SetVisibleItemSlot(slot
,NULL
);
10663 m_items
[slot
] = NULL
;
10665 else if(Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, bag
))
10666 pBag
->RemoveItem(slot
, update
);
10668 if( IsInWorld() && update
)
10670 pItem
->RemoveFromWorld();
10671 pItem
->DestroyForPlayer(this);
10674 //pItem->SetOwnerGUID(0);
10675 pItem
->SetUInt64Value( ITEM_FIELD_CONTAINED
, 0 );
10676 pItem
->SetSlot( NULL_SLOT
);
10677 pItem
->SetState(ITEM_REMOVED
, this);
10681 void Player::DestroyItemCount( uint32 item
, uint32 count
, bool update
, bool unequip_check
)
10683 sLog
.outDebug( "STORAGE: DestroyItemCount item = %u, count = %u", item
, count
);
10685 ItemPrototype
const *pProto
;
10686 uint32 remcount
= 0;
10689 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
10691 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10692 if( pItem
&& pItem
->GetEntry() == item
)
10694 if( pItem
->GetCount() + remcount
<= count
)
10696 // all items in inventory can unequipped
10697 remcount
+= pItem
->GetCount();
10698 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10700 if(remcount
>=count
)
10705 pProto
= pItem
->GetProto();
10706 ItemRemovedQuestCheck( pItem
->GetEntry(), count
- remcount
);
10707 pItem
->SetCount( pItem
->GetCount() - count
+ remcount
);
10708 if( IsInWorld() & update
)
10709 pItem
->SendUpdateToPlayer( this );
10710 pItem
->SetState(ITEM_CHANGED
, this);
10715 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
10717 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10718 if( pItem
&& pItem
->GetEntry() == item
)
10720 if( pItem
->GetCount() + remcount
<= count
)
10722 // all keys can be unequipped
10723 remcount
+= pItem
->GetCount();
10724 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10726 if(remcount
>=count
)
10731 pProto
= pItem
->GetProto();
10732 ItemRemovedQuestCheck( pItem
->GetEntry(), count
- remcount
);
10733 pItem
->SetCount( pItem
->GetCount() - count
+ remcount
);
10734 if( IsInWorld() & update
)
10735 pItem
->SendUpdateToPlayer( this );
10736 pItem
->SetState(ITEM_CHANGED
, this);
10742 // in inventory bags
10743 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10745 if(Bag
*pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
10747 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
10749 pItem
= pBag
->GetItemByPos(j
);
10750 if( pItem
&& pItem
->GetEntry() == item
)
10752 // all items in bags can be unequipped
10753 if( pItem
->GetCount() + remcount
<= count
)
10755 remcount
+= pItem
->GetCount();
10756 DestroyItem( i
, j
, update
);
10758 if(remcount
>=count
)
10763 pProto
= pItem
->GetProto();
10764 ItemRemovedQuestCheck( pItem
->GetEntry(), count
- remcount
);
10765 pItem
->SetCount( pItem
->GetCount() - count
+ remcount
);
10766 if( IsInWorld() && update
)
10767 pItem
->SendUpdateToPlayer( this );
10768 pItem
->SetState(ITEM_CHANGED
, this);
10776 // in equipment and bag list
10777 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10779 pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10780 if( pItem
&& pItem
->GetEntry() == item
)
10782 if( pItem
->GetCount() + remcount
<= count
)
10784 if(!unequip_check
|| CanUnequipItem(INVENTORY_SLOT_BAG_0
<< 8 | i
,false) == EQUIP_ERR_OK
)
10786 remcount
+= pItem
->GetCount();
10787 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10789 if(remcount
>=count
)
10795 pProto
= pItem
->GetProto();
10796 ItemRemovedQuestCheck( pItem
->GetEntry(), count
- remcount
);
10797 pItem
->SetCount( pItem
->GetCount() - count
+ remcount
);
10798 if( IsInWorld() & update
)
10799 pItem
->SendUpdateToPlayer( this );
10800 pItem
->SetState(ITEM_CHANGED
, this);
10807 void Player::DestroyZoneLimitedItem( bool update
, uint32 new_zone
)
10809 sLog
.outDebug( "STORAGE: DestroyZoneLimitedItem in map %u and area %u", GetMapId(), new_zone
);
10812 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
10814 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10815 if( pItem
&& pItem
->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone
) )
10816 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10818 for(int i
= KEYRING_SLOT_START
; i
< QUESTBAG_SLOT_END
; i
++)
10820 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10821 if( pItem
&& pItem
->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone
) )
10822 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10825 // in inventory bags
10826 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10828 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10831 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
10833 Item
* pItem
= pBag
->GetItemByPos(j
);
10834 if( pItem
&& pItem
->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone
) )
10835 DestroyItem( i
, j
, update
);
10840 // in equipment and bag list
10841 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10843 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10844 if( pItem
&& pItem
->IsLimitedToAnotherMapOrZone(GetMapId(),new_zone
) )
10845 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10849 void Player::DestroyConjuredItems( bool update
)
10851 // used when entering arena
10852 // destroys all conjured items
10853 sLog
.outDebug( "STORAGE: DestroyConjuredItems" );
10856 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
10858 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10859 if( pItem
&& pItem
->GetProto() &&
10860 (pItem
->GetProto()->Class
== ITEM_CLASS_CONSUMABLE
) &&
10861 (pItem
->GetProto()->Flags
& ITEM_FLAGS_CONJURED
) )
10862 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10865 // in inventory bags
10866 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10868 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10871 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
10873 Item
* pItem
= pBag
->GetItemByPos(j
);
10874 if( pItem
&& pItem
->GetProto() &&
10875 (pItem
->GetProto()->Class
== ITEM_CLASS_CONSUMABLE
) &&
10876 (pItem
->GetProto()->Flags
& ITEM_FLAGS_CONJURED
) )
10877 DestroyItem( i
, j
, update
);
10882 // in equipment and bag list
10883 for(int i
= EQUIPMENT_SLOT_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
10885 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
10886 if( pItem
&& pItem
->GetProto() &&
10887 (pItem
->GetProto()->Class
== ITEM_CLASS_CONSUMABLE
) &&
10888 (pItem
->GetProto()->Flags
& ITEM_FLAGS_CONJURED
) )
10889 DestroyItem( INVENTORY_SLOT_BAG_0
, i
, update
);
10893 void Player::DestroyItemCount( Item
* pItem
, uint32
&count
, bool update
)
10898 sLog
.outDebug( "STORAGE: DestroyItemCount item (GUID: %u, Entry: %u) count = %u", pItem
->GetGUIDLow(),pItem
->GetEntry(), count
);
10900 if( pItem
->GetCount() <= count
)
10902 count
-= pItem
->GetCount();
10904 DestroyItem( pItem
->GetBagSlot(),pItem
->GetSlot(), update
);
10908 ItemRemovedQuestCheck( pItem
->GetEntry(), count
);
10909 pItem
->SetCount( pItem
->GetCount() - count
);
10911 if( IsInWorld() & update
)
10912 pItem
->SendUpdateToPlayer( this );
10913 pItem
->SetState(ITEM_CHANGED
, this);
10917 void Player::SplitItem( uint16 src
, uint16 dst
, uint32 count
)
10919 uint8 srcbag
= src
>> 8;
10920 uint8 srcslot
= src
& 255;
10922 uint8 dstbag
= dst
>> 8;
10923 uint8 dstslot
= dst
& 255;
10925 Item
*pSrcItem
= GetItemByPos( srcbag
, srcslot
);
10928 SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, pSrcItem
, NULL
);
10932 // not let split all items (can be only at cheating)
10933 if(pSrcItem
->GetCount() == count
)
10935 SendEquipError( EQUIP_ERR_COULDNT_SPLIT_ITEMS
, pSrcItem
, NULL
);
10939 // not let split more existed items (can be only at cheating)
10940 if(pSrcItem
->GetCount() < count
)
10942 SendEquipError( EQUIP_ERR_TRIED_TO_SPLIT_MORE_THAN_COUNT
, pSrcItem
, NULL
);
10946 if(pSrcItem
->m_lootGenerated
) // prevent split looting item (item
10948 //best error message found for attempting to split while looting
10949 SendEquipError( EQUIP_ERR_COULDNT_SPLIT_ITEMS
, pSrcItem
, NULL
);
10953 sLog
.outDebug( "STORAGE: SplitItem bag = %u, slot = %u, item = %u, count = %u", dstbag
, dstslot
, pSrcItem
->GetEntry(), count
);
10954 Item
*pNewItem
= pSrcItem
->CloneItem( count
, this );
10957 SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, pSrcItem
, NULL
);
10961 if( IsInventoryPos( dst
) )
10963 // change item amount before check (for unique max count check)
10964 pSrcItem
->SetCount( pSrcItem
->GetCount() - count
);
10966 ItemPosCountVec dest
;
10967 uint8 msg
= CanStoreItem( dstbag
, dstslot
, dest
, pNewItem
, false );
10968 if( msg
!= EQUIP_ERR_OK
)
10971 pSrcItem
->SetCount( pSrcItem
->GetCount() + count
);
10972 SendEquipError( msg
, pSrcItem
, NULL
);
10977 pSrcItem
->SendUpdateToPlayer( this );
10978 pSrcItem
->SetState(ITEM_CHANGED
, this);
10979 StoreItem( dest
, pNewItem
, true);
10981 else if( IsBankPos ( dst
) )
10983 // change item amount before check (for unique max count check)
10984 pSrcItem
->SetCount( pSrcItem
->GetCount() - count
);
10986 ItemPosCountVec dest
;
10987 uint8 msg
= CanBankItem( dstbag
, dstslot
, dest
, pNewItem
, false );
10988 if( msg
!= EQUIP_ERR_OK
)
10991 pSrcItem
->SetCount( pSrcItem
->GetCount() + count
);
10992 SendEquipError( msg
, pSrcItem
, NULL
);
10997 pSrcItem
->SendUpdateToPlayer( this );
10998 pSrcItem
->SetState(ITEM_CHANGED
, this);
10999 BankItem( dest
, pNewItem
, true);
11001 else if( IsEquipmentPos ( dst
) )
11003 // change item amount before check (for unique max count check), provide space for splitted items
11004 pSrcItem
->SetCount( pSrcItem
->GetCount() - count
);
11007 uint8 msg
= CanEquipItem( dstslot
, dest
, pNewItem
, false );
11008 if( msg
!= EQUIP_ERR_OK
)
11011 pSrcItem
->SetCount( pSrcItem
->GetCount() + count
);
11012 SendEquipError( msg
, pSrcItem
, NULL
);
11017 pSrcItem
->SendUpdateToPlayer( this );
11018 pSrcItem
->SetState(ITEM_CHANGED
, this);
11019 EquipItem( dest
, pNewItem
, true);
11020 AutoUnequipOffhandIfNeed();
11024 void Player::SwapItem( uint16 src
, uint16 dst
)
11026 uint8 srcbag
= src
>> 8;
11027 uint8 srcslot
= src
& 255;
11029 uint8 dstbag
= dst
>> 8;
11030 uint8 dstslot
= dst
& 255;
11032 Item
*pSrcItem
= GetItemByPos( srcbag
, srcslot
);
11033 Item
*pDstItem
= GetItemByPos( dstbag
, dstslot
);
11038 sLog
.outDebug( "STORAGE: SwapItem bag = %u, slot = %u, item = %u", dstbag
, dstslot
, pSrcItem
->GetEntry());
11042 SendEquipError( EQUIP_ERR_YOU_ARE_DEAD
, pSrcItem
, pDstItem
);
11046 if(pSrcItem
->m_lootGenerated
) // prevent swap looting item
11048 //best error message found for attempting to swap while looting
11049 SendEquipError( EQUIP_ERR_CANT_DO_RIGHT_NOW
, pSrcItem
, NULL
);
11053 // check unequip potability for equipped items and bank bags
11054 if(IsEquipmentPos ( src
) || IsBagPos ( src
))
11056 // bags can be swapped with empty bag slots
11057 uint8 msg
= CanUnequipItem( src
, !IsBagPos ( src
) || IsBagPos ( dst
));
11058 if(msg
!= EQUIP_ERR_OK
)
11060 SendEquipError( msg
, pSrcItem
, pDstItem
);
11065 // prevent put equipped/bank bag in self
11066 if( IsBagPos ( src
) && srcslot
== dstbag
)
11068 SendEquipError( EQUIP_ERR_NONEMPTY_BAG_OVER_OTHER_BAG
, pSrcItem
, pDstItem
);
11074 if( IsInventoryPos( dst
) )
11076 ItemPosCountVec dest
;
11077 uint8 msg
= CanStoreItem( dstbag
, dstslot
, dest
, pSrcItem
, false );
11078 if( msg
!= EQUIP_ERR_OK
)
11080 SendEquipError( msg
, pSrcItem
, NULL
);
11084 RemoveItem(srcbag
, srcslot
, true);
11085 StoreItem( dest
, pSrcItem
, true);
11087 else if( IsBankPos ( dst
) )
11089 ItemPosCountVec dest
;
11090 uint8 msg
= CanBankItem( dstbag
, dstslot
, dest
, pSrcItem
, false);
11091 if( msg
!= EQUIP_ERR_OK
)
11093 SendEquipError( msg
, pSrcItem
, NULL
);
11097 RemoveItem(srcbag
, srcslot
, true);
11098 BankItem( dest
, pSrcItem
, true);
11100 else if( IsEquipmentPos ( dst
) )
11103 uint8 msg
= CanEquipItem( dstslot
, dest
, pSrcItem
, false );
11104 if( msg
!= EQUIP_ERR_OK
)
11106 SendEquipError( msg
, pSrcItem
, NULL
);
11110 RemoveItem(srcbag
, srcslot
, true);
11111 EquipItem( dest
, pSrcItem
, true);
11112 AutoUnequipOffhandIfNeed();
11115 else // if (!pDstItem)
11117 if(pDstItem
->m_lootGenerated
) // prevent swap looting item
11119 //best error message found for attempting to swap while looting
11120 SendEquipError( EQUIP_ERR_CANT_DO_RIGHT_NOW
, pDstItem
, NULL
);
11124 // check unequip potability for equipped items and bank bags
11125 if(IsEquipmentPos ( dst
) || IsBagPos ( dst
))
11127 // bags can be swapped with empty bag slots
11128 uint8 msg
= CanUnequipItem( dst
, !IsBagPos ( dst
) || IsBagPos ( src
) );
11129 if(msg
!= EQUIP_ERR_OK
)
11131 SendEquipError( msg
, pSrcItem
, pDstItem
);
11136 // attempt merge to / fill target item
11139 ItemPosCountVec sDest
;
11141 if( IsInventoryPos( dst
) )
11142 msg
= CanStoreItem( dstbag
, dstslot
, sDest
, pSrcItem
, false );
11143 else if( IsBankPos ( dst
) )
11144 msg
= CanBankItem( dstbag
, dstslot
, sDest
, pSrcItem
, false );
11145 else if( IsEquipmentPos ( dst
) )
11146 msg
= CanEquipItem( dstslot
, eDest
, pSrcItem
, false );
11150 // can be merge/fill
11151 if(msg
== EQUIP_ERR_OK
)
11153 if( pSrcItem
->GetCount() + pDstItem
->GetCount() <= pSrcItem
->GetProto()->Stackable
)
11155 RemoveItem(srcbag
, srcslot
, true);
11157 if( IsInventoryPos( dst
) )
11158 StoreItem( sDest
, pSrcItem
, true);
11159 else if( IsBankPos ( dst
) )
11160 BankItem( sDest
, pSrcItem
, true);
11161 else if( IsEquipmentPos ( dst
) )
11163 EquipItem( eDest
, pSrcItem
, true);
11164 AutoUnequipOffhandIfNeed();
11169 pSrcItem
->SetCount( pSrcItem
->GetCount() + pDstItem
->GetCount() - pSrcItem
->GetProto()->Stackable
);
11170 pDstItem
->SetCount( pSrcItem
->GetProto()->Stackable
);
11171 pSrcItem
->SetState(ITEM_CHANGED
, this);
11172 pDstItem
->SetState(ITEM_CHANGED
, this);
11175 pSrcItem
->SendUpdateToPlayer( this );
11176 pDstItem
->SendUpdateToPlayer( this );
11183 // impossible merge/fill, do real swap
11186 // check src->dest move possibility
11187 ItemPosCountVec sDest
;
11189 if( IsInventoryPos( dst
) )
11190 msg
= CanStoreItem( dstbag
, dstslot
, sDest
, pSrcItem
, true );
11191 else if( IsBankPos( dst
) )
11192 msg
= CanBankItem( dstbag
, dstslot
, sDest
, pSrcItem
, true );
11193 else if( IsEquipmentPos( dst
) )
11195 msg
= CanEquipItem( dstslot
, eDest
, pSrcItem
, true );
11196 if( msg
== EQUIP_ERR_OK
)
11197 msg
= CanUnequipItem( eDest
, true );
11200 if( msg
!= EQUIP_ERR_OK
)
11202 SendEquipError( msg
, pSrcItem
, pDstItem
);
11206 // check dest->src move possibility
11207 ItemPosCountVec sDest2
;
11209 if( IsInventoryPos( src
) )
11210 msg
= CanStoreItem( srcbag
, srcslot
, sDest2
, pDstItem
, true );
11211 else if( IsBankPos( src
) )
11212 msg
= CanBankItem( srcbag
, srcslot
, sDest2
, pDstItem
, true );
11213 else if( IsEquipmentPos( src
) )
11215 msg
= CanEquipItem( srcslot
, eDest2
, pDstItem
, true);
11216 if( msg
== EQUIP_ERR_OK
)
11217 msg
= CanUnequipItem( eDest2
, true);
11220 if( msg
!= EQUIP_ERR_OK
)
11222 SendEquipError( msg
, pDstItem
, pSrcItem
);
11226 // now do moves, remove...
11227 RemoveItem(dstbag
, dstslot
, false);
11228 RemoveItem(srcbag
, srcslot
, false);
11231 if( IsInventoryPos( dst
) )
11232 StoreItem(sDest
, pSrcItem
, true);
11233 else if( IsBankPos( dst
) )
11234 BankItem(sDest
, pSrcItem
, true);
11235 else if( IsEquipmentPos( dst
) )
11236 EquipItem(eDest
, pSrcItem
, true);
11239 if( IsInventoryPos( src
) )
11240 StoreItem(sDest2
, pDstItem
, true);
11241 else if( IsBankPos( src
) )
11242 BankItem(sDest2
, pDstItem
, true);
11243 else if( IsEquipmentPos( src
) )
11244 EquipItem(eDest2
, pDstItem
, true);
11246 AutoUnequipOffhandIfNeed();
11250 void Player::AddItemToBuyBackSlot( Item
*pItem
)
11254 uint32 slot
= m_currentBuybackSlot
;
11255 // if current back slot non-empty search oldest or free
11258 uint32 oldest_time
= GetUInt32Value( PLAYER_FIELD_BUYBACK_TIMESTAMP_1
);
11259 uint32 oldest_slot
= BUYBACK_SLOT_START
;
11261 for(uint32 i
= BUYBACK_SLOT_START
+1; i
< BUYBACK_SLOT_END
; ++i
)
11270 uint32 i_time
= GetUInt32Value( PLAYER_FIELD_BUYBACK_TIMESTAMP_1
+ i
- BUYBACK_SLOT_START
);
11272 if(oldest_time
> i_time
)
11274 oldest_time
= i_time
;
11280 slot
= oldest_slot
;
11283 RemoveItemFromBuyBackSlot( slot
, true );
11284 sLog
.outDebug( "STORAGE: AddItemToBuyBackSlot item = %u, slot = %u", pItem
->GetEntry(), slot
);
11286 m_items
[slot
] = pItem
;
11287 time_t base
= time(NULL
);
11288 uint32 etime
= uint32(base
- m_logintime
+ (30 * 3600));
11289 uint32 eslot
= slot
- BUYBACK_SLOT_START
;
11291 SetUInt64Value( PLAYER_FIELD_VENDORBUYBACK_SLOT_1
+ eslot
* 2, pItem
->GetGUID() );
11292 ItemPrototype
const *pProto
= pItem
->GetProto();
11294 SetUInt32Value( PLAYER_FIELD_BUYBACK_PRICE_1
+ eslot
, pProto
->SellPrice
* pItem
->GetCount() );
11296 SetUInt32Value( PLAYER_FIELD_BUYBACK_PRICE_1
+ eslot
, 0 );
11297 SetUInt32Value( PLAYER_FIELD_BUYBACK_TIMESTAMP_1
+ eslot
, (uint32
)etime
);
11299 // move to next (for non filled list is move most optimized choice)
11300 if(m_currentBuybackSlot
< BUYBACK_SLOT_END
-1)
11301 ++m_currentBuybackSlot
;
11305 Item
* Player::GetItemFromBuyBackSlot( uint32 slot
)
11307 sLog
.outDebug( "STORAGE: GetItemFromBuyBackSlot slot = %u", slot
);
11308 if( slot
>= BUYBACK_SLOT_START
&& slot
< BUYBACK_SLOT_END
)
11309 return m_items
[slot
];
11313 void Player::RemoveItemFromBuyBackSlot( uint32 slot
, bool del
)
11315 sLog
.outDebug( "STORAGE: RemoveItemFromBuyBackSlot slot = %u", slot
);
11316 if( slot
>= BUYBACK_SLOT_START
&& slot
< BUYBACK_SLOT_END
)
11318 Item
*pItem
= m_items
[slot
];
11321 pItem
->RemoveFromWorld();
11322 if(del
) pItem
->SetState(ITEM_REMOVED
, this);
11325 m_items
[slot
] = NULL
;
11327 uint32 eslot
= slot
- BUYBACK_SLOT_START
;
11328 SetUInt64Value( PLAYER_FIELD_VENDORBUYBACK_SLOT_1
+ eslot
* 2, 0 );
11329 SetUInt32Value( PLAYER_FIELD_BUYBACK_PRICE_1
+ eslot
, 0 );
11330 SetUInt32Value( PLAYER_FIELD_BUYBACK_TIMESTAMP_1
+ eslot
, 0 );
11332 // if current backslot is filled set to now free slot
11333 if(m_items
[m_currentBuybackSlot
])
11334 m_currentBuybackSlot
= slot
;
11338 void Player::SendEquipError( uint8 msg
, Item
* pItem
, Item
*pItem2
)
11340 sLog
.outDebug( "WORLD: Sent SMSG_INVENTORY_CHANGE_FAILURE (%u)",msg
);
11341 WorldPacket
data( SMSG_INVENTORY_CHANGE_FAILURE
, (msg
== EQUIP_ERR_CANT_EQUIP_LEVEL_I
? 22 : 18) );
11342 data
<< uint8(msg
);
11346 data
<< uint64(pItem
? pItem
->GetGUID() : 0);
11347 data
<< uint64(pItem2
? pItem2
->GetGUID() : 0);
11348 data
<< uint8(0); // not 0 there...
11350 if(msg
== EQUIP_ERR_CANT_EQUIP_LEVEL_I
)
11355 if(ItemPrototype
const* proto
= pItem
->GetProto())
11356 level
= proto
->RequiredLevel
;
11358 data
<< uint32(level
); // new 2.4.0
11361 GetSession()->SendPacket(&data
);
11364 void Player::SendBuyError( uint8 msg
, Creature
* pCreature
, uint32 item
, uint32 param
)
11366 sLog
.outDebug( "WORLD: Sent SMSG_BUY_FAILED" );
11367 WorldPacket
data( SMSG_BUY_FAILED
, (8+4+4+1) );
11368 data
<< uint64(pCreature
? pCreature
->GetGUID() : 0);
11369 data
<< uint32(item
);
11371 data
<< uint32(param
);
11372 data
<< uint8(msg
);
11373 GetSession()->SendPacket(&data
);
11376 void Player::SendSellError( uint8 msg
, Creature
* pCreature
, uint64 guid
, uint32 param
)
11378 sLog
.outDebug( "WORLD: Sent SMSG_SELL_ITEM" );
11379 WorldPacket
data( SMSG_SELL_ITEM
,(8+8+(param
?4:0)+1)); // last check 2.0.10
11380 data
<< uint64(pCreature
? pCreature
->GetGUID() : 0);
11381 data
<< uint64(guid
);
11383 data
<< uint32(param
);
11384 data
<< uint8(msg
);
11385 GetSession()->SendPacket(&data
);
11388 void Player::ClearTrade()
11391 acceptTrade
= false;
11392 for(int i
= 0; i
< TRADE_SLOT_COUNT
; i
++)
11393 tradeItems
[i
] = NULL_SLOT
;
11396 void Player::TradeCancel(bool sendback
)
11400 // send yellow "Trade canceled" message to both traders
11404 ws
->SendCancelTrade();
11405 ws
= pTrader
->GetSession();
11406 if(!ws
->PlayerLogout())
11407 ws
->SendCancelTrade();
11411 pTrader
->ClearTrade();
11412 // prevent loss of reference
11413 pTrader
->pTrader
= NULL
;
11418 void Player::UpdateItemDuration(uint32 time
, bool realtimeonly
)
11420 if(m_itemDuration
.empty())
11423 sLog
.outDebug("Player::UpdateItemDuration(%u,%u)", time
,realtimeonly
);
11425 for(ItemDurationList::iterator itr
= m_itemDuration
.begin();itr
!= m_itemDuration
.end(); )
11428 ++itr
; // current element can be erased in UpdateDuration
11430 if (realtimeonly
&& item
->GetProto()->Duration
< 0 || !realtimeonly
)
11431 item
->UpdateDuration(this,time
);
11435 void Player::UpdateEnchantTime(uint32 time
)
11437 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin(),next
;itr
!= m_enchantDuration
.end();itr
=next
)
11441 if(!itr
->item
->GetEnchantmentId(itr
->slot
))
11443 next
= m_enchantDuration
.erase(itr
);
11445 else if(itr
->leftduration
<= time
)
11447 ApplyEnchantment(itr
->item
,itr
->slot
,false,false);
11448 itr
->item
->ClearEnchantment(itr
->slot
);
11449 next
= m_enchantDuration
.erase(itr
);
11451 else if(itr
->leftduration
> time
)
11453 itr
->leftduration
-= time
;
11459 void Player::AddEnchantmentDurations(Item
*item
)
11461 for(int x
=0;x
<MAX_ENCHANTMENT_SLOT
;++x
)
11463 if(!item
->GetEnchantmentId(EnchantmentSlot(x
)))
11466 uint32 duration
= item
->GetEnchantmentDuration(EnchantmentSlot(x
));
11468 AddEnchantmentDuration(item
,EnchantmentSlot(x
),duration
);
11472 void Player::RemoveEnchantmentDurations(Item
*item
)
11474 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin();itr
!= m_enchantDuration
.end();)
11476 if(itr
->item
== item
)
11478 // save duration in item
11479 item
->SetEnchantmentDuration(EnchantmentSlot(itr
->slot
),itr
->leftduration
);
11480 itr
= m_enchantDuration
.erase(itr
);
11487 void Player::RemoveAllEnchantments(EnchantmentSlot slot
)
11489 // remove enchantments from equipped items first to clean up the m_enchantDuration list
11490 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin(),next
;itr
!= m_enchantDuration
.end();itr
=next
)
11493 if(itr
->slot
==slot
)
11495 if(itr
->item
&& itr
->item
->GetEnchantmentId(slot
))
11497 // remove from stats
11498 ApplyEnchantment(itr
->item
,slot
,false,false);
11500 itr
->item
->ClearEnchantment(slot
);
11502 // remove from update list
11503 next
= m_enchantDuration
.erase(itr
);
11509 // remove enchants from inventory items
11510 // NOTE: no need to remove these from stats, since these aren't equipped
11512 for(int i
= INVENTORY_SLOT_ITEM_START
; i
< INVENTORY_SLOT_ITEM_END
; i
++)
11514 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
11515 if( pItem
&& pItem
->GetEnchantmentId(slot
) )
11516 pItem
->ClearEnchantment(slot
);
11519 // in inventory bags
11520 for(int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
; i
++)
11522 Bag
* pBag
= (Bag
*)GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
11525 for(uint32 j
= 0; j
< pBag
->GetBagSize(); j
++)
11527 Item
* pItem
= pBag
->GetItemByPos(j
);
11528 if( pItem
&& pItem
->GetEnchantmentId(slot
) )
11529 pItem
->ClearEnchantment(slot
);
11535 // duration == 0 will remove item enchant
11536 void Player::AddEnchantmentDuration(Item
*item
,EnchantmentSlot slot
,uint32 duration
)
11541 if(slot
>= MAX_ENCHANTMENT_SLOT
)
11544 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin();itr
!= m_enchantDuration
.end();++itr
)
11546 if(itr
->item
== item
&& itr
->slot
== slot
)
11548 itr
->item
->SetEnchantmentDuration(itr
->slot
,itr
->leftduration
);
11549 m_enchantDuration
.erase(itr
);
11553 if(item
&& duration
> 0 )
11555 GetSession()->SendItemEnchantTimeUpdate(GetGUID(), item
->GetGUID(),slot
,uint32(duration
/1000));
11556 m_enchantDuration
.push_back(EnchantDuration(item
,slot
,duration
));
11560 void Player::ApplyEnchantment(Item
*item
,bool apply
)
11562 for(uint32 slot
= 0; slot
< MAX_ENCHANTMENT_SLOT
; ++slot
)
11563 ApplyEnchantment(item
, EnchantmentSlot(slot
), apply
);
11566 void Player::ApplyEnchantment(Item
*item
,EnchantmentSlot slot
,bool apply
, bool apply_dur
, bool ignore_condition
)
11571 if(!item
->IsEquipped())
11574 if(slot
>= MAX_ENCHANTMENT_SLOT
)
11577 uint32 enchant_id
= item
->GetEnchantmentId(slot
);
11581 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
11585 if(!ignore_condition
&& pEnchant
->EnchantmentCondition
&& !((Player
*)this)->EnchantmentFitsRequirements(pEnchant
->EnchantmentCondition
, -1))
11588 for (int s
=0; s
<3; s
++)
11590 uint32 enchant_display_type
= pEnchant
->type
[s
];
11591 uint32 enchant_amount
= pEnchant
->amount
[s
];
11592 uint32 enchant_spell_id
= pEnchant
->spellid
[s
];
11594 switch(enchant_display_type
)
11596 case ITEM_ENCHANTMENT_TYPE_NONE
:
11598 case ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL
:
11599 // processed in Player::CastItemCombatSpell
11601 case ITEM_ENCHANTMENT_TYPE_DAMAGE
:
11602 if (item
->GetSlot() == EQUIPMENT_SLOT_MAINHAND
)
11603 HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11604 else if (item
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
11605 HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11606 else if (item
->GetSlot() == EQUIPMENT_SLOT_RANGED
)
11607 HandleStatModifier(UNIT_MOD_DAMAGE_RANGED
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11609 case ITEM_ENCHANTMENT_TYPE_EQUIP_SPELL
:
11610 if(enchant_spell_id
)
11614 int32 basepoints
= int32(enchant_amount
);
11615 // Random Property Exist - try found basepoints for spell (basepoints depends from item suffix factor)
11616 if (item
->GetItemRandomPropertyId() !=0 && !enchant_amount
)
11618 ItemRandomSuffixEntry
const *item_rand
= sItemRandomSuffixStore
.LookupEntry(abs(item
->GetItemRandomPropertyId()));
11621 // Search enchant_amount
11622 for (int k
=0; k
<3; k
++)
11624 if(item_rand
->enchant_id
[k
] == enchant_id
)
11626 basepoints
= int32((item_rand
->prefix
[k
]*item
->GetItemSuffixFactor()) / 10000 );
11632 // Cast custom spell vs all equal basepoints getted from enchant_amount
11634 CastCustomSpell(this,enchant_spell_id
,&basepoints
,&basepoints
,&basepoints
,true,item
);
11636 CastSpell(this,enchant_spell_id
,true,item
);
11639 RemoveAurasDueToItemSpell(item
,enchant_spell_id
);
11642 case ITEM_ENCHANTMENT_TYPE_RESISTANCE
:
11643 if (!enchant_amount
)
11645 ItemRandomSuffixEntry
const *item_rand
= sItemRandomSuffixStore
.LookupEntry(abs(item
->GetItemRandomPropertyId()));
11648 for (int k
=0; k
<3; k
++)
11650 if(item_rand
->enchant_id
[k
] == enchant_id
)
11652 enchant_amount
= uint32((item_rand
->prefix
[k
]*item
->GetItemSuffixFactor()) / 10000 );
11659 HandleStatModifier(UnitMods(UNIT_MOD_RESISTANCE_START
+ enchant_spell_id
), TOTAL_VALUE
, float(enchant_amount
), apply
);
11661 case ITEM_ENCHANTMENT_TYPE_STAT
:
11663 if (!enchant_amount
)
11665 ItemRandomSuffixEntry
const *item_rand_suffix
= sItemRandomSuffixStore
.LookupEntry(abs(item
->GetItemRandomPropertyId()));
11666 if(item_rand_suffix
)
11668 for (int k
=0; k
<3; k
++)
11670 if(item_rand_suffix
->enchant_id
[k
] == enchant_id
)
11672 enchant_amount
= uint32((item_rand_suffix
->prefix
[k
]*item
->GetItemSuffixFactor()) / 10000 );
11679 sLog
.outDebug("Adding %u to stat nb %u",enchant_amount
,enchant_spell_id
);
11680 switch (enchant_spell_id
)
11682 case ITEM_MOD_AGILITY
:
11683 sLog
.outDebug("+ %u AGILITY",enchant_amount
);
11684 HandleStatModifier(UNIT_MOD_STAT_AGILITY
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11685 ApplyStatBuffMod(STAT_AGILITY
, enchant_amount
, apply
);
11687 case ITEM_MOD_STRENGTH
:
11688 sLog
.outDebug("+ %u STRENGTH",enchant_amount
);
11689 HandleStatModifier(UNIT_MOD_STAT_STRENGTH
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11690 ApplyStatBuffMod(STAT_STRENGTH
, enchant_amount
, apply
);
11692 case ITEM_MOD_INTELLECT
:
11693 sLog
.outDebug("+ %u INTELLECT",enchant_amount
);
11694 HandleStatModifier(UNIT_MOD_STAT_INTELLECT
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11695 ApplyStatBuffMod(STAT_INTELLECT
, enchant_amount
, apply
);
11697 case ITEM_MOD_SPIRIT
:
11698 sLog
.outDebug("+ %u SPIRIT",enchant_amount
);
11699 HandleStatModifier(UNIT_MOD_STAT_SPIRIT
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11700 ApplyStatBuffMod(STAT_SPIRIT
, enchant_amount
, apply
);
11702 case ITEM_MOD_STAMINA
:
11703 sLog
.outDebug("+ %u STAMINA",enchant_amount
);
11704 HandleStatModifier(UNIT_MOD_STAT_STAMINA
, TOTAL_VALUE
, float(enchant_amount
), apply
);
11705 ApplyStatBuffMod(STAT_STAMINA
, enchant_amount
, apply
);
11707 case ITEM_MOD_DEFENSE_SKILL_RATING
:
11708 ((Player
*)this)->ApplyRatingMod(CR_DEFENSE_SKILL
, enchant_amount
, apply
);
11709 sLog
.outDebug("+ %u DEFENCE", enchant_amount
);
11711 case ITEM_MOD_DODGE_RATING
:
11712 ((Player
*)this)->ApplyRatingMod(CR_DODGE
, enchant_amount
, apply
);
11713 sLog
.outDebug("+ %u DODGE", enchant_amount
);
11715 case ITEM_MOD_PARRY_RATING
:
11716 ((Player
*)this)->ApplyRatingMod(CR_PARRY
, enchant_amount
, apply
);
11717 sLog
.outDebug("+ %u PARRY", enchant_amount
);
11719 case ITEM_MOD_BLOCK_RATING
:
11720 ((Player
*)this)->ApplyRatingMod(CR_BLOCK
, enchant_amount
, apply
);
11721 sLog
.outDebug("+ %u SHIELD_BLOCK", enchant_amount
);
11723 case ITEM_MOD_HIT_MELEE_RATING
:
11724 ((Player
*)this)->ApplyRatingMod(CR_HIT_MELEE
, enchant_amount
, apply
);
11725 sLog
.outDebug("+ %u MELEE_HIT", enchant_amount
);
11727 case ITEM_MOD_HIT_RANGED_RATING
:
11728 ((Player
*)this)->ApplyRatingMod(CR_HIT_RANGED
, enchant_amount
, apply
);
11729 sLog
.outDebug("+ %u RANGED_HIT", enchant_amount
);
11731 case ITEM_MOD_HIT_SPELL_RATING
:
11732 ((Player
*)this)->ApplyRatingMod(CR_HIT_SPELL
, enchant_amount
, apply
);
11733 sLog
.outDebug("+ %u SPELL_HIT", enchant_amount
);
11735 case ITEM_MOD_CRIT_MELEE_RATING
:
11736 ((Player
*)this)->ApplyRatingMod(CR_CRIT_MELEE
, enchant_amount
, apply
);
11737 sLog
.outDebug("+ %u MELEE_CRIT", enchant_amount
);
11739 case ITEM_MOD_CRIT_RANGED_RATING
:
11740 ((Player
*)this)->ApplyRatingMod(CR_CRIT_RANGED
, enchant_amount
, apply
);
11741 sLog
.outDebug("+ %u RANGED_CRIT", enchant_amount
);
11743 case ITEM_MOD_CRIT_SPELL_RATING
:
11744 ((Player
*)this)->ApplyRatingMod(CR_CRIT_SPELL
, enchant_amount
, apply
);
11745 sLog
.outDebug("+ %u SPELL_CRIT", enchant_amount
);
11747 // Values from ITEM_STAT_MELEE_HA_RATING to ITEM_MOD_HASTE_RANGED_RATING are never used
11749 // case ITEM_MOD_HIT_TAKEN_MELEE_RATING:
11750 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_MELEE, enchant_amount, apply);
11752 // case ITEM_MOD_HIT_TAKEN_RANGED_RATING:
11753 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_RANGED, enchant_amount, apply);
11755 // case ITEM_MOD_HIT_TAKEN_SPELL_RATING:
11756 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_SPELL, enchant_amount, apply);
11758 // case ITEM_MOD_CRIT_TAKEN_MELEE_RATING:
11759 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply);
11761 // case ITEM_MOD_CRIT_TAKEN_RANGED_RATING:
11762 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply);
11764 // case ITEM_MOD_CRIT_TAKEN_SPELL_RATING:
11765 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply);
11767 // case ITEM_MOD_HASTE_MELEE_RATING:
11768 // ((Player*)this)->ApplyRatingMod(CR_HASTE_MELEE, enchant_amount, apply);
11770 // case ITEM_MOD_HASTE_RANGED_RATING:
11771 // ((Player*)this)->ApplyRatingMod(CR_HASTE_RANGED, enchant_amount, apply);
11773 case ITEM_MOD_HASTE_SPELL_RATING
:
11774 ((Player
*)this)->ApplyRatingMod(CR_HASTE_SPELL
, enchant_amount
, apply
);
11776 case ITEM_MOD_HIT_RATING
:
11777 ((Player
*)this)->ApplyRatingMod(CR_HIT_MELEE
, enchant_amount
, apply
);
11778 ((Player
*)this)->ApplyRatingMod(CR_HIT_RANGED
, enchant_amount
, apply
);
11779 ((Player
*)this)->ApplyRatingMod(CR_HIT_SPELL
, enchant_amount
, apply
);
11780 sLog
.outDebug("+ %u HIT", enchant_amount
);
11782 case ITEM_MOD_CRIT_RATING
:
11783 ((Player
*)this)->ApplyRatingMod(CR_CRIT_MELEE
, enchant_amount
, apply
);
11784 ((Player
*)this)->ApplyRatingMod(CR_CRIT_RANGED
, enchant_amount
, apply
);
11785 ((Player
*)this)->ApplyRatingMod(CR_CRIT_SPELL
, enchant_amount
, apply
);
11786 sLog
.outDebug("+ %u CRITICAL", enchant_amount
);
11788 // Values ITEM_MOD_HIT_TAKEN_RATING and ITEM_MOD_CRIT_TAKEN_RATING are never used in Enchantment
11789 // case ITEM_MOD_HIT_TAKEN_RATING:
11790 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_MELEE, enchant_amount, apply);
11791 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_RANGED, enchant_amount, apply);
11792 // ((Player*)this)->ApplyRatingMod(CR_HIT_TAKEN_SPELL, enchant_amount, apply);
11794 // case ITEM_MOD_CRIT_TAKEN_RATING:
11795 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_MELEE, enchant_amount, apply);
11796 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_RANGED, enchant_amount, apply);
11797 // ((Player*)this)->ApplyRatingMod(CR_CRIT_TAKEN_SPELL, enchant_amount, apply);
11799 case ITEM_MOD_RESILIENCE_RATING
:
11800 ((Player
*)this)->ApplyRatingMod(CR_CRIT_TAKEN_MELEE
, enchant_amount
, apply
);
11801 ((Player
*)this)->ApplyRatingMod(CR_CRIT_TAKEN_RANGED
, enchant_amount
, apply
);
11802 ((Player
*)this)->ApplyRatingMod(CR_CRIT_TAKEN_SPELL
, enchant_amount
, apply
);
11803 sLog
.outDebug("+ %u RESILIENCE", enchant_amount
);
11805 case ITEM_MOD_HASTE_RATING
:
11806 ((Player
*)this)->ApplyRatingMod(CR_HASTE_MELEE
, enchant_amount
, apply
);
11807 ((Player
*)this)->ApplyRatingMod(CR_HASTE_RANGED
, enchant_amount
, apply
);
11808 ((Player
*)this)->ApplyRatingMod(CR_HASTE_SPELL
, enchant_amount
, apply
);
11809 sLog
.outDebug("+ %u HASTE", enchant_amount
);
11811 case ITEM_MOD_EXPERTISE_RATING
:
11812 ((Player
*)this)->ApplyRatingMod(CR_EXPERTISE
, enchant_amount
, apply
);
11813 sLog
.outDebug("+ %u EXPERTISE", enchant_amount
);
11815 case ITEM_MOD_ARMOR_PENETRATION_RATING
:
11816 ((Player
*)this)->ApplyRatingMod(CR_ARMOR_PENETRATION
, enchant_amount
, apply
);
11817 sLog
.outDebug("+ %u ARMOR PENETRATION", enchant_amount
);
11824 case ITEM_ENCHANTMENT_TYPE_TOTEM
: // Shaman Rockbiter Weapon
11826 if(getClass() == CLASS_SHAMAN
)
11828 float addValue
= 0.0f
;
11829 if(item
->GetSlot() == EQUIPMENT_SLOT_MAINHAND
)
11831 addValue
= float(enchant_amount
* item
->GetProto()->Delay
/1000.0f
);
11832 HandleStatModifier(UNIT_MOD_DAMAGE_MAINHAND
, TOTAL_VALUE
, addValue
, apply
);
11834 else if(item
->GetSlot() == EQUIPMENT_SLOT_OFFHAND
)
11836 addValue
= float(enchant_amount
* item
->GetProto()->Delay
/1000.0f
);
11837 HandleStatModifier(UNIT_MOD_DAMAGE_OFFHAND
, TOTAL_VALUE
, addValue
, apply
);
11843 sLog
.outError("Unknown item enchantment display type: %d",enchant_display_type
);
11845 } /*switch(enchant_display_type)*/
11848 // visualize enchantment at player and equipped items
11849 if(slot
< MAX_INSPECTED_ENCHANTMENT_SLOT
)
11851 int VisibleBase
= PLAYER_VISIBLE_ITEM_1_0
+ (item
->GetSlot() * MAX_VISIBLE_ITEM_OFFSET
);
11852 SetUInt32Value(VisibleBase
+ 1 + slot
, apply
? item
->GetEnchantmentId(slot
) : 0);
11860 uint32 duration
= item
->GetEnchantmentDuration(slot
);
11862 AddEnchantmentDuration(item
,slot
,duration
);
11866 // duration == 0 will remove EnchantDuration
11867 AddEnchantmentDuration(item
,slot
,0);
11872 void Player::SendEnchantmentDurations()
11874 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin();itr
!= m_enchantDuration
.end();++itr
)
11876 GetSession()->SendItemEnchantTimeUpdate(GetGUID(), itr
->item
->GetGUID(),itr
->slot
,uint32(itr
->leftduration
)/1000);
11880 void Player::SendItemDurations()
11882 for(ItemDurationList::iterator itr
= m_itemDuration
.begin();itr
!= m_itemDuration
.end();++itr
)
11884 (*itr
)->SendTimeUpdate(this);
11888 void Player::SendNewItem(Item
*item
, uint32 count
, bool received
, bool created
, bool broadcast
)
11890 if(!item
) // prevent crash
11893 // last check 2.0.10
11894 WorldPacket
data( SMSG_ITEM_PUSH_RESULT
, (8+4+4+4+1+4+4+4+4+4) );
11895 data
<< GetGUID(); // player GUID
11896 data
<< uint32(received
); // 0=looted, 1=from npc
11897 data
<< uint32(created
); // 0=received, 1=created
11898 data
<< uint32(1); // always 0x01 (probably meant to be count of listed items)
11899 data
<< (uint8
)item
->GetBagSlot(); // bagslot
11900 // item slot, but when added to stack: 0xFFFFFFFF
11901 data
<< (uint32
) ((item
->GetCount()==count
) ? item
->GetSlot() : -1);
11902 data
<< uint32(item
->GetEntry()); // item id
11903 data
<< uint32(item
->GetItemSuffixFactor()); // SuffixFactor
11904 data
<< uint32(item
->GetItemRandomPropertyId()); // random item property id
11905 data
<< uint32(count
); // count of items
11906 data
<< GetItemCount(item
->GetEntry()); // count of items in inventory
11908 if (broadcast
&& GetGroup())
11909 GetGroup()->BroadcastPacket(&data
);
11911 GetSession()->SendPacket(&data
);
11914 /*********************************************************/
11915 /*** QUEST SYSTEM ***/
11916 /*********************************************************/
11918 void Player::PrepareQuestMenu( uint64 guid
)
11921 QuestRelations
* pObjectQR
;
11922 QuestRelations
* pObjectQIR
;
11923 Creature
*pCreature
= ObjectAccessor::GetCreature(*this, guid
);
11926 pObject
= (Object
*)pCreature
;
11927 pObjectQR
= &objmgr
.mCreatureQuestRelations
;
11928 pObjectQIR
= &objmgr
.mCreatureQuestInvolvedRelations
;
11932 GameObject
*pGameObject
= ObjectAccessor::GetGameObject(*this, guid
);
11935 pObject
= (Object
*)pGameObject
;
11936 pObjectQR
= &objmgr
.mGOQuestRelations
;
11937 pObjectQIR
= &objmgr
.mGOQuestInvolvedRelations
;
11943 QuestMenu
&qm
= PlayerTalkClass
->GetQuestMenu();
11946 for(QuestRelations::const_iterator i
= pObjectQIR
->lower_bound(pObject
->GetEntry()); i
!= pObjectQIR
->upper_bound(pObject
->GetEntry()); ++i
)
11948 uint32 quest_id
= i
->second
;
11949 QuestStatus status
= GetQuestStatus( quest_id
);
11950 if ( status
== QUEST_STATUS_COMPLETE
&& !GetQuestRewardStatus( quest_id
) )
11951 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_REWARD_REP
);
11952 else if ( status
== QUEST_STATUS_INCOMPLETE
)
11953 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_INCOMPLETE
);
11954 else if (status
== QUEST_STATUS_AVAILABLE
)
11955 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_CHAT
);
11958 for(QuestRelations::const_iterator i
= pObjectQR
->lower_bound(pObject
->GetEntry()); i
!= pObjectQR
->upper_bound(pObject
->GetEntry()); ++i
)
11960 uint32 quest_id
= i
->second
;
11961 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
11962 if(!pQuest
) continue;
11964 QuestStatus status
= GetQuestStatus( quest_id
);
11966 if (pQuest
->IsAutoComplete() && CanTakeQuest(pQuest
, false))
11967 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_REWARD_REP
);
11968 else if ( status
== QUEST_STATUS_NONE
&& CanTakeQuest( pQuest
, false ) )
11969 qm
.AddMenuItem(quest_id
, DIALOG_STATUS_AVAILABLE
);
11973 void Player::SendPreparedQuest( uint64 guid
)
11975 QuestMenu
& questMenu
= PlayerTalkClass
->GetQuestMenu();
11976 if( questMenu
.Empty() )
11979 QuestMenuItem
const& qmi0
= questMenu
.GetItem( 0 );
11981 uint32 status
= qmi0
.m_qIcon
;
11983 // single element case
11984 if ( questMenu
.MenuItemCount() == 1 )
11986 // Auto open -- maybe also should verify there is no greeting
11987 uint32 quest_id
= qmi0
.m_qId
;
11988 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
11991 if( status
== DIALOG_STATUS_REWARD_REP
&& !GetQuestRewardStatus( quest_id
) )
11992 PlayerTalkClass
->SendQuestGiverRequestItems( pQuest
, guid
, CanRewardQuest(pQuest
,false), true );
11993 else if( status
== DIALOG_STATUS_INCOMPLETE
)
11994 PlayerTalkClass
->SendQuestGiverRequestItems( pQuest
, guid
, false, true );
11995 // Send completable on repeatable quest if player don't have quest
11996 else if( pQuest
->IsRepeatable() && !pQuest
->IsDaily() )
11997 PlayerTalkClass
->SendQuestGiverRequestItems( pQuest
, guid
, CanCompleteRepeatableQuest(pQuest
), true );
11999 PlayerTalkClass
->SendQuestGiverQuestDetails( pQuest
, guid
, true );
12002 // multiply entries
12008 std::string title
= "";
12009 Creature
*pCreature
= ObjectAccessor::GetCreature(*this, guid
);
12012 uint32 textid
= pCreature
->GetNpcTextId();
12013 GossipText
* gossiptext
= objmgr
.GetGossipText(textid
);
12016 qe
._Delay
= 0; //TEXTEMOTE_MESSAGE; //zyg: player emote
12017 qe
._Emote
= 0; //TEXTEMOTE_HELLO; //zyg: NPC emote
12022 qe
= gossiptext
->Options
[0].Emotes
[0];
12024 if(!gossiptext
->Options
[0].Text_0
.empty())
12026 title
= gossiptext
->Options
[0].Text_0
;
12028 int loc_idx
= GetSession()->GetSessionDbLocaleIndex();
12031 NpcTextLocale
const *nl
= objmgr
.GetNpcTextLocale(textid
);
12034 if (nl
->Text_0
[0].size() > loc_idx
&& !nl
->Text_0
[0][loc_idx
].empty())
12035 title
= nl
->Text_0
[0][loc_idx
];
12041 title
= gossiptext
->Options
[0].Text_1
;
12043 int loc_idx
= GetSession()->GetSessionDbLocaleIndex();
12046 NpcTextLocale
const *nl
= objmgr
.GetNpcTextLocale(textid
);
12049 if (nl
->Text_1
[0].size() > loc_idx
&& !nl
->Text_1
[0][loc_idx
].empty())
12050 title
= nl
->Text_1
[0][loc_idx
];
12056 PlayerTalkClass
->SendQuestGiverQuestList( qe
, title
, guid
);
12060 bool Player::IsActiveQuest( uint32 quest_id
) const
12062 QuestStatusMap::const_iterator itr
= mQuestStatus
.find(quest_id
);
12064 return itr
!= mQuestStatus
.end() && itr
->second
.m_status
!= QUEST_STATUS_NONE
;
12067 Quest
const * Player::GetNextQuest( uint64 guid
, Quest
const *pQuest
)
12070 QuestRelations
* pObjectQR
;
12071 QuestRelations
* pObjectQIR
;
12073 Creature
*pCreature
= ObjectAccessor::GetCreature(*this, guid
);
12076 pObject
= (Object
*)pCreature
;
12077 pObjectQR
= &objmgr
.mCreatureQuestRelations
;
12078 pObjectQIR
= &objmgr
.mCreatureQuestInvolvedRelations
;
12082 GameObject
*pGameObject
= ObjectAccessor::GetGameObject(*this, guid
);
12085 pObject
= (Object
*)pGameObject
;
12086 pObjectQR
= &objmgr
.mGOQuestRelations
;
12087 pObjectQIR
= &objmgr
.mGOQuestInvolvedRelations
;
12093 uint32 nextQuestID
= pQuest
->GetNextQuestInChain();
12094 for(QuestRelations::const_iterator itr
= pObjectQR
->lower_bound(pObject
->GetEntry()); itr
!= pObjectQR
->upper_bound(pObject
->GetEntry()); ++itr
)
12096 if (itr
->second
== nextQuestID
)
12097 return objmgr
.GetQuestTemplate(nextQuestID
);
12103 bool Player::CanSeeStartQuest( Quest
const *pQuest
)
12105 if( SatisfyQuestRace( pQuest
, false ) && SatisfyQuestSkillOrClass( pQuest
, false ) &&
12106 SatisfyQuestExclusiveGroup( pQuest
, false ) && SatisfyQuestReputation( pQuest
, false ) &&
12107 SatisfyQuestPreviousQuest( pQuest
, false ) && SatisfyQuestNextChain( pQuest
, false ) &&
12108 SatisfyQuestPrevChain( pQuest
, false ) && SatisfyQuestDay( pQuest
, false ) )
12110 return getLevel() + sWorld
.getConfig(CONFIG_QUEST_HIGH_LEVEL_HIDE_DIFF
) >= pQuest
->GetMinLevel();
12116 bool Player::CanTakeQuest( Quest
const *pQuest
, bool msg
)
12118 return SatisfyQuestStatus( pQuest
, msg
) && SatisfyQuestExclusiveGroup( pQuest
, msg
)
12119 && SatisfyQuestRace( pQuest
, msg
) && SatisfyQuestLevel( pQuest
, msg
)
12120 && SatisfyQuestSkillOrClass( pQuest
, msg
) && SatisfyQuestReputation( pQuest
, msg
)
12121 && SatisfyQuestPreviousQuest( pQuest
, msg
) && SatisfyQuestTimed( pQuest
, msg
)
12122 && SatisfyQuestNextChain( pQuest
, msg
) && SatisfyQuestPrevChain( pQuest
, msg
)
12123 && SatisfyQuestDay( pQuest
, msg
);
12126 bool Player::CanAddQuest( Quest
const *pQuest
, bool msg
)
12128 if( !SatisfyQuestLog( msg
) )
12131 uint32 srcitem
= pQuest
->GetSrcItemId();
12134 uint32 count
= pQuest
->GetSrcItemCount();
12135 ItemPosCountVec dest
;
12136 uint8 msg
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, srcitem
, count
);
12138 // player already have max number (in most case 1) source item, no additional item needed and quest can be added.
12139 if( msg
== EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
)
12141 else if( msg
!= EQUIP_ERR_OK
)
12143 SendEquipError( msg
, NULL
, NULL
);
12150 bool Player::CanCompleteQuest( uint32 quest_id
)
12154 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
12155 if( q_status
.m_status
== QUEST_STATUS_COMPLETE
)
12156 return false; // not allow re-complete quest
12158 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
12163 // auto complete quest
12164 if (qInfo
->IsAutoComplete() && CanTakeQuest(qInfo
, false))
12167 if ( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
12170 if ( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
12172 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12174 if( qInfo
->ReqItemCount
[i
]!= 0 && q_status
.m_itemcount
[i
] < qInfo
->ReqItemCount
[i
] )
12179 if ( qInfo
->HasFlag(QUEST_MANGOS_FLAGS_KILL_OR_CAST
| QUEST_MANGOS_FLAGS_SPEAKTO
) )
12181 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12183 if( qInfo
->ReqCreatureOrGOId
[i
] == 0 )
12186 if( qInfo
->ReqCreatureOrGOCount
[i
] != 0 && q_status
.m_creatureOrGOcount
[i
] < qInfo
->ReqCreatureOrGOCount
[i
] )
12191 if ( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_EXPLORATION_OR_EVENT
) && !q_status
.m_explored
)
12194 if ( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_TIMED
) && q_status
.m_timer
== 0 )
12197 if ( qInfo
->GetRewOrReqMoney() < 0 )
12199 if ( GetMoney() < uint32(-qInfo
->GetRewOrReqMoney()) )
12203 uint32 repFacId
= qInfo
->GetRepObjectiveFaction();
12204 if ( repFacId
&& GetReputation(repFacId
) < qInfo
->GetRepObjectiveValue() )
12213 bool Player::CanCompleteRepeatableQuest( Quest
const *pQuest
)
12215 // Solve problem that player don't have the quest and try complete it.
12216 // if repeatable she must be able to complete event if player don't have it.
12217 // Seem that all repeatable quest are DELIVER Flag so, no need to add more.
12218 if( !CanTakeQuest(pQuest
, false) )
12221 if (pQuest
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
12222 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12223 if( pQuest
->ReqItemId
[i
] && pQuest
->ReqItemCount
[i
] && !HasItemCount(pQuest
->ReqItemId
[i
],pQuest
->ReqItemCount
[i
]) )
12226 if( !CanRewardQuest(pQuest
, false) )
12232 bool Player::CanRewardQuest( Quest
const *pQuest
, bool msg
)
12234 // not auto complete quest and not completed quest (only cheating case, then ignore without message)
12235 if(!pQuest
->IsAutoComplete() && GetQuestStatus(pQuest
->GetQuestId()) != QUEST_STATUS_COMPLETE
)
12238 // daily quest can't be rewarded (25 daily quest already completed)
12239 if(!SatisfyQuestDay(pQuest
,true))
12242 // rewarded and not repeatable quest (only cheating case, then ignore without message)
12243 if(GetQuestRewardStatus(pQuest
->GetQuestId()))
12246 // prevent receive reward with quest items in bank
12247 if ( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
12249 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12251 if( pQuest
->ReqItemCount
[i
]!= 0 &&
12252 GetItemCount(pQuest
->ReqItemId
[i
]) < pQuest
->ReqItemCount
[i
] )
12255 SendEquipError( EQUIP_ERR_ITEM_NOT_FOUND
, NULL
, NULL
);
12261 // prevent receive reward with low money and GetRewOrReqMoney() < 0
12262 if(pQuest
->GetRewOrReqMoney() < 0 && GetMoney() < uint32(-pQuest
->GetRewOrReqMoney()) )
12268 bool Player::CanRewardQuest( Quest
const *pQuest
, uint32 reward
, bool msg
)
12270 // prevent receive reward with quest items in bank or for not completed quest
12271 if(!CanRewardQuest(pQuest
,msg
))
12274 if ( pQuest
->GetRewChoiceItemsCount() > 0 )
12276 if( pQuest
->RewChoiceItemId
[reward
] )
12278 ItemPosCountVec dest
;
12279 uint8 res
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pQuest
->RewChoiceItemId
[reward
], pQuest
->RewChoiceItemCount
[reward
] );
12280 if( res
!= EQUIP_ERR_OK
)
12282 SendEquipError( res
, NULL
, NULL
);
12288 if ( pQuest
->GetRewItemsCount() > 0 )
12290 for (uint32 i
= 0; i
< pQuest
->GetRewItemsCount(); ++i
)
12292 if( pQuest
->RewItemId
[i
] )
12294 ItemPosCountVec dest
;
12295 uint8 res
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pQuest
->RewItemId
[i
], pQuest
->RewItemCount
[i
] );
12296 if( res
!= EQUIP_ERR_OK
)
12298 SendEquipError( res
, NULL
, NULL
);
12308 void Player::AddQuest( Quest
const *pQuest
, Object
*questGiver
)
12310 uint16 log_slot
= FindQuestSlot( 0 );
12311 assert(log_slot
< MAX_QUEST_LOG_SIZE
);
12313 uint32 quest_id
= pQuest
->GetQuestId();
12315 // if not exist then created with set uState==NEW and rewarded=false
12316 QuestStatusData
& questStatusData
= mQuestStatus
[quest_id
];
12317 if (questStatusData
.uState
!= QUEST_NEW
)
12318 questStatusData
.uState
= QUEST_CHANGED
;
12320 // check for repeatable quests status reset
12321 questStatusData
.m_status
= QUEST_STATUS_INCOMPLETE
;
12322 questStatusData
.m_explored
= false;
12324 if ( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
12326 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12327 questStatusData
.m_itemcount
[i
] = 0;
12330 if ( pQuest
->HasFlag(QUEST_MANGOS_FLAGS_KILL_OR_CAST
| QUEST_MANGOS_FLAGS_SPEAKTO
) )
12332 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
12333 questStatusData
.m_creatureOrGOcount
[i
] = 0;
12336 GiveQuestSourceItem( pQuest
);
12337 AdjustQuestReqItemCount( pQuest
);
12339 if( pQuest
->GetRepObjectiveFaction() )
12340 SetFactionVisibleForFactionId(pQuest
->GetRepObjectiveFaction());
12343 if( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_TIMED
) )
12345 uint32 limittime
= pQuest
->GetLimitTime();
12347 // shared timed quest
12348 if(questGiver
&& questGiver
->GetTypeId()==TYPEID_PLAYER
)
12349 limittime
= ((Player
*)questGiver
)->getQuestStatusMap()[quest_id
].m_timer
/ 1000;
12351 AddTimedQuest( quest_id
);
12352 questStatusData
.m_timer
= limittime
* 1000;
12353 qtime
= static_cast<uint32
>(time(NULL
)) + limittime
;
12356 questStatusData
.m_timer
= 0;
12358 SetQuestSlot(log_slot
, quest_id
, qtime
);
12360 //starting initial quest script
12361 if(questGiver
&& pQuest
->GetQuestStartScript()!=0)
12362 sWorld
.ScriptsStart(sQuestStartScripts
, pQuest
->GetQuestStartScript(), questGiver
, this);
12364 UpdateForQuestsGO();
12367 void Player::CompleteQuest( uint32 quest_id
)
12371 SetQuestStatus( quest_id
, QUEST_STATUS_COMPLETE
);
12373 uint16 log_slot
= FindQuestSlot( quest_id
);
12374 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12375 SetQuestSlotState(log_slot
,QUEST_STATE_COMPLETE
);
12377 if(Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
))
12379 if( qInfo
->HasFlag(QUEST_FLAGS_AUTO_REWARDED
) )
12380 RewardQuest(qInfo
,0,this,false);
12382 SendQuestComplete( quest_id
);
12387 void Player::IncompleteQuest( uint32 quest_id
)
12391 SetQuestStatus( quest_id
, QUEST_STATUS_INCOMPLETE
);
12393 uint16 log_slot
= FindQuestSlot( quest_id
);
12394 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12395 RemoveQuestSlotState(log_slot
,QUEST_STATE_COMPLETE
);
12399 void Player::RewardQuest( Quest
const *pQuest
, uint32 reward
, Object
* questGiver
, bool announce
)
12401 uint32 quest_id
= pQuest
->GetQuestId();
12403 for (int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++ )
12405 if ( pQuest
->ReqItemId
[i
] )
12406 DestroyItemCount( pQuest
->ReqItemId
[i
], pQuest
->ReqItemCount
[i
], true);
12409 //if( qInfo->HasSpecialFlag( QUEST_FLAGS_TIMED ) )
12410 // SetTimedQuest( 0 );
12411 m_timedquests
.erase(pQuest
->GetQuestId());
12413 if ( pQuest
->GetRewChoiceItemsCount() > 0 )
12415 if( pQuest
->RewChoiceItemId
[reward
] )
12417 ItemPosCountVec dest
;
12418 if( CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pQuest
->RewChoiceItemId
[reward
], pQuest
->RewChoiceItemCount
[reward
] ) == EQUIP_ERR_OK
)
12420 Item
* item
= StoreNewItem( dest
, pQuest
->RewChoiceItemId
[reward
], true);
12421 SendNewItem(item
, pQuest
->RewChoiceItemCount
[reward
], true, false);
12426 if ( pQuest
->GetRewItemsCount() > 0 )
12428 for (uint32 i
=0; i
< pQuest
->GetRewItemsCount(); ++i
)
12430 if( pQuest
->RewItemId
[i
] )
12432 ItemPosCountVec dest
;
12433 if( CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pQuest
->RewItemId
[i
], pQuest
->RewItemCount
[i
] ) == EQUIP_ERR_OK
)
12435 Item
* item
= StoreNewItem( dest
, pQuest
->RewItemId
[i
], true);
12436 SendNewItem(item
, pQuest
->RewItemCount
[i
], true, false);
12442 RewardReputation( pQuest
);
12444 if( pQuest
->GetRewSpellCast() > 0 )
12445 CastSpell( this, pQuest
->GetRewSpellCast(), true);
12446 else if( pQuest
->GetRewSpell() > 0)
12447 CastSpell( this, pQuest
->GetRewSpell(), true);
12449 uint16 log_slot
= FindQuestSlot( quest_id
);
12450 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12451 SetQuestSlot(log_slot
,0);
12453 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
12455 // Not give XP in case already completed once repeatable quest
12456 uint32 XP
= q_status
.m_rewarded
? 0 : uint32(pQuest
->XPValue( this )*sWorld
.getRate(RATE_XP_QUEST
));
12458 if ( getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) )
12459 GiveXP( XP
, NULL
);
12461 ModifyMoney( int32(pQuest
->GetRewMoneyMaxLevel() * sWorld
.getRate(RATE_DROP_MONEY
)) );
12463 // Give player extra money if GetRewOrReqMoney > 0 and get ReqMoney if negative
12464 ModifyMoney( pQuest
->GetRewOrReqMoney() );
12467 if(pQuest
->GetRewHonorableKills())
12468 RewardHonor(NULL
, 0, MaNGOS::Honor::hk_honor_at_level(getLevel(), pQuest
->GetRewHonorableKills()));
12471 if(pQuest
->GetCharTitleId())
12473 if(CharTitlesEntry
const* titleEntry
= sCharTitlesStore
.LookupEntry(pQuest
->GetCharTitleId()))
12474 SetTitle(titleEntry
);
12477 // Send reward mail
12478 if(pQuest
->GetRewMailTemplateId())
12480 MailMessageType mailType
;
12481 uint32 senderGuidOrEntry
;
12482 switch(questGiver
->GetTypeId())
12485 mailType
= MAIL_CREATURE
;
12486 senderGuidOrEntry
= questGiver
->GetEntry();
12488 case TYPEID_GAMEOBJECT
:
12489 mailType
= MAIL_GAMEOBJECT
;
12490 senderGuidOrEntry
= questGiver
->GetEntry();
12493 mailType
= MAIL_ITEM
;
12494 senderGuidOrEntry
= questGiver
->GetEntry();
12496 case TYPEID_PLAYER
:
12497 mailType
= MAIL_NORMAL
;
12498 senderGuidOrEntry
= questGiver
->GetGUIDLow();
12501 mailType
= MAIL_NORMAL
;
12502 senderGuidOrEntry
= GetGUIDLow();
12506 Loot questMailLoot
;
12508 questMailLoot
.FillLoot(pQuest
->GetQuestId(), LootTemplates_QuestMail
, this);
12511 MailItemsInfo mi
; // item list preparing
12513 for(size_t i
= 0; mi
.size() < MAX_MAIL_ITEMS
&& i
< questMailLoot
.items
.size(); ++i
)
12515 if(LootItem
* lootitem
= questMailLoot
.LootItemInSlot(i
,this))
12517 if(Item
* item
= Item::CreateItem(lootitem
->itemid
,lootitem
->count
,this))
12519 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
12520 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
12525 for(size_t i
= 0; mi
.size() < MAX_MAIL_ITEMS
&& i
< questMailLoot
.quest_items
.size(); ++i
)
12527 if(LootItem
* lootitem
= questMailLoot
.LootItemInSlot(i
+questMailLoot
.items
.size(),this))
12529 if(Item
* item
= Item::CreateItem(lootitem
->itemid
,lootitem
->count
,this))
12531 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
12532 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
12537 WorldSession::SendMailTo(this, mailType
, MAIL_STATIONERY_NORMAL
, senderGuidOrEntry
, GetGUIDLow(), "", 0, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
,pQuest
->GetRewMailDelaySecs(),pQuest
->GetRewMailTemplateId());
12540 if(pQuest
->IsDaily())
12542 SetDailyQuestStatus(quest_id
);
12543 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_DAILY_QUEST
, 1);
12546 if ( !pQuest
->IsRepeatable() )
12547 SetQuestStatus(quest_id
, QUEST_STATUS_COMPLETE
);
12549 SetQuestStatus(quest_id
, QUEST_STATUS_NONE
);
12551 q_status
.m_rewarded
= true;
12554 SendQuestReward( pQuest
, XP
, questGiver
);
12556 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
12557 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST_COUNT
);
12558 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST
);
12561 void Player::FailQuest( uint32 quest_id
)
12565 IncompleteQuest( quest_id
);
12567 uint16 log_slot
= FindQuestSlot( quest_id
);
12568 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12570 SetQuestSlotTimer(log_slot
, 1 );
12571 SetQuestSlotState(log_slot
,QUEST_STATE_FAIL
);
12573 SendQuestFailed( quest_id
);
12577 void Player::FailTimedQuest( uint32 quest_id
)
12581 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
12583 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
12584 q_status
.m_timer
= 0;
12586 IncompleteQuest( quest_id
);
12588 uint16 log_slot
= FindQuestSlot( quest_id
);
12589 if( log_slot
< MAX_QUEST_LOG_SIZE
)
12591 SetQuestSlotTimer(log_slot
, 1 );
12592 SetQuestSlotState(log_slot
,QUEST_STATE_FAIL
);
12594 SendQuestTimerFailed( quest_id
);
12598 bool Player::SatisfyQuestSkillOrClass( Quest
const* qInfo
, bool msg
)
12600 int32 zoneOrSort
= qInfo
->GetZoneOrSort();
12601 int32 skillOrClass
= qInfo
->GetSkillOrClass();
12603 // skip zone zoneOrSort and 0 case skillOrClass
12604 if( zoneOrSort
>= 0 && skillOrClass
== 0 )
12607 int32 questSort
= -zoneOrSort
;
12608 uint8 reqSortClass
= ClassByQuestSort(questSort
);
12610 // check class sort cases in zoneOrSort
12611 if( reqSortClass
!= 0 && getClass() != reqSortClass
)
12614 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12619 if( skillOrClass
< 0 )
12621 uint8 reqClass
= -int32(skillOrClass
);
12622 if(getClass() != reqClass
)
12625 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12630 else if( skillOrClass
> 0 )
12632 uint32 reqSkill
= skillOrClass
;
12633 if( GetSkillValue( reqSkill
) < qInfo
->GetRequiredSkillValue() )
12636 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12644 bool Player::SatisfyQuestLevel( Quest
const* qInfo
, bool msg
)
12646 if( getLevel() < qInfo
->GetMinLevel() )
12649 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12655 bool Player::SatisfyQuestLog( bool msg
)
12658 if( FindQuestSlot(0) < MAX_QUEST_LOG_SIZE
)
12663 WorldPacket
data( SMSG_QUESTLOG_FULL
, 0 );
12664 GetSession()->SendPacket( &data
);
12665 sLog
.outDebug( "WORLD: Sent QUEST_LOG_FULL_MESSAGE" );
12670 bool Player::SatisfyQuestPreviousQuest( Quest
const* qInfo
, bool msg
)
12672 // No previous quest (might be first quest in a series)
12673 if( qInfo
->prevQuests
.empty())
12676 for(Quest::PrevQuests::const_iterator iter
= qInfo
->prevQuests
.begin(); iter
!= qInfo
->prevQuests
.end(); ++iter
)
12678 uint32 prevId
= abs(*iter
);
12680 QuestStatusMap::iterator i_prevstatus
= mQuestStatus
.find( prevId
);
12681 Quest
const* qPrevInfo
= objmgr
.GetQuestTemplate(prevId
);
12683 if( qPrevInfo
&& i_prevstatus
!= mQuestStatus
.end() )
12685 // If any of the positive previous quests completed, return true
12686 if( *iter
> 0 && i_prevstatus
->second
.m_rewarded
)
12688 // skip one-from-all exclusive group
12689 if(qPrevInfo
->GetExclusiveGroup() >= 0)
12692 // each-from-all exclusive group ( < 0)
12693 // can be start if only all quests in prev quest exclusive group completed and rewarded
12694 ObjectMgr::ExclusiveQuestGroups::iterator iter
= objmgr
.mExclusiveQuestGroups
.lower_bound(qPrevInfo
->GetExclusiveGroup());
12695 ObjectMgr::ExclusiveQuestGroups::iterator end
= objmgr
.mExclusiveQuestGroups
.upper_bound(qPrevInfo
->GetExclusiveGroup());
12697 assert(iter
!=end
); // always must be found if qPrevInfo->ExclusiveGroup != 0
12699 for(; iter
!= end
; ++iter
)
12701 uint32 exclude_Id
= iter
->second
;
12703 // skip checked quest id, only state of other quests in group is interesting
12704 if(exclude_Id
== prevId
)
12707 QuestStatusMap::iterator i_exstatus
= mQuestStatus
.find( exclude_Id
);
12709 // alternative quest from group also must be completed and rewarded(reported)
12710 if( i_exstatus
== mQuestStatus
.end() || !i_exstatus
->second
.m_rewarded
)
12713 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12719 // If any of the negative previous quests active, return true
12720 if( *iter
< 0 && (i_prevstatus
->second
.m_status
== QUEST_STATUS_INCOMPLETE
12721 || (i_prevstatus
->second
.m_status
== QUEST_STATUS_COMPLETE
&& !GetQuestRewardStatus(prevId
))))
12723 // skip one-from-all exclusive group
12724 if(qPrevInfo
->GetExclusiveGroup() >= 0)
12727 // each-from-all exclusive group ( < 0)
12728 // can be start if only all quests in prev quest exclusive group active
12729 ObjectMgr::ExclusiveQuestGroups::iterator iter
= objmgr
.mExclusiveQuestGroups
.lower_bound(qPrevInfo
->GetExclusiveGroup());
12730 ObjectMgr::ExclusiveQuestGroups::iterator end
= objmgr
.mExclusiveQuestGroups
.upper_bound(qPrevInfo
->GetExclusiveGroup());
12732 assert(iter
!=end
); // always must be found if qPrevInfo->ExclusiveGroup != 0
12734 for(; iter
!= end
; ++iter
)
12736 uint32 exclude_Id
= iter
->second
;
12738 // skip checked quest id, only state of other quests in group is interesting
12739 if(exclude_Id
== prevId
)
12742 QuestStatusMap::iterator i_exstatus
= mQuestStatus
.find( exclude_Id
);
12744 // alternative quest from group also must be active
12745 if( i_exstatus
== mQuestStatus
.end() ||
12746 i_exstatus
->second
.m_status
!= QUEST_STATUS_INCOMPLETE
&&
12747 (i_prevstatus
->second
.m_status
!= QUEST_STATUS_COMPLETE
|| GetQuestRewardStatus(prevId
)) )
12750 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12759 // Has only positive prev. quests in non-rewarded state
12760 // and negative prev. quests in non-active state
12762 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12767 bool Player::SatisfyQuestRace( Quest
const* qInfo
, bool msg
)
12769 uint32 reqraces
= qInfo
->GetRequiredRaces();
12770 if ( reqraces
== 0 )
12772 if( (reqraces
& getRaceMask()) == 0 )
12775 SendCanTakeQuestResponse( INVALIDREASON_QUEST_FAILED_WRONG_RACE
);
12781 bool Player::SatisfyQuestReputation( Quest
const* qInfo
, bool msg
)
12783 uint32 fIdMin
= qInfo
->GetRequiredMinRepFaction(); //Min required rep
12784 if(fIdMin
&& GetReputation(fIdMin
) < qInfo
->GetRequiredMinRepValue())
12787 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12791 uint32 fIdMax
= qInfo
->GetRequiredMaxRepFaction(); //Max required rep
12792 if(fIdMax
&& GetReputation(fIdMax
) >= qInfo
->GetRequiredMaxRepValue())
12795 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12802 bool Player::SatisfyQuestStatus( Quest
const* qInfo
, bool msg
)
12804 QuestStatusMap::iterator itr
= mQuestStatus
.find( qInfo
->GetQuestId() );
12805 if ( itr
!= mQuestStatus
.end() && itr
->second
.m_status
!= QUEST_STATUS_NONE
)
12808 SendCanTakeQuestResponse( INVALIDREASON_QUEST_ALREADY_ON
);
12814 bool Player::SatisfyQuestTimed( Quest
const* qInfo
, bool msg
)
12816 if ( (find(m_timedquests
.begin(), m_timedquests
.end(), qInfo
->GetQuestId()) != m_timedquests
.end()) && qInfo
->HasFlag(QUEST_MANGOS_FLAGS_TIMED
) )
12819 SendCanTakeQuestResponse( INVALIDREASON_QUEST_ONLY_ONE_TIMED
);
12825 bool Player::SatisfyQuestExclusiveGroup( Quest
const* qInfo
, bool msg
)
12827 // non positive exclusive group, if > 0 then can be start if any other quest in exclusive group already started/completed
12828 if(qInfo
->GetExclusiveGroup() <= 0)
12831 ObjectMgr::ExclusiveQuestGroups::iterator iter
= objmgr
.mExclusiveQuestGroups
.lower_bound(qInfo
->GetExclusiveGroup());
12832 ObjectMgr::ExclusiveQuestGroups::iterator end
= objmgr
.mExclusiveQuestGroups
.upper_bound(qInfo
->GetExclusiveGroup());
12834 assert(iter
!=end
); // always must be found if qInfo->ExclusiveGroup != 0
12836 for(; iter
!= end
; ++iter
)
12838 uint32 exclude_Id
= iter
->second
;
12840 // skip checked quest id, only state of other quests in group is interesting
12841 if(exclude_Id
== qInfo
->GetQuestId())
12844 // not allow have daily quest if daily quest from exclusive group already recently completed
12845 Quest
const* Nquest
= objmgr
.GetQuestTemplate(exclude_Id
);
12846 if( !SatisfyQuestDay(Nquest
, false) )
12849 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12853 QuestStatusMap::iterator i_exstatus
= mQuestStatus
.find( exclude_Id
);
12855 // alternative quest already started or completed
12856 if( i_exstatus
!= mQuestStatus
.end()
12857 && (i_exstatus
->second
.m_status
== QUEST_STATUS_COMPLETE
|| i_exstatus
->second
.m_status
== QUEST_STATUS_INCOMPLETE
) )
12860 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12867 bool Player::SatisfyQuestNextChain( Quest
const* qInfo
, bool msg
)
12869 if(!qInfo
->GetNextQuestInChain())
12872 // next quest in chain already started or completed
12873 QuestStatusMap::iterator itr
= mQuestStatus
.find( qInfo
->GetNextQuestInChain() );
12874 if( itr
!= mQuestStatus
.end()
12875 && (itr
->second
.m_status
== QUEST_STATUS_COMPLETE
|| itr
->second
.m_status
== QUEST_STATUS_INCOMPLETE
) )
12878 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12882 // check for all quests further up the chain
12883 // only necessary if there are quest chains with more than one quest that can be skipped
12884 //return SatisfyQuestNextChain( qInfo->GetNextQuestInChain(), msg );
12888 bool Player::SatisfyQuestPrevChain( Quest
const* qInfo
, bool msg
)
12890 // No previous quest in chain
12891 if( qInfo
->prevChainQuests
.empty())
12894 for(Quest::PrevChainQuests::const_iterator iter
= qInfo
->prevChainQuests
.begin(); iter
!= qInfo
->prevChainQuests
.end(); ++iter
)
12896 uint32 prevId
= *iter
;
12898 QuestStatusMap::iterator i_prevstatus
= mQuestStatus
.find( prevId
);
12900 if( i_prevstatus
!= mQuestStatus
.end() )
12902 // If any of the previous quests in chain active, return false
12903 if( i_prevstatus
->second
.m_status
== QUEST_STATUS_INCOMPLETE
12904 || (i_prevstatus
->second
.m_status
== QUEST_STATUS_COMPLETE
&& !GetQuestRewardStatus(prevId
)))
12907 SendCanTakeQuestResponse( INVALIDREASON_DONT_HAVE_REQ
);
12912 // check for all quests further down the chain
12913 // only necessary if there are quest chains with more than one quest that can be skipped
12914 //if( !SatisfyQuestPrevChain( prevId, msg ) )
12918 // No previous quest in chain active
12922 bool Player::SatisfyQuestDay( Quest
const* qInfo
, bool msg
)
12924 if(!qInfo
->IsDaily())
12927 bool have_slot
= false;
12928 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
12930 uint32 id
= GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
);
12931 if(qInfo
->GetQuestId()==id
)
12941 SendCanTakeQuestResponse( INVALIDREASON_DAILY_QUESTS_REMAINING
);
12948 bool Player::GiveQuestSourceItem( Quest
const *pQuest
)
12950 uint32 srcitem
= pQuest
->GetSrcItemId();
12953 uint32 count
= pQuest
->GetSrcItemCount();
12957 ItemPosCountVec dest
;
12958 uint8 msg
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, srcitem
, count
);
12959 if( msg
== EQUIP_ERR_OK
)
12961 Item
* item
= StoreNewItem(dest
, srcitem
, true);
12962 SendNewItem(item
, count
, true, false);
12965 // player already have max amount required item, just report success
12966 else if( msg
== EQUIP_ERR_CANT_CARRY_MORE_OF_THIS
)
12969 SendEquipError( msg
, NULL
, NULL
);
12976 bool Player::TakeQuestSourceItem( uint32 quest_id
, bool msg
)
12978 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
12981 uint32 srcitem
= qInfo
->GetSrcItemId();
12984 uint32 count
= qInfo
->GetSrcItemCount();
12988 // exist one case when destroy source quest item not possible:
12989 // non un-equippable item (equipped non-empty bag, for example)
12990 uint8 res
= CanUnequipItems(srcitem
,count
);
12991 if(res
!= EQUIP_ERR_OK
)
12994 SendEquipError( res
, NULL
, NULL
);
12998 DestroyItemCount(srcitem
, count
, true, true);
13004 bool Player::GetQuestRewardStatus( uint32 quest_id
) const
13006 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
13009 // for repeatable quests: rewarded field is set after first reward only to prevent getting XP more than once
13010 QuestStatusMap::const_iterator itr
= mQuestStatus
.find( quest_id
);
13011 if( itr
!= mQuestStatus
.end() && itr
->second
.m_status
!= QUEST_STATUS_NONE
13012 && !qInfo
->IsRepeatable() )
13013 return itr
->second
.m_rewarded
;
13020 QuestStatus
Player::GetQuestStatus( uint32 quest_id
) const
13024 QuestStatusMap::const_iterator itr
= mQuestStatus
.find( quest_id
);
13025 if( itr
!= mQuestStatus
.end() )
13026 return itr
->second
.m_status
;
13028 return QUEST_STATUS_NONE
;
13031 bool Player::CanShareQuest(uint32 quest_id
) const
13033 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
13034 if( qInfo
&& qInfo
->HasFlag(QUEST_FLAGS_SHARABLE
) )
13036 QuestStatusMap::const_iterator itr
= mQuestStatus
.find( quest_id
);
13037 if( itr
!= mQuestStatus
.end() )
13038 return itr
->second
.m_status
== QUEST_STATUS_NONE
|| itr
->second
.m_status
== QUEST_STATUS_INCOMPLETE
;
13043 void Player::SetQuestStatus( uint32 quest_id
, QuestStatus status
)
13045 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
13048 if( status
== QUEST_STATUS_NONE
|| status
== QUEST_STATUS_INCOMPLETE
|| status
== QUEST_STATUS_COMPLETE
)
13050 if( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_TIMED
) )
13051 m_timedquests
.erase(qInfo
->GetQuestId());
13054 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
13056 q_status
.m_status
= status
;
13057 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13060 UpdateForQuestsGO();
13063 // not used in MaNGOS, but used in scripting code
13064 uint32
Player::GetReqKillOrCastCurrentCount(uint32 quest_id
, int32 entry
)
13066 Quest
const* qInfo
= objmgr
.GetQuestTemplate(quest_id
);
13070 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13071 if ( qInfo
->ReqCreatureOrGOId
[j
] == entry
)
13072 return mQuestStatus
[quest_id
].m_creatureOrGOcount
[j
];
13077 void Player::AdjustQuestReqItemCount( Quest
const* pQuest
)
13079 if ( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
13081 for(int i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
13083 uint32 reqitemcount
= pQuest
->ReqItemCount
[i
];
13084 if( reqitemcount
!= 0 )
13086 uint32 quest_id
= pQuest
->GetQuestId();
13087 uint32 curitemcount
= GetItemCount(pQuest
->ReqItemId
[i
],true);
13089 QuestStatusData
& q_status
= mQuestStatus
[quest_id
];
13090 q_status
.m_itemcount
[i
] = std::min(curitemcount
, reqitemcount
);
13091 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13097 uint16
Player::FindQuestSlot( uint32 quest_id
) const
13099 for ( uint16 i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13100 if ( GetQuestSlotQuestId(i
) == quest_id
)
13103 return MAX_QUEST_LOG_SIZE
;
13106 void Player::AreaExploredOrEventHappens( uint32 questId
)
13110 uint16 log_slot
= FindQuestSlot( questId
);
13111 if( log_slot
< MAX_QUEST_LOG_SIZE
)
13113 QuestStatusData
& q_status
= mQuestStatus
[questId
];
13115 if(!q_status
.m_explored
)
13117 q_status
.m_explored
= true;
13118 if (q_status
.uState
!= QUEST_NEW
)
13119 q_status
.uState
= QUEST_CHANGED
;
13122 if( CanCompleteQuest( questId
) )
13123 CompleteQuest( questId
);
13127 //not used in mangosd, function for external script library
13128 void Player::GroupEventHappens( uint32 questId
, WorldObject
const* pEventObject
)
13130 if( Group
*pGroup
= GetGroup() )
13132 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
13134 Player
*pGroupGuy
= itr
->getSource();
13136 // for any leave or dead (with not released body) group member at appropriate distance
13137 if( pGroupGuy
&& pGroupGuy
->IsAtGroupRewardDistance(pEventObject
) && !pGroupGuy
->GetCorpse() )
13138 pGroupGuy
->AreaExploredOrEventHappens(questId
);
13142 AreaExploredOrEventHappens(questId
);
13145 void Player::ItemAddedQuestCheck( uint32 entry
, uint32 count
)
13147 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13149 uint32 questid
= GetQuestSlotQuestId(i
);
13150 if ( questid
== 0 )
13153 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13155 if ( q_status
.m_status
!= QUEST_STATUS_INCOMPLETE
)
13158 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13159 if( !qInfo
|| !qInfo
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
13162 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13164 uint32 reqitem
= qInfo
->ReqItemId
[j
];
13165 if ( reqitem
== entry
)
13167 uint32 reqitemcount
= qInfo
->ReqItemCount
[j
];
13168 uint32 curitemcount
= q_status
.m_itemcount
[j
];
13169 if ( curitemcount
< reqitemcount
)
13171 uint32 additemcount
= ( curitemcount
+ count
<= reqitemcount
? count
: reqitemcount
- curitemcount
);
13172 q_status
.m_itemcount
[j
] += additemcount
;
13173 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13175 SendQuestUpdateAddItem( qInfo
, j
, additemcount
);
13177 if ( CanCompleteQuest( questid
) )
13178 CompleteQuest( questid
);
13183 UpdateForQuestsGO();
13184 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM
, entry
);
13187 void Player::ItemRemovedQuestCheck( uint32 entry
, uint32 count
)
13189 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13191 uint32 questid
= GetQuestSlotQuestId(i
);
13194 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13197 if( !qInfo
->HasFlag( QUEST_MANGOS_FLAGS_DELIVER
) )
13200 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13202 uint32 reqitem
= qInfo
->ReqItemId
[j
];
13203 if ( reqitem
== entry
)
13205 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13207 uint32 reqitemcount
= qInfo
->ReqItemCount
[j
];
13208 uint32 curitemcount
;
13209 if( q_status
.m_status
!= QUEST_STATUS_COMPLETE
)
13210 curitemcount
= q_status
.m_itemcount
[j
];
13212 curitemcount
= GetItemCount(entry
,true);
13213 if ( curitemcount
< reqitemcount
+ count
)
13215 uint32 remitemcount
= ( curitemcount
<= reqitemcount
? count
: count
+ reqitemcount
- curitemcount
);
13216 q_status
.m_itemcount
[j
] = curitemcount
- remitemcount
;
13217 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13219 IncompleteQuest( questid
);
13225 UpdateForQuestsGO();
13228 void Player::KilledMonster( uint32 entry
, uint64 guid
)
13230 uint32 addkillcount
= 1;
13231 GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE
, entry
, addkillcount
);
13232 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13234 uint32 questid
= GetQuestSlotQuestId(i
);
13238 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13241 // just if !ingroup || !noraidgroup || raidgroup
13242 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13243 if( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
&& (!GetGroup() || !GetGroup()->isRaidGroup() || qInfo
->GetType() == QUEST_TYPE_RAID
))
13245 if( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_KILL_OR_CAST
) )
13247 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13249 // skip GO activate objective or none
13250 if(qInfo
->ReqCreatureOrGOId
[j
] <=0)
13253 // skip Cast at creature objective
13254 if(qInfo
->ReqSpell
[j
] !=0 )
13257 uint32 reqkill
= qInfo
->ReqCreatureOrGOId
[j
];
13259 if ( reqkill
== entry
)
13261 uint32 reqkillcount
= qInfo
->ReqCreatureOrGOCount
[j
];
13262 uint32 curkillcount
= q_status
.m_creatureOrGOcount
[j
];
13263 if ( curkillcount
< reqkillcount
)
13265 q_status
.m_creatureOrGOcount
[j
] = curkillcount
+ addkillcount
;
13266 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13268 SendQuestUpdateAddCreatureOrGo( qInfo
, guid
, j
, curkillcount
, addkillcount
);
13270 if ( CanCompleteQuest( questid
) )
13271 CompleteQuest( questid
);
13273 // same objective target can be in many active quests, but not in 2 objectives for single quest (code optimization).
13282 void Player::CastedCreatureOrGO( uint32 entry
, uint64 guid
, uint32 spell_id
)
13284 bool isCreature
= IS_CREATURE_GUID(guid
);
13286 uint32 addCastCount
= 1;
13287 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13289 uint32 questid
= GetQuestSlotQuestId(i
);
13293 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13297 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13299 if ( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
13301 if( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_KILL_OR_CAST
) )
13303 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13305 // skip kill creature objective (0) or wrong spell casts
13306 if(qInfo
->ReqSpell
[j
] != spell_id
)
13309 uint32 reqTarget
= 0;
13313 // creature activate objectives
13314 if(qInfo
->ReqCreatureOrGOId
[j
] > 0)
13315 // checked at quest_template loading
13316 reqTarget
= qInfo
->ReqCreatureOrGOId
[j
];
13320 // GO activate objective
13321 if(qInfo
->ReqCreatureOrGOId
[j
] < 0)
13322 // checked at quest_template loading
13323 reqTarget
= - qInfo
->ReqCreatureOrGOId
[j
];
13326 // other not this creature/GO related objectives
13327 if( reqTarget
!= entry
)
13330 uint32 reqCastCount
= qInfo
->ReqCreatureOrGOCount
[j
];
13331 uint32 curCastCount
= q_status
.m_creatureOrGOcount
[j
];
13332 if ( curCastCount
< reqCastCount
)
13334 q_status
.m_creatureOrGOcount
[j
] = curCastCount
+ addCastCount
;
13335 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13337 SendQuestUpdateAddCreatureOrGo( qInfo
, guid
, j
, curCastCount
, addCastCount
);
13340 if ( CanCompleteQuest( questid
) )
13341 CompleteQuest( questid
);
13343 // same objective target can be in many active quests, but not in 2 objectives for single quest (code optimization).
13351 void Player::TalkedToCreature( uint32 entry
, uint64 guid
)
13353 uint32 addTalkCount
= 1;
13354 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13356 uint32 questid
= GetQuestSlotQuestId(i
);
13360 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13364 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13366 if ( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
13368 if( qInfo
->HasFlag( QUEST_MANGOS_FLAGS_KILL_OR_CAST
| QUEST_MANGOS_FLAGS_SPEAKTO
) )
13370 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13372 // skip spell casts and Gameobject objectives
13373 if(qInfo
->ReqSpell
[j
] > 0 || qInfo
->ReqCreatureOrGOId
[j
] < 0)
13376 uint32 reqTarget
= 0;
13378 if(qInfo
->ReqCreatureOrGOId
[j
] > 0) // creature activate objectives
13379 // checked at quest_template loading
13380 reqTarget
= qInfo
->ReqCreatureOrGOId
[j
];
13384 if ( reqTarget
== entry
)
13386 uint32 reqTalkCount
= qInfo
->ReqCreatureOrGOCount
[j
];
13387 uint32 curTalkCount
= q_status
.m_creatureOrGOcount
[j
];
13388 if ( curTalkCount
< reqTalkCount
)
13390 q_status
.m_creatureOrGOcount
[j
] = curTalkCount
+ addTalkCount
;
13391 if (q_status
.uState
!= QUEST_NEW
) q_status
.uState
= QUEST_CHANGED
;
13393 SendQuestUpdateAddCreatureOrGo( qInfo
, guid
, j
, curTalkCount
, addTalkCount
);
13395 if ( CanCompleteQuest( questid
) )
13396 CompleteQuest( questid
);
13398 // same objective target can be in many active quests, but not in 2 objectives for single quest (code optimization).
13407 void Player::MoneyChanged( uint32 count
)
13409 for( int i
= 0; i
< MAX_QUEST_LOG_SIZE
; i
++ )
13411 uint32 questid
= GetQuestSlotQuestId(i
);
13415 Quest
const* qInfo
= objmgr
.GetQuestTemplate(questid
);
13416 if( qInfo
&& qInfo
->GetRewOrReqMoney() < 0 )
13418 QuestStatusData
& q_status
= mQuestStatus
[questid
];
13420 if( q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
13422 if(int32(count
) >= -qInfo
->GetRewOrReqMoney())
13424 if ( CanCompleteQuest( questid
) )
13425 CompleteQuest( questid
);
13428 else if( q_status
.m_status
== QUEST_STATUS_COMPLETE
)
13430 if(int32(count
) < -qInfo
->GetRewOrReqMoney())
13431 IncompleteQuest( questid
);
13437 bool Player::HasQuestForItem( uint32 itemid
) const
13439 for( QuestStatusMap::const_iterator i
= mQuestStatus
.begin( ); i
!= mQuestStatus
.end( ); ++i
)
13441 QuestStatusData
const& q_status
= i
->second
;
13443 if (q_status
.m_status
== QUEST_STATUS_INCOMPLETE
)
13445 Quest
const* qinfo
= objmgr
.GetQuestTemplate(i
->first
);
13449 // hide quest if player is in raid-group and quest is no raid quest
13450 if(GetGroup() && GetGroup()->isRaidGroup() && qinfo
->GetType() != QUEST_TYPE_RAID
)
13453 // There should be no mixed ReqItem/ReqSource drop
13454 // This part for ReqItem drop
13455 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
13457 if(itemid
== qinfo
->ReqItemId
[j
] && q_status
.m_itemcount
[j
] < qinfo
->ReqItemCount
[j
] )
13460 // This part - for ReqSource
13461 for (int j
= 0; j
< QUEST_SOURCE_ITEM_IDS_COUNT
; j
++)
13463 // examined item is a source item
13464 if (qinfo
->ReqSourceId
[j
] == itemid
&& qinfo
->ReqSourceRef
[j
] > 0 && qinfo
->ReqSourceRef
[j
] <= QUEST_OBJECTIVES_COUNT
)
13466 uint32 idx
= qinfo
->ReqSourceRef
[j
]-1;
13468 // total count of created ReqItems and SourceItems is less than ReqItemCount
13469 if(qinfo
->ReqItemId
[idx
] != 0 &&
13470 q_status
.m_itemcount
[idx
] * qinfo
->ReqSourceCount
[j
] + GetItemCount(itemid
,true) < qinfo
->ReqItemCount
[idx
] * qinfo
->ReqSourceCount
[j
])
13473 // total count of casted ReqCreatureOrGOs and SourceItems is less than ReqCreatureOrGOCount
13474 if (qinfo
->ReqCreatureOrGOId
[idx
] != 0)
13476 if(q_status
.m_creatureOrGOcount
[idx
] * qinfo
->ReqSourceCount
[j
] + GetItemCount(itemid
,true) < qinfo
->ReqCreatureOrGOCount
[idx
] * qinfo
->ReqSourceCount
[j
])
13479 // spell with SPELL_EFFECT_QUEST_COMPLETE or SPELL_EFFECT_SEND_EVENT (with script) case
13480 else if(qinfo
->ReqSpell
[idx
] != 0)
13482 // not casted and need more reagents/item for use.
13483 if(!q_status
.m_explored
&& GetItemCount(itemid
,true) < qinfo
->ReqSourceCount
[j
])
13493 void Player::SendQuestComplete( uint32 quest_id
)
13497 WorldPacket
data( SMSG_QUESTUPDATE_COMPLETE
, 4 );
13498 data
<< uint32(quest_id
);
13499 GetSession()->SendPacket( &data
);
13500 sLog
.outDebug( "WORLD: Sent SMSG_QUESTUPDATE_COMPLETE quest = %u", quest_id
);
13504 void Player::SendQuestReward( Quest
const *pQuest
, uint32 XP
, Object
* questGiver
)
13506 uint32 questid
= pQuest
->GetQuestId();
13507 sLog
.outDebug( "WORLD: Sent SMSG_QUESTGIVER_QUEST_COMPLETE quest = %u", questid
);
13508 WorldPacket
data( SMSG_QUESTGIVER_QUEST_COMPLETE
, (4+4+4+4+4) );
13509 data
<< uint32(questid
);
13511 if ( getLevel() < sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) )
13513 data
<< uint32(XP
);
13514 data
<< uint32(pQuest
->GetRewOrReqMoney());
13519 data
<< uint32(pQuest
->GetRewOrReqMoney() + int32(pQuest
->GetRewMoneyMaxLevel() * sWorld
.getRate(RATE_DROP_MONEY
)));
13522 data
<< uint32(10*MaNGOS::Honor::hk_honor_at_level(getLevel(), pQuest
->GetRewHonorableKills()));
13523 data
<< uint32(pQuest
->GetBonusTalents()); // bonus talents
13524 GetSession()->SendPacket( &data
);
13526 if (pQuest
->GetQuestCompleteScript() != 0)
13527 sWorld
.ScriptsStart(sQuestEndScripts
, pQuest
->GetQuestCompleteScript(), questGiver
, this);
13530 void Player::SendQuestFailed( uint32 quest_id
)
13534 WorldPacket
data( SMSG_QUESTGIVER_QUEST_FAILED
, 4+4 );
13536 data
<< uint32(0); // failed reason (4 for inventory is full)
13537 GetSession()->SendPacket( &data
);
13538 sLog
.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_FAILED");
13542 void Player::SendQuestTimerFailed( uint32 quest_id
)
13546 WorldPacket
data( SMSG_QUESTUPDATE_FAILEDTIMER
, 4 );
13548 GetSession()->SendPacket( &data
);
13549 sLog
.outDebug("WORLD: Sent SMSG_QUESTUPDATE_FAILEDTIMER");
13553 void Player::SendCanTakeQuestResponse( uint32 msg
)
13555 WorldPacket
data( SMSG_QUESTGIVER_QUEST_INVALID
, 4 );
13556 data
<< uint32(msg
);
13557 GetSession()->SendPacket( &data
);
13558 sLog
.outDebug("WORLD: Sent SMSG_QUESTGIVER_QUEST_INVALID");
13561 void Player::SendPushToPartyResponse( Player
*pPlayer
, uint32 msg
)
13565 WorldPacket
data( MSG_QUEST_PUSH_RESULT
, (8+1) );
13566 data
<< uint64(pPlayer
->GetGUID());
13567 data
<< uint8(msg
); // valid values: 0-8
13568 GetSession()->SendPacket( &data
);
13569 sLog
.outDebug("WORLD: Sent MSG_QUEST_PUSH_RESULT");
13573 void Player::SendQuestUpdateAddItem( Quest
const* pQuest
, uint32 item_idx
, uint32 count
)
13575 WorldPacket
data( SMSG_QUESTUPDATE_ADD_ITEM
, 0 );
13576 sLog
.outDebug( "WORLD: Sent SMSG_QUESTUPDATE_ADD_ITEM" );
13577 //data << pQuest->ReqItemId[item_idx];
13579 GetSession()->SendPacket( &data
);
13582 void Player::SendQuestUpdateAddCreatureOrGo( Quest
const* pQuest
, uint64 guid
, uint32 creatureOrGO_idx
, uint32 old_count
, uint32 add_count
)
13584 assert(old_count
+ add_count
< 256 && "mob/GO count store in 8 bits 2^8 = 256 (0..256)");
13586 int32 entry
= pQuest
->ReqCreatureOrGOId
[ creatureOrGO_idx
];
13588 // client expected gameobject template id in form (id|0x80000000)
13589 entry
= (-entry
) | 0x80000000;
13591 WorldPacket
data( SMSG_QUESTUPDATE_ADD_KILL
, (4*4+8) );
13592 sLog
.outDebug( "WORLD: Sent SMSG_QUESTUPDATE_ADD_KILL" );
13593 data
<< uint32(pQuest
->GetQuestId());
13594 data
<< uint32(entry
);
13595 data
<< uint32(old_count
+ add_count
);
13596 data
<< uint32(pQuest
->ReqCreatureOrGOCount
[ creatureOrGO_idx
]);
13597 data
<< uint64(guid
);
13598 GetSession()->SendPacket(&data
);
13600 uint16 log_slot
= FindQuestSlot( pQuest
->GetQuestId() );
13601 if( log_slot
< MAX_QUEST_LOG_SIZE
)
13602 SetQuestSlotCounter(log_slot
,creatureOrGO_idx
,GetQuestSlotCounter(log_slot
,creatureOrGO_idx
)+add_count
);
13605 /*********************************************************/
13606 /*** LOAD SYSTEM ***/
13607 /*********************************************************/
13609 bool Player::MinimalLoadFromDB( QueryResult
*result
, uint32 guid
)
13611 bool delete_result
= true;
13614 // 0 1 2 3 4 5 6 7 8 9
13615 result
= CharacterDatabase
.PQuery("SELECT guid, data, name, position_x, position_y, position_z, map, totaltime, leveltime, at_login FROM characters WHERE guid = '%u'",guid
);
13616 if(!result
) return false;
13618 else delete_result
= false;
13620 Field
*fields
= result
->Fetch();
13622 if(!LoadValues( fields
[1].GetString()))
13624 sLog
.outError("ERROR: Player #%d have broken data in `data` field. Can't be loaded.",GUID_LOPART(guid
));
13625 if(delete_result
) delete result
;
13629 // overwrite possible wrong/corrupted guid
13630 SetUInt64Value(OBJECT_FIELD_GUID
, MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
));
13632 m_name
= fields
[2].GetCppString();
13634 Relocate(fields
[3].GetFloat(),fields
[4].GetFloat(),fields
[5].GetFloat());
13635 SetMapId(fields
[6].GetUInt32());
13636 // the instance id is not needed at character enum
13638 m_Played_time
[0] = fields
[7].GetUInt32();
13639 m_Played_time
[1] = fields
[8].GetUInt32();
13641 m_atLoginFlags
= fields
[9].GetUInt32();
13643 // I don't see these used anywhere ..
13646 _LoadBoundInstances();*/
13648 if (delete_result
) delete result
;
13650 for (int i
= 0; i
< PLAYER_SLOTS_COUNT
; i
++)
13653 if( HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
) )
13654 m_deathState
= DEAD
;
13659 void Player::_LoadDeclinedNames(QueryResult
* result
)
13665 delete m_declinedname
;
13667 m_declinedname
= new DeclinedName
;
13668 Field
*fields
= result
->Fetch();
13669 for(int i
= 0; i
< MAX_DECLINED_NAME_CASES
; ++i
)
13670 m_declinedname
->name
[i
] = fields
[i
].GetCppString();
13675 bool Player::LoadPositionFromDB(uint32
& mapid
, float& x
,float& y
,float& z
,float& o
, bool& in_flight
, uint64 guid
)
13677 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT position_x,position_y,position_z,orientation,map,taxi_path FROM characters WHERE guid = '%u'",GUID_LOPART(guid
));
13681 Field
*fields
= result
->Fetch();
13683 x
= fields
[0].GetFloat();
13684 y
= fields
[1].GetFloat();
13685 z
= fields
[2].GetFloat();
13686 o
= fields
[3].GetFloat();
13687 mapid
= fields
[4].GetUInt32();
13688 in_flight
= !fields
[5].GetCppString().empty();
13694 bool Player::LoadValuesArrayFromDB(Tokens
& data
, uint64 guid
)
13696 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT data FROM characters WHERE guid='%u'",GUID_LOPART(guid
));
13700 Field
*fields
= result
->Fetch();
13702 data
= StrSplit(fields
[0].GetCppString(), " ");
13709 uint32
Player::GetUInt32ValueFromArray(Tokens
const& data
, uint16 index
)
13711 if(index
>= data
.size())
13714 return (uint32
)atoi(data
[index
].c_str());
13717 float Player::GetFloatValueFromArray(Tokens
const& data
, uint16 index
)
13720 uint32 temp
= Player::GetUInt32ValueFromArray(data
,index
);
13721 memcpy(&result
, &temp
, sizeof(result
));
13726 uint32
Player::GetUInt32ValueFromDB(uint16 index
, uint64 guid
)
13729 if(!LoadValuesArrayFromDB(data
,guid
))
13732 return GetUInt32ValueFromArray(data
,index
);
13735 float Player::GetFloatValueFromDB(uint16 index
, uint64 guid
)
13738 uint32 temp
= Player::GetUInt32ValueFromDB(index
, guid
);
13739 memcpy(&result
, &temp
, sizeof(result
));
13744 bool Player::LoadFromDB( uint32 guid
, SqlQueryHolder
*holder
)
13746 //// 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
13747 //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 FROM characters WHERE guid = '%u'", guid);
13748 QueryResult
*result
= holder
->GetResult(PLAYER_LOGIN_QUERY_LOADFROM
);
13752 sLog
.outError("ERROR: Player (GUID: %u) not found in table `characters`, can't load. ",guid
);
13756 Field
*fields
= result
->Fetch();
13758 uint32 dbAccountId
= fields
[1].GetUInt32();
13760 // check if the character's account in the db and the logged in account match.
13761 // player should be able to load/delete character only with correct account!
13762 if( dbAccountId
!= GetSession()->GetAccountId() )
13764 sLog
.outError("ERROR: Player (GUID: %u) loading from wrong account (is: %u, should be: %u)",guid
,GetSession()->GetAccountId(),dbAccountId
);
13769 Object::_Create( guid
, 0, HIGHGUID_PLAYER
);
13771 m_name
= fields
[3].GetCppString();
13773 // check name limitations
13774 if(!ObjectMgr::IsValidName(m_name
) || GetSession()->GetSecurity() == SEC_PLAYER
&& objmgr
.IsReservedName(m_name
))
13777 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid ='%u'", uint32(AT_LOGIN_RENAME
),guid
);
13781 if(!LoadValues( fields
[2].GetString()))
13783 sLog
.outError("ERROR: Player #%d have broken data in `data` field. Can't be loaded.",GUID_LOPART(guid
));
13788 // overwrite possible wrong/corrupted guid
13789 SetUInt64Value(OBJECT_FIELD_GUID
, MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
));
13791 // cleanup inventory related item value fields (its will be filled correctly in _LoadInventory)
13792 for(uint8 slot
= EQUIPMENT_SLOT_START
; slot
< EQUIPMENT_SLOT_END
; ++slot
)
13794 SetUInt64Value( (uint16
)(PLAYER_FIELD_INV_SLOT_HEAD
+ (slot
* 2) ), 0 );
13795 SetVisibleItemSlot(slot
,NULL
);
13799 delete m_items
[slot
];
13800 m_items
[slot
] = NULL
;
13804 // update money limits
13805 if(GetMoney() > MAX_MONEY_AMOUNT
)
13806 SetMoney(MAX_MONEY_AMOUNT
);
13808 sLog
.outDebug("Load Basic value of player %s is: ", m_name
.c_str());
13811 m_race
= fields
[4].GetUInt8();
13812 //Need to call it to initialize m_team (m_team can be calculated from m_race)
13813 //Other way is to saves m_team into characters table.
13814 setFactionForRace(m_race
);
13817 m_class
= fields
[5].GetUInt8();
13819 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(m_race
, m_class
);
13822 sLog
.outError("Player have incorrect race/class pair. Can't be loaded.");
13827 InitPrimaryProffesions(); // to max set before any spell loaded
13829 uint32 transGUID
= fields
[24].GetUInt32();
13830 Relocate(fields
[6].GetFloat(),fields
[7].GetFloat(),fields
[8].GetFloat(),fields
[10].GetFloat());
13831 SetMapId(fields
[9].GetUInt32());
13832 SetDifficulty(fields
[32].GetUInt32()); // may be changed in _LoadGroup
13834 _LoadGroup(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADGROUP
));
13836 // check arena teams integrity
13837 for(uint32 arena_slot
= 0; arena_slot
< MAX_ARENA_SLOT
; ++arena_slot
)
13839 uint32 arena_team_id
= GetArenaTeamId(arena_slot
);
13843 if(ArenaTeam
* at
= objmgr
.GetArenaTeamById(arena_team_id
))
13844 if(at
->HaveMember(GetGUID()))
13847 // arena team not exist or not member, cleanup fields
13848 for(int j
=0; j
< 6; ++j
)
13849 SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ arena_slot
* 6 + j
, 0);
13852 _LoadBoundInstances(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADBOUNDINSTANCES
));
13854 if(!IsPositionValid())
13856 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());
13858 SetMapId(info
->mapId
);
13859 Relocate(info
->positionX
,info
->positionY
,info
->positionZ
,0.0f
);
13863 m_movementInfo
.t_x
= 0.0f
;
13864 m_movementInfo
.t_y
= 0.0f
;
13865 m_movementInfo
.t_z
= 0.0f
;
13866 m_movementInfo
.t_o
= 0.0f
;
13869 // load the player's map here if it's not already loaded
13870 Map
*map
= GetMap();
13871 // since the player may not be bound to the map yet, make sure subsequent
13872 // getmap calls won't create new maps
13873 SetInstanceId(map
->GetInstanceId());
13875 SaveRecallPosition();
13877 if (transGUID
!= 0)
13879 m_movementInfo
.t_x
= fields
[20].GetFloat();
13880 m_movementInfo
.t_y
= fields
[21].GetFloat();
13881 m_movementInfo
.t_z
= fields
[22].GetFloat();
13882 m_movementInfo
.t_o
= fields
[23].GetFloat();
13884 if( !MaNGOS::IsValidMapCoord(
13885 GetPositionX()+m_movementInfo
.t_x
,GetPositionY()+m_movementInfo
.t_y
,
13886 GetPositionZ()+m_movementInfo
.t_z
,GetOrientation()+m_movementInfo
.t_o
) ||
13887 // transport size limited
13888 m_movementInfo
.t_x
> 50 || m_movementInfo
.t_y
> 50 || m_movementInfo
.t_z
> 50 )
13890 sLog
.outError("ERROR: Player (guidlow %d) have invalid transport coordinates (X: %f Y: %f Z: %f O: %f). Teleport to default race/class locations.",
13891 guid
,GetPositionX()+m_movementInfo
.t_x
,GetPositionY()+m_movementInfo
.t_y
,
13892 GetPositionZ()+m_movementInfo
.t_z
,GetOrientation()+m_movementInfo
.t_o
);
13894 SetMapId(info
->mapId
);
13895 Relocate(info
->positionX
,info
->positionY
,info
->positionZ
,0.0f
);
13897 m_movementInfo
.t_x
= 0.0f
;
13898 m_movementInfo
.t_y
= 0.0f
;
13899 m_movementInfo
.t_z
= 0.0f
;
13900 m_movementInfo
.t_o
= 0.0f
;
13906 if (transGUID
!= 0)
13908 for (MapManager::TransportSet::iterator iter
= MapManager::Instance().m_Transports
.begin(); iter
!= MapManager::Instance().m_Transports
.end(); ++iter
)
13910 if( (*iter
)->GetGUIDLow() == transGUID
)
13912 m_transport
= *iter
;
13913 m_transport
->AddPassenger(this);
13914 SetMapId(m_transport
->GetMapId());
13921 sLog
.outError("ERROR: Player (guidlow %d) have invalid transport guid (%u). Teleport to default race/class locations.",
13924 SetMapId(info
->mapId
);
13925 Relocate(info
->positionX
,info
->positionY
,info
->positionZ
,0.0f
);
13927 m_movementInfo
.t_x
= 0.0f
;
13928 m_movementInfo
.t_y
= 0.0f
;
13929 m_movementInfo
.t_z
= 0.0f
;
13930 m_movementInfo
.t_o
= 0.0f
;
13936 time_t now
= time(NULL
);
13937 time_t logoutTime
= time_t(fields
[16].GetUInt64());
13939 // since last logout (in seconds)
13940 uint64 time_diff
= uint64(now
- logoutTime
);
13942 // set value, including drunk invisibility detection
13943 // calculate sobering. after 15 minutes logged out, the player will be sober again
13945 if(time_diff
> 15*MINUTE
)
13948 soberFactor
= 1-time_diff
/(15.0f
*MINUTE
);
13949 uint16 newDrunkenValue
= uint16(soberFactor
*(GetUInt32Value(PLAYER_BYTES_3
) & 0xFFFE));
13950 SetDrunkValue(newDrunkenValue
);
13952 m_rest_bonus
= fields
[15].GetFloat();
13953 //speed collect rest bonus in offline, in logout, far from tavern, city (section/in hour)
13954 float bubble0
= 0.031;
13955 //speed collect rest bonus in offline, in logout, in tavern, city (section/in hour)
13956 float bubble1
= 0.125;
13958 if((int32
)fields
[16].GetUInt32() > 0)
13960 float bubble
= fields
[17].GetUInt32() > 0
13961 ? bubble1
*sWorld
.getRate(RATE_REST_OFFLINE_IN_TAVERN_OR_CITY
)
13962 : bubble0
*sWorld
.getRate(RATE_REST_OFFLINE_IN_WILDERNESS
);
13964 SetRestBonus(GetRestBonus()+ time_diff
*((float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP
)/72000)*bubble
);
13967 m_cinematic
= fields
[12].GetUInt32();
13968 m_Played_time
[0]= fields
[13].GetUInt32();
13969 m_Played_time
[1]= fields
[14].GetUInt32();
13971 m_resetTalentsCost
= fields
[18].GetUInt32();
13972 m_resetTalentsTime
= time_t(fields
[19].GetUInt64());
13974 // reserve some flags
13975 uint32 old_safe_flags
= GetUInt32Value(PLAYER_FLAGS
) & ( PLAYER_FLAGS_HIDE_CLOAK
| PLAYER_FLAGS_HIDE_HELM
);
13977 if( HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GM
) )
13978 SetUInt32Value(PLAYER_FLAGS
, 0 | old_safe_flags
);
13980 m_taxi
.LoadTaxiMask( fields
[11].GetString() ); // must be before InitTaxiNodesForLevel
13982 uint32 extraflags
= fields
[25].GetUInt32();
13984 m_stableSlots
= fields
[26].GetUInt32();
13985 if(m_stableSlots
> 4)
13987 sLog
.outError("Player can have not more 4 stable slots, but have in DB %u",uint32(m_stableSlots
));
13991 m_atLoginFlags
= fields
[27].GetUInt32();
13994 // Update Honor kills data
13995 m_lastHonorUpdateTime
= logoutTime
;
13996 UpdateHonorFields();
13998 m_deathExpireTime
= (time_t)fields
[30].GetUInt64();
13999 if(m_deathExpireTime
> now
+MAX_DEATH_COUNT
*DEATH_EXPIRE_STEP
)
14000 m_deathExpireTime
= now
+MAX_DEATH_COUNT
*DEATH_EXPIRE_STEP
-1;
14002 std::string taxi_nodes
= fields
[31].GetCppString();
14006 // clear channel spell data (if saved at channel spell casting)
14007 SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, 0);
14008 SetUInt32Value(UNIT_CHANNEL_SPELL
,0);
14010 // clear charm/summon related fields
14013 SetCharmerGUID(NULL
);
14014 SetOwnerGUID(NULL
);
14015 SetCreatorGUID(NULL
);
14017 // reset some aura modifiers before aura apply
14019 SetUInt32Value(PLAYER_TRACK_CREATURES
, 0 );
14020 SetUInt32Value(PLAYER_TRACK_RESOURCES
, 0 );
14022 // reset skill modifiers and set correct unlearn flags
14023 for (uint32 i
= 0; i
< PLAYER_MAX_SKILLS
; i
++)
14025 SetUInt32Value(PLAYER_SKILL_BONUS_INDEX(i
),0);
14027 // set correct unlearn bit
14028 uint32 id
= GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF;
14031 SkillLineEntry
const *pSkill
= sSkillLineStore
.LookupEntry(id
);
14032 if(!pSkill
) continue;
14034 // enable unlearn button for primary professions only
14035 if (pSkill
->categoryId
== SKILL_CATEGORY_PROFESSION
)
14036 SetUInt32Value(PLAYER_SKILL_INDEX(i
), MAKE_PAIR32(id
,1));
14038 SetUInt32Value(PLAYER_SKILL_INDEX(i
), MAKE_PAIR32(id
,0));
14041 // make sure the unit is considered out of combat for proper loading
14044 // make sure the unit is considered not in duel for proper loading
14045 SetUInt64Value(PLAYER_DUEL_ARBITER
, 0);
14046 SetUInt32Value(PLAYER_DUEL_TEAM
, 0);
14048 // remember loaded power/health values to restore after stats initialization and modifier applying
14049 uint32 savedHealth
= GetHealth();
14050 uint32 savedPower
[MAX_POWERS
];
14051 for(uint32 i
= 0; i
< MAX_POWERS
; ++i
)
14052 savedPower
[i
] = GetPower(Powers(i
));
14054 // reset stats before loading any modifiers
14055 InitStatsForLevel();
14056 InitTaxiNodesForLevel();
14057 InitGlyphsForLevel();
14059 // apply original stats mods before spell loading or item equipment that call before equip _RemoveStatsMods()
14061 //mails are loaded only when needed ;-) - when player in game click on mailbox.
14064 _LoadAuras(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADAURAS
), time_diff
);
14066 // add ghost flag (must be after aura load: PLAYER_FLAGS_GHOST set in aura)
14067 if( HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_GHOST
) )
14068 m_deathState
= DEAD
;
14070 _LoadSpells(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADSPELLS
));
14072 // after spell load
14073 InitTalentForLevel();
14074 learnSkillRewardedSpells();
14076 // after spell load, learn rewarded spell if need also
14077 _LoadQuestStatus(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS
));
14078 _LoadDailyQuestStatus(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS
));
14080 _LoadTutorials(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADTUTORIALS
));
14082 // must be before inventory (some items required reputation check)
14083 _LoadReputation(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADREPUTATION
));
14085 _LoadInventory(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADINVENTORY
), time_diff
);
14087 // update items with duration and realtime
14088 UpdateItemDuration(time_diff
, true);
14090 _LoadActions(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADACTIONS
));
14092 // unread mails and next delivery time, actual mails not loaded
14093 _LoadMailInit(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADMAILCOUNT
), holder
->GetResult(PLAYER_LOGIN_QUERY_LOADMAILDATE
));
14095 m_social
= sSocialMgr
.LoadFromDB(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADSOCIALLIST
), GetGUIDLow());
14097 if(!_LoadHomeBind(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADHOMEBIND
)))
14100 // check PLAYER_CHOSEN_TITLE compatibility with PLAYER__FIELD_KNOWN_TITLES
14101 // note: PLAYER__FIELD_KNOWN_TITLES updated at quest status loaded
14102 if(uint32 curTitle
= GetUInt32Value(PLAYER_CHOSEN_TITLE
))
14104 if(!HasTitle(curTitle
))
14105 SetUInt32Value(PLAYER_CHOSEN_TITLE
,0);
14108 // Not finish taxi flight path
14109 if(!m_taxi
.LoadTaxiDestinationsFromString(taxi_nodes
))
14111 // problems with taxi path loading
14112 TaxiNodesEntry
const* nodeEntry
= NULL
;
14113 if(uint32 node_id
= m_taxi
.GetTaxiSource())
14114 nodeEntry
= sTaxiNodesStore
.LookupEntry(node_id
);
14116 if(!nodeEntry
) // don't know taxi start node, to homebind
14118 sLog
.outError("Character %u have wrong data in taxi destination list, teleport to homebind.",GetGUIDLow());
14119 SetMapId(m_homebindMapId
);
14120 Relocate( m_homebindX
, m_homebindY
, m_homebindZ
,0.0f
);
14121 SaveRecallPosition(); // save as recall also to prevent recall and fall from sky
14123 else // have start node, to it
14125 sLog
.outError("Character %u have too short taxi destination list, teleport to original node.",GetGUIDLow());
14126 SetMapId(nodeEntry
->map_id
);
14127 Relocate(nodeEntry
->x
, nodeEntry
->y
, nodeEntry
->z
,0.0f
);
14128 SaveRecallPosition(); // save as recall also to prevent recall and fall from sky
14130 m_taxi
.ClearTaxiDestinations();
14132 else if(uint32 node_id
= m_taxi
.GetTaxiSource())
14134 // save source node as recall coord to prevent recall and fall from sky
14135 TaxiNodesEntry
const* nodeEntry
= sTaxiNodesStore
.LookupEntry(node_id
);
14136 assert(nodeEntry
); // checked in m_taxi.LoadTaxiDestinationsFromString
14137 m_recallMap
= nodeEntry
->map_id
;
14138 m_recallX
= nodeEntry
->x
;
14139 m_recallY
= nodeEntry
->y
;
14140 m_recallZ
= nodeEntry
->z
;
14142 // flight will started later
14145 _LoadSpellCooldowns(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADSPELLCOOLDOWNS
));
14147 // Spell code allow apply any auras to dead character in load time in aura/spell/item loading
14148 // Do now before stats re-calculation cleanup for ghost state unexpected auras
14150 RemoveAllAurasOnDeath();
14152 //apply all stat bonuses from items and auras
14153 SetCanModifyStats(true);
14156 // restore remembered power/health values (but not more max values)
14157 SetHealth(savedHealth
> GetMaxHealth() ? GetMaxHealth() : savedHealth
);
14158 for(uint32 i
= 0; i
< MAX_POWERS
; ++i
)
14159 SetPower(Powers(i
),savedPower
[i
] > GetMaxPower(Powers(i
)) ? GetMaxPower(Powers(i
)) : savedPower
[i
]);
14161 sLog
.outDebug("The value of player %s after load item and aura is: ", m_name
.c_str());
14165 if(GetSession()->GetSecurity() > SEC_PLAYER
)
14167 switch(sWorld
.getConfig(CONFIG_GM_LOGIN_STATE
))
14170 case 0: break; // disable
14171 case 1: SetGameMaster(true); break; // enable
14172 case 2: // save state
14173 if(extraflags
& PLAYER_EXTRA_GM_ON
)
14174 SetGameMaster(true);
14178 switch(sWorld
.getConfig(CONFIG_GM_ACCEPT_TICKETS
))
14181 case 0: break; // disable
14182 case 1: SetAcceptTicket(true); break; // enable
14183 case 2: // save state
14184 if(extraflags
& PLAYER_EXTRA_GM_ACCEPT_TICKETS
)
14185 SetAcceptTicket(true);
14189 switch(sWorld
.getConfig(CONFIG_GM_CHAT
))
14192 case 0: break; // disable
14193 case 1: SetGMChat(true); break; // enable
14194 case 2: // save state
14195 if(extraflags
& PLAYER_EXTRA_GM_CHAT
)
14200 switch(sWorld
.getConfig(CONFIG_GM_WISPERING_TO
))
14203 case 0: break; // disable
14204 case 1: SetAcceptWhispers(true); break; // enable
14205 case 2: // save state
14206 if(extraflags
& PLAYER_EXTRA_ACCEPT_WHISPERS
)
14207 SetAcceptWhispers(true);
14212 _LoadDeclinedNames(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES
));
14216 m_achievementMgr
.LoadFromDB(holder
->GetResult(PLAYER_LOGIN_QUERY_LOADACHIEVEMENTS
), holder
->GetResult(PLAYER_LOGIN_QUERY_LOADCRITERIAPROGRESS
));
14217 m_achievementMgr
.CheckAllAchievementCriteria();
14221 bool Player::isAllowedToLoot(Creature
* creature
)
14223 if(Player
* recipient
= creature
->GetLootRecipient())
14225 if (recipient
== this)
14227 if( Group
* otherGroup
= recipient
->GetGroup())
14229 Group
* thisGroup
= GetGroup();
14232 return thisGroup
== otherGroup
;
14237 // prevent other players from looting if the recipient got disconnected
14238 return !creature
->hasLootRecipient();
14241 void Player::_LoadActions(QueryResult
*result
)
14243 m_actionButtons
.clear();
14245 //QueryResult *result = CharacterDatabase.PQuery("SELECT button,action,type,misc FROM character_action WHERE guid = '%u' ORDER BY button",GetGUIDLow());
14251 Field
*fields
= result
->Fetch();
14253 uint8 button
= fields
[0].GetUInt8();
14255 addActionButton(button
, fields
[1].GetUInt16(), fields
[2].GetUInt8(), fields
[3].GetUInt8());
14257 m_actionButtons
[button
].uState
= ACTIONBUTTON_UNCHANGED
;
14259 while( result
->NextRow() );
14265 void Player::_LoadAuras(QueryResult
*result
, uint32 timediff
)
14268 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
14269 m_modAuras
[i
].clear();
14271 //QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'",GetGUIDLow());
14277 Field
*fields
= result
->Fetch();
14278 uint64 caster_guid
= fields
[0].GetUInt64();
14279 uint32 spellid
= fields
[1].GetUInt32();
14280 uint32 effindex
= fields
[2].GetUInt32();
14281 uint32 stackcount
= fields
[3].GetUInt32();
14282 int32 damage
= (int32
)fields
[4].GetUInt32();
14283 int32 maxduration
= (int32
)fields
[5].GetUInt32();
14284 int32 remaintime
= (int32
)fields
[6].GetUInt32();
14285 int32 remaincharges
= (int32
)fields
[7].GetUInt32();
14287 SpellEntry
const* spellproto
= sSpellStore
.LookupEntry(spellid
);
14290 sLog
.outError("Unknown aura (spellid %u, effindex %u), ignore.",spellid
,effindex
);
14296 sLog
.outError("Invalid effect index (spellid %u, effindex %u), ignore.",spellid
,effindex
);
14300 // negative effects should continue counting down after logout
14301 if (remaintime
!= -1 && !IsPositiveEffect(spellid
, effindex
))
14303 if(remaintime
<= int32(timediff
))
14306 remaintime
-= timediff
;
14309 // prevent wrong values of remaincharges
14310 if(spellproto
->procCharges
)
14312 if(remaincharges
<= 0 || remaincharges
> spellproto
->procCharges
)
14313 remaincharges
= spellproto
->procCharges
;
14318 //do not load single target auras (unless they were cast by the player)
14319 if (caster_guid
!= GetGUID() && IsSingleTargetSpell(spellproto
))
14322 for(uint32 i
=0; i
<stackcount
; i
++)
14324 Aura
* aura
= CreateAura(spellproto
, effindex
, NULL
, this, NULL
);
14326 damage
= aura
->GetModifier()->m_amount
;
14327 aura
->SetLoadedState(caster_guid
,damage
,maxduration
,remaintime
,remaincharges
);
14329 sLog
.outString("Added aura spellid %u, effect %u", spellproto
->Id
, effindex
);
14332 while( result
->NextRow() );
14337 if(m_class
== CLASS_WARRIOR
)
14338 CastSpell(this,SPELL_ID_PASSIVE_BATTLE_STANCE
,true);
14341 void Player::LoadCorpse()
14345 ObjectAccessor::Instance().ConvertCorpseForPlayer(GetGUID());
14349 if(Corpse
*corpse
= GetCorpse())
14351 ApplyModFlag(PLAYER_FIELD_BYTES
, PLAYER_FIELD_BYTE_RELEASE_TIMER
, corpse
&& !sMapStore
.LookupEntry(corpse
->GetMapId())->Instanceable() );
14355 //Prevent Dead Player login without corpse
14356 ResurrectPlayer(0.5f
);
14361 void Player::_LoadInventory(QueryResult
*result
, uint32 timediff
)
14363 //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());
14364 std::map
<uint64
, Bag
*> bagMap
; // fast guid lookup for bags
14365 //NOTE: the "order by `bag`" is important because it makes sure
14366 //the bagMap is filled before items in the bags are loaded
14367 //NOTE2: the "order by `slot`" is needed because mainhand weapons are (wrongly?)
14368 //expected to be equipped before offhand items (TODO: fixme)
14370 uint32 zone
= GetZoneId();
14374 std::list
<Item
*> problematicItems
;
14376 // prevent items from being added to the queue when stored
14377 m_itemUpdateQueueBlocked
= true;
14380 Field
*fields
= result
->Fetch();
14381 uint32 bag_guid
= fields
[1].GetUInt32();
14382 uint8 slot
= fields
[2].GetUInt8();
14383 uint32 item_guid
= fields
[3].GetUInt32();
14384 uint32 item_id
= fields
[4].GetUInt32();
14386 ItemPrototype
const * proto
= objmgr
.GetItemPrototype(item_id
);
14390 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14391 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", item_guid
);
14392 sLog
.outError( "Player::_LoadInventory: Player %s has an unknown item (id: #%u) in inventory, deleted.", GetName(),item_id
);
14396 Item
*item
= NewItemOrBag(proto
);
14398 if(!item
->LoadFromDB(item_guid
, GetGUID(), result
))
14400 sLog
.outError( "Player::_LoadInventory: Player %s has broken item (id: #%u) in inventory, deleted.", GetName(),item_id
);
14401 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14402 item
->FSetState(ITEM_REMOVED
);
14403 item
->SaveToDB(); // it also deletes item object !
14407 // not allow have in alive state item limited to another map/zone
14408 if(isAlive() && item
->IsLimitedToAnotherMapOrZone(GetMapId(),zone
) )
14410 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14411 item
->FSetState(ITEM_REMOVED
);
14412 item
->SaveToDB(); // it also deletes item object !
14416 // "Conjured items disappear if you are logged out for more than 15 minutes"
14417 if ((timediff
> 15*60) && (item
->HasFlag(ITEM_FIELD_FLAGS
, ITEM_FLAGS_CONJURED
)))
14419 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14420 item
->FSetState(ITEM_REMOVED
);
14421 item
->SaveToDB(); // it also deletes item object !
14425 bool success
= true;
14429 // the item is not in a bag
14430 item
->SetContainer( NULL
);
14431 item
->SetSlot(slot
);
14433 if( IsInventoryPos( INVENTORY_SLOT_BAG_0
, slot
) )
14435 ItemPosCountVec dest
;
14436 if( CanStoreItem( INVENTORY_SLOT_BAG_0
, slot
, dest
, item
, false ) == EQUIP_ERR_OK
)
14437 item
= StoreItem(dest
, item
, true);
14441 else if( IsEquipmentPos( INVENTORY_SLOT_BAG_0
, slot
) )
14444 if( CanEquipItem( slot
, dest
, item
, false, false ) == EQUIP_ERR_OK
)
14445 QuickEquipItem(dest
, item
);
14449 else if( IsBankPos( INVENTORY_SLOT_BAG_0
, slot
) )
14451 ItemPosCountVec dest
;
14452 if( CanBankItem( INVENTORY_SLOT_BAG_0
, slot
, dest
, item
, false, false ) == EQUIP_ERR_OK
)
14453 item
= BankItem(dest
, item
, true);
14460 // store bags that may contain items in them
14461 if(item
->IsBag() && IsBagPos(item
->GetPos()))
14462 bagMap
[item_guid
] = (Bag
*)item
;
14467 item
->SetSlot(NULL_SLOT
);
14468 // the item is in a bag, find the bag
14469 std::map
<uint64
, Bag
*>::iterator itr
= bagMap
.find(bag_guid
);
14470 if(itr
!= bagMap
.end())
14471 itr
->second
->StoreItem(slot
, item
, true );
14476 // item's state may have changed after stored
14478 item
->SetState(ITEM_UNCHANGED
, this);
14481 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
);
14482 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid
);
14483 problematicItems
.push_back(item
);
14485 } while (result
->NextRow());
14488 m_itemUpdateQueueBlocked
= false;
14490 // send by mail problematic items
14491 while(!problematicItems
.empty())
14494 MailItemsInfo mi
; // item list preparing
14496 for(int i
= 0; !problematicItems
.empty() && i
< MAX_MAIL_ITEMS
; ++i
)
14498 Item
* item
= problematicItems
.front();
14499 problematicItems
.pop_front();
14501 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
14504 std::string subject
= GetSession()->GetMangosString(LANG_NOT_EQUIPPED_ITEM
);
14506 WorldSession::SendMailTo(this, MAIL_NORMAL
, MAIL_STATIONERY_GM
, GetGUIDLow(), GetGUIDLow(), subject
, 0, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
14510 _ApplyAllItemMods();
14513 // load mailed item which should receive current player
14514 void Player::_LoadMailedItems(Mail
*mail
)
14516 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT item_guid, item_template FROM mail_items WHERE mail_id='%u'", mail
->messageID
);
14522 Field
*fields
= result
->Fetch();
14523 uint32 item_guid_low
= fields
[0].GetUInt32();
14524 uint32 item_template
= fields
[1].GetUInt32();
14526 mail
->AddItem(item_guid_low
, item_template
);
14528 ItemPrototype
const *proto
= objmgr
.GetItemPrototype(item_template
);
14532 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
);
14533 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", item_guid_low
);
14534 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", item_guid_low
);
14538 Item
*item
= NewItemOrBag(proto
);
14540 if(!item
->LoadFromDB(item_guid_low
, 0))
14542 sLog
.outError( "Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail
->messageID
, item_guid_low
);
14543 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", item_guid_low
);
14544 item
->FSetState(ITEM_REMOVED
);
14545 item
->SaveToDB(); // it also deletes item object !
14550 } while (result
->NextRow());
14555 void Player::_LoadMailInit(QueryResult
*resultUnread
, QueryResult
*resultDelivery
)
14557 //set a count of unread mails
14558 //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);
14561 Field
*fieldMail
= resultUnread
->Fetch();
14562 unReadMails
= fieldMail
[0].GetUInt8();
14563 delete resultUnread
;
14566 // store nearest delivery time (it > 0 and if it < current then at next player update SendNewMaill will be called)
14567 //resultMails = CharacterDatabase.PQuery("SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(playerGuid));
14568 if (resultDelivery
)
14570 Field
*fieldMail
= resultDelivery
->Fetch();
14571 m_nextMailDelivereTime
= (time_t)fieldMail
[0].GetUInt64();
14572 delete resultDelivery
;
14576 void Player::_LoadMail()
14579 //mails are in right order 0 1 2 3 4 5 6 7 8 9 10 11 12 13
14580 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());
14585 Field
*fields
= result
->Fetch();
14586 Mail
*m
= new Mail
;
14587 m
->messageID
= fields
[0].GetUInt32();
14588 m
->messageType
= fields
[1].GetUInt8();
14589 m
->sender
= fields
[2].GetUInt32();
14590 m
->receiver
= fields
[3].GetUInt32();
14591 m
->subject
= fields
[4].GetCppString();
14592 m
->itemTextId
= fields
[5].GetUInt32();
14593 bool has_items
= fields
[6].GetBool();
14594 m
->expire_time
= (time_t)fields
[7].GetUInt64();
14595 m
->deliver_time
= (time_t)fields
[8].GetUInt64();
14596 m
->money
= fields
[9].GetUInt32();
14597 m
->COD
= fields
[10].GetUInt32();
14598 m
->checked
= fields
[11].GetUInt32();
14599 m
->stationery
= fields
[12].GetUInt8();
14600 m
->mailTemplateId
= fields
[13].GetInt16();
14602 if(m
->mailTemplateId
&& !sMailTemplateStore
.LookupEntry(m
->mailTemplateId
))
14604 sLog
.outError( "Player::_LoadMail - Mail (%u) have not existed MailTemplateId (%u), remove at load", m
->messageID
, m
->mailTemplateId
);
14605 m
->mailTemplateId
= 0;
14608 m
->state
= MAIL_STATE_UNCHANGED
;
14611 _LoadMailedItems(m
);
14613 m_mail
.push_back(m
);
14614 } while( result
->NextRow() );
14617 m_mailsLoaded
= true;
14620 void Player::LoadPet()
14622 //fixme: the pet should still be loaded if the player is not in world
14623 // just not added to the map
14626 Pet
*pet
= new Pet
;
14627 if(!pet
->LoadPetFromDB(this,0,0,true))
14632 void Player::_LoadQuestStatus(QueryResult
*result
)
14634 mQuestStatus
.clear();
14638 //// 0 1 2 3 4 5 6 7 8 9 10 11 12
14639 //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());
14645 Field
*fields
= result
->Fetch();
14647 uint32 quest_id
= fields
[0].GetUInt32();
14648 // used to be new, no delete?
14649 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
14653 QuestStatusData
& questStatusData
= mQuestStatus
[quest_id
];
14655 uint32 qstatus
= fields
[1].GetUInt32();
14656 if(qstatus
< MAX_QUEST_STATUS
)
14657 questStatusData
.m_status
= QuestStatus(qstatus
);
14660 questStatusData
.m_status
= QUEST_STATUS_NONE
;
14661 sLog
.outError("Player %s have invalid quest %d status (%d), replaced by QUEST_STATUS_NONE(0).",GetName(),quest_id
,qstatus
);
14664 questStatusData
.m_rewarded
= ( fields
[2].GetUInt8() > 0 );
14665 questStatusData
.m_explored
= ( fields
[3].GetUInt8() > 0 );
14667 time_t quest_time
= time_t(fields
[4].GetUInt64());
14669 if( pQuest
->HasFlag( QUEST_MANGOS_FLAGS_TIMED
) && !GetQuestRewardStatus(quest_id
) && questStatusData
.m_status
!= QUEST_STATUS_NONE
)
14671 AddTimedQuest( quest_id
);
14673 if (quest_time
<= sWorld
.GetGameTime())
14674 questStatusData
.m_timer
= 1;
14676 questStatusData
.m_timer
= (quest_time
- sWorld
.GetGameTime()) * 1000;
14681 questStatusData
.m_creatureOrGOcount
[0] = fields
[5].GetUInt32();
14682 questStatusData
.m_creatureOrGOcount
[1] = fields
[6].GetUInt32();
14683 questStatusData
.m_creatureOrGOcount
[2] = fields
[7].GetUInt32();
14684 questStatusData
.m_creatureOrGOcount
[3] = fields
[8].GetUInt32();
14685 questStatusData
.m_itemcount
[0] = fields
[9].GetUInt32();
14686 questStatusData
.m_itemcount
[1] = fields
[10].GetUInt32();
14687 questStatusData
.m_itemcount
[2] = fields
[11].GetUInt32();
14688 questStatusData
.m_itemcount
[3] = fields
[12].GetUInt32();
14690 questStatusData
.uState
= QUEST_UNCHANGED
;
14692 // add to quest log
14693 if( slot
< MAX_QUEST_LOG_SIZE
&&
14694 ( questStatusData
.m_status
==QUEST_STATUS_INCOMPLETE
||
14695 questStatusData
.m_status
==QUEST_STATUS_COMPLETE
&&
14696 (!questStatusData
.m_rewarded
|| pQuest
->IsDaily()) ) )
14698 SetQuestSlot(slot
,quest_id
,quest_time
);
14700 if(questStatusData
.m_status
== QUEST_STATUS_COMPLETE
)
14701 SetQuestSlotState(slot
,QUEST_STATE_COMPLETE
);
14703 for(uint8 idx
= 0; idx
< QUEST_OBJECTIVES_COUNT
; ++idx
)
14704 if(questStatusData
.m_creatureOrGOcount
[idx
])
14705 SetQuestSlotCounter(slot
,idx
,questStatusData
.m_creatureOrGOcount
[idx
]);
14710 if(questStatusData
.m_rewarded
)
14712 // learn rewarded spell if unknown
14713 learnQuestRewardedSpells(pQuest
);
14715 // set rewarded title if any
14716 if(pQuest
->GetCharTitleId())
14718 if(CharTitlesEntry
const* titleEntry
= sCharTitlesStore
.LookupEntry(pQuest
->GetCharTitleId()))
14719 SetTitle(titleEntry
);
14723 sLog
.outDebug("Quest status is {%u} for quest {%u} for player (GUID: %u)", questStatusData
.m_status
, quest_id
, GetGUIDLow());
14726 while( result
->NextRow() );
14731 // clear quest log tail
14732 for ( uint16 i
= slot
; i
< MAX_QUEST_LOG_SIZE
; ++i
)
14736 void Player::_LoadDailyQuestStatus(QueryResult
*result
)
14738 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
14739 SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
,0);
14741 //QueryResult *result = CharacterDatabase.PQuery("SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GetGUIDLow());
14745 uint32 quest_daily_idx
= 0;
14749 if(quest_daily_idx
>= PLAYER_MAX_DAILY_QUESTS
) // max amount with exist data in query
14751 sLog
.outError("Player (GUID: %u) have more 25 daily quest records in `charcter_queststatus_daily`",GetGUIDLow());
14755 Field
*fields
= result
->Fetch();
14757 uint32 quest_id
= fields
[0].GetUInt32();
14759 // save _any_ from daily quest times (it must be after last reset anyway)
14760 m_lastDailyQuestTime
= (time_t)fields
[1].GetUInt64();
14762 Quest
const* pQuest
= objmgr
.GetQuestTemplate(quest_id
);
14766 SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
,quest_id
);
14769 sLog
.outDebug("Daily quest {%u} cooldown for player (GUID: %u)", quest_id
, GetGUIDLow());
14771 while( result
->NextRow() );
14776 m_DailyQuestChanged
= false;
14779 void Player::_LoadReputation(QueryResult
*result
)
14781 m_factions
.clear();
14783 // Set initial reputations (so everything is nifty before DB data load)
14784 SetInitialFactions();
14786 //QueryResult *result = CharacterDatabase.PQuery("SELECT faction,standing,flags FROM character_reputation WHERE guid = '%u'",GetGUIDLow());
14792 Field
*fields
= result
->Fetch();
14794 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(fields
[0].GetUInt32());
14795 if( factionEntry
&& (factionEntry
->reputationListID
>= 0))
14797 FactionState
* faction
= &m_factions
[factionEntry
->reputationListID
];
14799 // update standing to current
14800 faction
->Standing
= int32(fields
[1].GetUInt32());
14802 uint32 dbFactionFlags
= fields
[2].GetUInt32();
14804 if( dbFactionFlags
& FACTION_FLAG_VISIBLE
)
14805 SetFactionVisible(faction
); // have internal checks for forced invisibility
14807 if( dbFactionFlags
& FACTION_FLAG_INACTIVE
)
14808 SetFactionInactive(faction
,true); // have internal checks for visibility requirement
14810 if( dbFactionFlags
& FACTION_FLAG_AT_WAR
) // DB at war
14811 SetFactionAtWar(faction
,true); // have internal checks for FACTION_FLAG_PEACE_FORCED
14812 else // DB not at war
14814 // allow remove if visible (and then not FACTION_FLAG_INVISIBLE_FORCED or FACTION_FLAG_HIDDEN)
14815 if( faction
->Flags
& FACTION_FLAG_VISIBLE
)
14816 SetFactionAtWar(faction
,false); // have internal checks for FACTION_FLAG_PEACE_FORCED
14819 // set atWar for hostile
14820 if(GetReputationRank(factionEntry
) <= REP_HOSTILE
)
14821 SetFactionAtWar(faction
,true);
14823 // reset changed flag if values similar to saved in DB
14824 if(faction
->Flags
==dbFactionFlags
)
14825 faction
->Changed
= false;
14828 while( result
->NextRow() );
14834 void Player::_LoadSpells(QueryResult
*result
)
14836 for (PlayerSpellMap::iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
14837 delete itr
->second
;
14840 //QueryResult *result = CharacterDatabase.PQuery("SELECT spell,slot,active FROM character_spell WHERE guid = '%u'",GetGUIDLow());
14846 Field
*fields
= result
->Fetch();
14848 addSpell(fields
[0].GetUInt16(), fields
[2].GetBool(), false, true, fields
[1].GetUInt16(), fields
[3].GetBool());
14850 while( result
->NextRow() );
14856 void Player::_LoadTutorials(QueryResult
*result
)
14858 //QueryResult *result = CharacterDatabase.PQuery("SELECT tut0,tut1,tut2,tut3,tut4,tut5,tut6,tut7 FROM character_tutorial WHERE account = '%u' AND realmid = '%u'", GetAccountId(), realmid);
14864 Field
*fields
= result
->Fetch();
14866 for (int iI
=0; iI
<8; iI
++)
14867 m_Tutorials
[iI
] = fields
[iI
].GetUInt32();
14869 while( result
->NextRow() );
14874 m_TutorialsChanged
= false;
14877 void Player::_LoadGroup(QueryResult
*result
)
14879 //QueryResult *result = CharacterDatabase.PQuery("SELECT leaderGuid FROM group_member WHERE memberGuid='%u'", GetGUIDLow());
14882 uint64 leaderGuid
= MAKE_NEW_GUID((*result
)[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
14884 Group
* group
= objmgr
.GetGroupByLeader(leaderGuid
);
14887 uint8 subgroup
= group
->GetMemberGroup(GetGUID());
14888 SetGroup(group
, subgroup
);
14889 if(getLevel() >= LEVELREQUIREMENT_HEROIC
)
14891 // the group leader may change the instance difficulty while the player is offline
14892 SetDifficulty(group
->GetDifficulty());
14898 void Player::_LoadBoundInstances(QueryResult
*result
)
14900 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
14901 m_boundInstances
[i
].clear();
14903 Group
*group
= GetGroup();
14905 //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));
14910 Field
*fields
= result
->Fetch();
14911 bool perm
= fields
[1].GetBool();
14912 uint32 mapId
= fields
[2].GetUInt32();
14913 uint32 instanceId
= fields
[0].GetUInt32();
14914 uint8 difficulty
= fields
[3].GetUInt8();
14915 time_t resetTime
= (time_t)fields
[4].GetUInt64();
14916 // the resettime for normal instances is only saved when the InstanceSave is unloaded
14917 // so the value read from the DB may be wrong here but only if the InstanceSave is loaded
14918 // and in that case it is not used
14922 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
);
14923 CharacterDatabase
.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND instance = '%d'", GetGUIDLow(), instanceId
);
14927 // since non permanent binds are always solo bind, they can always be reset
14928 InstanceSave
*save
= sInstanceSaveManager
.AddInstanceSave(mapId
, instanceId
, difficulty
, resetTime
, !perm
, true);
14929 if(save
) BindToInstance(save
, perm
, true);
14930 } while(result
->NextRow());
14935 InstancePlayerBind
* Player::GetBoundInstance(uint32 mapid
, uint8 difficulty
)
14937 // some instances only have one difficulty
14938 const MapEntry
* entry
= sMapStore
.LookupEntry(mapid
);
14939 if(!entry
|| !entry
->SupportsHeroicMode()) difficulty
= DIFFICULTY_NORMAL
;
14941 BoundInstancesMap::iterator itr
= m_boundInstances
[difficulty
].find(mapid
);
14942 if(itr
!= m_boundInstances
[difficulty
].end())
14943 return &itr
->second
;
14948 void Player::UnbindInstance(uint32 mapid
, uint8 difficulty
, bool unload
)
14950 BoundInstancesMap::iterator itr
= m_boundInstances
[difficulty
].find(mapid
);
14951 UnbindInstance(itr
, difficulty
, unload
);
14954 void Player::UnbindInstance(BoundInstancesMap::iterator
&itr
, uint8 difficulty
, bool unload
)
14956 if(itr
!= m_boundInstances
[difficulty
].end())
14958 if(!unload
) CharacterDatabase
.PExecute("DELETE FROM character_instance WHERE guid = '%u' AND instance = '%u'", GetGUIDLow(), itr
->second
.save
->GetInstanceId());
14959 itr
->second
.save
->RemovePlayer(this); // save can become invalid
14960 m_boundInstances
[difficulty
].erase(itr
++);
14964 InstancePlayerBind
* Player::BindToInstance(InstanceSave
*save
, bool permanent
, bool load
)
14968 InstancePlayerBind
& bind
= m_boundInstances
[save
->GetDifficulty()][save
->GetMapId()];
14971 // update the save when the group kills a boss
14972 if(permanent
!= bind
.perm
|| save
!= bind
.save
)
14973 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());
14976 if(!load
) CharacterDatabase
.PExecute("INSERT INTO character_instance (guid, instance, permanent) VALUES ('%u', '%u', '%u')", GetGUIDLow(), save
->GetInstanceId(), permanent
);
14978 if(bind
.save
!= save
)
14980 if(bind
.save
) bind
.save
->RemovePlayer(this);
14981 save
->AddPlayer(this);
14984 if(permanent
) save
->SetCanReset(false);
14987 bind
.perm
= permanent
;
14988 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());
14995 void Player::SendRaidInfo()
14997 WorldPacket
data(SMSG_RAID_INSTANCE_INFO
, 4);
14999 uint32 counter
= 0, i
;
15000 for(i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15001 for (BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); itr
++)
15002 if(itr
->second
.perm
) counter
++;
15005 for(i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15007 for (BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); itr
++)
15009 if(itr
->second
.perm
)
15011 InstanceSave
*save
= itr
->second
.save
;
15012 data
<< (save
->GetMapId());
15013 data
<< (uint32
)(save
->GetResetTime() - time(NULL
));
15014 data
<< save
->GetInstanceId();
15015 data
<< uint32(counter
);
15020 GetSession()->SendPacket(&data
);
15024 - called on every successful teleportation to a map
15026 void Player::SendSavedInstances()
15028 bool hasBeenSaved
= false;
15031 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15033 for (BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); ++itr
)
15035 if(itr
->second
.perm
) // only permanent binds are sent
15037 hasBeenSaved
= true;
15043 //Send opcode 811. true or false means, whether you have current raid/heroic instances
15044 data
.Initialize(SMSG_UPDATE_INSTANCE_OWNERSHIP
);
15045 data
<< uint32(hasBeenSaved
);
15046 GetSession()->SendPacket(&data
);
15051 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15053 for (BoundInstancesMap::iterator itr
= m_boundInstances
[i
].begin(); itr
!= m_boundInstances
[i
].end(); ++itr
)
15055 if(itr
->second
.perm
)
15057 data
.Initialize(SMSG_UPDATE_LAST_INSTANCE
);
15058 data
<< uint32(itr
->second
.save
->GetMapId());
15059 GetSession()->SendPacket(&data
);
15065 /// convert the player's binds to the group
15066 void Player::ConvertInstancesToGroup(Player
*player
, Group
*group
, uint64 player_guid
)
15068 bool has_binds
= false;
15069 bool has_solo
= false;
15071 if(player
) { player_guid
= player
->GetGUID(); if(!group
) group
= player
->GetGroup(); }
15072 assert(player_guid
);
15074 // copy all binds to the group, when changing leader it's assumed the character
15075 // will not have any solo binds
15079 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
15081 for (BoundInstancesMap::iterator itr
= player
->m_boundInstances
[i
].begin(); itr
!= player
->m_boundInstances
[i
].end();)
15084 if(group
) group
->BindToInstance(itr
->second
.save
, itr
->second
.perm
, true);
15085 // permanent binds are not removed
15086 if(!itr
->second
.perm
)
15088 player
->UnbindInstance(itr
, i
, true); // increments itr
15097 // if the player's not online we don't know what binds it has
15098 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
));
15099 // the following should not get executed when changing leaders
15100 if(!player
|| has_solo
) CharacterDatabase
.PExecute("DELETE FROM character_instance WHERE guid = '%d' AND permanent = 0", GUID_LOPART(player_guid
));
15103 bool Player::_LoadHomeBind(QueryResult
*result
)
15106 //QueryResult *result = CharacterDatabase.PQuery("SELECT map,zone,position_x,position_y,position_z FROM character_homebind WHERE guid = '%u'", GUID_LOPART(playerGuid));
15109 Field
*fields
= result
->Fetch();
15110 m_homebindMapId
= fields
[0].GetUInt32();
15111 m_homebindZoneId
= fields
[1].GetUInt16();
15112 m_homebindX
= fields
[2].GetFloat();
15113 m_homebindY
= fields
[3].GetFloat();
15114 m_homebindZ
= fields
[4].GetFloat();
15117 // accept saved data only for valid position (and non instanceable)
15118 if( MapManager::IsValidMapCoord(m_homebindMapId
,m_homebindX
,m_homebindY
,m_homebindZ
) &&
15119 !sMapStore
.LookupEntry(m_homebindMapId
)->Instanceable() )
15124 CharacterDatabase
.PExecute("DELETE FROM character_homebind WHERE guid = '%u'", GetGUIDLow());
15129 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(getRace(), getClass());
15130 if(!info
) return false;
15132 m_homebindMapId
= info
->mapId
;
15133 m_homebindZoneId
= info
->zoneId
;
15134 m_homebindX
= info
->positionX
;
15135 m_homebindY
= info
->positionY
;
15136 m_homebindZ
= info
->positionZ
;
15138 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
);
15141 DEBUG_LOG("Setting player home position: mapid is: %u, zoneid is %u, X is %f, Y is %f, Z is %f\n",
15142 m_homebindMapId
, m_homebindZoneId
, m_homebindX
, m_homebindY
, m_homebindZ
);
15147 /*********************************************************/
15148 /*** SAVE SYSTEM ***/
15149 /*********************************************************/
15151 void Player::SaveToDB()
15153 // delay auto save at any saves (manual, in code, or autosave)
15154 m_nextSave
= sWorld
.getConfig(CONFIG_INTERVAL_SAVE
);
15156 // first save/honor gain after midnight will also update the player's honor fields
15157 UpdateHonorFields();
15159 // Must saved before enter into BattleGround
15160 if(InBattleGround())
15163 int is_save_resting
= HasFlag(PLAYER_FLAGS
, PLAYER_FLAGS_RESTING
) ? 1 : 0;
15164 //save, far from tavern/city
15165 //save, but in tavern/city
15166 sLog
.outDebug("The value of player %s at save: ", m_name
.c_str());
15169 // save state (after auras removing), if aura remove some flags then it must set it back by self)
15170 uint32 tmp_bytes
= GetUInt32Value(UNIT_FIELD_BYTES_1
);
15171 uint32 tmp_bytes2
= GetUInt32Value(UNIT_FIELD_BYTES_2
);
15172 uint32 tmp_flags
= GetUInt32Value(UNIT_FIELD_FLAGS
);
15173 uint32 tmp_pflags
= GetUInt32Value(PLAYER_FLAGS
);
15174 uint32 tmp_displayid
= GetDisplayId();
15176 // Set player sit state to standing on save, also stealth and shifted form
15177 SetByteValue(UNIT_FIELD_BYTES_1
, 0, 0); // stand state
15178 SetByteValue(UNIT_FIELD_BYTES_2
, 3, 0); // shapeshift
15179 SetByteValue(UNIT_FIELD_BYTES_1
, 3, 0); // stand flags?
15180 RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_STUNNED
);
15181 SetDisplayId(GetNativeDisplayId());
15183 bool inworld
= IsInWorld();
15185 CharacterDatabase
.BeginTransaction();
15187 CharacterDatabase
.PExecute("DELETE FROM characters WHERE guid = '%u'",GetGUIDLow());
15189 std::string sql_name
= m_name
;
15190 CharacterDatabase
.escape_string(sql_name
);
15192 std::ostringstream ss
;
15193 ss
<< "INSERT INTO characters (guid,account,name,race,class,"
15194 "map, dungeon_difficulty, position_x, position_y, position_z, orientation, data, "
15195 "taximask, online, cinematic, "
15196 "totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, "
15197 "trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, "
15198 "death_expire_time, taxi_path) VALUES ("
15199 << GetGUIDLow() << ", "
15200 << GetSession()->GetAccountId() << ", '"
15201 << sql_name
<< "', "
15203 << m_class
<< ", ";
15205 bool save_to_dest
= false;
15206 if(IsBeingTeleported())
15208 // don't save to battlegrounds or arenas
15209 const MapEntry
*entry
= sMapStore
.LookupEntry(GetTeleportDest().mapid
);
15210 if(entry
&& entry
->map_type
!= MAP_BATTLEGROUND
&& entry
->map_type
!= MAP_ARENA
)
15211 save_to_dest
= true;
15216 ss
<< GetMapId() << ", "
15217 << (uint32
)GetDifficulty() << ", "
15218 << finiteAlways(GetPositionX()) << ", "
15219 << finiteAlways(GetPositionY()) << ", "
15220 << finiteAlways(GetPositionZ()) << ", "
15221 << finiteAlways(GetOrientation()) << ", '";
15225 ss
<< GetTeleportDest().mapid
<< ", "
15226 << (uint32
)GetDifficulty() << ", "
15227 << finiteAlways(GetTeleportDest().x
) << ", "
15228 << finiteAlways(GetTeleportDest().y
) << ", "
15229 << finiteAlways(GetTeleportDest().z
) << ", "
15230 << finiteAlways(GetTeleportDest().o
) << ", '";
15234 for( i
= 0; i
< m_valuesCount
; i
++ )
15236 ss
<< GetUInt32Value(i
) << " ";
15241 for( i
= 0; i
< 8; i
++ )
15242 ss
<< m_taxi
.GetTaximask(i
) << " ";
15245 ss
<< (inworld
? 1 : 0);
15251 ss
<< m_Played_time
[0];
15253 ss
<< m_Played_time
[1];
15256 ss
<< finiteAlways(m_rest_bonus
);
15258 ss
<< (uint64
)time(NULL
);
15260 ss
<< is_save_resting
;
15262 ss
<< m_resetTalentsCost
;
15264 ss
<< (uint64
)m_resetTalentsTime
;
15267 ss
<< finiteAlways(m_movementInfo
.t_x
);
15269 ss
<< finiteAlways(m_movementInfo
.t_y
);
15271 ss
<< finiteAlways(m_movementInfo
.t_z
);
15273 ss
<< finiteAlways(m_movementInfo
.t_o
);
15276 ss
<< m_transport
->GetGUIDLow();
15281 ss
<< m_ExtraFlags
;
15284 ss
<< uint32(m_stableSlots
); // to prevent save uint8 as char
15287 ss
<< uint32(m_atLoginFlags
);
15293 ss
<< (uint64
)m_deathExpireTime
;
15296 ss
<< m_taxi
.SaveTaxiDestinationsToString();
15299 CharacterDatabase
.Execute( ss
.str().c_str() );
15301 if(m_mailsUpdated
) //save mails only when needed
15305 _SaveQuestStatus();
15306 _SaveDailyQuestStatus();
15309 _SaveSpellCooldowns();
15314 CharacterDatabase
.CommitTransaction();
15316 // restore state (before aura apply, if aura remove flag then aura must set it ack by self)
15317 SetDisplayId(tmp_displayid
);
15318 SetUInt32Value(UNIT_FIELD_BYTES_1
, tmp_bytes
);
15319 SetUInt32Value(UNIT_FIELD_BYTES_2
, tmp_bytes2
);
15320 SetUInt32Value(UNIT_FIELD_FLAGS
, tmp_flags
);
15321 SetUInt32Value(PLAYER_FLAGS
, tmp_pflags
);
15323 // save pet (hunter pet level and experience and all type pets health/mana).
15324 if(Pet
* pet
= GetPet())
15325 pet
->SavePetToDB(PET_SAVE_AS_CURRENT
);
15326 m_achievementMgr
.SaveToDB();
15329 // fast save function for item/money cheating preventing - save only inventory and money state
15330 void Player::SaveInventoryAndGoldToDB()
15333 SetUInt32ValueInDB(PLAYER_FIELD_COINAGE
,GetMoney(),GetGUID());
15336 void Player::_SaveActions()
15338 for(ActionButtonList::iterator itr
= m_actionButtons
.begin(); itr
!= m_actionButtons
.end(); )
15340 switch (itr
->second
.uState
)
15342 case ACTIONBUTTON_NEW
:
15343 CharacterDatabase
.PExecute("INSERT INTO character_action (guid,button,action,type,misc) VALUES ('%u', '%u', '%u', '%u', '%u')",
15344 GetGUIDLow(), (uint32
)itr
->first
, (uint32
)itr
->second
.action
, (uint32
)itr
->second
.type
, (uint32
)itr
->second
.misc
);
15345 itr
->second
.uState
= ACTIONBUTTON_UNCHANGED
;
15348 case ACTIONBUTTON_CHANGED
:
15349 CharacterDatabase
.PExecute("UPDATE character_action SET action = '%u', type = '%u', misc= '%u' WHERE guid= '%u' AND button= '%u' ",
15350 (uint32
)itr
->second
.action
, (uint32
)itr
->second
.type
, (uint32
)itr
->second
.misc
, GetGUIDLow(), (uint32
)itr
->first
);
15351 itr
->second
.uState
= ACTIONBUTTON_UNCHANGED
;
15354 case ACTIONBUTTON_DELETED
:
15355 CharacterDatabase
.PExecute("DELETE FROM character_action WHERE guid = '%u' and button = '%u'", GetGUIDLow(), (uint32
)itr
->first
);
15356 m_actionButtons
.erase(itr
++);
15365 void Player::_SaveAuras()
15367 CharacterDatabase
.PExecute("DELETE FROM character_aura WHERE guid = '%u'",GetGUIDLow());
15369 AuraMap
const& auras
= GetAuras();
15374 spellEffectPair lastEffectPair
= auras
.begin()->first
;
15375 uint32 stackCounter
= 1;
15377 for(AuraMap::const_iterator itr
= auras
.begin(); ; ++itr
)
15379 if(itr
== auras
.end() || lastEffectPair
!= itr
->first
)
15381 AuraMap::const_iterator itr2
= itr
;
15382 // save previous spellEffectPair to db
15384 SpellEntry
const *spellInfo
= itr2
->second
->GetSpellProto();
15386 //skip all auras from spells that are passive or need a shapeshift
15387 if (!(itr2
->second
->IsPassive() || itr2
->second
->IsRemovedOnShapeLost()))
15389 //do not save single target auras (unless they were cast by the player)
15390 if (!(itr2
->second
->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo
)))
15393 // or apply at cast SPELL_AURA_MOD_SHAPESHIFT or SPELL_AURA_MOD_STEALTH auras
15394 for (i
= 0; i
< 3; i
++)
15395 if (spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MOD_SHAPESHIFT
||
15396 spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MOD_STEALTH
)
15401 CharacterDatabase
.PExecute("INSERT INTO character_aura (guid,caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges) "
15402 "VALUES ('%u', '" I64FMTD
"' ,'%u', '%u', '%u', '%d', '%d', '%d', '%d')",
15403 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
->m_procCharges
));
15408 if(itr
== auras
.end())
15412 if (lastEffectPair
== itr
->first
)
15416 lastEffectPair
= itr
->first
;
15422 void Player::_SaveInventory()
15424 // force items in buyback slots to new state
15425 // and remove those that aren't already
15426 for (uint8 i
= BUYBACK_SLOT_START
; i
< BUYBACK_SLOT_END
; i
++)
15428 Item
*item
= m_items
[i
];
15429 if (!item
|| item
->GetState() == ITEM_NEW
) continue;
15430 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item
->GetGUIDLow());
15431 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", item
->GetGUIDLow());
15432 m_items
[i
]->FSetState(ITEM_NEW
);
15435 // update enchantment durations
15436 for(EnchantDurationList::iterator itr
= m_enchantDuration
.begin();itr
!= m_enchantDuration
.end();++itr
)
15438 itr
->item
->SetEnchantmentDuration(itr
->slot
,itr
->leftduration
);
15442 if (m_itemUpdateQueue
.empty()) return;
15444 // do not save if the update queue is corrupt
15445 bool error
= false;
15446 for(size_t i
= 0; i
< m_itemUpdateQueue
.size(); i
++)
15448 Item
*item
= m_itemUpdateQueue
[i
];
15449 if(!item
|| item
->GetState() == ITEM_REMOVED
) continue;
15450 Item
*test
= GetItemByPos( item
->GetBagSlot(), item
->GetSlot());
15454 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());
15457 else if (test
!= item
)
15459 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());
15466 sLog
.outError("Player::_SaveInventory - one or more errors occurred save aborted!");
15467 ChatHandler(this).SendSysMessage(LANG_ITEM_SAVE_FAILED
);
15471 for(size_t i
= 0; i
< m_itemUpdateQueue
.size(); i
++)
15473 Item
*item
= m_itemUpdateQueue
[i
];
15474 if(!item
) continue;
15476 Bag
*container
= item
->GetContainer();
15477 uint32 bag_guid
= container
? container
->GetGUIDLow() : 0;
15479 switch(item
->GetState())
15482 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());
15485 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());
15488 CharacterDatabase
.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item
->GetGUIDLow());
15490 case ITEM_UNCHANGED
:
15494 item
->SaveToDB(); // item have unchanged inventory record and can be save standalone
15496 m_itemUpdateQueue
.clear();
15499 void Player::_SaveMail()
15501 if (!m_mailsLoaded
)
15504 for (PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end(); itr
++)
15507 if (m
->state
== MAIL_STATE_CHANGED
)
15509 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'",
15510 m
->itemTextId
, m
->HasItems() ? 1 : 0, (uint64
)m
->expire_time
, (uint64
)m
->deliver_time
, m
->money
, m
->COD
, m
->checked
, m
->messageID
);
15511 if(m
->removedItems
.size())
15513 for(std::vector
<uint32
>::iterator itr2
= m
->removedItems
.begin(); itr2
!= m
->removedItems
.end(); ++itr2
)
15514 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", *itr2
);
15515 m
->removedItems
.clear();
15517 m
->state
= MAIL_STATE_UNCHANGED
;
15519 else if (m
->state
== MAIL_STATE_DELETED
)
15522 for(std::vector
<MailItemInfo
>::iterator itr2
= m
->items
.begin(); itr2
!= m
->items
.end(); ++itr2
)
15523 CharacterDatabase
.PExecute("DELETE FROM item_instance WHERE guid = '%u'", itr2
->item_guid
);
15525 CharacterDatabase
.PExecute("DELETE FROM item_text WHERE id = '%u'", m
->itemTextId
);
15526 CharacterDatabase
.PExecute("DELETE FROM mail WHERE id = '%u'", m
->messageID
);
15527 CharacterDatabase
.PExecute("DELETE FROM mail_items WHERE mail_id = '%u'", m
->messageID
);
15531 //deallocate deleted mails...
15532 for (PlayerMails::iterator itr
= m_mail
.begin(); itr
!= m_mail
.end(); )
15534 if ((*itr
)->state
== MAIL_STATE_DELETED
)
15539 itr
= m_mail
.begin();
15545 m_mailsUpdated
= false;
15548 void Player::_SaveQuestStatus()
15550 // we don't need transactions here.
15551 for( QuestStatusMap::iterator i
= mQuestStatus
.begin( ); i
!= mQuestStatus
.end( ); ++i
)
15553 switch (i
->second
.uState
)
15556 CharacterDatabase
.PExecute("INSERT INTO character_queststatus (guid,quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4) "
15557 "VALUES ('%u', '%u', '%u', '%u', '%u', '" I64FMTD
"', '%u', '%u', '%u', '%u', '%u', '%u', '%u', '%u')",
15558 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]);
15560 case QUEST_CHANGED
:
15561 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' ",
15562 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
);
15564 case QUEST_UNCHANGED
:
15567 i
->second
.uState
= QUEST_UNCHANGED
;
15571 void Player::_SaveDailyQuestStatus()
15573 if(!m_DailyQuestChanged
)
15576 m_DailyQuestChanged
= false;
15578 // save last daily quest time for all quests: we need only mostly reset time for reset check anyway
15580 // we don't need transactions here.
15581 CharacterDatabase
.PExecute("DELETE FROM character_queststatus_daily WHERE guid = '%u'",GetGUIDLow());
15582 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
15583 if(GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
))
15584 CharacterDatabase
.PExecute("INSERT INTO character_queststatus_daily (guid,quest,time) VALUES ('%u', '%u','" I64FMTD
"')",
15585 GetGUIDLow(), GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
),uint64(m_lastDailyQuestTime
));
15588 void Player::_SaveReputation()
15590 for(FactionStateList::iterator itr
= m_factions
.begin(); itr
!= m_factions
.end(); ++itr
)
15592 if (itr
->second
.Changed
)
15594 CharacterDatabase
.PExecute("DELETE FROM character_reputation WHERE guid = '%u' AND faction='%u'", GetGUIDLow(), itr
->second
.ID
);
15595 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
);
15596 itr
->second
.Changed
= false;
15601 void Player::_SaveSpells()
15603 for (PlayerSpellMap::const_iterator itr
= m_spells
.begin(), next
= m_spells
.begin(); itr
!= m_spells
.end(); itr
= next
)
15606 if (itr
->second
->state
== PLAYERSPELL_REMOVED
|| itr
->second
->state
== PLAYERSPELL_CHANGED
)
15607 CharacterDatabase
.PExecute("DELETE FROM character_spell WHERE guid = '%u' and spell = '%u'", GetGUIDLow(), itr
->first
);
15608 if (itr
->second
->state
== PLAYERSPELL_NEW
|| itr
->second
->state
== PLAYERSPELL_CHANGED
)
15609 CharacterDatabase
.PExecute("INSERT INTO character_spell (guid,spell,slot,active,disabled) VALUES ('%u', '%u', '%u','%u','%u')", GetGUIDLow(), itr
->first
, itr
->second
->slotId
,itr
->second
->active
? 1 : 0,itr
->second
->disabled
? 1 : 0);
15611 if (itr
->second
->state
== PLAYERSPELL_REMOVED
)
15612 _removeSpell(itr
->first
);
15614 itr
->second
->state
= PLAYERSPELL_UNCHANGED
;
15618 void Player::_SaveTutorials()
15620 if(!m_TutorialsChanged
)
15624 // it's better than rebuilding indexes multiple times
15625 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT count(*) AS r FROM character_tutorial WHERE account = '%u' AND realmid = '%u'", GetSession()->GetAccountId(), realmID
);
15628 Rows
= result
->Fetch()[0].GetUInt32();
15634 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'",
15635 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
);
15639 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]);
15642 m_TutorialsChanged
= false;
15645 void Player::outDebugValues() const
15647 if(!sLog
.IsOutDebug()) // optimize disabled debug output
15650 sLog
.outDebug("HP is: \t\t\t%u\t\tMP is: \t\t\t%u",GetMaxHealth(), GetMaxPower(POWER_MANA
));
15651 sLog
.outDebug("AGILITY is: \t\t%f\t\tSTRENGTH is: \t\t%f",GetStat(STAT_AGILITY
), GetStat(STAT_STRENGTH
));
15652 sLog
.outDebug("INTELLECT is: \t\t%f\t\tSPIRIT is: \t\t%f",GetStat(STAT_INTELLECT
), GetStat(STAT_SPIRIT
));
15653 sLog
.outDebug("STAMINA is: \t\t%f\t\tSPIRIT is: \t\t%f",GetStat(STAT_STAMINA
), GetStat(STAT_SPIRIT
));
15654 sLog
.outDebug("Armor is: \t\t%u\t\tBlock is: \t\t%f",GetArmor(), GetFloatValue(PLAYER_BLOCK_PERCENTAGE
));
15655 sLog
.outDebug("HolyRes is: \t\t%u\t\tFireRes is: \t\t%u",GetResistance(SPELL_SCHOOL_HOLY
), GetResistance(SPELL_SCHOOL_FIRE
));
15656 sLog
.outDebug("NatureRes is: \t\t%u\t\tFrostRes is: \t\t%u",GetResistance(SPELL_SCHOOL_NATURE
), GetResistance(SPELL_SCHOOL_FROST
));
15657 sLog
.outDebug("ShadowRes is: \t\t%u\t\tArcaneRes is: \t\t%u",GetResistance(SPELL_SCHOOL_SHADOW
), GetResistance(SPELL_SCHOOL_ARCANE
));
15658 sLog
.outDebug("MIN_DAMAGE is: \t\t%f\tMAX_DAMAGE is: \t\t%f",GetFloatValue(UNIT_FIELD_MINDAMAGE
), GetFloatValue(UNIT_FIELD_MAXDAMAGE
));
15659 sLog
.outDebug("MIN_OFFHAND_DAMAGE is: \t%f\tMAX_OFFHAND_DAMAGE is: \t%f",GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE
), GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE
));
15660 sLog
.outDebug("MIN_RANGED_DAMAGE is: \t%f\tMAX_RANGED_DAMAGE is: \t%f",GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
), GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
));
15661 sLog
.outDebug("ATTACK_TIME is: \t%u\t\tRANGE_ATTACK_TIME is: \t%u",GetAttackTime(BASE_ATTACK
), GetAttackTime(RANGED_ATTACK
));
15664 /*********************************************************/
15665 /*** FLOOD FILTER SYSTEM ***/
15666 /*********************************************************/
15668 void Player::UpdateSpeakTime()
15670 // ignore chat spam protection for GMs in any mode
15671 if(GetSession()->GetSecurity() > SEC_PLAYER
)
15674 time_t current
= time (NULL
);
15675 if(m_speakTime
> current
)
15677 uint32 max_count
= sWorld
.getConfig(CONFIG_CHATFLOOD_MESSAGE_COUNT
);
15682 if(m_speakCount
>= max_count
)
15684 // prevent overwrite mute time, if message send just before mutes set, for example.
15685 time_t new_mute
= current
+ sWorld
.getConfig(CONFIG_CHATFLOOD_MUTE_TIME
);
15686 if(GetSession()->m_muteTime
< new_mute
)
15687 GetSession()->m_muteTime
= new_mute
;
15695 m_speakTime
= current
+ sWorld
.getConfig(CONFIG_CHATFLOOD_MESSAGE_DELAY
);
15698 bool Player::CanSpeak() const
15700 return GetSession()->m_muteTime
<= time (NULL
);
15703 /*********************************************************/
15704 /*** LOW LEVEL FUNCTIONS:Notifiers ***/
15705 /*********************************************************/
15707 void Player::SendAttackSwingNotInRange()
15709 WorldPacket
data(SMSG_ATTACKSWING_NOTINRANGE
, 0);
15710 GetSession()->SendPacket( &data
);
15713 void Player::SavePositionInDB(uint32 mapid
, float x
,float y
,float z
,float o
,uint32 zone
,uint64 guid
)
15715 std::ostringstream ss
;
15716 ss
<< "UPDATE characters SET position_x='"<<x
<<"',position_y='"<<y
15717 << "',position_z='"<<z
<<"',orientation='"<<o
<<"',map='"<<mapid
15718 << "',zone='"<<zone
<<"',trans_x='0',trans_y='0',trans_z='0',"
15719 << "transguid='0',taxi_path='' WHERE guid='"<< GUID_LOPART(guid
) <<"'";
15720 sLog
.outDebug(ss
.str().c_str());
15721 CharacterDatabase
.Execute(ss
.str().c_str());
15724 bool Player::SaveValuesArrayInDB(Tokens
const& tokens
, uint64 guid
)
15726 std::ostringstream ss2
;
15727 ss2
<<"UPDATE characters SET data='";
15729 for (Tokens::const_iterator iter
= tokens
.begin(); iter
!= tokens
.end(); ++iter
, ++i
)
15731 ss2
<<tokens
[i
]<<" ";
15733 ss2
<<"' WHERE guid='"<< GUID_LOPART(guid
) <<"'";
15735 return CharacterDatabase
.Execute(ss2
.str().c_str());
15738 void Player::SetUInt32ValueInArray(Tokens
& tokens
,uint16 index
, uint32 value
)
15741 snprintf(buf
,11,"%u",value
);
15743 if(index
>= tokens
.size())
15746 tokens
[index
] = buf
;
15749 void Player::SetUInt32ValueInDB(uint16 index
, uint32 value
, uint64 guid
)
15752 if(!LoadValuesArrayFromDB(tokens
,guid
))
15755 if(index
>= tokens
.size())
15759 snprintf(buf
,11,"%u",value
);
15760 tokens
[index
] = buf
;
15762 SaveValuesArrayInDB(tokens
,guid
);
15765 void Player::SetFloatValueInDB(uint16 index
, float value
, uint64 guid
)
15768 memcpy(&temp
, &value
, sizeof(value
));
15769 Player::SetUInt32ValueInDB(index
, temp
, guid
);
15772 void Player::SendAttackSwingNotStanding()
15774 WorldPacket
data(SMSG_ATTACKSWING_NOTSTANDING
, 0);
15775 GetSession()->SendPacket( &data
);
15778 void Player::SendAttackSwingDeadTarget()
15780 WorldPacket
data(SMSG_ATTACKSWING_DEADTARGET
, 0);
15781 GetSession()->SendPacket( &data
);
15784 void Player::SendAttackSwingCantAttack()
15786 WorldPacket
data(SMSG_ATTACKSWING_CANT_ATTACK
, 0);
15787 GetSession()->SendPacket( &data
);
15790 void Player::SendAttackSwingCancelAttack()
15792 WorldPacket
data(SMSG_CANCEL_COMBAT
, 0);
15793 GetSession()->SendPacket( &data
);
15796 void Player::SendAttackSwingBadFacingAttack()
15798 WorldPacket
data(SMSG_ATTACKSWING_BADFACING
, 0);
15799 GetSession()->SendPacket( &data
);
15802 void Player::SendAutoRepeatCancel()
15804 WorldPacket
data(SMSG_CANCEL_AUTO_REPEAT
, GetPackGUID().size());
15805 data
.append(GetPackGUID()); // may be it's target guid
15806 GetSession()->SendPacket( &data
);
15809 void Player::PlaySound(uint32 Sound
, bool OnlySelf
)
15811 WorldPacket
data(SMSG_PLAY_SOUND
, 4);
15814 GetSession()->SendPacket( &data
);
15816 SendMessageToSet( &data
, true );
15819 void Player::SendExplorationExperience(uint32 Area
, uint32 Experience
)
15821 WorldPacket
data( SMSG_EXPLORATION_EXPERIENCE
, 8 );
15823 data
<< Experience
;
15824 GetSession()->SendPacket(&data
);
15827 void Player::SendDungeonDifficulty(bool IsInGroup
)
15829 uint8 val
= 0x00000001;
15830 WorldPacket
data(MSG_SET_DUNGEON_DIFFICULTY
, 12);
15831 data
<< (uint32
)GetDifficulty();
15832 data
<< uint32(val
);
15833 data
<< uint32(IsInGroup
);
15834 GetSession()->SendPacket(&data
);
15837 void Player::SendResetFailedNotify(uint32 mapid
)
15839 WorldPacket
data(SMSG_RESET_FAILED_NOTIFY
, 4);
15840 data
<< uint32(mapid
);
15841 GetSession()->SendPacket(&data
);
15844 /// Reset all solo instances and optionally send a message on success for each
15845 void Player::ResetInstances(uint8 method
)
15847 // method can be INSTANCE_RESET_ALL, INSTANCE_RESET_CHANGE_DIFFICULTY, INSTANCE_RESET_GROUP_JOIN
15849 // we assume that when the difficulty changes, all instances that can be reset will be
15850 uint8 dif
= GetDifficulty();
15852 for (BoundInstancesMap::iterator itr
= m_boundInstances
[dif
].begin(); itr
!= m_boundInstances
[dif
].end();)
15854 InstanceSave
*p
= itr
->second
.save
;
15855 const MapEntry
*entry
= sMapStore
.LookupEntry(itr
->first
);
15856 if(!entry
|| !p
->CanReset())
15862 if(method
== INSTANCE_RESET_ALL
)
15864 // the "reset all instances" method can only reset normal maps
15865 if(dif
== DIFFICULTY_HEROIC
|| entry
->map_type
== MAP_RAID
)
15872 // if the map is loaded, reset it
15873 Map
*map
= MapManager::Instance().FindMap(p
->GetMapId(), p
->GetInstanceId());
15874 if(map
&& map
->IsDungeon())
15875 ((InstanceMap
*)map
)->Reset(method
);
15877 // since this is a solo instance there should not be any players inside
15878 if(method
== INSTANCE_RESET_ALL
|| method
== INSTANCE_RESET_CHANGE_DIFFICULTY
)
15879 SendResetInstanceSuccess(p
->GetMapId());
15882 m_boundInstances
[dif
].erase(itr
++);
15884 // the following should remove the instance save from the manager and delete it as well
15885 p
->RemovePlayer(this);
15889 void Player::SendResetInstanceSuccess(uint32 MapId
)
15891 WorldPacket
data(SMSG_INSTANCE_RESET
, 4);
15893 GetSession()->SendPacket(&data
);
15896 void Player::SendResetInstanceFailed(uint32 reason
, uint32 MapId
)
15898 // TODO: find what other fail reasons there are besides players in the instance
15899 WorldPacket
data(SMSG_INSTANCE_RESET_FAILED
, 4);
15902 GetSession()->SendPacket(&data
);
15905 /*********************************************************/
15906 /*** Update timers ***/
15907 /*********************************************************/
15909 ///checks the 15 afk reports per 5 minutes limit
15910 void Player::UpdateAfkReport(time_t currTime
)
15912 if(m_bgAfkReportedTimer
<= currTime
)
15914 m_bgAfkReportedCount
= 0;
15915 m_bgAfkReportedTimer
= currTime
+5*MINUTE
;
15919 void Player::UpdateContestedPvP(uint32 diff
)
15921 if(!m_contestedPvPTimer
||isInCombat())
15923 if(m_contestedPvPTimer
<= diff
)
15925 ResetContestedPvP();
15928 m_contestedPvPTimer
-= diff
;
15931 void Player::UpdatePvPFlag(time_t currTime
)
15935 if(pvpInfo
.endTimer
== 0 || currTime
< (pvpInfo
.endTimer
+ 300))
15941 void Player::UpdateDuelFlag(time_t currTime
)
15943 if(!duel
|| duel
->startTimer
== 0 ||currTime
< duel
->startTimer
+ 3)
15946 SetUInt32Value(PLAYER_DUEL_TEAM
, 1);
15947 duel
->opponent
->SetUInt32Value(PLAYER_DUEL_TEAM
, 2);
15949 duel
->startTimer
= 0;
15950 duel
->startTime
= currTime
;
15951 duel
->opponent
->duel
->startTimer
= 0;
15952 duel
->opponent
->duel
->startTime
= currTime
;
15955 void Player::RemovePet(Pet
* pet
, PetSaveMode mode
, bool returnreagent
)
15960 if(returnreagent
&& (pet
|| m_temporaryUnsummonedPetNumber
))
15962 //returning of reagents only for players, so best done here
15963 uint32 spellId
= pet
? pet
->GetUInt32Value(UNIT_CREATED_BY_SPELL
) : m_oldpetspell
;
15964 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
15968 for(uint32 i
= 0; i
< 7; ++i
)
15970 if(spellInfo
->Reagent
[i
] > 0)
15972 ItemPosCountVec dest
; //for succubus, voidwalker, felhunter and felguard credit soulshard when despawn reason other than death (out of range, logout)
15973 uint8 msg
= CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, spellInfo
->Reagent
[i
], spellInfo
->ReagentCount
[i
] );
15974 if( msg
== EQUIP_ERR_OK
)
15976 Item
* item
= StoreNewItem( dest
, spellInfo
->Reagent
[i
], true);
15978 SendNewItem(item
,spellInfo
->ReagentCount
[i
],true,false);
15983 m_temporaryUnsummonedPetNumber
= 0;
15986 if(!pet
|| pet
->GetOwnerGUID()!=GetGUID())
15989 // only if current pet in slot
15990 switch(pet
->getPetType())
15996 m_guardianPets
.erase(pet
->GetGUID());
15999 if(GetPetGUID() == pet
->GetGUID())
16008 switch(pet
->GetEntry())
16010 //warlock pets except imp are removed(?) when logging out
16015 mode
= PET_SAVE_NOT_IN_SLOT
;
16020 pet
->SavePetToDB(mode
);
16022 pet
->CleanupsBeforeDelete();
16023 pet
->AddObjectToRemoveList();
16024 pet
->m_removed
= true;
16026 if(pet
->isControlled())
16028 WorldPacket
data(SMSG_PET_SPELLS
, 8);
16031 GetSession()->SendPacket(&data
);
16034 SetGroupUpdateFlag(GROUP_UPDATE_PET
);
16038 void Player::RemoveMiniPet()
16040 if(Pet
* pet
= GetMiniPet())
16042 pet
->Remove(PET_SAVE_AS_DELETED
);
16047 Pet
* Player::GetMiniPet()
16051 return ObjectAccessor::GetPet(m_miniPet
);
16054 void Player::RemoveGuardians()
16056 while(!m_guardianPets
.empty())
16058 uint64 guid
= *m_guardianPets
.begin();
16059 if(Pet
* pet
= ObjectAccessor::GetPet(guid
))
16060 pet
->Remove(PET_SAVE_AS_DELETED
);
16062 m_guardianPets
.erase(guid
);
16066 bool Player::HasGuardianWithEntry(uint32 entry
)
16068 // pet guid middle part is entry (and creature also)
16069 // and in guardian list must be guardians with same entry _always_
16070 for(GuardianPetList::const_iterator itr
= m_guardianPets
.begin(); itr
!= m_guardianPets
.end(); ++itr
)
16071 if(GUID_ENPART(*itr
)==entry
)
16077 void Player::Uncharm()
16079 Unit
* charm
= GetCharm();
16083 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM
);
16084 charm
->RemoveSpellsCausingAura(SPELL_AURA_MOD_POSSESS
);
16087 void Player::BuildPlayerChat(WorldPacket
*data
, uint8 msgtype
, std::string text
, uint32 language
) const
16089 *data
<< (uint8
)msgtype
;
16090 *data
<< (uint32
)language
;
16091 *data
<< (uint64
)GetGUID();
16092 *data
<< (uint32
)language
; //language 2.1.0 ?
16093 *data
<< (uint64
)GetGUID();
16094 *data
<< (uint32
)(text
.length()+1);
16096 *data
<< (uint8
)chatTag();
16099 void Player::Say(const std::string text
, const uint32 language
)
16101 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
16102 BuildPlayerChat(&data
, CHAT_MSG_SAY
, text
, language
);
16103 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_SAY
),true);
16106 void Player::Yell(const std::string text
, const uint32 language
)
16108 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
16109 BuildPlayerChat(&data
, CHAT_MSG_YELL
, text
, language
);
16110 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_YELL
),true);
16113 void Player::TextEmote(const std::string text
)
16115 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
16116 BuildPlayerChat(&data
, CHAT_MSG_EMOTE
, text
, LANG_UNIVERSAL
);
16117 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE
),true, !sWorld
.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT
) );
16120 void Player::Whisper(std::string text
, uint32 language
,uint64 receiver
)
16122 if (language
!= LANG_ADDON
) // if not addon data
16123 language
= LANG_UNIVERSAL
; // whispers should always be readable
16125 Player
*rPlayer
= objmgr
.GetPlayer(receiver
);
16127 // when player you are whispering to is dnd, he cannot receive your message, unless you are in gm mode
16128 if(!rPlayer
->isDND() || isGameMaster())
16130 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
16131 BuildPlayerChat(&data
, CHAT_MSG_WHISPER
, text
, language
);
16132 rPlayer
->GetSession()->SendPacket(&data
);
16134 data
.Initialize(SMSG_MESSAGECHAT
, 200);
16135 rPlayer
->BuildPlayerChat(&data
, CHAT_MSG_REPLY
, text
, language
);
16136 GetSession()->SendPacket(&data
);
16140 // announce to player that player he is whispering to is dnd and cannot receive his message
16141 ChatHandler(this).PSendSysMessage(LANG_PLAYER_DND
, rPlayer
->GetName(), rPlayer
->dndMsg
.c_str());
16144 if(!isAcceptWhispers())
16146 SetAcceptWhispers(true);
16147 ChatHandler(this).SendSysMessage(LANG_COMMAND_WHISPERON
);
16150 // announce to player that player he is whispering to is afk
16151 if(rPlayer
->isAFK())
16152 ChatHandler(this).PSendSysMessage(LANG_PLAYER_AFK
, rPlayer
->GetName(), rPlayer
->afkMsg
.c_str());
16154 // if player whisper someone, auto turn of dnd to be able to receive an answer
16155 if(isDND() && !rPlayer
->isGameMaster())
16159 void Player::PetSpellInitialize()
16161 Pet
* pet
= GetPet();
16166 sLog
.outDebug("Pet Spells Groups");
16168 CharmInfo
*charmInfo
= pet
->GetCharmInfo();
16170 WorldPacket
data(SMSG_PET_SPELLS
, 8+4+4+4+10*4);
16171 data
<< uint64(pet
->GetGUID());
16172 data
<< uint32(pet
->GetCreatureInfo()->family
); // creature family (required for pet talents)
16174 data
<< uint8(charmInfo
->GetReactState()) << uint8(charmInfo
->GetCommandState()) << uint16(0);
16177 for(uint32 i
= 0; i
< 10; i
++)
16179 data
<< uint32(charmInfo
->GetActionBarEntry(i
)->Raw
);
16182 size_t spellsCountPos
= data
.wpos();
16186 data
<< uint8(addlist
); // placeholder
16188 if(pet
->isControlled() && ((pet
->getPetType() == HUNTER_PET
) || ((pet
->GetCreatureInfo()->type
== CREATURE_TYPE_DEMON
) && (getClass() == CLASS_WARLOCK
))))
16191 for (PetSpellMap::iterator itr
= pet
->m_spells
.begin(); itr
!= pet
->m_spells
.end(); ++itr
)
16193 if(itr
->second
->state
== PETSPELL_REMOVED
)
16196 data
<< uint16(itr
->first
);
16197 data
<< uint16(itr
->second
->active
); // pet spell active state isn't boolean
16202 data
.put
<uint8
>(spellsCountPos
, addlist
);
16204 uint8 cooldownsCount
= pet
->m_CreatureSpellCooldowns
.size() + pet
->m_CreatureCategoryCooldowns
.size();
16205 data
<< uint8(cooldownsCount
);
16207 time_t curTime
= time(NULL
);
16209 for(CreatureSpellCooldowns::const_iterator itr
= pet
->m_CreatureSpellCooldowns
.begin(); itr
!= pet
->m_CreatureSpellCooldowns
.end(); ++itr
)
16211 time_t cooldown
= 0;
16213 if(itr
->second
> curTime
)
16214 cooldown
= (itr
->second
- curTime
) * 1000;
16216 data
<< uint16(itr
->first
); // spellid
16217 data
<< uint16(0); // spell category?
16218 data
<< uint32(itr
->second
); // cooldown
16219 data
<< uint32(0); // category cooldown
16222 for(CreatureSpellCooldowns::const_iterator itr
= pet
->m_CreatureCategoryCooldowns
.begin(); itr
!= pet
->m_CreatureCategoryCooldowns
.end(); ++itr
)
16224 time_t cooldown
= 0;
16226 if(itr
->second
> curTime
)
16227 cooldown
= (itr
->second
- curTime
) * 1000;
16229 data
<< uint16(itr
->first
); // spellid
16230 data
<< uint16(0); // spell category?
16231 data
<< uint32(0); // cooldown
16232 data
<< uint32(itr
->second
); // category cooldown
16235 GetSession()->SendPacket(&data
);
16238 void Player::PossessSpellInitialize()
16240 Unit
* charm
= GetCharm();
16245 CharmInfo
*charmInfo
= charm
->GetCharmInfo();
16249 sLog
.outError("Player::PossessSpellInitialize(): charm ("I64FMTD
") has no charminfo!", charm
->GetGUID());
16254 WorldPacket
data(SMSG_PET_SPELLS
, 16+40+1+4*addlist
+25);// first line + actionbar + spellcount + spells + last adds
16257 data
<< uint64(charm
->GetGUID());
16258 data
<< uint32(0x00000000);
16260 data
<< uint8(0) << uint8(0) << uint16(0);
16262 for(uint32 i
= 0; i
< 10; i
++) //40
16264 data
<< uint16(charmInfo
->GetActionBarEntry(i
)->SpellOrAction
) << uint16(charmInfo
->GetActionBarEntry(i
)->Type
);
16267 data
<< uint8(addlist
); //1
16270 data
<< uint8(count
); // cooldowns count
16272 GetSession()->SendPacket(&data
);
16275 void Player::CharmSpellInitialize()
16277 Unit
* charm
= GetCharm();
16282 CharmInfo
*charmInfo
= charm
->GetCharmInfo();
16285 sLog
.outError("Player::CharmSpellInitialize(): the player's charm ("I64FMTD
") has no charminfo!", charm
->GetGUID());
16291 if(charm
->GetTypeId() != TYPEID_PLAYER
)
16293 CreatureInfo
const *cinfo
= ((Creature
*)charm
)->GetCreatureInfo();
16295 if(cinfo
&& cinfo
->type
== CREATURE_TYPE_DEMON
&& getClass() == CLASS_WARLOCK
)
16297 for(uint32 i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
16299 if(charmInfo
->GetCharmSpell(i
)->spellId
)
16305 WorldPacket
data(SMSG_PET_SPELLS
, 16+40+1+4*addlist
+25);// first line + actionbar + spellcount + spells + last adds
16307 data
<< uint64(charm
->GetGUID());
16308 data
<< uint32(0x00000000);
16310 if(charm
->GetTypeId() != TYPEID_PLAYER
)
16311 data
<< uint8(charmInfo
->GetReactState()) << uint8(charmInfo
->GetCommandState());
16313 data
<< uint8(0) << uint8(0);
16316 for(uint32 i
= 0; i
< 10; i
++) //40
16318 data
<< uint16(charmInfo
->GetActionBarEntry(i
)->SpellOrAction
) << uint16(charmInfo
->GetActionBarEntry(i
)->Type
);
16321 data
<< uint8(addlist
); //1
16325 for(uint32 i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
16327 CharmSpellEntry
*cspell
= charmInfo
->GetCharmSpell(i
);
16328 if(cspell
->spellId
)
16330 data
<< uint16(cspell
->spellId
);
16331 data
<< uint16(cspell
->active
);
16337 data
<< uint8(count
); // cooldowns count
16339 GetSession()->SendPacket(&data
);
16342 int32
Player::GetTotalFlatMods(uint32 spellId
, SpellModOp op
)
16344 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
16345 if (!spellInfo
) return 0;
16347 for (SpellModList::iterator itr
= m_spellMods
[op
].begin(); itr
!= m_spellMods
[op
].end(); ++itr
)
16349 SpellModifier
*mod
= *itr
;
16351 if(!IsAffectedBySpellmod(spellInfo
,mod
))
16354 if (mod
->type
== SPELLMOD_FLAT
)
16355 total
+= mod
->value
;
16360 int32
Player::GetTotalPctMods(uint32 spellId
, SpellModOp op
)
16362 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
16363 if (!spellInfo
) return 0;
16365 for (SpellModList::iterator itr
= m_spellMods
[op
].begin(); itr
!= m_spellMods
[op
].end(); ++itr
)
16367 SpellModifier
*mod
= *itr
;
16369 if(!IsAffectedBySpellmod(spellInfo
,mod
))
16372 if (mod
->type
== SPELLMOD_PCT
)
16373 total
+= mod
->value
;
16378 bool Player::IsAffectedBySpellmod(SpellEntry
const *spellInfo
, SpellModifier
*mod
, Spell
const* spell
)
16380 if (!mod
|| !spellInfo
)
16383 if(mod
->charges
== -1 && mod
->lastAffected
) // marked as expired but locked until spell casting finish
16385 // prevent apply to any spell except spell that trigger expire
16388 if(mod
->lastAffected
!= spell
)
16391 else if(mod
->lastAffected
!= FindCurrentSpellBySpellId(spellInfo
->Id
))
16395 return spellmgr
.IsAffectedBySpell(spellInfo
,mod
->spellId
,mod
->effectId
,mod
->mask
);
16398 void Player::AddSpellMod(SpellModifier
* mod
, bool apply
)
16400 uint16 Opcode
= (mod
->type
== SPELLMOD_FLAT
) ? SMSG_SET_FLAT_SPELL_MODIFIER
: SMSG_SET_PCT_SPELL_MODIFIER
;
16402 for(int eff
=0;eff
<64;++eff
)
16404 uint64 _mask
= uint64(1) << eff
;
16405 if ( mod
->mask
& _mask
)
16408 for (SpellModList::iterator itr
= m_spellMods
[mod
->op
].begin(); itr
!= m_spellMods
[mod
->op
].end(); ++itr
)
16410 if ((*itr
)->type
== mod
->type
&& (*itr
)->mask
& _mask
)
16411 val
+= (*itr
)->value
;
16413 val
+= apply
? mod
->value
: -(mod
->value
);
16414 WorldPacket
data(Opcode
, (1+1+4));
16415 data
<< uint8(eff
);
16416 data
<< uint8(mod
->op
);
16417 data
<< int32(val
);
16418 SendDirectMessage(&data
);
16423 m_spellMods
[mod
->op
].push_back(mod
);
16426 if (mod
->charges
== -1)
16427 --m_SpellModRemoveCount
;
16428 m_spellMods
[mod
->op
].remove(mod
);
16433 void Player::RemoveSpellMods(Spell
const* spell
)
16435 if(!spell
|| (m_SpellModRemoveCount
== 0))
16438 for(int i
=0;i
<MAX_SPELLMOD
;++i
)
16440 for (SpellModList::iterator itr
= m_spellMods
[i
].begin(); itr
!= m_spellMods
[i
].end();)
16442 SpellModifier
*mod
= *itr
;
16445 if (mod
&& mod
->charges
== -1 && (mod
->lastAffected
== spell
|| mod
->lastAffected
==NULL
))
16447 RemoveAurasDueToSpell(mod
->spellId
);
16448 if (m_spellMods
[i
].empty())
16451 itr
= m_spellMods
[i
].begin();
16457 // send Proficiency
16458 void Player::SendProficiency(uint8 pr1
, uint32 pr2
)
16460 WorldPacket
data(SMSG_SET_PROFICIENCY
, 8);
16461 data
<< pr1
<< pr2
;
16462 GetSession()->SendPacket (&data
);
16465 void Player::RemovePetitionsAndSigns(uint64 guid
, uint32 type
)
16467 QueryResult
*result
= NULL
;
16469 result
= CharacterDatabase
.PQuery("SELECT ownerguid,petitionguid FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid
));
16471 result
= CharacterDatabase
.PQuery("SELECT ownerguid,petitionguid FROM petition_sign WHERE playerguid = '%u' AND type = '%u'", GUID_LOPART(guid
), type
);
16474 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.
16475 { // and SendPetitionQueryOpcode reads data from the DB
16476 Field
*fields
= result
->Fetch();
16477 uint64 ownerguid
= MAKE_NEW_GUID(fields
[0].GetUInt32(), 0, HIGHGUID_PLAYER
);
16478 uint64 petitionguid
= MAKE_NEW_GUID(fields
[1].GetUInt32(), 0, HIGHGUID_ITEM
);
16480 // send update if charter owner in game
16481 Player
* owner
= objmgr
.GetPlayer(ownerguid
);
16483 owner
->GetSession()->SendPetitionQueryOpcode(petitionguid
);
16485 } while ( result
->NextRow() );
16490 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u'", GUID_LOPART(guid
));
16492 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE playerguid = '%u' AND type = '%u'", GUID_LOPART(guid
), type
);
16495 CharacterDatabase
.BeginTransaction();
16498 CharacterDatabase
.PExecute("DELETE FROM petition WHERE ownerguid = '%u'", GUID_LOPART(guid
));
16499 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE ownerguid = '%u'", GUID_LOPART(guid
));
16503 CharacterDatabase
.PExecute("DELETE FROM petition WHERE ownerguid = '%u' AND type = '%u'", GUID_LOPART(guid
), type
);
16504 CharacterDatabase
.PExecute("DELETE FROM petition_sign WHERE ownerguid = '%u' AND type = '%u'", GUID_LOPART(guid
), type
);
16506 CharacterDatabase
.CommitTransaction();
16509 void Player::SetRestBonus (float rest_bonus_new
)
16511 // Prevent resting on max level
16512 if(getLevel() >= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
16513 rest_bonus_new
= 0;
16515 if(rest_bonus_new
< 0)
16516 rest_bonus_new
= 0;
16518 float rest_bonus_max
= (float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP
)*1.5/2;
16520 if(rest_bonus_new
> rest_bonus_max
)
16521 m_rest_bonus
= rest_bonus_max
;
16523 m_rest_bonus
= rest_bonus_new
;
16525 // update data for client
16526 if(m_rest_bonus
>10)
16527 SetByteValue(PLAYER_BYTES_2
, 3, 0x01); // Set Reststate = Rested
16528 else if(m_rest_bonus
<=1)
16529 SetByteValue(PLAYER_BYTES_2
, 3, 0x02); // Set Reststate = Normal
16532 SetUInt32Value(PLAYER_REST_STATE_EXPERIENCE
, uint32(m_rest_bonus
));
16535 void Player::HandleStealthedUnitsDetection()
16537 std::list
<Unit
*> stealthedUnits
;
16539 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(),GetPositionY()));
16541 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
16542 cell
.SetNoCreate();
16544 MaNGOS::AnyStealthedCheck u_check
;
16545 MaNGOS::UnitListSearcher
<MaNGOS::AnyStealthedCheck
> searcher(stealthedUnits
, u_check
);
16547 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyStealthedCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
16548 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyStealthedCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
16550 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
16551 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *GetMap());
16552 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *GetMap());
16554 for (std::list
<Unit
*>::iterator i
= stealthedUnits
.begin(); i
!= stealthedUnits
.end();)
16558 i
= stealthedUnits
.erase(i
);
16562 if ((*i
)->isVisibleForOrDetect(this,true))
16565 (*i
)->SendUpdateToPlayer(this);
16566 m_clientGUIDs
.insert((*i
)->GetGUID());
16568 #ifdef MANGOS_DEBUG
16569 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
16570 sLog
.outDebug("Object %u (Type: %u) is detected in stealth by player %u. Distance = %f",(*i
)->GetGUIDLow(),(*i
)->GetTypeId(),GetGUIDLow(),GetDistance(*i
));
16573 // target aura duration for caster show only if target exist at caster client
16574 // send data at target visibility change (adding to client)
16575 if((*i
)!=this && (*i
)->isType(TYPEMASK_UNIT
))
16576 SendAurasForTarget(*i
);
16578 i
= stealthedUnits
.erase(i
);
16586 bool Player::ActivateTaxiPathTo(std::vector
<uint32
> const& nodes
, uint32 mount_id
, Creature
* npc
)
16588 if(nodes
.size() < 2)
16591 // not let cheating with start flight mounted
16594 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16595 data
<< uint32(ERR_TAXIPLAYERALREADYMOUNTED
);
16596 GetSession()->SendPacket(&data
);
16600 if( m_ShapeShiftFormSpellId
&& m_form
!= FORM_BATTLESTANCE
&& m_form
!= FORM_BERSERKERSTANCE
&& m_form
!= FORM_DEFENSIVESTANCE
&& m_form
!= FORM_SHADOW
)
16602 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16603 data
<< uint32(ERR_TAXIPLAYERSHAPESHIFTED
);
16604 GetSession()->SendPacket(&data
);
16608 // 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
16609 if(GetSession()->isLogingOut() ||
16610 (!m_currentSpells
[CURRENT_GENERIC_SPELL
] ||
16611 m_currentSpells
[CURRENT_GENERIC_SPELL
]->m_spellInfo
->Effect
[0] != SPELL_EFFECT_SEND_TAXI
)&&
16612 IsNonMeleeSpellCasted(false) ||
16615 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16616 data
<< uint32(ERR_TAXIPLAYERBUSY
);
16617 GetSession()->SendPacket(&data
);
16621 if(HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_DISABLE_MOVE
))
16624 uint32 sourcenode
= nodes
[0];
16626 // starting node too far away (cheat?)
16627 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(sourcenode
);
16628 if( !node
|| node
->map_id
!= GetMapId() ||
16629 (node
->x
- GetPositionX())*(node
->x
- GetPositionX())+
16630 (node
->y
- GetPositionY())*(node
->y
- GetPositionY())+
16631 (node
->z
- GetPositionZ())*(node
->z
- GetPositionZ()) >
16632 (2*INTERACTION_DISTANCE
)*(2*INTERACTION_DISTANCE
)*(2*INTERACTION_DISTANCE
) )
16634 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16635 data
<< uint32(ERR_TAXIUNSPECIFIEDSERVERERROR
);
16636 GetSession()->SendPacket(&data
);
16640 // Prepare to flight start now
16642 // stop combat at start taxi flight if any
16645 // stop trade (client cancel trade at taxi map open but cheating tools can be used for reopen it)
16648 // clean not finished taxi path if any
16649 m_taxi
.ClearTaxiDestinations();
16651 // 0 element current node
16652 m_taxi
.AddTaxiDestination(sourcenode
);
16654 // fill destinations path tail
16655 uint32 sourcepath
= 0;
16656 uint32 totalcost
= 0;
16658 uint32 prevnode
= sourcenode
;
16659 uint32 lastnode
= 0;
16661 for(uint32 i
= 1; i
< nodes
.size(); ++i
)
16665 lastnode
= nodes
[i
];
16666 objmgr
.GetTaxiPath(prevnode
, lastnode
, path
, cost
);
16670 m_taxi
.ClearTaxiDestinations();
16676 if(prevnode
== sourcenode
)
16679 m_taxi
.AddTaxiDestination(lastnode
);
16681 prevnode
= lastnode
;
16684 if(!mount_id
) // if not provide then attempt use default.
16685 mount_id
= objmgr
.GetTaxiMount(sourcenode
, GetTeam());
16687 if (mount_id
== 0 || sourcepath
== 0)
16689 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16690 data
<< uint32(ERR_TAXIUNSPECIFIEDSERVERERROR
);
16691 GetSession()->SendPacket(&data
);
16692 m_taxi
.ClearTaxiDestinations();
16696 uint32 money
= GetMoney();
16700 totalcost
= (uint32
)ceil(totalcost
*GetReputationPriceDiscount(npc
));
16703 if(money
< totalcost
)
16705 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16706 data
<< uint32(ERR_TAXINOTENOUGHMONEY
);
16707 GetSession()->SendPacket(&data
);
16708 m_taxi
.ClearTaxiDestinations();
16712 //Checks and preparations done, DO FLIGHT
16713 ModifyMoney(-(int32
)totalcost
);
16715 // prevent stealth flight
16716 RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
16718 WorldPacket
data(SMSG_ACTIVATETAXIREPLY
, 4);
16719 data
<< uint32(ERR_TAXIOK
);
16720 GetSession()->SendPacket(&data
);
16722 sLog
.outDebug("WORLD: Sent SMSG_ACTIVATETAXIREPLY");
16724 GetSession()->SendDoFlight(mount_id
, sourcepath
);
16729 void Player::ProhibitSpellScholl(SpellSchoolMask idSchoolMask
, uint32 unTimeMs
)
16731 // last check 2.0.10
16732 WorldPacket
data(SMSG_SPELL_COOLDOWN
, 8+1+m_spells
.size()*8);
16734 data
<< uint8(0x0); // flags (0x1, 0x2)
16735 time_t curTime
= time(NULL
);
16736 for(PlayerSpellMap::const_iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
16738 if (itr
->second
->state
== PLAYERSPELL_REMOVED
)
16740 uint32 unSpellId
= itr
->first
;
16741 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(unSpellId
);
16748 // Not send cooldown for this spells
16749 if (spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
16752 if((idSchoolMask
& GetSpellSchoolMask(spellInfo
)) && GetSpellCooldownDelay(unSpellId
) < unTimeMs
)
16755 data
<< unTimeMs
; // in m.secs
16756 AddSpellCooldown(unSpellId
, 0, curTime
+ unTimeMs
/1000);
16759 GetSession()->SendPacket(&data
);
16762 void Player::InitDataForForm(bool reapplyMods
)
16764 SpellShapeshiftEntry
const* ssEntry
= sSpellShapeshiftStore
.LookupEntry(m_form
);
16765 if(ssEntry
&& ssEntry
->attackSpeed
)
16767 SetAttackTime(BASE_ATTACK
,ssEntry
->attackSpeed
);
16768 SetAttackTime(OFF_ATTACK
,ssEntry
->attackSpeed
);
16769 SetAttackTime(RANGED_ATTACK
, BASE_ATTACK_TIME
);
16772 SetRegularAttackTime();
16778 if(getPowerType()!=POWER_ENERGY
)
16779 setPowerType(POWER_ENERGY
);
16783 case FORM_DIREBEAR
:
16785 if(getPowerType()!=POWER_RAGE
)
16786 setPowerType(POWER_RAGE
);
16789 default: // 0, for example
16791 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(getClass());
16792 if(cEntry
&& cEntry
->powerType
< MAX_POWERS
&& uint32(getPowerType()) != cEntry
->powerType
)
16793 setPowerType(Powers(cEntry
->powerType
));
16798 // update auras at form change, ignore this at mods reapply (.reset stats/etc) when form not change.
16800 UpdateEquipSpellsAtFormChange();
16802 UpdateAttackPowerAndDamage();
16803 UpdateAttackPowerAndDamage(true);
16806 // Return true is the bought item has a max count to force refresh of window by caller
16807 bool Player::BuyItemFromVendor(uint64 vendorguid
, uint32 item
, uint8 count
, uint64 bagguid
, uint8 slot
)
16809 // cheating attempt
16810 if(count
< 1) count
= 1;
16815 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( item
);
16818 SendBuyError( BUY_ERR_CANT_FIND_ITEM
, NULL
, item
, 0);
16822 Creature
*pCreature
= ObjectAccessor::GetNPCIfCanInteractWith(*this, vendorguid
,UNIT_NPC_FLAG_VENDOR
);
16825 sLog
.outDebug( "WORLD: BuyItemFromVendor - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(vendorguid
)) );
16826 SendBuyError( BUY_ERR_DISTANCE_TOO_FAR
, NULL
, item
, 0);
16830 VendorItemData
const* vItems
= pCreature
->GetVendorItems();
16831 if(!vItems
|| vItems
->Empty())
16833 SendBuyError( BUY_ERR_CANT_FIND_ITEM
, pCreature
, item
, 0);
16837 size_t vendor_slot
= vItems
->FindItemSlot(item
);
16838 if(vendor_slot
>= vItems
->GetItemCount())
16840 SendBuyError( BUY_ERR_CANT_FIND_ITEM
, pCreature
, item
, 0);
16844 VendorItem
const* crItem
= vItems
->m_items
[vendor_slot
];
16846 // check current item amount if it limited
16847 if( crItem
->maxcount
!= 0 )
16849 if(pCreature
->GetVendorItemCurrentCount(crItem
) < pProto
->BuyCount
* count
)
16851 SendBuyError( BUY_ERR_ITEM_ALREADY_SOLD
, pCreature
, item
, 0);
16856 if( uint32(GetReputationRank(pProto
->RequiredReputationFaction
)) < pProto
->RequiredReputationRank
)
16858 SendBuyError( BUY_ERR_REPUTATION_REQUIRE
, pCreature
, item
, 0);
16862 if(crItem
->ExtendedCost
)
16864 ItemExtendedCostEntry
const* iece
= sItemExtendedCostStore
.LookupEntry(crItem
->ExtendedCost
);
16867 sLog
.outError("Item %u have wrong ExtendedCost field value %u", pProto
->ItemId
, crItem
->ExtendedCost
);
16871 // honor points price
16872 if(GetHonorPoints() < (iece
->reqhonorpoints
* count
))
16874 SendEquipError(EQUIP_ERR_NOT_ENOUGH_HONOR_POINTS
, NULL
, NULL
);
16878 // arena points price
16879 if(GetArenaPoints() < (iece
->reqarenapoints
* count
))
16881 SendEquipError(EQUIP_ERR_NOT_ENOUGH_ARENA_POINTS
, NULL
, NULL
);
16886 for (uint8 i
= 0; i
< 5; ++i
)
16888 if(iece
->reqitem
[i
] && !HasItemCount(iece
->reqitem
[i
], (iece
->reqitemcount
[i
] * count
)))
16890 SendEquipError(EQUIP_ERR_VENDOR_MISSING_TURNINS
, NULL
, NULL
);
16895 // check for personal arena rating requirement
16896 if( GetMaxPersonalArenaRatingRequirement() < iece
->reqpersonalarenarating
)
16898 // probably not the proper equip err
16899 SendEquipError(EQUIP_ERR_CANT_EQUIP_RANK
,NULL
,NULL
);
16904 uint32 price
= pProto
->BuyPrice
* count
;
16906 // reputation discount
16907 price
= uint32(floor(price
* GetReputationPriceDiscount(pCreature
)));
16909 if( GetMoney() < price
)
16911 SendBuyError( BUY_ERR_NOT_ENOUGHT_MONEY
, pCreature
, item
, 0);
16915 uint8 bag
= 0; // init for case invalid bagGUID
16917 if (bagguid
!= NULL_BAG
&& slot
!= NULL_SLOT
)
16920 if( bagguid
== GetGUID() )
16922 bag
= INVENTORY_SLOT_BAG_0
;
16926 for (int i
= INVENTORY_SLOT_BAG_START
; i
< INVENTORY_SLOT_BAG_END
;i
++)
16928 pBag
= (Bag
*)GetItemByPos(INVENTORY_SLOT_BAG_0
,i
);
16931 if( bagguid
== pBag
->GetGUID() )
16941 if( IsInventoryPos( bag
, slot
) || (bagguid
== NULL_BAG
&& slot
== NULL_SLOT
) )
16943 ItemPosCountVec dest
;
16944 uint8 msg
= CanStoreNewItem( bag
, slot
, dest
, item
, pProto
->BuyCount
* count
);
16945 if( msg
!= EQUIP_ERR_OK
)
16947 SendEquipError( msg
, NULL
, NULL
);
16951 ModifyMoney( -(int32
)price
);
16952 if(crItem
->ExtendedCost
) // case for new honor system
16954 ItemExtendedCostEntry
const* iece
= sItemExtendedCostStore
.LookupEntry(crItem
->ExtendedCost
);
16955 if(iece
->reqhonorpoints
)
16956 ModifyHonorPoints( - int32(iece
->reqhonorpoints
* count
));
16957 if(iece
->reqarenapoints
)
16958 ModifyArenaPoints( - int32(iece
->reqarenapoints
* count
));
16959 for (uint8 i
= 0; i
< 5; ++i
)
16961 if(iece
->reqitem
[i
])
16962 DestroyItemCount(iece
->reqitem
[i
], (iece
->reqitemcount
[i
] * count
), true);
16966 if(Item
*it
= StoreNewItem( dest
, item
, true ))
16968 uint32 new_count
= pCreature
->UpdateVendorItemCurrentCount(crItem
,pProto
->BuyCount
* count
);
16970 WorldPacket
data(SMSG_BUY_ITEM
, (8+4+4+4));
16971 data
<< pCreature
->GetGUID();
16972 data
<< (uint32
)(vendor_slot
+1); // numbered from 1 at client
16973 data
<< (uint32
)(crItem
->maxcount
> 0 ? new_count
: 0xFFFFFFFF);
16974 data
<< (uint32
)count
;
16975 GetSession()->SendPacket(&data
);
16977 SendNewItem(it
, pProto
->BuyCount
*count
, true, false, false);
16980 else if( IsEquipmentPos( bag
, slot
) )
16983 uint8 msg
= CanEquipNewItem( slot
, dest
, item
, pProto
->BuyCount
* count
, false );
16984 if( msg
!= EQUIP_ERR_OK
)
16986 SendEquipError( msg
, NULL
, NULL
);
16990 ModifyMoney( -(int32
)price
);
16991 if(crItem
->ExtendedCost
) // case for new honor system
16993 ItemExtendedCostEntry
const* iece
= sItemExtendedCostStore
.LookupEntry(crItem
->ExtendedCost
);
16994 if(iece
->reqhonorpoints
)
16995 ModifyHonorPoints( - int32(iece
->reqhonorpoints
));
16996 if(iece
->reqarenapoints
)
16997 ModifyArenaPoints( - int32(iece
->reqarenapoints
));
16998 for (uint8 i
= 0; i
< 5; ++i
)
17000 if(iece
->reqitem
[i
])
17001 DestroyItemCount(iece
->reqitem
[i
], iece
->reqitemcount
[i
], true);
17005 if(Item
*it
= EquipNewItem( dest
, item
, pProto
->BuyCount
* count
, true ))
17007 uint32 new_count
= pCreature
->UpdateVendorItemCurrentCount(crItem
,pProto
->BuyCount
* count
);
17009 WorldPacket
data(SMSG_BUY_ITEM
, (8+4+4+4));
17010 data
<< pCreature
->GetGUID();
17011 data
<< (uint32
)(vendor_slot
+1); // numbered from 1 at client
17012 data
<< (uint32
)(crItem
->maxcount
> 0 ? new_count
: 0xFFFFFFFF);
17013 data
<< (uint32
)count
;
17014 GetSession()->SendPacket(&data
);
17016 SendNewItem(it
, pProto
->BuyCount
*count
, true, false, false);
17018 AutoUnequipOffhandIfNeed();
17023 SendEquipError( EQUIP_ERR_ITEM_DOESNT_GO_TO_SLOT
, NULL
, NULL
);
17027 return crItem
->maxcount
!=0;
17030 uint32
Player::GetMaxPersonalArenaRatingRequirement()
17032 // returns the maximal personal arena rating that can be used to purchase items requiring this condition
17033 // the personal rating of the arena team must match the required limit as well
17034 // so return max[in arenateams](min(personalrating[teamtype], teamrating[teamtype]))
17035 uint32 max_personal_rating
= 0;
17036 for(int i
= 0; i
< MAX_ARENA_SLOT
; ++i
)
17038 if(ArenaTeam
* at
= objmgr
.GetArenaTeamById(GetArenaTeamId(i
)))
17040 uint32 p_rating
= GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1
+ (i
* 6) + 5);
17041 uint32 t_rating
= at
->GetRating();
17042 p_rating
= p_rating
<t_rating
? p_rating
: t_rating
;
17043 if(max_personal_rating
< p_rating
)
17044 max_personal_rating
= p_rating
;
17047 return max_personal_rating
;
17050 void Player::UpdateHomebindTime(uint32 time
)
17052 // GMs never get homebind timer online
17053 if (m_InstanceValid
|| isGameMaster())
17055 if(m_HomebindTimer
) // instance valid, but timer not reset
17058 WorldPacket
data(SMSG_RAID_GROUP_ONLY
, 4+4);
17061 GetSession()->SendPacket(&data
);
17063 // instance is valid, reset homebind timer
17064 m_HomebindTimer
= 0;
17066 else if (m_HomebindTimer
> 0)
17068 if (time
>= m_HomebindTimer
)
17070 // teleport to homebind location
17071 TeleportTo(m_homebindMapId
, m_homebindX
, m_homebindY
, m_homebindZ
, GetOrientation());
17074 m_HomebindTimer
-= time
;
17078 // instance is invalid, start homebind timer
17079 m_HomebindTimer
= 60000;
17080 // send message to player
17081 WorldPacket
data(SMSG_RAID_GROUP_ONLY
, 4+4);
17082 data
<< m_HomebindTimer
;
17084 GetSession()->SendPacket(&data
);
17085 sLog
.outDebug("PLAYER: Player '%s' (GUID: %u) will be teleported to homebind in 60 seconds", GetName(),GetGUIDLow());
17089 void Player::UpdatePvP(bool state
, bool ovrride
)
17091 if(!state
|| ovrride
)
17094 if(Pet
* pet
= GetPet())
17095 pet
->SetPvP(state
);
17096 if(Unit
* charmed
= GetCharm())
17097 charmed
->SetPvP(state
);
17099 pvpInfo
.endTimer
= 0;
17103 if(pvpInfo
.endTimer
!= 0)
17104 pvpInfo
.endTimer
= time(NULL
);
17109 if(Pet
* pet
= GetPet())
17110 pet
->SetPvP(state
);
17111 if(Unit
* charmed
= GetCharm())
17112 charmed
->SetPvP(state
);
17117 void Player::AddSpellCooldown(uint32 spellid
, uint32 itemid
, time_t end_time
)
17121 sc
.itemid
= itemid
;
17122 m_spellCooldowns
[spellid
] = sc
;
17125 void Player::SendCooldownEvent(SpellEntry
const *spellInfo
)
17127 if ( !(spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
) )
17130 // Get spell cooldown
17131 int32 cooldown
= GetSpellRecoveryTime(spellInfo
);
17133 ApplySpellMod(spellInfo
->Id
, SPELLMOD_COOLDOWN
, cooldown
);
17137 AddSpellCooldown(spellInfo
->Id
, 0, time(NULL
) + cooldown
/ 1000);
17139 WorldPacket
data(SMSG_COOLDOWN_EVENT
, (4+8));
17140 data
<< spellInfo
->Id
;
17142 SendDirectMessage(&data
);
17144 //slot to be excluded while counting
17145 bool Player::EnchantmentFitsRequirements(uint32 enchantmentcondition
, int8 slot
)
17147 if(!enchantmentcondition
)
17150 SpellItemEnchantmentConditionEntry
const *Condition
= sSpellItemEnchantmentConditionStore
.LookupEntry(enchantmentcondition
);
17155 uint8 curcount
[4] = {0, 0, 0, 0};
17157 //counting current equipped gem colors
17158 for(uint8 i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_END
; ++i
)
17162 Item
*pItem2
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
);
17163 if(pItem2
&& pItem2
->GetProto()->Socket
[0].Color
)
17165 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
17167 uint32 enchant_id
= pItem2
->GetEnchantmentId(EnchantmentSlot(enchant_slot
));
17171 SpellItemEnchantmentEntry
const* enchantEntry
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
17175 uint32 gemid
= enchantEntry
->GemID
;
17179 ItemPrototype
const* gemProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(gemid
);
17183 GemPropertiesEntry
const* gemProperty
= sGemPropertiesStore
.LookupEntry(gemProto
->GemProperties
);
17187 uint8 GemColor
= gemProperty
->color
;
17189 for(uint8 b
= 0, tmpcolormask
= 1; b
< 4; b
++, tmpcolormask
<<= 1)
17191 if(tmpcolormask
& GemColor
)
17198 bool activate
= true;
17200 for(int i
= 0; i
< 5; i
++)
17202 if(!Condition
->Color
[i
])
17205 uint32 _cur_gem
= curcount
[Condition
->Color
[i
] - 1];
17207 // if have <CompareColor> use them as count, else use <value> from Condition
17208 uint32 _cmp_gem
= Condition
->CompareColor
[i
] ? curcount
[Condition
->CompareColor
[i
] - 1]: Condition
->Value
[i
];
17210 switch(Condition
->Comparator
[i
])
17212 case 2: // requires less <color> than (<value> || <comparecolor>) gems
17213 activate
&= (_cur_gem
< _cmp_gem
) ? true : false;
17215 case 3: // requires more <color> than (<value> || <comparecolor>) gems
17216 activate
&= (_cur_gem
> _cmp_gem
) ? true : false;
17218 case 5: // requires at least <color> than (<value> || <comparecolor>) gems
17219 activate
&= (_cur_gem
>= _cmp_gem
) ? true : false;
17224 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");
17229 void Player::CorrectMetaGemEnchants(uint8 exceptslot
, bool apply
)
17231 //cycle all equipped items
17232 for(uint32 slot
= EQUIPMENT_SLOT_START
; slot
< EQUIPMENT_SLOT_END
; ++slot
)
17234 //enchants for the slot being socketed are handled by Player::ApplyItemMods
17235 if(slot
== exceptslot
)
17238 Item
* pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, slot
);
17240 if(!pItem
|| !pItem
->GetProto()->Socket
[0].Color
)
17243 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
17245 uint32 enchant_id
= pItem
->GetEnchantmentId(EnchantmentSlot(enchant_slot
));
17249 SpellItemEnchantmentEntry
const* enchantEntry
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
17253 uint32 condition
= enchantEntry
->EnchantmentCondition
;
17256 //was enchant active with/without item?
17257 bool wasactive
= EnchantmentFitsRequirements(condition
, apply
? exceptslot
: -1);
17258 //should it now be?
17259 if(wasactive
^ EnchantmentFitsRequirements(condition
, apply
? -1 : exceptslot
))
17261 // ignore item gem conditions
17262 //if state changed, (dis)apply enchant
17263 ApplyEnchantment(pItem
,EnchantmentSlot(enchant_slot
),!wasactive
,true,true);
17270 //if false -> then toggled off if was on| if true -> toggled on if was off AND meets requirements
17271 void Player::ToggleMetaGemsActive(uint8 exceptslot
, bool apply
)
17273 //cycle all equipped items
17274 for(int slot
= EQUIPMENT_SLOT_START
; slot
< EQUIPMENT_SLOT_END
; ++slot
)
17276 //enchants for the slot being socketed are handled by WorldSession::HandleSocketOpcode(WorldPacket& recv_data)
17277 if(slot
== exceptslot
)
17280 Item
*pItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, slot
);
17282 if(!pItem
|| !pItem
->GetProto()->Socket
[0].Color
) //if item has no sockets or no item is equipped go to next item
17285 //cycle all (gem)enchants
17286 for(uint32 enchant_slot
= SOCK_ENCHANTMENT_SLOT
; enchant_slot
< SOCK_ENCHANTMENT_SLOT
+3; ++enchant_slot
)
17288 uint32 enchant_id
= pItem
->GetEnchantmentId(EnchantmentSlot(enchant_slot
));
17289 if(!enchant_id
) //if no enchant go to next enchant(slot)
17292 SpellItemEnchantmentEntry
const* enchantEntry
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
17296 //only metagems to be (de)activated, so only enchants with condition
17297 uint32 condition
= enchantEntry
->EnchantmentCondition
;
17299 ApplyEnchantment(pItem
,EnchantmentSlot(enchant_slot
), apply
);
17304 void Player::LeaveBattleground(bool teleportToEntryPoint
)
17306 if(BattleGround
*bg
= GetBattleGround())
17308 bool need_debuf
= bg
->isBattleGround() && (bg
->GetStatus() == STATUS_IN_PROGRESS
) && sWorld
.getConfig(CONFIG_BATTLEGROUND_CAST_DESERTER
);
17310 bg
->RemovePlayerAtLeave(GetGUID(), teleportToEntryPoint
, true);
17312 // call after remove to be sure that player resurrected for correct cast
17314 CastSpell(this, 26013, true); // Deserter
17318 bool Player::CanJoinToBattleground() const
17320 // check Deserter debuff
17321 if(GetDummyAura(26013))
17327 bool Player::CanReportAfkDueToLimit()
17329 // a player can complain about 15 people per 5 minutes
17330 if(m_bgAfkReportedCount
>= 15)
17332 ++m_bgAfkReportedCount
;
17336 ///This player has been blamed to be inactive in a battleground
17337 void Player::ReportedAfkBy(Player
* reporter
)
17339 BattleGround
*bg
= GetBattleGround();
17340 if(!bg
|| bg
!= reporter
->GetBattleGround() || GetTeam() != reporter
->GetTeam())
17343 // check if player has 'Idle' or 'Inactive' debuff
17344 if(m_bgAfkReporter
.find(reporter
->GetGUIDLow())==m_bgAfkReporter
.end() && !HasAura(43680,0) && !HasAura(43681,0) && reporter
->CanReportAfkDueToLimit())
17346 m_bgAfkReporter
.insert(reporter
->GetGUIDLow());
17347 // 3 players have to complain to apply debuff
17348 if(m_bgAfkReporter
.size() >= 3)
17350 // cast 'Idle' spell
17351 CastSpell(this, 43680, true);
17352 m_bgAfkReporter
.clear();
17357 bool Player::IsVisibleInGridForPlayer( Player
* pl
) const
17359 // gamemaster in GM mode see all, including ghosts
17360 if(pl
->isGameMaster() && GetSession()->GetSecurity() <= pl
->GetSession()->GetSecurity())
17363 // It seems in battleground everyone sees everyone, except the enemy-faction ghosts
17364 if (InBattleGround())
17366 if (!(isAlive() || m_deathTimer
> 0) && !IsFriendlyTo(pl
) )
17371 // Live player see live player or dead player with not realized corpse
17372 if(pl
->isAlive() || pl
->m_deathTimer
> 0)
17374 return isAlive() || m_deathTimer
> 0;
17377 // Ghost see other friendly ghosts, that's for sure
17378 if(!(isAlive() || m_deathTimer
> 0) && IsFriendlyTo(pl
))
17381 // Dead player see live players near own corpse
17384 Corpse
*corpse
= pl
->GetCorpse();
17387 // 20 - aggro distance for same level, 25 - max additional distance if player level less that creature level
17388 if(corpse
->IsWithinDistInMap(this,(20+25)*sWorld
.getRate(RATE_CREATURE_AGGRO
)))
17393 // and not see any other
17397 bool Player::IsVisibleGloballyFor( Player
* u
) const
17402 // Always can see self
17406 // Visible units, always are visible for all players
17407 if (GetVisibility() == VISIBILITY_ON
)
17410 // GMs are visible for higher gms (or players are visible for gms)
17411 if (u
->GetSession()->GetSecurity() > SEC_PLAYER
)
17412 return GetSession()->GetSecurity() <= u
->GetSession()->GetSecurity();
17414 // non faction visibility non-breakable for non-GMs
17415 if (GetVisibility() == VISIBILITY_OFF
)
17418 // non-gm stealth/invisibility not hide from global player lists
17422 void Player::UpdateVisibilityOf(WorldObject
* target
)
17424 if(HaveAtClient(target
))
17426 if(!target
->isVisibleForInState(this,true))
17428 target
->DestroyForPlayer(this);
17429 m_clientGUIDs
.erase(target
->GetGUID());
17431 #ifdef MANGOS_DEBUG
17432 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
17433 sLog
.outDebug("Object %u (Type: %u) out of range for player %u. Distance = %f",target
->GetGUIDLow(),target
->GetTypeId(),GetGUIDLow(),GetDistance(target
));
17439 if(target
->isVisibleForInState(this,false))
17441 target
->SendUpdateToPlayer(this);
17442 if(target
->GetTypeId()!=TYPEID_GAMEOBJECT
||!((GameObject
*)target
)->IsTransport())
17443 m_clientGUIDs
.insert(target
->GetGUID());
17445 #ifdef MANGOS_DEBUG
17446 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
17447 sLog
.outDebug("Object %u (Type: %u) is visible now for player %u. Distance = %f",target
->GetGUIDLow(),target
->GetTypeId(),GetGUIDLow(),GetDistance(target
));
17450 // target aura duration for caster show only if target exist at caster client
17451 // send data at target visibility change (adding to client)
17452 if(target
!=this && target
->isType(TYPEMASK_UNIT
))
17453 SendAurasForTarget((Unit
*)target
);
17455 if(target
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)target
)->isAlive())
17456 ((Creature
*)target
)->SendMonsterMoveWithSpeedToCurrentDestination(this);
17462 inline void UpdateVisibilityOf_helper(std::set
<uint64
>& s64
, T
* target
)
17464 s64
.insert(target
->GetGUID());
17468 inline void UpdateVisibilityOf_helper(std::set
<uint64
>& s64
, GameObject
* target
)
17470 if(!target
->IsTransport())
17471 s64
.insert(target
->GetGUID());
17475 void Player::UpdateVisibilityOf(T
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
)
17477 if(HaveAtClient(target
))
17479 if(!target
->isVisibleForInState(this,true))
17481 target
->BuildOutOfRangeUpdateBlock(&data
);
17482 m_clientGUIDs
.erase(target
->GetGUID());
17484 #ifdef MANGOS_DEBUG
17485 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
17486 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
));
17492 if(target
->isVisibleForInState(this,false))
17494 visibleNow
.insert(target
);
17495 target
->BuildUpdate(data_updates
);
17496 target
->BuildCreateUpdateBlockForPlayer(&data
, this);
17497 UpdateVisibilityOf_helper(m_clientGUIDs
,target
);
17499 #ifdef MANGOS_DEBUG
17500 if((sLog
.getLogFilter() & LOG_FILTER_VISIBILITY_CHANGES
)==0)
17501 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
));
17507 template void Player::UpdateVisibilityOf(Player
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17508 template void Player::UpdateVisibilityOf(Creature
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17509 template void Player::UpdateVisibilityOf(Corpse
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17510 template void Player::UpdateVisibilityOf(GameObject
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17511 template void Player::UpdateVisibilityOf(DynamicObject
* target
, UpdateData
& data
, UpdateDataMapType
& data_updates
, std::set
<WorldObject
*>& visibleNow
);
17513 void Player::InitPrimaryProffesions()
17515 SetFreePrimaryProffesions(sWorld
.getConfig(CONFIG_MAX_PRIMARY_TRADE_SKILL
));
17518 void Player::SendComboPoints()
17520 Unit
*combotarget
= ObjectAccessor::GetUnit(*this, m_comboTarget
);
17523 WorldPacket
data(SMSG_UPDATE_COMBO_POINTS
, combotarget
->GetPackGUID().size()+1);
17524 data
.append(combotarget
->GetPackGUID());
17525 data
<< uint8(m_comboPoints
);
17526 GetSession()->SendPacket(&data
);
17530 void Player::AddComboPoints(Unit
* target
, int8 count
)
17535 // without combo points lost (duration checked in aura)
17536 RemoveSpellsCausingAura(SPELL_AURA_RETAIN_COMBO_POINTS
);
17538 if(target
->GetGUID() == m_comboTarget
)
17540 m_comboPoints
+= count
;
17545 if(Unit
* target
= ObjectAccessor::GetUnit(*this,m_comboTarget
))
17546 target
->RemoveComboPointHolder(GetGUIDLow());
17548 m_comboTarget
= target
->GetGUID();
17549 m_comboPoints
= count
;
17551 target
->AddComboPointHolder(GetGUIDLow());
17554 if (m_comboPoints
> 5) m_comboPoints
= 5;
17555 if (m_comboPoints
< 0) m_comboPoints
= 0;
17560 void Player::ClearComboPoints()
17565 // without combopoints lost (duration checked in aura)
17566 RemoveSpellsCausingAura(SPELL_AURA_RETAIN_COMBO_POINTS
);
17572 if(Unit
* target
= ObjectAccessor::GetUnit(*this,m_comboTarget
))
17573 target
->RemoveComboPointHolder(GetGUIDLow());
17578 void Player::SetGroup(Group
*group
, int8 subgroup
)
17580 if(group
== NULL
) m_group
.unlink();
17583 // never use SetGroup without a subgroup unless you specify NULL for group
17584 assert(subgroup
>= 0);
17585 m_group
.link(group
, this);
17586 m_group
.setSubGroup((uint8
)subgroup
);
17590 void Player::SendInitialPacketsBeforeAddToMap()
17592 WorldPacket
data(SMSG_SET_REST_START_OBSOLETE
, 4);
17593 data
<< uint32(0); // unknown, may be rest state time or experience
17594 GetSession()->SendPacket(&data
);
17597 data
.Initialize(SMSG_BINDPOINTUPDATE
, 5*4);
17598 data
<< m_homebindX
<< m_homebindY
<< m_homebindZ
;
17599 data
<< (uint32
) m_homebindMapId
;
17600 data
<< (uint32
) m_homebindZoneId
;
17601 GetSession()->SendPacket(&data
);
17603 // SMSG_SET_PROFICIENCY
17604 // SMSG_UPDATE_AURA_DURATION
17607 data
.Initialize(SMSG_TUTORIAL_FLAGS
, 8*4);
17608 for (int i
= 0; i
< 8; ++i
)
17609 data
<< uint32( GetTutorialInt(i
) );
17610 GetSession()->SendPacket(&data
);
17612 SendInitialSpells();
17614 data
.Initialize(SMSG_SEND_UNLEARN_SPELLS
, 4);
17615 data
<< uint32(0); // count, for(count) uint32;
17616 GetSession()->SendPacket(&data
);
17618 SendInitialActionButtons();
17619 SendInitialReputations();
17620 m_achievementMgr
.SendAllAchievementData();
17621 UpdateZone(GetZoneId());
17622 SendInitWorldStates();
17624 // SMSG_SET_AURA_SINGLE
17626 data
.Initialize(SMSG_LOGIN_SETTIMESPEED
, 8);
17627 data
<< uint32(secsToTimeBitFields(sWorld
.GetGameTime()));
17628 data
<< (float)0.01666667f
; // game speed
17629 GetSession()->SendPacket( &data
);
17631 data
.Initialize(SMSG_TIME_SYNC_REQ
, 4); // new 2.0.x, enable movement
17632 data
<< uint32(0x00000000); // on blizz it increments periodically
17633 GetSession()->SendPacket(&data
);
17635 // set fly flag if in fly form or taxi flight to prevent visually drop at ground in showup moment
17636 if(HasAuraType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
) || isInFlight())
17637 AddUnitMovementFlag(MOVEMENTFLAG_FLYING2
);
17642 void Player::SendInitialPacketsAfterAddToMap()
17644 WorldPacket
data(SMSG_TIME_SYNC_REQ
, 4); // new 2.0.x, enable movement
17645 data
<< uint32(0x00000000); // on blizz it increments periodically
17646 GetSession()->SendPacket(&data
);
17648 CastSpell(this, 836, true); // LOGINEFFECT
17650 // set some aura effects that send packet to player client after add player to map
17651 // SendMessageToSet not send it to player not it map, only for aura that not changed anything at re-apply
17652 // same auras state lost at far teleport, send it one more time in this case also
17653 static const AuraType auratypes
[] =
17655 SPELL_AURA_MOD_FEAR
, SPELL_AURA_TRANSFORM
, SPELL_AURA_WATER_WALK
,
17656 SPELL_AURA_FEATHER_FALL
, SPELL_AURA_HOVER
, SPELL_AURA_SAFE_FALL
,
17657 SPELL_AURA_FLY
, SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
, SPELL_AURA_NONE
17659 for(AuraType
const* itr
= &auratypes
[0]; itr
&& itr
[0] != SPELL_AURA_NONE
; ++itr
)
17661 Unit::AuraList
const& auraList
= GetAurasByType(*itr
);
17662 if(!auraList
.empty())
17663 auraList
.front()->ApplyModifier(true,true);
17666 if(HasAuraType(SPELL_AURA_MOD_STUN
))
17667 SetMovement(MOVE_ROOT
);
17669 // manual send package (have code in ApplyModifier(true,true); that don't must be re-applied.
17670 if(HasAuraType(SPELL_AURA_MOD_ROOT
))
17672 WorldPacket
data(SMSG_FORCE_MOVE_ROOT
, 10);
17673 data
.append(GetPackGUID());
17675 SendMessageToSet(&data
,true);
17678 SendAurasForTarget(this);
17679 SendEnchantmentDurations(); // must be after add to map
17680 SendItemDurations(); // must be after add to map
17683 void Player::SendUpdateToOutOfRangeGroupMembers()
17685 if (m_groupUpdateMask
== GROUP_UPDATE_FLAG_NONE
)
17687 if(Group
* group
= GetGroup())
17688 group
->UpdatePlayerOutOfRange(this);
17690 m_groupUpdateMask
= GROUP_UPDATE_FLAG_NONE
;
17691 m_auraUpdateMask
= 0;
17692 if(Pet
*pet
= GetPet())
17693 pet
->ResetAuraUpdateMask();
17696 void Player::SendTransferAborted(uint32 mapid
, uint8 reason
, uint8 arg
)
17698 WorldPacket
data(SMSG_TRANSFER_ABORTED
, 4+2);
17699 data
<< uint32(mapid
);
17700 data
<< uint8(reason
); // transfer abort reason
17703 case TRANSFER_ABORT_INSUF_EXPAN_LVL
:
17704 case TRANSFER_ABORT_DIFFICULTY
:
17705 case TRANSFER_ABORT_UNIQUE_MESSAGE
:
17706 data
<< uint8(arg
);
17709 GetSession()->SendPacket(&data
);
17712 void Player::SendInstanceResetWarning(uint32 mapid
, uint32 time
)
17714 // type of warning, based on the time remaining until reset
17717 type
= RAID_INSTANCE_WELCOME
;
17718 else if(time
> 900 && time
<= 3600)
17719 type
= RAID_INSTANCE_WARNING_HOURS
;
17720 else if(time
> 300 && time
<= 900)
17721 type
= RAID_INSTANCE_WARNING_MIN
;
17723 type
= RAID_INSTANCE_WARNING_MIN_SOON
;
17724 WorldPacket
data(SMSG_RAID_INSTANCE_MESSAGE
, 4+4+4);
17725 data
<< uint32(type
);
17726 data
<< uint32(mapid
);
17727 data
<< uint32(time
);
17728 GetSession()->SendPacket(&data
);
17731 void Player::ApplyEquipCooldown( Item
* pItem
)
17733 for(int i
= 0; i
<5; ++i
)
17735 _Spell
const& spellData
= pItem
->GetProto()->Spells
[i
];
17738 if( !spellData
.SpellId
)
17741 // wrong triggering type (note: ITEM_SPELLTRIGGER_ON_NO_DELAY_USE not have cooldown)
17742 if( spellData
.SpellTrigger
!= ITEM_SPELLTRIGGER_ON_USE
)
17745 AddSpellCooldown(spellData
.SpellId
, pItem
->GetEntry(), time(NULL
) + 30);
17747 WorldPacket
data(SMSG_ITEM_COOLDOWN
, 12);
17748 data
<< pItem
->GetGUID();
17749 data
<< uint32(spellData
.SpellId
);
17750 GetSession()->SendPacket(&data
);
17754 void Player::resetSpells()
17756 // not need after this call
17757 if(HasAtLoginFlag(AT_LOGIN_RESET_SPELLS
))
17759 m_atLoginFlags
= m_atLoginFlags
& ~AT_LOGIN_RESET_SPELLS
;
17760 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login & ~ %u WHERE guid ='%u'", uint32(AT_LOGIN_RESET_SPELLS
), GetGUIDLow());
17763 // make full copy of map (spells removed and marked as deleted at another spell remove
17764 // and we can't use original map for safe iterative with visit each spell at loop end
17765 PlayerSpellMap smap
= GetSpellMap();
17767 for(PlayerSpellMap::const_iterator iter
= smap
.begin();iter
!= smap
.end(); ++iter
)
17768 removeSpell(iter
->first
); // only iter->first can be accessed, object by iter->second can be deleted already
17770 learnDefaultSpells();
17771 learnQuestRewardedSpells();
17774 void Player::learnDefaultSpells(bool loading
)
17776 // learn default race/class spells
17777 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(getRace(),getClass());
17778 std::list
<CreateSpellPair
>::const_iterator spell_itr
;
17779 for (spell_itr
= info
->spell
.begin(); spell_itr
!=info
->spell
.end(); ++spell_itr
)
17781 uint16 tspell
= spell_itr
->first
;
17784 sLog
.outDebug("PLAYER: Adding initial spell, id = %u",tspell
);
17785 if(loading
|| !spell_itr
->second
) // not care about passive spells or loading case
17786 addSpell(tspell
,spell_itr
->second
);
17787 else // but send in normal spell in game learn case
17788 learnSpell(tspell
);
17793 void Player::learnQuestRewardedSpells(Quest
const* quest
)
17795 uint32 spell_id
= quest
->GetRewSpellCast();
17797 // skip quests without rewarded spell
17801 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spell_id
);
17805 // check learned spells state
17806 bool found
= false;
17807 for(int i
=0; i
< 3; ++i
)
17809 if(spellInfo
->Effect
[i
] == SPELL_EFFECT_LEARN_SPELL
&& !HasSpell(spellInfo
->EffectTriggerSpell
[i
]))
17816 // skip quests with not teaching spell or already known spell
17820 // prevent learn non first rank unknown profession and second specialization for same profession)
17821 uint32 learned_0
= spellInfo
->EffectTriggerSpell
[0];
17822 if( spellmgr
.GetSpellRank(learned_0
) > 1 && !HasSpell(learned_0
) )
17824 // not have first rank learned (unlearned prof?)
17825 uint32 first_spell
= spellmgr
.GetFirstSpellInChain(learned_0
);
17826 if( !HasSpell(first_spell
) )
17829 SpellEntry
const *learnedInfo
= sSpellStore
.LookupEntry(learned_0
);
17834 if(learnedInfo
->Effect
[0]==SPELL_EFFECT_TRADE_SKILL
&& learnedInfo
->Effect
[1]==0)
17836 // search other specialization for same prof
17837 for(PlayerSpellMap::const_iterator itr
= m_spells
.begin(); itr
!= m_spells
.end(); ++itr
)
17839 if(itr
->second
->state
== PLAYERSPELL_REMOVED
|| itr
->first
==learned_0
)
17842 SpellEntry
const *itrInfo
= sSpellStore
.LookupEntry(itr
->first
);
17846 // compare only specializations
17847 if(itrInfo
->Effect
[0]!=SPELL_EFFECT_TRADE_SKILL
|| itrInfo
->Effect
[1]!=0)
17850 // compare same chain spells
17851 if(spellmgr
.GetFirstSpellInChain(itr
->first
) != first_spell
)
17854 // now we have 2 specialization, learn possible only if found is lesser specialization rank
17855 if(!spellmgr
.IsHighRankOfSpell(learned_0
,itr
->first
))
17861 CastSpell( this, spell_id
, true);
17864 void Player::learnQuestRewardedSpells()
17866 // learn spells received from quest completing
17867 for(QuestStatusMap::const_iterator itr
= mQuestStatus
.begin(); itr
!= mQuestStatus
.end(); ++itr
)
17869 // skip no rewarded quests
17870 if(!itr
->second
.m_rewarded
)
17873 Quest
const* quest
= objmgr
.GetQuestTemplate(itr
->first
);
17877 learnQuestRewardedSpells(quest
);
17881 void Player::learnSkillRewardedSpells(uint32 skill_id
)
17883 uint32 raceMask
= getRaceMask();
17884 uint32 classMask
= getClassMask();
17885 for (uint32 j
=0; j
<sSkillLineAbilityStore
.GetNumRows(); ++j
)
17887 SkillLineAbilityEntry
const *pAbility
= sSkillLineAbilityStore
.LookupEntry(j
);
17888 if (!pAbility
|| pAbility
->skillId
!=skill_id
|| pAbility
->learnOnGetSkill
!= ABILITY_LEARNED_ON_GET_PROFESSION_SKILL
)
17890 // Check race if set
17891 if (pAbility
->racemask
&& !(pAbility
->racemask
& raceMask
))
17893 // Check class if set
17894 if (pAbility
->classmask
&& !(pAbility
->classmask
& classMask
))
17897 if (sSpellStore
.LookupEntry(pAbility
->spellId
))
17899 // Ok need learn spell
17900 learnSpell(pAbility
->spellId
);
17905 void Player::learnSkillRewardedSpells()
17907 for (uint16 i
=0; i
< PLAYER_MAX_SKILLS
; i
++)
17909 if(!GetUInt32Value(PLAYER_SKILL_INDEX(i
)))
17912 uint32 pskill
= GetUInt32Value(PLAYER_SKILL_INDEX(i
)) & 0x0000FFFF;
17914 learnSkillRewardedSpells(pskill
);
17918 void Player::SendAurasForTarget(Unit
*target
)
17920 if(target
->GetVisibleAuras()->empty()) // speedup things
17923 WorldPacket
data(SMSG_AURA_UPDATE_ALL
);
17924 data
.append(target
->GetPackGUID());
17926 Unit::VisibleAuraMap
const *visibleAuras
= target
->GetVisibleAuras();
17927 for(Unit::VisibleAuraMap::const_iterator itr
= visibleAuras
->begin(); itr
!= visibleAuras
->end(); ++itr
)
17929 for(uint32 j
= 0; j
< 3; ++j
)
17931 if(Aura
*aura
= target
->GetAura(itr
->second
, j
))
17933 data
<< uint8(aura
->GetAuraSlot());
17934 data
<< uint32(aura
->GetId());
17938 uint8 auraFlags
= aura
->GetAuraFlags();
17940 data
<< uint8(auraFlags
);
17942 data
<< uint8(aura
->GetAuraLevel());
17944 data
<< uint8(aura
->m_procCharges
);
17946 if(!(auraFlags
& AFLAG_NOT_CASTER
))
17948 data
<< uint8(0); // packed GUID of someone (caster?)
17951 if(auraFlags
& AFLAG_DURATION
) // include aura duration
17953 data
<< uint32(aura
->GetAuraMaxDuration());
17954 data
<< uint32(aura
->GetAuraDuration());
17962 GetSession()->SendPacket(&data
);
17965 void Player::SetDailyQuestStatus( uint32 quest_id
)
17967 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
17969 if(!GetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
))
17971 SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
,quest_id
);
17972 m_lastDailyQuestTime
= time(NULL
); // last daily quest time
17973 m_DailyQuestChanged
= true;
17979 void Player::ResetDailyQuestStatus()
17981 for(uint32 quest_daily_idx
= 0; quest_daily_idx
< PLAYER_MAX_DAILY_QUESTS
; ++quest_daily_idx
)
17982 SetUInt32Value(PLAYER_FIELD_DAILY_QUESTS_1
+quest_daily_idx
,0);
17984 // DB data deleted in caller
17985 m_DailyQuestChanged
= false;
17986 m_lastDailyQuestTime
= 0;
17989 BattleGround
* Player::GetBattleGround() const
17991 if(GetBattleGroundId()==0)
17994 return sBattleGroundMgr
.GetBattleGround(GetBattleGroundId());
17997 bool Player::InArena() const
17999 BattleGround
*bg
= GetBattleGround();
18000 if(!bg
|| !bg
->isArena())
18006 bool Player::GetBGAccessByLevel(uint32 bgTypeId
) const
18008 BattleGround
*bg
= sBattleGroundMgr
.GetBattleGround(bgTypeId
);
18012 if(getLevel() < bg
->GetMinLevel() || getLevel() > bg
->GetMaxLevel())
18018 uint32
Player::GetMinLevelForBattleGroundQueueId(uint32 queue_id
)
18026 return 10*(queue_id
+1);
18029 uint32
Player::GetMaxLevelForBattleGroundQueueId(uint32 queue_id
)
18032 return 255; // hardcoded max level
18034 return 10*(queue_id
+2)-1;
18037 uint32
Player::GetBattleGroundQueueIdFromLevel() const
18039 uint32 level
= getLevel();
18042 else if (level
> 79)
18045 return level
/10 - 1; // 20..29 -> 1, 30-39 -> 2, ...
18048 float Player::GetReputationPriceDiscount( Creature
const* pCreature
) const
18050 FactionTemplateEntry
const* vendor_faction
= pCreature
->getFactionTemplateEntry();
18051 if(!vendor_faction
)
18054 ReputationRank rank
= GetReputationRank(vendor_faction
->faction
);
18055 if(rank
<= REP_NEUTRAL
)
18058 return 1.0f
- 0.05f
* (rank
- REP_NEUTRAL
);
18061 bool Player::IsSpellFitByClassAndRace( uint32 spell_id
) const
18063 uint32 racemask
= getRaceMask();
18064 uint32 classmask
= getClassMask();
18066 SkillLineAbilityMap::const_iterator lower
= spellmgr
.GetBeginSkillLineAbilityMap(spell_id
);
18067 SkillLineAbilityMap::const_iterator upper
= spellmgr
.GetEndSkillLineAbilityMap(spell_id
);
18069 for(SkillLineAbilityMap::const_iterator _spell_idx
= lower
; _spell_idx
!= upper
; ++_spell_idx
)
18071 // skip wrong race skills
18072 if( _spell_idx
->second
->racemask
&& (_spell_idx
->second
->racemask
& racemask
) == 0)
18075 // skip wrong class skills
18076 if( _spell_idx
->second
->classmask
&& (_spell_idx
->second
->classmask
& classmask
) == 0)
18082 bool Player::HasQuestForGO(int32 GOId
)
18084 for( QuestStatusMap::iterator i
= mQuestStatus
.begin( ); i
!= mQuestStatus
.end( ); ++i
)
18086 QuestStatusData qs
=i
->second
;
18087 if (qs
.m_status
== QUEST_STATUS_INCOMPLETE
)
18089 Quest
const* qinfo
= objmgr
.GetQuestTemplate(i
->first
);
18093 if(GetGroup() && GetGroup()->isRaidGroup() && qinfo
->GetType() != QUEST_TYPE_RAID
)
18096 for (int j
= 0; j
< QUEST_OBJECTIVES_COUNT
; j
++)
18098 if (qinfo
->ReqCreatureOrGOId
[j
]>=0) //skip non GO case
18101 if((-1)*GOId
== qinfo
->ReqCreatureOrGOId
[j
] && qs
.m_creatureOrGOcount
[j
] < qinfo
->ReqCreatureOrGOCount
[j
])
18109 void Player::UpdateForQuestsGO()
18111 if(m_clientGUIDs
.empty())
18115 WorldPacket packet
;
18116 for(ClientGUIDs::iterator itr
=m_clientGUIDs
.begin(); itr
!=m_clientGUIDs
.end(); ++itr
)
18118 if(IS_GAMEOBJECT_GUID(*itr
))
18120 GameObject
*obj
= HashMapHolder
<GameObject
>::Find(*itr
);
18122 obj
->BuildValuesUpdateBlockForPlayer(&udata
,this);
18125 udata
.BuildPacket(&packet
);
18126 GetSession()->SendPacket(&packet
);
18129 void Player::SummonIfPossible(bool agree
)
18133 m_summon_expire
= 0;
18137 // expire and auto declined
18138 if(m_summon_expire
< time(NULL
))
18141 // stop taxi flight at summon
18144 GetMotionMaster()->MovementExpired();
18145 m_taxi
.ClearTaxiDestinations();
18148 // drop flag at summon
18149 if(BattleGround
*bg
= GetBattleGround())
18150 bg
->EventPlayerDroppedFlag(this);
18152 m_summon_expire
= 0;
18154 TeleportTo(m_summon_mapid
, m_summon_x
, m_summon_y
, m_summon_z
,GetOrientation());
18157 void Player::RemoveItemDurations( Item
*item
)
18159 for(ItemDurationList::iterator itr
= m_itemDuration
.begin();itr
!= m_itemDuration
.end(); ++itr
)
18163 m_itemDuration
.erase(itr
);
18169 void Player::AddItemDurations( Item
*item
)
18171 if(item
->GetUInt32Value(ITEM_FIELD_DURATION
))
18173 m_itemDuration
.push_back(item
);
18174 item
->SendTimeUpdate(this);
18178 void Player::AutoUnequipOffhandIfNeed()
18180 Item
*offItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
);
18184 Item
*mainItem
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_MAINHAND
);
18186 if(!mainItem
|| mainItem
->GetProto()->InventoryType
!= INVTYPE_2HWEAPON
)
18189 ItemPosCountVec off_dest
;
18190 uint8 off_msg
= CanStoreItem( NULL_BAG
, NULL_SLOT
, off_dest
, offItem
, false );
18191 if( off_msg
== EQUIP_ERR_OK
)
18193 RemoveItem(INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
, true);
18194 StoreItem( off_dest
, offItem
, true );
18198 sLog
.outError("Player::EquipItem: Can's store offhand item at 2hand item equip for player (GUID: %u).",GetGUIDLow());
18202 bool Player::HasItemFitToSpellReqirements(SpellEntry
const* spellInfo
, Item
const* ignoreItem
)
18204 if(spellInfo
->EquippedItemClass
< 0)
18207 // scan other equipped items for same requirements (mostly 2 daggers/etc)
18208 // for optimize check 2 used cases only
18209 switch(spellInfo
->EquippedItemClass
)
18211 case ITEM_CLASS_WEAPON
:
18213 for(int i
= EQUIPMENT_SLOT_MAINHAND
; i
< EQUIPMENT_SLOT_TABARD
; ++i
)
18214 if(Item
*item
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
18215 if(item
!=ignoreItem
&& item
->IsFitToSpellRequirements(spellInfo
))
18219 case ITEM_CLASS_ARMOR
:
18221 // tabard not have dependent spells
18222 for(int i
= EQUIPMENT_SLOT_START
; i
< EQUIPMENT_SLOT_MAINHAND
; ++i
)
18223 if(Item
*item
= GetItemByPos( INVENTORY_SLOT_BAG_0
, i
))
18224 if(item
!=ignoreItem
&& item
->IsFitToSpellRequirements(spellInfo
))
18227 // shields can be equipped to offhand slot
18228 if(Item
*item
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_OFFHAND
))
18229 if(item
!=ignoreItem
&& item
->IsFitToSpellRequirements(spellInfo
))
18232 // ranged slot can have some armor subclasses
18233 if(Item
*item
= GetItemByPos( INVENTORY_SLOT_BAG_0
, EQUIPMENT_SLOT_RANGED
))
18234 if(item
!=ignoreItem
&& item
->IsFitToSpellRequirements(spellInfo
))
18240 sLog
.outError("HasItemFitToSpellReqirements: Not handled spell requirement for item class %u",spellInfo
->EquippedItemClass
);
18247 void Player::RemoveItemDependentAurasAndCasts( Item
* pItem
)
18249 AuraMap
& auras
= GetAuras();
18250 for(AuraMap::iterator itr
= auras
.begin(); itr
!= auras
.end(); )
18252 Aura
* aura
= itr
->second
;
18254 // skip passive (passive item dependent spells work in another way) and not self applied auras
18255 SpellEntry
const* spellInfo
= aura
->GetSpellProto();
18256 if(aura
->IsPassive() || aura
->GetCasterGUID()!=GetGUID())
18262 // skip if not item dependent or have alternative item
18263 if(HasItemFitToSpellReqirements(spellInfo
,pItem
))
18269 // no alt item, remove aura, restart check
18270 RemoveAurasDueToSpell(aura
->GetId());
18271 itr
= auras
.begin();
18274 // currently casted spells can be dependent from item
18275 for (uint32 i
= 0; i
< CURRENT_MAX_SPELL
; i
++)
18277 if( m_currentSpells
[i
] && m_currentSpells
[i
]->getState()!=SPELL_STATE_DELAYED
&&
18278 !HasItemFitToSpellReqirements(m_currentSpells
[i
]->m_spellInfo
,pItem
) )
18283 uint32
Player::GetResurrectionSpellId()
18285 // search priceless resurrection possibilities
18287 uint32 spell_id
= 0;
18288 AuraList
const& dummyAuras
= GetAurasByType(SPELL_AURA_DUMMY
);
18289 for(AuraList::const_iterator itr
= dummyAuras
.begin(); itr
!= dummyAuras
.end(); ++itr
)
18291 // Soulstone Resurrection // prio: 3 (max, non death persistent)
18292 if( prio
< 2 && (*itr
)->GetSpellProto()->SpellVisual
[0] == 99 && (*itr
)->GetSpellProto()->SpellIconID
== 92 )
18294 switch((*itr
)->GetId())
18296 case 20707: spell_id
= 3026; break; // rank 1
18297 case 20762: spell_id
= 20758; break; // rank 2
18298 case 20763: spell_id
= 20759; break; // rank 3
18299 case 20764: spell_id
= 20760; break; // rank 4
18300 case 20765: spell_id
= 20761; break; // rank 5
18301 case 27239: spell_id
= 27240; break; // rank 6
18303 sLog
.outError("Unhandled spell %%u: S.Resurrection",(*itr
)->GetId());
18309 // Twisting Nether // prio: 2 (max)
18310 else if((*itr
)->GetId()==23701 && roll_chance_i(10))
18317 // Reincarnation (passive spell) // prio: 1
18318 if(prio
< 1 && HasSpell(20608) && !HasSpellCooldown(21169) && HasItemCount(17030,1))
18324 bool Player::RewardPlayerAndGroupAtKill(Unit
* pVictim
)
18326 bool PvP
= pVictim
->isCharmedOwnedByPlayerOrPlayer();
18328 // prepare data for near group iteration (PvP and !PvP cases)
18330 bool honored_kill
= false;
18332 if(Group
*pGroup
= GetGroup())
18335 uint32 sum_level
= 0;
18336 Player
* member_with_max_level
= NULL
;
18337 Player
* not_gray_member_with_max_level
= NULL
;
18339 pGroup
->GetDataForXPAtKill(pVictim
,count
,sum_level
,member_with_max_level
,not_gray_member_with_max_level
);
18341 if(member_with_max_level
)
18343 /// not get Xp in PvP or no not gray players in group
18344 xp
= (PvP
|| !not_gray_member_with_max_level
) ? 0 : MaNGOS::XP::Gain(not_gray_member_with_max_level
, pVictim
);
18346 /// skip in check PvP case (for speed, not used)
18347 bool is_raid
= PvP
? false : sMapStore
.LookupEntry(GetMapId())->IsRaid() && pGroup
->isRaidGroup();
18348 bool is_dungeon
= PvP
? false : sMapStore
.LookupEntry(GetMapId())->IsDungeon();
18349 float group_rate
= MaNGOS::XP::xp_in_group_rate(count
,is_raid
);
18351 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
18353 Player
* pGroupGuy
= itr
->getSource();
18357 if(!pGroupGuy
->IsAtGroupRewardDistance(pVictim
))
18358 continue; // member (alive or dead) or his corpse at req. distance
18360 // honor can be in PvP and !PvP (racial leader) cases (for alive)
18361 if(pGroupGuy
->isAlive() && pGroupGuy
->RewardHonor(pVictim
,count
) && pGroupGuy
==this)
18362 honored_kill
= true;
18364 // xp and reputation only in !PvP case
18367 float rate
= group_rate
* float(pGroupGuy
->getLevel()) / sum_level
;
18369 // if is in dungeon then all receive full reputation at kill
18370 // rewarded any alive/dead/near_corpse group member
18371 pGroupGuy
->RewardReputation(pVictim
,is_dungeon
? 1.0f
: rate
);
18373 // XP updated only for alive group member
18374 if(pGroupGuy
->isAlive() && not_gray_member_with_max_level
&&
18375 pGroupGuy
->getLevel() <= not_gray_member_with_max_level
->getLevel())
18377 uint32 itr_xp
= (member_with_max_level
== not_gray_member_with_max_level
) ? uint32(xp
*rate
) : uint32((xp
*rate
/2)+1);
18379 pGroupGuy
->GiveXP(itr_xp
, pVictim
);
18380 if(Pet
* pet
= pGroupGuy
->GetPet())
18381 pet
->GivePetXP(itr_xp
/2);
18384 // quest objectives updated only for alive group member or dead but with not released body
18385 if(pGroupGuy
->isAlive()|| !pGroupGuy
->GetCorpse())
18387 // normal creature (not pet/etc) can be only in !PvP case
18388 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
18389 pGroupGuy
->KilledMonster(pVictim
->GetEntry(), pVictim
->GetGUID());
18395 else // if (!pGroup)
18397 xp
= PvP
? 0 : MaNGOS::XP::Gain(this, pVictim
);
18399 // honor can be in PvP and !PvP (racial leader) cases
18400 if(RewardHonor(pVictim
,1))
18401 honored_kill
= true;
18403 // xp and reputation only in !PvP case
18406 RewardReputation(pVictim
,1);
18407 GiveXP(xp
, pVictim
);
18409 if(Pet
* pet
= GetPet())
18410 pet
->GivePetXP(xp
);
18412 // normal creature (not pet/etc) can be only in !PvP case
18413 if(pVictim
->GetTypeId()==TYPEID_UNIT
)
18414 KilledMonster(pVictim
->GetEntry(),pVictim
->GetGUID());
18417 return xp
|| honored_kill
;
18420 bool Player::IsAtGroupRewardDistance(WorldObject
const* pRewardSource
) const
18422 if(pRewardSource
->GetDistance(this) <= sWorld
.getConfig(CONFIG_GROUP_XP_DISTANCE
))
18428 Corpse
* corpse
= GetCorpse();
18432 return pRewardSource
->GetDistance(corpse
) <= sWorld
.getConfig(CONFIG_GROUP_XP_DISTANCE
);
18435 uint32
Player::GetBaseWeaponSkillValue (WeaponAttackType attType
) const
18437 Item
* item
= GetWeaponForAttack(attType
,true);
18439 // unarmed only with base attack
18440 if(attType
!= BASE_ATTACK
&& !item
)
18443 // weapon skill or (unarmed for base attack)
18444 uint32 skill
= item
? item
->GetSkill() : SKILL_UNARMED
;
18445 return GetBaseSkillValue(skill
);
18448 void Player::ResurectUsingRequestData()
18450 ResurrectPlayer(0.0f
,false);
18452 if(GetMaxHealth() > m_resurrectHealth
)
18453 SetHealth( m_resurrectHealth
);
18455 SetHealth( GetMaxHealth() );
18457 if(GetMaxPower(POWER_MANA
) > m_resurrectMana
)
18458 SetPower(POWER_MANA
, m_resurrectMana
);
18460 SetPower(POWER_MANA
, GetMaxPower(POWER_MANA
) );
18462 SetPower(POWER_RAGE
, 0 );
18464 SetPower(POWER_ENERGY
, GetMaxPower(POWER_ENERGY
) );
18466 SpawnCorpseBones();
18468 TeleportTo(m_resurrectMap
, m_resurrectX
, m_resurrectY
, m_resurrectZ
, GetOrientation());
18471 void Player::SetClientControl(Unit
* target
, uint8 allowMove
)
18473 WorldPacket
data(SMSG_CLIENT_CONTROL_UPDATE
, target
->GetPackGUID().size()+1);
18474 data
.append(target
->GetPackGUID());
18475 data
<< uint8(allowMove
);
18476 GetSession()->SendPacket(&data
);
18479 void Player::UpdateZoneDependentAuras( uint32 newZone
)
18481 // remove new continent flight forms
18482 uint32 v_map
= GetVirtualMapForMapAndZone(GetMapId(), newZone
);
18483 if( !isGameMaster() && v_map
!= 530 && v_map
!= 571)
18485 RemoveSpellsCausingAura(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
);
18486 RemoveSpellsCausingAura(SPELL_AURA_FLY
);
18489 // Some spells applied at enter into zone (with subzones)
18491 // NOTE: these are removed by RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_CHANGE_MAP);
18492 if ( newZone
== 2367 ) // Old Hillsbrad Foothills
18494 uint32 spellid
= 0;
18496 if( GetTeam() == HORDE
)
18497 spellid
= getGender() == GENDER_FEMALE
? 35481 : 35480;
18498 // and some alliance races
18499 else if( getRace() == RACE_NIGHTELF
|| getRace() == RACE_DRAENEI
)
18500 spellid
= getGender() == GENDER_FEMALE
? 35483 : 35482;
18502 if(spellid
&& !HasAura(spellid
,0) )
18503 CastSpell(this,spellid
,true);
18507 void Player::UpdateAreaDependentAuras( uint32 newArea
)
18509 // remove auras from spells with area limitations
18510 for(AuraMap::iterator iter
= m_Auras
.begin(); iter
!= m_Auras
.end();)
18512 // use m_zoneUpdateId for speed: UpdateArea called from UpdateZone or instead UpdateZone in both cases m_zoneUpdateId up-to-date
18513 if(!IsSpellAllowedInLocation(iter
->second
->GetSpellProto(),GetMapId(),m_zoneUpdateId
,newArea
))
18519 // unmount if enter in this subzone
18521 RemoveSpellsCausingAura(SPELL_AURA_MOUNTED
);
18522 // Dragonmaw Illusion
18523 else if( newArea
== 3759 || newArea
== 3966 || newArea
== 3939 )
18525 if( GetDummyAura(40214) )
18527 if( !HasAura(40216,0) )
18528 CastSpell(this,40216,true);
18529 if( !HasAura(42016,0) )
18530 CastSpell(this,42016,true);
18535 uint32
Player::GetCorpseReclaimDelay(bool pvp
) const
18537 if( pvp
&& !sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVP
) ||
18538 !pvp
&& !sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE
) )
18540 return copseReclaimDelay
[0];
18543 time_t now
= time(NULL
);
18544 // 0..2 full period
18545 uint32 count
= (now
< m_deathExpireTime
) ? (m_deathExpireTime
- now
)/DEATH_EXPIRE_STEP
: 0;
18546 return copseReclaimDelay
[count
];
18549 void Player::UpdateCorpseReclaimDelay()
18551 bool pvp
= m_ExtraFlags
& PLAYER_EXTRA_PVP_DEATH
;
18553 if( pvp
&& !sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVP
) ||
18554 !pvp
&& !sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE
) )
18557 time_t now
= time(NULL
);
18558 if(now
< m_deathExpireTime
)
18560 // full and partly periods 1..3
18561 uint32 count
= (m_deathExpireTime
- now
)/DEATH_EXPIRE_STEP
+1;
18562 if(count
< MAX_DEATH_COUNT
)
18563 m_deathExpireTime
= now
+(count
+1)*DEATH_EXPIRE_STEP
;
18565 m_deathExpireTime
= now
+MAX_DEATH_COUNT
*DEATH_EXPIRE_STEP
;
18568 m_deathExpireTime
= now
+DEATH_EXPIRE_STEP
;
18571 void Player::SendCorpseReclaimDelay(bool load
)
18573 Corpse
* corpse
= GetCorpse();
18580 if(corpse
->GetGhostTime() > m_deathExpireTime
)
18583 bool pvp
= corpse
->GetType()==CORPSE_RESURRECTABLE_PVP
;
18586 if( pvp
&& sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVP
) ||
18587 !pvp
&& sWorld
.getConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE
) )
18589 count
= (m_deathExpireTime
-corpse
->GetGhostTime())/DEATH_EXPIRE_STEP
;
18590 if(count
>=MAX_DEATH_COUNT
)
18591 count
= MAX_DEATH_COUNT
-1;
18596 time_t expected_time
= corpse
->GetGhostTime()+copseReclaimDelay
[count
];
18598 time_t now
= time(NULL
);
18599 if(now
>= expected_time
)
18602 delay
= expected_time
-now
;
18605 delay
= GetCorpseReclaimDelay(corpse
->GetType()==CORPSE_RESURRECTABLE_PVP
);
18607 //! corpse reclaim delay 30 * 1000ms or longer at often deaths
18608 WorldPacket
data(SMSG_CORPSE_RECLAIM_DELAY
, 4);
18609 data
<< uint32(delay
*1000);
18610 GetSession()->SendPacket( &data
);
18613 Player
* Player::GetNextRandomRaidMember(float radius
)
18615 Group
*pGroup
= GetGroup();
18619 std::vector
<Player
*> nearMembers
;
18620 nearMembers
.reserve(pGroup
->GetMembersCount());
18622 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
18624 Player
* Target
= itr
->getSource();
18626 // IsHostileTo check duel and controlled by enemy
18627 if( Target
&& Target
!= this && IsWithinDistInMap(Target
, radius
) &&
18628 !Target
->HasInvisibilityAura() && !IsHostileTo(Target
) )
18629 nearMembers
.push_back(Target
);
18632 if (nearMembers
.empty())
18635 uint32 randTarget
= urand(0,nearMembers
.size()-1);
18636 return nearMembers
[randTarget
];
18639 void Player::UpdateUnderwaterState( Map
* m
, float x
, float y
, float z
)
18641 float water_z
= m
->GetWaterLevel(x
,y
);
18642 float height_z
= m
->GetHeight(x
,y
,z
, false); // use .map base surface height
18643 uint8 flag1
= m
->GetTerrainType(x
,y
);
18645 //!Underwater check, not in water if underground or above water level
18646 if (height_z
<= INVALID_HEIGHT
|| z
< (height_z
-2) || z
> (water_z
- 2) )
18647 m_isunderwater
&= 0x7A;
18648 else if ((z
< (water_z
- 2)) && (flag1
& 0x01))
18649 m_isunderwater
|= 0x01;
18651 //!in lava check, anywhere under lava level
18652 if ((height_z
<= INVALID_HEIGHT
|| z
< (height_z
- 0)) && (flag1
== 0x00) && IsInWater())
18653 m_isunderwater
|= 0x80;
18656 void Player::SetCanParry( bool value
)
18658 if(m_canParry
==value
)
18661 m_canParry
= value
;
18662 UpdateParryPercentage();
18665 void Player::SetCanBlock( bool value
)
18667 if(m_canBlock
==value
)
18670 m_canBlock
= value
;
18671 UpdateBlockPercentage();
18674 bool ItemPosCount::isContainedIn(ItemPosCountVec
const& vec
) const
18676 for(ItemPosCountVec::const_iterator itr
= vec
.begin(); itr
!= vec
.end();++itr
)
18677 if(itr
->pos
== pos
)
18683 bool Player::isAllowUseBattleGroundObject()
18685 return ( //InBattleGround() && // in battleground - not need, check in other cases
18686 !IsMounted() && // not mounted
18687 !HasStealthAura() && // not stealthed
18688 !HasInvisibilityAura() && // not invisible
18689 !HasAura(SPELL_RECENTLY_DROPPED_FLAG
, 0) && // can't pickup
18690 isAlive() // live player
18694 uint32
Player::GetBarberShopCost(uint8 newhairstyle
, uint8 newhaircolor
, uint8 newfacialhair
)
18696 uint32 level
= getLevel();
18698 if(level
> sGtBarberShopCostBaseStore
.GetNumRows())
18699 level
= GT_MAX_LEVEL
; // max level in this dbc
18701 uint8 hairstyle
= GetByteValue(PLAYER_BYTES
, 2);
18702 uint8 haircolor
= GetByteValue(PLAYER_BYTES
, 3);
18703 uint8 facialhair
= GetByteValue(PLAYER_BYTES_2
, 0);
18705 if((hairstyle
== newhairstyle
) && (haircolor
== newhaircolor
) && (facialhair
== newfacialhair
))
18708 GtBarberShopCostBaseEntry
const *bsc
= sGtBarberShopCostBaseStore
.LookupEntry(level
- 1);
18710 if(!bsc
) // shouldn't happen
18715 if(hairstyle
!= newhairstyle
)
18716 cost
+= bsc
->cost
; // full price
18718 if((haircolor
!= newhaircolor
) && (hairstyle
== newhairstyle
))
18719 cost
+= bsc
->cost
* 0.5f
; // +1/2 of price
18721 if(facialhair
!= newfacialhair
)
18722 cost
+= bsc
->cost
* 0.75f
; // +3/4 of price
18724 return uint32(cost
);
18727 void Player::InitGlyphsForLevel()
18729 uint32 level
= getLevel();
18732 // 0x3F = 0x01 | 0x02 | 0x04 | 0x08 | 0x10 | 0x20 for 80 level
18734 value
|= (0x01 | 0x02);
18744 SetUInt32Value(PLAYER_GLYPHS_ENABLED
, value
);
18747 void Player::EnterVehicle(Vehicle
*vehicle
)
18749 VehicleEntry
const *ve
= sVehicleStore
.LookupEntry(vehicle
->GetVehicleId());
18753 VehicleSeatEntry
const *veSeat
= sVehicleSeatStore
.LookupEntry(ve
->m_seatID
[0]);
18757 vehicle
->SetCharmerGUID(GetGUID());
18758 vehicle
->RemoveFlag(UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPELLCLICK
);
18759 vehicle
->SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNKNOWN5
);
18760 vehicle
->setFaction(getFaction());
18762 SetCharm(vehicle
); // charm
18763 SetFarSight(vehicle
->GetGUID()); // set view
18765 SetClientControl(vehicle
, 1); // redirect controls to vehicle
18767 WorldPacket
data(SMSG_SHOW_VEHICLE_UI
, 0); // shows vehicle UI?
18768 GetSession()->SendPacket(&data
);
18770 data
.Initialize(MSG_MOVE_TELEPORT_ACK
, 30);
18771 data
.append(GetPackGUID());
18772 data
<< uint32(0); // counter?
18773 data
<< uint32(MOVEMENTFLAG_ONTRANSPORT
); // transport
18774 data
<< uint16(0); // special flags
18775 data
<< uint32(getMSTime()); // time
18776 data
<< vehicle
->GetPositionX(); // x
18777 data
<< vehicle
->GetPositionY(); // y
18778 data
<< vehicle
->GetPositionZ(); // z
18779 data
<< vehicle
->GetOrientation(); // o
18780 // transport part, TODO: load/calculate seat offsets
18781 data
<< uint64(vehicle
->GetGUID()); // transport guid
18782 data
<< float(veSeat
->m_attachmentOffsetX
); // transport offsetX
18783 data
<< float(veSeat
->m_attachmentOffsetY
); // transport offsetY
18784 data
<< float(veSeat
->m_attachmentOffsetZ
); // transport offsetZ
18785 data
<< float(0); // transport orientation
18786 data
<< uint32(getMSTime()); // transport time
18787 data
<< uint8(0); // seat
18788 // end of transport part
18789 data
<< uint32(0); // fall time
18790 GetSession()->SendPacket(&data
);
18792 data
.Initialize(SMSG_PET_SPELLS
, 8+4+4+4+4*10+1+1);
18793 data
<< uint64(vehicle
->GetGUID());
18794 data
<< uint32(0x00000000);
18795 data
<< uint32(0x00000000);
18796 data
<< uint32(0x00000101);
18798 for(uint32 i
= 0; i
< 10; ++i
)
18799 data
<< uint16(0) << uint8(0) << uint8(i
+8);
18803 GetSession()->SendPacket(&data
);
18806 void Player::ExitVehicle(Vehicle
*vehicle
)
18808 vehicle
->SetCharmerGUID(0);
18809 vehicle
->SetFlag(UNIT_NPC_FLAGS
, UNIT_NPC_FLAG_SPELLCLICK
);
18810 vehicle
->RemoveFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNKNOWN5
);
18811 vehicle
->setFaction((GetTeam() == ALLIANCE
) ? vehicle
->GetCreatureInfo()->faction_A
: vehicle
->GetCreatureInfo()->faction_H
);
18816 SetClientControl(vehicle
, 0);
18818 WorldPacket
data(MSG_MOVE_TELEPORT_ACK
, 30);
18819 data
.append(GetPackGUID());
18820 data
<< uint32(0); // counter?
18821 data
<< uint32(MOVEMENTFLAG_FLY_UNK1
); // fly unk
18822 data
<< uint16(0x40); // special flags
18823 data
<< uint32(getMSTime()); // time
18824 data
<< vehicle
->GetPositionX(); // x
18825 data
<< vehicle
->GetPositionY(); // y
18826 data
<< vehicle
->GetPositionZ(); // z
18827 data
<< vehicle
->GetOrientation(); // o
18828 data
<< uint32(0); // fall time
18829 GetSession()->SendPacket(&data
);
18831 data
.Initialize(SMSG_PET_SPELLS
, 8+4);
18834 GetSession()->SendPacket(&data
);
18836 // only for flyable vehicles?
18837 CastSpell(this, 45472, true); // Parachute
18840 bool Player::HasTitle(uint32 bitIndex
)
18842 if (bitIndex
> 128)
18845 uint32 fieldIndexOffset
= bitIndex
/32;
18846 uint32 flag
= 1 << (bitIndex
%32);
18847 return HasFlag(PLAYER__FIELD_KNOWN_TITLES
+fieldIndexOffset
, flag
);
18850 void Player::SetTitle(CharTitlesEntry
const* title
)
18852 uint32 fieldIndexOffset
= title
->bit_index
/32;
18853 uint32 flag
= 1 << (title
->bit_index
%32);
18854 SetFlag(PLAYER__FIELD_KNOWN_TITLES
+fieldIndexOffset
, flag
);
18857 void Player::ConvertRune(uint8 index
, uint8 newType
)
18859 // SMSG_CONVERT_RUNE
18862 void Player::InitRunes()
18864 if(getClass() != CLASS_DEATH_KNIGHT
)
18867 m_runes
= new Runes
;
18869 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
18871 SetBaseRune(i
, i
/ 2);
18872 SetCurrentRune(i
, i
/ 2);
18873 SetRuneCooldown(i
, 0);
18876 for(uint32 i
= 0; i
< NUM_RUNES
; ++i
)
18877 SetFloatValue(PLAYER_RUNE_REGEN_1
+ i
, 0.1f
);