Combat Examples

Fighting Monsters

Basic monster combat:

from artifacts import ArtifactsClient

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

    # Move to monster location
    char.move(x=0, y=1)  # Example: chicken location

    # Fight the monster
    result = char.fight()

    # Check result
    print(f"Fight result: {result.fight.result}")  # "win" or "lose"
    print(f"XP gained: {result.fight.xp}")
    print(f"Gold gained: {result.fight.gold}")

    # Check drops
    if result.fight.drops:
        for drop in result.fight.drops:
            print(f"Dropped: {drop.quantity}x {drop.code}")

Combat Loop

Fight monsters continuously with automatic cooldown handling:

from artifacts import ArtifactsClient, wait_for_cooldown
import time

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

    # Move to monster location
    char.move(x=0, y=1)

    # Fight 10 times
    for i in range(10):
        result = char.fight()

        print(f"Fight {i+1}: {result.fight.result}")
        print(f"  XP: +{result.fight.xp}, Gold: +{result.fight.gold}")

        # Wait for cooldown before next fight
        if result.data.cooldown_expiration:
            wait_for_cooldown(result.data.cooldown_expiration)

Multi-Character Combat

Run multiple characters fighting simultaneously:

from artifacts import AsyncArtifactsClient
import asyncio

async def fight_loop(client, char_name, location):
    char = client.character(char_name)
    await char.move(x=location[0], y=location[1])

    for i in range(5):
        result = await char.fight()
        print(f"{char_name} fight {i+1}: {result.fight.result}")

        # Async sleep for cooldown
        if result.data.cooldown > 0:
            await asyncio.sleep(result.data.cooldown)

async def main():
    async with AsyncArtifactsClient(token="your_token") as client:
        # Fight with multiple characters in parallel
        await asyncio.gather(
            fight_loop(client, "Fighter1", (0, 1)),
            fight_loop(client, "Fighter2", (0, 1)),
            fight_loop(client, "Mage1", (2, 3))
        )

asyncio.run(main())

Equipment Management

Equip weapons and armor for combat:

from artifacts import ArtifactsClient

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

    # Equip a weapon
    char.equip(code="wooden_sword", slot="weapon")
    print("Equipped wooden sword")

    # Equip armor
    char.equip(code="leather_armor", slot="body_armor")
    print("Equipped leather armor")

    # Unequip an item
    char.unequip(slot="weapon")
    print("Unequipped weapon")

Healing After Combat

Use consumables to restore HP:

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

    # Check HP
    char_data = char.get()
    print(f"HP: {char_data.hp}/{char_data.max_hp}")

    # Rest to restore HP (if at spawn point)
    if char_data.hp < char_data.max_hp:
        result = char.rest()
        char_data = result.data
        print(f"Rested - HP: {char_data.hp}/{char_data.max_hp}")

Boss Farming

Farm a boss with automatic retry on defeat:

from artifacts import ArtifactsClient, wait_for_cooldown

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

    # Move to boss location
    char.move(x=5, y=5)  # Example boss location

    wins = 0
    attempts = 0

    while wins < 10:
        result = char.fight()
        attempts += 1

        if result.fight.result == "win":
            wins += 1
            print(f"Victory {wins}/10!")

            # Check for rare drops
            if result.fight.drops:
                for drop in result.fight.drops:
                    print(f"  DROP: {drop.quantity}x {drop.code}")
        else:
            print(f"Defeat... (Attempt {attempts})")

        # Wait for cooldown
        if result.data.cooldown_expiration:
            wait_for_cooldown(result.data.cooldown_expiration)