feat(pets): play as your pet in any room, from the pet chooser

A switch in the pet chooser (the settings menu's own On/Off switch, at
the top left of the pet's picture) puts the pet that is out in the
avatar's place, for everyone, as at a Play-As-Your-Pet party: the pet
at the party's size where the avatar stands, turning as it walks, its
name on the name bar, chat balloons and emotes over it, the pet in the
HUD. Hidden at the party itself.

- kept as user var 9008 (9007 is the performance profile), so it holds
  through rooms and logins and is kept for the next pet when the pet is
  put away. the server tells the room by user communication type 13,
  also to players coming in later.
- WorldPet and AvatarWorldView ask the avatar's own form instead of the
  room-wide party test; a pet that cannot come into the room leaves the
  avatar shown.
- the type-13 handler read a variable it never set, so every client took
  every message for "off" and nobody else saw the form.
- the action menu's pet button does the pet's trick again (5c9b2e0 had
  made it the switch, which only hid the avatar).

Flying pets keep to the ground's walls (the party lets them over).
buildVersion 74.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
BurrowdevandClaude Opus 5.5 committed 2026-10-20 15:25:35 +03:00
1 parent 2344270291
commit 096ceafea7
12 files changed
+627 -67

No files matched your search

+36 -17
View File
@@ -3,7 +3,7 @@
const accounts = require("./accounts.js");
const achievements = require("./achievements.js");
const defpacks = require("./defpacks.js");
const {activeAvatar, isUint} = require("./player.js");
const {activeAvatar, activePet, isUint} = require("./player.js");
// pets (client side: PetManager, PetXtCommManager). A pet's species and look
// are packed into three integers by PetManager.packPetBits; the species is
@@ -30,6 +30,13 @@ const MASTERY_FULL = 100;
const MASTERY_PER_ROOM = 5;
const MASTERY_BITS = 0xF00; // the part of uBits PetInventory writes
const SECONDS_TO_HATCH = 259200; // PetManager.hasHatched
// not one of the game's: the pet chooser's "play as your pet" switch
// (gui.PetInventory), kept with the user vars so it reaches the client at
// login. on, whichever pet is out stands in for the avatar, in any room, as
// at a Play-As-Your-Pet party.
const USER_VAR_PET_FORM = 9008;
const inPetForm = account => Number(account.userVars[USER_VAR_PET_FORM]) === 1 && Boolean(activePet(account));
const random = (min, max) => min + Math.floor(Math.random() * (max - min + 1));
@@ -106,6 +113,24 @@ module.exports = ({others, findOnline, petFields}) => {
const ownPet = (account, invIdx) => account.pets.find(candidate => candidate.inv === Number(invIdx));
// tells the player and everyone who sees them whether the pet stands in
// for the avatar (UserCommXtCommManager, user communication type 13).
const sendPetForm = session => {
if (session.pos) {
const state = inPetForm(session.account) ? "on" : "off";
for (const other of [session, ...others(session)]) {
other.sendXt("uc", session.room.id, session.id, state, "13");
}
}
};
// the pet chooser's switch. on with no pet out is kept for the next pet.
const setPetForm = (session, on) => {
achievements.set(session.account, USER_VAR_PET_FORM, on ? 1 : 0);
accounts.save(session.account);
sendPetForm(session);
};
const handlers = {
// PetManager.onPetListResponse: [found, username, count, (invIdx,
// createdTs, name, lBits, uBits, eBits, mastery, personality, toy, food,
@@ -146,15 +171,8 @@ module.exports = ({others, findOnline, petFields}) => {
session.sendXt("ps", -1, 0);
return;
}
const wasPetForm = inPetForm(account);
activeAvatar(account).petInvId = pet ? pet.inv : 0;
if (!pet && session.petPlayerMode) {
session.petPlayerMode = false;
if (session.pos) {
for (const other of [session, ...others(session)]) {
other.sendXt("uc", session.room.id, session.id, "off", "13");
}
}
}
accounts.save(account);
const messageRoom = session.room ? session.room.id : -1;
session.sendXt("ps", messageRoom, 1, session.id, pet ? pet.inv : 0);
@@ -163,6 +181,11 @@ module.exports = ({others, findOnline, petFields}) => {
other.sendXt("ps", messageRoom, 1, session.id, ...petFields(pet));
}
}
// with no pet out the avatar comes back; the next pet out takes its
// place again while the switch is on.
if (wasPetForm !== inPetForm(account)) {
sendPetForm(session);
}
},
// PetManager.onPetDismissResponse: [success, invIdx]
@@ -173,14 +196,10 @@ module.exports = ({others, findOnline, petFields}) => {
session.sendXt("pd", -1, 0, invIdx);
return;
}
const wasPetForm = inPetForm(account);
account.pets = account.pets.filter(candidate => candidate !== pet);
if (session.petPlayerMode && activeAvatar(account).petInvId === pet.inv) {
session.petPlayerMode = false;
if (session.pos) {
for (const other of [session, ...others(session)]) {
other.sendXt("uc", session.room.id, session.id, "off", "13");
}
}
if (wasPetForm && !inPetForm(account)) {
sendPetForm(session);
}
for (const avatar of account.avatars) {
if (avatar.petInvId === pet.inv) {
@@ -251,5 +270,5 @@ module.exports = ({others, findOnline, petFields}) => {
},
};
return {handlers, walked, giveCharacter, favouritesList, personalityList, PERSONALITY_LIST};
return {handlers, walked, giveCharacter, favouritesList, personalityList, PERSONALITY_LIST, inPetForm, setPetForm};
};
+6 -9
View File
@@ -469,7 +469,7 @@ const sendAvatarCreate = (to, target) => {
if (target.invisible) {
to.sendXt("xiv", -1, target.id, 1);
}
if (target.petPlayerMode) {
if (pets.inPetForm(account)) {
to.sendXt("uc", room.id, target.id, "on", "13");
}
// `ac` only creates the avatar. Actions normally travel as live `uc`
@@ -1772,15 +1772,12 @@ module.exports = {
minigames.bubble(session, fields[0], fields[2]);
return;
}
// Per-player pet form. It is deliberately a user-communication
// message so every client already in the room updates the same
// avatar, while the normal pet-out state stays unchanged.
// Per-player pet form (the pet chooser's switch, lib/pets.js). It
// is deliberately a user-communication message so every client
// already in the room updates the same avatar, while the normal
// pet-out state stays unchanged.
if (fields[1] === "13") {
const enabled = fields[0] === "on" && Boolean(activePet(session.account));
session.petPlayerMode = enabled;
for (const other of [session, ...watchers(session)]) {
other.sendXt("uc", session.room.id, session.id, enabled ? "on" : "off", "13");
}
pets.setPetForm(session, fields[0] === "on");
return;
}
// Type 3 is the action packet. It used to be sent only to people