battlepillars-bot/apple-farm.py

95 lines
2.0 KiB
Python
Raw Normal View History

2022-12-26 01:02:19 +03:00
from datetime import datetime
2022-12-26 21:39:58 +03:00
import shutil
2022-12-26 01:02:19 +03:00
__author__ = "Alexander Popov <iiiypuk@fastmail.fm>"
__version__ = "1.0.0"
__license__ = "Unlicense"
2022-12-26 21:39:58 +03:00
def date_string(symbols=True):
2022-12-26 21:23:27 +03:00
"""Return current date."""
date_now = datetime.now()
2022-12-26 21:39:58 +03:00
if symbols:
date_str = date_now.strftime("%Y-%m-%d %H:%M:%S")
else:
date_str = date_now.strftime("%Y-%m-%d_%H_%M_%S")
2022-12-26 21:23:27 +03:00
return(date_str)
2022-12-26 21:39:58 +03:00
def make_screenshot():
"""..."""
image = capture(App.focusedWindow())
shutil.move(image, "{0}.png".format(date_string(False)))
2022-12-26 21:23:27 +03:00
def run_level():
"""Running level and farming apples"""
2022-12-26 01:02:19 +03:00
wait("images/farm_level_on_map.png", 10)
click("images/farm_level_on_map.png")
wait("images/level_title.png", 3)
click("images/level_start_button.png")
2022-12-26 21:39:58 +03:00
make_screenshot()
2022-12-26 01:02:19 +03:00
wait("images/equip_window.png", 3)
click("images/button_start.png")
wait("images/level_info_message.png", 5)
click("images/level_info_message_ok.png")
Mouse.wheel(WHEEL_DOWN, 6)
2022-12-26 21:11:29 +03:00
pillar_heal = find("images/pillar_heal.png")
pillar_fire = find("images/pillar_fire.png")
2022-12-26 01:02:19 +03:00
for pillar in range(2):
2022-12-26 21:11:29 +03:00
pillar_fire.click("images/pillar_fire.png")
2022-12-26 01:02:19 +03:00
2022-12-26 21:11:29 +03:00
for x in range(6):
pillar_heal.click("images/pillar_heal.png")
2022-12-26 01:02:19 +03:00
click("images/pillar_go.png")
2022-12-26 21:23:27 +03:00
try:
wait("images/winner_window.png", 60 * 2)
click("images/level_complete.png")
except FindFailed as e:
print("[{0}] Level timeout. Return to Map".format(date_string()))
return_to_menu()
def return_to_menu():
"""Return to Map if an error has passed"""
click("images/menu_button.png")
click("images/menu_map_button.png")
2022-12-26 01:02:19 +03:00
def main():
"""Main farm loop."""
print("Battlepillars Farming Bot {0} by {1}".format(__version__, __author__))
run_count = 0
2022-12-26 21:23:27 +03:00
2022-12-26 01:02:19 +03:00
while True:
run_count += 1
print(
"[{date}] Running farm {times} times".format(
2022-12-26 21:23:27 +03:00
date=date_string(), times=run_count
2022-12-26 01:02:19 +03:00
)
)
2022-12-26 21:23:27 +03:00
run_level()
2022-12-26 01:02:19 +03:00
if __name__ == "__main__":
main()