game: implement SMSG_PET_SPELLS/MODE/BROKEN and pet action plumbing

SMSG_PET_SPELLS: Parse full packet — pet GUID, react/command state,
10 action bar slots, per-spell entries with autocast flags.  Previously
only read the GUID.

SMSG_PET_MODE: Parse petGuid + mode uint32 (command low byte, react
high byte) to keep stance state in sync after server updates.

SMSG_PET_BROKEN: Clear pet state and show "Your pet has died." chat
message.

SMSG_PET_LEARNED_SPELL / SMSG_PET_UNLEARNED_SPELL: Maintain pet spell
list incrementally.

SMSG_PET_CAST_FAILED: Parse and log cast count + spell + reason.

New state accessors: getPetActionSlot(), getPetCommand(), getPetReact(),
getPetSpells(), isPetSpellAutocast().

CMSG_PET_ACTION: Add targetGuid (uint64) field — the wire format
requires petGuid(8)+action(4)+targetGuid(8).  Was sending an 12-byte
packet instead of the required 20 bytes.

sendPetAction(): New method that builds and sends CMSG_PET_ACTION with
the correct target guid.
This commit is contained in:
Kelsi 2026-03-09 22:53:09 -07:00
parent 52c1fed6ab
commit 06a628dae2
4 changed files with 153 additions and 12 deletions

View file

@ -456,6 +456,27 @@ public:
void dismissPet();
bool hasPet() const { return petGuid_ != 0; }
uint64_t getPetGuid() const { return petGuid_; }
// ---- Pet state (populated by SMSG_PET_SPELLS / SMSG_PET_MODE) ----
// 10 action bar slots; each entry is a packed uint32:
// bits 0-23 = spell ID (or 0 for empty)
// bits 24-31 = action type (0x00=cast, 0xC0=autocast on, 0x40=autocast off)
static constexpr int PET_ACTION_BAR_SLOTS = 10;
uint32_t getPetActionSlot(int idx) const {
if (idx < 0 || idx >= PET_ACTION_BAR_SLOTS) return 0;
return petActionSlots_[idx];
}
// Pet command/react state from SMSG_PET_MODE or SMSG_PET_SPELLS
uint8_t getPetCommand() const { return petCommand_; } // 0=stay,1=follow,2=attack,3=dismiss
uint8_t getPetReact() const { return petReact_; } // 0=passive,1=defensive,2=aggressive
// Spells the pet knows (from SMSG_PET_SPELLS spell list)
const std::vector<uint32_t>& getPetSpells() const { return petSpellList_; }
// Pet autocast set (spellIds that have autocast enabled)
bool isPetSpellAutocast(uint32_t spellId) const {
return petAutocastSpells_.count(spellId) != 0;
}
// Send CMSG_PET_ACTION to issue a pet command
void sendPetAction(uint32_t action, uint64_t targetGuid = 0);
const std::unordered_set<uint32_t>& getKnownSpells() const { return knownSpells; }
// Player proficiency bitmasks (from SMSG_SET_PROFICIENCY)
@ -1763,6 +1784,11 @@ private:
std::vector<AuraSlot> playerAuras;
std::vector<AuraSlot> targetAuras;
uint64_t petGuid_ = 0;
uint32_t petActionSlots_[10] = {}; // SMSG_PET_SPELLS action bar (10 slots)
uint8_t petCommand_ = 1; // 0=stay,1=follow,2=attack,3=dismiss
uint8_t petReact_ = 1; // 0=passive,1=defensive,2=aggressive
std::vector<uint32_t> petSpellList_; // known pet spells
std::unordered_set<uint32_t> petAutocastSpells_; // spells with autocast on
// ---- Battleground queue state ----
struct BgQueueSlot {