Game state

Initializing mod.game submodules, common properties and game events.

mod.game

tera-game-state is the built-in game state library for network modules, available as mod.game. Use enter_game instead of repeatedly parsing S_LOGIN, and mod.game.me.name instead of tracking the character name yourself. This reduces duplicate hooks and dependence on packet versions.

Initialization

me loads by default. Request other submodules in your constructor, before character login:

module.exports = function StateExample(mod) {
    mod.game.initialize(['inventory', 'party', 'me.abnormalities']);
    const onEnter = () => mod.log(`Character: ${mod.game.me.name}`);
    const onInventory = () => mod.log(`Gold: ${mod.game.inventory.money / 10000n}`);
    mod.game.on('enter_game', onEnter);
    mod.game.inventory.on('update', onInventory);

    this.destructor = () => {
        mod.game.removeListener('enter_game', onEnter);
        mod.game.inventory.removeListener('update', onInventory);
    };
};

initialize('inventory') and initialize(['inventory']) are equivalent. me.abnormalities enables the submodule and its additional feature. Repeated requests reuse a loaded submodule. Late initialization does not automatically replay packets missed before activation.

Common properties

Property Meaning
isIngame A character has entered the game
isInLoadingScreen A loading screen is active
state Internal state: 0 INVALID, 1 CHARACTER_LOBBY, 2 INGAME
language Language from C_LOGIN_ARBITER
accountId, accountName Account information after the corresponding packets
serverId Current server ID
isTBA TERA Battle Arena mode on supported patches
data Client data caches

Events

enter_character_lobby, leave_character_lobby, enter_game, leave_game, enter_loading_screen and leave_loading_screen have no arguments. State events fire on transitions. For example, S_LOGIN enters the loading screen and game state; S_SPAWN_ME ends the loading screen. Entering the game does not mean inventory is available: wait for inventory.update.

Submodules use EventEmitter (on, once, removeListener). Remove your listeners on unload; do not call removeAllListeners on a shared emitter, as other modules may have subscriptions.

Submodules

me, inventory, party, contract, glyphs, talents, data.

Sources: doc/mod/tera-game-state.md, mods/tera-game-state/README.md, mods/tera-game-state/index.js.