API Docs for:
Show:

ValidTargetsFinder Class

Gets a list of valid targets filtered by provided criteria.

Constructor

ValidTargetsFinder

(
  • game
  • settings
)

Parameters:

  • game Game
  • settings Object
    • x Number
      • The x map tile coord to use as the origin of the attack.
    • y Number
      • The y map tile coord to use as the origin of the attack.
    • [limitToFov=false] FovROT optional
      • If set only targets within the given FovROT will be valid.
    • [limitToNonDiagonalAdjacent=false] Bool optional
      • If true diagonally adjacent targets are not valid (only used if range = 1).
    • [range=1] Number optional
      • Max distance in tiles target can be from origin.
    • [validTypes=[]] Array optional
      • Array of valid target object types. Checked using target instanceof type.
    • [includeTiles=false] Bool optional
      • If true tile objects are can be valid targets.
    • [exclude=false] Object | Array optional
      • Object or Array of objects to exclude from results.
    • [prepareValidTargets=true] Bool optional
      • If true valid targets are wraped in an object with x, y, range, value properties.
    • [filter=false] Function optional
      • Function to filter objects when checking if they are valid. function(obj){ return true } . Targets must still be a valid type.

Methods

checkValidTarget

(
  • target
)
Bool

Checks if an object is a valid target for this action.

Parameters:

  • target Object
    • The target to be checked.

Returns:

Bool:

true if valid.

checkValidType

(
  • target
)
Bool

Checks if a target object is an instance of a type in this.validTypes.

Parameters:

  • target Object
    • The target to be checked.

Returns:

Bool:

true if valid.

getValidTargets

() Array

Gets all valid targets.

Returns:

Array:

getValidTargetsAtPosition

(
  • x
  • y
)
Array

Get valid target objects on a tile coord.

Parameters:

  • x Number
    • Map tile coord to get valid target objects from.
  • y Number
    • Map tile coord to get valid target objects from.

Returns:

Array:

mixed objects

getValidTargetTiles

() Array

Get tile coords a valid target may be on. Only checking range and fov, not objects on the tile.

Returns:

Array:

of Tile objects

prepareTargetObject

(
  • target
  • [x=target.x]
  • [y=target.y]
  • [range]
)
Object

Wraps a target object in a container object with x, y, range

Parameters:

  • target Object
  • [x=target.x] Number optional
  • [y=target.y] Number optional
  • [range] Number optional

    range from this.x, this.y to x,y

Returns:

Object:

result.value target object

Properties

exclude

Object | Array

Object or Array of objects to exclude from results.

filter

Function

Function to filter objects when checking if they are valid. function(obj){ return true } . Targets must still be an instance of this.validTypes.

game

Game

Game instance this obj is attached to.

includeTiles

Boolean

If true tile objects are can be valid targets.

limitToFov

FovROT

If set only targets within the given FovROT will be valid.

limitToNonDiagonalAdjacent

Boolean

Limit results to non-diagonal adjacent tiles

prepareValidTargets

Boolean

If true valid targets are wraped in an object with x, y, range, value properties.

range

Number

Max distance in tiles target can be from origin.

validTypes

Array

Array of valid target object types. Checked using target instanceof type. If set to an empty array or a value evaluating to false, all types are considered valid.

x

Number

The x map tile coord to use as the origin of this target finder.

y

Number

The y map tile coord to use as the origin of this target finder.