Files
Magic-Garden-Bot/protocol.js
2025-12-09 23:21:09 +00:00

75 lines
1.7 KiB
JavaScript

const HANDSHAKE_SCOPE = ["Room"];
// Based on logs, Ping and most game actions use ["Room", "Quinoa"]
const GAME_SCOPE = ["Room", "Quinoa"];
module.exports = {
SCOPES: {
HANDSHAKE: HANDSHAKE_SCOPE,
GAME: GAME_SCOPE
},
TYPES: {
VOTE: 'VoteForGame',
SELECT: 'SetSelectedGame',
PING: 'Ping',
PONG: 'Pong',
WELCOME: 'Welcome',
PARTIAL_STATE: 'PartialState',
TELEPORT: 'Teleport',
PLANT: 'PlantSeed',
HARVEST: 'HarvestCrop',
SELL: 'SellAllCrops',
PURCHASE: 'PurchaseSeed'
},
createHandshakeMessages: (gameName = 'Quinoa') => [
{
scopePath: HANDSHAKE_SCOPE,
type: 'VoteForGame',
gameName: gameName
},
{
scopePath: HANDSHAKE_SCOPE,
type: 'SetSelectedGame',
gameName: gameName
}
],
createPing: () => ({
type: 'Ping',
id: Date.now(),
scopePath: GAME_SCOPE
}),
createTeleport: (x, y) => ({
type: 'Teleport',
position: { x, y },
scopePath: GAME_SCOPE
}),
createPlant: (slot, species) => ({
type: 'PlantSeed',
slot: parseInt(slot),
species: species,
scopePath: GAME_SCOPE
}),
createHarvest: (slot) => ({
type: 'HarvestCrop',
slot: parseInt(slot),
slotsIndex: 0, // Default to 0 as seen in logs
scopePath: GAME_SCOPE
}),
createSellAll: () => ({
type: 'SellAllCrops',
scopePath: GAME_SCOPE
}),
createPurchase: (species) => ({
type: 'PurchaseSeed',
species: species,
scopePath: GAME_SCOPE
})
};