Character

The Character class acts as the base for both NPCs and Players. It is opinionated about how stats are calculated (see getMaxAttribute), if you want to change what stats a player has and how they are calculated it should be changed here and in Attributes.js

Constructor

new Character()

Properties:
Name Type Description
name string

Name shown on look/who/login

inventory Map
combatants Set

Enemies this character is currently in combat with

level number
attributes object
effects EffectList

List of current effects applied to the character

skills Map

List of all character's skills

room Room

Room the character is currently in

Implements:

Extends

  • EventEmitter

Members

isNpc

Methods

addAttribute()

See:

addCombatant(target)

Parameters:
Name Type Description
target Character

addEffect(effect) → {boolean}

Parameters:
Name Type Description
effect Effect
Returns:
boolean

addFollower(follower)

Parameters:
Name Type Description
follower Character

addItem(item)

Move an item to the character's inventory

Parameters:
Name Type Description
item Item

emit(event, …args)

Proxy all events on the player to effects

Parameters:
Name Type Attributes Description
event string
args * <repeatable>

evaluateIncomingDamage(damage) → {number}

Parameters:
Name Type Description
damage Damage
Returns:
number
See:
  • EffectList.evaluateIncomingDamage

evaluateOutgoingDamage(damage, currentAmount) → {number}

Parameters:
Name Type Description
damage Damage
currentAmount number
Returns:
number
See:
  • EffectList.evaluateOutgoingDamage

follow(target)

Begin following another character. If the character follows itself they stop following.

Parameters:
Name Type Description
target Character

getAttribute(attr) → {number}

Get the current value of an attribute (base modified by delta)

Parameters:
Name Type Description
attr string
Returns:
number

getBaseAttribute(attr) → {number}

Get the base value for a given attribute

Parameters:
Name Type Description
attr string

Attribute name

Returns:
number

getBroadcastTargets()

See:

getMaxAttribute(attr) → {number}

Get current maximum value of attribute (as modified by effects.)

Parameters:
Name Type Description
attr string
Returns:
number

hasAttribute(attr) → {boolean}

Parameters:
Name Type Description
attr string

Attribute name

Returns:
boolean

hasEffectType(type) → {boolean}

Parameters:
Name Type Description
type string
Returns:
boolean
See:

hasFollower(target) → {boolean}

Parameters:
Name Type Description
target Character
Returns:
boolean

hydrate(state)

Initialize the character from storage

Parameters:
Name Type Description
state GameState

initiateCombat(target, lagnullable)

Start combat with a given target.

Parameters:
Name Type Attributes Default Description
target Character
lag number <nullable>
0

Optional milliseconds of lag to apply before the first attack

isFollowing(target) → {boolean}

Parameters:
Name Type Description
target Character
Returns:
boolean

isInCombat(targetnullable)

Check to see if this character is currently in combat or if they are currently in combat with a specific character

Parameters:
Name Type Attributes Description
target Character <nullable>
Returns:
-

boolean

isInventoryFull() → {boolean}

Returns:
boolean

lowerAttribute(attr, amount)

Lower an attribute by name

Parameters:
Name Type Description
attr string
amount number
See:
  • Attributes#lower

raiseAttribute(attr, amount)

Raise an attribute by name

Parameters:
Name Type Description
attr string
amount number
See:
  • Attributes#raise

removeCombatant(target)

Parameters:
Name Type Description
target Character

removeEffect(effect)

Parameters:
Name Type Description
effect Effect
See:

removeFollower(target)

Parameters:
Name Type Description
target Character

removeFromCombat()

Fully remove this character from combat

removeItem(item)

Remove an item from the character's inventory. Warning: This does not automatically place the item in any particular place. You will need to manually add it to the room or another character's inventory

Parameters:
Name Type Description
item Item

serialize() → {Object}

Gather data to be persisted

Returns:
Object

setAttributeBase(attr, newBase)

Update an attribute's base value.

NOTE: You probably don't want to use this the way you think you do. You should not use this for any temporary modifications to an attribute, instead you should use an Effect modifier.

This will permanently update the base value for an attribute to be used for things like a player purchasing a permanent upgrade or increasing a stat on level up

Parameters:
Name Type Description
attr string

Attribute name

newBase number

New base value

setAttributeToMax(attr)

Clears any changes to the attribute, setting it to its base value.

Parameters:
Name Type Description
attr string

unequip(slot)

Remove equipment in a given slot and move it to the character's inventory

Parameters:
Name Type Description
slot string

unfollow()

Stop following whoever the character was following

Events

damaged

Parameters:
Name Type Description
damage Damage

heal

Parameters:
Name Type Description
heal Heal
target Character

healed

Parameters:
Name Type Description
heal Heal

hit

Parameters:
Name Type Description
damage Damage
target Character