2020-04-09 17:13:02 +00:00
|
|
|
import numpy as np
|
2020-05-15 06:18:14 +00:00
|
|
|
|
2020-04-09 16:55:49 +00:00
|
|
|
from module.base.switch import Switch
|
|
|
|
from module.handler.assets import *
|
2020-05-15 06:18:14 +00:00
|
|
|
from module.handler.info_handler import InfoHandler
|
2020-04-09 16:55:49 +00:00
|
|
|
from module.logger import logger
|
2020-05-15 06:18:14 +00:00
|
|
|
from module.template.assets import TEMPLATE_FORMATION_1, TEMPLATE_FORMATION_2, TEMPLATE_FORMATION_3
|
2020-04-09 16:55:49 +00:00
|
|
|
|
|
|
|
formation = Switch('Formation')
|
|
|
|
formation.add_status('1', check_button=FORMATION_1, offset=120)
|
|
|
|
formation.add_status('2', check_button=FORMATION_2, offset=120)
|
|
|
|
formation.add_status('3', check_button=FORMATION_3, offset=120)
|
|
|
|
|
|
|
|
submarine_view = Switch('Submarine_view')
|
|
|
|
submarine_view.add_status('on', check_button=SUBMARINE_VIEW_ON, offset=120)
|
|
|
|
submarine_view.add_status('off', check_button=SUBMARINE_VIEW_OFF, offset=120)
|
|
|
|
|
|
|
|
submarine_hunt = Switch('Submarine_hunt')
|
|
|
|
submarine_hunt.add_status('on', check_button=SUBMARINE_HUNT_ON, offset=120)
|
|
|
|
submarine_hunt.add_status('off', check_button=SUBMARINE_HUNT_OFF, offset=120)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
|
2020-05-15 06:18:14 +00:00
|
|
|
class StrategyHandler(InfoHandler):
|
2020-04-09 16:55:49 +00:00
|
|
|
fleet_1_formation_fixed = False
|
|
|
|
fleet_2_formation_fixed = False
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
def handle_opened_strategy_bar(self):
|
2020-04-09 16:55:49 +00:00
|
|
|
if self.appear_then_click(STRATEGY_OPENED, offset=120):
|
2020-03-28 17:22:46 +00:00
|
|
|
self.device.sleep(0.5)
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2020-04-09 16:55:49 +00:00
|
|
|
|
|
|
|
def strategy_open(self):
|
|
|
|
self.device.click(STRATEGY_OPEN)
|
|
|
|
self.device.sleep(0.5)
|
|
|
|
|
|
|
|
def strategy_close(self):
|
|
|
|
self.appear_then_click(STRATEGY_OPENED, offset=120)
|
|
|
|
self.device.sleep(0.5)
|
|
|
|
|
|
|
|
def strategy_set_execute(self, formation_index=2, sub_view=False, sub_hunt=False):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
formation_index (int):
|
|
|
|
sub_view (bool):
|
|
|
|
sub_hunt (bool):
|
|
|
|
"""
|
|
|
|
logger.info(f'Strategy set: formation={formation_index}, submarine_view={sub_view}, submarine_hunt={sub_hunt}')
|
|
|
|
self.strategy_open()
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
formation.set(str(formation_index), main=self)
|
2020-06-06 07:43:38 +00:00
|
|
|
# Disable this until the icon bug of submarine zone is fixed
|
|
|
|
# And don't enable MAP_HAS_DYNAMIC_RED_BORDER when using submarine
|
|
|
|
# if submarine_view.appear(main=self):
|
|
|
|
# submarine_view.set('on' if sub_view else 'off', main=self)
|
2020-04-09 16:55:49 +00:00
|
|
|
if submarine_hunt.appear(main=self):
|
|
|
|
submarine_hunt.set('on' if sub_hunt else 'off', main=self)
|
|
|
|
|
|
|
|
self.strategy_close()
|
|
|
|
|
|
|
|
def handle_strategy(self, index):
|
|
|
|
"""
|
|
|
|
|
|
|
|
Args:
|
|
|
|
index (int): Fleet index.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: If changed.
|
|
|
|
"""
|
2020-04-09 17:13:02 +00:00
|
|
|
if not self.config.ENABLE_FLEET_CONTROL:
|
|
|
|
return False
|
2020-04-09 16:55:49 +00:00
|
|
|
if self.__getattribute__(f'fleet_{index}_formation_fixed'):
|
|
|
|
return False
|
2020-04-09 17:13:02 +00:00
|
|
|
expected_formation = self.config.__getattribute__(f'FLEET_{index}_FORMATION')
|
|
|
|
if self._strategy_get_from_map_buff() == expected_formation and not self.config.SUBMARINE:
|
|
|
|
logger.info('Skip strategy bar check.')
|
|
|
|
self.__setattr__(f'fleet_{index}_formation_fixed', True)
|
|
|
|
return False
|
2020-04-09 16:55:49 +00:00
|
|
|
|
|
|
|
self.strategy_set_execute(
|
2020-04-09 17:13:02 +00:00
|
|
|
formation_index=expected_formation,
|
2020-04-09 16:55:49 +00:00
|
|
|
sub_view=False,
|
2020-04-18 08:19:31 +00:00
|
|
|
sub_hunt=bool(self.config.SUBMARINE) and self.config.SUBMARINE_MODE == 'hunt_only'
|
2020-04-09 16:55:49 +00:00
|
|
|
)
|
|
|
|
self.__setattr__(f'fleet_{index}_formation_fixed', True)
|
|
|
|
return True
|
2020-04-09 17:13:02 +00:00
|
|
|
|
|
|
|
def _strategy_get_from_map_buff(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
int: Formation index.
|
|
|
|
"""
|
|
|
|
image = np.array(self.device.image.crop(MAP_BUFF.area))
|
|
|
|
if TEMPLATE_FORMATION_2.match(image):
|
2020-04-10 03:05:06 +00:00
|
|
|
buff = 2
|
2020-04-09 17:13:02 +00:00
|
|
|
elif TEMPLATE_FORMATION_1.match(image):
|
2020-04-10 03:05:06 +00:00
|
|
|
buff = 1
|
2020-04-09 17:13:02 +00:00
|
|
|
elif TEMPLATE_FORMATION_3.match(image):
|
2020-04-10 03:05:06 +00:00
|
|
|
buff = 3
|
2020-04-09 17:13:02 +00:00
|
|
|
else:
|
2020-04-10 03:05:06 +00:00
|
|
|
buff = 0
|
|
|
|
|
|
|
|
logger.attr('Map_buff', buff)
|
|
|
|
return buff
|