# RpgServerEngine

# Example to use (in module)

import { RpgServer, RpgModule, RpgServerEngine } from '@rpgjs/server'
import { player } from './player' // optional

@RpgModule<RpgServer>({ 
    engine: {
        onStart(engine: RpgServerEngine) {
            const globalConfig = engine.globalConfig
        }
    }
})
export default class RpgServerModuleEngine {}

# RpgServerEngineHooks

Summary


# onStart

  • Property: onStart
  • Type: (engine: RpgServerEngine) => any
  • Optional: true
  • Usage:

When the server starts


# onStep

  • Property: onStep
  • Type: (engine: RpgServerEngine) => any
  • Optional: true
  • Usage:

At each server frame. Normally represents 60FPS

# RpgServerEngine


# app

  • Property: app
  • Type: Express App
  • Optional: true
  • Usage:

Express App Instance. If you have assigned this variable before starting the game, you can get the instance of Express


# database

  • Property: database
  • Type: object
  • Optional: true
  • Usage:

List of the data


# globalConfig

  • Property: globalConfig
  • Type: object
  • Optional: true
  • Read Only
  • Usage:

retrieve the global configurations assigned at the entry point


# damageFormulas

  • Property: damageFormulas
  • Type: object
  • Optional: true
  • Usage:

Combat formulas


# io

  • Property: io
  • Type: Socket Io Server
  • Optional: true
  • Usage:

Combat formulas


# Add in database

  • Since: 3.0.0-beta.4
  • Method: server.addInDatabase(id,data)
  • Arguments:
    • {number} id. resource id (Optional: false)
    • {class} dataClass. A class representing the data (Optional: false)
  • Return: void
  • Example:
@Item({
     name: 'Potion',
     description: 'Gives 100 HP',
})
class MyItem() {}

server.addInDatabase('dynamic_item', MyItem)
  • Usage:

Adds data to the server's database (in RAM) for later use


# Start Server

  • Method: server.start()
  • Return: void
  • Usage:

Start the RPG server


# Send All Packets

  • Method: server.send()
  • Return: void
  • Usage:

Sends all packages to clients. The sending is done automatically but you can decide to send yourself by calling this method (for example, for unit tests)


# sceneMap

  • Since: 3.0.0-beta.4
  • Property: sceneMap
  • Type: SceneMap
  • Optional: true
  • Usage:

Return the scene that manages the maps of the game