87 lines
3.6 KiB
C++
87 lines
3.6 KiB
C++
// Owned pet, possess and charm spell-bar notifications from the ordinary world session.
|
|
#pragma once
|
|
#include "gateway/legacy_stream.hpp"
|
|
#include <climits>
|
|
#include <optional>
|
|
|
|
namespace gateway {
|
|
struct PetSpellbook {
|
|
struct Cooldown {
|
|
uint16_t spell, category;
|
|
uint32_t duration, category_duration;
|
|
};
|
|
uint64_t unit=0;
|
|
uint32_t time_limit=0;
|
|
uint8_t react=0, command=0, flag=0;
|
|
std::array<uint32_t,10> buttons{};
|
|
std::vector<uint32_t> actions;
|
|
std::vector<Cooldown> cooldowns;
|
|
};
|
|
|
|
inline void turtle_pet_mode(Reader& r, PetSpellbook& state) {
|
|
state.react=uint8_t(r.le(1));
|
|
state.command=uint8_t(r.le(1));
|
|
const auto reserved=r.le(1);
|
|
state.flag=uint8_t(r.le(1));
|
|
if (reserved || state.react>2 || state.command>3 || (state.flag!=0 && state.flag!=8))
|
|
throw Error("unsupported source pet-bar state");
|
|
}
|
|
|
|
inline PetSpellbook turtle_pet_spellbook(std::span<const uint8_t> body) {
|
|
Reader r(body);PetSpellbook result;
|
|
result.unit=r.le(8);
|
|
if (!result.unit) { r.end(); return result; } // Player::RemovePetActionBar
|
|
result.time_limit=uint32_t(r.le(4));
|
|
turtle_pet_mode(r,result);
|
|
for(auto& button:result.buttons)button=uint32_t(r.le(4));
|
|
const auto spells=r.le(1);
|
|
for(unsigned i=0;i<spells;++i)result.actions.push_back(uint32_t(r.le(4)));
|
|
const auto cooldowns=r.le(1);
|
|
for(unsigned i=0;i<cooldowns;++i) {
|
|
PetSpellbook::Cooldown c{uint16_t(r.le(2)),uint16_t(r.le(2)),uint32_t(r.le(4)),uint32_t(r.le(4))};
|
|
if(!c.spell || c.duration>uint32_t(INT32_MAX) || c.category_duration>uint32_t(INT32_MAX))
|
|
throw Error("unsupported source pet cooldown");
|
|
result.cooldowns.push_back(c);
|
|
}
|
|
r.end();return result;
|
|
}
|
|
|
|
inline Bytes forever_pet_spellbook(const PetSpellbook& state,const Guid128& unit,uint16_t family) {
|
|
// Original 70334 PetSpells::Write uses 18 action cells, including eight
|
|
// Classic supplemental buttons, before its three 32-bit list lengths.
|
|
Bytes out=pack_guid(unit);le(out,family,2);le(out,0,2);le(out,state.time_limit,4);
|
|
le(out,state.command,1);le(out,state.flag,1);le(out,state.react,1);
|
|
for(auto button:state.buttons)le(out,button,4);
|
|
for(unsigned i=0;i<4;++i)le(out,state.buttons[i],4);
|
|
le(out,0x16000000,4);
|
|
for(unsigned i=7;i<10;++i)le(out,state.buttons[i],4);
|
|
le(out,state.actions.size(),4);le(out,state.cooldowns.size(),4);le(out,0,4);
|
|
for(auto action:state.actions)le(out,action,4);
|
|
for(const auto& c:state.cooldowns) {
|
|
le(out,c.spell,4);le(out,c.duration,4);le(out,c.category_duration,4);
|
|
le(out,0x3f800000,4);le(out,c.category,2); // PetSpellCooldown's default 1.0 ModRate.
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// The source reports only the reason. Its UNKNOWNERROR=12 collides with
|
|
// target CantControlExotic=12. Neither this nor an unknown feedback code
|
|
// should become a different stock client message.
|
|
inline std::optional<LegacyPacket> pet_owner_feedback(uint32_t source,std::span<const uint8_t> body) {
|
|
Reader r(body);auto reason=r.le(1);r.end();Bytes out;
|
|
if(source==0x273){
|
|
// Source STABLE_ERR_STABLE is overloaded across unrelated failures.
|
|
// Buy-slot success moved from 10 (now revive success) to 14.
|
|
if(reason!=1 && reason!=8 && reason!=9 && reason!=10)return {};
|
|
le(out,reason==10?14:reason,4);return LegacyPacket{0x47002a,std::move(out)};
|
|
}
|
|
if(source==0x173 && reason>=1 && reason<=11) {
|
|
le(out,reason,4);return LegacyPacket{0x47015f,std::move(out)};
|
|
}
|
|
if(source==0x2c6 && reason>=1 && reason<=4) {
|
|
le(out,reason,4);le(out,0,4);return LegacyPacket{0x4701f4,std::move(out)};
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
}
|