2020-05-01 09:54:24 +00:00
|
|
|
import numpy as np
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.base.timer import Timer
|
2020-05-01 09:54:24 +00:00
|
|
|
from module.base.utils import color_similarity_2d
|
2020-04-29 09:45:35 +00:00
|
|
|
from module.exception import CampaignEnd
|
|
|
|
from module.exception import ScriptEnd
|
2020-04-09 13:22:01 +00:00
|
|
|
from module.handler.fast_forward import FastForwardHandler
|
2020-04-15 07:14:35 +00:00
|
|
|
from module.handler.mystery import MysteryHandler
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.logger import logger
|
|
|
|
from module.map.assets import *
|
|
|
|
from module.map.map_fleet_preparation import FleetPreparation
|
|
|
|
from module.retire.retirement import Retirement
|
|
|
|
|
|
|
|
|
2020-05-15 06:18:14 +00:00
|
|
|
class MapOperation(MysteryHandler, FleetPreparation, Retirement, FastForwardHandler):
|
2020-05-01 09:54:24 +00:00
|
|
|
map_cat_attack_timer = Timer(2)
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
def fleet_switch_click(self):
|
|
|
|
"""
|
|
|
|
Switch fleet.
|
|
|
|
"""
|
|
|
|
logger.info('Switch over')
|
|
|
|
if self.appear_then_click(SWITCH_OVER):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
logger.warning('No buttons detected.')
|
|
|
|
|
|
|
|
self.device.sleep((1, 1.5))
|
|
|
|
# self.ensure_no_info_bar()
|
|
|
|
|
|
|
|
def enter_map(self, button, mode='normal'):
|
|
|
|
"""Enter a campaign.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
button: Campaign to enter.
|
|
|
|
mode (str): 'normal' or 'hard' or 'cd'
|
|
|
|
"""
|
|
|
|
logger.hr('Enter map')
|
|
|
|
campaign_timer = Timer(2)
|
|
|
|
map_timer = Timer(1)
|
|
|
|
fleet_timer = Timer(1)
|
|
|
|
checked_in_map = False
|
|
|
|
while 1:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if not checked_in_map and self.is_in_map():
|
2020-03-30 04:27:18 +00:00
|
|
|
logger.info('Already in map, skip enter_map.')
|
2020-03-28 17:22:46 +00:00
|
|
|
return False
|
|
|
|
else:
|
|
|
|
checked_in_map = True
|
|
|
|
|
|
|
|
# Map preparation
|
|
|
|
if map_timer.reached() and self.appear(MAP_PREPARATION):
|
2020-04-14 09:32:26 +00:00
|
|
|
self.device.sleep(0.3) # Wait for map information.
|
|
|
|
self.device.screenshot()
|
2020-04-24 07:26:11 +00:00
|
|
|
if self.handle_map_clear_mode_stop():
|
|
|
|
self.enter_map_cancel()
|
|
|
|
raise ScriptEnd(f'Reach condition: {self.config.CLEAR_MODE_STOP_CONDITION}')
|
2020-04-09 13:22:01 +00:00
|
|
|
self.handle_fast_forward()
|
2020-03-28 17:22:46 +00:00
|
|
|
self.device.click(MAP_PREPARATION)
|
|
|
|
map_timer.reset()
|
|
|
|
campaign_timer.reset()
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Fleet preparation
|
|
|
|
if fleet_timer.reached() and self.appear(FLEET_PREPARATION):
|
|
|
|
if self.config.ENABLE_FLEET_CONTROL:
|
|
|
|
if mode == 'normal' or mode == 'hard':
|
|
|
|
self.fleet_preparation()
|
|
|
|
self.device.click(FLEET_PREPARATION)
|
|
|
|
fleet_timer.reset()
|
|
|
|
campaign_timer.reset()
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Retire
|
|
|
|
if self.handle_retirement():
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Emotion
|
Add: 适配第一章, 修复大量bug
- 修复处理夜间委托时, 出现递归调用的问题
- 增加红脸出击确认的功能
- 增加了透视识别错误图片保存的开关
- 修复了地图太小时, 透视识别报错的问题
- 修复了相机位于地图外时, 透视识别出错的问题
- 修复了离开退役时, 会连击的问题
- 修复了同时出现低心情和船坞已满弹窗时, 卡住的问题
- 更新了一键退役实装后的安全点击的位置
- 修复了换装滑动失败时, 卡住的问题
- 修复了关闭自动收获后, 出现委托完成的提示是, 进图卡住的问题
- 修复了, 无正在跑的委托时, 报错的问题
2020-04-11 07:23:51 +00:00
|
|
|
if self.handle_combat_low_emotion():
|
|
|
|
continue
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
# Urgent commission
|
|
|
|
if self.handle_urgent_commission():
|
|
|
|
continue
|
|
|
|
|
2020-04-24 07:26:11 +00:00
|
|
|
# Story skip
|
|
|
|
if self.handle_story_skip():
|
2020-04-30 15:40:29 +00:00
|
|
|
campaign_timer.reset()
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Enter campaign
|
|
|
|
if campaign_timer.reached() and self.is_in_stage():
|
|
|
|
self.device.click(button)
|
|
|
|
campaign_timer.reset()
|
2020-04-24 07:26:11 +00:00
|
|
|
continue
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
# End
|
|
|
|
if self.handle_in_map_with_enemy_searching():
|
|
|
|
break
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2020-04-24 07:26:11 +00:00
|
|
|
def enter_map_cancel(self, skip_first_screenshot=True):
|
|
|
|
logger.hr('Enter map cancel')
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if self.appear(MAP_PREPARATION) or self.appear(FLEET_PREPARATION):
|
|
|
|
self.device.click(MAP_PREPARATION_CANCEL)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if self.is_in_stage():
|
|
|
|
break
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
def withdraw(self):
|
|
|
|
"""
|
|
|
|
Withdraw campaign.
|
|
|
|
"""
|
|
|
|
logger.hr('Map withdraw')
|
|
|
|
while 1:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
2020-04-13 15:00:19 +00:00
|
|
|
if self.handle_popup_confirm():
|
2020-03-28 17:22:46 +00:00
|
|
|
continue
|
2020-04-12 05:54:06 +00:00
|
|
|
if self.appear_then_click(WITHDRAW, interval=2):
|
|
|
|
continue
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
# End
|
|
|
|
if self.handle_in_stage():
|
|
|
|
raise CampaignEnd('Withdraw')
|
|
|
|
|
|
|
|
def handle_map_cat_attack(self):
|
|
|
|
"""
|
|
|
|
Click to skip the animation when cat attacks.
|
|
|
|
"""
|
2020-05-01 09:54:24 +00:00
|
|
|
if not self.map_cat_attack_timer.reached():
|
|
|
|
return False
|
|
|
|
if np.sum(color_similarity_2d(self.image_area(MAP_CAT_ATTACK), (255, 231, 123)) > 221) > 100:
|
2020-03-28 17:22:46 +00:00
|
|
|
logger.info('Skip map cat attack')
|
2020-05-02 07:07:30 +00:00
|
|
|
self.device.click(MAP_CAT_ATTACK)
|
2020-05-01 09:54:24 +00:00
|
|
|
self.map_cat_attack_timer.reset()
|
2020-03-28 17:22:46 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def handle_fleet_reverse(self):
|
|
|
|
"""
|
|
|
|
The game chooses the fleet with a smaller index to be the first fleet,
|
|
|
|
no matter what we choose in fleet preparation.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: Fleet changed
|
|
|
|
"""
|
|
|
|
if (self.config.FLEET_2 == 0) or (self.config.FLEET_2 > self.config.FLEET_1):
|
|
|
|
return False
|
|
|
|
|
|
|
|
self.fleet_switch_click()
|
|
|
|
return True
|
|
|
|
|
|
|
|
def handle_spare_fleet(self):
|
|
|
|
pass
|