TazUO Miningscript: Unterschied zwischen den Versionen

Aus UO-Sigena Wiki
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „Dieses Script ist für TazUO Legion Scripts (Python). Aktuell sind Routen für die Kohle-, Kupfer und Bronzemine eingetragen, sowie für ein kleine…“)
(kein Unterschied)

Version vom 18. Oktober 2025, 21:39 Uhr

Dieses Script ist für TazUO Legion Scripts (Python). Aktuell sind Routen für die Kohle-, Kupfer und Bronzemine eingetragen, sowie für ein kleines Lehmfeld.


# Important: You need to define a "detect item" graphic
# At least one of this needs to be in your backpack.
# It is used to detect the container ID of your pack animal.
# Said item must only exist directly in your main backpack.
# This is due to odd pack animal container handling on the Sigena freeshard.
# TODO: Count successful minings per tile to avoid "useless mines" to get the empty message
# TODO: max count clay: 3, ore: 9
import API

food_gid = 0x1728
#detect_item_gid = 0xeed # Gold / Kristall
detect_item_gid = 3617 # Bandage
packanimal_gids = [0x0124, 0x0123]
shovel_gid = 0x0f39
mining_range = 2
tile_marking_hue = 34
active_route = "bronze"
max_tile_yield = 9 # 3 for clay

minable_tile_graphics = list(range(1300, 1400)) + list(range(15830, 15860)) + [3333, 12877, 12878]
ore_gid = 0x19b9
clay_gid = 7145
crystal_gid = 0x2747

mining_messages = {
    "fail" : ["Ihr konntet kein verwertbares Erz gewinnen.", "Ihr findet keinen verwertbaren ", "I am already doing something else."],
    "success": ["Ihr legt etwas ", ],
    "empty": ["Hier gibt es kein Erz mehr abzubauen.", "Hier kann kein sand mehr abgebaut werden.", "Hier ist nichts zu holen.", "ihr eine Spitzhacke.", "Hier kann kein clay mehr abgebaut werden."]
}
pack_full_message = "Euer Tier kann ein solches Gewicht nicht tragen."

def main():
    packis = detect_pack_animals()
    move_ore_to_packanimal(packis)
    for waypoint in waypoints[active_route]:
        API.SysMsg(f"Pathfind: {waypoint[0]}, {waypoint[1]}", 33)
        API.Msg("all follow me")
        API.Pathfind(x=waypoint[0], y=waypoint[1], z=waypoint[2], distance=0, wait=True, timeout=20)
        for x in range(mining_range * -1, mining_range + 1):
            for y in range(mining_range * -1, mining_range + 1):
                yield_count = 0
                while True:
                    API.Pause(0.01)
                    mining_result = mine(x, y, waypoint[2])
                    if API.Player.WeightMax < API.Player.Weight + 15:
                        move_ore_to_packanimal(packis)

                    if mining_result == 1:
                        yield_count += 1
                        API.SysMsg(f"Yield: {yield_count}", 33)

                    mine_crystal()

                    if mining_result == 2 or yield_count >= max_tile_yield:
                        API.MarkTile(waypoint[0] + x, waypoint[1] + y, tile_marking_hue, API.GetMap())
                        break

    move_ore_to_packanimal(packis)

def detect_pack_animals():
    API.Pause(1)
    packis = {}
    animal_serials = get_animal_serials()
    for packi_serial in animal_serials:
        packis[packi_serial] = {
            "container": detect_packi_container_id(packi_serial),
            "is_full": False
        }
    return packis

def detect_packi_container_id(packi_serial) -> int:
    API.UseObject(packi_serial)
    detect_item = API.FindType(detect_item_gid, API.Backpack)
    API.QueueMoveItem(detect_item, packi_serial, 1)
    API.Pause(0.5)
    items = API.FindTypeAll(detect_item_gid)
    for item in items:
        if item.Container != API.Backpack:
            API.QueueMoveItem(item, API.Backpack)
            return item.Container
    return 0

def get_animal_serials():
    animals = []
    mobiles = API.GetAllMobiles()
    if mobiles:
        for mob in mobiles:
            if mob.Graphic in packanimal_gids:
                animals.append(mob)
                API.SysMsg(f"Found Packi: {mob.Name}, {mob.Serial}", 33)
    return animals

def mine_crystal():
    crystal = API.FindType(graphic=crystal_gid, range=0)
    if crystal:
        API.UseObject(crystal.Serial)
        while not API.InJournal("Ihr legt den Kristall in Euren Rucksack.", clearMatches=True):
            API.Pause(0.1)

def move_ore_to_packanimal(packis):
    API.Msg("all come")
    API.Pause(0.5)
    for pack_serial in packis:
        if packis[pack_serial]["is_full"]:
            continue
        items_to_move = []
        ores = API.FindTypeAll(graphic=ore_gid, container=API.Backpack)
        if ores:
            items_to_move += ores
        clay = API.FindTypeAll(graphic=clay_gid, container=API.Backpack)
        if clay:
            items_to_move += clay

        API.UseObject(pack_serial)
        API.Pause(0.1)
        for item in items_to_move:
            API.QueueMoveItem(item.Serial, packis[pack_serial]["container"])
        API.Pause(0.5)
        # TODO: Improve. Don't rely on journal?
        if API.InJournal(msg=pack_full_message, clearMatches=True):
            packis[pack_serial]["is_full"] = True

def mine(x_rel, y_rel, z_abs) -> int:
    """
    :param x_rel:
    :param y_rel:
    :param z_abs:
    :return: int: 0 = Fail, 1 = Success, 2 = Empty/Ignore
    """
    x_abs = API.Player.X - x_rel
    y_abs = API.Player.Y - y_rel
    shovel = API.FindType(graphic=shovel_gid, container=API.Backpack)
    if not shovel:
        # Will pick from containers other than backpack
        shovel = API.FindType(graphic=shovel_gid)
    if not shovel:
        API.SysMsg("No Shovel Found!", 33)
        API.Stop()

    field = get_minable_field(x_abs, y_abs)
    if not field:
        return 2

    API.UseObject(shovel.Serial)
    API.WaitForTarget()
    API.Target(x_abs, y_abs, z_abs, graphic=field.Graphic)

    while True:
        API.Pause(0.1)
        if API.InJournalAny(msgs=mining_messages["success"], clearMatches=True):
            return 1
        if API.InJournalAny(msgs=mining_messages["fail"], clearMatches=True):
            return 0
        if API.InJournalAny(msgs=mining_messages["empty"], clearMatches=True):
            return 2

def get_minable_field(x, y):
    fields = API.GetStaticsAt(x,y) or [API.GetTile(x, y)]
    if not fields:
        return None
    for field in fields:
        if int(field.Graphic) in minable_tile_graphics and field.Hue != tile_marking_hue:
            return field
        API.SysMsg(f"No match: {field.Graphic} - {field.X},{field.Y},{field.Z}", 33)
    return None

waypoints = {
    "kupfer": [
        [2025, 1304, 0],
        [2020, 1304, 0],
        [2018, 1300, 0],
        [2016, 1297, 0],
        [2011, 1297, 0],
        [2011, 1301, 0],
        [2007, 1301, 0],
        [2007, 1306, 0],
        [2012, 1311, 0],
        [2017, 1306, 0],
        [2020, 1306, 0],
    ],
    "kohle": [
        [5242, 68, -20],
        [5242, 63, -20],
        [5242, 58, -20],
        [5237, 53, -20],
        [5237, 58, -20],
        [5237, 63, -20],
        [5237, 68, -20],
        [5237, 72, -20],
        [5232, 72, -20],
        [5232, 67, -20],
        [5232, 62, -20],
        [5232, 57, -20],
        [5232, 52, -20],
        [5227, 62, -20],
        [5227, 67, -20],
        [5227, 72, -20],
        [5222, 72, -20],
        [5222, 67, -20],
        [5222, 62, -20],
        [5222, 57, -20],
        [5222, 52, -20],
        [5218, 62, -20],
        [5218, 67, -20],
    ],
    "bronze": [
        [1707, 653, 0],
        [1702, 653, 0],
        [1698, 652, 0],
        [1693, 647, 0],
        [1698, 647, 0],
        [1698, 642, 0],
        [1693, 642, 0],
        [1688, 642, 0],
        [1683, 638, 0],
        [1688, 638, 0],
        [1693, 638, 0],
        [1696, 638, 0],
        [1693, 635, 0],
        [1688, 635, 0],
        [1683, 635, 0],
        [1689, 643, 0],# Way down
        [1697, 654, 0],# Way down
        [1699, 658, 0],
        [1703, 658, 0],
        [1703, 663, 0],
        [1699, 663, 0],
        [1699, 668, 0],
        [1703, 668, 0],
        [1704, 672, 0],
        [1699, 672, 0],
        [1706, 675, 0],
        [1696, 675, 0],
        [1691, 675, 0],
        [1691, 680, 0],
        [1688, 680, 0],
        [1696, 680, 0],
        [1701, 680, 0],
        [1706, 680, 0],
        [1706, 684, 0],
        [1701, 684, 0],
        [1696, 684, 0],
        [1691, 684, 0],
        [1691, 687, 0],
        [1696, 689, 0],
        [1701, 689, 0],
    ],
    "clay1": [
        [1164, 1324, 0],
        [1164, 1319, 0],
        [1169, 1319, 0],
        [1169, 1314, 0],
        [1164, 1314, 0],
        [1164, 1309, 0],
        [1169, 1309, 0],
        [1169, 1304, 0],
        [1164, 1304, 0],
        [1164, 1299, 0],
        [1169, 1299, 0],
        [1159, 1304, 0],
        [1159, 1299, 0],
        [1159, 1309, 0],
        [1159, 1314, 0],
        [1159, 1319, 0],
        [1159, 1324, 0],
        [1154, 1324, 0],
        [1154, 1319, 0],
        [1154, 1314, 0],
        [1154, 1309, 0],
        [1154, 1304, 0],
        [1152, 1304, 0],
        [1152, 1309, 0],
    ]
}

main()