Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Hostable<T>

Represents an object capable of hosting games.

See HostableEvents for events to listen to.

Type parameters

  • T: HostableEvents

Hierarchy

Index

Properties

Static FixedUpdateInterval

FixedUpdateInterval: number = ...

How often a FixedUpdate should be called.

code

code: number

The code of the room.

config

config: HostableOptions = {}

counter

counter: number

The current start counter for the room.

endGameIntents

endGameIntents: EndGameIntent<any>[]

Every end game intent that should happen in a queue to be or not to be canceled.

The first item of each element being the name of the end game intent and the second being metadata passed with it.

See RoomEndGameIntentEvent to cancel an end game intent, or see Hostable.registerEndGameIntent to register your own.

See RoomGameEndEvent to listen for a game actually ending.

gameData

gameData: undefined | GameData<Hostable<T>>

An instance of the game data in the room. Contains information about players such as their name, colour, hat etc.

It is possible for more than one game data to be spawned, however this property is set and cleared for simplicity.

See Hostable.objectList if you're looking to find all game data objects that have been spawned.

gameState

gameState: GameState

The state that the game is currently in.

hostId

hostId: number

The ID of the host of the room.

lobbyBehaviour

lobbyBehaviour: undefined | LobbyBehaviour<Hostable<T>>

An instance of the lobby behaviour in the room. Spawned when the room is currently in the lobby waiting for a game to start.

It is possible for more than one lobby behaviour to be spawned, however this property is set and cleared for simplicity.

See Hostable.objectList if you're looking to find all lobby behaviour objects that have been spawned.

meetingHud

meetingHud: undefined | MeetingHud<Hostable<T>>

An instance of the meeting hud in the room. Spawned when a meeting is started.

It is possible for more than one meeting hud to be spawned, however this property is set and cleared for simplicity.

See Hostable.objectList if you're looking to find all meeting hud objects that have been spawned.

messageStream

messageStream: BaseGameDataMessage[]

The current message stream to be sent to the server on fixed update.

netobjects

netobjects: Map<number, Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<T>>>

The networkable components in the room.

objectList

objectList: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<any>>[]

A list of all objects in the room.

players

players: Map<number, PlayerData<Hostable<T>>>

The players in the room.

privacy

privacy: PrivacyType

The privacy state of the room.

registeredPrefabs

registeredPrefabs: Map<number, NetworkableConstructor<any>[]>

A map of spawn type -> objects used in the protocol. Useful to register custom INO (inner net objects) such as replicating behaviour from a client mod, see Hostable.registerPrefab.

registeredRoles

registeredRoles: Map<number, typeof BaseRole>

All roles that can be assigned to players. See Hostable.registerRole.

settings

settings: GameSettings

The settings of the room.

shipStatus

shipStatus: undefined | InnerShipStatus<Hostable<T>>

An instance of the ship status in the room. Spawned when a game is started and represents the current map.

It is possible for more than one ship status to be spawned, however this property is set and cleared for simplicity.

See Hostable.objectList if you're looking to find all ship status objects that have been spawned.

voteBanSystem

voteBanSystem: undefined | VoteBanSystem<Hostable<T>>

An instance of the voting ban system in the room. Used as a utility object for handling kick and ban votes.

It is possible for more than one vote ban system to be spawned, however this property is set and cleared for simplicity.

See Hostable.objectList if you're looking to find all vote ban system objects that have been spawned.

Methods

FixedUpdate

  • FixedUpdate(): Promise<void>

broadcast

  • broadcast(gamedata: BaseGameDataMessage[], payloads?: BaseRootMessage[], include?: (number | PlayerData<Hostable<any>>)[], exclude?: (number | PlayerData<Hostable<any>>)[], reliable?: boolean): Promise<void>

canManageObject

  • canManageObject(object: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<any>>): boolean
  • Whether or not this client/room is able to manage an object, i.e. perform host actions on it.

    Parameters

    • object: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<any>>

      The object to manage.

    Returns boolean

    Whether or not the object can be managed by this client/room.

checkPlayersRemaining

  • checkPlayersRemaining(): void

createFakePlayer

  • createFakePlayer(isNew?: boolean): PlayerData<Hostable<T>>
  • Create a fake player in the room that doesn't need a client to be connected to own it.

    To dispose of the player, use player.despawn().

    Parameters

    • isNew: boolean = true

      Whether or not the player should be seen jumping off of the seat in the lobby.

    Returns PlayerData<Hostable<T>>

    The fake player created.

despawnComponent

  • despawnComponent(component: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<T>>): void
  • Despawn a component.

    example
    room.despawnComponent(room.meetinghud);
    

    Parameters

    • component: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<T>>

      The component being despawned.

    Returns void

destroy

  • destroy(): void

emit

  • emit<Event>(event: Event): Promise<Event>

emitSerial

  • emitSerial<Event>(event: Event): Promise<Event>

emitSync

  • emitSync<Event>(event: Event): Event

endGame

  • endGame(reason: GameOverReason): Promise<void>

findPlayersWithName

  • findPlayersWithName(displayName: string): PlayerData<Hostable<T>>[]

getAvailablePlayerID

  • getAvailablePlayerID(): number
  • Get an available player ID.

    example
    // Get an available player ID and add it to the gamedata.
    const playerId = room.getAvailablePlayerID();
    room.gamedata.add(playerId);
    

    Returns number

    The player ID that was found.

getExistingObjectSpawn

getListeners

  • getListeners<Event>(event: string): Listener<Event>[]

getNextNetId

  • getNextNetId(): number

getPlayerByNetId

  • getPlayerByNetId(netId: number): undefined | PlayerData<Hostable<T>>
  • Get a player by one of their components' netIds.

    example
    const player = room.getPlayerByNetId(34);
    

    Parameters

    • netId: number

      The net ID of the component of the player to search.

    Returns undefined | PlayerData<Hostable<T>>

    The player that was found, or null if they do not exist.

getPlayerByPlayerId

  • getPlayerByPlayerId(playerId: number): undefined | PlayerData<Hostable<T>>
  • Get a player by their player ID.

    example
    const player = room.getPlayerByPlayerId(1);
    

    Parameters

    • playerId: number

      The player ID of the player.

    Returns undefined | PlayerData<Hostable<T>>

    The player that was found, or null if they do not exist.

getPlayerControlByPlayerId

  • getPlayerControlByPlayerId(playerId: number): undefined | PlayerControl<Hostable<T>>

handleEnd

  • handleEnd(reason: GameOverReason): Promise<void>
  • Handle when the game is ended.

    Parameters

    • reason: GameOverReason

      The reason for why the game ended.

    Returns Promise<void>

handleJoin

  • handleJoin(joinInfo: PlayerJoinData): any
  • Handle when a client joins the game.

    Parameters

    • joinInfo: PlayerJoinData

    Returns any

handleLeave

  • handleLeave(resolvable: PlayerDataResolvable): Promise<null | PlayerData<Hostable<T>>>
  • Handle when a client leaves the game.

    Parameters

    • resolvable: PlayerDataResolvable

      The client that left the game.

    Returns Promise<null | PlayerData<Hostable<T>>>

handleReady

  • handleReady(player: PlayerDataResolvable): Promise<void>
  • Handle a client readying up.

    Parameters

    • player: PlayerDataResolvable

      The client that readied.

    Returns Promise<void>

handleStart

  • handleStart(): Promise<void>

murderIsValid

  • murderIsValid(murderer: PlayerData<Hostable<any>>, victim: PlayerData<Hostable<any>>): boolean
  • Parameters

    • murderer: PlayerData<Hostable<any>>
    • victim: PlayerData<Hostable<any>>

    Returns boolean

off

  • off<EventName>(event: EventName, listener: Listener<T[EventName]>): void
  • off<K>(event: string, listener: Listener<K>): void
  • Type parameters

    • EventName: string | number | symbol

    Parameters

    • event: EventName
    • listener: Listener<T[EventName]>

    Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns void

on

  • on<EventName>(event: EventName, listener: Listener<T[EventName]>): () => void
  • on<K>(event: string, listener: Listener<K>): () => void
  • Type parameters

    • EventName: string | number | symbol

    Parameters

    • event: EventName
    • listener: Listener<T[EventName]>

    Returns () => void

      • (): void
      • Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns () => void

      • (): void
      • Returns void

once

  • once<EventName>(event: EventName, listener: Listener<T[EventName]>): () => void
  • once<K>(event: string, listener: Listener<K>): () => void
  • Type parameters

    • EventName: string | number | symbol

    Parameters

    • event: EventName
    • listener: Listener<T[EventName]>

    Returns () => void

      • (): void
      • Returns void

  • Type parameters

    Parameters

    • event: string
    • listener: Listener<K>

    Returns () => void

      • (): void
      • Returns void

registerEndGameIntent

registerPrefab

  • registerPrefab(spawnType: number, components: NetworkableConstructor<Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<any>>>[]): void
  • Register a custom INO spawn object by its spawn type. Can also override built-in objects.

    Parameters

    • spawnType: number

      The spawn type of the component as an integer.

    • components: NetworkableConstructor<Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<any>>>[]

      The components in the object. The first component should be the main object which will inherit the rest of the components.

    Returns void

registerRole

  • registerRole(roleCtr: typeof BaseRole): void
  • Register a role that can be assigned to a player.

    Parameters

    • roleCtr: typeof BaseRole

      The role to register to the room.

    Returns void

removeAllListeners

  • removeAllListeners(): void

removeListeners

  • removeListeners(event: string): void

resolvePlayer

  • resolvePlayer(player: PlayerDataResolvable): undefined | PlayerData<Hostable<T>>
  • Resolve a player by some identifier.

    example
    // Resolve a player by their client id.
    const player = room.resolvePlayer(11013);
    

    Parameters

    • player: PlayerDataResolvable

      The identifier to resolve to a player.

    Returns undefined | PlayerData<Hostable<T>>

    The resolved player.

resolvePlayerClientID

  • resolvePlayerClientID(player: PlayerDataResolvable): undefined | number
  • Resolve a client id by some identifier.

    Parameters

    • player: PlayerDataResolvable

      The identifier to resolve to a client ID.

    Returns undefined | number

    The resolved client ID.

resolvePlayerId

setCode

  • setCode(code: RoomID): void
  • Set the code of the room.

    example
    room.setCode("ABCDEF");
    

    Parameters

    • code: RoomID

    Returns void

setHost

  • setHost(host: PlayerDataResolvable): Promise<void>
  • Set the host of the room. If the current client is the host, it will conduct required host changes. e.g. Spawning objects if they are not already spawned.

    Parameters

    • host: PlayerDataResolvable

      The new host of the room.

    Returns Promise<void>

setPrivacy

  • setPrivacy(privacy: PrivacyType): Promise<void>
  • Change the the privacy of the room.

    example
    room.setAlterGameTag(AlterGameTag.ChangePrivacy, 1); // 0 for private, 1 for public.
    

    Parameters

    • privacy: PrivacyType

    Returns Promise<void>

setSettings

  • setSettings(settings: Partial<AllGameSettings>): void
  • Change the settings of the room. If the host, it will broadcast these changes.

    example
    room.syncSettings({
      crewmateVision: 0.5,
      votingTime: 120
    });
    

    Parameters

    • settings: Partial<AllGameSettings>

      The settings to set to (Can be partial).

    Returns void

spawnComponent

  • spawnComponent(component: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<T>>): void
  • Spawn a component (Not broadcasted to all clients, see Hostable.spawnPrefabOfType).

    example
    const meetinghud = new MeetingHud(
      this,
      this.getNextNetId(),
      ownerId,
      {
        dirtyBit: 0,
        states: new Map(),
      }
    );
    
    this.spawnComponent(meetinghud);
    

    Parameters

    • component: Networkable<any, NetworkableEvents<Hostable<any>>, Hostable<T>>

      The component being spawned.

    Returns void

spawnNecessaryObjects

  • spawnNecessaryObjects(): void

spawnPrefabOfType

  • spawnPrefabOfType(spawnType: number, ownerId: undefined | number | PlayerData<Hostable<any>>, flags?: number, componentData?: any[], doBroadcast?: boolean, doAwake?: boolean): undefined | Networkable<any, any, Hostable<T>>
  • Spawn a prefab of an object.

    example
    room.spawnPrefab(SpawnType.Player, client.myPlayer);
    

    Parameters

    • spawnType: number

      The type of object to spawn.

    • ownerId: undefined | number | PlayerData<Hostable<any>>
    • Optional flags: number
    • Optional componentData: any[]
    • doBroadcast: boolean = true
    • doAwake: boolean = true

    Returns undefined | Networkable<any, any, Hostable<T>>

    The object that was spawned.

wait

  • wait<EventName>(event: EventName): Promise<T[EventName]>
  • wait(event: string): Promise<BasicEvent>

waitf

  • waitf<EventName>(event: EventName, filter: (ev: T[EventName]) => boolean | Promise<boolean>): Promise<T[EventName]>
  • waitf<K>(event: string, filter: (ev: K) => boolean | Promise<boolean>): Promise<BasicEvent>
  • Type parameters

    • EventName: string | number | symbol

    Parameters

    • event: EventName
    • filter: (ev: T[EventName]) => boolean | Promise<boolean>
        • (ev: T[EventName]): boolean | Promise<boolean>
        • Parameters

          • ev: T[EventName]

          Returns boolean | Promise<boolean>

    Returns Promise<T[EventName]>

  • Type parameters

    Parameters

    • event: string
    • filter: (ev: K) => boolean | Promise<boolean>
        • (ev: K): boolean | Promise<boolean>
        • Parameters

          • ev: K

          Returns boolean | Promise<boolean>

    Returns Promise<BasicEvent>

Constructors

constructor

Accessors

destroyed

  • get destroyed(): boolean

host

  • get host(): undefined | PlayerData<this>

hostIsMe

  • get hostIsMe(): boolean

myPlayer

  • get myPlayer(): undefined | PlayerData<this>

Generated using TypeDoc