void WorldSession::HandlePetSpellAutocastOpcode(WorldPacket& recvPacket) { DETAIL_LOG("CMSG_PET_SPELL_AUTOCAST"); ObjectGuid guid; uint32 spellid; uint8 state; // 1 for on, 0 for off recvPacket >> guid >> spellid >> state; Creature* pet = _player->GetMap()->GetAnyTypeCreature(guid); if (!pet || (guid != _player->GetPetGuid() && guid != _player->GetCharmGuid())) { sLog.outError("HandlePetSpellAutocastOpcode. %s isn't pet of %s .", guid.GetString().c_str(), _player->GetGuidStr().c_str()); return; } // do not add not learned spells/ passive spells if (!pet->HasSpell(spellid) || !IsAutocastable(spellid)) return; CharmInfo* charmInfo = pet->GetCharmInfo(); if (!charmInfo) { sLog.outError("WorldSession::HandlePetSpellAutocastOpcod: %s is considered pet-like but doesn't have a charminfo!", guid.GetString().c_str()); return; } if (pet->isCharmed()) // state can be used as boolean pet->GetCharmInfo()->ToggleCreatureAutocast(spellid, !!state); else ((Pet*)pet)->ToggleAutocast(spellid, !!state); charmInfo->SetSpellAutocast(spellid, !!state); }
void WorldSession::HandlePetSpellAutocastOpcode(WorldPacket& recvPacket) { DETAIL_LOG("CMSG_PET_SPELL_AUTOCAST"); ObjectGuid guid; uint32 spellid; uint8 state; // 1 for on, 0 for off recvPacket >> guid >> spellid >> state; Unit* petUnit = _player->GetMap()->GetUnit(guid); if (!petUnit || (guid != _player->GetPetGuid() && !_player->HasCharm(guid))) { sLog.outError("HandlePetSpellAutocastOpcode. %s isn't pet of %s .", guid.GetString().c_str(), _player->GetGuidStr().c_str()); return; } Creature* petCreature = petUnit->GetTypeId() == TYPEID_UNIT ? static_cast<Creature*>(petUnit) : nullptr; Pet* pet = (petCreature && petCreature->IsPet()) ? static_cast<Pet*>(petUnit) : nullptr; // do not add not learned spells/ passive spells if (!petUnit->HasSpell(spellid) || !IsAutocastable(spellid)) return; CharmInfo* charmInfo = petUnit->GetCharmInfo(); if (!charmInfo) { sLog.outError("WorldSession::HandlePetSpellAutocastOpcod: %s is considered pet-like but doesn't have a charminfo!", guid.GetString().c_str()); return; } if (petUnit->HasCharmer()) // state can be used as boolean petUnit->GetCharmInfo()->ToggleCreatureAutocast(spellid, state != 0); else if (pet) pet->ToggleAutocast(spellid, state != 0); charmInfo->SetSpellAutocast(spellid, state != 0); }