单元 API
As a maker, you call methods on units when writing the logic for the abilities you create.
Class Methods
以下是可供您使用的各种方法:
unit.heal(amount)
Adds the given amount of health in HP.
Health can't go over max health.
Arguments
amount
(number): The amount of HP to add.
unit.takeDamage(amount)
Subtracts the given amount of health in HP.
If the unit is bound, it will unbound when taking damage.
Health can't go under zero. If it reaches zero, the unit will die and vanish from the floor.
Arguments
amount
(number): The amount of HP to subtract.
unit.damage(receiver, amount)
Damages another unit.
If the other unit dies, the damager will earn or lose points equal to the dead unit's reward depending on whether that unit was an enemy or a friend, respectively.
Arguments
receiver
(Unit): The unit to damage.
amount
(number): The amount of HP to inflict.
unit.isAlive()
Determines if the unit is alive.
A unit is alive if it has a position.
返回值
(boolean): Whether the unit is alive or not.
unit.release(unit)
Releases (unbinds) another unit.
If the other unit was a friend, the releaser will earn points equal to the released unit's reward.
Arguments
receiver
(Unit): The unit to release.
unit.unbind()
Unbinds the unit.
unit.bind()
Binds the unit.
unit.isBound()
Determines if the unit is bound.
返回值
(boolean): Whether this unit is bound or not.
unit.earnPoints(points)
Adds the given points to the score.
Arguments
points
(number): The points to earn.
unit.losePoints(points)
Subtracts the given points from the score.
Arguments
points
(number): The points to lose.
unit.triggerEffect(effect)
Triggers the given effect.
Arguments
effect
(string): The name of the effect.
unit.isUnderEffect(effect)
Determines if the unit is under the given effect.
Arguments
effect
(string): The name of the effect.
返回值
(boolean): Whether this unit is under the given effect or not.
unit.getOtherUnits()
Returns the units in the floor minus this unit.
返回值
(Unit[]): The other units in the floor.
unit.getSpace()
Returns the space where this unit is located.
返回值
(Space): The space this unit is located at.
unit.getSensedSpaceAt(direction, forward = 1, right = 0)
Returns the sensed space located at the direction and number of spaces.
Use this method when returning spaces from senses. Always return sensed spaces to the player.
Arguments
direction
(string): The direction.
forward
(number): The number of spaces forward.
right
(number): The number of spaces to the right.
返回值
(SensedSpace): The sensed space.
unit.getSpaceAt(direction, forward = 1, right = 0)
Returns the space located at the direction and number of spaces.
Use this method internally. Never return a regular space to the player.
Arguments
direction
(string): The direction.
forward
(number): The number of spaces forward.
right
(number): The number of spaces to the right.
返回值
(Space): The space.
unit.getDirectionOfStairs()
Returns the direction of the stairs with reference to this unit.
返回值
(string): The relative direction of the stairs.
unit.getDirectionOf(space)
Returns the direction of the given space with reference to this unit.
Arguments
space
(SensedSpace): The space to get the direction of.
返回值
(string): The relative direction of the space.
unit.getDistanceOf(space)
Returns the distance between the given space and this unit.
Arguments
space
(SensedSpace): The space to calculate the distance of.
返回值
(number): The distance of the space.
unit.move(direction, forward = 1, right = 0)
Moves the unit in the given direction and number of spaces.
Arguments
direction
(string): The direction.
forward
(number): The number of spaces forward.
right
(number): The number of spaces to the right.
unit.rotate(direction)
Rotates the unit in a given direction.
Arguments
direction
(string): The direction in which to rotate.
unit.vanish()
Vanishes the unit from the floor.
unit.log(message)
Logs a message to the play log.
Arguments
message
(string): The message to log.
Instance Properties
name
(string)
The name of the unit.
character
(string)
The character that represents the unit in the floor map.
health
(number)
The total damage the unit may take before dying, in HP.
maxHealth
(number)
The maximum health
value.
reward
(number)
The number of points to reward when interacting.
enemy
(boolean)
Whether the unit belongs to the enemy side or not.
bound
(boolean)
Whether the unit is bound or not.