ViperViking
Newcomer
- Joined
- Mar 24, 2023
- Sythe Gold
- 4
- Messages
- 6
- Age
- 35
Code:
#The minotaur_alive.png photo is the health bar
#of the minotaur that I set in the top left corner
#of the game when playing
#https://imgur.com/a/DL732u2
import pyautogui
import random
import time
from PIL import Image, ImageGrab
import re
import pytesseract
import math
# Set up the Tesseract OCR path
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
def main(minotaur_images, region):
# Loop continuously
while True:
# Check if the player is fighting the minotaur
if pyautogui.locateOnScreen("minotaur_alive.png", confidence=0.95, region=(0,0,300,200)) is None:
# If the minotaur is on screen, attack it and then check health
for image in minotaur_images:
print(image.filename)
minotaur_location = pyautogui.locateOnScreen(image, confidence=0.6, region=region)
if minotaur_location:
pyautogui.moveTo(minotaur_location, duration=random.randint(23,32)/100, tween=pyautogui.easeOutQuad)
pyautogui.moveTo(pyautogui.position()[0] + random.randint(-4, 4), pyautogui.position()[1] + random.randint(-4, 4), duration=.2, tween=pyautogui.easeOutQuad)
pyautogui.click(button='left')
time.sleep(random.randint(230, 320) / 100)
break
health_button = ImageGrab.grab(bbox=(104, 933, 104+36, 933+15))
resized_img = health_button.resize((health_button.width * 2, health_button.height * 2))
health_amount = get_text(resized_img)
if health_amount and not math.isnan(int(replace_chars(health_amount))):
print(int(replace_chars(health_amount)))
if (int(replace_chars(health_amount)) > 2000 and int(replace_chars(health_amount)) < 4200):
lobster_location = pyautogui.locateOnScreen('lobster.png', confidence=0.95, region=region)
if lobster_location:
pyautogui.moveTo(lobster_location,duration=random.randint(23,32)/100,tween=pyautogui.easeOutQuad)
pyautogui.moveTo(pyautogui.position()[0]+random.randint(-4,4), pyautogui.position()[1]+random.randint(-4,4),duration=random.randint(23,55)/100,tween=pyautogui.easeOutQuad)
pyautogui.click(button='left')
time.sleep(random.randint(89,132)/100)
else:
# If the minotaur is not on screen, wait for it to appear
time.sleep(0.2)
def get_text(image):
return pytesseract.image_to_string(image, config='--psm 6')
def replace_chars(text):
"""
Replaces all characters instead of numbers from 'text'.
:param text: Text string to be filtered
:return: Resulting number
"""
list_of_numbers = re.findall(r'\d+', text)
result_number = ''.join(list_of_numbers)
return result_number
if __name__ == '__main__':
# Define the region to search for images in
REGION = (0, 0, 1920, 1080)
# Load the images of the minotaur
minotaur_images = ['minotaur1.png', 'minotaur2.png', 'minotaur3.png', 'minotaur4.png', 'minotaur5.png']
minotaur_images = [Image.open(image) for image in minotaur_images]
# Start the main function
main(minotaur_images, REGION)
Last edited:

