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…“)
 
 
Zeile 2: Zeile 2:
  
 
  <nowiki>
 
  <nowiki>
 
 
# Important: You need to define a "detect item" graphic
 
# Important: You need to define a "detect item" graphic
 
# At least one of this needs to be in your backpack.
 
# At least one of this needs to be in your backpack.
Zeile 17: Zeile 16:
 
packanimal_gids = [0x0124, 0x0123]
 
packanimal_gids = [0x0124, 0x0123]
 
shovel_gid = 0x0f39
 
shovel_gid = 0x0f39
mining_range = 2
 
 
tile_marking_hue = 34
 
tile_marking_hue = 34
active_route = "bronze"
+
active_route = "kohle"
 
max_tile_yield = 9 # 3 for clay
 
max_tile_yield = 9 # 3 for clay
  
minable_tile_graphics = list(range(1300, 1400)) + list(range(15830, 15860)) + [3333, 12877, 12878]
+
minable_graphics = list(range(1300, 1400)) + list(range(15830, 15860)) + [3333, 12877, 12878]
 
ore_gid = 0x19b9
 
ore_gid = 0x19b9
 
clay_gid = 7145
 
clay_gid = 7145
Zeile 30: Zeile 28:
 
     "fail" : ["Ihr konntet kein verwertbares Erz gewinnen.", "Ihr findet keinen verwertbaren ", "I am already doing something else."],
 
     "fail" : ["Ihr konntet kein verwertbares Erz gewinnen.", "Ihr findet keinen verwertbaren ", "I am already doing something else."],
 
     "success": ["Ihr legt etwas ", ],
 
     "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."]
+
     "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.", "Hier gibt es nichts zu holen."]
 
}
 
}
 
pack_full_message = "Euer Tier kann ein solches Gewicht nicht tragen."
 
pack_full_message = "Euer Tier kann ein solches Gewicht nicht tragen."
Zeile 39: Zeile 37:
 
     for waypoint in waypoints[active_route]:
 
     for waypoint in waypoints[active_route]:
 
         API.SysMsg(f"Pathfind: {waypoint[0]}, {waypoint[1]}", 33)
 
         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)
 
         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 field in get_minable_fields():
             for y in range(mining_range * -1, mining_range + 1):
+
             yield_count = 0
                yield_count = 0
+
            mining_result = -1
                while True:
+
            while mining_result != 2 and yield_count < max_tile_yield:
                    API.Pause(0.01)
+
                API.Pause(0.01)
                    mining_result = mine(x, y, waypoint[2])
+
                mining_result = mine(field)
                    if API.Player.WeightMax < API.Player.Weight + 15:
+
                if API.Player.WeightMax < API.Player.Weight + 10:
                        move_ore_to_packanimal(packis)
+
                    move_ore_to_packanimal(packis)
 +
                if mining_result == 1:
 +
                    yield_count += 1
 +
                    API.SysMsg(f"Yield: {yield_count}", 33)
 +
                mine_crystal()
  
                    if mining_result == 1:
+
            API.MarkTile(field.X, field.Y, tile_marking_hue, API.GetMap())
                        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)
 
     move_ore_to_packanimal(packis)
Zeile 67: Zeile 60:
 
     animal_serials = get_animal_serials()
 
     animal_serials = get_animal_serials()
 
     for packi_serial in animal_serials:
 
     for packi_serial in animal_serials:
 +
        container_id = detect_packi_container_id(packi_serial)
 
         packis[packi_serial] = {
 
         packis[packi_serial] = {
             "container": detect_packi_container_id(packi_serial),
+
             "container": container_id,
 
             "is_full": False
 
             "is_full": False
 
         }
 
         }
 +
        API.SysMsg(f"Packi: {packi_serial}, Backpack: {container_id}", 33)
 
     return packis
 
     return packis
  
Zeile 91: Zeile 86:
 
         for mob in mobiles:
 
         for mob in mobiles:
 
             if mob.Graphic in packanimal_gids:
 
             if mob.Graphic in packanimal_gids:
                 animals.append(mob)
+
                 animals.append(mob.Serial)
                 API.SysMsg(f"Found Packi: {mob.Name}, {mob.Serial}", 33)
+
                 API.SysMsg(f"Found Packi: {mob.Name}", 33)
 
     return animals
 
     return animals
  
Zeile 105: Zeile 100:
 
     API.Msg("all come")
 
     API.Msg("all come")
 
     API.Pause(0.5)
 
     API.Pause(0.5)
 +
    full_count = 0
 
     for pack_serial in packis:
 
     for pack_serial in packis:
 
         if packis[pack_serial]["is_full"]:
 
         if packis[pack_serial]["is_full"]:
 +
            full_count += 1
 
             continue
 
             continue
 +
        if full_count >= len(packis):
 +
            raise Exception("All Packis full!")
 
         items_to_move = []
 
         items_to_move = []
 
         ores = API.FindTypeAll(graphic=ore_gid, container=API.Backpack)
 
         ores = API.FindTypeAll(graphic=ore_gid, container=API.Backpack)
Zeile 121: Zeile 120:
 
             API.QueueMoveItem(item.Serial, packis[pack_serial]["container"])
 
             API.QueueMoveItem(item.Serial, packis[pack_serial]["container"])
 
         API.Pause(0.5)
 
         API.Pause(0.5)
        # TODO: Improve. Don't rely on journal?
 
 
         if API.InJournal(msg=pack_full_message, clearMatches=True):
 
         if API.InJournal(msg=pack_full_message, clearMatches=True):
 
             packis[pack_serial]["is_full"] = True
 
             packis[pack_serial]["is_full"] = True
 +
    API.Msg("all follow me")
  
def mine(x_rel, y_rel, z_abs) -> int:
+
 
 +
def get_shovel():
 +
    shovels = API.FindTypeAll(graphic=shovel_gid)
 +
    if not shovels:
 +
        raise Exception("No shovel not found")
 +
    result = None
 +
    for shovel_stack in shovels:
 +
        if shovel_stack.Amount == 1:
 +
            return shovel_stack
 +
        result = shovel_stack
 +
    return result
 +
 
 +
 
 +
def mine(field) -> int:
 
     """
 
     """
     :param x_rel:
+
     :param x_abs:
 
     :param y_rel:
 
     :param y_rel:
 
     :param z_abs:
 
     :param z_abs:
 
     :return: int: 0 = Fail, 1 = Success, 2 = Empty/Ignore
 
     :return: int: 0 = Fail, 1 = Success, 2 = Empty/Ignore
 
     """
 
     """
    x_abs = API.Player.X - x_rel
+
     shovel = get_shovel()
    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.UseObject(shovel.Serial)
 
     API.WaitForTarget()
 
     API.WaitForTarget()
     API.Target(x_abs, y_abs, z_abs, graphic=field.Graphic)
+
     API.Target(field.X, field.Y, field.Z, graphic=field.Graphic)
  
 
     while True:
 
     while True:
Zeile 159: Zeile 158:
 
             return 2
 
             return 2
  
def get_minable_field(x, y):
+
def get_minable_fields():
    fields = API.GetStaticsAt(x,y) or [API.GetTile(x, y)]
+
    minable_fields = []
    if not fields:
+
    fields = []
        return None
+
    for x in range(-2, 3):
 +
        for y in range(-2, 3):
 +
            x_abs = x + API.Player.X
 +
            y_abs = y + API.Player.Y
 +
            statics = API.GetStaticsAt(x_abs, y_abs)
 +
            tile = API.GetTile(x_abs, y_abs)
 +
            if statics:
 +
                fields.extend(statics)
 +
            if tile:
 +
                fields.append(tile)
 +
 
 
     for field in fields:
 
     for field in fields:
         if int(field.Graphic) in minable_tile_graphics and field.Hue != tile_marking_hue:
+
         if int(field.Graphic) in minable_graphics and field.Hue != tile_marking_hue:
             return field
+
             minable_fields.append(field)
        API.SysMsg(f"No match: {field.Graphic} - {field.X},{field.Y},{field.Z}", 33)
+
     return minable_fields
     return None
+
  
 
waypoints = {
 
waypoints = {

Aktuelle Version vom 19. Oktober 2025, 22:44 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
tile_marking_hue = 34
active_route = "kohle"
max_tile_yield = 9 # 3 for clay

minable_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.", "Hier gibt es nichts zu holen."]
}
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.Pathfind(x=waypoint[0], y=waypoint[1], z=waypoint[2], distance=0, wait=True, timeout=20)
        for field in get_minable_fields():
            yield_count = 0
            mining_result = -1
            while mining_result != 2 and yield_count < max_tile_yield:
                API.Pause(0.01)
                mining_result = mine(field)
                if API.Player.WeightMax < API.Player.Weight + 10:
                    move_ore_to_packanimal(packis)
                if mining_result == 1:
                    yield_count += 1
                    API.SysMsg(f"Yield: {yield_count}", 33)
                mine_crystal()

            API.MarkTile(field.X, field.Y, tile_marking_hue, API.GetMap())

    move_ore_to_packanimal(packis)

def detect_pack_animals():
    API.Pause(1)
    packis = {}
    animal_serials = get_animal_serials()
    for packi_serial in animal_serials:
        container_id = detect_packi_container_id(packi_serial)
        packis[packi_serial] = {
            "container": container_id,
            "is_full": False
        }
        API.SysMsg(f"Packi: {packi_serial}, Backpack: {container_id}", 33)
    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.Serial)
                API.SysMsg(f"Found Packi: {mob.Name}", 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)
    full_count = 0
    for pack_serial in packis:
        if packis[pack_serial]["is_full"]:
            full_count += 1
            continue
        if full_count >= len(packis):
            raise Exception("All Packis full!")
        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)
        if API.InJournal(msg=pack_full_message, clearMatches=True):
            packis[pack_serial]["is_full"] = True
    API.Msg("all follow me")


def get_shovel():
    shovels = API.FindTypeAll(graphic=shovel_gid)
    if not shovels:
        raise Exception("No shovel not found")
    result = None
    for shovel_stack in shovels:
        if shovel_stack.Amount == 1:
            return shovel_stack
        result = shovel_stack
    return result


def mine(field) -> int:
    """
    :param x_abs:
    :param y_rel:
    :param z_abs:
    :return: int: 0 = Fail, 1 = Success, 2 = Empty/Ignore
    """
    shovel = get_shovel()
    API.UseObject(shovel.Serial)
    API.WaitForTarget()
    API.Target(field.X, field.Y, field.Z, 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_fields():
    minable_fields = []
    fields = []
    for x in range(-2, 3):
        for y in range(-2, 3):
            x_abs = x + API.Player.X
            y_abs = y + API.Player.Y
            statics = API.GetStaticsAt(x_abs, y_abs)
            tile = API.GetTile(x_abs, y_abs)
            if statics:
                fields.extend(statics)
            if tile:
                fields.append(tile)

    for field in fields:
        if int(field.Graphic) in minable_graphics and field.Hue != tile_marking_hue:
            minable_fields.append(field)
    return minable_fields

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()