Переглянути джерело

fix moloch and angus recognition, add STOP_AT_FIRST_DEATH env

Richard Köhl 1 рік тому
батько
коміт
8422efeb58
4 змінених файлів з 25 додано та 6 видалено
  1. 25 6
      dungeon.py
  2. BIN
      templates/dungeon/angus.png
  3. BIN
      templates/dungeon/fire.png
  4. BIN
      templates/dungeon/moloch.png

+ 25 - 6
dungeon.py

@@ -1,4 +1,5 @@
 import cv2
+import os
 import time
 import numpy as np
 from helper import (
@@ -9,6 +10,8 @@ from helper import (
     get_current_screen,
 )
 
+fire_vs_earth = os.getenv("FIRE_VS_EARTH", "earth").lower()
+
 # templates
 templates = {
     "to_battle": cv2.imread("templates/dungeon/to_battle.png"),
@@ -22,6 +25,7 @@ templates = {
 tpl_mixed = cv2.imread("templates/dungeon/mixed.png")
 tpl_water = cv2.imread("templates/dungeon/water.png")
 tpl_earth = cv2.imread("templates/dungeon/earth.png")
+tpl_fire = cv2.imread("templates/dungeon/fire.png")
 tpl_angus = cv2.imread("templates/dungeon/angus.png")
 tpl_moloch = cv2.imread("templates/dungeon/moloch.png")
 tpl_angus2 = cv2.imread("templates/dungeon/angus2.png")
@@ -32,13 +36,13 @@ tpl_dead = cv2.imread("templates/dungeon/dead.png")
 def low_health(element, name):
     left = element[0] - 113
     right = element[0] + 108
-    top = element[1] + 158
+    top = element[1] + 138
     bottom = top + 11
 
     screen = read_screen()
 
     health_bar = screen[top:bottom, left:right]
-    cv2.imwrite("test/health_bar.png", health_bar)
+    # cv2.imwrite("test/health_bar.png", health_bar)
 
     health_bar_hsv = cv2.cvtColor(health_bar, cv2.COLOR_BGR2HSV)
     green_lower = np.array([40, 40, 40])  # Lower end of green in HSV
@@ -90,13 +94,20 @@ while True:
                 tap(name, *locations[0])
                 continue
             if name in ["auto_battle"]:
-                dead = first_template(tpl_dead)
+                dead = os.getenv(
+                    "STOP_AT_FIRST_DEATH", "False"
+                ).lower() == "true" and first_template(tpl_dead)
                 if dead:
                     print("++++++++ at least one titan is dead. stopping")
                     break
                 if is_mixed:
                     moloch = first_template(tpl_moloch)
-                    if moloch and moloch[1] < 1000 and low_health(moloch, "moloch"):
+                    if (
+                        moloch
+                        and moloch[1] > 450
+                        and moloch[1] < 1350
+                        and low_health(moloch, "moloch")
+                    ):
                         angus = first_template(tpl_angus2)
                         if angus:
                             tap("remove angus", angus)
@@ -108,7 +119,12 @@ while True:
                             break
                     else:
                         angus = first_template(tpl_angus)
-                        if angus and angus[1] < 1000 and low_health(angus, "angus"):
+                        if (
+                            angus
+                            and moloch[1] > 450
+                            and angus[1] < 1350
+                            and low_health(angus, "angus")
+                        ):
                             moloch = first_template(tpl_moloch2)
                             if moloch:
                                 tap("remove moloch", moloch)
@@ -135,7 +151,10 @@ while True:
                         is_mixed = False
                         element = first_template(tpl_water)
                         if element is None:
-                            element = first_template(tpl_earth)
+                            if fire_vs_earth == "earth":
+                                element = first_template(tpl_earth)
+                            else:
+                                element = first_template(tpl_fire)
 
                     tap(name, element[0], locations[0][1])
                     continue

BIN
templates/dungeon/angus.png


BIN
templates/dungeon/fire.png


BIN
templates/dungeon/moloch.png