Skip to content

Commit

Permalink
Added Terra + Terra Breeding Bot with a max of 32 cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioken22 committed Mar 17, 2024
1 parent 317e933 commit 6e6a6d0
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 1 deletion.
12 changes: 11 additions & 1 deletion options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import tkinter as tk
from tkinter import simpledialog,messagebox

options = ["Collect All Gold and Food", "Watch DTV Ads", "Skip 6h Ads", "Watch Greenhouse Ads", "League Auto Combat", "Dragon Rescue Auto Combat", "Arena Fight to Lose Points"]
options = ["Collect All Gold and Food",
"Watch DTV Ads", "Skip 6h Ads",
"Watch Greenhouse Ads",
"League Auto Combat",
"Dragon Rescue Auto Combat",
"Unli Terra Breed",
"Arena Fight to Lose Points",]

class OptionDialog(simpledialog.Dialog):
def __init__(self, parent, title, options, execute_func):
Expand Down Expand Up @@ -64,6 +70,10 @@ def execute_selected_option(selected_option):
print(f"Selected: {selected_option}")
script_path = os.path.join(os.path.dirname(__file__), "dragon_rescue_bot", "dragon_rescue_bot.py")
subprocess.run(["python", script_path])
elif selected_option == "Unli Terra Breed":
print(f"Selected: {selected_option}")
script_path = os.path.join(os.path.dirname(__file__), "terra_breed_bot", "terra_breed_bot.py")
subprocess.run(["python", script_path])
elif selected_option == "Arena Fight to Lose Points":
print(f"Selected: {selected_option}")
messagebox.showinfo("Feature Under Development", "This feature is still under development.")
Expand Down
Binary file added terra_breed_bot/breed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added terra_breed_bot/hatchery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added terra_breed_bot/rebreed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added terra_breed_bot/sell-green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added terra_breed_bot/sell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added terra_breed_bot/take-egg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added terra_breed_bot/terra-hatch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions terra_breed_bot/terra_breed_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import pyautogui
import ctypes
import sys
import os
import time
import tkinter as tk
from tkinter import messagebox, simpledialog


sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from options import show_options_dialog

# Variable declarations
folder_location = 'terra_breed_bot/'
window_name = "Unlimited Terra Breeding"
game_location = "Ultra Breeding Tree 2"
image_hint = "Ultra Breeding Tree 2"

# For terminal printing only
GREEN = '\033[92m'
RED = '\033[91m'
RESET = '\033[0m'

# Set uniform values here
uniform_delay = 0.5
uniform_confidence = 0.8
uniform_click_delay = 0.25

def locate_and_click(image_path, success_message, click=True, set_confidence=0.8):
try:
position = pyautogui.locateOnScreen(image_path, confidence=set_confidence)

if position is not None:
print(GREEN + f"Found {success_message} at: {position}" + RESET)
if click:
pyautogui.moveTo(position, duration=0.66)
pyautogui.click(position, duration=0.01)
return True
except pyautogui.ImageNotFoundException:
print(RED + f"Could not locate the {image_path} on the screen." + RESET)
except Exception as e:
print(RED + f"An unexpected error occurred: {e}" + RESET)

def show_dialog(message):
ctypes.windll.user32.MessageBoxW(0, message, "Bot Notification", 1)

# Bot sequence of tasks
def bot_cycle():
for _ in range (selected_cycles):
time.sleep(0.66)
if locate_and_click(folder_location + 'ultra-breeding-tree.png', 'Ultra Breeding Tree 2'):
time.sleep(0.66)
if locate_and_click(folder_location + 'rebreed.png', 'Rebreed Button'):
time.sleep(1)
if locate_and_click(folder_location + 'breed.png', 'Breed Button'):
time.sleep(14)
if locate_and_click(folder_location + 'take-egg.png', 'Take Egg Button'):
time.sleep(16)
if locate_and_click(folder_location + 'terra-hatch.png', 'Terra Hatch Button'):
time.sleep(0.66)
if locate_and_click(folder_location + 'sell.png', 'Sell Button'):
time.sleep(0.66)
locate_and_click(folder_location + 'sell-green.png', 'Green Sell Button')

# Step 1: Open a Dialogue
root = tk.Tk()
root.withdraw()

# Bot Cycles Dropdown
class BotCyclesDialog(simpledialog.Dialog):
def __init__(self, parent):
self.dialog_title = "Terra Breeding Times"
self.prompt = "Choose the number of times you want to breed your Terra Dragons:"
super().__init__(parent, self.dialog_title)

def body(self, master):
self.bot_cycle_choices = [str(i) for i in range(1, 33)]
self.var = tk.StringVar()
self.var.set(self.bot_cycle_choices[0])

tk.Label(master, text=self.prompt).pack()
bot_cycles_dropdown = tk.OptionMenu(master, self.var, *self.bot_cycle_choices)
bot_cycles_dropdown.pack()

def apply(self):
self.result = self.var.get()

bot_cycles_dialog_instance = BotCyclesDialog(root)
selected_cycles = bot_cycles_dialog_instance.result
if selected_cycles is not None:
selected_cycles = int(selected_cycles)
else:
selected_cycles = 0
show_options_dialog()

# Confirmation Message
confirmation = messagebox.askquestion(window_name, "Locate " + game_location + " and make sure it's in MAXIMIZE window mode. "
"\nIn order for this to work, MAX the ZOOM OUT first then ZOOM IN TWO(2) times by pressing the PLUS(+) button."
"\nThen make sure the the HATCHERY 6 is VISIBLE on your screen and you go AFK while this bot is running."
"\n\nHave you followed everything?")

root.destroy()

if confirmation == 'no':
show_options_dialog()
sys.exit()

# Step 2: Attempt to locate
while confirmation == 'yes':
show_dialog("This is a REBREED process. Make sure your recent breeding is Terra + Terra Dragon.")
try:
hatchery = pyautogui.locateOnScreen(folder_location + 'hatchery.png', confidence=0.8)
ultra_breeding_tree = pyautogui.locateOnScreen(folder_location + 'ultra-breeding-tree.png', confidence=0.8)
if hatchery and ultra_breeding_tree is not None:
print(GREEN + f"{image_hint} is found at: {hatchery}" + RESET)
print(GREEN + f"{image_hint} is found at: {ultra_breeding_tree}" + RESET)
bot_cycle()
show_dialog(f"Done breeding Terra Dragons for {selected_cycles} times.")
show_options_dialog()
break
except pyautogui.ImageNotFoundException:
print(RED + f"Could not locate {image_hint}." + RESET)
answer = messagebox.askyesno(window_name, "Are you sure " + game_location + " is located?\n\n"
"Locate " + game_location + " and make sure it's in MAXIMIZE window mode. "
"\nIn order for this to work well, MAX the ZOOM OUT first then ZOOM IN TWO(2) times by pressing the PLUS(+) button."
"\nThen make sure the the HATCHERY 6 is VISIBLE on your screen and you go AFK while this bot is running."
"\n\nWould you like to try scanning again?")
if not answer:
show_options_dialog()
break
else:
print(f"Searching for the {image_hint}...")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Binary file added terra_breed_bot/ultra-breeding-tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6e6a6d0

Please sign in to comment.