Files
2026-11-23 03:28:32 +02:00

73 lines
3.9 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
// Hunter stable: Tortoise MSG_LIST_STABLED_PETS (0x26F) -> native ActivePlayerData.PetStable
// (TC UF::StableInfo). Decisions (Codex 2026-11-21): the current pet is presentation slot 0,
// stabled pets are 1..n in the latest Source list order within purchased capacity, and the
// fields absent from the Source wire (Happiness, Experience, NextLevelExperience, LoyaltyPoints)
// stay zero/unknown.
#pragma once
#include "gateway/protocol.hpp"
#include "gateway/legacy_stream.hpp"
#include <functional>
#include <optional>
#include <span>
#include <string>
#include <vector>
namespace gateway {
struct TurtleStablePet {uint32_t number=0,entry=0,level=0,loyalty=0;std::string name;bool current=false;};
struct TurtleStableList {uint64_t npc=0;uint8_t slots=0;std::vector<TurtleStablePet> pets;};
TurtleStableList turtle_stable_list(std::span<const uint8_t>);
// Validates the Source list as Codex's codec will present it (current pet first and unique,
// stabled count within purchased capacity, unique pet numbers); throws Error otherwise.
void validate_stable_list(const TurtleStableList&);
// GW_CODEC_PET_STABLE (mode 76) DTOs, Codex contract 2026-11-21, little endian, all start kind:u8.
// context = realm:u16, map:u32, self_source_player:u64
// K1 = context + snapshot (full replacement, nonzero bound NPC)
// K2 = context only (clear StableMaster, keep slots and pets)
// snapshot = npc:u64, purchased_slots:u8, count:u8, rows in Source order
// row = kind:u8 (1 current, 2 stabled), pet_number:u32, creature_entry:u32, display_id:u32, level:u32,
// loyalty_level:u8, loyalty_points:u32, happiness:u32, experience:u32, next_xp:u32, name:cstring
// Metrics absent from the Source wire are zero. The codec assigns presentation slots (0 current, 1..n).
struct StableRowMetrics {uint32_t loyalty_points=0,happiness=0,experience=0,next_xp=0;};
Bytes pet_stable_snapshot_input(uint16_t realm,uint32_t map,uint64_t self,const TurtleStableList&,const std::function<uint32_t(uint32_t)>& display);
Bytes pet_stable_close_input(uint16_t realm,uint32_t map,uint64_t self);
struct PetStableDto {uint8_t kind=0;uint16_t realm=0;uint32_t map=0;uint64_t self=0;TurtleStableList list;std::vector<uint32_t> displays;std::vector<StableRowMetrics> metrics;};
// K0 = home:u8 + snapshot + existing GW_CODEC_SELF body. The session only emits K1/K2.
// The enclosing DTO owns its boundary; a create continues after the snapshot.
inline PetStableDto read_pet_stable_snapshot(Reader& input) {
PetStableDto dto;
dto.list.npc = input.le(8);
dto.list.slots = uint8_t(input.le(1));
const auto count = input.le(1);
for (unsigned i = 0; i < count; ++i) {
TurtleStablePet pet;
const auto kind = input.le(1);
if (kind != 1 && kind != 2)
throw Error("pet stable DTO row kind");
pet.current = kind == 1;
pet.number = uint32_t(input.le(4));
pet.entry = uint32_t(input.le(4));
dto.displays.push_back(uint32_t(input.le(4)));
pet.level = uint32_t(input.le(4));
pet.loyalty = uint32_t(input.le(1));
auto& metrics = dto.metrics.emplace_back();
metrics.loyalty_points = uint32_t(input.le(4));
metrics.happiness = uint32_t(input.le(4));
metrics.experience = uint32_t(input.le(4));
metrics.next_xp = uint32_t(input.le(4));
pet.name = input.cstring(255);
dto.list.pets.push_back(std::move(pet));
}
validate_stable_list(dto.list);
return dto;
}
PetStableDto pet_stable_from_input(std::span<const uint8_t>);
// Native CMSG_SET_PET_SLOT {u32 PetNumber, u8 DestSlot, Guid StableMaster}: the Source request
// for the current snapshot, or nullopt when Source cannot express it (stable-to-stable move).
struct NativeSetPetSlot {uint32_t number=0;uint8_t dest=0;Bytes master;};
NativeSetPetSlot native_set_pet_slot(std::span<const uint8_t>);
std::optional<LegacyPacket> source_set_pet_slot(const NativeSetPetSlot&,const TurtleStableList&);
}