|
@@ -2,6 +2,7 @@ import cv2
|
|
|
import os
|
|
import os
|
|
|
import time
|
|
import time
|
|
|
import numpy as np
|
|
import numpy as np
|
|
|
|
|
+import random
|
|
|
from helper import (
|
|
from helper import (
|
|
|
tap as tap_helper,
|
|
tap as tap_helper,
|
|
|
look_for_templates,
|
|
look_for_templates,
|
|
@@ -10,7 +11,11 @@ from helper import (
|
|
|
get_current_screen,
|
|
get_current_screen,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-fire_vs_earth = os.getenv("FIRE_VS_EARTH", "earth").lower()
|
|
|
|
|
|
|
+fire_or_earth = os.getenv("FIRE_OR_EARTH", "earth").lower()
|
|
|
|
|
+stop_at_first_death = os.getenv("FIRST_DEATH_STOP", "False").lower() == "true"
|
|
|
|
|
+swap_tank_at_low_health = (
|
|
|
|
|
+ os.getenv("SWAP_TANK_AT_LOW_HEALTH", "False").lower() == "true"
|
|
|
|
|
+)
|
|
|
|
|
|
|
|
# templates
|
|
# templates
|
|
|
templates = {
|
|
templates = {
|
|
@@ -56,7 +61,7 @@ def low_health(element, name):
|
|
|
|
|
|
|
|
print(f"Remaining Health ({name}): {health_percentage:.2f}%")
|
|
print(f"Remaining Health ({name}): {health_percentage:.2f}%")
|
|
|
|
|
|
|
|
- return health_percentage < 60
|
|
|
|
|
|
|
+ return health_percentage < 70
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_screen():
|
|
def read_screen():
|
|
@@ -68,22 +73,23 @@ def read_screen():
|
|
|
|
|
|
|
|
def tap(name, x, y=None):
|
|
def tap(name, x, y=None):
|
|
|
sleep = 0.5
|
|
sleep = 0.5
|
|
|
- if name in ["ok"]:
|
|
|
|
|
|
|
+ if name in ["ok", "lock"]:
|
|
|
sleep = 2
|
|
sleep = 2
|
|
|
elif name in ["collect"]:
|
|
elif name in ["collect"]:
|
|
|
sleep = 5
|
|
sleep = 5
|
|
|
- elif name in ["lock"]:
|
|
|
|
|
- sleep = 2
|
|
|
|
|
elif name in ["remove angus", "remove moloch"]:
|
|
elif name in ["remove angus", "remove moloch"]:
|
|
|
sleep = 1
|
|
sleep = 1
|
|
|
|
|
|
|
|
|
|
+ sleep += random.uniform(0, 0.2)
|
|
|
text = f"- {name} (pause for {sleep}s)"
|
|
text = f"- {name} (pause for {sleep}s)"
|
|
|
- tap_helper(x, y, text)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ tap_helper(x + random.randint(-3, 3), y + random.randint(-3, 3), text)
|
|
|
time.sleep(sleep)
|
|
time.sleep(sleep)
|
|
|
|
|
|
|
|
|
|
|
|
|
print("watching the screen...")
|
|
print("watching the screen...")
|
|
|
is_mixed = False
|
|
is_mixed = False
|
|
|
|
|
+idle_counter = 0
|
|
|
while True:
|
|
while True:
|
|
|
try:
|
|
try:
|
|
|
capture_current_screen()
|
|
capture_current_screen()
|
|
@@ -92,15 +98,14 @@ while True:
|
|
|
if name is not None:
|
|
if name is not None:
|
|
|
if name in ["to_battle", "ok", "lock", "collect"]:
|
|
if name in ["to_battle", "ok", "lock", "collect"]:
|
|
|
tap(name, *locations[0])
|
|
tap(name, *locations[0])
|
|
|
|
|
+ idle_counter = 0
|
|
|
continue
|
|
continue
|
|
|
if name in ["auto_battle"]:
|
|
if name in ["auto_battle"]:
|
|
|
- dead = os.getenv(
|
|
|
|
|
- "STOP_AT_FIRST_DEATH", "False"
|
|
|
|
|
- ).lower() == "true" and first_template(tpl_dead)
|
|
|
|
|
|
|
+ dead = stop_at_first_death and first_template(tpl_dead)
|
|
|
if dead:
|
|
if dead:
|
|
|
print("++++++++ at least one titan is dead. stopping")
|
|
print("++++++++ at least one titan is dead. stopping")
|
|
|
break
|
|
break
|
|
|
- if is_mixed:
|
|
|
|
|
|
|
+ if swap_tank_at_low_health and is_mixed:
|
|
|
moloch = first_template(tpl_moloch)
|
|
moloch = first_template(tpl_moloch)
|
|
|
if (
|
|
if (
|
|
|
moloch
|
|
moloch
|
|
@@ -135,6 +140,7 @@ while True:
|
|
|
)
|
|
)
|
|
|
break
|
|
break
|
|
|
tap(name, *locations[0])
|
|
tap(name, *locations[0])
|
|
|
|
|
+ idle_counter = 0
|
|
|
continue
|
|
continue
|
|
|
if name == "attack":
|
|
if name == "attack":
|
|
|
if len(locations) == 1:
|
|
if len(locations) == 1:
|
|
@@ -151,13 +157,18 @@ while True:
|
|
|
is_mixed = False
|
|
is_mixed = False
|
|
|
element = first_template(tpl_water)
|
|
element = first_template(tpl_water)
|
|
|
if element is None:
|
|
if element is None:
|
|
|
- if fire_vs_earth == "earth":
|
|
|
|
|
|
|
+ if fire_or_earth == "earth":
|
|
|
element = first_template(tpl_earth)
|
|
element = first_template(tpl_earth)
|
|
|
else:
|
|
else:
|
|
|
element = first_template(tpl_fire)
|
|
element = first_template(tpl_fire)
|
|
|
|
|
|
|
|
tap(name, element[0], locations[0][1])
|
|
tap(name, element[0], locations[0][1])
|
|
|
|
|
+ idle_counter = 0
|
|
|
continue
|
|
continue
|
|
|
print("...")
|
|
print("...")
|
|
|
|
|
+ idle_counter += 1
|
|
|
|
|
+ if idle_counter >= 3:
|
|
|
|
|
+ print("######### stopping due to three idle loop iterations.")
|
|
|
|
|
+ break
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
print(f"error: {e}")
|
|
print(f"error: {e}")
|