Bladeren bron

optimize sleep times, add action output

Richard Köhl 1 jaar geleden
bovenliggende
commit
2e63f5379c
2 gewijzigde bestanden met toevoegingen van 27 en 13 verwijderingen
  1. 25 11
      dungeon.py
  2. 2 2
      helper.py

+ 25 - 11
dungeon.py

@@ -2,7 +2,7 @@ import cv2
 import time
 import numpy as np
 from helper import (
-    tap,
+    tap as tap_helper,
     look_for_templates,
     first_template,
     capture_current_screen,
@@ -62,6 +62,22 @@ def read_screen():
     return cv2.imdecode(image_data, cv2.IMREAD_COLOR)
 
 
+def tap(name, x, y=None):
+    sleep = 0.5
+    if name in ["ok"]:
+        sleep = 2
+    elif name in ["collect"]:
+        sleep = 5
+    elif name in ["lock"]:
+        sleep = 2
+    elif name in ["remove angus", "remove moloch"]:
+        sleep = 1
+
+    text = f"- {name} ({sleep})"
+    tap_helper(x, y, text)
+    time.sleep(sleep)
+
+
 print("watching the screen...")
 is_mixed = False
 while True:
@@ -71,7 +87,7 @@ while True:
         name, locations = look_for_templates(templates)
         if name is not None:
             if name in ["to_battle", "ok", "lock", "collect"]:
-                tap(*locations[0])
+                tap(name, *locations[0])
                 continue
             if name in ["auto_battle"]:
                 dead = first_template(tpl_dead)
@@ -83,9 +99,8 @@ while True:
                     if moloch and moloch[1] < 1000 and low_health(moloch, "moloch"):
                         angus = first_template(tpl_angus2)
                         if angus:
-                            tap(angus)
-                            time.sleep(0.5)
-                            tap(angus[0] + 500, angus[1])
+                            tap("remove angus", angus)
+                            tap("add moloch", angus[0] + 500, angus[1])
                         else:
                             print(
                                 "######### seems like angus is dead already. stopping"
@@ -96,21 +111,20 @@ while True:
                         if angus and angus[1] < 1000 and low_health(angus, "angus"):
                             moloch = first_template(tpl_moloch2)
                             if moloch:
-                                tap(moloch)
-                                time.sleep(0.5)
-                                tap(moloch[0] - 500, moloch[1])
+                                tap("remove moloch", moloch)
+                                tap("add angus", moloch[0] - 500, moloch[1])
                             else:
                                 print(
                                     "######### seems like moloch is dead already. stopping"
                                 )
                                 break
-                tap(*locations[0])
+                tap(name, *locations[0])
                 continue
             if name == "attack":
                 if len(locations) == 1:
                     element = first_template(tpl_mixed)
                     is_mixed = element is not None
-                    tap(*locations[0])
+                    tap(name, *locations[0])
                     continue
 
                 if len(locations) == 2:
@@ -123,7 +137,7 @@ while True:
                         if element is None:
                             element = first_template(tpl_earth)
 
-                    tap(element[0], locations[0][1])
+                    tap(name, element[0], locations[0][1])
                     continue
         print("...")
     except Exception as e:

+ 2 - 2
helper.py

@@ -105,7 +105,7 @@ def call_device_shell(action, timeout=10):
         thread.join()
 
 
-def tap(x, y=None):
+def tap(x, y=None, text=None):
     # Check if x is an int
     if isinstance(x, int):
         if not isinstance(y, int):
@@ -122,7 +122,7 @@ def tap(x, y=None):
 
     # Assuming 'device' is a previously defined object with a 'shell' method
     action = f"input tap {location}"
-    print(action)
+    print(f"{action} {text}")
     call_device_shell(action, timeout=5)