fix: trading, machine rewards and claw prizes from the owner's list

- a completed trade no longer plays the failure sound over the success one
- a sign over players who are trading, seen by everyone in the room
- every item added to a trade list is shown; lists keep up to 200 items
- the drink, popcorn and cotton candy machines always hand over what they
  made (the game sent nothing when it was like the last one it gave), the
  smoothie machine even when the game it is was not noted down, and the
  server takes a game's message for a moment after it is left
- claw machine, Phantom Invasion and Sky High prizes are the game's own
  items only: a custom item could be missing from the winner's game
This commit is contained in:
Burrowdev committed 2026-10-23 21:29:49 +03:00
1 parent 22fb7f0fa5
commit 6c273554d7
12 files changed
+2791 -11

No files matched your search

+13 -3
View File
@@ -6,6 +6,7 @@ const defpacks = require("./defpacks.js");
const buddyGames = require("./buddygames.js");
const masterpieces = require("./masterpieces.js");
const dens = require("./dens.js");
const customItems = require("./customitems.js");
const limits = require("./limits.js");
const {activeAvatar, addClothing, sendClothingAdded} = require("./player.js");
@@ -42,6 +43,7 @@ const {activeAvatar, addClothing, sendClothingAdded} = require("./player.js");
const games = new Map(require("./games.json").map(game => [game.id, game]));
const GAME_AFTERGLOW_MS = 15000; // how long a game's room id is still taken after leaving it (leave)
const IN_ROOM = 0;
const MAX_GEMS_PER_AWARD = 5000;
const MAX_MASTERY_PER_AWARD = 100;
@@ -234,6 +236,10 @@ module.exports = ({tell, leaveRoom, findOnline, blocks, watchers}) => {
return;
}
session.game = null;
// an in-room game may say it is done just before it hands over what it
// made (the Juice Bar's smoothie, the Cocoa Hut's drink: an attachment,
// lib/world.js pubMsg), labelled with the game's room
session.lastGame = {roomId: game.roomId, until: Date.now() + GAME_AFTERGLOW_MS};
if (session.bubbleOffOwed) {
bubbleOff(session);
}
@@ -408,8 +414,12 @@ module.exports = ({tell, leaveRoom, findOnline, blocks, watchers}) => {
// den items a claw machine can drop: the plushies, of the machine's own
// animal when it is named for one ("The Wolf Claw").
let plushies = null;
// the game's own den items only: a custom item (and a player's own, which
// is nobody else's to win) may be missing from the winner's game, whose
// prize popup then threw (DenItem.initShopItem) and left the game frozen.
const gameOwnDenItemIds = () => defpacks.denItemIds().filter(id => id < customItems.FIRST_ID);
const clawPrizes = game => {
plushies = plushies || defpacks.denItemIds().filter(id => /plush/i.test(defpacks.denItemDef(id).abbrName));
plushies = plushies || gameOwnDenItemIds().filter(id => /plush/i.test(defpacks.denItemDef(id).abbrName));
const item = defpacks.denItemIds().map(id => defpacks.denItemDef(id)).find(def => Number(def.gameDefId) === game.id);
const animal = item ? /^ArcCraneGame(.+)$/.exec(item.abbrName) : null;
const own = animal ? plushies.filter(id => defpacks.denItemDef(id).abbrName.toLowerCase().includes(animal[1].toLowerCase())) : [];
@@ -420,7 +430,7 @@ module.exports = ({tell, leaveRoom, findOnline, blocks, watchers}) => {
// machines aside.
let phantomItems = null;
const invasionPrizes = () => {
phantomItems = phantomItems || defpacks.denItemIds().filter(id => /phantom/i.test(defpacks.denItemDef(id).abbrName)
phantomItems = phantomItems || gameOwnDenItemIds().filter(id => /phantom/i.test(defpacks.denItemDef(id).abbrName)
&& !/^Arc/.test(defpacks.denItemDef(id).abbrName) && defpacks.string(defpacks.denItemDef(id).nameStrId));
return phantomItems.length ? phantomItems : defpacks.denItemIds().slice(0, 1);
};
@@ -550,7 +560,7 @@ module.exports = ({tell, leaveRoom, findOnline, blocks, watchers}) => {
WindRider: {
go() {},
gw(session, game, params, reply) {
const ids = defpacks.clothingIds();
const ids = defpacks.clothingIds().filter(id => id < customItems.FIRST_ID);
const def = Math.random() < SKY_HIGH_PRIZE_CHANCE ? defpacks.itemDef(ids[Math.floor(Math.random() * ids.length)]) : null;
session.gamePrize = def ? {def: Number(def.id), color: Number(String(def.colors).split(",")[0])} : null;
reply("gw", def ? "1" : "0", def ? def.id : 0, 0, def ? session.gamePrize.color : 0);
+14 -4
View File
@@ -15,7 +15,7 @@ const TYPE_CLOTHING = 0;
const TYPE_DEN_ITEM = 1;
const TYPE_PET = 3;
const MAX_TRADE_ITEMS = 50;
const MAX_TRADE_ITEMS = 200; // on a trade list (the game sets no end to it; past this the rest were dropped)
const MAX_PETS = 1000; // as in lib/pets.js
// "ti" request steps (first parameter from the client)
@@ -46,7 +46,7 @@ const TRADES_KEPT = 50; // per account, for its page
const MAX_WAITING_OFFERS = 50; // offers left on one account
const MAX_OFFERS_MADE = 20; // by one account, still waiting
module.exports = ({findOnline, blocks}) => {
module.exports = ({findOnline, blocks, showTrading}) => {
// TradeManager.onTradeListReceived: [username, clothingCount, (defId,
// invIdx, color)..., denItemCount, (defId, invIdx, version, approved,
// imageId, creatorDbId, creatorUuid)..., petCount, (speciesId, invIdx,
@@ -138,6 +138,8 @@ module.exports = ({findOnline, blocks}) => {
const other = trade.requester === session ? trade.owner : trade.requester;
trade.requester.trade = trade.owner.trade = null;
other.sendXt("ti", -1, status, session.account.username, USERNAME_SHOWN);
showTrading(session);
showTrading(other);
};
// moves one entry between accounts. it gets a fresh inventory id, and
@@ -209,6 +211,8 @@ module.exports = ({findOnline, blocks}) => {
return;
}
session.trade = owner.trade = {requester: session, owner, wantedType, wanted, offered, accepted: false, confirmed: new Set()};
showTrading(session);
showTrading(owner);
// TradeManager.displayTradeRequested: [0, requesterName, moderatedFlag,
// wantedCode, wantedInvIdx, clothingCount, denCount, petCount, ...items]
const ofType = type => offered.filter(item => item.type === type);
@@ -251,6 +255,8 @@ module.exports = ({findOnline, blocks}) => {
}
const {requester, owner, wantedType, wanted, offered} = trade;
requester.trade = owner.trade = null;
showTrading(requester);
showTrading(owner);
// either side may have recycled or re-traded something while deciding.
const stillThere = collectionOf(owner.account, wantedType).includes(wanted)
&& offered.every(item => collectionOf(requester.account, item.type).includes(item.entry))
@@ -312,8 +318,12 @@ module.exports = ({findOnline, blocks}) => {
sendTradeList(session, account);
},
// ["1"/"0"]: busy flag while the trade window is open; nothing to answer.
tb() {},
// ["1"/"0"]: busy flag while the trade window is open; nothing to
// answer. it shows as the trading sign (lib/world.js showTrading).
tb(session, roomId, [busy]) {
session.tradeBusy = busy === "1";
showTrading(session);
},
ti(session, roomId, params) {
switch (params[0]) {
+30 -1
View File
@@ -794,6 +794,10 @@ const handlers = {
other.sendXt("au", session.room.id, 1, session.id, count, ...coords, teleport);
}
}
// a trade going on when they came in: the sign over them again
if (firstUpdate) {
showTrading(session);
}
},
// GenericListXtCommManager.handleNewData: [listId, entryType, 4 unused
@@ -1343,8 +1347,25 @@ const staffMove = (whoName, toName) => {
return {ok: true, room: shown};
};
// trading: a sign over the animal of a player in a trade, or with the trade
// window open, in everyone else's game (the patched AvatarWorldView.
// setTrading): "xtr" [.., .., sfsId, 1 | 0], told as it changes, and to
// whoever comes into the room (enterRoom).
const isTrading = session => Boolean(session.trade || session.tradeBusy);
const showTrading = session => {
const on = isTrading(session) && Boolean(session.room);
if (Boolean(session.tradingShown) === on) {
return;
}
session.tradingShown = on;
for (const other of watchers(session)) {
other.sendXt("xtr", -1, session.id, on ? 1 : 0);
}
};
const context = {
others: watchers,
showTrading,
watchers,
findOnline,
findBySfsId,
@@ -1398,6 +1419,9 @@ const leaveRoom = session => {
session.room = null;
session.pos = null;
delete session.activeAction;
// the sign goes with the animal; it comes back in the next room if the
// trade goes on there (showTrading)
session.tradingShown = false;
minigames.roomLeft(session);
for (const other of room.sessions) {
// AvatarManager.avatarRemoveResponse
@@ -1607,6 +1631,9 @@ const enterRoom = (session, name, base, displayName, shardId, props = {}) => {
for (const other of others(session)) {
if (other.pos && sees(session, other)) {
sendAvatarCreate(session, other);
if (other.tradingShown) {
session.sendXt("xtr", -1, other.id, 1);
}
}
}
return room;
@@ -1837,7 +1864,9 @@ module.exports = {
// embedded SWF labels outgoing user messages with the minigame's
// temporary sub-room id. Accept that id as well so its attachment
// reward can make the normal round trip back to the avatar.
if (session.room && (session.room.id === msg.roomId || (session.game && session.game.roomId === Number(msg.roomId)))) {
const fromGame = (session.game && session.game.roomId === Number(msg.roomId))
|| (session.lastGame && session.lastGame.roomId === Number(msg.roomId) && Date.now() < session.lastGame.until);
if (session.room && (session.room.id === msg.roomId || fromGame)) {
// at most text, type and one extra field, and no essays.
const fields = decodeEntities(msg.cdata("txt") || "").split("%").slice(0, 3);
if (fields[0].length > config.maxChatLength || (fields[2] || "").length > MAX_CHAT_EXTRA) {