forked from coderwilson/FFX_TAS_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzz_eggHuntAuto.py
More file actions
257 lines (243 loc) · 11.8 KB
/
zz_eggHuntAuto.py
File metadata and controls
257 lines (243 loc) · 11.8 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import pyxinput
import time
import FFX_Xbox
import FFX_Battle
import FFX_Screen
import FFX_core
import FFX_memory
import FFX_Logs
FFXC = FFX_Xbox.FFXC
def engage():
print("Start egg hunt")
startTime = time.time()
checkpoint = 0
battleCount = 0
lookingCount = 0
camCount = 0
print("Generating Plot file (the X/Y kind)")
#FFX_Logs.nextPlot()
#time.sleep(3)
while FFX_memory.getStoryProgress() < 3251:
if FFX_Screen.BattleScreen():
print("Battle engaged - using flee.")
FFX_Battle.fleeLateGame()
battleCount += 1
elif FFX_memory.menuOpen():
print("Clicking to control.")
FFXC.set_value('BtnB',1)
time.sleep(0.035)
FFXC.set_value('BtnB',0)
time.sleep(0.035)
else:
#Move to first egg, while in control.
complete = 0
activeEgg = 99
target = [10,-10]
moveVersion = 0
while complete == 0:
if activeEgg == 99:
if lookingCount % 200 < 100:
target = [20,-20]
else:
target = [-20,20]
#print("Building egg array")
eggArray = FFX_memory.buildEggs()
currentTime = time.time()
if activeEgg == 99:
for marker in range(10): #Only print active eggs/icicles
if activeEgg == 99 and eggArray[marker].goForEgg == True and eggArray[marker].eggLife < 150:
activeEgg = marker
target = [eggArray[marker].x, eggArray[marker].y]
clickTimer = currentTime + 8 #We will hunt for this egg for this many seconds.
print("New target egg: ", target)
elif eggArray[activeEgg].goForEgg == False:
activeEgg = 99
if lookingCount % 200 < 100:
target = [20,-20]
else:
target = [-20,20]
elif eggArray[activeEgg].eggLife == 150:
activeEgg = 99
if lookingCount % 200 < 100:
target = [20,-20]
else:
target = [-20,20]
if FFX_Screen.BattleScreen():
print("Battle engaged - using flee. (Loop break)")
complete = 1
elif FFX_memory.getStoryProgress() > 3250:
print("Story progress trigger. Moving on. (loop break)")
complete = 1
else:
#print("Movement happening.")
#target = [-70,-70]
player = FFX_memory.getCoords()
cam = FFX_memory.getCamera()
#camCount += 1
#print(camCount)
#if camCount % 20 == 0:
# FFX_Logs.writePlot("TEST")
if cam[0] > 1.1:
moveVersion = 1
if player[0] < target[0] - 2:
FFXC.set_value('AxisLy', -1)
elif player[0] > target[0] + 2:
FFXC.set_value('AxisLy', 1)
else:
FFXC.set_value('AxisLy', 0)
if cam[2] < player[1]:
if player[1] < target[1] - 2:
FFXC.set_value('AxisLx', 1)
elif player[1] + target[1] + 2:
FFXC.set_value('AxisLx', -1)
else:
FFXC.set_value('AxisLx', 0)
else:
if player[1] < target[1] - 2:
FFXC.set_value('AxisLx', -1)
elif player[1] + target[1] + 2:
FFXC.set_value('AxisLx', 1)
else:
FFXC.set_value('AxisLx', 0)
elif cam[0] < -1:
moveVersion = 2
if player[0] < target[0] - 2:
FFXC.set_value('AxisLy', 1)
elif player[0] > target[0] + 2:
FFXC.set_value('AxisLy', -1)
else:
FFXC.set_value('AxisLy', 0)
if cam[2] < player[1]:
if player[1] < target[1] - 2:
FFXC.set_value('AxisLx', -1)
elif player[1] + target[1] + 2:
FFXC.set_value('AxisLx', 1)
else:
FFXC.set_value('AxisLx', 0)
else:
if player[1] < target[1] - 2:
FFXC.set_value('AxisLx', 1)
elif player[1] + target[1] + 2:
FFXC.set_value('AxisLx', -1)
else:
FFXC.set_value('AxisLx', 0)
elif cam[4] < -0.88:
moveVersion = 3
if player[1] > target[1] + 1.5:
FFXC.set_value('AxisLy', 1)
elif player[1] < target[1] - 1.5:
FFXC.set_value('AxisLy', -1)
else:
FFXC.set_value('AxisLx', 0)
if player[0] < target[0] - 1.5:
FFXC.set_value('AxisLx', -1)
elif player[0] + target[0] + 1.5:
FFXC.set_value('AxisLx', 1)
else:
FFXC.set_value('AxisLx', 0)
elif cam[4] > 0.9:
moveVersion = 4
if player[1] > target[1] + 1.5:
FFXC.set_value('AxisLy', -1)
elif player[1] < target[1] - 1.5:
FFXC.set_value('AxisLy', 1)
else:
FFXC.set_value('AxisLx', 0)
if player[0] < target[0] - 1.5:
FFXC.set_value('AxisLx', 1)
elif player[0] + target[0] + 1.5:
FFXC.set_value('AxisLx', -1)
else:
FFXC.set_value('AxisLx', 0)
elif cam[0] > 0.01 and cam[4] > 0.01:
moveVersion = 5
if player[1] - target[1] < player[0] - target[0]:
FFXC.set_value('AxisLy', 1)
elif player[1] - target[1] > player[0] - target[0]:
FFXC.set_value('AxisLy', -1)
else:
FFXC.set_value('AxisLy', 0)
if player[0] + target[0] < player[1] + target[1]:
FFXC.set_value('AxisLx', -1)
elif player[0] + target[0] + player[1] + target[1]:
FFXC.set_value('AxisLx', 1)
else:
FFXC.set_value('AxisLx', 0)
elif cam[0] < 0.01 and cam[4] < 0.01:
moveVersion = 6
if player[1] - target[1] < player[0] - target[0]:
FFXC.set_value('AxisLy', -1)
elif player[1] - target[1] > player[0] - target[0]:
FFXC.set_value('AxisLy', 1)
else:
FFXC.set_value('AxisLy', 0)
if player[0] + target[0] < player[1] + target[1]:
FFXC.set_value('AxisLx', 1)
elif player[0] + target[0] + player[1] + target[1]:
FFXC.set_value('AxisLx', -1)
else:
FFXC.set_value('AxisLx', 0)
elif cam[0] > 0.01 and cam[4] < 0.01:
moveVersion = 7
if player[1] - target[1] < player[0] - target[0]:
FFXC.set_value('AxisLx', 1)
elif player[1] - target[1] > player[0] - target[0]:
FFXC.set_value('AxisLx', -1)
else:
FFXC.set_value('AxisLx', 0)
if player[0] + target[0] < player[1] + target[1]:
FFXC.set_value('AxisLy', -1)
elif player[0] + target[0] + player[1] + target[1]:
FFXC.set_value('AxisLy', 1)
else:
FFXC.set_value('AxisLy', 0)
elif cam[0] < 0.01 and cam[4] > 0.01:
moveVersion = 8
if player[1] - target[1] < player[0] - target[0]:
FFXC.set_value('AxisLx', -1)
elif player[1] - target[1] > player[0] - target[0]:
FFXC.set_value('AxisLx', 1)
else:
FFXC.set_value('AxisLx', 0)
if player[0] + target[0] < player[1] + target[1]:
FFXC.set_value('AxisLy', 1)
elif player[0] + target[0] + player[1] + target[1]:
FFXC.set_value('AxisLy', -1)
else:
FFXC.set_value('AxisLy', 0)
else:
moveVersion = 0
FFXC.set_value('AxisLx', 0)
FFXC.set_value('AxisLy', 0)
print("In-between.")
#Now if we're close, we want to slow down a bit.
if activeEgg != 99 and eggArray[activeEgg].distance < 15 and eggArray[activeEgg].eggLife < 130:
time.sleep(0.15)
FFXC.set_value('AxisLx', 0)
FFXC.set_value('AxisLy', 0)
time.sleep(0.15)
elif activeEgg == 99:
print("Looking for a new egg. Move version: ", moveVersion," | ",lookingCount)
lookingCount += 1
else:
print("Targetting egg: ", moveVersion," | ",target)
if FFX_memory.userControl() == False:
if FFX_Screen.Minimap2():
FFX_Xbox.menuB()
else:
FFXC.set_value('AxisLx', 0)
FFXC.set_value('AxisLy', 0)
endTime = time.time()
print("End egg hunt")
FFXC.set_value('AxisLx', 0)
FFXC.set_value('AxisLy', 0)
duration = endTime - startTime
print("Duration: ", str(duration))
print("Battle count: ", battleCount)
try:
FFX_Logs.writeStats("Egg hunt duration in seconds:")
FFX_Logs.writeStats(str(round(duration,2)))
FFX_Logs.writeStats("Egg hunt battles:")
FFX_Logs.writeStats(str(battleCount))
except:
print("No log file.")