GameState class

class app.engine.game_state.GameState

The game state itself. Keeps track of all objects in the game

This includes things like all Units, all Regions, all Skills, Items, Statuses, Parties, Events, etc. It also keeps track of the current level, all game_vars and level_vars, the current difficulty mode, etc.

Attributes you can access:

current_mode (DifficultyModeObject): The current difficulty mode of the game. game_vars (Counter): A counter for storing game-wide variables. You can do game.game_vars.get(‘Waffle’) to determine the value of the Waffle variable. level_vars (Counter): A counter for storing level-specific variables. playtime (int): The total playtime of the game in milliseconds. current_save_slot (int): The current save slot. unit_registry (Dict[NID, UnitObject]): A dictionary mapping unit NIDs to UnitObjects. item_registry (Dict[UID, ItemObject]): A dictionary mapping item UIDs to ItemObjects. skill_registry (Dict[UID, SkillObject]): A dictionary mapping skill UIDs to SkillObjects. region_registry (Dict[NID, RegionObject]): A dictionary mapping region NIDs to RegionObjects. overworld_registry (Dict[NID, OverworldObject]): A dictionary mapping overworld NIDs to OverworldObjects. parties (Dict[NID, PartyObject]): A dictionary mapping party NIDs to PartyObjects. unlocked_lore (List[NID]): A list of unlocked lore entries. market_items (Dict[NID, int]): A dictionary mapping item NIDs to their stock quantity. supports (supports.SupportController): The support controller. records (records.Recordkeeper): The record keeper. turncount (int): The current turn count. talk_options (List[Tuple[NID, NID]]): A list of talk options. board (game_board.GameBoard): The game board. cursor (cursor.BaseCursor): The cursor. camera (camera.Camera): The camera. phase (phase.PhaseController): The phase controller. game.phase.get_current_phase() == ‘player’

is_displaying_overworld() bool

Checks if the game is currently displaying the overworld map.

Returns:

True if the overworld map is being displayed, False otherwise.

Return type:

bool

property level: LevelObject

Gets the current level object.

Returns:

The current level object.

Return type:

LevelObject

property level_nid: NID

Gets the NID of the current level.

Returns:

The NID of the current level.

Return type:

NID

property current_party: NID

Gets the NID of the current party.

Returns:

The NID of the current party.

Return type:

str

property tilemap: TileMapObject | None

Gets the tilemap of the current level or the overworld.

Returns:

The tilemap of the current level or the overworld.

Return type:

TileMapObject

property bg_tilemap: TileMapObject | None

Gets the background tilemap of the current level.

Returns:

The background tilemap of the current level.

Return type:

TileMapObject

property mode: DifficultyModeObject

Gets the current difficulty mode object.

Returns:

The current difficulty mode object.

Return type:

DifficultyModeObject

property party: PartyObject

Gets the current party object.

Returns:

The current party object.

Return type:

PartyObject

get_party(party_nid: NID = None) PartyObject

Gets the party object with the given NID.

Parameters:

party_nid (NID, optional) – The NID of the party to get. Defaults to the current party.

Returns:

The party object.

Return type:

PartyObject

property units: List[UnitObject]

Gets a list of all registered units.

Returns:

A list of all registered unit objects.

Return type:

List[UnitObject]

property regions: List[RegionObject]

Gets a list of all registered region objects.

Returns:

A list of all registered region objects.

Return type:

List[RegionObject]

get_data(raw_data_nid: NID)

Gets data from the raw data database.

Parameters:

raw_data_nid (NID) – The NID of the raw data.

Returns:

The raw data retrieved from the database.

Return type:

Any

get_unit(unit_nid: NID) UnitObject | None

Gets a unit object by its NID.

Can get units not just in the current level, but also overworld, base, etc.

Parameters:

unit_nid (NID) – The NID of the unit.

Returns:

The unit object with the given NID.

Return type:

UnitObject

get_klass(unit_nid: NID) Klass | None

Gets the class data for a unit’s current class.

Parameters:

unit_nid (NID) – The NID of the unit.

Returns:

The class data for the unit.

Return type:

Klass

get_convoy_inventory(party: PartyObject | None = None) List[ItemObject]

Gets a list of the items in the party’s convoy.

Parameters:

party (PartyObject, optional) – The party to get the convoy inventory from. Defaults to current party.

Returns:

The convoy inventory of the party.

Return type:

List[ItemObject]

get_item(item_uid: UID) ItemObject | None

Gets an item object by its UID (unique id).

Parameters:

item_uid (UID) – The unique id of the item.

Returns:

The item object with the given UID.

Return type:

ItemObject

get_skill(skill_uid: UID) SkillObject | None

Gets a skill object by its UID (unique id).

Parameters:

skill_uid (UID) – The unique id of the skill.

Returns:

The skill object with the given UID.

Return type:

SkillObject

get_region(region_nid: NID) RegionObject | None

Gets a region object by its NID.

Parameters:

region_nid (NID) – The NID of the region.

Returns:

The region object with the given NID.

Return type:

RegionObject

get_region_under_pos(pos: Pos, region_type: RegionType = None) RegionObject | None

Gets the region object located at the given position.

Parameters:
  • pos (Pos) – The position to check for a region.

  • region_type (RegionType, optional) – The type of region to filter by. Defaults to no filtering.

Returns:

The first region object located at the position, or None if not found.

Return type:

Optional[RegionObject]

get_ai_group(ai_group_nid: NID) AIGroupObject | None

Gets an AI group object by its NID.

Parameters:

ai_group_nid (str) – The NID of the AI group.

Returns:

The AI group object with the given NID, or None if not found.

Return type:

Optional[AIGroupObject]

ai_group_active(ai_group_nid: NID) bool

Checks if an AI group is active.

Parameters:

ai_group_nid (str) – The NID of the AI group.

Returns:

True if the AI group is active, False otherwise.

Return type:

bool

get_units_in_ai_group(ai_group_nid: NID) List[UnitObject]

Gets all units belonging to a specific AI group.

Parameters:

ai_group_nid (str) – The NID of the AI group.

Returns:

A list of units belonging to the specified AI group.

Return type:

List[UnitObject]

get_all_units(only_on_field: bool = True) List[UnitObject]

Gets all units currently loaded in the game.

Parameters:

only_on_field (bool, optional) – Whether to include only units on the field. Defaults to True.

Returns:

A list of all units in the game.

Return type:

List[UnitObject]

get_player_units(only_on_field: bool = True) List[UnitObject]

Gets all units belonging to the player’s team.

Parameters:

only_on_field (bool, optional) – Whether to include only units currently on the field. Defaults to True.

Returns:

A list of all units belonging to the player’s team.

Return type:

List[UnitObject]

get_enemy_units(only_on_field: bool = True) List[UnitObject]

Gets all units belonging to enemy teams. Enemy teams are those that are not allies of the player team.

Parameters:

only_on_field (bool, optional) – Whether to include only units currently on the field. Defaults to True.

Returns:

A list of all units belonging to enemy teams.

Return type:

List[UnitObject]

get_enemy1_units(only_on_field: bool = True) List[UnitObject]

Gets all units belonging to the ‘enemy’ team.

Parameters:

only_on_field (bool, optional) – Whether to include only units currently on the field. Defaults to True.

Returns:

A list of all units belonging to the ‘enemy’ team.

Return type:

List[UnitObject]

get_enemy2_units(only_on_field: bool = True) List[UnitObject]

Gets all units belonging to the ‘enemy2’ team.

Parameters:

only_on_field (bool, optional) – Whether to include only units currently on the field. Defaults to True.

Returns:

A list of all units belonging to the ‘enemy2’ team.

Return type:

List[UnitObject]

get_other_units(only_on_field: bool = True) List[UnitObject]

Gets all units belonging to the ‘other’ team.

Parameters:

only_on_field (bool, optional) – Whether to include only units currently on the field. Defaults to True.

Returns:

A list of all units belonging to the ‘other’ team.

Return type:

List[UnitObject]

get_team_units(team: str, only_on_field: bool = True) List[UnitObject]

Gets all units belonging to the specified team.

Parameters:
  • team (str) – The team identifier.

  • only_on_field (bool, optional) – Whether to include only units currently on the field. Defaults to True.

Returns:

A list of all units belonging to the specified team.

Return type:

List[UnitObject]

get_travelers() List[UnitObject]

Gets all units acting as travelers. These units are currently being rescued or paired up with someone else.

Returns:

A list of all units acting as travelers.

Return type:

List[UnitObject]

get_player_units_and_travelers() List[UnitObject]

Gets all player units on the field and their travelers.

Returns:

A list of all player units and traveler units.

Return type:

List[UnitObject]

get_rescuer(unit: UnitObject) UnitObject | None

Gets the rescuer of a unit.

Parameters:

unit (UnitObject) – The unit to find the rescuer for.

Returns:

The rescuer unit, if found, otherwise None.

Return type:

UnitObject

get_rescuers_position(unit: UnitObject) Pos | None

Gets the position of the rescuer of a unit.

Parameters:

unit (UnitObject) – The unit to find the rescuer’s position for.

Returns:

The position of the rescuer unit, if found, otherwise None.

Return type:

Pos

get_all_units_in_party(party: PartyObject = None) List[UnitObject]

Gets all units in a specified party (even dead ones).

Parameters:

party (str, optional) – The NID of the party. Defaults to the current party.

Returns:

A list of all units in the specified party.

Return type:

List[UnitObject]

get_units_in_party(party: PartyObject = None) List[UnitObject]

Gets all living units in a specified party, sorted according to party preparation.

Parameters:

party (str, optional) – The NID of the party. Defaults to the current party.

Returns:

A list of all living units in the specified party, sorted according to party preparation.

Return type:

List[UnitObject]

get_all_player_units() List[UnitObject]

Gets all persistent player units (even if dead).

Returns:

A list of all persistent player units.

Return type:

List[UnitObject]

is_roam() bool

Checks if roaming mode is enabled.

Returns:

True if roaming mode is enabled, False otherwise.

Return type:

bool

get_roam_unit() UnitObject | None

Gets the roaming unit.

Returns:

The roaming unit if it exists, otherwise None.

Return type:

UnitObject

check_dead(nid: NID) bool

Checks if a unit with the given NID is dead or dying.

Parameters:

nid – The NID of the unit to check.

Returns:

True if the unit is dead or dying, False otherwise.

Return type:

bool

check_alive(nid: NID) bool

Checks if a unit with the given NID is alive.

Parameters:

nid – The NID of the unit to check.

Returns:

True if the unit is alive, False otherwise.

Return type:

bool

get_terrain_nid(tilemap: TileMapObject, position: Pos) NID

Gets the terrain NID at a given position on the tilemap.

Parameters:
  • tilemap (TileMapObject) – The tilemap object.

  • position (Pos) – The position to check.

Returns:

The NID of the terrain at the specified position.

Return type:

NID

get_all_formation_spots() List[Pos]

Gets all the formation spots on the current level.

Returns:

A list of tuples representing the coordinates of formation spots.

Return type:

List[Pos]

get_open_formation_spots() List[Pos]

Gets all open formation spots on the current level.

Returns:

A list of tuples representing the coordinates of open formation spots.

Return type:

List[Pos]

get_money() int

Gets the current amount of money for the current party.

Returns:

The amount of money.

Return type:

int

get_bexp() int

Gets the current amount of bonus experience (BEXP) for the current party.

Returns:

The amount of BEXP.

Return type:

int

get_random(a: int, b: int) int

Canononical method for getting a random integer between a and b (inclusive) without screwing up the turnwheel.

Parameters:
  • a (int) – The lower bound.

  • b (int) – The upper bound.

Returns:

A random integer.

Return type:

int

get_random_float() float

Canonical method for getting a random float (0, 1] without messing up the turnwheel.

Returns:

A random float.

Return type:

float

get_random_choice(choices: Iterable, seed: int = None)

Canonical method for getting a random choice from an iterable (a list or set) without messing up the turnwheel.

Parameters:
  • choices (Iterable) – The iterable to choose from.

  • seed (int) – An optional seed for reproducibility. Defaults to in-game seed.

Returns:

A random choice from the iterable.

Return type:

Any

get_random_weighted_choice(choices: List, weights: List[float])

Canonical method for getting a random weighted choice from a list of choices without messing up the turnwheel.

Parameters:
  • choices (List) – The list of choices.

  • weights (List[float]) – The corresponding weights for each choice.

Returns:

A random choice from the list, weighted by the provided weights.

Return type:

Any