World¶
Items¶
Items
Here are defined abstract classes for items, tools and item-stacks
-
class
Item(item_id: int, name: str, required_tools: Optional[list] = None)¶ Bases:
objectItem are to represent objects that could be present in an inventory
-
class
ItemStack(item: crafting.world.items.Item, size: int = 1)¶ Bases:
crafting.world.items.ItemItemStack are to represent stackable objects that could be present in an inventory.
-
required_tools¶ List of tools that can be used to gather the item. If None (Default), the item can be gathered without requirement.
-
-
class
Tool(item_id: int, name: str, required_tools: Optional[list] = None)¶ Bases:
crafting.world.items.ItemTool are to represent special usable items.
-
use(item: Optional[crafting.world.items.Item] = None) → List[crafting.world.items.ItemStack]¶ Use the tool on the (optional) given item.
- Parameters
item – Item to use the tool on.
- Returns
The list of found item stacks.
-
Recipes¶
Recipe are to represent transformations of items.
Recipes are initiated using an input-output design but they can also affect and be affected by the Zone in which the craft is done.
-
class
Recipe(recipe_id: int, inputs: Optional[List[crafting.world.items.ItemStack]] = None, outputs: Optional[List[crafting.world.items.ItemStack]] = None, needed_properties: Optional[dict] = None, added_properties: Optional[dict] = None)¶ Bases:
objectRecipe are to represent transformations of items.
Recipes are initiated using an input-output design but they can also affect and be affected by the Zone in which the craft is done.
-
inputs¶ List of consumed items.
- Type
list of
ItemStack
-
outputs¶ List of created items.
- Type
list of
ItemStack
-
has_enought(inventory: crafting.player.inventory.Inventory)¶ Check if the inventory contains the necessary materials
- Parameters
inventory – The inventory to check.
- Returns
True if the inventory has enough materials, False otherwise.
-
has_properties(zone: crafting.world.zones.Zone)¶ Check if the zone has the necessary propreties
- Parameters
zone – The zone to check.
- Returns
True if the zone has the necessary propreties, False otherwise.
-
can_craft(inventory: crafting.player.inventory.Inventory, zone: crafting.world.zones.Zone) → bool¶ Check if the craft can be performed
- Parameters
inventory – Inventory to transform.
zone – Zone in which the crafting is done.
- Returns
True if the craft can be performed, False otherwise.
-
craft(inventory: crafting.player.inventory.Inventory, zone: crafting.world.zones.Zone) → bool¶ Use the recipe using an inventory in a zone
- Parameters
inventory – Inventory to transform.
zone – Zone in which the crafting is done.
- Returns
True if successful, False otherwise
-
World¶
A World stiches together every non-player parts of the environment.
-
class
World(items: List[crafting.world.items.Item], recipes: List[crafting.world.recipes.Recipe], zones: List[crafting.world.zones.Zone], searchable_items: Optional[List[crafting.world.items.Item]] = None, resources_path: Optional[str] = None, font_path: Optional[str] = None)¶ Bases:
objectA crafting World containing items, recipes and zones.
-
action(action_type: str, identification: int) → int¶ Return the action_id from action_type and identification.
-
zone_id_from_observation(observation)¶ Return the player zone from an observation.
-
properties_from_observation(observation)¶ Return the zone proprietes from an observation.
-
get_all_options() → Dict[str, crafting.option.Option]¶ Return a dictionary of handcrafted options to get each item, zone and property.
-
get_requirements_graph() → networkx.classes.digraph.DiGraph¶ Build the world requirements graph.
- Returns
The world requirements graph as a networkx DiGraph.
-
draw_requirements_graph(ax)¶ Draw the requirement graph on a given Axes.
- Parameters
ax – Axes to draw on.
- Returns
The Axes with requirements_graph drawn on it.
-
Zones¶
Zone
Gives an abstract way of doing spacialization. The Zones have special properties for finding or crafting items.
-
class
Zone(zone_id: int, name: str, items: List[crafting.world.items.Item], properties: Optional[dict] = None)¶ Bases:
objectZones are to represent abstract places in the world.
Zone have specific properties that can change how items can be gathered and how craftings are done.
By default
-
items¶ Dictionary associating an item_id with the tools needed to gather it and how efficient it is.
- Type
-
can_search_for(item: crafting.world.items.Item, tool: Optional[crafting.world.items.Tool] = None) → bool¶ Check if the item can be found using a tool
- Parameters
item – The item to look for.
tool – The tool to use in search.
- Returns
True if the item can be found, False otherwise.
-
search_for(item: crafting.world.items.Item, tool: Optional[crafting.world.items.Tool] = None) → List[crafting.world.items.ItemStack]¶ Searches for the given item using a tool
- Parameters
item – The item to look for.
tool – The tool to use.
- Returns
The found item stacks.
-