mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat(minigames): implement buddy game bubbles
Introduce a bubble system that allows players to signal availability for specific buddy games. Other players in the same room can click the bubble to initiate a game. The implementation handles bubble visibility for new arrivals and ensures bubbles are cleared when players leave rooms or start other activities.
This commit is contained in:
1 parent
bb532a78bb
commit
422719dade
3 files changed
+169
-5
No files matched your search
+94
-5
@@ -103,7 +103,7 @@ function serial() {
|
||||
|
||||
let nextGameRoomId = 500000; // well clear of the world's room ids
|
||||
|
||||
module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
|
||||
module.exports = ({tell, leaveRoom, findOnline, blocks, watchers}) => {
|
||||
// MinigameInfo.init, the 19 fields the "mi" reply carries for a game.
|
||||
const info = game => [
|
||||
game.id,
|
||||
@@ -145,6 +145,65 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
|
||||
}
|
||||
};
|
||||
|
||||
// A buddy game's bubble over a player's head, which anyone else in the
|
||||
// room can click to play them (UserCommXtCommManager.sendCustomPVPMessage:
|
||||
// a chat line "on|off" of type 12 with the game's id after it). the client
|
||||
// reads it back as "on|<gameDefId>" or "off", and its sender waits for
|
||||
// their own before going on. `session.pvpBubble` is the game's id.
|
||||
const BUBBLE = "12";
|
||||
const bubbleLine = session => [`on|${session.pvpBubble}`, BUBBLE, 0];
|
||||
const bubbleSeers = session => watchers(session).filter(other => !blocks.either(other.account, session.account));
|
||||
// the bubble goes for everyone else. the player's own "off" waits, when
|
||||
// they are in a game, till they are out of it: it would end the game the
|
||||
// client has only just set up (MinigameManager.readySelfForPvpGame).
|
||||
const dropBubble = session => {
|
||||
if (!session.pvpBubble) {
|
||||
return;
|
||||
}
|
||||
session.pvpBubble = null;
|
||||
if (session.room) {
|
||||
for (const other of bubbleSeers(session)) {
|
||||
other.sendXt("uc", session.room.id, session.id, "off", BUBBLE);
|
||||
}
|
||||
}
|
||||
};
|
||||
const bubbleOff = session => {
|
||||
if (session.game) {
|
||||
session.bubbleOffOwed = true;
|
||||
}
|
||||
else if (session.room) {
|
||||
session.bubbleOffOwed = false;
|
||||
session.sendXt("uc", session.room.id, session.id, "off", BUBBLE);
|
||||
}
|
||||
};
|
||||
const bubble = (session, word, gameDefId) => {
|
||||
if (word !== "on") {
|
||||
dropBubble(session);
|
||||
bubbleOff(session);
|
||||
return;
|
||||
}
|
||||
const def = games.get(Number(gameDefId));
|
||||
if (!def || !def.buddy || !Object.hasOwn(buddyGames, def.swf) || !session.room || session.game || session.invite
|
||||
|| session.invisible || !accounts.featureOn(session.account, "gameInvites")) {
|
||||
if (session.room && !session.game) {
|
||||
tell(session, session.invisible ? "Nobody can see you to play with you." : "You cannot ask for a game right now.");
|
||||
}
|
||||
dropBubble(session);
|
||||
bubbleOff(session);
|
||||
return;
|
||||
}
|
||||
session.pvpBubble = def.id;
|
||||
for (const other of [session, ...bubbleSeers(session)]) {
|
||||
other.sendXt("uc", session.room.id, session.id, ...bubbleLine(session));
|
||||
}
|
||||
};
|
||||
// a bubble that is up, for a player who has just been shown its owner.
|
||||
const showBubble = (to, owner) => {
|
||||
if (owner.pvpBubble && owner.room && to !== owner && !blocks.either(to.account, owner.account)) {
|
||||
to.sendXt("uc", owner.room.id, owner.id, ...bubbleLine(owner));
|
||||
}
|
||||
};
|
||||
|
||||
// takes the player out of the game they are in, if any, and out of an
|
||||
// invitation.
|
||||
const leave = session => {
|
||||
@@ -154,6 +213,9 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
|
||||
return;
|
||||
}
|
||||
session.game = null;
|
||||
if (session.bubbleOffOwed) {
|
||||
bubbleOff(session);
|
||||
}
|
||||
game.players = game.players.filter(player => player !== session);
|
||||
if (game.lobby) {
|
||||
if (game.players.length === 0) {
|
||||
@@ -208,6 +270,11 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
|
||||
// minigamePetMastery) and who is in the game (joinGameResponse).
|
||||
const seat = (session, game, music) => {
|
||||
const avatar = activeAvatar(session.account);
|
||||
// off to a game: a bubble still up goes (and its owner is told after).
|
||||
if (session.pvpBubble) {
|
||||
dropBubble(session);
|
||||
session.bubbleOffOwed = true;
|
||||
}
|
||||
session.game = game;
|
||||
session.sendXt("rj", -1, 1, `game${game.def.id}_${game.roomId}`, game.roomId, game.players.length, game.players.length, 0, 0,
|
||||
0, 1, 0, 1, game.def.type === IN_ROOM ? 1 : 0, // isPrivate, isGame, isLimbo, isTemp, isSubRoom
|
||||
@@ -683,13 +750,29 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
|
||||
session.invite = target.invite = {def, sender: session, target};
|
||||
target.sendXt("mp", -1, def.id, 0, session.account.username, 1);
|
||||
},
|
||||
// an open challenge to whoever walks up (UserCommXtCommManager.sendCustomPVPMessage); not offered.
|
||||
mcp() {},
|
||||
// a click on another player's game bubble (MinigameXtCommManager
|
||||
// .sendMinigameCustomPvpJoinMsg): [gameDefId, 0, their username]. the
|
||||
// game starts at once, as an invitation said yes to; a bubble that is
|
||||
// gone by now is answered as an invitation said no to
|
||||
// (MinigameManager.pvpResponse), which puts the clicker back as they were.
|
||||
mcp(session, roomId, [gameDefId, , username]) {
|
||||
const def = games.get(Number(gameDefId));
|
||||
const host = findOnline(String(username || ""));
|
||||
const free = player => player && player.room && !player.game && !player.invite;
|
||||
if (!def || !host || host === session || host.pvpBubble !== def.id || host.room !== session.room
|
||||
|| !free(session) || !free(host) || blocks.either(session.account, host.account)
|
||||
|| !accounts.featureOn(session.account, "gameInvites")) {
|
||||
session.sendXt("mp", -1, def ? def.id : Number(gameDefId) || 0, 1);
|
||||
return;
|
||||
}
|
||||
startMatch(def, host, session);
|
||||
},
|
||||
};
|
||||
|
||||
// the HUD's Games window (GameJoinPopup, generic list 341): the playable
|
||||
// games that have a picture for it, by name.
|
||||
const library = [...games.values()].filter(game => game.icon && game.ready !== false)
|
||||
// games that have a picture for it, by name. A buddy game's card picture
|
||||
// is drawn the same way, and picking one there puts its bubble up.
|
||||
const library = [...games.values()].filter(game => (game.icon || (game.buddy && game.card)) && game.ready !== false)
|
||||
.sort((one, other) => one.title.localeCompare(other.title)).map(game => game.id);
|
||||
|
||||
// the buddy games' descriptions, sent unasked when a player arrives: a
|
||||
@@ -704,6 +787,12 @@ module.exports = ({tell, leaveRoom, findOnline, blocks}) => {
|
||||
handlers,
|
||||
leave,
|
||||
greet,
|
||||
bubble,
|
||||
showBubble,
|
||||
// out of the room: nobody there is left to see the bubble.
|
||||
roomLeft: session => {
|
||||
session.pvpBubble = null;
|
||||
},
|
||||
library: () => library,
|
||||
// the room a player in a room-replacing game came from, for the panel.
|
||||
playing: session => (session.game ? session.game.def.title : null),
|
||||
|
||||
@@ -436,6 +436,7 @@ const sendAvatarCreate = (to, target) => {
|
||||
if (target.invisible) {
|
||||
to.sendXt("xiv", -1, target.id, 1);
|
||||
}
|
||||
minigames.showBubble(to, target);
|
||||
};
|
||||
|
||||
// redraws `session`'s animal for everyone else in the room, for changes the
|
||||
@@ -1190,6 +1191,7 @@ const leaveRoom = session => {
|
||||
room.sessions.delete(session);
|
||||
session.room = null;
|
||||
session.pos = null;
|
||||
minigames.roomLeft(session);
|
||||
for (const other of room.sessions) {
|
||||
// AvatarManager.avatarRemoveResponse
|
||||
if (sees(other, session)) {
|
||||
@@ -1629,6 +1631,11 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
fields[1] = String(Number(fields[1]));
|
||||
// A buddy game's bubble over the player's head (lib/minigames.js).
|
||||
if (fields[1] === "12") {
|
||||
minigames.bubble(session, fields[0], fields[2]);
|
||||
return;
|
||||
}
|
||||
// typed chat shows as "..." over the sender until the server sends
|
||||
// it back (UserCommXtCommManager.sendChatMessage); everything else
|
||||
// the sender has already shown themselves.
|
||||
|
||||
Reference in new issue
Block a user