Skip to content

EventManager ​

Inherits: Node

Central coordinator for events, quests, and quest lines. Manages lifecycle, state tracking, and signal-based communication between game systems.

Description ​

RESPONSIBILITIES:

  • Loads runtime duplicates of events, quests, and quest lines from database
  • Coordinates quest line progression through signal-based communication
  • Tracks active/completed/failed states for all managed resources
  • Manages quest objective signal connections for level transitions
  • Handles quest activation, completion, and rewards
  • Stores global variables for branching narratives and world state
  • Provides save/load functionality for all quest progress

INITIALIZATION: Call initialize(system_hub) once during game setup. This loads all resources as runtime duplicates, sets up signal connections, and initializes global variables.

SIGNAL-BASED COORDINATION: QuestLines emit signals when they need quests activated. EventManager responds by activating quests and providing references back. This loose coupling allows components to be self-managing while EventManager coordinates cross-system communication.

USAGE:

  • activate_quest_line(id) / activate_quest(id) to start quests
  • EventManager coordinates progression through signal responses
  • track_quest(id) / untrack_quest(id) for UI tracking
  • get_active_quests() / get_completed_quests() for queries
  • to_save_data() / from_save_data() for persistence

Variables ​

Dictionaryevents{}
Arrayactive_events[]
Arraycompleted_events[]
Arrayfailed_events[]
Dictionaryquest_lines{} # int -> QuestLine
Dictionaryquests{} # int -> Quest
Arraypopups_seen[]
boolgame_start_donefalse
Arrayactive_quest_lines[]
Arrayactive_quests[]
Arraycompleted_quests[]
Arraycompleted_quest_lines[]
Arraytracked_quests[]
Dictionaryvariables{}

Methods ​

voidinitialize( system_hub: GameHost.SystemHub )
voidsetup_all_events()
voidreset_for_new_game()
boolactivate_quest_line( quest_line_id: int )
boolactivate_quest( quest_id: int, forced: bool = false )
booltrack_quest( quest_id: int )
booluntrack_quest( quest_id: int )
boolis_quest_tracked( quest_id: int )
Array[Quest]get_tracked_quests()
boolforce_trigger_event( event_id: int )
booltry_trigger_event( event_id: int, event_data: Dictionary = {} )
Eventget_event( event_id: int )
boolis_event_completed( event_id: int )
boolis_event_active( event_id: int )
boolis_event_failed( event_id: int )
boolcan_accept_quest( quest_id: int )
Array[String]get_quest_requirement_failures( quest_id: int )
boolabandon_quest( quest_id: int )
boolcomplete_quest_objective( quest_id: int, objective_id: int )
Array[QuestLine]get_active_quest_lines()
Array[Quest]get_active_quests()
Array[Dictionary]get_objectives_concerning( target: Variant )
Array[Quest]get_completed_quests()
Array[QuestLine]get_completed_quest_lines()
boolhas_seen_popup( popup_id: int )
voidmark_popup_seen( popup_id: int )
boolhas_quest( quest_id: int )
Questget_quest( quest_id: int )
QuestLineget_quest_line( quest_line_id: int )
QuestLineget_quest_line_for_quest( quest_id: int )
Variantget_variable( key: String, default_value: Variant = null )
voidset_variable( key: String, value: Variant )
boolhas_variable( key: String )
voidupdate_objective_signals()
voiddisconnect_objective_signals()
Dictionaryto_save_data()
voidfrom_save_data( save_data: Dictionary )
voidcleanup_event_triggers()

Signals ​

variable_changed( key: String, old_value: Variant, new_value: Variant ) ​

Emitted when a variable is set or changed

variable_removed( key: String, old_value: Variant ) ​

Emitted when a variable is removed

variables_cleared() ​

Emitted when all variables are cleared

conversation_chat_shown( conversation_id: int, chat_id: int, player: Entity ) ​

Emitted when a chat of a conversation is shown to a player (the conversation starts, or the player goes on to another chat)

quest_line_activated( quest_line: QuestLine ) ​

Emitted when a quest line is activated

quest_line_completed( quest_line: QuestLine ) ​

Emitted when a quest line is completed

quest_line_failed( quest_line: QuestLine ) ​

Emitted when a quest line has failed

quest_activated( quest: Quest ) ​

Emitted when a quest is activated

quest_completed( quest: Quest ) ​

Emitted when a quest is completed

quest_failed( quest: Quest ) ​

Emitted when a quest has failed

quest_abandoned( quest: Quest ) ​

Emitted when the player gives a quest up (not a failure: nothing that waits for a quest to fail is told)

objective_completed( quest: Quest, objective: QuestObjective ) ​

Emitted when an objective within a quest is completed

quest_tracking_changed( quest: Quest, is_tracked: bool ) ​

Emitted when a quest's tracking status changes

Variable descriptions ​

Dictionary events = ​

int -> Event

Array active_events = [] ​

The ids of the events that are in progress.

Array completed_events = [] ​

The ids of the events that are done.

Array failed_events = [] ​

The ids of the events that failed.

Dictionary quest_lines = # int -> QuestLine ​

Dictionary to store all registered quest lines by their ID

Dictionary quests = # int -> Quest ​

Dictionary to store all registered quests by their ID

Array popups_seen = [] ​

The popups that were shown and are shown once only (PopupData.show_once)

bool game_start_done = false ​

Has the game start been announced in this game? (the game start triggers fire once per game: not when a save is loaded or the world changes)

Array active_quest_lines = [] ​

Array of IDs for currently active quest lines

Array active_quests = [] ​

Array of IDs for currently active quests

Array completed_quests = [] ​

Array of IDs for completed quests

Array completed_quest_lines = [] ​

Array of IDs for completed quest lines

Array tracked_quests = [] ​

Stores IDs of quests that are currently being tracked in the UI

Dictionary variables = ​

Dictionary storing all global variables

Method descriptions ​

void initialize( system_hub: GameHost.SystemHub ) ​

Initialize EventManager with DUPLICATED resources from database This is the primary initialization method - call once at game system setup

void setup_all_events() ​

Setup all event triggers (called after loading events)

void reset_for_new_game() ​

Reset all state for new game (keeps resource instances, resets their state)

bool activate_quest_line( quest_line_id: int ) ​

Activates a quest line by ID, returns true if successful Note: Quest requirements are checked when activating individual quests

bool activate_quest( quest_id: int, forced: bool = false ) ​

Activates an individual quest by ID, returns true if successful Checks player requirements before activation Automatically activates parent quest line if quest belongs to one forced is for the events (the Start quest action): the event decides, so the requirements, the limit of quests, a cooldown and a quest that was done or failed do not stop it

bool track_quest( quest_id: int ) ​

Tracks a quest in the UI

bool untrack_quest( quest_id: int ) ​

Stops tracking a quest in the UI

bool is_quest_tracked( quest_id: int ) ​

Returns whether a quest is currently being tracked

Array[Quest] get_tracked_quests() ​

Returns an array of all tracked quests

bool force_trigger_event( event_id: int ) ​

Manually trigger an event (bypasses conditions)

bool try_trigger_event( event_id: int, event_data: Dictionary = {} ) ​

Manually trigger an event with condition checking

Event get_event( event_id: int ) ​

The event with this id, or null.

bool is_event_completed( event_id: int ) ​

Is the event done?

bool is_event_active( event_id: int ) ​

Is the event in progress?

bool is_event_failed( event_id: int ) ​

Did the event fail?

bool can_accept_quest( quest_id: int ) ​

Check if a quest can be accepted by the current player

Array[String] get_quest_requirement_failures( quest_id: int ) ​

Get failure messages for why a quest cannot be accepted

bool abandon_quest( quest_id: int ) ​

The player gives a quest up (when the quest and the settings allow it): it goes back to the start and can be taken again. False when it cannot be given up

bool complete_quest_objective( quest_id: int, objective_id: int ) ​

Marks a specific objective as completed for a quest

Array[QuestLine] get_active_quest_lines() ​

Returns an array of all active quest lines

Array[Quest] get_active_quests() ​

Returns an array of all active quests

Array[Dictionary] get_objectives_concerning( target: Variant ) ​

The active objectives of the active quests that are about this entity or object (kill it, talk to it, open it ...): a list of {quest, objective}. What the tooltip of an entity shows

Array[Quest] get_completed_quests() ​

Returns an array of all completed quests

Array[QuestLine] get_completed_quest_lines() ​

Returns an array of all completed quest lines

bool has_seen_popup( popup_id: int ) ​

Was this popup shown in this game? (only popups that are shown once are remembered)

void mark_popup_seen( popup_id: int ) ​

Remembers that a popup was shown (a popup that shows once does not show again).

bool has_quest( quest_id: int ) ​

Is there a quest with this id?

Quest get_quest( quest_id: int ) ​

Get a quest by ID, returns null if not found

QuestLine get_quest_line( quest_line_id: int ) ​

Get a quest line by ID, returns null if not found

QuestLine get_quest_line_for_quest( quest_id: int ) ​

Find the quest line that contains a specific quest, returns null if not in any quest line

Variant get_variable( key: String, default_value: Variant = null ) ​

Get a variable value with optional default

void set_variable( key: String, value: Variant ) ​

Set a variable (runtime only - doesn't save to database)

bool has_variable( key: String ) ​

Check if variable exists

void update_objective_signals() ​

Updates signal connections for all active objectives Should be called after level loading is complete

void disconnect_objective_signals() ​

Disconnects all signal connections for all active objectives Should be called before level unloading

Dictionary to_save_data() ​

Save complete event manager state (events, quests, questlines, variables)

void from_save_data( save_data: Dictionary ) ​

Load complete event manager state (events, quests, questlines, variables). Everything the save does not mention starts over: the game that is loaded may be one that went further than the save

void cleanup_event_triggers() ​

Stops the triggers of every event.