Useful Functions

You can use any of these functions from within an evaluable in an event directly.

class app.engine.query_engine.GameQueryEngine
get_item(unit, item) ItemObject | None

Returns a item object by nid or uid. :param unit: unit to check :param item: item to check

Returns:

Item if exists on unit, otherwise None

Return type:

Optional[ItemObject]

get_subitem(unit, parent_item, child_item) ItemObject | None

Returns a item object by nid. :param unit: unit to check :param parent_item: parent item (multi-item) to check :param child_item: child item (subitem) to check

Returns:

Item if exists on unit, otherwise None

Return type:

Optional[ItemObject]

has_item(item, nid=None, team=None, tag=None, party=None) bool

Check if any unit matching criteria has item. Example usage: * has_item(“Iron Sword”, team=”player”) will check if any player unit is holding an iron sword * has_item(“Sacred Stone”, party=’Eirika’) will check if Eirika’s party has the item “Sacred Stone” :param item: item to check :param nid: use to check specific unit nid :type nid: optional :param team: used to match for team. :type team: optional :param tag: used to match for tag. :type tag: optional :param party: used to match for party :type party: optional

Returns:

True if unit has item, else False

Return type:

bool

get_skill(unit, skill) SkillObject | None

Returns a skill object by nid. :param unit: unit in question :param skill: nid of skill

Returns:

Skill, if exists on unit, else None.

Return type:

Optional[SkillObject] | None

has_skill(unit, skill) bool

checks if unit has skill :param unit: unit to check :param skill: skill to check

Returns:

True if unit has skill, else false

Return type:

bool

get_klass(unit) Klass | None

Returns the klass prefab of the unit. :param unit: unit in question

Returns:

Klass object if the unit exists and has a valid klass, otherwise None

get_class(unit) Klass | None

Returns the klass prefab of the unit. :param unit: unit in question

Returns:

Klass object if the unit exists and has a valid klass, otherwise None

get_closest_allies(position, num: int = 1) List[Tuple[UnitObject, int]]

Return a list containing the closest player units and their distances. :param position: position or unit :param num: How many allies to search for. Defaults to 1. :type num: int, optional

Returns:

Returns num pairs of (unit, distance) to the position. Will return fewer if there are fewer player units than num.

Return type:

List[Tuple[UnitObject, int]]

get_units_within_distance(position, dist: int = 1, nid=None, team=None, tag=None, party=None) List[Tuple[UnitObject, int]]

Return a list containing all units within dist distance to the specific position that match specific criteria :param position: position or unit :param dist: How far to search. Defaults to 1. :type dist: int, optional :param nid: use to check specific unit nid :type nid: optional :param team: used to match for team. :type team: optional :param tag: used to match for tag. :type tag: optional :param party: used to match for party :type party: optional

Returns:

Returns all pairs of (unit, distance) within the specified dist that match criteria.

Return type:

List[Tuple[UnitObject, int]]

get_allies_within_distance(position, dist: int = 1) List[Tuple[UnitObject, int]]

Return a list containing all player units within dist distance to the specific position. :param position: position or unit :param dist: How far to search. Defaults to 1. :type dist: int, optional

Returns:

Returns all pairs of (unit, distance) within the specified dist.

Return type:

List[Tuple[UnitObject, int]]

get_units_in_area(position_corner_1: Tuple[int, int], position_corner_2: Tuple[int, int]) List[UnitObject]

Returns a list of units within a rectangular area. :param position_corner_1: (x, y) coordinates for one corner of the area :type position_corner_1: Tuple[int, int] :param position_corner_2: (x, y) coordinates for the opposite corner :type position_corner_2: Tuple[int, int]

Returns:

Returns all units with positions with values between those specified by the corners (inclusive), or an empty list if no units exist in that area

Return type:

List[UnitObject]

get_debuff_count(unit) int

Checks how many negative skills the unit has. :param unit: Unit in question

Returns:

Number of unique negative skills on the unit

Return type:

int

get_units_in_region(region, nid=None, team=None, tag=None) List[UnitObject]

returns all units matching the criteria in the given region Example usage: * get_units_in_region(‘NorthReinforcements’, team=’player’) will return all player units in the region * get_units_in_region(‘NorthReinforcements’, nid=’Eirika’) will return Eirika if Eirika is in the region * get_units_in_region(‘NorthReinforcements’) will return all units in the region :param region: region in question :param nid: used to match for NID :type nid: optional :param team: used to match for team. :type team: optional :param tag: used to match for tag. :type tag: optional

Returns:

all units matching the criteria in the region

Return type:

List[UnitObject]

any_unit_in_region(region, nid=None, team=None, tag=None) bool

checks if any unit matching the criteria is in the region Example usage: * any_unit_in_region(‘NorthReinforcements’, team=’player’) will check if any player unit is in the region * any_unit_in_region(‘NorthReinforcements’, nid=’Eirika’) will check if Eirika is in the region * any_unit_in_region(‘NorthReinforcements’) will check if ANY unit is in the region :param region: region in question :param nid: used to match for NID :type nid: optional :param team: used to match for team. :type team: optional :param tag: used to match for tag. :type tag: optional

Returns:

if any unit matching criteria is in the region

Return type:

bool

is_dead(unit) bool

checks if unit is dead :param unit: unit to check

Returns:

if the unit has died

Return type:

bool

u(unit) UnitObject | None

Shorthand for game.get_unit. Fetches the unit object. :param unit: unit nid

Returns:

the actual unit object, if exists, else None

Return type:

Optional[UnitObject]

v(varname, fallback=None) Any

shorthand for game.level_vars.get and game.game_vars.get. Fetches the variable if game.level_vars and game.game_vars share an identical name, game.level_vars takes priority :param varname: name of the variable :param fallback: fallback value, if any. Defaults to None

Returns:

the value of the variable

Return type:

Any

get_support_rank(unit1, unit2) NID | None

Returns the most recently obtained support rank between two units. :param unit1: unit in the support pair :param unit2: the other unit in the support pair

Returns:

if the two units have achieved a support rank. none: if the support pair is invalid or no rank has been obtained

Return type:

Rank nid

get_terrain(pos) NID | None

Returns the terrain at position, or, if unit is provided, the terrain underneath the unit. :param pos: Position tuple or unit

Returns:

the nid of the region, or None if the position is invalid

Return type:

Optional[NID]

has_achievement(nid) bool

Checks if an achievement is completed :param nid: nid to check for completion

Returns:

if the achievement exists

Return type:

bool