evennia.contrib.tutorials.evadventure.equipment

Knave has a system of Slots for its inventory.

exception evennia.contrib.tutorials.evadventure.equipment.EquipmentError[源代码]

基类:TypeError

class evennia.contrib.tutorials.evadventure.equipment.EquipmentHandler(obj)[源代码]

基类: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)[源代码]

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

count_slots()[源代码]

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)[源代码]

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

参数

obj (EvAdventureObject) – The object to add.

get_current_slot(obj)[源代码]

Check which slot-type the given object is in.

参数

obj (EvAdventureObject) – The object to check.

返回

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.

返回

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.

返回

obj or None – The weapon. None if unarmored.

display_loadout()[源代码]

Get a visual representation of your current loadout.

返回

str – The current loadout.

display_backpack()[源代码]

Get a visual representation of the backpack’s contents.

display_slot_usage()[源代码]

Get a slot usage/max string for display.

返回

str – The usage string.

move(obj)[源代码]

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.

参数

obj (EvAdventureObject) – Thing to use.

引发

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

提示

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)[源代码]

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

参数

obj (EvAdventureObject) – The object to add.

提示

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

remove(obj_or_slot)[源代码]

Remove specific object or objects from a slot.

参数

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!

返回

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

提示

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

get_wieldable_objects_from_backpack()[源代码]

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.

返回

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()[源代码]

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.

返回

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()[源代码]

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

返回

list – A list of objects that are usable.

all(only_objs=False)[源代码]

Get all objects in inventory, regardless of location.

关键字参数

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

返回

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.