node-haxball
Version:
The most powerful and lightweight API that allows you to develop your original Haxball(www.haxball.com) host, client, and standalone applications both on node.js and browser environments and also includes every possible hack and functionality that you can
2,052 lines (1,689 loc) • 378 kB
TypeScript
declare namespace MainReturnType {
/**
* The current version number of the API.
*/
export const version: string;
/**
* This object binds event (operation) names to numbers that are
* obtained during Haxball's event mechanism, to let us understand
* what kind of message is received from the client. By nature,
* these include only those events that can be sent by a client
* and received by a host.
*/
export enum OperationType {
/**
* The operation to send announcement text. This requires
* the sender to be the host of the current room.
*/
SendAnnouncement = 0,
/**
* The operation to set a player's chat indicator status.
*/
SendChatIndicator = 1,
/**
* The operation to check whether the client is in sync
* with the host. This requires the sender to be a client
* of the current room.
*/
CheckConsistency = 2,
/**
* The operation to set your own input. (key state)
*/
SendInput = 3,
/**
* The operation to send chat text.
*/
SendChat = 4,
/**
* The operation to add a player to the current room. This
* requires the sender to be the host of the current room.
*/
JoinRoom = 5,
/**
* The operation to leave the room, or kick/ban a player.
* (This is decided by the `reason` property being `null`.)
* The kick/ban operation requires the sender to be an admin
* in the current room.
*/
KickBanPlayer = 6,
/**
* The operation to start the game. This requires the sender
* to be an admin in the current room. Also, the game must
* not be active.
*/
StartGame = 7,
/**
* The operation to stop the game. This requires the sender
* to be an admin in the current room. Also, the game must
* be active.
*/
StopGame = 8,
/**
* The operation to pause or resume the game. This requires
* the sender to be an admin in the current room. Also, the
* game must be active.
*/
PauseResumeGame = 9,
/**
* The operation to set the score/time limit of the room.
* This requires the sender to be an admin in the current
* room. Also, the game must not be active.
*/
SetGamePlayLimit = 10, // SetScoreLimit + SetTimeLimit
/**
* The operation to set the room's current stadium. This
* requires the sender to be an admin in the current room.
* Also, the game must not be active.
*/
SetStadium = 11,
/**
* The operation to move a player to a team. This requires
* the sender to be an admin in the current room. If teams
* are not locked and the game is not active, the non-admin
* players are also allowed to use this event only to
* change their own teams.
*/
SetPlayerTeam = 12,
/**
* The operation to lock/unlock the room's teams. This
* requires the sender to be an admin in the current room.
*/
SetTeamsLock = 13,
/**
* The operation to grant/take away a player's admin rights.
* This requires the sender to be an admin in the current room.
*/
SetPlayerAdmin = 14,
/**
* The operation to automatically move one player from the
* spectators team to the red team, and one player to the
* blue team. This requires the sender to be an admin in the
* current room.
*/
AutoTeams = 15,
/**
* The operation to set your own synchronization status.
*/
SetPlayerSync = 16,
/**
* The operation to inform players of the ping values of
* each player. This requires the sender to be the host
* of the current room.
*/
Ping = 17,
/**
* The operation to set your own avatar.
*/
SetAvatar = 18,
/**
* The operation to set a team's colors. This requires the
* sender to be an admin in the current room.
*/
SetTeamColors = 19,
/**
* The operation to change the ordering of the players
* in the room. This requires the sender to be the host
* of the current room.
*/
ReorderPlayers = 20,
/**
* The operation to set the room's current stadium. This
* requires the sender to be an admin in the current room.
*/
SetKickRateLimit = 21,
/**
* The operation to set a player's headless avatar. This
* requires the sender to be the host of the current room.
*/
SetHeadlessAvatar = 22,
/**
* The operation to set a disc's properties. This requires
* the sender to be the host of the current room.
*/
SetDiscProperties = 23,
/**
* The operation to trigger a custom event. This requires
* the receiver to use this API, otherwise the operation
* will not be sent to that client. This might create
* desynchronization issues for non-API clients if the
* custom event includes important changes such as
* stadium objects, names, etc.
*/
CustomEvent = 24,
/**
* The operation to trigger a binary custom event. This
* requires the receiver to use this API, otherwise the
* operation will not be sent to that client. This might
* create desynchronization issues for non-API clients
* if the custom event includes important changes such as
* stadium objects, names, etc.
*/
BinaryCustomEvent = 25,
/**
* The operation to set a player's backend identity. This
* requires the receiver to use this API, otherwise the
* operation will not be sent to that client.
*/
SetPlayerIdentity = 26
}
/**
* While writing an addon, one might want to define variables whose values
* can be altered from outside the class. This object defines the type of
* variable that is defined inside the class. If you have a GUI to alter
* these values in real-time, you will have to implement the necessary
* GUI components to be able to edit these data types.
*/
export enum VariableType {
/**
* The void type. Used to show a button. Its value should be a function that will be executed when the button is clicked.
*/
Void = 0,
/**
* The boolean type. Can be `true` or `false`.
*/
Boolean = 1,
/**
* The integer type. Can be any integer. Should be used
* with a `range` property to define its range.
*/
Integer = 2,
/**
* The number type. Can be any real number or +-Infinity or NaN.
* Should be used with a `range` property to define its range.
*/
Number = 3,
/**
* The string type. Can be any string. Should be used
* with a `range` property to define the range of its length.
*/
String = 4,
/**
* The color type. This is in fact currently an integer in
* the range [-1, 16777216). Specialized only to be edited
* with a color picker component inside a GUI environment.
*/
Color = 5,
/**
* The collision flags type. This is in fact an ordinary
* integer. Specialized only to be edited with a collision
* flags editor component inside a GUI environment.
*/
CollisionFlags = 6,
/**
* The coordinate type. This is in fact an ordinary array
* using this structure: `[x: number, y: number]` where
* `x` and `y` are assumed to be the coordinates of a point.
* Specialized to be edited with a coordinate editor
* component inside a GUI environment.
*/
Coordinate = 7,
/**
* The team type. Currently, the only accepted values for
* this type is `1` and `2` where `1` is the red team and
* `2` is the blue team. Specialized to be edited with a
* team selector component inside a GUI environment.
*/
Team = 8,
/**
* The team type. Currently, the only accepted values for
* this type is `0`, `1` and `2` where `0` is the spectators
* team, `1` is the red team and `2` is the blue team.
* Specialized to be edited with a team selector component
* inside a GUI environment.
*/
TeamWithSpec = 9,
/**
* The background type. Currently, the only accepted values for
* this type is `0`, `1` and `2` where `0` means no background
* texture, `1` means grass texture and `2` means hockey texture.
* Specialized to be edited with a background selector component
* inside a GUI environment.
*/
BgType = 10,
/**
* The camera follow type. Currently, the only accepted values for
* this type is `0` and `1` where `0` means not to follow players and
* `1` means to follow the current player. Specialized to be edited
* with a camera follow selector component inside a GUI environment.
*/
CameraFollow = 11,
/**
* The kickOffReset type. Currently, the only accepted values for
* this type is `true` and `false` where `true` means "full" kick-off
* reset and `1` means "partial" kick-off reset. Specialized to be edited
* with a camera follow selector component inside a GUI environment.
*/
KickOffReset = 12,
/**
* The flag type. This is in fact a string value that represents the
* country code of a country. Specialized to be edited with a flag
* selector component inside a GUI environment.
*/
Flag = 13,
/**
* The file type. Should be editable with a file selector component
* inside a GUI environment.
*/
File = 14,
/**
* The playerId type. Should be editable with a player selector component
* inside a GUI environment.
*/
PlayerId = 15,
/**
* The keys array type. Should be editable with a keyboard keys editor component
* inside a GUI environment.
*/
Keys = 16,
/**
* A progress indicator. Its value should be an integer between 0 and 100, and
* null should disable the progressbar component inside a GUI environment.
*/
Progress = 17,
/**
* The player position type. Its possible values are the common player positions
* in most football manager games. (Check the PlayerPositionInGame enum)
*/
PlayerPositionInGame = 18
}
/**
* These values are used to track the current state of connection while joining a room. (Designed for the `onConnInfo(state, extraInfo)` callback in the `commonParams` parameter of `Room.join` function.)
*/
export enum ConnectionState {
/**
* "Trying reverse connection"
*/
TryingReverseConnection = -1,
/**
* "Connecting to master"
*/
ConnectingToMaster = 0,
/**
* "Connecting to peer"
*/
ConnectingToPeer = 1,
/**
* "Awaiting state"
*/
AwaitingState = 2,
/**
* "Active"
*/
Active = 3,
/**
* "Connection Failed"
*/
ConnectionFailed = 4
}
/**
* These values help understand whether a user is allowed to use an addon while joining a room or creating a room. They are designed to act like flags and be used in bitwise operations.
*/
export enum AllowFlags {
/**
* Whether the addon is useable while joining a room.
*/
JoinRoom = 1,
/**
* Whether the addon is useable while creating a room.
*/
CreateRoom = 2
}
/**
* These values help understand the type of addon object we are dealing with. One of these is assigned to the "addonType" property of every Addon constructor.
*/
export enum AddonType {
/**
* The "RoomConfig" addon type
*/
RoomConfig = 0,
/**
* The "Plugin" addon type
*/
Plugin = 1,
/**
* The "Renderer" addon type
*/
Renderer = 2,
/**
* The "Library" addon type
*/
Library = 3
}
/**
* These flags are used internally in Haxball's physics engine. They are designed to act like flags and be used in bitwise operations. Most types of stadium objects have collisionMask and collisionGroup properties that directly uses these flags to decide whether collision check should happen or not.
*
* Let's say discA seemingly collided with discB. The physics engine will just skip the collision without doing any further calculation if the below condition is not satisfied:
*
* ```js
* ((discA.collisionMask & discB.collisionGroup)>0) && ((discB.collisionMask & discA.collisionGroup)>0)
* ```
*/
export enum CollisionFlags {
/**
* If defined, the object will accept collisions with other "ball"s.
*/
ball = 1,
/**
* If defined, the object will accept collisions with other "red"s.
*/
red = 2,
/**
* If defined, the object will accept collisions with other "blue"s.
*/
blue = 4,
/**
* If defined, the object will accept collisions with other "red"s only until the kick-off event happens.
*/
redKO = 8,
/**
* If defined, the object will accept collisions with other "blue"s only until the kick-off event happens.
*/
blueKO = 16,
/**
* If defined, the object will act as a wall.
*/
wall = 32,
/**
* If defined, the object will become kickable. Haxball makes a player kick some object only if this `kick` flag exists in the object and the object is near enough to the player. (`4` map units, to be precise.)
*/
kick = 64,
/**
* If defined, the object will score a goal for the opposite team if it passes a goal line.
*/
score = 128,
/**
* Free
*/
free1 = 256,
/**
* Free
*/
free2 = 512,
/**
* Free
*/
free3 = 1024,
/**
* Free
*/
free4 = 2048,
/**
* Free
*/
free5 = 4096,
/**
* Free
*/
free6 = 8192,
/**
* Free
*/
free7 = 16384,
/**
* Free
*/
free8 = 32768,
/**
* Free
*/
free9 = 65536,
/**
* Free
*/
free10 = 131072,
/**
* Free
*/
free11 = 262144,
/**
* Free
*/
free12 = 524288,
/**
* Free
*/
free13 = 1048576,
/**
* Free
*/
free14 = 2097152,
/**
* Free
*/
free15 = 4194304,
/**
* Free
*/
free16 = 8388608,
/**
* Free
*/
free17 = 16777216,
/**
* Free
*/
free18 = 33554432,
/**
* Free
*/
free19 = 67108864,
/**
* Free
*/
free20 = 134217728,
/**
* Free
*/
c0 = 268435456,
/**
* Free
*/
c1 = 536870912,
/**
* Free
*/
c2 = 1073741824,
/**
* Free
*/
c3 = -2147483648
}
declare type int = number;
declare type uint8 = number;
declare type uint16 = number;
declare type int32 = number;
declare type uint32 = number;
declare type TemplateString = string;
declare type TextToNumberMap = {
[x: string]: number;
}
declare type NumberToTemplateStringMap = {
[x: number]: TemplateString;
}
/**
* These values help understand the direction of a movement for an axis. Only designed for room.keyState function to combine seperate directions for x and y axis to generate the value of the key to press.
*/
export enum Direction {
/**
* A backward movement.
*/
Backward = -1,
/**
* No movement.
*/
Still = 0,
/**
* A forward movement.
*/
Forward = 1
}
/**
* These values help understand whether the camera will follow the player or not. This is only used as a variable in all stadiums.
*/
export enum CameraFollow {
/**
* Camera is not bound to follow any player.
*/
None = 0,
/**
* Camera is bound to follow the current player.
*/
Player = 1
}
/**
* This is the type of the variable in a stadium that defines its background texture type.
*/
export enum BackgroundType {
/**
* No background texture.
*/
None = 0,
/**
* Grass background texture.
*/
Grass = 1,
/**
* Hockey background texture.
*/
Hockey = 2
}
/**
* This type lets us understand the actual state of the game. This type only exists in a GameState object.
*/
export enum GamePlayState {
/**
* This is the state of the game when the game has started,
* but kick-off has not happened yet.
*/
BeforeKickOff = 0,
/**
* This is the state of the game when the game is active and
* kick-off has already happened.
*/
Playing = 1,
/**
* This is the state of the game when the game is active and
* a goal has been scored. `GameState.goalTickCounter` is counting
* down from its initial value `150` while in this state. The
* game state is restored to `Playing` when this counter reaches `0`.
*/
AfterGoal = 2,
/**
* This is the state of the game when the game is active and a team
* has just been declared to have won the game. `GameState.goalTickCounter`
* is counting down from its initial value `300` while in this state. The
* game is stopped when this counter reaches `0`.
*/
Ending = 3
}
/**
* These are the common player positions in most football manager games.
*/
export enum PlayerPositionInGame {
/**
* No position. Unfortunately specific to Haxball. :)
*/
None = 0,
/**
* Goalkeeper
*/
GK = 1,
/**
* Sweeper
*/
SW = 2,
/**
* Wing Back Left
*/
WBL = 3,
/**
* Defender Left
*/
DL = 4,
/**
* Defender Centre
*/
DC = 5,
/**
* Defender Right
*/
DR = 6,
/**
* Wing Back Right
*/
WBR = 7,
/**
* Defensive Midfielder Left
*/
DML = 8,
/**
* Defensive Midfielder Centre
*/
DMC = 9,
/**
* Defensive Midfielder Right
*/
DMR = 10,
/**
* Midfielder Left
*/
ML = 11,
/**
* Midfielder Centre
*/
MC = 12,
/**
* Midfielder Right
*/
MR = 13,
/**
* Attacking Midfielder Left
*/
AML = 14,
/**
* Attacking Midfielder Centre
*/
AMC = 15,
/**
* Attacking Midfielder Right
*/
AMR = 16,
/**
* Left Forward
*/
FL = 17,
/**
* Centre Forward
*/
FC = 18,
/**
* Right Forward
*/
FR = 19,
/**
* Striker
*/
ST = 20,
};
/**
* The base class for all Haxball events.
*/
declare class HaxballEvent {
/**
* Type of the event. Should not be modified.
*/
public readonly eventType: OperationType;
/**
* Id of the player who triggered this event.
*/
public byId: uint16;
/**
* Creates a copy of this event object.
*/
public copy: ()=>HaxballEvent;
};
/**
* The event message structure that is created when a consistency check has to be performed.
*/
declare class ConsistencyCheckEvent extends HaxballEvent {
/**
* The consistency data to be checked.
*/
public data: ArrayBuffer;
};
/**
* The event message structure that is created when the game is started.
*/
declare class StartGameEvent extends HaxballEvent {};
/**
* The event message structure that is created when the game is stopped.
*/
declare class StopGameEvent extends HaxballEvent {};
/**
* The event message structure that is created when auto teams button is clicked.
*/
declare class AutoTeamsEvent extends HaxballEvent {};
/**
* The event message structure that is created when a player's synchronization status changes.
*/
declare class SetPlayerSyncEvent extends HaxballEvent {
/**
* The new synchronization status of the player who sent this event.
*/
public value: boolean;
};
/**
* The event message structure that is created when an announcement is sent/received.
*/
declare class SendAnnouncementEvent extends HaxballEvent {
/**
* The announcement message. ( max length = 1000 )
*/
public msg: string;
/**
* The color of the announcement message. Range: -1 <= `color` < 16777216.
* - The color value can be converted into a rgba string via API's `Utils.numberToColor` function.
* - The special value `-1` means `transparent` color.
*/
public color: int32;
/**
* The style of the announcement message. Must be one of the following:
* - 0: use document's default font style.
* - 1: fontWeight = "bold".
* - 2: fontStyle = "italic".
* - 3: fontSize = "12px".
* - 4: fontWeight = "bold", fontSize = "12px".
* - 5: fontWeight = "italic", fontSize = "12px".
*/
public style: uint8;
/**
* The sound of the announcement message. Must be one of the following:
* - 0: no sound.
* - 1: chat sound.
* - 2: highlight sound.
*/
public sound: uint8;
/**
* Id of the player who will receive the announcement.
* If `null`, everyone receives it. Can not be modified.
*/
public readonly targetId: uint16 | null;
};
/**
* The event message structure that is created when score limit or time limit is changed.
*/
declare class SetLimitEvent extends HaxballEvent {
/**
* Type of the event.
* - If `0`, score limit is changed.
* - Otherwise, time limit is changed.
*/
public type: uint8;
/**
* The new value of the limit. (0 <= value < 100)
*/
public newValue: int;
};
/**
* The event message structure that is created when a player's admin status is changed.
*/
declare class SetPlayerAdminEvent extends HaxballEvent {
/**
* Id of the player whose admin status is changed.
*/
public playerId: uint16;
/**
* The new admin status value.
*/
public value: boolean;
};
/**
* The event message structure that is created when a player changes its avatar.
*/
declare class SetAvatarEvent extends HaxballEvent {
/**
* The new avatar. ( max length = 2 )
*/
public value: string | null;
};
/**
* The event message structure that is created when a player is moved to a team.
*/
declare class SetPlayerTeamEvent extends HaxballEvent {
/**
* Id of the player whose team is changed.
*/
public playerId: uint16;
/**
* The new team.
*/
public team: Team;
};
/**
* The event message structure that is created when the stadium is changed.
*/
declare class SetStadiumEvent extends HaxballEvent {
/**
* The new stadium.
*/
public stadium: Impl.Stadium.Stadium;
};
/**
* The event message structure that is created when the team colors are being changed.
*/
declare class SetTeamColorsEvent extends HaxballEvent {
/**
* The team whose colors are being changed.
*/
public team: Team;
/**
* The new team colors.
*/
public colors: TeamColors;
};
/**
* The event message structure that is created when the teams lock status is changed.
*/
declare class SetTeamsLockEvent extends HaxballEvent {
/**
* The new teams lock status.
*/
public newValue: boolean;
};
/**
* The event message structure that is created when a new player joins the room.
*/
declare class JoinRoomEvent extends HaxballEvent {
/**
* Id of the new player.
*/
public id: uint16;
/**
* Name of the new player.
*/
public name: string | null;
/**
* Flag of the new player.
*/
public flag: string | null;
/**
* Avatar of the new player.
*/
public avatar: string | null;
/**
* Hex-encoded "connection string"(!) of the new player.
*/
public conn: string;
/**
* Auth of the new player.
*/
public auth: string;
};
/**
* The event message structure that is created when a player's headless avatar is changed.
*/
declare class SetHeadlessAvatarEvent extends HaxballEvent {
/**
* Id of the player whose headless avatar is changed.
*/
public playerId: uint16;
/**
* The new headless avatar value. ( max length = 2 )
*/
public value: string | null;
};
/**
* The event message structure that is created when the game is paused/resumed.
*/
declare class PauseResumeGameEvent extends HaxballEvent {
/**
* Whether the game is paused or not.
*/
public paused: boolean;
};
/**
* The event message structure that is created when a chat message is sent.
*/
declare class SendChatEvent extends HaxballEvent {
/**
* The chat text that is sent. ( max length = 140 )
*/
public text: string;
/**
* Id of the player who will receive the chat.
* If `null`, everyone receives it. Can not be modified.
*/
public readonly targetId: uint16 | null;
};
/**
* The event message structure that is created when a player's input changes.
*/
declare class SendInputEvent extends HaxballEvent {
/**
* The new input value. ( 0 <= input < 32 )
*/
public input: uint32;
};
/**
* The event message structure that is created when a player's chat indicator status changes.
*/
declare class SendChatIndicatorEvent extends HaxballEvent {
/**
* The new value of the chat indicator status. (0: off, 1: on)
*/
public value: uint8;
};
/**
* The event message structure that is created when a custom event is triggered by this API.
*/
declare class CustomEvent extends HaxballEvent {
/**
* Type of the custom event. This value can be anything you want.
*/
public type: uint32;
/**
* Custom data of the custom event. This value can be anything you want.
* It has to be any json object that can be `JSON.stringify`ed and `JSON.parse`d.
*/
public data: object;
};
/**
* The event message structure that is created when a binary custom event is triggered by this API.
*/
declare class BinaryCustomEvent extends HaxballEvent {
/**
* Type of the binary custom event. This value can be anything you want.
*/
public type: uint32;
/**
* Custom binary data of the binary custom event. This value can be anything you want.
*/
public data: Uint8Array;
};
/**
* The event message structure that is created when an identity event is triggered by this API.
*/
declare class IdentityEvent extends HaxballEvent {
/**
* Id of the player whose identity data is desired to be changed.
*/
public id: int32;
/**
* The identity data that should be received from the backend. It can be any JSON object.
*/
public data: object;
};
/**
* The event message structure that is created when a player leaves the room or is kicked/banned by the host.
*/
declare class KickBanPlayerEvent extends HaxballEvent {
/**
* Id of the player who left the room.
*/
public id: uint16;
/**
* The reason of kick/ban. ( max length = 100 )
* Interpreted as leaving by himself/herself if this value is `null`.
*/
public reason: string | null;
/**
* Whether the player is banned or not.
*/
public ban: boolean;
};
/**
* The event message structure that is created when the host calls room.reorderPlayers function.
*/
declare class ReorderPlayersEvent extends HaxballEvent {
/**
* Id of the players who will be reordered in the player list.
*/
public playerIdList: uint16[];
/**
* Whether the players will be moved to the top or bottom of the list.
*/
public moveToTop: boolean;
};
/**
* The event message structure that is created when the host calls room.setDiscProperties or room.setPlayerDiscProperties function.
*/
declare class SetDiscPropertiesEvent extends HaxballEvent {
/**
* Id of the disc/player whose properties are changed.
*/
public id: uint16;
/**
* If `true`, this is triggered by room.setPlayerDiscProperties, and `id` is the player's id.
* Otherwise, this is triggered by room.setDiscProperties, and `id` is the disc's id.
*/
public type: boolean;
/**
* Contains the floating point properties that are sent, in this order:
* `[x, y, xspeed, yspeed, xgravity, ygravity, radius, bCoeff, invMass, damping]`
* If any of these values are `null`, it means that that value is not modified.
*/
public data1: (number | null)[];
/**
* Contains the integer properties that are sent, in this order:
* `[color, cMask, cGroup]`
* If any of these values are `null`, it means that that value is not modified.
*/
public data2: (int | null)[];
};
/**
* The event message structure that is created when the kick rate limit is changed.
*/
declare class SetKickRateLimitEvent extends HaxballEvent {
/**
* The `min` component of the kick rate limit.
*/
public min: int;
/**
* The `rate` component of the kick rate limit.
*/
public rate: int;
/**
* The `burst` component of the kick rate limit.
*/
public burst: int;
};
/**
* The event message structure that is automatically created by the host to indicate current ping values of players.
*/
declare class PingEvent extends HaxballEvent {
/**
* The ping values of all players in the same order as the players list.
*/
public pings: int[];
};
declare type BanEntryId = uint32;
/**
* These values help understand the type of a ban entry instance inside a room's ban list.
*/
export enum BanEntryType {
/**
* A ban rule referring to a player's id.
*/
Player = 0,
/**
* A ban rule referring to an IP address/range.
*/
IP = 1,
/**
* A ban rule referring to a player's auth string.
*/
Auth = 2
};
declare type NumericIPv4 = uint32;
declare type NumericIPv6 = BigInt;
declare type AuthString = string;
declare type BanEntry = {
id: BanEntryId;
type: BanEntryType;
value: {pId: int, pName: string, ips: string[], auth: AuthString} | NumericIPv4 | NumericIPv6 | AuthString;
};
declare type IPv4Range = {
ip: NumericIPv4,
mask: NumericIPv4
};
declare type IPv6Range = {
ip: NumericIPv6,
mask: NumericIPv6
};
/**
* A player can be identified from the stringified instance of this class that the player carries.
*/
declare type Auth = {};
/**
* A class that defines the coordinates of an object.
*/
declare type Point = {
/**
* The x coordinate.
*/
x: number;
/**
* The y coordinate.
*/
y: number;
};
/**
* A class that defines an active disc.
*/
declare type MovableDisc = {
/**
* The position of this Disc.
*/
pos: Point;
/**
* The radius of this Disc.
*/
radius: number;
/**
* The speed of this Disc.
*/
speed: Point;
/**
* The gravity(acceleration) of this Disc.
*/
gravity: Point;
/**
* The damping value of this Disc.
*/
damping: number;
/**
* The 1/mass value of this Disc.
*/
invMass: number;
/**
* The bouncing coefficient of this Disc.
*/
bCoef: number;
/**
* The color of this Disc. Range: -1 <= `color` < 16777216.
* - This value can be converted into a rgba string via API's `Utils.numberToColor` function.
* - The special value `-1` means `transparent` color.
*/
color: int;
/**
* The collision group of this Disc.
*/
cGroup: int;
/**
* The collision mask of this Disc.
*/
cMask: int;
/**
* Id of the player that owns this Disc, or `null` if it is not owned by a player.
*/
playerId: uint16 | null;
/**
* The extrapolated version of this Disc, or `null` if the data is not available.
*/
ext: MovableDisc | null;
};
/**
* A class that defines an object to store game-specific physical properties of a player.
*/
declare type PlayerPhysics = {
/**
* A value to determine how much each player is pushed back when a player kicks the ball.
*/
kickback: number;
/**
* Radius of each player's Disc.
*/
radius: number;
/**
* The collision group of each player's Disc.
*/
cGroup: int;
/**
* The constant gravity(acceleration) applied to each player's Disc all the time.
*/
gravity: Point;
/**
* The bouncing coefficient of this Vertex.
*/
bCoef: number;
/**
* The 1/mass value of each player's Disc.
*/
invMass: number;
/**
* The damping value of each player's Disc.
*/
damping: number;
/**
* The acceleration(for manual movements only) of each player's Disc.
*/
acceleration: number;
/**
* The acceleration(for manual movements only) of each player's Disc while the kick key is pressed.
*/
kickingAcceleration: number;
/**
* The damping value of each player's Disc while the kick key is pressed.
*/
kickingDamping: number;
/**
* The kicking strength of each player.
*/
kickStrength: number;
};
/**
* A class that defines the colors of a team.
*/
declare type TeamColors = {
/**
* The angle of stripes shown inside the player disc object. (in radians)
*/
angle: number;
/**
* The angle of stripes shown inside the player disc object. (in degrees)
*/
readonly angleDeg: number;
/**
* Color of the avatar text. Range: -1 <= `text` < 16777216.
* - This value can be converted into a rgba string via API's `Utils.numberToColor` function.
* - The special value `-1` means `transparent` color.
*/
text: int;
/**
* Colors of the stripes. (A maximum of 3 stripes are allowed.)
* For each `value` in the array; range: -1 <= `value` < 16777216.
* - This value can be converted into a rgba string via API's `Utils.numberToColor` function.
* - The special value `-1` means `transparent` color.
*/
inner: int[];
/**
* Creates a copy of this TeamColors object.
*/
copy: ()=>TeamColors;
};
/**
* A class that defines a team.
*/
declare type Team = {
/**
* The id of this Team.
*/
id: number;
/**
* The color of this Team. Range: -1 <= `color` < 16777216.
* - This value can be converted into a rgba string via API's `Utils.numberToColor` function.
* - The special value `-1` means `transparent` color.
*/
color: int;
/**
* The default defense direction on the x axis for this Team.
*/
defenseDir: Direction;
/**
* The default cMask of this Team's player objects. (This value | 39) is
* overwritten into all of the players' cMask values whenever a goal is scored.
*/
cMask: int;
/**
* The default cGroup of this Team's player objects.
*/
cGroup: int;
};
declare namespace Team {
/**
* The Spectators Team.
*/
export const spec: Team;
/**
* The Red Team.
*/
export const red: Team;
/**
* The Blue Team.
*/
export const blue: Team;
/**
* All teams can be reached by their ids using
* this object in the following manner:
*
* `Team.byId[id]`.
*/
export const byId: Team[];
}
/**
* A class that defines a geographic location.
*/
declare type GeoLocation = {
/**
* The latitude of this GeoLocation.
*/
lat: number;
/**
* The longitude of this GeoLocation.
*/
lon: number;
/**
* The country code of this GeeLocation.
*/
flag: string;
};
/**
* A class that defines a player inside a room state.
*/
declare type Player = {
/**
* Id of this Player.
*/
id: int;
/**
* Name of this Player.
*/
name: string;
/**
* Team of this Player.
*/
team: Team;
/**
* Country code of this Player.
*/
flag: string;
/**
* Client avatar of this Player.
*/
avatar: string | null;
/**
* Headless avatar of this Player.
*/
headlessAvatar: string | null;
/**
* Whether this Player is an admin or not.
*/
isAdmin: boolean;
/**
* Avatar number of this Player. If no avatar is set, this number is shown.
*/
avatarNumber: int;
/**
* Connection string of this Player.
*/
conn: string | null;
/**
* Public auth string of this Player.
*/
auth: string | null;
/**
* Whether this Player is using this API or not.
*/
customClient: boolean;
/**
* Current ping value of this Player.
*/
ping: int;
/**
* Current key-state of this Player.
*/
input: int;
/**
* Min tick counter for kick rate of this Player.
*/
kickRateMinTickCounter: int;
/**
* Max tick counter for kick rate of this Player.
*/
kickRateMaxTickCounter: int;
/**
* Whether this Player is currently kicking the ball or not.
*/
isKicking: boolean;
/**
* Whether this Player is currently synchronized with the room's host or not.
*/
sync: boolean;
/**
* Current disc of this Player, or null if this Player is not currently playing.
*/
disc: MovableDisc | null;
/**
* The extrapolated version of this Player, or `null` if the data is not available.
*/
ext: Player | null;
/**
* The identity data of the current player that is received from a backend/proxy server.
*/
identity: object | null;
};
/**
* A class that has all the objects that are related to the physics simulation.
*/
declare type World = {
/**
* All vertices of this World.
*/
vertices: Impl.Stadium.Vertex[];
/**
* All segments of this World.
*/
segments: Impl.Stadium.Segment[];
/**
* All planes of this World.
*/
planes: Impl.Stadium.Plane[];
/**
* All movable discs of this World.
*/
discs: MovableDisc[];
/**
* All joints of this World.
*/
joints: Impl.Stadium.Joint[];
/**
* The extrapolated version of this World, or `null` if the data is not available.
*/
ext: World | null;
/**
* Creates the physical ball kicking effect. No kicking will happen if the distance between ball and player is >= 4 map units.
*
* @param pDisc The actual disc of the player that is kicking the ball.
* @param bDisc The actual disc of the ball that is being kicked.
* @param pp The current physical attributes of the players.
*
* @returns Whether the ball was kicked or not.
*/
kickBall: (pDisc: MovableDisc, bDisc: MovableDisc, pp: PlayerPhysics) => boolean;
};
/**
* A class that defines the complete game state of a room.
*/
declare type GameState = {
/**
* Counts how many ticks are left to resume the game.
* This value is set to `120` whenever the game is paused.
*/
pauseGameTickCounter: int;
/**
* The currently elapsed time in miliseconds.
*/
timeElapsed: number;
/**
* The current score of blue team.
*/
blueScore: int;
/**
* The current score of red team.
*/
redScore: int;
/**
* The current state of the actual gameplay.
*/
state: GamePlayState;
/**
* Counts how many ticks are left to reset the positions of discs.
* This value is set to `150` just after a goal is scored.
*/
goalTickCounter: int;
/**
* The physical state of the objects inside the game.
*/
physicsState: World;
/**
* The time limit of the game in minutes. 0 = no limit.
*/
timeLimit: int;
/**
* The score limit of the game. 0 = no limit.
*/
scoreLimit: int;
/**
* The stadium that the game is currently being played in.
*/
stadium: Impl.Stadium.Stadium;
/**
* The team that conceded the last goal.
*/
goalConcedingTeam: Team;
/**
* Whether the game is currently paused or not.
*/
readonly paused: boolean;
/**
* The extrapolated version of this GameState, or `null` if the data is not available.
*/
ext: GameState | null;
/**
* Creates a copy of this GameState object.
*/
copy: ()=>GameState;
/**
* Advances the game time `steps` number of frames. Called automatically by the game itself.
*
* @param steps The number of game ticks to execute.
*
* @returns {void}
*/
runSteps: (steps: int)=>void;
};
declare interface RoomStateBase {
/**
* The stadium that the game is currently being played in.
*/
stadium: Impl.Stadium.Stadium;
/**
* The min value of kick rate limit.
*/
kickRate_min: int;
/**
* The rate value of kick rate limit.
*/
kickRate_rate: int;
/**
* The max value of kick rate limit.
*/
kickRate_max: int;
/**
* The time limit of this current RoomState in minutes. 0 = no limit.
*/
timeLimit: int;
/**
* The score limit of this current RoomState. 0 = no limit.
*/
scoreLimit: int;
/**
* Whether the teams are locked or not.
* The non-admin players are allowed to change teams only
* if this feature is disabled and the game is stopped.
*/
teamsLocked: boolean;
/**
* Current state of the game, or `null` if the game is stopped.
*/
gameState: GameState | null;
/**
* All players that are currently in this room.
*/
players: Player[];
/**
* Name of this room.
*/
name: string;
/**
* The custom colors for each team. The 0th index has `null` because it's the Spectators team.
*/
teamColors: TeamColors[];
/**
* The extrapolated version of this RoomState, or `null` if the data is not available.
*/
ext: RoomState | null;
/**
* Returns a snapshot of the current room state. You can load the returned object directly into sandbox using its `useSnapshot(roomState)` function.
*
* @returns A complete snapshot of the current room state.
*/
copy: ()=>RoomState;
/**
* Returns the Player object for the player whose id is `id`.
*
* @param id The id of the player to be returned.
*
* @returns The Player object, or `null` if the player is not found.
*/
getPlayer: (id: uint16)=>(Player | null);
/**
* Runs the simulation `count` steps. Use with extreme caution, especially on network rooms.
*
* @param count Number of steps to run the simulation.
*
* @returns void.
*/
runSteps: (count: int)=>void;
}
/**
* A class that defines the complete state of a room.
*/
declare type RoomState = (RoomStateBase & SandboxModeFunctions);
/**
* A class that stores some detailed properties of a room. This instance is only received from the backend.
*/
declare type RoomDataDetails = {
/**
* Version of this room.
*/
version: number;
/**
* Name of this room.
*/
name: string;
/**
* Country code of this room.
*/
flag: string;
/**
* Latitude value of this room.
*/
lat: number;
/**
* Longitude value of this room.
*/
lon: number;
/**
* Whether this room is password-protected or not.
*/
password: boolean;
/**
* Maximum allowed number of players in this room.
*/
maxPlayers: number;
/**
* Current player count in this room.
*/
players: number;
};
/**
* A class that stores the complete summary of properties of a room. This instance is only received from the backend.
*/
declare type RoomData = {
/**
* Id of this room. You have to use this value in `Room.join`.
*/
id: string;
/**
* Details of this room.
*/
data: RoomDataDetails;
/**
* The calculated distance of this room to a specific GeoLocation.
* Use `Utils.calculateAllRoomDistances` to calculate this value automatically.
*/
dist: number;
/**
* Creates a copy of this RoomData struct.
*/
copy: ()=>RoomData;
};
declare type UpdatedRoomProps = {
name?: string | null,
password?: string | null,
fakePassword?: boolean | null,
geo?: GeoLocation | null,
playerCount?: int | null,
maxPlayerCount?: int | null
};
/**
* These events can only be received by a host room.
*/
declare interface HostOnlyCallbacks {
/**
* The room link was received from Haxball's backend server. Called some time after a room is created successfully. Also called when your room stops sending signal to Haxball's backend server, and starts it again after some time. This can happen if your connection gets interrupted or the room somehow becomes unstable due to bugs.
*
* @param {string} link The room link that was just received.
* @param {any} customData the custom data that was returned from the previous callback.
*
* @returns {any} void or a custom data to pass to the next callback.
*/
onRoomLink?: (link: string, customData?: any)=>any;
/**
* Called just after all bans have been cleared using `room.clearBans()`.
*
* @returns void or a custom data to pass to the next callback.
*/
onBansClear?: (customData?: any)=>any;
/**
* Called just after the ban of a player has been cleared using `room.clearBan(id)`.
*
* @param id Id of the player whose ban has just been cleared.
* @param customData the custom data that was returned from the previous callback.
*
* @returns void or a custom data to pass to the next callback.
*/
onBanClear?: (id: uint16, customData?: any)=>any;
/**
* Called just after the room's recaptcha mode was changed using `room.requireRecaptcha = on`.
*
* @param on The new value; whether to request recaptcha or not while joining the room.
* @param customData the custom data that was returned from the previous callback.
*
* @returns void or a custom data to pass to the next callback.
*/
onRoomRecaptchaModeChange?: (on: boolean, customData?: any)=>any;
/**
* Called just a little after the room's token was changed using `room.token = value`.
*
* @param token The new token of the room.
* @param customData the custom data that was returned from the previous callback.
*
* @returns void or a custom data to pass to the next callback.
*/
onRoomTokenChange?: (token: string, customData?: any)=>any;
}
/**
* These events can only be triggered by the room's host.
*/
declare interface HostTriggeredCallbacks {
/**
* Called just after an announcement was made by the room host.
*
* @param msg The announcement message.
* @param color The color of the announcement message. Range: -1 <= `color` < 16777216.
* - The color value can be converted into a rgba string via API's `Utils.numberToColor` function.
* - The special value `-1` means `transparent` color.
* @param style The style of the announcement message. Must be one of the following:
* - 0: