inventory
inventory
The inventory module includes the Inventory class which backs the inventory attribute of a PlayerCharacter.
Inventory
A container to hold and manage items owned by a PlayerCharacter.
You should not create an Inventory directly. When you initialize a PlayerCharacter, an inventory is created as a
property of the PC. You can then add and remove items to and from the inventory using methods on the
PlayerCharacter.
Attributes:
-
item_dict(defaultdict[ItemType, List[Item]]) –List of items in the inventory.
-
owner(PlayerCharacter) –Owner of the inventory.
Example:
Parameters:
-
player_character_owner(PlayerCharacter) –The player character that owns the inventory.
all_items
property
armor
property
equipment
property
equipped_items
property
magic_items
property
misc_items
property
spells
property
weapons
property
add_item
add_item(item: Item)
drop_all_items
equip_item
Equips an item if it can be equipped.
Parameters:
-
item(Item) –Item to equip.
Returns:
-
bool(bool) –Whether the item was successfully equipped.
Raises:
-
ItemNotUsableError–If the item is not usable by the owner's character class.
from_dict
classmethod
Deserializes a dictionary representation of an Inventory object. Typically done after getting the dictionary from persistent storage.
Parameters:
-
inventory_dict(dict) –Dictionary representation of the inventory.
-
player_character_owner(PlayerCharacter) –The player character that owns the inventory.
get_equipped_weapon
get_equipped_weapon() -> Weapon
Gets the first equipped weapon in the inventory.
Returns:
-
Weapon(Weapon) –The equipped weapon. Returns "Fists" (1 HP damage) if no other weapon is equipped.
get_item
remove_item
to_dict
to_dict() -> dict
Serializes the Inventory to a dictionary, typically in preparation for writing it to persistent storage in a downstream operation.