Example #1
0
void WorldSession::HandlePetSpellAutocastOpcode( WorldPacket& recvPacket )
{
    CHECK_PACKET_SIZE(recvPacket,8+2+2+1);

    sLog.outDetail("CMSG_PET_SPELL_AUTOCAST");
    uint64 guid;
    uint16 spellid;
    uint16 spellid2;                                        //maybe second spell, automatically toggled off when first toggled on?
    uint8  state;                                           //1 for on, 0 for off
    recvPacket >> guid >> spellid >> spellid2 >> state;

    if(!_player->GetGuardianPet() && !_player->GetCharm())
        return;

    if(ObjectAccessor::FindPlayer(guid))
        return;

    Creature* pet=ObjectAccessor::GetCreatureOrPetOrVehicle(*_player,guid);

    if(!pet || (pet != _player->GetGuardianPet() && pet != _player->GetCharm()))
    {
        sLog.outError( "HandlePetSpellAutocastOpcode.Pet %u isn't pet of player %s .", uint32(GUID_LOPART(guid)),GetPlayer()->GetName() );
        return;
    }

    // do not add not learned spells/ passive spells
    if(!pet->HasSpell(spellid) || IsAutocastableSpell(spellid))
        return;

    CharmInfo *charmInfo = pet->GetCharmInfo();
    if(!charmInfo)
    {
        sLog.outError("WorldSession::HandlePetSpellAutocastOpcod: object "I64FMTD" is considered pet-like but doesn't have a charminfo!", pet->GetGUID());
        return;
    }

    if(pet->isPet())
        ((Pet*)pet)->ToggleAutocast(spellid, state);
    else
        pet->GetCharmInfo()->ToggleCreatureAutocast(spellid, state);

    for(uint8 i = 0; i < 10; ++i)
    {
        if((charmInfo->GetActionBarEntry(i)->Type == ACT_ENABLED || charmInfo->GetActionBarEntry(i)->Type == ACT_DISABLED) && spellid == charmInfo->GetActionBarEntry(i)->SpellOrAction)
            charmInfo->GetActionBarEntry(i)->Type = state ? ACT_ENABLED : ACT_DISABLED;
    }
}
Example #2
0
void WorldSession::HandlePetSpellAutocastOpcode(WorldPacket& recvPacket) {
	sLog->outDetail("CMSG_PET_SPELL_AUTOCAST");
	uint64 guid;
	uint32 spellid;
	uint8 state; //1 for on, 0 for off
	recvPacket >> guid >> spellid >> state;

	if (!_player->GetGuardianPet() && !_player->GetCharm())
		return;

	if (ObjectAccessor::FindPlayer(guid))
		return;

	Creature* pet = ObjectAccessor::GetCreatureOrPetOrVehicle(*_player, guid);

	if (!pet
			|| (pet != _player->GetGuardianPet() && pet != _player->GetCharm())) {
		sLog->outError(
				"HandlePetSpellAutocastOpcode.Pet %u isn't pet of player %s .",
				uint32(GUID_LOPART(guid)), GetPlayer()->GetName());
		return;
	}

	// do not add not learned spells/ passive spells
	if (!pet->HasSpell(spellid) || IsAutocastableSpell(spellid))
		return;

	CharmInfo *charmInfo = pet->GetCharmInfo();
	if (!charmInfo) {
		sLog->outError(
				"WorldSession::HandlePetSpellAutocastOpcod: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!",
				pet->GetGUIDLow(), pet->GetTypeId());
		return;
	}

	if (pet->isPet())
		((Pet*) pet)->ToggleAutocast(spellid, state);
	else
		pet->GetCharmInfo()->ToggleCreatureAutocast(spellid, state);

	charmInfo->SetSpellAutocast(spellid, state);
}