Skip to content
On this page

States Commands


Get States Defense

  • Property: player.statesDefense
  • Type: Array<{ rate: number, state: StateClass}>
  • Optional: false
  • Read Only
  • Usage:

Recovers the player's states defense on inventory. This list is generated from the statesDefense property defined on the weapons or armors equipped. If several items have the same element, only the highest rate will be taken into account.

ts
import { Armor, State } from '@rpgjs/server'

@State({
     name: 'Paralyze'
})
class Paralyze {}

@Armor({
     name: 'Shield',
     statesDefense: [{ rate: 1, state: Paralyze }]
})
class Shield {}

@Armor({
     name: 'FireShield',
     statesDefense: [{ rate: 0.5, state: Paralyze }]
})
class FireShield {}

player.addItem(Shield)
player.addItem(FireShield)
player.equip(Shield)
player.equip(FireShield)

console.log(player.statesDefense) // [{ rate: 1, state: instance of Paralyze }]

Set/Get States Efficiency

  • Property: player.statesEfficiency
  • Type: Array<{ rate: number, state: StateClass}>
  • Optional: false
  • Usage:

Set or retrieves all the states where the player is vulnerable or not.

ts
import { Class, State } from '@rpgjs/server'

@State({
     name: 'Paralyze'
})
class Paralyze {}

@State({
     name: 'Sleep'
})
class Sleep {}

@Class({
     name: 'Fighter',
     statesEfficiency: [{ rate: 1, state: Paralyze }]
})
class Hero {}

player.setClass(Hero)

console.log(player.statesEfficiency) // [{ rate: 1, instance of Paralyze }]

player.statesEfficiency = [{ rate: 2, state: Sleep }]

console.log(player.statesEfficiency) // [{ rate: 1, state: instance of Paralyze }, { rate: 2, state: instance of Sleep }]

Get State

  • Method: player.getState(stateClass)
  • Arguments:
    • { StateClass | string} stateClass. or state id (Optional: false)
  • Return: instance of StateClass | null
  • Usage:

Get a state to the player. Returns null if the state is not present on the player

ts
import Paralyze from 'your-database/states/paralyze'

player.getState(Paralyze)

Add State

WARNING

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

  • Method: player.addState(stateClass,chance=1)
  • Arguments:
    • { StateClass | string} stateClass. state class or state id (Optional: false)
    • {number} chance. 1 by default (Optional: true)
  • Throws:

If the chance to add the state has failed (defined with the chance param)

{
    id: ADD_STATE_FAILED,
    msg: '...'
}

Adds a state to the player. Set the chance between 0 and 1 that the state can apply

ts
import Paralyze from 'your-database/states/paralyze'

try { 
     player.addState(Paralyze)
}
catch (err) {
     console.log(err)
}

Remove State

  • Method: player.removeState(stateClass,chance=1)
  • Arguments:
    • { StateClass|string} stateClass. class state or state id (Optional: false)
    • {number} chance. 1 by default (Optional: true)
  • Throws:

If the chance to remove the state has failed (defined with the chance param)

{
    id: REMOVE_STATE_FAILED,
    msg: '...'
}

If the status does not exist

{
    id: STATE_NOT_APPLIED,
    msg: '...'
}

Remove a state to the player. Set the chance between 0 and 1 that the state can be removed

ts
import Paralyze from 'your-database/states/paralyze'

try { 
     player.removeState(Paralyze)
}
catch (err) {
     console.log(err)
}