mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 22:37:02 +00:00
[10235] Cleanup in pet stable handlers
This commit is contained in:
parent
631a6a5e59
commit
e7093e3ebb
3 changed files with 62 additions and 50 deletions
|
|
@ -34,6 +34,16 @@
|
||||||
#include "Pet.h"
|
#include "Pet.h"
|
||||||
#include "Guild.h"
|
#include "Guild.h"
|
||||||
|
|
||||||
|
enum StableResultCode
|
||||||
|
{
|
||||||
|
STABLE_ERR_MONEY = 0x01, // "you don't have enough money"
|
||||||
|
STABLE_ERR_STABLE = 0x06, // currently used in most fail cases
|
||||||
|
STABLE_SUCCESS_STABLE = 0x08, // stable success
|
||||||
|
STABLE_SUCCESS_UNSTABLE = 0x09, // unstable/swap success
|
||||||
|
STABLE_SUCCESS_BUY_SLOT = 0x0A, // buy slot success
|
||||||
|
STABLE_ERR_EXOTIC = 0x0C, // "you are unable to control exotic creatures"
|
||||||
|
};
|
||||||
|
|
||||||
void WorldSession::HandleTabardVendorActivateOpcode( WorldPacket & recv_data )
|
void WorldSession::HandleTabardVendorActivateOpcode( WorldPacket & recv_data )
|
||||||
{
|
{
|
||||||
uint64 guid;
|
uint64 guid;
|
||||||
|
|
@ -452,14 +462,14 @@ void WorldSession::SendBindPoint(Creature *npc)
|
||||||
void WorldSession::HandleListStabledPetsOpcode( WorldPacket & recv_data )
|
void WorldSession::HandleListStabledPetsOpcode( WorldPacket & recv_data )
|
||||||
{
|
{
|
||||||
DEBUG_LOG("WORLD: Recv MSG_LIST_STABLED_PETS");
|
DEBUG_LOG("WORLD: Recv MSG_LIST_STABLED_PETS");
|
||||||
uint64 npcGUID;
|
ObjectGuid npcGUID;
|
||||||
|
|
||||||
recv_data >> npcGUID;
|
recv_data >> npcGUID;
|
||||||
|
|
||||||
Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER);
|
Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID.GetRawValue(), UNIT_NPC_FLAG_STABLEMASTER);
|
||||||
if (!unit)
|
if (!unit)
|
||||||
{
|
{
|
||||||
DEBUG_LOG( "WORLD: HandleListStabledPetsOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) );
|
DEBUG_LOG( "WORLD: HandleListStabledPetsOpcode - %s not found or you can't interact with him.", npcGUID.GetString().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -470,12 +480,12 @@ void WorldSession::HandleListStabledPetsOpcode( WorldPacket & recv_data )
|
||||||
SendStablePet(npcGUID);
|
SendStablePet(npcGUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldSession::SendStablePet(uint64 guid )
|
void WorldSession::SendStablePet( ObjectGuid guid )
|
||||||
{
|
{
|
||||||
DEBUG_LOG("WORLD: Recv MSG_LIST_STABLED_PETS Send.");
|
DEBUG_LOG("WORLD: Recv MSG_LIST_STABLED_PETS Send.");
|
||||||
|
|
||||||
WorldPacket data(MSG_LIST_STABLED_PETS, 200); // guess size
|
WorldPacket data(MSG_LIST_STABLED_PETS, 200); // guess size
|
||||||
data << uint64 ( guid );
|
data << guid;
|
||||||
|
|
||||||
Pet *pet = _player->GetPet();
|
Pet *pet = _player->GetPet();
|
||||||
|
|
||||||
|
|
@ -523,6 +533,13 @@ void WorldSession::SendStablePet(uint64 guid )
|
||||||
SendPacket(&data);
|
SendPacket(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldSession::SendStableResult(uint8 res)
|
||||||
|
{
|
||||||
|
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
||||||
|
data << uint8(res);
|
||||||
|
SendPacket(&data);
|
||||||
|
}
|
||||||
|
|
||||||
void WorldSession::HandleStablePet( WorldPacket & recv_data )
|
void WorldSession::HandleStablePet( WorldPacket & recv_data )
|
||||||
{
|
{
|
||||||
DEBUG_LOG("WORLD: Recv CMSG_STABLE_PET");
|
DEBUG_LOG("WORLD: Recv CMSG_STABLE_PET");
|
||||||
|
|
@ -531,12 +548,16 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data )
|
||||||
recv_data >> npcGUID;
|
recv_data >> npcGUID;
|
||||||
|
|
||||||
if(!GetPlayer()->isAlive())
|
if(!GetPlayer()->isAlive())
|
||||||
|
{
|
||||||
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER);
|
Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER);
|
||||||
if (!unit)
|
if (!unit)
|
||||||
{
|
{
|
||||||
DEBUG_LOG( "WORLD: HandleStablePet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) );
|
DEBUG_LOG( "WORLD: HandleStablePet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) );
|
||||||
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -549,9 +570,7 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data )
|
||||||
// can't place in stable dead pet
|
// can't place in stable dead pet
|
||||||
if(!pet||!pet->isAlive()||pet->getPetType()!=HUNTER_PET)
|
if(!pet||!pet->isAlive()||pet->getPetType()!=HUNTER_PET)
|
||||||
{
|
{
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
data << uint8(0x06);
|
|
||||||
SendPacket(&data);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -578,16 +597,13 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data )
|
||||||
delete result;
|
delete result;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
|
||||||
if( free_slot > 0 && free_slot <= GetPlayer()->m_stableSlots)
|
if( free_slot > 0 && free_slot <= GetPlayer()->m_stableSlots)
|
||||||
{
|
{
|
||||||
_player->RemovePet(pet,PetSaveMode(free_slot));
|
_player->RemovePet(pet,PetSaveMode(free_slot));
|
||||||
data << uint8(0x08);
|
SendStableResult(STABLE_SUCCESS_STABLE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
data << uint8(0x06);
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
|
|
||||||
SendPacket(&data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
|
void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
|
||||||
|
|
@ -602,6 +618,7 @@ void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
|
||||||
if (!unit)
|
if (!unit)
|
||||||
{
|
{
|
||||||
DEBUG_LOG( "WORLD: HandleUnstablePet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) );
|
DEBUG_LOG( "WORLD: HandleUnstablePet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) );
|
||||||
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -624,27 +641,25 @@ void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
|
||||||
|
|
||||||
if(!creature_id)
|
if(!creature_id)
|
||||||
{
|
{
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
data << uint8(0x06);
|
|
||||||
SendPacket(&data);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatureInfo const* creatureInfo = ObjectMgr::GetCreatureTemplate(creature_id);
|
CreatureInfo const* creatureInfo = ObjectMgr::GetCreatureTemplate(creature_id);
|
||||||
if(!creatureInfo || !creatureInfo->isTameable(_player->CanTameExoticPets()))
|
if(!creatureInfo || !creatureInfo->isTameable(_player->CanTameExoticPets()))
|
||||||
{
|
{
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
// if problem in exotic pet
|
||||||
data << uint8(0x06);
|
if (creatureInfo && creatureInfo->isTameable(true))
|
||||||
SendPacket(&data);
|
SendStableResult(STABLE_ERR_EXOTIC);
|
||||||
|
else
|
||||||
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pet* pet = _player->GetPet();
|
Pet* pet = _player->GetPet();
|
||||||
if(pet && pet->isAlive())
|
if(pet && pet->isAlive())
|
||||||
{
|
{
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
data << uint8(0x06);
|
|
||||||
SendPacket(&data);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -657,15 +672,11 @@ void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
|
||||||
{
|
{
|
||||||
delete newpet;
|
delete newpet;
|
||||||
newpet = NULL;
|
newpet = NULL;
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
data << uint8(0x06);
|
|
||||||
SendPacket(&data);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
SendStableResult(STABLE_SUCCESS_UNSTABLE);
|
||||||
data << uint8(0x09);
|
|
||||||
SendPacket(&data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data )
|
void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data )
|
||||||
|
|
@ -679,6 +690,7 @@ void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data )
|
||||||
if (!unit)
|
if (!unit)
|
||||||
{
|
{
|
||||||
DEBUG_LOG( "WORLD: HandleBuyStableSlot - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) );
|
DEBUG_LOG( "WORLD: HandleBuyStableSlot - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) );
|
||||||
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -686,8 +698,6 @@ void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data )
|
||||||
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
|
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
|
||||||
GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
|
GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
|
||||||
|
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 200);
|
|
||||||
|
|
||||||
if(GetPlayer()->m_stableSlots < MAX_PET_STABLES)
|
if(GetPlayer()->m_stableSlots < MAX_PET_STABLES)
|
||||||
{
|
{
|
||||||
StableSlotPricesEntry const *SlotPrice = sStableSlotPricesStore.LookupEntry(GetPlayer()->m_stableSlots+1);
|
StableSlotPricesEntry const *SlotPrice = sStableSlotPricesStore.LookupEntry(GetPlayer()->m_stableSlots+1);
|
||||||
|
|
@ -695,15 +705,13 @@ void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data )
|
||||||
{
|
{
|
||||||
++GetPlayer()->m_stableSlots;
|
++GetPlayer()->m_stableSlots;
|
||||||
_player->ModifyMoney(-int32(SlotPrice->Price));
|
_player->ModifyMoney(-int32(SlotPrice->Price));
|
||||||
data << uint8(0x0A); // success buy
|
SendStableResult(STABLE_SUCCESS_BUY_SLOT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
data << uint8(0x06);
|
SendStableResult(STABLE_ERR_MONEY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
data << uint8(0x06);
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
|
|
||||||
SendPacket(&data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldSession::HandleStableRevivePet( WorldPacket &/* recv_data */)
|
void WorldSession::HandleStableRevivePet( WorldPacket &/* recv_data */)
|
||||||
|
|
@ -723,6 +731,7 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data )
|
||||||
if (!unit)
|
if (!unit)
|
||||||
{
|
{
|
||||||
DEBUG_LOG( "WORLD: HandleStableSwapPet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) );
|
DEBUG_LOG( "WORLD: HandleStableSwapPet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) );
|
||||||
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -734,13 +743,19 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data )
|
||||||
Pet* pet = _player->GetPet();
|
Pet* pet = _player->GetPet();
|
||||||
|
|
||||||
if(!pet || pet->getPetType()!=HUNTER_PET)
|
if(!pet || pet->getPetType()!=HUNTER_PET)
|
||||||
|
{
|
||||||
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// find swapped pet slot in stable
|
// find swapped pet slot in stable
|
||||||
QueryResult *result = CharacterDatabase.PQuery("SELECT slot,entry FROM character_pet WHERE owner = '%u' AND id = '%u'",
|
QueryResult *result = CharacterDatabase.PQuery("SELECT slot,entry FROM character_pet WHERE owner = '%u' AND id = '%u'",
|
||||||
_player->GetGUIDLow(),pet_number);
|
_player->GetGUIDLow(),pet_number);
|
||||||
if(!result)
|
if(!result)
|
||||||
|
{
|
||||||
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Field *fields = result->Fetch();
|
Field *fields = result->Fetch();
|
||||||
|
|
||||||
|
|
@ -750,37 +765,33 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data )
|
||||||
|
|
||||||
if(!creature_id)
|
if(!creature_id)
|
||||||
{
|
{
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
data << uint8(0x06);
|
|
||||||
SendPacket(&data);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatureInfo const* creatureInfo = ObjectMgr::GetCreatureTemplate(creature_id);
|
CreatureInfo const* creatureInfo = ObjectMgr::GetCreatureTemplate(creature_id);
|
||||||
if(!creatureInfo || !creatureInfo->isTameable(_player->CanTameExoticPets()))
|
if(!creatureInfo || !creatureInfo->isTameable(_player->CanTameExoticPets()))
|
||||||
{
|
{
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1);
|
// if problem in exotic pet
|
||||||
data << uint8(0x06);
|
if (creatureInfo && creatureInfo->isTameable(true))
|
||||||
SendPacket(&data);
|
SendStableResult(STABLE_ERR_EXOTIC);
|
||||||
|
else
|
||||||
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// move alive pet to slot or delete dead pet
|
// move alive pet to slot or delete dead pet
|
||||||
_player->RemovePet(pet,pet->isAlive() ? PetSaveMode(slot) : PET_SAVE_AS_DELETED);
|
_player->RemovePet(pet,pet->isAlive() ? PetSaveMode(slot) : PET_SAVE_AS_DELETED);
|
||||||
|
|
||||||
WorldPacket data(SMSG_STABLE_RESULT, 1); // guess size
|
|
||||||
|
|
||||||
// summon unstabled pet
|
// summon unstabled pet
|
||||||
Pet *newpet = new Pet;
|
Pet *newpet = new Pet;
|
||||||
if(!newpet->LoadPetFromDB(_player,creature_id,pet_number))
|
if(!newpet->LoadPetFromDB(_player,creature_id,pet_number))
|
||||||
{
|
{
|
||||||
delete newpet;
|
delete newpet;
|
||||||
data << uint8(0x06);
|
SendStableResult(STABLE_ERR_STABLE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
data << uint8(0x09);
|
SendStableResult(STABLE_SUCCESS_UNSTABLE);
|
||||||
|
|
||||||
SendPacket(&data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldSession::HandleRepairItemOpcode( WorldPacket & recv_data )
|
void WorldSession::HandleRepairItemOpcode( WorldPacket & recv_data )
|
||||||
|
|
|
||||||
|
|
@ -225,14 +225,15 @@ class MANGOS_DLL_SPEC WorldSession
|
||||||
void SendBattlegGroundList( uint64 guid, BattleGroundTypeId bgTypeId );
|
void SendBattlegGroundList( uint64 guid, BattleGroundTypeId bgTypeId );
|
||||||
|
|
||||||
void SendTradeStatus(TradeStatus status);
|
void SendTradeStatus(TradeStatus status);
|
||||||
|
void SendUpdateTrade(bool trader_state = true);
|
||||||
void SendCancelTrade();
|
void SendCancelTrade();
|
||||||
|
|
||||||
void SendStablePet(uint64 guid );
|
|
||||||
void SendPetitionQueryOpcode( uint64 petitionguid);
|
void SendPetitionQueryOpcode( uint64 petitionguid);
|
||||||
void SendUpdateTrade(bool trader_state = true);
|
|
||||||
|
|
||||||
//pet
|
//pet
|
||||||
void SendPetNameQuery(uint64 guid, uint32 petnumber);
|
void SendPetNameQuery(uint64 guid, uint32 petnumber);
|
||||||
|
void SendStablePet(ObjectGuid guid );
|
||||||
|
void SendStableResult(uint8 res);
|
||||||
|
|
||||||
// Account Data
|
// Account Data
|
||||||
AccountData *GetAccountData(AccountDataType type) { return &m_accountData[type]; }
|
AccountData *GetAccountData(AccountDataType type) { return &m_accountData[type]; }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "10234"
|
#define REVISION_NR "10235"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue