2021-02-19 18:32:20 +08:00
|
|
|
from pyautogui import *
|
|
|
|
import time
|
|
|
|
|
2021-02-19 19:00:15 +08:00
|
|
|
#
|
|
|
|
# Functions.
|
|
|
|
#
|
|
|
|
|
2021-02-26 20:14:23 +08:00
|
|
|
def do_click(box, button):
|
|
|
|
time.sleep(0.2)
|
|
|
|
x, y = box.left + box.width / 2, box.top + box.height / 2
|
|
|
|
moveTo(x, y)
|
|
|
|
long_click(button=button)
|
|
|
|
|
|
|
|
|
2021-02-19 19:12:39 +08:00
|
|
|
# Locates gui element.
|
|
|
|
def locate_click(imgname, alt=None, t=0.1, button="left"):
|
2021-02-19 19:00:15 +08:00
|
|
|
# Add pause to allow time for gui elements to appear.
|
2021-02-19 18:32:20 +08:00
|
|
|
time.sleep(t)
|
2021-02-19 19:00:15 +08:00
|
|
|
|
2021-02-19 19:12:39 +08:00
|
|
|
# Try to find image from screengrab.
|
2021-02-19 18:32:20 +08:00
|
|
|
box = locateOnScreen(imgname)
|
2021-02-19 19:38:41 +08:00
|
|
|
print(imgname, "found at:\n\t", box)
|
2021-02-19 18:32:20 +08:00
|
|
|
|
2021-02-19 19:00:15 +08:00
|
|
|
# It not found, try to find alt image.
|
2021-02-19 18:32:20 +08:00
|
|
|
if box is None:
|
|
|
|
if alt is not None:
|
2021-02-26 20:14:23 +08:00
|
|
|
box = locate_click(alt, button=button)
|
|
|
|
return False, None
|
2021-02-19 18:32:20 +08:00
|
|
|
|
2021-02-19 19:00:15 +08:00
|
|
|
# Get center of button and click.
|
2021-02-26 20:14:23 +08:00
|
|
|
do_click(box, button)
|
|
|
|
return True, box
|
|
|
|
|
2021-02-19 18:32:20 +08:00
|
|
|
|
2021-02-19 19:12:39 +08:00
|
|
|
# Longer click, so FFXIV registers it.
|
|
|
|
def long_click(t=0.100, button="left"):
|
2021-02-19 18:32:20 +08:00
|
|
|
mouseDown(button=button)
|
|
|
|
time.sleep(t)
|
|
|
|
mouseUp(button=button)
|
|
|
|
|
2021-02-26 20:14:23 +08:00
|
|
|
|
2021-02-19 19:00:15 +08:00
|
|
|
#
|
|
|
|
# Main logic.
|
|
|
|
#
|
|
|
|
|
2021-02-19 19:38:41 +08:00
|
|
|
# Define image paths:
|
|
|
|
img_dir = "img/"
|
2021-02-26 20:14:23 +08:00
|
|
|
img_purchaseland = img_dir + "PurchaseLand.png"
|
|
|
|
img_purchaseland_alt = None
|
|
|
|
img_freecompany = img_dir + "FreeCompany.png"
|
|
|
|
img_freecompany_alt = img_dir + "FreeCompanyAlt.png"
|
|
|
|
img_yes = img_dir + "Yes.png"
|
|
|
|
img_yes_alt = None
|
|
|
|
count = 1
|
|
|
|
|
|
|
|
# save pos
|
|
|
|
saved_purchase = None
|
|
|
|
saved_yes = None
|
|
|
|
|
|
|
|
while True:
|
2021-02-19 19:00:15 +08:00
|
|
|
# Option to pause every 5 iteratons to stop program
|
2021-02-26 20:14:23 +08:00
|
|
|
# if count%5 == 0: time.sleep(5);
|
|
|
|
|
|
|
|
# get center left third of of screen
|
2021-02-19 18:32:20 +08:00
|
|
|
start_x, start_y = size()
|
2021-02-26 20:14:23 +08:00
|
|
|
start_x /= 3
|
|
|
|
start_y /= 2
|
2021-02-19 18:32:20 +08:00
|
|
|
|
2021-02-19 19:00:15 +08:00
|
|
|
# move cursor to get focus, and click on sign
|
2021-02-19 18:32:20 +08:00
|
|
|
moveTo(start_x, start_y)
|
2021-02-26 20:14:23 +08:00
|
|
|
click()
|
2021-02-19 19:12:39 +08:00
|
|
|
long_click(button="right")
|
2021-02-19 18:32:20 +08:00
|
|
|
|
2021-02-26 20:14:23 +08:00
|
|
|
# Attempt to find gui buttons.
|
|
|
|
if saved_purchase is not None:
|
|
|
|
print("using saved purchase pos\n\t", saved_purchase)
|
|
|
|
do_click(saved_purchase, "left")
|
|
|
|
else:
|
|
|
|
success, box = locate_click(img_purchaseland, img_purchaseland_alt, t=0.4)
|
|
|
|
if not success:
|
|
|
|
press("esc")
|
|
|
|
continue
|
|
|
|
saved_purchase = box
|
|
|
|
# if not locate_click(img_freecompany_alt, img_freecompany):
|
|
|
|
# press("esc");
|
|
|
|
# press("esc");
|
|
|
|
# continue
|
|
|
|
if saved_yes is not None:
|
|
|
|
print("using saved yes pos\n\t", saved_yes)
|
|
|
|
do_click(saved_yes, "left")
|
|
|
|
else:
|
|
|
|
sucess, box = locate_click(img_yes, img_yes_alt)
|
|
|
|
if not success:
|
|
|
|
press("esc")
|
|
|
|
press("esc")
|
|
|
|
continue
|
|
|
|
saved_yes = box
|
|
|
|
|
|
|
|
count += 1
|