evennia.contrib.tutorials.evadventure.equipment

Knave has a system of Slots for its inventory.

exception evennia.contrib.tutorials.evadventure.equipment.EquipmentError[source]

Bases: TypeError

class evennia.contrib.tutorials.evadventure.equipment.EquipmentHandler(obj)[source]

Bases: object

_Knave_ puts a lot of emphasis on the inventory. You have CON_DEFENSE inventory slots. Some things, like torches can fit multiple in one slot, other (like big weapons and armor) use more than one slot. The items carried and wielded has a big impact on character customization - even magic requires carrying a runestone per spell.

The inventory also doubles as a measure of negative effects. Getting soaked in mud or slime could gunk up some of your inventory slots and make the items there unusuable until you clean them.

save_attribute = 'inventory_slots'
__init__(obj)[source]

Initialize self. See help(type(self)) for accurate signature.

count_slots()[source]

Count slot usage. This is fetched from the .size Attribute of the object. The size can also be partial slots.

property max_slots

The max amount of equipment slots (‘carrying capacity’) is based on the constitution defense.

validate_slot_usage(obj)[source]

Check if obj can fit in equipment, based on its size.

Parameters

obj (EvAdventureObject) – The object to add.

get_current_slot(obj)[source]

Check which slot-type the given object is in.

Parameters

obj (EvAdventureObject) – The object to check.

Returns

WieldLocation – A location the object is in. None if the object is not in the inventory at all.

property armor

Armor provided by actually worn equipment/shield. For body armor this is a base value, like 12, for shield/helmet, it’s a bonus, like +1. We treat values and bonuses equal and just add them up. This value can thus be 0, the ‘unarmored’ default should be handled by the calling method.

Returns

int

Armor from equipment. Note that this is the +bonus of Armor, not the

’defense’ (to get that one adds 10).

property weapon

Conveniently get the currently active weapon or rune stone.

Returns

obj or None – The weapon. None if unarmored.

display_loadout()[source]

Get a visual representation of your current loadout.

Returns

str – The current loadout.

display_backpack()[source]

Get a visual representation of the backpack’s contents.

display_slot_usage()[source]

Get a slot usage/max string for display.

Returns

str – The usage string.

move(obj)[source]

Moves item to the place it things it should be in - this makes use of the object’s wield slot to decide where it goes. The item is assumed to already be in the backpack.

Parameters

obj (EvAdventureObject) – Thing to use.

Raises

EquipmentError – If there’s no room in inventory. It will contains the details of the error, suitable to echo to user.

Notes

This will cleanly move any ‘colliding’ items to the backpack to make the use possible (such as moving sword + shield to backpack when wielding a two-handed weapon). If wanting to warn the user about this, it needs to happen before this call.

add(obj)[source]

Put something in the backpack specifically (even if it could be wield/worn).

Parameters

obj (EvAdventureObject) – The object to add.

Notes

This will not change the object’s .location, this must be done by the calling code.

remove(obj_or_slot)[source]

Remove specific object or objects from a slot.

Parameters

obj_or_slot (EvAdventureObject or WieldLocation) – The specific object or location to empty. If this is WieldLocation.BACKPACK, all items in the backpack will be emptied and returned!

Returns

list – A list of 0, 1 or more objects emptied from the inventory.

Notes

This will not change the object’s .location, this must be done separately by the calling code.

get_wieldable_objects_from_backpack()[source]

Get all wieldable weapons (or spell runes) from backpack. This is useful in order to have a list to select from when swapping your wielded loadout.

Returns

list – A list of objects with a suitable inventory_use_slot. We don’t check quality, so this may include broken items (we may want to visually show them in the list after all).

get_wearable_objects_from_backpack()[source]

Get all wearable items (armor or helmets) from backpack. This is useful in order to have a list to select from when swapping your worn loadout.

Returns

list – A list of objects with a suitable inventory_use_slot. We don’t check quality, so this may include broken items (we may want to visually show them in the list after all).

get_usable_objects_from_backpack()[source]

Get all ‘usable’ items (like potions) from backpack. This is useful for getting a list to select from.

Returns

list – A list of objects that are usable.

all(only_objs=False)[source]

Get all objects in inventory, regardless of location.

Keyword Arguments

only_objs (bool) – Only return a flat list of objects, not tuples.

Returns

list – A list of item tuples [(item, WieldLocation),…] starting with the wielded ones, backpack content last. If only_objs is set, this will just be a flat list of objects.