Table of Contents

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:

KeyTypeDescription
dependsString/
Array of String
The name of the perk on which this perk depends. It is possible to specify more than one in an array.
sectionNameStringThe 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.
orderNumberThe 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

ParameterTypeDescription
handlerName
Required
StringThe name of a handler to create.
…argsArray of ArgumentsThe 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

ParameterTypeDescription
perkName
Required
StringThe 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

ParameterTypeDescription
unit
Required
UnitA unit to be attached.
optionsObjectInitialization 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

ParameterTypeDescription
handler
Required
FunctionThe handler to register.
perkNameStringThe 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

ParameterTypeDescription
perk
Required
PerkThe 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

ParameterTypeDescription
perk
Required
PerkThe perk to attach.
optionsObjectOptions. 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

ParameterTypeDescription
options
Required
ObjectOptions. Has the following keys:
“settings”ObjectThe unit settings.

Return Value

Undefined.