Skip to content
On this page

Classes

Prerequisites

Read the article Create database to find out how to put the data into your game and then use it.

Full Class

ts
import { RpgPlayer } from '@rpgjs/server'
import { Class } from '@rpgjs/database'
import type { ClassOnSet, ClassCanEquip, WeaponInstance, ArmorInstance } from '@rpgjs/database'

@Class({  
    name: 'Fighter',
    description: 'A great fighter!',
    skillsToLearn: [],
    statesEfficiency: [],
    elementsEfficiency: []
})
export class Fighter implements ClassOnSet, ClassCanEquip {
    // Called when the class is assigned to the player
    onSet(player: RpgPlayer): void { }

    // Return true if the player can equip the item
    canEquip(item: WeaponInstance | ArmorInstance, player: RpgPlayer): boolean { }
}

API


skillsToLearn

  • Property: skillsToLearn
  • Type: Array<{ level: number, skill: SkillClass }>
  • Optional: true
  • Usage:

Indicate which skill will be learned when the level is reached

ts
import { Fire } from 'my-database/skills/fire'

skillsToLearn: [{ level: 5, skill: Fire }]

id

  • Property: id
  • Type: string
  • Optional: true
  • Usage:

The id of the item. The identifier makes it possible to find an object in the database. By default, the identifier is the name of the class


name

  • Property: name
  • Type: string
  • Optional: true
  • Usage:

The name of the item.


description

  • Property: description
  • Type: string
  • Optional: true
  • Usage:

The description of the item.


statesEfficiency

WARNING

The realization of this property or method has not been completed.

  • Enum: number
TagDescription
  • Property: statesEfficiency
  • Type: Array<{ rate: number, element: StateClass} | StateClass>
  • Optional: true
  • Example:

Example 1

ts
import { Paralyze } from 'my-database/states/paralyze'

statesEfficiency: [Paralyze] // rate is 1 by default

Example 2

ts
import { Paralyze } from 'my-database/states/paralyze'

statesEfficiency: [{ rate: 1.5, state: Paralyze }]

Example 3 (todo)

ts
import { Efficiency } from '@rpgjs/server'
import { Paralyze } from 'my-database/states/paralyze'

statesEfficiency: [{ rate: Efficiency.VULNERABLE, state: Paralyze }]
  • Usage:

List of states.

Changes the efficiency of the states. It indicates whether or not the player with a class or state will be vulnerable to the state. It is a multiplying coefficient for damage calculations.

To help, you can use the Efficiency enumerations


elementsEfficiency

  • Enum: number
TagDescription
Efficiency.GAIN_HP-0.5 value
Efficiency.PERFECT_INVULNERABLE0 value
Efficiency.INVULNERABLE0.5 value
Efficiency.NORMAL1 value
Efficiency.VULNERABLE1.5 value
Efficiency.VERY_VULNERABLE2 value
  • Property: elementsEfficiency
  • Type: Array<{ rate: number, element: Element} | Element>
  • Optional: true
  • Example:

Example 1

ts
import { Element } from 'my-database/elements'

elementsEfficiency: [Element.Fire] // rate is 1 by default

Example 2

ts
import { Element } from 'my-database/elements'

elementsEfficiency: [{ rate: 1.5, element: Element.Fire }]

Example 3

ts
import { Efficiency } from '@rpgjs/server'
import { Element } from 'my-database/elements'

elementsEfficiency: [{ rate: Efficiency.VULNERABLE, element: Element.Fire }]
  • Usage:

List of elements.

Changes the efficiency of the elements. It indicates whether or not the player with a class or state will be vulnerable to the element. It is a multiplying coefficient for damage calculations.

To help, you can use the Efficiency enumerations