Characters¶
- class turnable.chars.AIEntity(*args, **kwargs)¶
For now it can only attack.
- get_action() turnable.streams.CommandResponse¶
This method defines what action is the Entity playing in it’s turn.
For a Playable character you might request the input to the user, whilst for an AI character you’d run some algorithm (or random.randint() :D)
- target_attack(enemies)¶
This method is called first in
attack()to target enemies.
- class turnable.chars.CharacterStatus(value)¶
An enumeration.
- class turnable.chars.Entity(name: str = 'Entity', damage: int = 10, pos: Optional[turnable.geometry.Position] = None, *args, **kwargs)¶
Represents base entity for both AI (enemies) and not-AI characters Entities. Most of the time you shouldn’t need to directly inherit from this class.
- attack()¶
Deals damage equal to
damageto all enemies targetted bytarget_attack().
- available_actions()¶
Returns actions available to the player.
Actions are added as
COMMAND_CLASSwhich defaults toturnable.command.Command, if you are using a command subclass remember to override the attribute in your subclass.Note
If you’re adding actions in a subclass and wanna keep the existing ones remember to start with
actions = super().available_actions(), add your custom actions to the dictionary and return it.
- get_action() turnable.streams.CommandResponse¶
This method defines what action is the Entity playing in it’s turn.
For a Playable character you might request the input to the user, whilst for an AI character you’d run some algorithm (or random.randint() :D)
- handle_attack(resp: turnable.streams.CommandResponse)¶
Handles attack from
turnable.streams.CommandResponse.It’s good practice to make handler functions for every Actions in
available_actions()that takes care of setup, and then defer the actual logic to it’s own function. Even if the only thing you are currently doing is calling the logic function, as in this example, it will make inheritance much easier.For other example see
handle_move().
- play_turn()¶
Plays turn and triggers appropiate hooks. You can change the hooks triggered overriding
TURN_START_HOOKandTURN_END_HOOK.By default, Entity enables the Special Commands feature.
- class turnable.chars.HealthyEntity(health: int = 100, armor: int = 100)¶
Represents an Entity with health and armor
- is_alive()¶
Returns if entity has health left.
- take_damage(damage: int)¶
Handles health and armor reduction based on incomming damage.
- class turnable.chars.Mage(*args, max_targets: int = 2, **kwargs)¶
Mage class. Deals damage in area.
- target_attack(enemies)¶
Selects
max_targetstargets randomly.
- class turnable.chars.PlayableEntity(name: str = 'Entity', damage: int = 10, pos: Optional[turnable.geometry.Position] = None, *args, **kwargs)¶
Entity that represents a human player.
- available_actions()¶
Adds move action as a Playable character should be able to move between rooms.
- get_action() turnable.streams.CommandResponse¶
Sends out the request for the next move and retries if command is invalid.
- handle_move(resp: turnable.streams.CommandResponse) bool¶
Prepares move from action
turnable.streams.CommandResponse.It’s good practice to make handler functions for every Actions in
available_actions()that takes care of setup, and then defer the actual logic to it’s own function.For other example see
handle_attack().
- move(newpos: turnable.geometry.Position, delta: bool = True) bool¶
Tries to move character to new position. If delta is True the position will be added; otherwise it’ll be replaced.
- target_attack(enemies)¶
Ask player for target.