Class: Unit

Pirates. Unit

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

new Pirates.Unit()

Initializes a Unit with basic logic as provided by the Creer code generator. Never use this directly. It is for internal Joueur use.

Extends

Members

boolean acted

Whether this Unit has performed its action this turn.

number crew

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

number crewHealth

How much total health the crew on this Tile have.

string gameObjectName

Inherited From:
Pirates.GameObject#gameObjectName
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.

number gold

How much gold this Unit is carrying.

string id

Inherited From:
Pirates.GameObject#id
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.

Array.<string> logs

Inherited From:
Pirates.GameObject#logs
Any strings logged will be stored here. Intended for debugging.

number moves

How many more times this Unit may move this turn.
The Player that owns and can control this Unit, or null if the Unit is neutral.

Array.<Pirates.Tile> path

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

number shipHealth

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

number stunTurns

(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.

Pirates.Port targetPort

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

Methods

boolean attack(tile, target)

Attacks either the 'crew' or 'ship' on a Tile in range.
Name Type Description
tile Pirates.Tile The Tile to attack.
target string Whether to attack 'crew' or 'ship'. Crew deal damage to crew and ships deal damage to ships. Consumes any remaining moves.
Returns: boolean
True if successfully attacked, false otherwise.

boolean bury(amount)

Buries gold on this Unit's Tile. Gold must be a certain distance away for it to get interest (Game.minInterestDistance).
Name Type Description
amount number How much gold this Unit should bury. Amounts <= 0 will bury as much as possible.
Returns: boolean
True if successfully buried, false otherwise.

boolean deposit(amount)

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.
Name Type Description
amount number optional The amount of gold to deposit. Amounts <= 0 will deposit all the gold on this Unit.
Returns: boolean
True if successfully deposited, false otherwise.

boolean dig(amount)

Digs up gold on this Unit's Tile.
Name Type Description
amount number optional How much gold this Unit should take. Amounts <= 0 will dig up as much as possible.
Returns: boolean
True if successfully dug up, false otherwise.

log(message)

Inherited From:
Pirates.GameObject#log
Adds a message to this GameObject's logs. Intended for your own debugging purposes, as strings stored here are saved in the gamelog.
Name Type Description
message string A string to add to this GameObject's log. Intended for debugging.

boolean move(tile)

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.
Name Type Description
tile Pirates.Tile The Tile this Unit should move to.
Returns: boolean
True if it moved, false otherwise.

boolean rest()

Regenerates this Unit's health. Must be used in range of a port.
Returns: boolean
True if successfully rested, false otherwise.

boolean split(tile, amount, gold)

Moves a number of crew from this Unit to the given Tile. This will consume a move from those crew.
Name Type Description
tile Pirates.Tile The Tile to move the crew to.
amount number optional The number of crew to move onto that Tile. Amount <= 0 will move all the crew to that Tile.
gold number optional The amount of gold the crew should take with them. Gold < 0 will move all the gold to that Tile.
Returns: boolean
True if successfully split, false otherwise.

string toString()

Inherited From:
BaseGameObject#toString
toString override for easier debugging
Returns: string
readable string in the format `GameObjectName #id`

boolean withdraw(amount)

Takes gold from the Player. You can only withdraw from your own Port.
Name Type Description
amount number optional The amount of gold to withdraw. Amounts <= 0 will withdraw everything.
Returns: boolean
True if successfully withdrawn, false otherwise.