2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "Database/DatabaseEnv.h"
22 #include "WorldPacket.h"
23 #include "WorldSession.h"
27 #include "ObjectMgr.h"
30 #include "GossipDef.h"
31 #include "SpellAuras.h"
32 #include "UpdateMask.h"
33 #include "ScriptCalls.h"
34 #include "ObjectAccessor.h"
36 #include "MapManager.h"
38 #include "BattleGroundMgr.h"
39 #include "BattleGround.h"
42 void WorldSession::HandleTabardVendorActivateOpcode( WorldPacket
& recv_data
)
44 CHECK_PACKET_SIZE(recv_data
,8);
49 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
,UNIT_NPC_FLAG_TABARDDESIGNER
);
52 sLog
.outDebug( "WORLD: HandleTabardVendorActivateOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid
)) );
57 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
58 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
60 SendTabardVendorActivate(guid
);
63 void WorldSession::SendTabardVendorActivate( uint64 guid
)
65 WorldPacket
data( MSG_TABARDVENDOR_ACTIVATE
, 8 );
70 void WorldSession::HandleBankerActivateOpcode( WorldPacket
& recv_data
)
72 CHECK_PACKET_SIZE(recv_data
,8);
76 sLog
.outDebug( "WORLD: Received CMSG_BANKER_ACTIVATE" );
80 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
,UNIT_NPC_FLAG_BANKER
);
83 sLog
.outDebug( "WORLD: HandleBankerActivateOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid
)) );
88 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
89 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
94 void WorldSession::SendShowBank( uint64 guid
)
96 WorldPacket
data( SMSG_SHOW_BANK
, 8 );
101 void WorldSession::HandleTrainerListOpcode( WorldPacket
& recv_data
)
103 CHECK_PACKET_SIZE(recv_data
,8);
108 SendTrainerList( guid
);
111 void WorldSession::SendTrainerList( uint64 guid
)
113 std::string str
= GetMangosString(LANG_NPC_TAINER_HELLO
);
114 SendTrainerList( guid
, str
);
117 void WorldSession::SendTrainerList( uint64 guid
, const std::string
& strTitle
)
119 sLog
.outDebug( "WORLD: SendTrainerList" );
121 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
,UNIT_NPC_FLAG_TRAINER
);
124 sLog
.outDebug( "WORLD: SendTrainerList - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid
)) );
129 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
130 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
132 // trainer list loaded at check;
133 if(!unit
->isCanTrainingOf(_player
,true))
136 CreatureInfo
const *ci
= unit
->GetCreatureInfo();
140 sLog
.outDebug( "WORLD: SendTrainerList - (GUID: %u) NO CREATUREINFO!",GUID_LOPART(guid
) );
144 TrainerSpellData
const* trainer_spells
= unit
->GetTrainerSpells();
147 sLog
.outDebug( "WORLD: SendTrainerList - Training spells not found for creature (GUID: %u Entry: %u)",
148 GUID_LOPART(guid
), unit
->GetEntry());
152 WorldPacket
data( SMSG_TRAINER_LIST
, 8+4+4+trainer_spells
->spellList
.size()*38 + strTitle
.size()+1);
154 data
<< uint32(trainer_spells
->trainerType
);
156 size_t count_pos
= data
.wpos();
157 data
<< uint32(trainer_spells
->spellList
.size());
159 // reputation discount
160 float fDiscountMod
= _player
->GetReputationPriceDiscount(unit
);
163 for(TrainerSpellList::const_iterator itr
= trainer_spells
->spellList
.begin(); itr
!= trainer_spells
->spellList
.end(); ++itr
)
165 TrainerSpell
const* tSpell
= *itr
;
167 if(!_player
->IsSpellFitByClassAndRace(tSpell
->learnedSpell
))
172 bool primary_prof_first_rank
= spellmgr
.IsPrimaryProfessionFirstRankSpell(tSpell
->learnedSpell
);
174 SpellChainNode
const* chain_node
= spellmgr
.GetSpellChainNode(tSpell
->learnedSpell
);
176 data
<< uint32(tSpell
->spell
); // learned spell (or cast-spell in profession case)
177 data
<< uint8(_player
->GetTrainerSpellState(tSpell
));
178 data
<< uint32(floor(tSpell
->spellCost
* fDiscountMod
));
180 data
<< uint32(primary_prof_first_rank
? 1 : 0); // primary prof. learn confirmation dialog
181 data
<< uint32(primary_prof_first_rank
? 1 : 0); // must be equal prev. field to have learn button in enabled state
182 data
<< uint8(tSpell
->reqLevel
);
183 data
<< uint32(tSpell
->reqSkill
);
184 data
<< uint32(tSpell
->reqSkillValue
);
185 data
<< uint32(chain_node
? (chain_node
->prev
? chain_node
->prev
: chain_node
->req
) : 0);
186 data
<< uint32(chain_node
&& chain_node
->prev
? chain_node
->req
: 0);
192 data
.put
<uint32
>(count_pos
,count
);
196 void WorldSession::HandleTrainerBuySpellOpcode( WorldPacket
& recv_data
)
198 CHECK_PACKET_SIZE(recv_data
,8+4);
203 recv_data
>> guid
>> spellId
;
204 sLog
.outDebug( "WORLD: Received CMSG_TRAINER_BUY_SPELL NpcGUID=%u, learn spell id is: %u",uint32(GUID_LOPART(guid
)), spellId
);
206 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
, UNIT_NPC_FLAG_TRAINER
);
209 sLog
.outDebug( "WORLD: HandleTrainerBuySpellOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid
)) );
214 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
215 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
217 if(!unit
->isCanTrainingOf(_player
,true))
220 // check present spell in trainer spell list
221 TrainerSpellData
const* trainer_spells
= unit
->GetTrainerSpells();
226 TrainerSpell
const* trainer_spell
= trainer_spells
->Find(spellId
);
230 // can't be learn, cheat? Or double learn with lags...
231 if(_player
->GetTrainerSpellState(trainer_spell
) != TRAINER_SPELL_GREEN
)
234 // apply reputation discount
235 uint32 nSpellCost
= uint32(floor(trainer_spell
->spellCost
* _player
->GetReputationPriceDiscount(unit
)));
237 // check money requirement
238 if(_player
->GetMoney() < nSpellCost
)
241 _player
->ModifyMoney( -int32(nSpellCost
) );
243 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 12); // visual effect on trainer
244 data
<< uint64(guid
) << uint32(0xB3);
247 data
.Initialize(SMSG_PLAY_SPELL_IMPACT
, 12); // visual effect on player
248 data
<< uint64(_player
->GetGUID()) << uint32(0x016A);
251 // learn explicitly or cast explicitly
252 if(trainer_spell
->IsCastable ())
253 //FIXME: prof. spell entry in trainer list not marked gray until list re-open.
254 _player
->CastSpell(_player
,trainer_spell
->spell
,true);
256 _player
->learnSpell(spellId
,false);
258 data
.Initialize(SMSG_TRAINER_BUY_SUCCEEDED
, 12);
259 data
<< uint64(guid
) << uint32(trainer_spell
->spell
);
263 void WorldSession::HandleGossipHelloOpcode( WorldPacket
& recv_data
)
265 CHECK_PACKET_SIZE(recv_data
,8);
267 sLog
.outDebug( "WORLD: Received CMSG_GOSSIP_HELLO" );
272 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
, UNIT_NPC_FLAG_NONE
);
275 sLog
.outDebug( "WORLD: HandleGossipHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid
)) );
280 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
281 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
283 if( unit
->isArmorer() || unit
->isCivilian() || unit
->isQuestGiver() || unit
->isServiceProvider())
288 // If spiritguide, no need for gossip menu, just put player into resurrect queue
289 if (unit
->isSpiritGuide())
291 BattleGround
*bg
= _player
->GetBattleGround();
294 bg
->AddPlayerToResurrectQueue(unit
->GetGUID(), _player
->GetGUID());
295 sBattleGroundMgr
.SendAreaSpiritHealerQueryOpcode(_player
, bg
, unit
->GetGUID());
300 if(!Script
->GossipHello( _player
, unit
))
302 _player
->TalkedToCreature(unit
->GetEntry(),unit
->GetGUID());
303 unit
->prepareGossipMenu(_player
);
304 unit
->sendPreparedGossip(_player
);
308 void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket
& recv_data
)
310 CHECK_PACKET_SIZE(recv_data
,8+4+4);
312 sLog
.outDebug("WORLD: CMSG_GOSSIP_SELECT_OPTION");
317 std::string code
= "";
319 recv_data
>> guid
>> unk
>> option
;
321 if(_player
->PlayerTalkClass
->GossipOptionCoded( option
))
324 CHECK_PACKET_SIZE(recv_data
,8+4+1);
325 sLog
.outBasic("reading string");
327 sLog
.outBasic("string read: %s", code
.c_str());
330 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
, UNIT_NPC_FLAG_NONE
);
333 sLog
.outDebug( "WORLD: HandleGossipSelectOptionOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid
)) );
338 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
339 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
343 if (!Script
->GossipSelectWithCode(_player
, unit
, _player
->PlayerTalkClass
->GossipOptionSender (option
), _player
->PlayerTalkClass
->GossipOptionAction( option
), code
.c_str()))
344 unit
->OnGossipSelect (_player
, option
);
348 if (!Script
->GossipSelect (_player
, unit
, _player
->PlayerTalkClass
->GossipOptionSender (option
), _player
->PlayerTalkClass
->GossipOptionAction (option
)))
349 unit
->OnGossipSelect (_player
, option
);
353 void WorldSession::HandleSpiritHealerActivateOpcode( WorldPacket
& recv_data
)
355 CHECK_PACKET_SIZE(recv_data
,8);
357 sLog
.outDebug("WORLD: CMSG_SPIRIT_HEALER_ACTIVATE");
363 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
, UNIT_NPC_FLAG_SPIRITHEALER
);
366 sLog
.outDebug( "WORLD: HandleSpiritHealerActivateOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid
)) );
371 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
372 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
374 SendSpiritResurrect();
377 void WorldSession::SendSpiritResurrect()
379 _player
->ResurrectPlayer(0.5f
, true);
381 _player
->DurabilityLossAll(0.25f
,true);
383 // get corpse nearest graveyard
384 WorldSafeLocsEntry
const *corpseGrave
= NULL
;
385 Corpse
*corpse
= _player
->GetCorpse();
387 corpseGrave
= objmgr
.GetClosestGraveYard(
388 corpse
->GetPositionX(), corpse
->GetPositionY(), corpse
->GetPositionZ(), corpse
->GetMapId(), _player
->GetTeam() );
390 // now can spawn bones
391 _player
->SpawnCorpseBones();
393 // teleport to nearest from corpse graveyard, if different from nearest to player ghost
396 WorldSafeLocsEntry
const *ghostGrave
= objmgr
.GetClosestGraveYard(
397 _player
->GetPositionX(), _player
->GetPositionY(), _player
->GetPositionZ(), _player
->GetMapId(), _player
->GetTeam() );
399 if(corpseGrave
!= ghostGrave
)
400 _player
->TeleportTo(corpseGrave
->map_id
, corpseGrave
->x
, corpseGrave
->y
, corpseGrave
->z
, _player
->GetOrientation());
401 // or update at original position
403 ObjectAccessor::UpdateVisibilityForPlayer(_player
);
405 // or update at original position
407 ObjectAccessor::UpdateVisibilityForPlayer(_player
);
412 void WorldSession::HandleBinderActivateOpcode( WorldPacket
& recv_data
)
414 CHECK_PACKET_SIZE(recv_data
,8);
417 recv_data
>> npcGUID
;
419 if(!GetPlayer()->isAlive())
422 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, npcGUID
,UNIT_NPC_FLAG_INNKEEPER
);
425 sLog
.outDebug( "WORLD: HandleBinderActivateOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID
)) );
430 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
431 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
436 void WorldSession::SendBindPoint(Creature
*npc
)
438 uint32 bindspell
= 3286;
440 // update sql homebind
441 CharacterDatabase
.PExecute("UPDATE character_homebind SET map = '%u', zone = '%u', position_x = '%f', position_y = '%f', position_z = '%f' WHERE guid = '%u'", _player
->GetMapId(), _player
->GetZoneId(), _player
->GetPositionX(), _player
->GetPositionY(), _player
->GetPositionZ(), _player
->GetGUIDLow());
442 _player
->m_homebindMapId
= _player
->GetMapId();
443 _player
->m_homebindZoneId
= _player
->GetZoneId();
444 _player
->m_homebindX
= _player
->GetPositionX();
445 _player
->m_homebindY
= _player
->GetPositionY();
446 _player
->m_homebindZ
= _player
->GetPositionZ();
448 // send spell for bind 3286 bind magic
449 npc
->CastSpell(_player
, bindspell
, true);
451 WorldPacket
data( SMSG_TRAINER_BUY_SUCCEEDED
, (8+4));
452 data
<< npc
->GetGUID();
457 data
.Initialize( SMSG_BINDPOINTUPDATE
, (4+4+4+4+4) );
458 data
<< float(_player
->GetPositionX());
459 data
<< float(_player
->GetPositionY());
460 data
<< float(_player
->GetPositionZ());
461 data
<< uint32(_player
->GetMapId());
462 data
<< uint32(_player
->GetZoneId());
465 DEBUG_LOG("New Home Position X is %f",_player
->GetPositionX());
466 DEBUG_LOG("New Home Position Y is %f",_player
->GetPositionY());
467 DEBUG_LOG("New Home Position Z is %f",_player
->GetPositionZ());
468 DEBUG_LOG("New Home MapId is %u",_player
->GetMapId());
469 DEBUG_LOG("New Home ZoneId is %u",_player
->GetZoneId());
472 data
.Initialize( SMSG_PLAYERBOUND
, 8+4 );
473 data
<< uint64(_player
->GetGUID());
474 data
<< uint32(_player
->GetZoneId());
477 _player
->PlayerTalkClass
->CloseGossip();
481 void WorldSession::HandleListStabledPetsOpcode( WorldPacket
& recv_data
)
483 CHECK_PACKET_SIZE(recv_data
,8);
485 sLog
.outDebug("WORLD: Recv MSG_LIST_STABLED_PETS");
488 recv_data
>> npcGUID
;
490 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, npcGUID
, UNIT_NPC_FLAG_STABLEMASTER
);
493 sLog
.outDebug( "WORLD: HandleListStabledPetsOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID
)) );
498 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
499 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
501 SendStablePet(npcGUID
);
504 void WorldSession::SendStablePet(uint64 guid
)
506 sLog
.outDebug("WORLD: Recv MSG_LIST_STABLED_PETS Send.");
508 WorldPacket
data(MSG_LIST_STABLED_PETS
, 200); // guess size
509 data
<< uint64 ( guid
);
511 Pet
*pet
= _player
->GetPet();
513 data
<< uint8(0); // place holder for slot show number
514 data
<< uint8(GetPlayer()->m_stableSlots
);
516 uint8 num
= 0; // counter for place holder
518 // not let move dead pet in slot
519 if(pet
&& pet
->isAlive() && pet
->getPetType()==HUNTER_PET
)
521 data
<< uint32(pet
->GetCharmInfo()->GetPetNumber());
522 data
<< uint32(pet
->GetEntry());
523 data
<< uint32(pet
->getLevel());
524 data
<< pet
->GetName(); // petname
525 data
<< uint8(0x01); // flags?, client slot 1 == current pet (0)
530 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT owner, slot, id, entry, level, name FROM character_pet WHERE owner = '%u' AND slot > 0 AND slot < 5",_player
->GetGUIDLow());
536 Field
*fields
= result
->Fetch();
538 data
<< uint32(fields
[2].GetUInt32()); // petnumber
539 data
<< uint32(fields
[3].GetUInt32()); // creature entry
540 data
<< uint32(fields
[4].GetUInt32()); // level
541 data
<< fields
[5].GetString(); // name
542 data
<< uint8(fields
[1].GetUInt32()+1); // slot
545 }while( result
->NextRow() );
550 data
.put
<uint8
>(8, num
); // set real data to placeholder
554 void WorldSession::HandleStablePet( WorldPacket
& recv_data
)
556 CHECK_PACKET_SIZE(recv_data
, 8);
558 sLog
.outDebug("WORLD: Recv CMSG_STABLE_PET");
561 recv_data
>> npcGUID
;
563 if(!GetPlayer()->isAlive())
566 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, npcGUID
, UNIT_NPC_FLAG_STABLEMASTER
);
569 sLog
.outDebug( "WORLD: HandleStablePet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID
)) );
574 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
575 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
577 Pet
*pet
= _player
->GetPet();
579 WorldPacket
data(SMSG_STABLE_RESULT
, 200); // guess size
581 // can't place in stable dead pet
582 if(!pet
||!pet
->isAlive()||pet
->getPetType()!=HUNTER_PET
)
589 uint32 free_slot
= 1;
591 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT owner,slot,id FROM character_pet WHERE owner = '%u' AND slot > 0 AND slot < 5 ORDER BY slot ",_player
->GetGUIDLow());
596 Field
*fields
= result
->Fetch();
598 uint32 slot
= fields
[1].GetUInt32();
600 if(slot
==free_slot
) // this slot not free
602 }while( result
->NextRow() );
606 if( free_slot
> 0 && free_slot
<= GetPlayer()->m_stableSlots
)
608 _player
->RemovePet(pet
,PetSaveMode(free_slot
));
617 void WorldSession::HandleUnstablePet( WorldPacket
& recv_data
)
619 CHECK_PACKET_SIZE(recv_data
, 8+4);
621 sLog
.outDebug("WORLD: Recv CMSG_UNSTABLE_PET.");
625 recv_data
>> npcGUID
>> petnumber
;
627 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, npcGUID
, UNIT_NPC_FLAG_STABLEMASTER
);
630 sLog
.outDebug( "WORLD: HandleUnstablePet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID
)) );
635 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
636 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
638 WorldPacket
data(SMSG_STABLE_RESULT
, 200); // guess size
640 Pet
* pet
= _player
->GetPet();
641 if(pet
&& pet
->isAlive())
651 _player
->RemovePet(pet
,PET_SAVE_AS_DELETED
);
655 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT entry FROM character_pet WHERE owner = '%u' AND id = '%u' AND slot > 0 AND slot < 5",_player
->GetGUIDLow(),petnumber
);
658 Field
*fields
= result
->Fetch();
659 uint32 petentry
= fields
[0].GetUInt32();
661 newpet
= new Pet(HUNTER_PET
);
662 if(!newpet
->LoadPetFromDB(_player
,petentry
,petnumber
))
677 void WorldSession::HandleBuyStableSlot( WorldPacket
& recv_data
)
679 CHECK_PACKET_SIZE(recv_data
, 8);
681 sLog
.outDebug("WORLD: Recv CMSG_BUY_STABLE_SLOT.");
684 recv_data
>> npcGUID
;
686 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, npcGUID
, UNIT_NPC_FLAG_STABLEMASTER
);
689 sLog
.outDebug( "WORLD: HandleBuyStableSlot - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID
)) );
694 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
695 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
697 WorldPacket
data(SMSG_STABLE_RESULT
, 200);
699 if(GetPlayer()->m_stableSlots
< 4) // max slots amount = 4
701 StableSlotPricesEntry
const *SlotPrice
= sStableSlotPricesStore
.LookupEntry(GetPlayer()->m_stableSlots
+1);
702 if(_player
->GetMoney() >= SlotPrice
->Price
)
704 ++GetPlayer()->m_stableSlots
;
705 _player
->ModifyMoney(-int32(SlotPrice
->Price
));
706 data
<< uint8(0x0A); // success buy
717 void WorldSession::HandleStableRevivePet( WorldPacket
&/* recv_data */)
719 sLog
.outDebug("HandleStableRevivePet: Not implemented");
722 void WorldSession::HandleStableSwapPet( WorldPacket
& recv_data
)
724 CHECK_PACKET_SIZE(recv_data
, 8+4);
726 sLog
.outDebug("WORLD: Recv CMSG_STABLE_SWAP_PET.");
730 recv_data
>> npcGUID
>> pet_number
;
732 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, npcGUID
, UNIT_NPC_FLAG_STABLEMASTER
);
735 sLog
.outDebug( "WORLD: HandleStableSwapPet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID
)) );
740 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
741 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
743 WorldPacket
data(SMSG_STABLE_RESULT
, 200); // guess size
745 Pet
* pet
= _player
->GetPet();
747 if(!pet
|| pet
->getPetType()!=HUNTER_PET
)
750 // find swapped pet slot in stable
751 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT slot,entry FROM character_pet WHERE owner = '%u' AND id = '%u'",_player
->GetGUIDLow(),pet_number
);
755 Field
*fields
= result
->Fetch();
757 uint32 slot
= fields
[0].GetUInt32();
758 uint32 petentry
= fields
[1].GetUInt32();
761 // move alive pet to slot or delele dead pet
762 _player
->RemovePet(pet
,pet
->isAlive() ? PetSaveMode(slot
) : PET_SAVE_AS_DELETED
);
764 // summon unstabled pet
765 Pet
*newpet
= new Pet
;
766 if(!newpet
->LoadPetFromDB(_player
,petentry
,pet_number
))
777 void WorldSession::HandleRepairItemOpcode( WorldPacket
& recv_data
)
779 CHECK_PACKET_SIZE(recv_data
, 8+8+1);
781 sLog
.outDebug("WORLD: CMSG_REPAIR_ITEM");
783 uint64 npcGUID
, itemGUID
;
784 uint8 guildBank
; // new in 2.3.2, bool that means from guild bank money
786 recv_data
>> npcGUID
>> itemGUID
>> guildBank
;
788 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, npcGUID
, UNIT_NPC_FLAG_REPAIR
);
791 sLog
.outDebug( "WORLD: HandleRepairItemOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID
)) );
796 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
797 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
799 // reputation discount
800 float discountMod
= _player
->GetReputationPriceDiscount(unit
);
802 uint32 TotalCost
= 0;
805 sLog
.outDebug("ITEM: Repair item, itemGUID = %u, npcGUID = %u", GUID_LOPART(itemGUID
), GUID_LOPART(npcGUID
));
807 Item
* item
= _player
->GetItemByGuid(itemGUID
);
810 TotalCost
= _player
->DurabilityRepair(item
->GetPos(),true,discountMod
,guildBank
>0?true:false);
814 sLog
.outDebug("ITEM: Repair all items, npcGUID = %u", GUID_LOPART(npcGUID
));
816 TotalCost
= _player
->DurabilityRepairAll(true,discountMod
,guildBank
>0?true:false);
820 uint32 GuildId
= _player
->GetGuildId();
823 Guild
*pGuild
= objmgr
.GetGuildById(GuildId
);
826 pGuild
->LogBankEvent(GUILD_BANK_LOG_REPAIR_MONEY
, 0, _player
->GetGUIDLow(), TotalCost
);
827 pGuild
->SendMoneyInfo(this, _player
->GetGUIDLow());