-
Notifications
You must be signed in to change notification settings - Fork 62
/
simplesushibot.py
155 lines (133 loc) · 6.06 KB
/
simplesushibot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#! python3
# A simpler version of the Sushi Go Round bot made for the NCSS 2015 Summer Camp
# To use this program, have the Sushi Go Round game at the starting screen.
# At the > prompt, enter the first three letters of an order to make it
# (oni, gun, cal, sal, shr, una, dra, com) or enter a number 1-6 to order new
# ingredients.
# 1-shrimp 2-rice
# 3-nori 4-roe
# 5-salmon 6-unagi
# Entering nothing will clear plates and re-scan for orders.
import pyautogui, sys, time
print('Program started.')
# Note where the bot's window is.
input('Move mouse over bot window and press Enter.')
botWindow = pyautogui.position()
# locate the game window
window = pyautogui.locateOnScreen('top_left_corner.png')
if window is None:
sys.exit('Could not find game on screen. Is the game visible?')
winLeft = window[0]
winTop = window[1]
print('Found game window at:', winLeft, winTop)
# preprogram all the ingredient button coordinates
shrimp = [35 + winLeft, 330 + winTop]
nori = [35 + winLeft, 380 + winTop]
salmon = [35 + winLeft, 430 + winTop]
rice = [90 + winLeft, 330 + winTop]
roe = [90 + winLeft, 380 + winTop]
unagi = [90 + winLeft, 430 + winTop]
mat = [200 + winLeft, 400 + winTop]
# preprogram phone coordinates
phone = [550 + winLeft, 350 + winTop]
rice1Button = [500 + winLeft, 290 + winTop]
rice2Button = [550 + winLeft, 300 + winTop]
toppingButton = [500 + winLeft, 270 + winTop]
ingredButtons = {'1': [500 + winLeft, 220 + winTop], # shrimp
'3': [500 + winLeft, 270 + winTop], # nori
'5': [500 + winLeft, 320 + winTop], # salmon
'4': [550 + winLeft, 270 + winTop], # roe
'6': [550 + winLeft, 220 + winTop]} # unagi
cancelButton = [580 + winLeft, 330 + winTop]
deliveryButton = [500 + winLeft, 300 + winTop]
phoneRegion = [440 + winLeft, 190 + winTop, 200, 200]
# navigate through start screen
pyautogui.click(320 + winLeft, 200 + winTop) # click on Play button
pyautogui.click(300 + winLeft, 380 + winTop) # click on Continue button
pyautogui.click(550 + winLeft, 450 + winTop) # click on Skip
pyautogui.click(300 + winLeft, 380 + winTop) # click on Continue button
pyautogui.click(botWindow) # click back on bot window
def clickIngredients(coordinates):
# click on all the coordinates in the coordinates list, then click the mat
for c in coordinates:
pyautogui.click(c)
pyautogui.click(mat)
def clearPlates():
# clear the plates by clicking on them
for platex in range(80, 581, 100):
pyautogui.click(platex + winLeft, 200 + winTop)
pyautogui.click(botWindow) # put bot window back into focus
# The main program loop will constantly ask the user for a command until
# they enter "quit".
while True:
# get the user's command
command = input('> ')
if command == 'quit':
sys.exit() # exit program
elif command == '':
# read screen for all orders and display them
print('CURRENT ORDERS: (press Enter to re-scan)')
for foodImage in ['onigiri_order.png', 'california_roll_order.png',
'gunkan_maki_order.png', 'salmon_roll_order.png',
'shrimp_sushi_order.png', 'unagi_roll_order.png',
'dragon_roll_order.png', 'combo_order.png']:
numOrders = len(list(pyautogui.locateAllOnScreen(foodImage, region=[20 + winLeft, 40 + winTop, 580, 60])))
if numOrders > 0:
# only display amount of orders if there are any
print(foodImage[:3], numOrders)
print('==================')
clearPlates()
continue # go back to start of loop
elif not command.isdigit(): # command is to create an order
if command == 'oni':
print('Making onigiri...')
clickIngredients([rice, rice, nori])
elif command == 'cal':
print('Making california roll...')
clickIngredients([rice, nori, roe])
elif command == 'gun':
print('Making gunkan maki...')
clickIngredients([rice, nori, roe, roe])
elif command == 'sal':
print('Making salmon roll...')
clickIngredients([rice, nori, salmon, salmon])
elif command == 'shr':
print('Making shrimp sushi...')
clickIngredients([rice, nori, shrimp, shrimp])
elif command == 'una':
print('Making unagi roll...')
clickIngredients([rice, nori, unagi, unagi])
elif command == 'dra':
print('Making dragon roll...')
clickIngredients([rice, rice, nori, roe, unagi, unagi])
elif command == 'com':
print('Making combo...')
clickIngredients([rice, rice, nori, roe, salmon, unagi, shrimp])
else:
continue # invalid sushi order, go back to start of loop
clearPlates()
time.sleep(1.5) # mat rolling takes 1.5 seconds to complete
elif command.isdigit(): # ordering more ingredients
if command == '2': # handle ordering more rice
print('Ordering more rice...')
pyautogui.click(phone)
pyautogui.click(rice1Button)
if pyautogui.locateOnScreen('cant_afford_rice.png', region=phoneRegion) != None:
print('Cannot afford rice right now.')
pyautogui.click(cancelButton) # close the phone menu
else:
# complete the order
pyautogui.click(rice2Button)
pyautogui.click(deliveryButton)
elif command in '13456': # handle ordering non-rice toppings
print('Ordering more toppings...')
pyautogui.click(phone)
pyautogui.click(toppingButton)
if pyautogui.locateOnScreen('cant_afford_' + command + '.png', region=phoneRegion) != None:
print('Cannot afford that topping right now.')
pyautogui.click(cancelButton) # close the phone menu
else:
# complete the order
pyautogui.click(ingredButtons[command])
pyautogui.click(deliveryButton)
clearPlates()