Entities

Entities are anything that exist within your world that is either the player or that the player can interact with in some way. Things like enemies, other people, animals, etc… They can also be inanimate object, for example a table that the player needs to grab a key from.

class pyzork.entities.Player(**kwargs)[source]

The player, this implents some changes from the base entity class such as the player dying raising an error and ending the game.

Parameters:
  • max_health (int) – The maximum amount of health the entity can have, 0 by default
  • health (int) – The entity’s current health. Same as max_health by default
  • attack (int) – How much damage a entity deals with empty hands, 0 by default
  • defense (int) – How much an entity reduces damage with no extra armor, 0 by default.
  • max_energy (int) – The maximum amount of energy an entity can have, 0 by default
  • energy (int) – The entity’s current energy. Same as max_energy by default.
  • inventory (Inventory) – The entity’s inventory
  • experience (ExperienceLevels) – This entity’s experience and levels
  • money (int) – This is entity’s current money
  • name (str) – The entity’s name
  • description (str) – Flavour text about the entity
max_health

The maximum amount of health the entity can have.

Type:int
health

The entity’s current health.

Type:int
attack

How much damage a entity deals with empty hands.

Type:int
defense

How much an entity reduces damage with no extra armor.

Type:int
max_energy

The maximum amount of energy an entity can have.

Type:int
energy

The entity’s current energy.

Type:int
inventory

The entity’s inventory

Type:Inventory
experience

This entity’s experience and levels

Type:ExperienceLevels
money

This is entity’s current money

Type:int
name

The entity’s name

Type:str
description

Flavour text about the entity

Type:str
world

The world the player is interacting with, this is not set until the method set_world is called, which normally the World you pass the player to will take care.

Type:World
add_ability(ability)

Add an ability to the entity, making it available for casting

Parameters:ability (Ability) – The ability to add
add_modifier(modifier)

Add a modifier to the entity, if the modifier already exists it will refresh the duration.

Parameters:modifier (Modifier) – The modifier to add
add_money(value)

Add some money to the entity

Parameters:value (int) – The amount of money to add
can_cast(value)

Check if this entity can cast

Parameters:???
Returns:True if they can cast
Return type:bool
do_attack(target)

Perform an attack on target, the entity attacks with their weapon and the target takes damage. This method applies the weapon effect to the target and the armor effect of the target to the attacking entity.

Parameters:target (Entity) – The target to attack
end_turn()

End this entity’s turn, decrementing all the modifier’s durations and removing the expired ones.

gain_energy(value)

Gain some energy

Parameters:value (int) – The amount of energy to gain
gain_experience(value)

Increase the experience of the entity by a certain amount, this amount is affect by the entity experience_gain modifier.

Parameters:value (int) – The amount of exp to gain
is_alive()

Check if this entity is alive.

Returns:True if the entity is alive
Return type:bool
lose_experience(value)

Reduce the experience of the entity by certain amount, this number is not affected by anything.

Parameters:value (int) – The amount of exp to remove
print_abilities()

Print all the abilities of an entity

print_inventory()[source]

Print the inventory, abilities and quests of the player.

print_stats()

Print all the stats of the entity

remove_ability(ability)

Remove an ability from the list of available abilities for this entity. The argument does not need to be the exact same instance, it just needs to hash to the same as your intended target..

Parameters:ability (Ability) – The ability to remove
remove_modifier(modifer)

Remove a modifier from the entity. The argument doesn’t need to be the exact same instance, it just needs to hash to the same as your intended target.

Parameters:modifier (Modifier) – The modifier to remove
remove_money(value)

Remove some money from the entity

Parameters:value (int) – The amount of money to remove
restore_health(value)

Restore some of this entity’s health

Parameters:value (int) – The amount of value to restore
set_world(world)[source]

You must call this if you made changes to the World class’ init so that the player has access to the world they are interacting in.

Parameters:world (World) – The world instance to link the player to
take_damage(value)

Deal damage to this entity, the entity’s defense is substracted from this damage, but this can deal no less than 1 damage.

Parameters:value (int) – The amount of damage to take
take_pure_damage(value)

Deal pure damage to this entity. Pure damage cannot be reduced by the entity’s defense

Parameters:value (in) – The amount of damage to take
use_ability(ability, target)

Use an ability on an entity

Parameters:
  • ability (Ability) – The ability to cast
  • target (Entity) – The target to cast the ability on
use_energy(value)

Use some energy

Parameters:value (int) – The amount of energy to use
use_item_on(item, target)

Use an item on a target

Parameters:
  • item (Item) – The item to use
  • target (Entity) – The entity to use this item on
use_item_on_me(item)

Use an item on this entity

Parameters:item (Item) – The item to use
class pyzork.entities.NPC(**kwargs)[source]

Any interactable entity that isn’t the Player

Parameters:
  • max_health (int) – The maximum amount of health the entity can have, 0 by default
  • health (int) – The entity’s current health. Same as max_health by default
  • attack (int) – How much damage a entity deals with empty hands, 0 by default
  • defense (int) – How much an entity reduces damage with no extra armor, 0 by default.
  • max_energy (int) – The maximum amount of energy an entity can have, 0 by default
  • energy (int) – The entity’s current energy. Same as max_energy by default.
  • inventory (Inventory) – The entity’s inventory
  • experience (ExperienceLevels) – This entity’s experience and levels
  • money (int) – This is entity’s current money
  • name (str) – The entity’s name
  • description (str) – Flavour text about the entity
  • experience_points (Optiona[int]) – How much experience this entity grants when defeated in battle, zero by default
max_health

The maximum amount of health the entity can have.

Type:int
health

The entity’s current health.

Type:int
attack

How much damage a entity deals with empty hands.

Type:int
defense

How much an entity reduces damage with no extra armor.

Type:int
max_energy

The maximum amount of energy an entity can have.

Type:int
energy

The entity’s current energy.

Type:int
inventory

The entity’s inventory

Type:Inventory
experience

This entity’s experience and levels

Type:ExperienceLevels
money

This is entity’s current money

Type:int
name

The entity’s name

Type:str
description

Flavour text about the entity

Type:str
experience_points

How much experience this entity grants when defeated in battle

Type:int
add_ability(ability)

Add an ability to the entity, making it available for casting

Parameters:ability (Ability) – The ability to add
add_modifier(modifier)

Add a modifier to the entity, if the modifier already exists it will refresh the duration.

Parameters:modifier (Modifier) – The modifier to add
add_money(value)

Add some money to the entity

Parameters:value (int) – The amount of money to add
battle_logic(battle)[source]

This method implement the behavior of enemies during battle. A basic logic is aready implemented which just attacks the player. For boss battles this method is overwritten to implement more complex logic. This method takes the entire battle instance as the argument and therefore has full unrestricted access to the entire context of the battle, make full use of that.

Parameters:battle (Battle) – The battle where this entity is taking place
can_cast(value)

Check if this entity can cast

Parameters:???
Returns:True if they can cast
Return type:bool
do_attack(target)

Perform an attack on target, the entity attacks with their weapon and the target takes damage. This method applies the weapon effect to the target and the armor effect of the target to the attacking entity.

Parameters:target (Entity) – The target to attack
end_turn()

End this entity’s turn, decrementing all the modifier’s durations and removing the expired ones.

experience_granted(player)[source]

Overwritable method which determines how experience is granted to the player when the entity is deafeted, by default this simply returns the entity’s experience_points

Parameters:player (Player) – The player that defeated the entity
Returns:The amount of experience to gratn in response
Return type:int
gain_energy(value)

Gain some energy

Parameters:value (int) – The amount of energy to gain
gain_experience(value)

Increase the experience of the entity by a certain amount, this amount is affect by the entity experience_gain modifier.

Parameters:value (int) – The amount of exp to gain
interaction(world)[source]

Abstract method for interacting with this entity, give a quest or fight

Parameters:world (World) – The world where this entity lives
is_alive()

Check if this entity is alive.

Returns:True if the entity is alive
Return type:bool
lose_experience(value)

Reduce the experience of the entity by certain amount, this number is not affected by anything.

Parameters:value (int) – The amount of exp to remove
print_abilities()

Print all the abilities of an entity

print_interaction(world)[source]

Abstract method to be implemented, notifies the player that they can interact with this NPC.

Parameters:world (World) – The world where this entity lives
print_inventory()

Print all the inventory of entity

print_stats()

Print all the stats of the entity

remove_ability(ability)

Remove an ability from the list of available abilities for this entity. The argument does not need to be the exact same instance, it just needs to hash to the same as your intended target..

Parameters:ability (Ability) – The ability to remove
remove_modifier(modifer)

Remove a modifier from the entity. The argument doesn’t need to be the exact same instance, it just needs to hash to the same as your intended target.

Parameters:modifier (Modifier) – The modifier to remove
remove_money(value)

Remove some money from the entity

Parameters:value (int) – The amount of money to remove
restore_health(value)

Restore some of this entity’s health

Parameters:value (int) – The amount of value to restore
take_damage(value)

Deal damage to this entity, the entity’s defense is substracted from this damage, but this can deal no less than 1 damage.

Parameters:value (int) – The amount of damage to take
take_pure_damage(value)

Deal pure damage to this entity. Pure damage cannot be reduced by the entity’s defense

Parameters:value (in) – The amount of damage to take
use_ability(ability, target)

Use an ability on an entity

Parameters:
  • ability (Ability) – The ability to cast
  • target (Entity) – The target to cast the ability on
use_energy(value)

Use some energy

Parameters:value (int) – The amount of energy to use
use_item_on(item, target)

Use an item on a target

Parameters:
  • item (Item) – The item to use
  • target (Entity) – The entity to use this item on
use_item_on_me(item)

Use an item on this entity

Parameters:item (Item) – The item to use

Examples

There are many ways of making entities, for most cases you’ll only need the from_dict method but you can always subclass the Player or NPC classes for further edits

Basic

import pyzork

Goblin = pyzork.Goblin.from_dict(name="Goblin", max_health=20, attack=3, description="A lowly goblin")