Ejemplo n.º 1
0
void WorldSession::HandleStableSwapPetCallback(PetData* t_pet, uint32 newslot)
{
    if (!GetPlayer())
        return;

    uint32 slot = t_pet->slot;
    
    if (!t_pet->entry)
    {
        SendStableResult(STABLE_ERR_STABLE);
        return;
    }

    if (newslot < PET_SLOT_STABLE_FIRST)
    {
        CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(t_pet->entry);
        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;
        }
    }

    PetData* t_newslot = _player->GetPetDatabySlot(newslot);

    Pet* p_pet = _player->GetPet();
    if(p_pet && (p_pet->GetGUIDMid() == t_pet->id || (t_newslot && p_pet->GetGUIDMid() == t_newslot->id) ) && newslot >=5)
    {
        _player->RemovePet(p_pet, PetSlot(newslot));
        _player->_currentPetSlot = PetSlot(0);
    }

    if(t_newslot && t_newslot->_state != DATA_REMOVED)
    {
        t_newslot->slot     = slot;
        t_newslot->_state   = DATA_CHANGED;
        t_pet->slot         = newslot;
        t_pet->_state       = DATA_CHANGED;
    }
    else
    {
        t_pet->slot         = newslot;
        t_pet->_state       = DATA_CHANGED;
    }

    SendStableResult(STABLE_SUCCESS_STABLE);
}
Ejemplo n.º 2
0
void WorldSession::HandleStablePetCallback(PreparedQueryResult result)
{
    if (!GetPlayer())
        return;

    uint32 free_slot = 1;
    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()->_petSlotUsed)
    {
        _player->RemovePet(_player->GetPet(), PetSlot(free_slot));
        SendStableResult(STABLE_SUCCESS_STABLE);
    }
    else
        SendStableResult(STABLE_ERR_STABLE);
}