Ejemplo n.º 1
0
def use_macro(args):
    """Uses the selected macro on a set amt of cycles.
    Args:
        macro: Comes from read_macro()
        flags: List of options like repairing, and collectables
    """
    inputs = input_handler.craft(args)  #inputs has macro amt opt
    macro = inputs["macro"]
    options = {"-repair": False, "-food": False, "-pot": False}
    for f in inputs["opt"]:
        if options.get(f, "") != "":
            options[f] = True
    print(f"Starting {inputs['amt']} crafts:")
    proc = Process()
    select = "{VK_NUMPAD0}"
    steps = len(macro["macro"]["keys"])
    repair_counter = 0
    # Can adjust sleeps according to lag
    sleeps = {"step1": 0.5, "step2": 1, "input": 2.5}
    est = h.get_time_estimation(macro, inputs["amt"], sleeps)
    print(f" > Time estimation: {est:.2f} minutes.")
    for i in range(inputs["amt"]):
        print(f" > Craft #{i + 1}")
        for _ in range(4):
            proc.press_key(select)
        sleep(1)
        for step in range(steps):
            wait = macro["macro"]["wait"][step]
            key = macro["macro"]["keys"][step]
            print(f"   > Pressing {key}")
            sleep(sleeps["step1"])
            proc.press_key(key)
            print(f"   > Waiting {wait}s")
            sleep(wait)
            sleep(sleeps["step2"])
        if repair_counter > s.REPAIR_COUNTER:
            if options["-repair"] == True:
                print("Self repairing...")
                opt_repair(proc)
            repair_counter = 0
        repair_counter += 1
        sleep(sleeps["input"])
    print("Crafts finished.")
    notify.finished()
def use_macro(macro: dict, amt: int, flags: list):
    """Uses the selected macro on a set amt of cycles.
    macro returns None if there is no macro read.
    macro format: check parse_macro() docstring.
    Args:
        macro: Comes from read_macro()
    """
    options = {"-collect": False}
    for f in flags:
        if options.get(f, "") != "":
            options[f] = True
    if not macro:
        print("ERROR: Macro name does not exist your profiles")
        quit()
    print(f"Starting {amt} crafts:")
    proc = Process()
    select = "{VK_NUMPAD0}"
    for i in range(amt):
        print(f" > Craft #{i}")
        for i in range(4):
            proc.press_key(select)
        sleep(0.5)
        for step in macro:
            wait = macro[step]["wait"]
            key = macro[step]["key"]
            print(f"   > Pressing {key}")
            proc.press_key(key)
            print(f"   > Waiting {wait}s")
            sleep(wait)
        if options["-collect"] == True:
            print(f"   > Collectable Menu")
            for i in range(4):
                proc.press_key(select)
            sleep(2.5)
    print("Crafts finished.")