trigger module

class core.gameCreation.trigger.Trigger(event_type, condition, reaction, label=None, source=None, flags=None, next_trigger=None, cooldown=None, last_fired_turn=None)

Bases: object

Represents a trigger that listens for an event, checks a condition, and fires a reaction.

Parameters:
  • event_type (str) – The type of event this trigger listens for.

  • condition (callable or SkillCheck) – The condition to check before firing the reaction. Can be a callable or SkillCheck.

  • reaction (callable or object with an execute() method) – The reaction to execute if the condition passes.

  • label (str, optional) – Optional label for the trigger.

  • source (str, optional) – Optional source identifier for the trigger.

  • flags (dict, optional) – Optional dictionary of flags for the trigger.

  • next_trigger (Trigger, optional) – Optional next trigger to chain after this one.

  • cooldown (int, optional) – Optional cooldown in turns before this trigger can fire again.

  • last_fired_turn (int, optional) – Internal use for cooldown tracking.

check_and_react(event_data)

Checks the trigger’s condition and fires the reaction if appropriate.

Parameters:

event_data (dict) – Data about the event that occurred.

classmethod from_dict(data)

Deserializes a trigger from a dictionary.

Parameters:

data (dict) – The dictionary to deserialize from.

Returns:

The deserialized Trigger instance.

Return type:

Trigger

property label

The label for this trigger.

Returns:

The label string.

Return type:

str

to_dict()

Serializes this trigger to a dictionary.

Returns:

A dictionary representation of the trigger.

Return type:

dict