Skip to content
On this page

RpgServerEngine

Example to use (in module)

ts
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


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
  • Enum: string type
TagDescription
The type of data
item
weapon
armor
skill
class
state
actor
  • Method: server.addInDatabase(id,data)
  • Arguments:
    • {number} id. resource id (Optional: false)
    • {class | object} dataClass. A class representing the data. You can just add a object if you specify the type (Optional: false)
  • Return: void
  • Example:
ts
@Item({
     name: 'Potion',
     description: 'Gives 100 HP',
})
class MyItem() {}

server.addInDatabase('dynamic_item', MyItem)

or with an object

ts
server.addInDatabase('dynamic_item', {
     name: 'Potion',
     description: 'Gives 100 HP',
}, 'item')
  • 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