uncategorized sandboxRoom - wxyz-abcd/node-haxball GitHub Wiki

SandboxRoom

This is not an instance of a class, but a custom object generated on the fly, with the following keys:

1. Properties

  • state: RoomState: An object containing all information about the current room state. Note that this object also has all of the functions explained below in section: sandbox mode functions. (It only has copy() instead of takeSnapshot().)
  • gameState: GameState | null: The original object that holds the game state information. Returns null if game is not active.
  • currentPlayerId: int : This is a read-only property that always returns 0. It is only added for compatibility with renderers. (And it is only used in the initialization code of renderers.)

2. Functions

  • setSimulationSpeed(coefficient: number): void

    Changes the speed of the simulation.

    Parameters:

    • coefficient: number: The desired speed coefficient. Must be a real number >=0. Meaning of possible value ranges is as follows:
      • value = 0 : stop simulation.
      • 0 < value < 1 : slow-motion simulation.
      • value = 1 : normal speed simulation.
      • value > 1 : fast-motion simulation.

    Return value: void.

  • runSteps(count: int): void

    Runs the simulation count steps. Simulation should be stopped for this function to work as expected.

    Parameters:

    • count: int: Number of steps to run the simulation.

    Return value: void.

  • executeEvent(eventMsg: HaxballEvent): void

    Applies an event to the current room state. For example; the event object may come from a ReplayData structure, or from a onOperationReceived(type, msg, globalFrameNo, clientFrameNo, customData) callback.

    Parameters:

    • eventMsg: HaxballEvent: The event message to apply.

    Return value: void.

  • takeSnapshot(): RoomState

    Returns a snapshot of the current room state. You can load this object directly into sandbox using its useSnapshot(roomState) function. Note that the values stored here are the currently active values, not the static and stored ones.

    Return value: The snapshot copy of the current RoomState object.

  • useSnapshot(newRoomState: RoomState): void

    Generates a copy of the given RoomState and sets the current room state reference to the generated RoomState.

    Parameters:

    • newRoomState: RoomState: The RoomState to use. Should be created by takeSnapshot() first.

    Return value: void.

  • playerJoin(id: int, name: string, flag: string, avatar: string, conn: string, auth: string): void

    Adds a new player to the room.

    Parameters:

    • id: int: Id of the new player.
    • name: string: Name of the new player.
    • flag: string: Flag of the new player.
    • avatar: string: Avatar of the new player.
    • conn: string: Connection string of the new player.
    • auth: string: Auth of the new player.

    Return value: void.

  • playerLeave(playerId: int): void

    Removes a player from the room.

    Parameters:

    • playerId: int: Id of the player to be removed.

    Return value: void.

  • playerInput(input: int, byId: int): void

    Sets the current key state of a player.

    Parameters:

    • input: int: The desired key state of the player.
    • byId: int: Id of the player whose key state is being set.

    Return value: void.

  • playerChat(msg: string, byId: int): void

    Sends a chat message as a player.

    Parameters:

    • msg: string: The chat message to be sent.
    • byId: int: Id of the player who sent this message.

    Return value: void.

  • setKeyState(state: int): void

    Sets the current player's key state. (added for compatibility with normal rooms.)

    Parameters:

    • state: int: The desired key state.

    Return value: void.

  • setPlayerChatIndicator(value: int, byId: int): void

    Sets the chat indicator status of a player.

    Parameters:

    • value: int: The desired chat indicator status.
    • byId: int: Id of the player whose chat indicator status is being set.

    Return value: void.

  • setPlayerAvatar(value: string, byId: int): void

    Sets the avatar of a player.

    Parameters:

    • value: string: The desired avatar value.
    • byId: int: Id of the player whose avatar is being set.

    Return value: void.

  • setCurrentStadium(value: Stadium, byId: int, onError: Function): void

    Sets the current stadium using a fake identity.

    Parameters:

    • value: Stadium: The desired stadium value.
    • byId: int: The fake id of the player who changed this stadium.
    • onError: Function: An error callback.

    Return value: void.

  • sendAnnouncement(msg: string, color: int=-1, style: int=0, sound: int=1, targetId: int | null, byId: int=0): void

    Sends an announcement message to a player.

    Parameters:

    • msg: string: Contents of the announcement message.
    • color: int=-1: Color of the announcement message.
    • style: int=0: Style of the announcement message.
    • sound: int=1: Sound of the announcement message.
    • targetId: int | null: Id of the player who will receive this announcement.
      • If this value is null, the announcement is sent to everyone.
    • byId: int: This value must always be 0.

    Return value: void.

  • startGame(byId: int): void

    Starts the game using a fake identity.

    Parameters:

    • byId: int: Id of the player who started the game.

    Return value: void.

  • stopGame(byId: int): void

    Stops the game using a fake identity.

    Parameters:

    • byId: int: Id of the player who stopped the game.

    Return value: void.

  • setGamePaused(value: boolean, byId: int): void

    Pauses/resumes the game using a fake identity.

    Parameters:

    • value: boolean: The desired pausedness value of the game.
      • true: Pauses the game, if it is not already paused.
      • false: Resumes the game, if it is not already resumed.
    • byId: int: Id of the player who paused/resumed the game.

    Return value: void.

  • setScoreLimit(value: int, byId: int): void

    Sets the game's score limit using a fake identity.

    Parameters:

    • value: int: The desired score limit of the game.
    • byId: int: Id of the player who set the game's score limit.

    Return value: void.

  • setTimeLimit(value: int, byId: int): void

    Sets the game's time limit using a fake identity.

    Parameters:

    • value: int: The desired time limit of the game.
    • byId: int: Id of the player who set the game's time limit.

    Return value: void.

  • setTeamsLock(value: int, byId: int): void

    Locks/unlocks the teams using a fake identity.

    Parameters:

    • value: int: The desired teams lock value of the game.
    • byId: int: Id of the player who set the game's teams lock value.

    Return value: void.

  • autoTeams(byId: int): void

    Removes the last 2 players from spectators and adds them to opposite teams in order using a fake identity.

    Parameters:

    • byId: int: Id of the player who changed the teams of these players.

    Return value: void.

  • setPlayerTeam(playerId: int, teamId: int, byId: int): void

    Moves a player to a team using a fake identity.

    Parameters:

    • playerId: int: Id of the player whose team is desired to be changed.
    • teamId: int: Id of the desired team.
    • byId: int: Id of the player who changed the team of this player.

    Return value: void.

  • setKickRateLimit(min: int, rate: int, burst: int, byId: int): void

    Sets the room's kick rate limit using a fake identity.

    Parameters:

    • min: int: The desired min value of kick rate limit.
    • rate: int: The desired rate value of kick rate limit.
    • burst: int: The desired burst value of kick rate limit.
    • byId: int: Id of the player who set the kick rate limit of the room.

    Return value: void.

  • setTeamColors(teamId: int, angle: int, colors: int[], byId: int): void

    Sets the colors of a team using a fake identity.

    Parameters:

    • teamId: int: Id of the team whose colors are desired to be changed.
      • 1: red.
      • 2: blue.
    • angle: int: The angle of stripes. (in degrees)
    • colors: int[]: Minimum 2, maximum 4 parseable(hex-rgb) color strings.
    • byId: int: Id of the player who set the colors of the team.

    Return value: void.

  • setPlayerAdmin(playerId: int, value: boolean, byId: int): void

    Gives/takes away the admin status of a player using a fake identity.

    Parameters:

    • playerId: int: Id of the player whose admin status is being set.
    • value: boolean: The desired admin status of the player.
      • true: Give admin rights to the player.
      • false: Take away admin rights from the player.
    • byId: int: Id of the player who set the admin status of the player.

    Return value: void.

  • kickPlayer(playerId: int, reason: string | null, ban: boolean, byId: int): void

    Kicks/bans a player using a fake identity.

    Parameters:

    • playerId: int: Id of the desired player to be kicked/banned.
    • reason: string | null: Reason of kicking/banning.
      • If null, this event is interpreted as the player leaving by himself/herself.
    • ban: boolean: Whether this is a banning event or not.
    • byId: int: Id of the player who kicked/banned the player.

    Return value: void.

  • setPlayerSync(value: boolean, byId: int): void

    Set the synchronization status of a player.

    Parameters:

    • value: boolean: The desired synchronization status.
    • byId: int: Id of the player whose synchronization status is being set.

    Return value: void.

  • sendPingData(valueFunc: int[], byId: int): void

    Sets the ping values of all players.

    Parameters:

    • valueFunc: int[]: The desired ping values for all players.
    • byId: int: This value must always be 0.

    Return value: void.

  • setDiscProperties(discId: int, type: int, data: object, byId: int): void

    Sets the properties of a disc.

    Parameters:

    • discId: int: Id of the object whose properties are desired to be set.
    • type: int: The type of this operation.
      • 0: discId is actually the id of a disc.
      • 1: discId is actually the id of a player.
    • properties: object: The desired properties to set. This will not change the omitted keys of the disc. properties has the following structure:
      • x: number | null: The desired x coordinate of the disc.
      • y: number | null: The desired y coordinate of the disc.
      • xspeed: number | null: The desired x component of the speed of the disc.
      • yspeed: number | null: The desired y component of the speed of the disc.
      • xgravity: number | null: The desired x component of the gravity of the disc.
      • ygravity: number | null: The desired y component of the gravity of the disc.
      • radius: number | null: The desired radius of the disc.
      • bCoeff: number | null: The desired bouncing coefficient of the disc.
      • invMass: number | null: The desired inverse mass of the disc.
      • damping: number | null: The desired damping of the disc.
      • color: int | null: The desired color of the disc.
      • cMask: int | null: The desired collision mask of the disc.
      • cGroup: int | null: The desired collision group of the disc.
    • byId: int: This value must always be 0.

    Return value: void.

  • sendCustomEvent(type: int, data: object, byId: int): void

    Triggers a fake custom event using a fake identity.

    Parameters:

    • type: int: The type of the custom event.
    • data: object: The data of the custom event. (Any JSON object)
    • byId: int: Id of the player who triggered this custom event.

    Return value: void.

  • destroy(): void

    Frees the resources that are used by this object.

    Parameters: None.

    Return value: void.

⚠️ **GitHub.com Fallback** ⚠️