reaction package

Submodules

models.flow.reaction.reaction module

class models.flow.reaction.reaction.Reaction(reactor, trigger_action)

Bases: object

Represents a reaction to a trigger action in the flow.

reactor

The entity performing the reaction.

Type:

object

trigger_action

The action that triggered this reaction.

Type:

object

resolve()

Resolve the reaction.

This method implements the logic of the reaction. It could interrupt, modify, or negate the original action.

Return type:

None

models.flow.reaction.reaction_queue module

class models.flow.reaction.reaction_queue.ReactionQueue

Bases: object

A queue to manage and resolve reaction objects.

Reactions are expected to have a resolve() method.

classmethod add(reaction)

Add a reaction to the queue.

Parameters:

reaction (object) – An object with at least a resolve() method.

classmethod blocked()

Check if execution is currently blocked by pending reactions.

Returns:

True if there are pending reactions in the queue, False otherwise.

Return type:

bool

classmethod resolve()

Resolve all queued reactions in order.

Each reaction’s resolve() method is called. If an exception occurs, it is caught and printed, and resolution continues with the next reaction.

models.flow.reaction.reactions module

class models.flow.reaction.reactions.Reactions

Bases: object

Base class for reaction handlers.

This class should be subclassed to implement specific reaction logic.

classmethod from_dict(data)

Create a reaction instance from a dictionary.

Parameters:

data (dict) – Dictionary containing the reaction data.

Returns:

An instance of the reaction.

Return type:

Reactions

Raises:

NotImplementedError – If not implemented in a subclass.

to_dict()

Serialize the reaction to a dictionary.

Returns:

A dictionary representation of the reaction.

Return type:

dict

Raises:

NotImplementedError – If not implemented in a subclass.

models.flow.reaction.reactiona_list module

class models.flow.reaction.reactions_list.AlertGamemaster(message: str)

Bases: Reactions

Reaction that alerts the gamemaster with a message.

Parameters:

message (str) – The message to send to the gamemaster.

classmethod from_dict(data)

Create an AlertGamemaster reaction from a dictionary.

Parameters:

data (dict) – Dictionary containing ‘message’.

Returns:

An instance of AlertGamemaster.

Return type:

AlertGamemaster

to_dict()

Serialize the reaction to a dictionary.

Returns:

Dictionary representation of the reaction.

Return type:

dict

class models.flow.reaction.reactions_list.ApplyDamage(damage_type: str, amount: int)

Bases: Reactions

Reaction that applies damage to a target.

Parameters:
  • damage_type (str) – The type of damage to apply (e.g., “fire”, “bludgeoning”).

  • amount (int) – The amount of damage to apply.

classmethod from_dict(data)

Create an ApplyDamage reaction from a dictionary.

Parameters:

data (dict) – Dictionary containing ‘damage_type’ and ‘amount’.

Returns:

An instance of ApplyDamage.

Return type:

ApplyDamage

to_dict()

Serialize the reaction to a dictionary.

Returns:

Dictionary representation of the reaction.

Return type:

dict