Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Unit

A unit in the game.

Hierarchy

Implements

  • IBaseGameObject

Index

Properties

acted

acted: boolean

Whether this Unit has performed its action this turn.

energy

energy: number

The amount of energy this Unit has (from 0.0 to 100.0).

food

food: number

The amount of food this Unit is holding.

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.

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.

job

job: Job

The Job this Unit was recruited to do.

logs

logs: string[]

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

materials

materials: number

The amount of materials this Unit is holding.

movementTarget

movementTarget: Tile | undefined

The tile this Unit is moving to. This only applies to neutral fresh humans spawned on the road. Otherwise, the tile this Unit is on.

moves

moves: number

How many moves this Unit has left this turn.

owner

owner: Player | undefined

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

squad

squad: Unit[]

The Units in the same squad as this Unit. Units in the same squad attack and defend together.

starving

starving: boolean

Whether this Unit is starving. Starving Units regenerate energy at half the rate they normally would while resting.

tile

tile: Tile | undefined

The Tile this Unit is on.

turnsToDie

turnsToDie: number

The number of turns before this Unit dies. This only applies to neutral fresh humans created from combat. Otherwise, 0.

Methods

attack

  • attack(tile: Tile): Promise<boolean>
  • Attacks an adjacent Tile. Costs an action for each Unit in this Unit's squad. Units in the squad without an action don't participate in combat. Units in combat cannot move afterwards. Attacking structures will not give materials.

    Parameters

    • tile: Tile

      The Tile to attack.

    Returns Promise<boolean>

    True if successfully attacked, false otherwise.

changeJob

  • changeJob(job: "soldier" | "gatherer" | "builder" | "missionary"): Promise<boolean>
  • Changes this Unit's Job. Must be at max energy (100) to change Jobs.

    Parameters

    • job: "soldier" | "gatherer" | "builder" | "missionary"

      The name of the Job to change to.

    Returns Promise<boolean>

    True if successfully changed Jobs, false otherwise.

construct

  • construct(tile: Tile, type: "neutral" | "shelter" | "monument" | "wall" | "road"): Promise<boolean>
  • Constructs a Structure on an adjacent Tile.

    Parameters

    • tile: Tile

      The Tile to construct the Structure on. It must have enough materials on it for a Structure to be constructed.

    • type: "neutral" | "shelter" | "monument" | "wall" | "road"

      The type of Structure to construct on that Tile.

    Returns Promise<boolean>

    True if successfully constructed a structure, false otherwise.

convert

  • convert(tile: Tile): Promise<boolean>
  • Converts an adjacent Unit to your side.

    Parameters

    • tile: Tile

      The Tile with the Unit to convert.

    Returns Promise<boolean>

    True if successfully converted, false otherwise.

deconstruct

  • deconstruct(tile: Tile): Promise<boolean>
  • Removes materials from an adjacent Tile's Structure. You cannot deconstruct friendly structures (see Unit.attack).

    Parameters

    • tile: Tile

      The Tile to deconstruct. It must have a Structure on it.

    Returns Promise<boolean>

    True if successfully deconstructed, false otherwise.

drop

  • drop(tile: Tile, resource: "materials" | "food", amount?: number): Promise<boolean>
  • Drops some of the given resource on or adjacent to the Unit's Tile. Does not count as an action.

    Parameters

    • tile: Tile

      The Tile to drop materials/food on.

    • resource: "materials" | "food"

      The type of resource to drop ('materials' or 'food').

    • Default value amount: number = 0

      The amount of the resource to drop. Amounts <= 0 will drop as much as possible.

    Returns Promise<boolean>

    True if successfully dropped the resource, false otherwise.

harvest

  • harvest(tile: Tile): Promise<boolean>
  • Harvests the food on an adjacent Tile.

    Parameters

    • tile: Tile

      The Tile you want to harvest.

    Returns Promise<boolean>

    True if successfully harvested, 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.

    Parameters

    • tile: Tile

      The Tile this Unit should move to.

    Returns Promise<boolean>

    True if it moved, false otherwise.

pickup

  • pickup(tile: Tile, resource: "materials" | "food", amount?: number): Promise<boolean>
  • Picks up some materials or food on or adjacent to the Unit's Tile. Does not count as an action.

    Parameters

    • tile: Tile

      The Tile to pickup materials/food from.

    • resource: "materials" | "food"

      The type of resource to pickup ('materials' or 'food').

    • Default value amount: number = 0

      The amount of the resource to pickup. Amounts <= 0 will pickup as much as possible.

    Returns Promise<boolean>

    True if successfully picked up a resource, false otherwise.

rest

  • rest(): Promise<boolean>
  • Regenerates energy. Must be in range of a friendly shelter to rest. Costs an action. Units cannot move after resting.

    Returns Promise<boolean>

    True if successfully rested, 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.

Generated using TypeDoc