/// /// /// /// import { type Client, type ISendOptions, Room as colRoom } from "@colyseus/core"; import type { IBroadcastOptions } from "@colyseus/core/build/Room.js"; import type { ActionDefinition } from "../actions/types.js"; import type { BotActionsSet } from "../bots/botNeuron.js"; import { BotRunner } from "../bots/runner.js"; import { BotOptions } from "../player/bot.js"; import { Player, ServerPlayerMessage, Bot } from "../player/index.js"; import { GameClient } from "../state/client.js"; import { State } from "../state/state.js"; import type { Command } from "../command.js"; import { CommandsManager } from "../commandsManager/commandsManager.js"; import type { IntegrationHookNames, IntegrationHooks, IntegrationHookCallbackContext, IntegrationHookData } from "../integration.js"; import type { RoomDefinition } from "./roomType.js"; type BroadcastOptions = IBroadcastOptions & { undo: boolean; }; type ClientSendOptions = ISendOptions & { undo: boolean; }; /** * @ignore */ export declare abstract class Room = Record> extends colRoom implements RoomDefinition { patchRate: number; commandsManager: CommandsManager; /** * Reference to your game's `State` class. */ stateConstructor: new () => S; playersCount?: PlayersCount; variantsConfig?: VariantsConfig; /** * May be undefined if the game doesn't include any * bot-related configuration */ botRunner?: BotRunner; /** * Set of all possible actions players can take in this game */ possibleActions: ActionDefinition[]; botActivities: BotActionsSet; /** * Direct reference to Bot "players". */ botClients: Bot[]; /** * All room's available integration tests */ integrationHooks: Record>; /** * Currently running integration test * @private */ currentIntegration: { name: string; data: IntegrationHookData; }; /** * An object passed down to integration hooks. * Contains limited set of methods on room and * additional (readonly) data defined in integration itself * @private */ integrationContext: IntegrationHookCallbackContext; /** * Count all connected clients, with planned bot players */ get allClientsCount(): number; /** * Count all clients who declared ready for the game. */ get readyClientsCount(): number; get name(): string; /** * Run a callback on integration hook, if available * @ignore */ _executeIntegrationHook(hookName: IntegrationHookNames): void; onCreate(options?: RoomCreateOptions): void; /** * Add client to `state.clients` * @returns `undefined` is client is already there or if the game is already started * * @ignore exposed only for testing, do not use */ addClient(sessionId: string): GameClient; addBot(bot: BotOptions): boolean; /** * Remove client from `state.clients` * * @ignore exposed only for testing, do not use */ removeClient(sessionId: string): boolean; /** * Is called when the client successfully joins the room, after onAuth has succeeded. * * So we have guarantee, this new client is still within `maxClients` limit. */ onJoin(newClient: Client): void; onLeave(client: Client, consented: boolean): void; clientSend(clientID: string, type: string | number, message?: any, options?: ClientSendOptions): void; clientSend(client: Client, type: string | number, message?: any, options?: ClientSendOptions): void; /** * For convenience. Wraps message with additional data (like undo) */ broadcast>(type: T, message?: AllServerMessageTypes[T], options?: BroadcastOptions): void; /** * Handles new incoming event from client (human or bot). * @returns ~~DEPRECATE - is anyone listening to this return value?...~~ server testing might benefit * `true` if action was executed, `false` if not, or if it failed. */ handleMessage(message: ServerPlayerMessage): Promise; /** * Override it to state your own conditions of whether the game can be started or not. * @returns {boolean} */ canGameStart(): boolean; /** * Will be called right after the game room is created. * Create your game state here: * * ~~```this.setState(new MyState())```~~ DON'T * * Prepare your play area now. * * @param state */ onInitGame(options?: RoomCreateOptions): void; /** * Will be called when clients agree to start the game. * `state.players` is already populated with all players. * Game options (variant data) is already set. * After this function, the game will give turn to the first player. * @param state */ onStartGame(): void | Command[]; /** * Invoked when players turn starts */ onPlayerTurnStarted(player: Player): void | Command[]; /** * Invoked when players turn ends */ onPlayerTurnEnded(player: Player): void | Command[]; /** * Invoked when each round starts. */ onRoundStart(): void | Command[]; /** * Invoked when a round is near completion. */ onRoundEnd(): void | Command[]; onDispose(): void; } export {};