Perk
Overview
This is the base class of the Perks. All perks inherit this Perk.
Settings
Format - Unit
Unit-specific settings are written in the “perk” section.
{ "perk": { "options": { "apply": [String, ...], } } }
Properties
info
Type:Object get
Returns an object with information about this perk. It has the following keys:
| Key | Type | Description | 
|---|---|---|
| depends | String/ Array of String | The name of the perk on which this perk depends. It is possible to specify more than one in an array. | 
| sectionName | String | The section name of the settings this perk will use. If this section name is present in the settings, the corresponding perk will be attached to the unit. | 
| order | Number | The priority level of the perk. The lower the number, the higher the priority. Perk initialization and event handlers are executed according to this priority order. | 
Each perk needs to override this property and return proper information.
ready
Type:Promise get
The promise that is resolved when a perk is ready.
Methods
createHandler(handlerName, ...args)
Type:Function
Create a handler. The handler must have been previously registered with registerHandler().
Parameters
| Parameter | Type | Description | 
|---|---|---|
| handlerName Required | String | The name of a handler to create. | 
| …args | Array of Arguments | The arguments passed to a handler's constructor. | 
Return Value
A created handler instance.
getPerk(perkName)
Type:Perk static
Returns a perk specified with the perkName argument. The perk must have been previously registered with registerPerk().
Parameters
| Parameter | Type | Description | 
|---|---|---|
| perkName Required | String | The name of a perk to retrieve. | 
Return Value
Perk.
globalInit()
Type:Undefined static
Initializes the perk. It is called automatically once when a perk is registered using registerPerk(). Normally, the perk is registered before any other processing begins.
Each perk needs to override this method and do its processing if necessary.
Parameters
None.
Return Value
Undefined.
init(unit, options)
Type:Undefined Asynchronous static
Initializes the unit. It is called when attaching a perk to a unit. Normally, it is called automatically when the settings are loaded. The unit to be attached is passed as an argument.
Each perk needs to override this method and do its processing if necessary.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| unit Required | Unit | A unit to be attached. | 
| options | Object | Initialization options. | 
Return Value
Undefined.
registerHandler(handler, perkName)
Type:Undefined
Registers a handler with the perk. The handler is a class that is used by a perk to handle actual processing.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| handler Required | Function | The handler to register. | 
| perkName | String | The perk with which a handler registers. | 
Return Value
None.
registerPerk(perk)
Type:Undefined
Registers the perk with the system. A perk cannot be attached unless it is registered. The perk's global initialization process is executed when registered.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| perk Required | Perk | The perk to register. | 
Return Value
Undefined.
Spells
attach
Type:Undefined Target:Unit
Attaches the perk passed in the argument to the unit. If the perk depends on other perks, dependent perks are attached first. The attached perk is added to the unit's perk asset. When attaching, each park's init() method is called and the unit is upgraded. If the specified perk is already attached, nothing is done.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| perk Required | Perk | The perk to attach. | 
| options | Object | Options. Passed to the init() method of the attaching perk. | 
Return Value
Undefined.
attachPerks
Type:Undefined Target:Unit
Attaches all the perks depending on the settings using the attachl spell. The order of attaching is based on the priority number of each perk, the lower the number the earlier.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| options Required | Object | Options. Has the following keys: | 
| “settings” | Object | The unit settings. | 
Return Value
Undefined.