void WorldSession::HandleStablePetCallback(PreparedQueryResult result) { if (!GetPlayer()) return; uint8 freeSlot = 1; if (result) { do { Field* fields = result->Fetch(); uint8 slot = fields[1].GetUInt8(); // slots ordered in query, and if not equal then free if (slot != freeSlot) break; // this slot not free, skip ++freeSlot; } while (result->NextRow()); } if (freeSlot > 0 && freeSlot <= GetPlayer()->m_stableSlots) { _player->RemovePet(_player->GetPet(), PetSaveMode(freeSlot)); SendStableResult(STABLE_SUCCESS_STABLE); } else SendStableResult(STABLE_ERR_INVALID_SLOT); }
void WorldSession::HandleStablePet(WorldPacket& recv_data) { sLog->outDebug("WORLD: Recv CMSG_STABLE_PET"); uint64 npcGUID; recv_data >> npcGUID; if (!GetPlayer()->isAlive()) return; Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER); if (!unit) { sLog->outDebug("WORLD: HandleStablePet - Unit (GUID: %u) not found or you can not interact with him.", uint32(GUID_LOPART(npcGUID))); return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); Pet *pet = _player->GetPet(); WorldPacket data(SMSG_STABLE_RESULT, 200); // guess size // can't place in stable dead pet if (!pet||!pet->isAlive()||pet->getPetType() != HUNTER_PET) { data << uint8(0x06); SendPacket(&data); return; } uint32 free_slot = 1; QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT owner, slot, id FROM character_pet WHERE owner = '%u' AND slot > 0 AND slot < 3 ORDER BY slot ", _player->GetGUIDLow()); if (result) { do { Field *fields = result->Fetch(); uint32 slot = fields[1].GetUInt32(); if (slot == free_slot) // this slot not free ++free_slot; }while (result->NextRow()); } if (free_slot > 0 && free_slot <= GetPlayer()->m_stableSlots) { _player->RemovePet(pet, PetSaveMode(free_slot)); data << uint8(0x08); } else data << uint8(0x06); SendPacket(&data); }
void WorldSession::HandleStableSwapPetCallback(PreparedQueryResult result, uint32 petId) { if (!GetPlayer()) return; if (!result) { SendStableResult(STABLE_ERR_STABLE); return; } Field* fields = result->Fetch(); uint32 slot = fields[0].GetUInt8(); uint32 petEntry = fields[1].GetUInt32(); if (!petEntry) { SendStableResult(STABLE_ERR_STABLE); return; } CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(petEntry); if (!creatureInfo || !creatureInfo->IsTameable(true)) { SendStableResult(STABLE_ERR_STABLE); return; } if (!creatureInfo->IsTameable(_player->CanTameExoticPets())) { SendStableResult(STABLE_ERR_EXOTIC); return; } Pet* pet = _player->GetPet(); // The player's pet could have been removed during the delay of the DB callback if (!pet) { 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); // summon unstabled pet Pet* newPet = new Pet(_player); if (!newPet->LoadPetFromDB(_player, petEntry, petId)) { delete newPet; SendStableResult(STABLE_ERR_STABLE); } else { SendStableResult(STABLE_SUCCESS_UNSTABLE); _player->SetPetSlot(slot); } }
void WorldSession::HandleStableSwapPet(WorldPacket& recv_data) { sLog->outDebug("WORLD: Recv CMSG_STABLE_SWAP_PET."); uint64 npcGUID; uint32 pet_number; recv_data >> npcGUID >> pet_number; Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER); if (!unit) { sLog->outDebug("WORLD: HandleStableSwapPet - Unit (GUID: %u) not found or you can not interact with him.", uint32(GUID_LOPART(npcGUID))); return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); WorldPacket data(SMSG_STABLE_RESULT, 200); // guess size Pet* pet = _player->GetPet(); if (!pet || pet->getPetType() != HUNTER_PET) return; // find swapped pet slot in stable QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT slot, entry FROM character_pet WHERE owner = '%u' AND id = '%u'", _player->GetGUIDLow(), pet_number); if (!result) return; Field *fields = result->Fetch(); uint32 slot = fields[0].GetUInt32(); uint32 petentry = fields[1].GetUInt32(); // move alive pet to slot or delele dead pet _player->RemovePet(pet, pet->isAlive() ? PetSaveMode(slot) : PET_SAVE_AS_DELETED); // summon unstabled pet Pet *newpet = new Pet(_player); if (!newpet->LoadPetFromDB(_player, petentry, pet_number)) { delete newpet; data << uint8(0x06); } else data << uint8(0x09); SendPacket(&data); }
void WorldSession::HandleStableSwapPetCallback(QueryResult result, uint32 petnumber) { if (!GetPlayer()) return; if (!result) { SendStableResult(STABLE_ERR_STABLE); return; } Field* fields = result->Fetch(); uint32 slot = fields[0].GetUInt8(); uint32 creature_id = fields[1].GetUInt32(); if (!creature_id) { SendStableResult(STABLE_ERR_STABLE); return; } CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(creature_id); if (!creatureInfo || !creatureInfo->isTameable(_player->CanTameExoticPets())) { // 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 Pet* pet = _player->GetPet(); _player->RemovePet(pet, pet->isAlive() ? PetSaveMode(slot) : PET_SAVE_AS_DELETED); // summon unstabled pet Pet* newpet = new Pet(_player); if (!newpet->LoadPetFromDB(_player, creature_id, petnumber)) { delete newpet; SendStableResult(STABLE_ERR_STABLE); } else SendStableResult(STABLE_SUCCESS_UNSTABLE); }
void WorldSession::HandleStablePet( WorldPacket & recv_data ) { sLog.outDebug("WORLD: Recv CMSG_STABLE_PET"); uint64 npcGUID; recv_data >> npcGUID; if(!GetPlayer()->isAlive()) return; Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(npcGUID, UNIT_NPC_FLAG_STABLEMASTER); if (!unit) { sLog.outDebug( "WORLD: HandleStablePet - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(npcGUID)) ); return; } // remove fake death if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); Pet *pet = _player->GetPet(); // 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); return; } uint32 free_slot = 1; QueryResult *result = CharacterDatabase.PQuery("SELECT owner,slot,id FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot ", _player->GetGUIDLow(),PET_SAVE_FIRST_STABLE_SLOT,PET_SAVE_LAST_STABLE_SLOT); if(result) { do { Field *fields = result->Fetch(); uint32 slot = fields[1].GetUInt32(); // slots ordered in query, and if not equal then free if(slot!=free_slot) break; // this slot not free, skip ++free_slot; }while( result->NextRow() ); 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); } else data << uint8(0x06); SendPacket(&data); }
void WorldSession::HandleStableSwapPet(WorldPacket & recv_data) { sLog.outDebug("WORLD: Recv CMSG_STABLE_SWAP_PET."); uint64 npcGUID; uint32 pet_number; recv_data >> npcGUID >> pet_number; if (!CheckStableMaster(npcGUID)) { SendStableResult(STABLE_ERR_STABLE); return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); Pet* pet = _player->GetPet(); if (!pet || pet->getPetType() != HUNTER_PET) { SendStableResult(STABLE_ERR_STABLE); return; } // find swapped pet slot in stable QueryResult_AutoPtr 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(); uint32 slot = fields[0].GetUInt32(); uint32 creature_id = fields[1].GetUInt32(); if (!creature_id) { SendStableResult(STABLE_ERR_STABLE); return; } CreatureInfo const* creatureInfo = sObjectMgr.GetCreatureTemplate(creature_id); if (!creatureInfo || !creatureInfo->isTameable(_player->CanTameExoticPets())) { // 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); // summon unstabled pet Pet *newpet = new Pet(_player); if (!newpet->LoadPetFromDB(_player,creature_id,pet_number)) { delete newpet; SendStableResult(STABLE_ERR_STABLE); } else SendStableResult(STABLE_SUCCESS_UNSTABLE); }
void WorldSession::HandleStablePet(WorldPacket & recv_data) { sLog.outDebug("WORLD: Recv CMSG_STABLE_PET"); uint64 npcGUID; recv_data >> npcGUID; if (!GetPlayer()->isAlive()) { SendStableResult(STABLE_ERR_STABLE); return; } if (!CheckStableMaster(npcGUID)) { SendStableResult(STABLE_ERR_STABLE); return; } // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); Pet *pet = _player->GetPet(); // can't place in stable dead pet if (!pet||!pet->isAlive()||pet->getPetType() != HUNTER_PET) { SendStableResult(STABLE_ERR_STABLE); return; } uint32 free_slot = 1; QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT owner,slot,id FROM character_pet WHERE owner = '%u' AND slot >= '%u' AND slot <= '%u' ORDER BY slot ", _player->GetGUIDLow(),PET_SAVE_FIRST_STABLE_SLOT,PET_SAVE_LAST_STABLE_SLOT); if (result) { do { Field *fields = result->Fetch(); uint32 slot = fields[1].GetUInt32(); // slots ordered in query, and if not equal then free if (slot != free_slot) break; // this slot not free, skip ++free_slot; }while (result->NextRow()); } WorldPacket data(SMSG_STABLE_RESULT, 1); if (free_slot > 0 && free_slot <= GetPlayer()->m_stableSlots) { _player->RemovePet(pet,PetSaveMode(free_slot)); SendStableResult(STABLE_SUCCESS_STABLE); } else SendStableResult(STABLE_ERR_STABLE); }