diff options
Diffstat (limited to 'src/server/game/Handlers/PetHandler.cpp')
-rw-r--r-- | src/server/game/Handlers/PetHandler.cpp | 180 |
1 files changed, 52 insertions, 128 deletions
diff --git a/src/server/game/Handlers/PetHandler.cpp b/src/server/game/Handlers/PetHandler.cpp index 6f62fc7cd5a..a1e57ff087a 100644 --- a/src/server/game/Handlers/PetHandler.cpp +++ b/src/server/game/Handlers/PetHandler.cpp @@ -28,6 +28,7 @@ #include "CreatureAI.h" #include "Util.h" #include "Pet.h" +#include "PetPackets.h" #include "World.h" #include "Group.h" #include "SpellHistory.h" @@ -59,22 +60,13 @@ void WorldSession::HandleRequestPetInfo(WorldPackets::Pet::RequestPetInfo& /*pac { } -void WorldSession::HandlePetAction(WorldPacket& recvData) +void WorldSession::HandlePetAction(WorldPackets::Pet::PetAction& packet) { - ObjectGuid guid1; - uint32 data; - ObjectGuid guid2; - float x, y, z; - recvData >> guid1; //pet guid - recvData >> data; - recvData >> guid2; //tag guid - // Position - recvData >> x; - recvData >> y; - recvData >> z; - - uint32 spellid = UNIT_ACTION_BUTTON_ACTION(data); - uint8 flag = UNIT_ACTION_BUTTON_TYPE(data); //delete = 0x07 CastSpell = C1 + ObjectGuid guid1 = packet.PetGUID; //pet guid + ObjectGuid guid2 = packet.TargetGUID; //tag guid + + uint32 spellid = UNIT_ACTION_BUTTON_ACTION(packet.Action); + uint8 flag = UNIT_ACTION_BUTTON_TYPE(packet.Action); //delete = 0x07 CastSpell = C1 // used also for charmed creature Unit* pet = ObjectAccessor::GetUnit(*_player, guid1); @@ -106,7 +98,7 @@ void WorldSession::HandlePetAction(WorldPacket& recvData) return; if (GetPlayer()->m_Controlled.size() == 1) - HandlePetActionHelper(pet, guid1, spellid, flag, guid2, x, y, z); + HandlePetActionHelper(pet, guid1, spellid, flag, guid2, packet.ActionPosition.x, packet.ActionPosition.y, packet.ActionPosition.z); else { //If a pet is dismissed, m_Controlled will change @@ -115,7 +107,7 @@ void WorldSession::HandlePetAction(WorldPacket& recvData) if ((*itr)->GetEntry() == pet->GetEntry() && (*itr)->IsAlive()) controlled.push_back(*itr); for (std::vector<Unit*>::iterator itr = controlled.begin(); itr != controlled.end(); ++itr) - HandlePetActionHelper(*itr, guid1, spellid, flag, guid2, x, y, z); + HandlePetActionHelper(*itr, guid1, spellid, flag, guid2, packet.ActionPosition.x, packet.ActionPosition.y, packet.ActionPosition.z); } } @@ -462,13 +454,9 @@ bool WorldSession::CheckStableMaster(ObjectGuid guid) return true; } -void WorldSession::HandlePetSetAction(WorldPacket& recvData) +void WorldSession::HandlePetSetAction(WorldPackets::Pet::PetSetAction& packet) { - ObjectGuid petguid; - uint8 count; - - recvData >> petguid; - + ObjectGuid petguid = packet.PetGUID; Unit* pet = ObjectAccessor::GetUnit(*_player, petguid); if (!pet || pet != _player->GetFirstControlled()) @@ -484,110 +472,53 @@ void WorldSession::HandlePetSetAction(WorldPacket& recvData) return; } - count = (recvData.size() == 24) ? 2 : 1; - - uint32 position[2]; - uint32 data[2]; - bool move_command = false; + uint32 position = packet.Index; + uint32 actionData = packet.Action; - for (uint8 i = 0; i < count; ++i) - { - recvData >> position[i]; - recvData >> data[i]; + uint32 spell_id = UNIT_ACTION_BUTTON_ACTION(actionData); + uint8 act_state = UNIT_ACTION_BUTTON_TYPE(actionData); - uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]); - - //ignore invalid position - if (position[i] >= MAX_UNIT_ACTION_BAR_INDEX) - return; - - // in the normal case, command and reaction buttons can only be moved, not removed - // at moving count == 2, at removing count == 1 - // ignore attempt to remove command|reaction buttons (not possible at normal case) - if (act_state == ACT_COMMAND || act_state == ACT_REACTION) - { - if (count == 1) - return; + TC_LOG_DEBUG("network", "Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X", + _player->GetName().c_str(), position, spell_id, uint32(act_state)); - move_command = true; - } - } - - // check swap (at command->spell swap client remove spell first in another packet, so check only command move correctness) - if (move_command) + //if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add + if (!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_PASSIVE) && spell_id && !pet->HasSpell(spell_id))) { - uint8 act_state_0 = UNIT_ACTION_BUTTON_TYPE(data[0]); - if (act_state_0 == ACT_COMMAND || act_state_0 == ACT_REACTION) - { - uint32 spell_id_0 = UNIT_ACTION_BUTTON_ACTION(data[0]); - UnitActionBarEntry const* actionEntry_1 = charmInfo->GetActionBarEntry(position[1]); - if (!actionEntry_1 || spell_id_0 != actionEntry_1->GetAction() || - act_state_0 != actionEntry_1->GetType()) - return; - } - - uint8 act_state_1 = UNIT_ACTION_BUTTON_TYPE(data[1]); - if (act_state_1 == ACT_COMMAND || act_state_1 == ACT_REACTION) + if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id)) { - uint32 spell_id_1 = UNIT_ACTION_BUTTON_ACTION(data[1]); - UnitActionBarEntry const* actionEntry_0 = charmInfo->GetActionBarEntry(position[0]); - if (!actionEntry_0 || spell_id_1 != actionEntry_0->GetAction() || - act_state_1 != actionEntry_0->GetType()) - return; - } - } - - for (uint8 i = 0; i < count; ++i) - { - uint32 spell_id = UNIT_ACTION_BUTTON_ACTION(data[i]); - uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]); - - TC_LOG_DEBUG("network", "Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X", - _player->GetName().c_str(), position[i], spell_id, uint32(act_state)); - - //if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add - if (!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_PASSIVE) && spell_id && !pet->HasSpell(spell_id))) - { - if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell_id)) + //sign for autocast + if (act_state == ACT_ENABLED) { - //sign for autocast - if (act_state == ACT_ENABLED) - { - if (pet->GetTypeId() == TYPEID_UNIT && pet->IsPet()) - ((Pet*)pet)->ToggleAutocast(spellInfo, true); - else - for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr) - if ((*itr)->GetEntry() == pet->GetEntry()) - (*itr)->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, true); - } - //sign for no/turn off autocast - else if (act_state == ACT_DISABLED) - { - if (pet->GetTypeId() == TYPEID_UNIT && pet->IsPet()) - ((Pet*)pet)->ToggleAutocast(spellInfo, false); - else - for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr) - if ((*itr)->GetEntry() == pet->GetEntry()) - (*itr)->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, false); - } + if (pet->GetTypeId() == TYPEID_UNIT && pet->IsPet()) + ((Pet*)pet)->ToggleAutocast(spellInfo, true); + else + for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr) + if ((*itr)->GetEntry() == pet->GetEntry()) + (*itr)->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, true); + } + //sign for no/turn off autocast + else if (act_state == ACT_DISABLED) + { + if (pet->GetTypeId() == TYPEID_UNIT && pet->IsPet()) + ((Pet*)pet)->ToggleAutocast(spellInfo, false); + else + for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr) + if ((*itr)->GetEntry() == pet->GetEntry()) + (*itr)->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, false); } - - charmInfo->SetActionBar(position[i], spell_id, ActiveStates(act_state)); } + + charmInfo->SetActionBar(position, spell_id, ActiveStates(act_state)); } } -void WorldSession::HandlePetRename(WorldPacket& recvData) +void WorldSession::HandlePetRename(WorldPackets::Pet::PetRename& packet) { - ObjectGuid petguid; - uint8 isdeclined; + ObjectGuid petguid = packet.RenameData.PetGUID; + bool isdeclined = packet.RenameData.HasDeclinedNames; - std::string name; - DeclinedName declinedname; - - recvData >> petguid; - recvData >> name; - recvData >> isdeclined; + std::string name = packet.RenameData.NewName; + DeclinedName declinedname = packet.RenameData.DeclinedNames; Pet* pet = ObjectAccessor::GetPet(*_player, petguid); // check it! @@ -617,11 +548,6 @@ void WorldSession::HandlePetRename(WorldPacket& recvData) if (isdeclined) { - for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) - { - recvData >> declinedname.name[i]; - } - std::wstring wname; if (!Utf8toWStr(name, wname)) return; @@ -788,13 +714,11 @@ void WorldSession::HandlePetCastSpellOpcode(WorldPackets::Spells::PetCastSpell& void WorldSession::SendPetNameInvalid(uint32 error, const std::string& name, DeclinedName *declinedName) { - WorldPacket data(SMSG_PET_NAME_INVALID, 4 + name.size() + 1 + 1); - data << uint32(error); - data << name; - data << uint8(declinedName ? 1 : 0); - if (declinedName) - for (uint32 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) - data << declinedName->name[i]; - - SendPacket(&data); + WorldPackets::Pet::PetNameInvalid petNameInvalid; + petNameInvalid.Result = error; + petNameInvalid.RenameData.NewName = name; + for (int i = 0; i < MAX_DECLINED_NAME_CASES; i++) + petNameInvalid.RenameData.DeclinedNames.name[i] = declinedName[i].name[i]; + + SendPacket(petNameInvalid.Write()); } |