Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Unit

A unit group in the game. This may consist of a ship and any number of crew.

Hierarchy

Implements

  • IBaseGameObject

Index

Properties

acted

acted: boolean

Whether this Unit has performed its action this turn.

crew

crew: number

How many crew are on this Tile. This number will always be <= crewHealth.

crewHealth

crewHealth: number

How much total health the crew on this Tile have.

gameObjectName

gameObjectName: string

String representing the top level Class that this game object is an instance of. Used for reflection to create new instances on clients, but exposed for convenience should AIs want this data.

gold

gold: number

How much gold this Unit is carrying.

id

id: string

A unique id for each instance of a GameObject or a sub class. Used for client and server communication. Should never change value after being set.

logs

logs: string[]

Any strings logged will be stored here. Intended for debugging.

moves

moves: number

How many more times this Unit may move this turn.

owner

owner: Player | undefined

The Player that owns and can control this Unit, or null if the Unit is neutral.

path

path: Tile[]

(Merchants only) The path this Unit will follow. The first element is the Tile this Unit will move to next.

shipHealth

shipHealth: number

If a ship is on this Tile, how much health it has remaining. 0 for no ship.

stunTurns

stunTurns: number

(Merchants only) The number of turns this merchant ship won't be able to move. They will still attack. Merchant ships are stunned when they're attacked.

targetPort

targetPort: Port | undefined

(Merchants only) The Port this Unit is moving to.

tile

tile: Tile | undefined

The Tile this Unit is on.

Methods

attack

  • attack(tile: Tile, target: "crew" | "ship"): Promise<boolean>
  • Attacks either the 'crew' or 'ship' on a Tile in range.

    Parameters

    • tile: Tile

      The Tile to attack.

    • target: "crew" | "ship"

      Whether to attack 'crew' or 'ship'. Crew deal damage to crew and ships deal damage to ships. Consumes any remaining moves.

    Returns Promise<boolean>

    True if successfully attacked, false otherwise.

bury

  • bury(amount: number): Promise<boolean>
  • Buries gold on this Unit's Tile. Gold must be a certain distance away for it to get interest (Game.minInterestDistance).

    Parameters

    • amount: number

      How much gold this Unit should bury. Amounts <= 0 will bury as much as possible.

    Returns Promise<boolean>

    True if successfully buried, false otherwise.

deposit

  • deposit(amount?: number): Promise<boolean>
  • Puts gold into an adjacent Port. If that Port is the Player's port, the gold is added to that Player. If that Port is owned by merchants, it adds to that Port's investment.

    Parameters

    • Default value amount: number = 0

      The amount of gold to deposit. Amounts <= 0 will deposit all the gold on this Unit.

    Returns Promise<boolean>

    True if successfully deposited, false otherwise.

dig

  • dig(amount?: number): Promise<boolean>
  • Digs up gold on this Unit's Tile.

    Parameters

    • Default value amount: number = 0

      How much gold this Unit should take. Amounts <= 0 will dig up as much as possible.

    Returns Promise<boolean>

    True if successfully dug up, false otherwise.

log

  • log(message: string): Promise<void>
  • Adds a message to this GameObject's logs. Intended for your own debugging purposes, as strings stored here are saved in the gamelog.

    Parameters

    • message: string

      A string to add to this GameObject's log. Intended for debugging.

    Returns Promise<void>

move

  • move(tile: Tile): Promise<boolean>
  • Moves this Unit from its current Tile to an adjacent Tile. If this Unit merges with another one, the other Unit will be destroyed and its tile will be set to null. Make sure to check that your Unit's tile is not null before doing things with it.

    Parameters

    • tile: Tile

      The Tile this Unit should move to.

    Returns Promise<boolean>

    True if it moved, false otherwise.

rest

  • rest(): Promise<boolean>
  • Regenerates this Unit's health. Must be used in range of a port.

    Returns Promise<boolean>

    True if successfully rested, false otherwise.

split

  • split(tile: Tile, amount?: number, gold?: number): Promise<boolean>
  • Moves a number of crew from this Unit to the given Tile. This will consume a move from those crew.

    Parameters

    • tile: Tile

      The Tile to move the crew to.

    • Default value amount: number = 1

      The number of crew to move onto that Tile. Amount <= 0 will move all the crew to that Tile.

    • Default value gold: number = 0

      The amount of gold the crew should take with them. Gold < 0 will move all the gold to that Tile.

    Returns Promise<boolean>

    True if successfully split, false otherwise.

toString

  • toString(): string
  • A toString override for easier debugging.

    example

    String(gameObject); 🠞 "GameObjectName #1245"

    Returns string

    A human readable representation of the game object.

withdraw

  • withdraw(amount?: number): Promise<boolean>
  • Takes gold from the Player. You can only withdraw from your own Port.

    Parameters

    • Default value amount: number = 0

      The amount of gold to withdraw. Amounts <= 0 will withdraw everything.

    Returns Promise<boolean>

    True if successfully withdrawn, false otherwise.

Generated using TypeDoc