View difference between Paste ID: 6UPv0NKE and CWkgnins
SHOW: | | - or go back to the newest paste.
1
/* 
2
Simple KanColle expedition and Leveling script.
3
Constantly runs and repairs ships ships and can run in three modes:
4
Solo ship (sub) running 2-3 for levels and fuel, 3-2 for levels and steel,
5
or Fleet of ships (hopefully with 1 or more subs) running 3-2-A for levels
6
Also runs Expedition 2 (Steel and buckets) on Fleet 2,
7
and Expedition 5 (Fuel) on Fleet 4.
8
Ctrl+Alt+o to start script and respond to the prompts accordingly.
9
Ctrl+Alt+p to pause the script at any time
10
11
This script relies on relative mouse coordinates.  Therefore to keep screen
12
resolution consistent, this script must be run on Adobe Flash Projector
13
with the game in native resolution. Get Adobe Flash Projector here: 
14
http://www.adobe.com/support/flashplayer/downloads.html
15
Run the game through your API link with Adobe Flash Projector and be
16
sure not to resize the window.  Note that after hitting Game Start
17
the Adobe Flash Projector menu bar should disappear leaving a black region
18
on the top and bottom akin to a letterbox.  Leave these be.
19
20
Finally this script scans pixel colors to determine what's happening on the
21
screen.  Because of this AutoHotkey needs constant data being sent out
22
from the computer's graphics unit.  Therefore be sure that your computer is
23
not turning off display output after a certain amount of time.  For Windows
24
users go to Control Panel > Power Options > Change (current) plan settings >
25
Turn off the display > Never . It's fine, however, to turn off your monitor
26
so long as data from your graphics unit is still being sent by setting this
27
option to Never.
28
*/
29
30
!^p::pause
31
!^s::suspend
32
33
global expedition_1_timer_complete
34
global expedition_2_timer_complete
35
global expedition_1_fuel_pending
36
global expedition_2_fuel_pending
37
global expedition_1_dispatch_pending
38
global expedition_2_dispatch_pending
39
40
/*
41
##### Functions #####
42
*/ 
43
44
rand_sleep(time_low, time_high) { ; Probably unnecessary, but set sleep to be semi-random to alleviate some banhammer suspicion.  Not like this is really detectable-
45
	Random, rand, %time_low%, %time_high% ; Generate sleep time between time_low and time_high in ms
46
	Sleep %rand% ; Sleep the generated time
47
}
48
49
home_screen_check() ; Checks if the current screen is the home screen
50
{   
51
    MouseMove 30, 430, 1 ; Moves mouse out of the way
52
    PixelSearch shutsugeki_x, shutsugeki_y, 207, 281, 218, 295, 0x209BFB, 2, fast
53
    if (shutsugeki_y < 294) { ; Check if shutsugeki button is present
54
        shutsugeki_ok := 1
55
    }
56
    PixelSearch ammo_x, ammo_y, 695, 94, 730, 105, 0xF2F6FF, 15, fast
57
    if (ammo_y < 104) { ; Check if ammo stats are present
58
        ammo_ok := 1
59
    }
60
    PixelSearch config_x, config_y, 776, 485, 791, 497, 0xF2F6FF, 2, fast
61
    if (config_y < 496) { ; Check if config button is present
62
        config_ok := 1
63
    }
64
    condition_check := shutsugeki_ok + ammo_ok + config_ok
65
    if (condition_check = 3) {
66
        return 1
67
    } else {
68
        return 0
69
    }
70
}
71
72
sortie_menu_check() ; Checks if you're stuck in the stage select screen for some reason
73
{
74
	MouseMove 30, 430, 1 ; Moves mouse out of the way
75
    PixelSearch shutsugeki_x, shutsugeki_y, 20, 482, 52, 506, 0xF2F6FF, 5, fast
76
    if (shutsugeki_y < 505) { ; Check if shutsugeki button is present
77
        shutsugeki_ok := 1
78
    }
79
    PixelSearch ammo_x, ammo_y, 695, 94, 730, 105, 0xF2F6FF, 15, fast
80
    if (ammo_y < 104) { ; Check if ammo stats are present
81
        ammo_ok := 1
82
    }
83
	condition_check := shutsugeki_ok + ammo_ok
84
    if (condition_check = 2) {
85
        return 1
86
    } else {
87
        return 1
88
    }
89
}
90
91
compass_check() ; Checks if the current screen is the compass
92
{   
93
    MouseMove 30, 430, 1 ; Moves mouse out of the way
94
    PixelSearch center_compass_x, center_compass_y, 405, 248, 412, 262, 0x08088F, 15, fast
95
    if (center_compass_y < 261) { ; Check if shutsugeki button is present
96
        center_compass_ok := 1
97
    }
98
    PixelSearch corner_compass_x, corner_compass_y, 56, 463, 65, 477, 0x05073F, 15, fast
99
    if (corner_compass_y < 674) { ; Check if steel stats are present
100
        corner_compass_ok := 1
101
    }
102
    condition_check := center_compass_ok + corner_compass_ok
103
    if (condition_check = 2) {
104
        return 1
105
    } else {
106
        return 0
107
    }
108
}
109
110
formation_select_check() ; Checks if the current screen is the formation selection screen
111
{
112
	MouseMove 30, 430, 1 ; Moves mouse out of the way
113
    PixelSearch corner_compass_x, corner_compass_y, 56, 463, 65, 477, 0x07098C, 15, fast
114
    if (corner_compass_y < 476) { ; Check if corner compass is present
115
        corner_compass_ok := 1
116
    }
117
    PixelSearch line_ahead_dot_x, line_ahead_dot_y, 447, 146, 460, 158, 0x83FF5D, 5, fast
118
    if (line_ahead_dot_y < 157) { ; Check if green dot in line ahead formation is present
119
        line_ahead_dot_ok := 1
120
    }
121
	PixelSearch diamond_dot_x, diamond_dot_y, 711, 160, 722, 170, 0x83FF5D, 5, fast
122
    if (diamond_dot_y < 169) { ; Check if green dot in diamond formation is present
123
        diamond_dot_ok := 1
124
    }
125
    PixelSearch echelon_text_x, echelon_text_y, 515, 379, 530, 395, 0xF2F6FF, 5, fast
126
    if (echolon_text_y < 394) { ; Check echelon white text is present
127
        echelon_test_ok := 1
128
    }
129
	condition_check := corner_compass_ok + line_ahead_dot_ok + diamond_dot_ok + echelon_test_ok
130
	if (condition_check = 4) { ; Check if all are present
131
		return 1
132
	} else {
133
		return 0
134
	}
135
}
136
137
night_battle_decision() ; Checks if the current screen is the night battle decision screen
138
{
139
    MouseMove 30, 430, 1 ; Moves mouse out of the way
140
    PixelSearch retreat_x, retreat_y, 281, 267, 301, 288, 0xFFFFFF, 5, fast
141
    if (retreat_y < 287) { ; Check if left button is present
142
        retreat_button_ok := 1
143
    }
144
    PixelSearch night_x, night_y, 500, 266, 520, 288, 0xFFFFFF, 5, fast
145
    if (night_y < 287) { ; Check if right button is present
146
        night_battle_ok := 1
147
    }
148
    PixelSearch blue_gear_x, blue_gear_y, 18, 68, 36, 91, 0xC0BD1D, 5, fast
149
    if (blue_gear_y < 90) { ; Check if top left gear is present
150
        blue_gear_ok := 1
151
    }
152
    PixelSearch gray_bar_x, gray_bar_y, 153, 78, 163, 92, 0x2B2A26, 5, fast
153
    if (gray_bar_y < 91) { ; Check if top left gray background is present
154
        gray_bar_ok := 1
155
    }
156
    condition_check := retreat_button_ok + night_battle_ok + blue_gear_ok + gray_bar_ok
157
    if (condition_check = 4) {
158
        return 1
159
    } else {
160
        return 0
161
    }
162
163
}
164
165
retreat_decision() ; Checks if the current screen is the retreat decision screen
166
{
167
    MouseMove 30, 430, 1 ; Moves mouse out of the way
168
    PixelSearch retreat_x, retreat_y, 281, 267, 301, 288, 0xFFFFFF, 5, fast
169
    if (retreat_y < 287) { ; Check if left button is present
170
        retreat_button_ok := 1
171
    }
172
    PixelSearch night_x, night_y, 500, 266, 520, 288, 0xFFFFFF, 5, fast
173
    if (night_y < 287) { ; Check if right button is present
174
        night_battle_ok := 1
175
    }
176
;    PixelSearch blue_gear_x, blue_gear_y, 18, 68, 36, 91, 0xC0BD1D, 5, fast
177
;    if (blue_gear_y < 90) { ; Check if top left gear is present
178
;        blue_gear_ok := 1
179
;    }
180
;    PixelSearch gray_bar_x, gray_bar_y, 153, 78, 163, 92, 0x2B2A26, 5, fast
181
;    if (gray_bar_y < 91) { ; Check if top left gray background is present
182
;        gray_bar_ok := 1
183
;    }
184
    condition_check := retreat_button_ok + night_battle_ok  ; + blue_gear_ok + gray_bar_ok
185
    if (condition_check = 2) {
186
        return 1
187
    } else {
188
        return 0
189
    }
190
191
}
192
193
expedition_1:
194
    expedition_1_timer_complete := 1
195
return
196
197
expedition_2:
198
    expedition_2_timer_complete := 1
199
return
200
201
expedition_complete_check() ; Check if expeditions are done and deal with the pop ups
202
{
203
MsgBox, %expedition_1_timer_complete%
204
    if (expedition_1_timer_complete = 1) { ; expedition 1 end check
205
        Click 52, 492, 1 ; Click somewhere to get expedition results
206
        is_expedition_1_results_over_yet := 0 ; Flag to check if it's really over yet
207
        While (is_expedition_1_results_over_yet = 0) {
208
            loop 12 { ; Keep clicking in the corner till it's done
209
                rand_sleep(2500, 3500) 
210
                Click 52, 492, 1
211
            }
212
            if (home_screen_check() = 1) { ; Is it REALLY done yet?
213
                is_expedition_1_results_over_yet := 1
214
            }
215
        }
216
        expedition_1_fuel_pending := 1
217
        expedition_1_timer_complete := 0
218
    }
219
    
220
    if (expedition_2_timer_complete = 1) { ; expedition 2 end check
221
        Click 52, 492, 1 ; Click somewhere to get expedition results
222
        is_expedition_2_results_over_yet := 0 ; Flag to check if it's really over yet
223
        While (is_expedition_2_results_over_yet = 0) {
224
            loop 12 { ; Keep clicking in the corner till it's done
225
                rand_sleep(2500, 3500) 
226
                Click 52, 492, 1
227
            }
228
            if (home_screen_check() = 1) { ; Is it REALLY done yet?
229
                is_expedition_2_results_over_yet := 1
230
            }
231
        }
232
        expedition_2_fuel_pending := 1
233
        expedition_2_timer_complete := 0
234
    }
235
}
236
237
expedition_refuel() ; Refuel expedition fleets
238
{
239
    if (expedition_1_fuel_pending = 1 OR expedition_2_fuel_pending = 1) { ; Check if fleets are ready to be sent to an expedition
240
        Click 87, 259, 1 ; Click Resupply
241
        rand_sleep(7500, 8500)
242
        if (expedition_1_fuel_pending = 1) {
243
            Click 188, 159, 1 ; Click 2nd fleet
244
            rand_sleep(4500, 5500)
245
            Click 128, 160, 1 ; Click select all ships for resupply
246
            rand_sleep(2500, 3500)
247
            Click 708, 482, 1 ; Resupply fleet 2 ships
248
            rand_sleep(9500, 10500)
249
            expedition_1_dispatch_pending := 1
250
            expedition_1_fuel_pending := 0
251
        }
252
        if (expedition_2_fuel_pending = 1) {
253
            Click 247 161, 1 ; Click 4th fleet
254
            rand_sleep(4500, 5500)
255
            Click 128, 160, 1 ; Click select all ships for resupply
256
            rand_sleep(3000, 4000)
257
            Click 708, 482, 1 ; Resupply fleet 4 ships
258
            rand_sleep(9500, 10500)
259
            expedition_2_dispatch_pending := 1
260
            expedition_2_fuel_pending := 0
261
        }
262
    Click 83, 296, 1 ; Return to home
263
    rand_sleep(8000, 9000)
264
    }
265
}
266
267
expedition_send() ; and send them out to expeditions 2 (Fleet 2) and 5 (Fleet 4)
268
{
269
    if (expedition_1_dispatch_pending = 1 OR expedition_2_dispatch_pending = 1) {
270
        Click 210, 294, 1 ; Click on Shutsugeki button in home
271
        rand_sleep(5500, 6500)
272
        Click 686, 265, 1 ; Click on Expedition button
273
        rand_sleep(6500, 7500)
274
        if (expedition_1_dispatch_pending = 1) {
275
            Click 218, 247, 1 ; Select Expedition 2
276
            rand_sleep(4500, 5500)
277
            Click 218, 247, 1 ; Confirm Expedition 2
278
            rand_sleep(4500, 5500)
279
            Click 403, 172, 1 ; Select Fleet 2
280
            rand_sleep(5500, 6500)
281
            Click 635, 489, 1 ; Send out Fleet 2
282
            rand_sleep(1500, 3500)
283
            SetTimer, expedition_1, -1800000
284
            expedition_1_dispatch_pending := 0
285
            rand_sleep(8000, 9000)
286
         }
287
         rand_sleep(2000, 3000)
288
         if (expedition_2_dispatch_pending = 1) {
289
            Click 218, 335, 1 ; Select Expedition 5
290
            rand_sleep(4500, 5500)
291
            Click 688, 485, 1 ; Confirm Expedition 5
292
            rand_sleep(4500, 5500)
293
            Click 462, 170, 1 ; Select Fleet 4
294
            rand_sleep(5500, 6500)
295
            Click 635, 489, 1 ; Send out Fleet 4
296
            rand_sleep(1500, 3500)
297
            SetTimer, expedition_2, -5400000
298
            expedition_2_dispatch_pending := 0
299
            rand_sleep(8000, 9000)
300
         }
301
         Click 83, 296, 1 ; Return to home
302
         rand_sleep(8000, 9000)
303
    }
304
}
305
306
convert_time(time) ; Converts user inputted HH:MM:SS to ms for timer function
307
{
308
	hours := SubStr(%time%, 1, 2)
309
	hours_ms := hours*60*60*1000
310
	minutes := SubStr(%time%, 4, 2)
311
	minutes_ms := minutes*60*1000
312
	seconds := SubStr(%time%, 7, 2)
313
	seconds_ms := seconds*1000
314
	total_time_ms := hours_ms + minutes_ms + seconds_ms
315
	return %total_time_ms%
316
}
317
318
/*
319
##### End Functions #####
320
*/
321
322
!^o::
323
324
3_2_message := 0 ; Flag to check whether the user has input a valid input
325
While (3_2_message = 0) { ; Keep asking user until a valid input
326
	InputBox, sortie_mode_input, Select Sortie Mode, Do you want to run 2-3 for sub leveling and fuel`, 3-2 for sub leveling and steel or 3-2-A for levels. Use solo ship for 2-3 and 3-2.  Team is okay for 3-2-A.  Suggest a sub for all.`nA for 2-3 sub leveling and fuel. `nB for 3-2 sub leveling and steel`nC for 3-2-A Leveling.
327
	if (sortie_mode_input = "A" OR sortie_mode_input = "B" OR sortie_mode_input = "C") { ; Proceed if A, B, or C
328
		3_2_message := 1 ; Proceed outside the while loop.
329
	} else {
330
		MsgBox, Invalid Input.  Please put either A for 2-3 runs, B for 3-2 runs, or C for 3-2-A runs. Stop anytime with Ctrl+Alt+p.
331
	}
332
}
333
expedition_message := 0 ; Flag to check whether the user has input a valid input to run expeditions or not
334
While (expedition_message = 0) { ; Keep asking user until a valid input
335
	InputBox, expedition_trigger, Select Expedition Mode, Do you want to run expeditions on Fleets 2 and 4 as well?`nY/N ; Ask user whether to run expeditions on Fleets 2 and 4
336
	if (expedition_trigger = "Y" OR expedition_trigger = "N") { ; Proceed if Y or N
337
		expedition_message := 1 ; Escape while loop if Y or N
338
	} else { ; If the user put an invalid input
339
		MsgBox, Invalid Input.  Please put either Y for Yes (will run expeditions) or N for No (Will not run expeditions). Stop anytime with Ctrl+Alt+p.
340
	}
341
}
342
if (expedition_trigger = "Y") {  ; Expedition trigger.  before Ctrl + Alt + o to include expeditions
343
	expedition_1_message := 0 ; Flag to check whether the user has input a valid input for Fleet 2 remaining time
344
	While (expedition_1_message = 0) { ; Keep asking for Fleet 2 Remaining time until a valid input
345
		InputBox, expedition_1_remaining_input, Fleet 2 Expedition Remaining Time, Please input the remaining time until Fleet 2's expedition time is over.`nInput 0 if Fleet 2 is already home and ready for expedition 2. `nInput format HH:MM:SS
346
		expedition_1_remaining_ms := convert_time(%expedition_1_remaining_input%) ; Convert remaining time from HH:MM:SS to ms for timer
347
		if (expedition_1_remaining_ms>=0) { ; If we get a time value in milliseconds
348
			SetTimer, expedition_1, -%expedition_1_remaining_ms% ; Set the timer for when expeditions are over
349
			expedition_1_message := 1 ; And proceed outside the while loop
350
		} else if (expedition_1_remaining_input = 0) { ; If the user inputs 0
351
			SetTimer, expedition_1, -0 ; Set the timer to 0, and Fleet 2 will be sent out during expedition phase
352
			expedition_1_message :=1 ; Proceed out of the while loop
353
		} else { ; If the user put an invalid format
354
			MsgBox, Invalid Input.  Please input the remaining time for Fleet 2 to return in HH:MM:SS format. Stop anytime with Ctrl+Alt+p.
355
		}
356
	}
357
	expedition_2_message := 0 ; Flag to check whether the user has input a valid input for Fleet 4 remaining time
358
	While (expedition_2_message = 0) {
359
		InputBox, expedition_2_remaining_input, Fleet 4 Expedition Remaining Time, Please input the remaining time until Fleet 4's expedition time is over.`nInput 0 if Fleet 4 is already home and ready for expedition 5. `nInput format HH:MM:SS
360
		expedition_2_remaining_ms := convert_time(%expedition_2_remaining_input%) ; Convert remaining time from HH:MM:SS to ms for timer
361
		if (expedition_2_remaining_ms>=0) {
362
			SetTimer, expedition_2, -%expedition_2_remaining_ms%
363
			expedition_2_message := 1
364
		} else if (expedition_2_remaining_input = 0) {
365
			SetTimer, expedition_2, -0
366
			expedition_2_message :=1
367
		} else {
368
			MsgBox, Invalid Input.  Please input the remaining time for Fleet 4 to return in HH:MM:SS format. Stop anytime with Ctrl+Alt+p.
369
		}
370
	}
371
}
372
373
While (1>0) { ; Run this forever~
374
375
IfWinExist, Adobe Flash Player ; Make sure Adobe Flash Player is activated
376
	WinActivate, Adobe Flash Player
377
378
While (home_screen_check() = 0) {
379
    rand_sleep(1000, 1100)
380
}
381
Click 210, 294, 1 ; Click on Shutsugeki button in home
382
rand_sleep(3000, 4000)
383
Click 240, 265, 1 ; Shutsugeki~
384
rand_sleep(3000, 4000)
385
if (sortie_mode_input = "B" OR sortie_mode_input = "C") {
386
	Click 316, 488, 1 ; Select Stage 3
387
	rand_sleep(3000, 4000)
388
	Click 631, 248, 1 Select 3-2
389
	rand_sleep(3000, 4000)
390
} else {
391
	Click 243, 482 ; Select Stage 2
392
	rand_sleep(3000, 4000)
393
	Click 292, 387 ; Selects 2-3
394
	rand_sleep(3000, 4000)
395
}
396
Click 685, 487, 1 ; Confirm Stage Select
397
rand_sleep(3000, 4000)
398
Click 435, 158, 1 ; Select Fleet 3
399
rand_sleep(3000, 4000)
400
Click 633, 487 ; Begin Sortie-
401
rand_sleep(3000, 4000)
402
403
sortie_menu_check_flags := 0 ; Get too many and we're probably stuck
404
While (compass_check() = 0) { ; Wait till compass is out
405
    rand_sleep(1000, 1500)
406
	if (sortie_menu_check() = 1) { ; Check if we're stuck in the sortie menu.  Escape if we are
407
		sortie_menu_check_flags := sortie_menu_check_flags + 1
408
		if (sortie_menu_check_flags > 10) { ; We stuck
409
			Click 56, 84, 1 ; Click the big blue orb in the corner to go back to home
410
			rand_sleep(7000,9000)
411
			break ; Get out of the compass check loop
412
		}
413
	}		
414
	if (home_screen_check() = 1) { ; In case something weird happened and we're still in the home screen
415
		rand_sleep(4000,5000)
416
		break ; Get out of the compass check loop
417
	}
418
}
419
rand_sleep(1500, 2500)
420
Click 52, 492, 1 ; Spin the compass (click on bottom left corner)
421
422
if (sortie_mode_input = "C") { ; Run the 3-2-A leveling loop
423
	shutsugeki_chuu := 1 ; Currently in sortie.  Keep clicking/checking till out of sortie.
424
	While (shutsugeki_chuu = 1) {
425
	    rand_sleep(3000, 5000)
426
	    Click 52, 492, 1 ; Click in the corner
427
		if (formation_select_check() = 1) { ; Check if we're currently in the formation selection screen 
428
			Click 655, 390, 1 ; Select the Line Abreast formation for survivability
429
			rand_sleep(5000, 6000)
430
		}
431
	    if retreat_decision() {
432
			rand_sleep(1500,2500)
433
			if night_battle_decision() { ; Check if it's actually the night battle decision
434
		       	Click 290, 275, 1 ; Click left button to skip night battle
435
				rand_sleep(1000,2000)
436
			} else if retreat_decision() { ; Check again just to make sure it's an actual decision
437
				Click 510, 277, 1 ; Retreat after 3-2-A
438
			}
439
	        rand_sleep(3000, 5000)
440
	    } else if home_screen_check() {
441
	        shutsugeki_chuu := 0
442
	    }
443
	}
444
} else { ; Run the 2-3 or 3-2 solo sub leveling and resource gathering loop
445
	shutsugeki_chuu := 1 ; Currently in sortie.  Keep clicking/checking till out of sortie.
446
	While (shutsugeki_chuu = 1) {
447
	    rand_sleep(3000, 5000)
448
	    Click 52, 492, 1 ; Click in the corner
449
	    if retreat_decision() {
450
	        Click 290, 275, 1 ; Click left button to skip night battle / continue sortie
451
	        rand_sleep(3000, 5000)
452
	    } else if home_screen_check() {
453
	        shutsugeki_chuu := 0
454
	    }
455
	}
456
}
457
458
if (expedition_trigger = "Y") {
459
    expedition_complete_check() ; Check if expeditions are done.  Deal with popups if they are
460
    expedition_complete_check() ; One more check just in case another expedition completed during the first one
461
    expedition_refuel() ; Refuel expedition fleets
462
    expedition_complete_check() ; One more check in case another expedition completed dring refuel
463
    expedition_refuel() ; Another refuel attempt for the check one line above
464
    expedition_send() ; Send out fleets to expedition
465
    expedition_complete_check() ; Anoother check just in case expedition completes during prior send
466
    expedition_refuel() ; Another refuel attempt for the check one line above
467
    expedition_send() ; Another send out attempt for the check two lines above
468
}
469
470
Click 87, 259, 1 ; Click Resupply
471
rand_sleep(5000, 7000)
472
Click 216, 163, 1 ; Click 3rd fleet
473
rand_sleep(3000, 5000)
474
Click 128, 160, 1 ; Click select all ships for resupply
475
rand_sleep(2500, 4000)
476
Click 708, 482, 1 ; Resupply ships
477
rand_sleep(11000, 13000)
478
479
/*
480
##### Repairing #####
481
*/
482
483
Click 28, 355, 1 ; Click on Dock
484
rand_sleep(7000, 9000)
485
MouseMove 52, 492, 1
486
empty_dock := 0
487
dock_1_empty := 0 ; Assume dock 1 is full first
488
dock_2_empty := 0 ; Assume dock 2 is full first
489
While (empty_dock = 0) { ; Assuming only 2 docks available, wait till the dock is completely empty
490
	MouseMove 52, 492, 1
491
	PixelSearch dock_1_empty_x, dock_1_empty_y, 756, 188, 762, 194, 0xD4C3A9, 8, fast ; Check dock 1 if it's empty or not
492
	if (dock_1_empty_y < 193) {
493
		dock_1_empty := 1 ; Dock 1 is empty
494
	}
495
	PixelSearch dock_2_empty_x, dock_2_empty_y, 756, 253, 768, 268, 0xEDDAAB, 13, fast ; Check dock 2 if it's empty or not
496
	if (dock_2_empty_y < 267) {
497
		dock_2_empty := 1 ; Dock 2 is empty
498
	}
499
	if (dock_1_empty = 1 AND dock_2_empty = 1) { ; Check if dock slots 1 and 2 are empty
500
		empty_dock := 1 ; Proceed out of the loop if dock slots 1 and 2 are empty
501
	}
502
	rand_sleep(5000, 6000)
503
}
504
505
506
ships_are_healthy := 0 ; Assume there's a damaged ship
507
repairing_ship_pos_1 := 0 ; Assume that the dock isn't currently repairing any ships
508
repairing_ship_pos_2 := 0 ; So slots 2 and 3 aren't in the
509
repairing_ship_pos_3 := 0 ; Repairing state
510
dock_1_repairing_pos_1 := 0 ; Dock 1 is not repairing anything in position 1
511
dock_1_repairing_pos_2 := 0 ; Or in position 2
512
dock_2_repairing_pos_1 := 0 ; Dock 2 is not repairing anything in position 1
513
dock_2_repairing_pos_2 := 0 ; Or in position 2
514
final_ship_repairing := 0
515
While (ships_are_healthy = 0) { ; Loop until all ships are healthy
516
	if (final_ship_repairing = 0) { ; If there's more than the last one ship being repaired 
517
		if (dock_1_empty = 1) {
518
			Click 259, 205, 1 ; Click on the empty dock 1
519
			dock_1_selected := 1 ; Mark selected dock
520
		} else if (dock_2_empty = 1) {
521
			Click 263, 285, 1 ; Or click on the empty dock 2
522
			dock_2_selected := 1 ; Mark selected dock
523
		}
524
	}
525
	rand_sleep(5000,6000)
526
	MouseMove 52, 492, 1 ; Moves mouse out of the way
527
	if (dock_1_selected = 1 OR dock_2_selected = 1) {
528
		PixelSearch slot_1_x, slot_1_y, 626, 174, 634, 184, 0x00FF00, 0, fast
529
		if (slot_1_y < 183) { ; Check if first slot is damaged or not
530
		    healthy_ship_pos_1 := 1 ; Healthy ship in position 1
531
		} else {
532
			damaged_ship_pos_1 := 1 ; Damaged ship in position 1
533
		}
534
		PixelSearch slot_2_x, slot_2_y, 626, 205, 634, 215, 0x00FF00, 0, fast
535
		if (slot_2_y < 214) { ; Check if second slot is damaged or not
536
		    healthy_ship_pos_2 := 1 ; Healthy ship in position 2
537
		} else {
538
			damaged_ship_pos_2 := 1 ; Damaged ship in position 2
539
		}
540
		PixelSearch slot_3_x, slot_3_y, 626, 235, 634, 245, 0x00FF00, 0, fast
541
		if (slot_3_y < 244) { ; Check if third slot is damaged or not
542
		    healthy_ship_pos_3 := 1 ; Healthy ship in position 3
543
		} else {
544
			damaged_ship_pos_3 := 1 ; Damaged ship in position 3
545
		}
546
		if (damaged_ship_pos_1 AND repairing_ship_pos_1 AND healthy_ship_pos_2) { ; Check if the last ship is repairing
547
			final_ship_repairing := 1 ; Last ship repairing. Wait for it to finish
548
			Click 259, 205, 1 ; Slide out the select ship to repair tab
549
			rand_sleep(5000,8000)
550
			continue ; Go back and wait for the final ship
551
		}
552
		if (healthy_ship_pos_1 = 1 AND healthy_ship_pos_2 = 1 AND healthy_ship_pos_3 = 1) { ; If all ships are healthy
553
			final_ship_repairing := 1 ; Set to skip dock clicking check
554
			Click 259, 205, 1 ; Slide out the select ship to repair tab
555
			rand_sleep(5000,8000)
556
			continue ; Go back and get to the final check
557
		}
558
		if (damaged_ship_pos_1 = 1 AND repairing_ship_pos_1 = 0) { ; If there's a damaged ship in position 1 and no dock is repairing it
559
			Click 502, 181, 1 ; Click the first ship
560
		    rand_sleep(3000, 5000)
561
		    Click 696, 480 ; Begin docking
562
		    rand_sleep(3000, 5000)
563
		    Click 511, 442 ; Confirm Docking
564
		    rand_sleep(15000, 20000)
565
			if (dock_1_selected = 1) { ; Change currently selected dock 1 state
566
				While (dock_1_empty = 1) { ; Wait till Dock 1 is actually repairing
567
					PixelSearch repairing_1_x, repairing_1_y, 752, 177, 771, 195, 0x36D1B3, 10, fast
568
			        if (repairing_1_y < 194) { ; Check if ship is actually being repaired
569
						repairing_ship_pos_1 := 1 ; Position 1 being repaired
570
						dock_1_repairing_pos_1 := 1 ; Dock 1 is repairing position 1
571
						dock_1_empty := 0 ; Dock 1 no longer empty
572
						dock_1_selected := 0 ; Dock 1 no longer selected
573
					}
574
				}
575
			} else if (dock_2_selected = 1) { ; change currently selected dock 2 state
576
				While (dock_2_empty = 1) { ; Wait till Dock 2 is actually repairing
577
					PixelSearch repairing_2_x, repairing_2_y, 758, 255, 768, 268, 0x36D1B3, 8, fast ; ***************************
578
			        if (repairing_y < 194) { ; Check if ship is actually being repaired  *************
579
						repairing_ship_pos_1 := 1 ; Position 1 being repaired
580
						dock_2_repairing_pos_1 := 1 ; Dock 2 is repairing position 1
581
						dock_2_empty := 0 ; Dock 2 no longer empty
582
						dock_2_selected := 0 ; Dock 2 no longer selected
583
					}
584
				}
585
			}
586
		} else if (damaged_ship_pos_2 = 1 AND repairing_ship_pos_2 = 0) { ; If there's a damaged ship in position 2 and no dock is repairing it
587
			Click 448, 213, 1 ; Click the second ship
588
		    rand_sleep(3000, 5000)
589
		    Click 696, 480 ; Begin docking
590
		    rand_sleep(3000, 5000)
591
		    Click 511, 442 ; Confirm Docking
592
		    rand_sleep(15000, 20000)
593
			if (dock_1_selected = 1) { ; Change currently selected dock 1 state
594
				While (dock_1_empty = 1) { ; Wait till Dock 1 is actually repairing
595
					PixelSearch repairing_1_x, repairing_1_y, 752, 177, 771, 195, 0x36D1B3, 10, fast
596
			        if (repairing_1_y < 194) { ; Check if ship is actually being repaired
597
						repairing_ship_pos_2 := 1 ; Position 2 being repaired
598
						dock_1_repairing_pos_2 := 1 ; Dock 1 is repairing position 2
599
						dock_1_empty := 0 ; Dock 1 no longer empty
600
						dock_1_selected := 0 ; Dock 1 no longer selected
601
					}
602
				}
603
			} else if (dock_2_selected = 1) { ; change currently selected dock 2 state
604
				While (dock_2_empty = 1) { ; Wait till Dock 2 is actually repairing
605
					PixelSearch repairing_2_x, repairing_2_y, 758, 255, 768, 273, 0x36D1B3, 8, fast
606
			        if (repairing_y < 272) { ; Check if ship is actually being repaired 
607
						repairing_ship_pos_2 := 1 ; Position 2 being repaired
608
						dock_2_repairing_pos_2 := 1 ; Dock 2 is repairing position 2
609
						dock_2_empty := 0 ; Dock 2 no longer empty
610
						dock_2_selected := 0 ; Dock 2 no longer selected
611
					}
612
				}
613
			}
614
		}
615
	}
616
617
	MouseMove 52, 492, 1
618
	rand_sleep(1000,1500)
619
	if (dock_1_empty = 0) { ; If dock 1 is occupied, check if repairs have finished and it has become empty
620
		PixelSearch dock_1_empty_x, dock_1_empty_y, 756, 188, 762, 194, 0xD4C3A9, 8, fast ; Check dock 1 if it's empty or not
621
		if (dock_1_empty_y < 193) {
622
			dock_1_empty := 1 ; Repairs have finished and dock 1 is now empty
623
			if (dock_1_repairing_pos_1 = 1) { ; If dock 1 was repairing position 1, move position 2 up	
624
				dock_1_repairing_pos_1 := 0 ; Dock 1 finished repairing position 1
625
				repairing_ship_pos_1 := 0 ; Position 1 might not be being repaired anymore
626
				if (repairing_ship_pos_2 = 1) { ; But if position 2 was under repair 
627
					repairing_ship_pos_1 := 1 ; Position 2 becomes position 1 and is now under repair
628
					repairing_ship_pos_2 := 0 ; And position 2 is now no longer under repair
629
					dock_2_repairing_pos_1 := 1 ; Likewise dock 2 is now repairing position 1
630
					dock_2_repairing_pos_2 := 0 ; And dock 2 is no longer repairing position 2
631
				}
632
			} else if (dock_1_repairing_pos_2 = 1) { ; If dock 1 was repairing position 2
633
				dock_1_repairing_pos_2 := 0 ; Dock 1 is no longer repairing position 2
634
				repairing_ship_pos_2 := ; Position 2 is no longer under repair
635
			}
636
		}
637
	}
638
	if (dock_2_empty = 0) { ; If dock 2 is occupied, check if repairs have finished and it has become empty
639
		PixelSearch dock_2_empty_x, dock_2_empty_y, 756, 253, 768, 268, 0xEDDAAB, 13, fast ; Check dock 2 if it's empty or not
640
		if (dock_2_empty_y < 267) {
641
			dock_2_empty := 1 ; Repairs have finished and dock 2 is now empty
642
			if (dock_2_repairing_pos_1 = 1) { ; If dock 2 was repairing position 1, move position 2 up	
643
				dock_2_repairing_pos_1 := 0 ; Dock 2 finished repairing position 1
644
				repairing_ship_pos_1 := 0 ; Position 1 might not be being repaired anymore
645
				if (repairing_ship_pos_2 = 1) { ; But if position 2 was under repair 
646
					repairing_ship_pos_1 := 1 ; Position 2 becomes position 1 and is now under repair
647
					repairing_ship_pos_2 := 0 ; And position 2 is now no longer under repair
648
					dock_1_repairing_pos_1 := 1 ; Likewise dock 1 is now repairing position 1
649
					dock_1_repairing_pos_2 := 0 ; And dock 1 is no longer repairing position 2
650
				}
651
			} else if (dock_2_repairing_pos_2 = 1) { ; If dock 2 was repairing position 2
652
				dock_2_repairing_pos_2 := 0 ; Dock 2 is no longer repairing position 2
653
				repairing_ship_pos_2 := ; Position 2 is no longer under repair
654
			}
655
		}
656
	}
657
	rand_sleep(4000,5000)
658
	if (dock_1_empty = 1 AND dock_2_empty = 1) {  ; Final health check
659
		Click 259, 205 ; Select an arbitrary dock to see the repair ship select screen
660
		rand_sleep(6000,8000)
661
		PixelSearch slot_1_x, slot_1_y, 626, 174, 634, 184, 0x00FF00, 0, fast
662
		if (slot_1_y < 183) { ; Check if first slot is damaged or not
663
		    healthy_ship_pos_1 := 1 ; Healthy ship in position 1
664
		} else {
665
			damaged_ship_pos_1 := 1 ; Damaged ship in position 1
666
			final_ship_repairing := 0 ; Unset final ship flag if it was somehow turned on
667
		}
668
		PixelSearch slot_2_x, slot_2_y, 626, 205, 634, 215, 0x00FF00, 0, fast
669
		if (slot_2_y < 214) { ; Check if second slot is damaged or not
670
		    healthy_ship_pos_2 := 1 ; Healthy ship in position 2
671
		} else {
672
			damaged_ship_pos_2 := 1 ; Damaged ship in position 2
673
			final_ship_repairing := 0 ; Unset final ship flag if it was somehow turned on
674
		}
675
		PixelSearch slot_3_x, slot_3_y, 626, 235, 634, 245, 0x00FF00, 0, fast
676
		if (slot_3_y < 244) { ; Check if third slot is damaged or not
677
		    healthy_ship_pos_3 := 1 ; Healthy ship in position 3
678
		} else {
679
			damaged_ship_pos_3 := 1 ; Damaged ship in position 3
680
			final_ship_repairing := 0 ; Unset final ship flag if it was somehow turned on
681
		}
682
		healthy_check := healthy_ship_pos_1 + healthy_ship_pos_2 + healthy_ship_pos_3
683
		if (healthy_check = 3) {
684
			ships_are_healthy := 1
685
		}
686
		Click 259, 205 ; Slide out repair ship selection
687
		rand_sleep(5000, 6000)
688
	}
689
	if (expedition_trigger = "Y") { ; If expeditions are done may as well complete them while waiting on repairs
690
		if (expedition_1_timer_complete = 1 OR expedition_2_timer_complete = 1) { ; Check if any expeditions are complete
691
			Click 56, 84, 1 ; Click the big blue orb in the corner to go back to home
692
			rand_sleep(8000,10000)
693
			expedition_complete_check() ; Check if expeditions are done.  Deal with popups if they are
694
			expedition_complete_check() ; One more check just in case another expedition completed during the first one
695
			expedition_refuel() ; Refuel expedition fleets
696
			expedition_complete_check() ; One more check in case another expedition completed dring refuel
697
			expedition_refuel() ; Another refuel attempt for the check one line above
698
			expedition_send() ; Send out fleets to expedition
699
			expedition_complete_check() ; Anoother check just in case expedition completes during prior send
700
			expedition_refuel() ; Another refuel attempt for the check one line above
701
			expedition_send() ; Another send out attempt for the check two lines above
702
			Click  131, 403, 1 ; Return to the docks and continue repairing 
703
			rand_sleep(8000,10000)
704
		}
705
	}
706
}	
707
708
709
/*
710
##### End Repairing #####
711
*/ 
712
713
Click 83, 296, 1 ; Click back to home
714
rand_sleep(6000, 8000)
715
716
if (expedition_trigger = "Y") {
717
	expedition_complete_check() ; Check if expeditions are done.  Deal with popups if they are
718
	expedition_complete_check() ; One more check just in case another expedition completed during the first one
719
	expedition_refuel() ; Refuel expedition fleets
720
	expedition_complete_check() ; One more check in case another expedition completed dring refuel
721
	expedition_refuel() ; Another refuel attempt for the check one line above
722
	expedition_send() ; Send out fleets to expedition
723
	expedition_complete_check() ; Anoother check just in case expedition completes during prior send
724
	expedition_refuel() ; Another refuel attempt for the check one line above
725
	expedition_send() ; Another send out attempt for the check two lines above
726
}
727
728
}
729
730
return