Skip to content

Confusion spell

ConfusionSpell class

def __init__(self, number_of_turns, owner=None):

Bases: Consumable

Consumable which applies a confusion effect on a target.

Attributes
Name Type Description
number_of_turns int

Number of turns the confusion effect should persist for.

owner Item | None

Item instance that owns this component.

Parameters
Name Type Description Default
number_of_turns int

Number of turns the confusion effect should persist for.

required
owner Item | None

Item instance that owns this component.

None

get_action_or_handler method

def get_action_or_handler(self, entity, engine, old_event_handler=None):

Method to get the event handler that should be used to consume this consumable.

Parameters
Name Type Description Default
entity ActiveEntity

Entity consuming the consumable. This argument is not actually used by the method.

required
engine Engine

Engine that represents the current game.

required
old_event_handler BaseEventHandler | None

Previous event handler.

None
Raises
Type Description
AttributeError

When self.owner is None.

Returns
Type Description
SelectTargetIndexEventHandler

Event handler for selecting the target index.

get_targets method

def get_targets(self, *, engine, consumer=None, location=None):

Method to get the target for the confusion effect.

Passing consumer has no effect since the confusion spell is applied to a specific entity at a location.

Parameters
Name Type Description Default
engine Engine

Engine that represents the current game.

required
location tuple[int, int] | None

Location to get the target from.

None
Returns
Type Description
ActiveEntity | set[ActiveEntity] | None

Target at location, or None if no target exists or if location is set as None.

activate method

def activate(self, consumer, engine, target_location=None):

Method to activate the confusion effect on a target.

Parameters
Name Type Description Default
consumer ActiveEntity

Entity consuming the consumable.

required
engine Engine

Engine representing the current game.

required
target_location tuple[int, int] | None

Location of the target the effect should be applied on.

None
Raises
Type Description
AttributeError

If self.owner is None.

ImpossibleActionException

When consumable cannot be activated.