Crafting Examples

Basic Crafting

Craft items using resources:

from artifacts import ArtifactsClient

with ArtifactsClient(token="your_token") as client:
    char = client.character("Crafter")

    # Move to workshop
    char.move(x=1, y=1)  # Example: weaponcrafting workshop

    # Craft an item
    result = char.craft(code="wooden_sword", quantity=1)

    print(f"Crafted: {result.details.items[0].code}")
    print(f"XP gained: {result.details.xp}")

Gathering and Crafting Loop

Gather resources and craft items:

from artifacts import ArtifactsClient, wait_for_cooldown

with ArtifactsClient(token="your_token") as client:
    char = client.character("Blacksmith")

    # Define locations
    copper_rocks = (2, 0)
    workshop = (1, 1)

    for i in range(5):
        # Gather copper
        print("Gathering copper...")
        char.move(x=copper_rocks[0], y=copper_rocks[1])
        result = char.gather()
        wait_for_cooldown(result.data.cooldown_expiration)

        # Return to workshop
        char.move(x=workshop[0], y=workshop[1])
        wait_for_cooldown(result.data.cooldown_expiration)

        # Craft items
        print("Crafting...")
        result = char.craft(code="copper_dagger", quantity=1)
        print(f"Crafted: {result.details.items[0].code}")

        wait_for_cooldown(result.data.cooldown_expiration)

Check Crafting Requirements

View what’s needed to craft an item:

from artifacts import ArtifactsClient

with ArtifactsClient(token="your_token") as client:
    # Get item details
    item = client.get_item(code="iron_sword")

    print(f"Item: {item.name}")
    print(f"Crafting skill: {item.craft.skill}")
    print(f"Required level: {item.craft.level}")

    print("Materials needed:")
    for material in item.craft.items:
        print(f"  {material.quantity}x {material.code}")

Recipe Discovery

Check available recipes for your level:

from artifacts import ArtifactsClient

with ArtifactsClient(token="your_token") as client:
    char = client.character("Crafter")
    char_data = char.get()

    # Get all items
    items = client.get_all_items()

    # Filter craftable items
    print(f"Recipes for {char_data.weaponcrafting_level} Weaponcrafting:")
    for item in items.data:
        if (item.craft and
            item.craft.skill == "weaponcrafting" and
            item.craft.level <= char_data.weaponcrafting_level):
            print(f"  - {item.name} (Level {item.craft.level})")

Mass Production

Craft multiple items efficiently:

from artifacts import ArtifactsClient, wait_for_cooldown

with ArtifactsClient(token="your_token") as client:
    char = client.character("MassProducer")

    # Move to workshop
    char.move(x=1, y=1)

    # Craft in batches
    items_to_craft = [
        ("wooden_sword", 5),
        ("wooden_shield", 3),
        ("leather_armor", 2)
    ]

    for item_code, quantity in items_to_craft:
        print(f"Crafting {quantity}x {item_code}...")
        result = char.craft(code=item_code, quantity=quantity)

        total_xp = sum(item.xp for item in result.details.items) if result.details.items else 0
        print(f"  Crafted! Total XP: {total_xp}")

        wait_for_cooldown(result.data.cooldown_expiration)

Recycling Items

Break down items for materials:

from artifacts import ArtifactsClient

with ArtifactsClient(token="your_token") as client:
    char = client.character("Recycler")

    # Move to workshop
    char.move(x=1, y=5)  # Example: recycling workshop

    # Recycle an item
    result = char.recycle(code="wooden_sword", quantity=1)

    print("Recycled items:")
    if result.details.items:
        for item in result.details.items:
            print(f"  Received: {item.quantity}x {item.code}")

Multi-Workshop Crafting

Use multiple workshops for different items:

from artifacts import AsyncArtifactsClient
import asyncio

async def craft_at_workshop(char, location, item_code, quantity):
    await char.move(x=location[0], y=location[1])
    result = await char.craft(code=item_code, quantity=quantity)
    print(f"Crafted {quantity}x {item_code}")
    return result

async def main():
    async with AsyncArtifactsClient(token="your_token") as client:
        weaponsmith = client.character("Weaponsmith")
        armorsmith = client.character("Armorsmith")
        jewelcrafter = client.character("Jewelcrafter")

        # Craft in parallel with different characters
        await asyncio.gather(
            craft_at_workshop(weaponsmith, (1, 1), "iron_sword", 3),
            craft_at_workshop(armorsmith, (2, 1), "iron_armor", 2),
            craft_at_workshop(jewelcrafter, (3, 1), "ruby_ring", 1)
        )

asyncio.run(main())