Reference Source Test
public class | source

Game

Creates an instance of the game

Constructor Summary

Public Constructor
public

constructor(client: Client)

Keep track of the game logic and the HTML5 canvas

Member Summary

Public Members
public

Controls the game music and sfx

public

A reference to the chat bubbles controller

public

An instance of the client application

public

Returns server/config.json => devClient value

public

An array of entities in the game

public

guild: Guild

A reference to a guild

public

An ID used to identify the player after they've been given a handshake by the Node server

public

Used to display additional information on the screen (ie level up and hits and health/exp regeneration)

public

Controls all of the game's input

public

Controls the interface in the game

public

Last time (used for renderer??)

public

Whether or not the map is loaded

public

map: Map

An instance of the game's map

public

An array of mesages from the web socket

public

Used to find paths of entities

public

An instance of the player

public

An instance of the game's player handler

public

The pointer shown on the HTML5 canvas

public

How many players are in the game, defaults to -1

public

True if there is currently pvp combat

public

Whether or not the game is ready

public

An instance of the renderer

public
public

An instance of the web socket used to talk to the node server

public

Whether or not the game is started

public

A reference to the player's LocalStorage

public

Used for rendering fame ticks

public

An instance of the updater

public

zoning: Zoning

Used to figure out direction

Method Summary

Public Methods
public

Handles incoming animation packet data from the server

public

Handles an audio track change notification from the server

public

bankCallback(opcode: Number, info: Array)

Handles incoming bank packet data from the server

public

blinkCallback(instance: String)

Triggers an item blink effect for the given entity instance

public

Handles an incoming chat message from the server

public

Handles incoming combat packet data from the server

public

Connect to the nodeJS server and setup all the server to client callback messages

public

Instantiates the local player entity

public

Handles the player death event from the server

public

Callback for removing a spawned entity

public

enchantCallback(opcode: Number, info: Object)

Handles incoming enchantment operation data from the server

public

Callback for when the list of entities is done loading and adds the new entities to the screen

public

Callback for when player equipment is done loading

public

Handles incoming experience gain data and updates the player's level display

public

findPath(character: Character, x: Number, y: Number, ignores: Array): Array

Finds a path for a character to a target grid position, optionally ignoring entities

public

Returns the camera instance from the renderer

public

getEntityAt(x: Number, y: Number, ignoreSelf: Boolean): Entity | null

Returns the entity at the given grid position, optionally ignoring the local player

public

Returns the current UI scale factor from the client

public

getSprite(spriteName: String): Sprite

Returns a Sprite instance by name from the entity controller

public

Returns the local storage controller instance

public

Returns the saved password from local storage

public

Returns the saved username from local storage

public

guildCallback(opcode: Number, info: Object)

Handles incoming guild operation data from the server

public

handleDisconnection(noError: *)

This function is responsible for handling sudden disconnects of a player whilst in the game, not menu-based errors.

public

Callback for when the server has acknowledged the client connection then it creates the player object, makes sure the map is loaded, and if the user is registering or logging in it handles player registration or login requests

public

Returns whether the player has opted to save their login credentials

public

Handles incoming heal packet data and updates entity hit points

public

Pre-populates the login form fields with saved username and password from storage

public

inventoryCallback(opcode: Number, info: Array)

Handles incoming inventory packet data from the server

public

Load all of the game controllers

public

Load the game map data

public

Load the HTML5 canvas renderer layers for:

  • background
  • foreground
  • text
  • entities
  • cursor
public

Invoked once all sprites have been loaded

public

Callback for when the map data is done loading

public

moveCharacter(character: Character, x: Number, y: Number)

Moves a character entity to the specified grid position

public

Moves the local player to the specified grid position

public

Callback for entity movement

public

Responds to a network ping from the server with a pong

public

notificationCallback(opcode: Number, message: String)

Handles incoming notification messages from the server

public

npcCallback(opcode: Number, info: Object)

Handles incoming NPC interaction packet data from the server

public

onInput(inputType: Number, data: Object)

Routes an input event to the input handler

public

pointerCallback(opcode: Number, info: Object)

Handles incoming pointer/waypoint indicator data from the server

public

Handles incoming hit points and mana updates for an entity

public

populationCallback(population: Number)

Handles the server population count update

public

Call this after the player has been welcomed by the server and the client received the connection.

public

projectileCallback(opcode: Number, info: Object)

Handles incoming projectile packet data from the server

public

Handles a PVP flag update for an entity

public

questCallback(opcode: Number, info: Object)

Handles incoming quest progress and completion data from the server

public

resize()

Handles a window resize event by updating the renderer and pointer positions

public

Sends a respawn request to the server and plays the revive sound effect

public

Handles the player respawn event, repositioning them and resetting their state

public

setAudio(audio: Audio)

Sets the audio controller if one has not already been assigned

public

setBubble(bubble: Bubble)

Sets the bubble chat controller if one has not already been assigned

public

Sets the entity controller instance if one has not already been assigned

public

setInfo(info: Info)

Sets the info display controller if one has not already been assigned

public

setInput(input: Input)

Sets the input handler instance if one has not already been assigned

public

setInterface(intrface: Interface)

Sets the UI interface controller if one has not already been assigned

public

setMessages(messages: Messages)

Sets the messages handler instance if one has not already been assigned

public

setPathfinder(pathfinder: Pathfinder)

Sets the pathfinder instance if one has not already been assigned

public

Sets the current movement direction of the player

public

setPointer(pointer: Pointer)

Sets the pointer/waypoint indicator controller if one has not already been assigned

public

setRenderer(renderer: Renderer)

Sets the renderer instance if one has not already been assigned

public

setSocket(socket: Socket)

Sets the socket instance if one has not already been assigned

public

setStorage(storage: Storage)

Sets the storage controller instance if one has not already been assigned

public

setUpdater(updater: Updater)

Sets the updater instance if one has not already been assigned

public

shopCallback(opcode: Number, info: Object)

Handles incoming shop operation data from the server

public

Triggered when an entity has finished being spawned

public

Start the game

public

stop()

Stop the game, sets started and ready to false

public

syncCallback(playerEntity: Entity<Player>): Boolean

Callback for when server side sync is done.

public

Callback for player teleport

public

tick()

Calls the renderer to draw to the HTML5 canvas if the game is ready and requests animations if the game is started

public

tradeWith(player: Player)

Sends a trade request to the specified player

public

Resets all of the controllers, storage and entities in the game.

public

The callback for when the welcome message for brand new players is done.

Public Constructors

public constructor(client: Client) source

Keep track of the game logic and the HTML5 canvas

Params:

NameTypeAttributeDescription
client Client

an instance of the client application

Public Members

public audio: Audio source

Controls the game music and sfx

public bubble: Bubble source

A reference to the chat bubbles controller

public client: Client source

An instance of the client application

public development: Boolean source

Returns server/config.json => devClient value

public entities: Array<Entity> source

An array of entities in the game

public guild: Guild source

A reference to a guild

public id: Number source

An ID used to identify the player after they've been given a handshake by the Node server

public info: Info source

Used to display additional information on the screen (ie level up and hits and health/exp regeneration)

public input: Input source

Controls all of the game's input

public interface: Interface source

Controls the interface in the game

public lastTime: Boolean source

Last time (used for renderer??)

public loaded: Boolean source

Whether or not the map is loaded

public map: Map source

An instance of the game's map

public messages: Messages source

An array of mesages from the web socket

public pathfinder: Pathfinder source

Used to find paths of entities

public player: Player source

An instance of the player

public playerHandler: PlayerHandler source

An instance of the game's player handler

public pointer: Pointer source

The pointer shown on the HTML5 canvas

public population: Number source

How many players are in the game, defaults to -1

public pvp: Boolean source

True if there is currently pvp combat

public ready: Boolean source

Whether or not the game is ready

public renderer: Renderer source

An instance of the renderer

public shop: Object source

public socket: Socket source

An instance of the web socket used to talk to the node server

public started: Boolean source

Whether or not the game is started

public storage: Object source

A reference to the player's LocalStorage

public time: Date source

Used for rendering fame ticks

public updater: Updater source

An instance of the updater

public zoning: Zoning source

Used to figure out direction

Public Methods

public animationCallback(id: String, info: Array) source

Handles incoming animation packet data from the server

Params:

NameTypeAttributeDescription
id String

the entity instance ID to animate

info Array

the animation data array containing name, speed, and count

public audioCallback(song: String) source

Handles an audio track change notification from the server

Params:

NameTypeAttributeDescription
song String

the name of the song to play

public bankCallback(opcode: Number, info: Array) source

Handles incoming bank packet data from the server

Params:

NameTypeAttributeDescription
opcode Number

the bank operation code

info Array

the bank packet data

public blinkCallback(instance: String) source

Triggers an item blink effect for the given entity instance

Params:

NameTypeAttributeDescription
instance String

the entity instance ID to blink

public chatCallback(info: Object) source

Handles an incoming chat message from the server

Params:

NameTypeAttributeDescription
info Object

the chat message object containing id, text, name, and display options

public combatCallback(data: Array) source

Handles incoming combat packet data from the server

Params:

NameTypeAttributeDescription
data Array

the combat packet data array

public connect(): Boolean source

Connect to the nodeJS server and setup all the server to client callback messages

Return:

Boolean

public createPlayer() source

Instantiates the local player entity

public deathCallback(id: String) source

Handles the player death event from the server

Params:

NameTypeAttributeDescription
id String

the entity instance ID of the dead entity

public despawnCallback(id: Number): Boolean source

Callback for removing a spawned entity

Params:

NameTypeAttributeDescription
id Number

the id of the entity that needs to be removed

Return:

Boolean

public enchantCallback(opcode: Number, info: Object) source

Handles incoming enchantment operation data from the server

Params:

NameTypeAttributeDescription
opcode Number

the enchant operation code

info Object

the enchant data containing type and index

public entityListCallback(data: Array<Entity>): Boolean source

Callback for when the list of entities is done loading and adds the new entities to the screen

Params:

NameTypeAttributeDescription
data Array<Entity>

array of entities

Return:

Boolean

public equipmentCallback(action: Number, info: Object): Boolean source

Callback for when player equipment is done loading

Params:

NameTypeAttributeDescription
action Number

the equipment action

info Object

information about the equipment

Return:

Boolean

public experienceCallback(info: Object) source

Handles incoming experience gain data and updates the player's level display

Params:

NameTypeAttributeDescription
info Object

the experience data containing id, experience, level, and amount

public findPath(character: Character, x: Number, y: Number, ignores: Array): Array source

Finds a path for a character to a target grid position, optionally ignoring entities

Params:

NameTypeAttributeDescription
character Character

the character to find a path for

x Number

the target grid X position

y Number

the target grid Y position

ignores Array

list of entities to ignore during pathfinding

Return:

Array

the calculated path as an array of grid coordinates

public getCamera(): Camera source

Returns the camera instance from the renderer

Return:

Camera

the camera instance

public getEntityAt(x: Number, y: Number, ignoreSelf: Boolean): Entity | null source

Returns the entity at the given grid position, optionally ignoring the local player

Params:

NameTypeAttributeDescription
x Number

the grid X position

y Number

the grid Y position

ignoreSelf Boolean

whether to skip the local player entity

Return:

Entity | null

the entity at the position or null if none

public getScaleFactor(): Number source

Returns the current UI scale factor from the client

Return:

Number

the scale factor

public getSprite(spriteName: String): Sprite source

Returns a Sprite instance by name from the entity controller

Params:

NameTypeAttributeDescription
spriteName String

the name of the sprite to retrieve

Return:

Sprite

the sprite instance

public getStorage(): Storage source

Returns the local storage controller instance

Return:

Storage

the storage controller

public getStoragePassword(): String source

Returns the saved password from local storage

Return:

String

the stored password

public getStorageUsername(): String source

Returns the saved username from local storage

Return:

String

the stored username

public guildCallback(opcode: Number, info: Object) source

Handles incoming guild operation data from the server

Params:

NameTypeAttributeDescription
opcode Number

the guild operation code

info Object

the guild data

public handleDisconnection(noError: *) source

This function is responsible for handling sudden disconnects of a player whilst in the game, not menu-based errors.

Params:

NameTypeAttributeDescription
noError *

public handshakeCallback(data: Messages): Boolean source

Callback for when the server has acknowledged the client connection then it creates the player object, makes sure the map is loaded, and if the user is registering or logging in it handles player registration or login requests

Params:

NameTypeAttributeDescription
data Messages

server network message

Return:

Boolean

public hasRemember(): Boolean source

Returns whether the player has opted to save their login credentials

Return:

Boolean

true if remember-me is enabled

public healCallback(info: Object) source

Handles incoming heal packet data and updates entity hit points

Params:

NameTypeAttributeDescription
info Object

the heal data containing id, type, and amount

public implementStorage() source

Pre-populates the login form fields with saved username and password from storage

public inventoryCallback(opcode: Number, info: Array) source

Handles incoming inventory packet data from the server

Params:

NameTypeAttributeDescription
opcode Number

the inventory operation code

info Array

the inventory packet data

public loadControllers(): Boolean source

Load all of the game controllers

Return:

Boolean

public loadGameMap(): Boolean source

Load the game map data

Return:

Boolean

public loadRenderer(): Boolean source

Load the HTML5 canvas renderer layers for:

  • background
  • foreground
  • text
  • entities
  • cursor

Return:

Boolean

public loadedSpritesCallback() source

Invoked once all sprites have been loaded

public mapReadyCallback(): Boolean source

Callback for when the map data is done loading

Return:

Boolean

public moveCharacter(character: Character, x: Number, y: Number) source

Moves a character entity to the specified grid position

Params:

NameTypeAttributeDescription
character Character

the character entity to move

x Number

the target grid X position

y Number

the target grid Y position

public movePlayer(x: Number, y: Number) source

Moves the local player to the specified grid position

Params:

NameTypeAttributeDescription
x Number

the target grid X position

y Number

the target grid Y position

public movementCallback(data: Object<Messages>): Boolean source

Callback for entity movement

Params:

NameTypeAttributeDescription
data Object<Messages>

message data

Return:

Boolean

public networkCallback() source

Responds to a network ping from the server with a pong

public notificationCallback(opcode: Number, message: String) source

Handles incoming notification messages from the server

Params:

NameTypeAttributeDescription
opcode Number

the notification operation code

message String

the notification message text

public npcCallback(opcode: Number, info: Object) source

Handles incoming NPC interaction packet data from the server

Params:

NameTypeAttributeDescription
opcode Number

the NPC operation code

info Object

the NPC packet data

public onInput(inputType: Number, data: Object) source

Routes an input event to the input handler

Params:

NameTypeAttributeDescription
inputType Number

the type of input event

data Object

the input event data

public pointerCallback(opcode: Number, info: Object) source

Handles incoming pointer/waypoint indicator data from the server

Params:

NameTypeAttributeDescription
opcode Number

the pointer operation code

info Object

the pointer data containing id and position

public pointsCallback(data: Array) source

Handles incoming hit points and mana updates for an entity

Params:

NameTypeAttributeDescription
data Array

the points packet data array containing id, hitPoints, and mana

public populationCallback(population: Number) source

Handles the server population count update

Params:

NameTypeAttributeDescription
population Number

the current number of players online

public postLoad() source

Call this after the player has been welcomed by the server and the client received the connection.

public projectileCallback(opcode: Number, info: Object) source

Handles incoming projectile packet data from the server

Params:

NameTypeAttributeDescription
opcode Number

the projectile operation code

info Object

the projectile data

public pvpCallback(id: String, pvp: Boolean) source

Handles a PVP flag update for an entity

Params:

NameTypeAttributeDescription
id String

the entity instance ID

pvp Boolean

whether the entity has PVP enabled

public questCallback(opcode: Number, info: Object) source

Handles incoming quest progress and completion data from the server

Params:

NameTypeAttributeDescription
opcode Number

the quest operation code

info Object

the quest packet data

public resize() source

Handles a window resize event by updating the renderer and pointer positions

public respawn() source

Sends a respawn request to the server and plays the revive sound effect

public respawnCallback(id: String, x: Number, y: Number) source

Handles the player respawn event, repositioning them and resetting their state

Params:

NameTypeAttributeDescription
id String

the player entity instance ID

x Number

the respawn grid X position

y Number

the respawn grid Y position

public setAudio(audio: Audio) source

Sets the audio controller if one has not already been assigned

Params:

NameTypeAttributeDescription
audio Audio

the audio controller to set

public setBubble(bubble: Bubble) source

Sets the bubble chat controller if one has not already been assigned

Params:

NameTypeAttributeDescription
bubble Bubble

the bubble controller to set

public setEntityController(entities: Entities) source

Sets the entity controller instance if one has not already been assigned

Params:

NameTypeAttributeDescription
entities Entities

the entity controller to set

public setInfo(info: Info) source

Sets the info display controller if one has not already been assigned

Params:

NameTypeAttributeDescription
info Info

the info controller to set

public setInput(input: Input) source

Sets the input handler instance if one has not already been assigned

Params:

NameTypeAttributeDescription
input Input

the input handler to set

public setInterface(intrface: Interface) source

Sets the UI interface controller if one has not already been assigned

Params:

NameTypeAttributeDescription
intrface Interface

the interface controller to set

public setMessages(messages: Messages) source

Sets the messages handler instance if one has not already been assigned

Params:

NameTypeAttributeDescription
messages Messages

the messages handler to set

public setPathfinder(pathfinder: Pathfinder) source

Sets the pathfinder instance if one has not already been assigned

Params:

NameTypeAttributeDescription
pathfinder Pathfinder

the pathfinder instance to set

public setPlayerMovement(direction: Number) source

Sets the current movement direction of the player

Params:

NameTypeAttributeDescription
direction Number

the movement direction constant

public setPointer(pointer: Pointer) source

Sets the pointer/waypoint indicator controller if one has not already been assigned

Params:

NameTypeAttributeDescription
pointer Pointer

the pointer controller to set

public setRenderer(renderer: Renderer) source

Sets the renderer instance if one has not already been assigned

Params:

NameTypeAttributeDescription
renderer Renderer

the renderer instance to set

public setSocket(socket: Socket) source

Sets the socket instance if one has not already been assigned

Params:

NameTypeAttributeDescription
socket Socket

the socket instance to set

public setStorage(storage: Storage) source

Sets the storage controller instance if one has not already been assigned

Params:

NameTypeAttributeDescription
storage Storage

the storage controller to set

public setUpdater(updater: Updater) source

Sets the updater instance if one has not already been assigned

Params:

NameTypeAttributeDescription
updater Updater

the updater instance to set

public shopCallback(opcode: Number, info: Object) source

Handles incoming shop operation data from the server

Params:

NameTypeAttributeDescription
opcode Number

the shop operation code

info Object

the shop data

public spawnCallback(data: Object): Boolean source

Triggered when an entity has finished being spawned

Params:

NameTypeAttributeDescription
data Object

entity id

Return:

Boolean

public start(): Boolean source

Start the game

Return:

Boolean

true if the game was successfully started, false if the game is already running

public stop() source

Stop the game, sets started and ready to false

public syncCallback(playerEntity: Entity<Player>): Boolean source

Callback for when server side sync is done. Used to make sure the player's information doesn't differntiate from what the server has for them

Params:

NameTypeAttributeDescription
playerEntity Entity<Player>

player entity object

Return:

Boolean

false if this entity is not a player type

public teleportCallback(data: Object<Messages>): Boolean source

Callback for player teleport

Params:

NameTypeAttributeDescription
data Object<Messages>

information about the teleport

Return:

Boolean

public tick() source

Calls the renderer to draw to the HTML5 canvas if the game is ready and requests animations if the game is started

public tradeWith(player: Player) source

Sends a trade request to the specified player

Params:

NameTypeAttributeDescription
player Player

the player entity to trade with

public unload(): Boolean source

Resets all of the controllers, storage and entities in the game. Stops all audio too. Sets the game to a totally blank state so that it can be initialized like a new game all over again

Return:

Boolean

public welcomeCallback(playerData: Object): Boolean source

The callback for when the welcome message for brand new players is done. Loads the player data and sets their starting position then calls this.postLoad()

Params:

NameTypeAttributeDescription
playerData Object

the data needed to load the player

Return:

Boolean