This repository has been archived by the owner on Apr 19, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathfleet.py
83 lines (68 loc) · 2.71 KB
/
fleet.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
from sikuli import Pattern
from threading import Thread
from util import Util
class Fleet(object):
"""Base Fleet class, extended by ExpeditionFleet and CombatFleet in the
Expedition and Combat modules, respectively.
Attributes:
at_base (bool): specifies whether or not the fleet is currently at base
and not conducting a sortie
fleet_id (int): id of the fleet, 1~4
needs_resupply (bool): specifies whether or not the fleet needs to be
resupplied
"""
fleet_id = None
fleet_type = None
at_base = True
needs_resupply = False
def __init__(self, id):
"""Initializes the Fleet object.
Args:
id (int): id of the fleet
"""
self.fleet_id = id
def print_state(self):
"""Method to print the at_base and needs_resupply state of the fleet.
"""
Util.log_msg("Fleet {}: at base '{}' needs resupply '{}'".format(
self.fleet_id, self.at_base, self.needs_resupply))
Util.log_msg(self.damage_counts)
def check_supplies(self, region):
"""Method to multithread the detection of fleet supply states
pre-expedition or pre-sortie.
Args:
region (Region): Region in which to search for the supply states
Returns:
bool: False if the fleet needs resupply, True otherwise
"""
thread_check_alert = Thread(
target=self._check_supplies_func, args=('', region))
thread_check_alert_red = Thread(
target=self._check_supplies_func, args=('_red', region))
Util.multithreader([thread_check_alert, thread_check_alert_red])
if self.needs_resupply:
Util.log_warning("Fleet needs resupply!")
self.at_base = True
return False
return True
def _check_supplies_func(self, type, region):
"""Child multithreaded method for checking supply states.
Args:
type (str): which supply state to check for
region (Region): Region in which to search for the supply state
"""
if region.exists('resupply_alert{}.png'.format(type)):
self.needs_resupply = True
@staticmethod
def switch(region, fleet):
"""Method that switches to the specified fleet by pressing the fleet
icon in the specified region.
Args:
region (Region): sikuli Region in which to search for the fleet
icons
fleet (int): id of fleet to switch to
"""
Util.wait_and_click_and_wait(
region, Pattern('fleet_{}.png'.format(fleet)).exact(),
region, Pattern('fleet_{}_active.png'.format(fleet)).exact())
Util.kc_sleep()