Pārlūkot izejas kodu

stop if titan tank is dead

Richard Köhl 1 gadu atpakaļ
vecāks
revīzija
ac2878c59f
1 mainītis faili ar 55 papildinājumiem un 39 dzēšanām
  1. 55 39
      dungeon.py

+ 55 - 39
dungeon.py

@@ -64,44 +64,60 @@ def read_screen():
 print("watching the screen...")
 is_mixed = False
 while True:
-    capture_current_screen()
-
-    name, locations = look_for_templates(templates)
-    if name is not None:
-        if name in ["to_battle", "auto_battle", "ok", "lock", "collect"]:
-            if name in ["auto_battle"]:
-                if is_mixed:
-                    moloch = first_template(tpl_moloch)
-                    if moloch and moloch[1] < 1000 and low_health(moloch, "moloch"):
-                        angus = first_template(tpl_angus2)
-                        tap(angus)
+    try:
+        capture_current_screen()
+
+        name, locations = look_for_templates(templates)
+        if name is not None:
+            if name in ["to_battle", "auto_battle", "ok", "lock", "collect"]:
+                if name in ["auto_battle"]:
+                    if is_mixed:
+                        moloch = first_template(tpl_moloch)
+                        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])
+                            else:
+                                print(
+                                    "######### seems like angus is dead already. stopping"
+                                )
+                                break
+                        else:
+                            angus = first_template(tpl_angus)
+                            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])
+                                else:
+                                    print(
+                                        "######### seems like moloch is dead already. stopping"
+                                    )
+                                    break
                         time.sleep(0.5)
-                        tap(angus[0] + 500, angus[1])
+                tap(*locations[0])
+                if name in ["auto_battle", "ok"]:
+                    time.sleep(1.5)
+            if name == "attack":
+                if len(locations) == 1:
+                    element = first_template(tpl_mixed)
+                    is_mixed = element is not None
+                    tap(*locations[0])
+                elif len(locations) == 2:
+                    element = first_template(tpl_mixed)
+                    if element:
+                        is_mixed = True
                     else:
-                        angus = first_template(tpl_angus)
-                        if angus and angus[1] < 1000 and low_health(angus, "angus"):
-                            moloch = first_template(tpl_moloch2)
-                            tap(moloch)
-                            time.sleep(0.5)
-                            tap(moloch[0] - 500, moloch[1])
-                    time.sleep(0.5)
-            tap(*locations[0])
-            if name in ["auto_battle", "ok"]:
-                time.sleep(1.5)
-        if name == "attack" and len(locations) == 1:
-            element = first_template(tpl_mixed)
-            is_mixed = element is not None
-            tap(*locations[0])
-        if name == "attack" and len(locations) == 2:
-            element = first_template(tpl_mixed)
-            if element:
-                is_mixed = True
-            else:
-                is_mixed = False
-                element = first_template(tpl_water)
-                if element is None:
-                    element = first_template(tpl_earth)
-
-            tap(element[0], locations[0][1])
-
-    print("...")
+                        is_mixed = False
+                        element = first_template(tpl_water)
+                        if element is None:
+                            element = first_template(tpl_earth)
+
+                    tap(element[0], locations[0][1])
+
+        print("...")
+    except Exception as e:
+        print(f"error: {e}")