[10235] Cleanup in pet stable handlers

This commit is contained in:
VladimirMangos 2010-07-21 04:01:25 +04:00
parent 631a6a5e59
commit e7093e3ebb
3 changed files with 62 additions and 50 deletions

View file

@ -34,6 +34,16 @@
#include "Pet.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 )
{
uint64 guid;
@ -452,14 +462,14 @@ void WorldSession::SendBindPoint(Creature *npc)
void WorldSession::HandleListStabledPetsOpcode( WorldPacket & recv_data )
{
DEBUG_LOG("WORLD: Recv MSG_LIST_STABLED_PETS");
uint64 npcGUID;
ObjectGuid 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)
{
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;
}
@ -470,12 +480,12 @@ void WorldSession::HandleListStabledPetsOpcode( WorldPacket & recv_data )
SendStablePet(npcGUID);
}
void WorldSession::SendStablePet(uint64 guid )
void WorldSession::SendStablePet( ObjectGuid guid )
{
DEBUG_LOG("WORLD: Recv MSG_LIST_STABLED_PETS Send.");
WorldPacket data(MSG_LIST_STABLED_PETS, 200); // guess size
data << uint64 ( guid );
data << guid;
Pet *pet = _player->GetPet();
@ -523,6 +533,13 @@ void WorldSession::SendStablePet(uint64 guid )
SendPacket(&data);
}
void WorldSession::SendStableResult(uint8 res)
{
WorldPacket data(SMSG_STABLE_RESULT, 1);
data << uint8(res);
SendPacket(&data);
}
void WorldSession::HandleStablePet( WorldPacket & recv_data )
{
DEBUG_LOG("WORLD: Recv CMSG_STABLE_PET");
@ -531,12 +548,16 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data )
recv_data >> npcGUID;
if(!GetPlayer()->isAlive())
{
SendStableResult(STABLE_ERR_STABLE);
return;
}
Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER);
if (!unit)
{
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;
}
@ -549,9 +570,7 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data )
// can't place in stable dead pet
if(!pet||!pet->isAlive()||pet->getPetType()!=HUNTER_PET)
{
WorldPacket data(SMSG_STABLE_RESULT, 1);
data << uint8(0x06);
SendPacket(&data);
SendStableResult(STABLE_ERR_STABLE);
return;
}
@ -578,16 +597,13 @@ void WorldSession::HandleStablePet( WorldPacket & recv_data )
delete result;
}
WorldPacket data(SMSG_STABLE_RESULT, 1);
if( free_slot > 0 && free_slot <= GetPlayer()->m_stableSlots)
{
_player->RemovePet(pet,PetSaveMode(free_slot));
data << uint8(0x08);
SendStableResult(STABLE_SUCCESS_STABLE);
}
else
data << uint8(0x06);
SendPacket(&data);
SendStableResult(STABLE_ERR_STABLE);
}
void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
@ -602,6 +618,7 @@ void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
if (!unit)
{
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;
}
@ -624,27 +641,25 @@ void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
if(!creature_id)
{
WorldPacket data(SMSG_STABLE_RESULT, 1);
data << uint8(0x06);
SendPacket(&data);
SendStableResult(STABLE_ERR_STABLE);
return;
}
CreatureInfo const* creatureInfo = ObjectMgr::GetCreatureTemplate(creature_id);
if(!creatureInfo || !creatureInfo->isTameable(_player->CanTameExoticPets()))
{
WorldPacket data(SMSG_STABLE_RESULT, 1);
data << uint8(0x06);
SendPacket(&data);
// if problem in exotic pet
if (creatureInfo && creatureInfo->isTameable(true))
SendStableResult(STABLE_ERR_EXOTIC);
else
SendStableResult(STABLE_ERR_STABLE);
return;
}
Pet* pet = _player->GetPet();
if(pet && pet->isAlive())
{
WorldPacket data(SMSG_STABLE_RESULT, 1);
data << uint8(0x06);
SendPacket(&data);
SendStableResult(STABLE_ERR_STABLE);
return;
}
@ -657,15 +672,11 @@ void WorldSession::HandleUnstablePet( WorldPacket & recv_data )
{
delete newpet;
newpet = NULL;
WorldPacket data(SMSG_STABLE_RESULT, 1);
data << uint8(0x06);
SendPacket(&data);
SendStableResult(STABLE_ERR_STABLE);
return;
}
WorldPacket data(SMSG_STABLE_RESULT, 1);
data << uint8(0x09);
SendPacket(&data);
SendStableResult(STABLE_SUCCESS_UNSTABLE);
}
void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data )
@ -679,6 +690,7 @@ void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data )
if (!unit)
{
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;
}
@ -686,8 +698,6 @@ void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data )
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
WorldPacket data(SMSG_STABLE_RESULT, 200);
if(GetPlayer()->m_stableSlots < MAX_PET_STABLES)
{
StableSlotPricesEntry const *SlotPrice = sStableSlotPricesStore.LookupEntry(GetPlayer()->m_stableSlots+1);
@ -695,15 +705,13 @@ void WorldSession::HandleBuyStableSlot( WorldPacket & recv_data )
{
++GetPlayer()->m_stableSlots;
_player->ModifyMoney(-int32(SlotPrice->Price));
data << uint8(0x0A); // success buy
SendStableResult(STABLE_SUCCESS_BUY_SLOT);
}
else
data << uint8(0x06);
SendStableResult(STABLE_ERR_MONEY);
}
else
data << uint8(0x06);
SendPacket(&data);
SendStableResult(STABLE_ERR_STABLE);
}
void WorldSession::HandleStableRevivePet( WorldPacket &/* recv_data */)
@ -723,6 +731,7 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data )
if (!unit)
{
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;
}
@ -734,13 +743,19 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data )
Pet* pet = _player->GetPet();
if(!pet || pet->getPetType()!=HUNTER_PET)
{
SendStableResult(STABLE_ERR_STABLE);
return;
}
// find swapped pet slot in stable
QueryResult *result = CharacterDatabase.PQuery("SELECT slot,entry FROM character_pet WHERE owner = '%u' AND id = '%u'",
_player->GetGUIDLow(),pet_number);
if(!result)
{
SendStableResult(STABLE_ERR_STABLE);
return;
}
Field *fields = result->Fetch();
@ -750,37 +765,33 @@ void WorldSession::HandleStableSwapPet( WorldPacket & recv_data )
if(!creature_id)
{
WorldPacket data(SMSG_STABLE_RESULT, 1);
data << uint8(0x06);
SendPacket(&data);
SendStableResult(STABLE_ERR_STABLE);
return;
}
CreatureInfo const* creatureInfo = ObjectMgr::GetCreatureTemplate(creature_id);
if(!creatureInfo || !creatureInfo->isTameable(_player->CanTameExoticPets()))
{
WorldPacket data(SMSG_STABLE_RESULT, 1);
data << uint8(0x06);
SendPacket(&data);
// if problem in exotic pet
if (creatureInfo && creatureInfo->isTameable(true))
SendStableResult(STABLE_ERR_EXOTIC);
else
SendStableResult(STABLE_ERR_STABLE);
return;
}
// move alive pet to slot or delete dead pet
_player->RemovePet(pet,pet->isAlive() ? PetSaveMode(slot) : PET_SAVE_AS_DELETED);
WorldPacket data(SMSG_STABLE_RESULT, 1); // guess size
// summon unstabled pet
Pet *newpet = new Pet;
if(!newpet->LoadPetFromDB(_player,creature_id,pet_number))
{
delete newpet;
data << uint8(0x06);
SendStableResult(STABLE_ERR_STABLE);
}
else
data << uint8(0x09);
SendPacket(&data);
SendStableResult(STABLE_SUCCESS_UNSTABLE);
}
void WorldSession::HandleRepairItemOpcode( WorldPacket & recv_data )