2020-04-12 13:54:06 +08:00
|
|
|
import numpy as np
|
|
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
from module.base.timer import Timer
|
|
|
|
|
from module.combat.assets import *
|
2020-04-11 21:12:54 +08:00
|
|
|
from module.combat.combat_auto import CombatAuto
|
|
|
|
|
from module.combat.combat_manual import CombatManual
|
2020-03-29 01:22:46 +08:00
|
|
|
from module.combat.hp_balancer import HPBalancer
|
2020-10-05 20:45:08 +08:00
|
|
|
from module.combat.level import Level
|
2020-04-10 12:05:16 +08:00
|
|
|
from module.combat.submarine import SubmarineCall
|
2021-01-28 00:35:15 +08:00
|
|
|
from module.handler.auto_search import AutoSearchHandler
|
2020-03-29 01:22:46 +08:00
|
|
|
from module.logger import logger
|
|
|
|
|
from module.map.assets import MAP_OFFENSIVE
|
|
|
|
|
from module.retire.retirement import Retirement
|
2021-09-15 21:33:11 +08:00
|
|
|
from module.statistics.azurstats import DropImage
|
2020-07-10 00:40:01 +08:00
|
|
|
from module.template.assets import TEMPLATE_COMBAT_LOADING
|
2020-03-29 01:22:46 +08:00
|
|
|
from module.ui.assets import BACK_ARROW
|
|
|
|
|
|
|
|
|
|
|
2021-01-28 00:35:15 +08:00
|
|
|
class Combat(Level, HPBalancer, Retirement, SubmarineCall, CombatAuto, CombatManual, AutoSearchHandler):
|
2020-03-29 01:22:46 +08:00
|
|
|
_automation_set_timer = Timer(1)
|
2020-04-15 21:44:11 +08:00
|
|
|
battle_status_click_interval = 0
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
def combat_appear(self):
|
|
|
|
|
"""
|
|
|
|
|
Returns:
|
|
|
|
|
bool: If enter combat.
|
|
|
|
|
"""
|
2021-09-15 21:33:11 +08:00
|
|
|
if self.config.Campaign_UseFleetLock and not self.is_in_map():
|
2020-03-29 01:22:46 +08:00
|
|
|
if self.is_combat_loading():
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
if self.appear(BATTLE_PREPARATION):
|
|
|
|
|
return True
|
|
|
|
|
if self.appear(BATTLE_PREPARATION_WITH_OVERLAY) and self.handle_combat_automation_confirm():
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2021-11-21 16:24:26 +08:00
|
|
|
def map_offensive(self, skip_first_screenshot=True):
|
|
|
|
|
"""
|
|
|
|
|
Pages:
|
|
|
|
|
in: in_map, MAP_OFFENSIVE
|
|
|
|
|
out: combat_appear
|
|
|
|
|
"""
|
2020-03-29 01:22:46 +08:00
|
|
|
while 1:
|
2021-11-21 16:24:26 +08:00
|
|
|
if skip_first_screenshot:
|
|
|
|
|
skip_first_screenshot = False
|
|
|
|
|
else:
|
|
|
|
|
self.device.screenshot()
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
if self.appear_then_click(MAP_OFFENSIVE, interval=1):
|
|
|
|
|
continue
|
2020-04-25 20:51:15 +08:00
|
|
|
if self.handle_combat_low_emotion():
|
2021-11-21 16:24:26 +08:00
|
|
|
self.interval_reset(MAP_OFFENSIVE)
|
2020-04-25 20:51:15 +08:00
|
|
|
continue
|
2020-06-01 17:26:35 +08:00
|
|
|
if self.handle_retirement():
|
|
|
|
|
continue
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
# Break
|
|
|
|
|
if self.combat_appear():
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
def is_combat_loading(self):
|
|
|
|
|
"""
|
|
|
|
|
Returns:
|
|
|
|
|
bool:
|
|
|
|
|
"""
|
2022-01-23 15:50:15 +08:00
|
|
|
similarity, button = TEMPLATE_COMBAT_LOADING.match_result(self.image_crop((0, 620, 1280, 720)))
|
2020-07-10 00:40:01 +08:00
|
|
|
if similarity > 0.85:
|
2021-06-30 13:59:24 +08:00
|
|
|
loading = (button.area[0] + 38 - LOADING_BAR.area[0]) / (LOADING_BAR.area[2] - LOADING_BAR.area[0])
|
2020-07-10 00:40:01 +08:00
|
|
|
logger.attr('Loading', f'{int(loading * 100)}%')
|
2020-03-29 01:22:46 +08:00
|
|
|
return True
|
2020-07-10 00:40:01 +08:00
|
|
|
else:
|
|
|
|
|
return False
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
def is_combat_executing(self):
|
|
|
|
|
"""
|
|
|
|
|
Returns:
|
|
|
|
|
bool:
|
|
|
|
|
"""
|
2022-01-23 15:50:15 +08:00
|
|
|
return self.appear(PAUSE) and np.max(self.image_crop(PAUSE_DOUBLE_CHECK)) < 153
|
2020-03-29 01:22:46 +08:00
|
|
|
|
2020-06-30 07:10:10 +08:00
|
|
|
def ensure_combat_oil_loaded(self):
|
|
|
|
|
self.wait_until_stable(COMBAT_OIL_LOADING)
|
|
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
def handle_combat_automation_confirm(self):
|
|
|
|
|
if self.appear(AUTOMATION_CONFIRM_CHECK, interval=1):
|
|
|
|
|
self.appear_then_click(AUTOMATION_CONFIRM, offset=True)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2020-07-29 00:50:49 +08:00
|
|
|
def combat_preparation(self, balance_hp=False, emotion_reduce=False, auto='combat_auto', fleet_index=1):
|
2020-03-29 01:22:46 +08:00
|
|
|
"""
|
|
|
|
|
Args:
|
|
|
|
|
balance_hp (bool):
|
|
|
|
|
emotion_reduce (bool):
|
2020-07-29 00:50:49 +08:00
|
|
|
auto (str):
|
2020-03-29 01:22:46 +08:00
|
|
|
fleet_index (int):
|
|
|
|
|
"""
|
|
|
|
|
logger.info('Combat preparation.')
|
2021-01-17 21:31:37 +08:00
|
|
|
skip_first_screenshot = True
|
2021-10-16 18:00:58 +08:00
|
|
|
interval_set = False
|
2020-03-29 01:22:46 +08:00
|
|
|
|
2020-04-07 22:08:06 +08:00
|
|
|
if emotion_reduce:
|
2021-09-24 19:42:36 +08:00
|
|
|
self.emotion.wait(fleet_index=fleet_index)
|
2020-03-29 01:22:46 +08:00
|
|
|
if balance_hp:
|
2020-04-07 22:08:06 +08:00
|
|
|
self.hp_balance()
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
while 1:
|
2021-01-17 21:31:37 +08:00
|
|
|
if skip_first_screenshot:
|
|
|
|
|
skip_first_screenshot = False
|
|
|
|
|
else:
|
|
|
|
|
self.device.screenshot()
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
if self.appear(BATTLE_PREPARATION):
|
2020-07-29 00:50:49 +08:00
|
|
|
if self.handle_combat_automation_set(auto=auto == 'combat_auto'):
|
2020-03-29 01:22:46 +08:00
|
|
|
continue
|
|
|
|
|
if self.handle_retirement():
|
2020-09-25 14:16:15 +08:00
|
|
|
continue
|
2020-04-12 13:54:06 +08:00
|
|
|
if self.handle_combat_low_emotion():
|
|
|
|
|
continue
|
2020-08-15 20:15:07 +08:00
|
|
|
if balance_hp and self.handle_emergency_repair_use():
|
2020-05-17 17:11:02 +08:00
|
|
|
continue
|
2021-09-25 00:38:53 +08:00
|
|
|
if self.handle_battle_preparation():
|
2020-03-29 01:22:46 +08:00
|
|
|
continue
|
|
|
|
|
if self.handle_combat_automation_confirm():
|
|
|
|
|
continue
|
2020-04-30 23:40:29 +08:00
|
|
|
if self.handle_story_skip():
|
|
|
|
|
continue
|
2021-10-16 18:00:58 +08:00
|
|
|
if not interval_set:
|
|
|
|
|
if self.is_combat_loading():
|
2022-02-02 00:46:06 +08:00
|
|
|
self.device.screenshot_interval_set('combat')
|
2021-10-16 18:00:58 +08:00
|
|
|
interval_set = True
|
2020-04-30 23:40:29 +08:00
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
# End
|
|
|
|
|
if self.is_combat_executing():
|
|
|
|
|
if emotion_reduce:
|
|
|
|
|
self.emotion.reduce(fleet_index)
|
|
|
|
|
break
|
|
|
|
|
|
2021-09-25 00:38:53 +08:00
|
|
|
def handle_battle_preparation(self):
|
|
|
|
|
"""
|
|
|
|
|
Returns:
|
|
|
|
|
bool:
|
|
|
|
|
"""
|
|
|
|
|
if self.appear_then_click(BATTLE_PREPARATION, interval=2):
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
def handle_combat_automation_set(self, auto):
|
|
|
|
|
"""
|
|
|
|
|
Args:
|
|
|
|
|
auto (bool): If use auto.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
bool:
|
|
|
|
|
"""
|
|
|
|
|
if not self._automation_set_timer.reached():
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if self.appear(AUTOMATION_ON):
|
|
|
|
|
logger.info('[Automation] ON')
|
|
|
|
|
if not auto:
|
|
|
|
|
self.device.click(AUTOMATION_SWITCH)
|
|
|
|
|
self.device.sleep(1)
|
|
|
|
|
self._automation_set_timer.reset()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
if self.appear(AUTOMATION_OFF):
|
|
|
|
|
logger.info('[Automation] OFF')
|
|
|
|
|
if auto:
|
|
|
|
|
self.device.click(AUTOMATION_SWITCH)
|
|
|
|
|
self.device.sleep(1)
|
|
|
|
|
self._automation_set_timer.reset()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
if self.appear_then_click(AUTOMATION_CONFIRM, offset=True):
|
|
|
|
|
self._automation_set_timer.reset()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2020-05-17 17:11:02 +08:00
|
|
|
def handle_emergency_repair_use(self):
|
2021-09-15 21:33:11 +08:00
|
|
|
if not self.config.HpControl_UseEmergencyRepair:
|
|
|
|
|
return False
|
|
|
|
|
|
2020-05-17 17:11:02 +08:00
|
|
|
if self.appear_then_click(EMERGENCY_REPAIR_CONFIRM, offset=True):
|
|
|
|
|
return True
|
2020-05-22 21:48:56 +08:00
|
|
|
if self.appear(BATTLE_PREPARATION) and self.appear(EMERGENCY_REPAIR_AVAILABLE):
|
2021-01-28 00:35:15 +08:00
|
|
|
# When entering battle_preparation page (or after emergency repairing),
|
|
|
|
|
# the emergency icon is active by default, even if nothing to use.
|
|
|
|
|
# After a short animation, everything shows as usual.
|
|
|
|
|
# Using fleet power number as a stable checker.
|
|
|
|
|
# First wait for it to be non-zero, then wait for it to be stable.
|
2020-09-26 17:12:24 +08:00
|
|
|
self.wait_until_disappear(MAIN_FLEET_POWER_ZERO, offset=(20, 20))
|
2021-01-28 00:35:15 +08:00
|
|
|
stable_checker = Button(
|
|
|
|
|
area=MAIN_FLEET_POWER_ZERO.area, color=(), button=MAIN_FLEET_POWER_ZERO.button, name='STABLE_CHECKER')
|
2020-09-26 17:12:24 +08:00
|
|
|
self.wait_until_stable(stable_checker)
|
2020-09-25 14:16:15 +08:00
|
|
|
if not self.appear(EMERGENCY_REPAIR_AVAILABLE):
|
|
|
|
|
return False
|
2020-05-17 17:11:02 +08:00
|
|
|
logger.info('EMERGENCY_REPAIR_AVAILABLE')
|
2020-05-26 03:14:30 +08:00
|
|
|
if not len(self.hp):
|
|
|
|
|
return False
|
2021-09-15 21:33:11 +08:00
|
|
|
if np.min(np.array(self.hp)[np.array(self.hp) > 0.001]) < self.config.HpControl_RepairUseSingleThreshold \
|
|
|
|
|
or np.max(self.hp[:3]) < self.config.HpControl_RepairUseMultiThreshold \
|
|
|
|
|
or np.max(self.hp[3:]) < self.config.HpControl_RepairUseMultiThreshold:
|
2020-05-17 17:11:02 +08:00
|
|
|
logger.info('Use emergency repair')
|
|
|
|
|
self.device.click(EMERGENCY_REPAIR_AVAILABLE)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2021-09-21 00:56:33 +08:00
|
|
|
def combat_execute(self, auto='combat_auto', submarine='do_not_use', drop=None):
|
2020-03-29 01:22:46 +08:00
|
|
|
"""
|
|
|
|
|
Args:
|
2021-09-21 00:56:33 +08:00
|
|
|
auto (str): ['combat_auto', 'combat_manual', 'stand_still_in_the_middle', 'hide_in_bottom_left']
|
|
|
|
|
submarine (str): ['do_not_use', 'hunt_only', 'every_combat']
|
2021-09-15 21:33:11 +08:00
|
|
|
drop (DropImage):
|
2020-03-29 01:22:46 +08:00
|
|
|
"""
|
|
|
|
|
logger.info('Combat execute')
|
2020-04-10 12:05:16 +08:00
|
|
|
self.submarine_call_reset()
|
2020-04-11 21:12:54 +08:00
|
|
|
self.combat_auto_reset()
|
|
|
|
|
self.combat_manual_reset()
|
2022-06-05 08:35:21 +08:00
|
|
|
self.device.click_record_clear()
|
2020-03-29 01:22:46 +08:00
|
|
|
confirm_timer = Timer(10)
|
|
|
|
|
confirm_timer.start()
|
|
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
|
|
if not confirm_timer.reached() and self.appear_then_click(AUTOMATION_CONFIRM, offset=True):
|
|
|
|
|
continue
|
|
|
|
|
|
2020-04-24 15:26:11 +08:00
|
|
|
if self.handle_story_skip():
|
|
|
|
|
continue
|
2020-07-29 00:50:49 +08:00
|
|
|
if self.handle_combat_auto(auto):
|
2020-04-11 21:12:54 +08:00
|
|
|
continue
|
2020-07-29 00:50:49 +08:00
|
|
|
if self.handle_combat_manual(auto):
|
2020-04-11 21:12:54 +08:00
|
|
|
continue
|
2020-07-29 00:50:49 +08:00
|
|
|
if auto != 'combat_auto' and self.auto_mode_checked and self.is_combat_executing():
|
2020-05-22 22:33:18 +08:00
|
|
|
if self.handle_combat_weapon_release():
|
|
|
|
|
continue
|
2021-09-21 00:56:33 +08:00
|
|
|
if self.handle_submarine_call(submarine):
|
|
|
|
|
continue
|
2021-09-20 18:01:15 +08:00
|
|
|
if self.handle_popup_confirm('COMBAT_EXECUTE'):
|
|
|
|
|
continue
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
# End
|
2021-09-15 21:33:11 +08:00
|
|
|
if self.handle_battle_status(drop=drop) \
|
|
|
|
|
or self.handle_get_items(drop=drop):
|
2022-02-02 00:46:06 +08:00
|
|
|
self.device.screenshot_interval_set()
|
2020-03-29 01:22:46 +08:00
|
|
|
break
|
|
|
|
|
|
2021-09-15 21:33:11 +08:00
|
|
|
def handle_battle_status(self, drop=None):
|
2020-03-29 01:22:46 +08:00
|
|
|
"""
|
|
|
|
|
Args:
|
2021-09-15 21:33:11 +08:00
|
|
|
drop (DropImage):
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
bool:
|
|
|
|
|
"""
|
2020-06-17 17:56:10 +08:00
|
|
|
if self.is_combat_executing():
|
|
|
|
|
return False
|
2021-09-15 23:07:51 +08:00
|
|
|
if self.appear(BATTLE_STATUS_S, interval=self.battle_status_click_interval):
|
2021-09-15 21:33:11 +08:00
|
|
|
if drop:
|
2021-09-15 23:07:51 +08:00
|
|
|
drop.handle_add(self)
|
2021-09-15 21:33:11 +08:00
|
|
|
else:
|
2020-04-15 21:44:11 +08:00
|
|
|
self.device.sleep((0.25, 0.5))
|
2021-09-15 23:07:51 +08:00
|
|
|
self.device.click(BATTLE_STATUS_S)
|
2020-03-29 01:22:46 +08:00
|
|
|
return True
|
2021-09-15 23:07:51 +08:00
|
|
|
if self.appear(BATTLE_STATUS_A, interval=self.battle_status_click_interval):
|
2021-02-28 16:40:01 +08:00
|
|
|
logger.warning('Battle status A')
|
2021-09-15 21:33:11 +08:00
|
|
|
if drop:
|
2021-09-15 23:07:51 +08:00
|
|
|
drop.handle_add(self)
|
2021-09-15 21:33:11 +08:00
|
|
|
else:
|
2020-04-15 21:44:11 +08:00
|
|
|
self.device.sleep((0.25, 0.5))
|
2021-09-15 23:07:51 +08:00
|
|
|
self.device.click(BATTLE_STATUS_A)
|
2020-03-29 01:22:46 +08:00
|
|
|
return True
|
2021-09-15 23:07:51 +08:00
|
|
|
if self.appear(BATTLE_STATUS_B, interval=self.battle_status_click_interval):
|
2020-06-08 14:16:00 +08:00
|
|
|
logger.warning('Battle Status B')
|
2021-09-15 21:33:11 +08:00
|
|
|
if drop:
|
2021-09-15 23:07:51 +08:00
|
|
|
drop.handle_add(self)
|
2021-09-15 21:33:11 +08:00
|
|
|
else:
|
2020-06-08 14:16:00 +08:00
|
|
|
self.device.sleep((0.25, 0.5))
|
2021-09-15 23:07:51 +08:00
|
|
|
self.device.click(BATTLE_STATUS_B)
|
2020-06-08 14:16:00 +08:00
|
|
|
return True
|
2021-09-15 23:07:51 +08:00
|
|
|
if self.appear(BATTLE_STATUS_C, interval=self.battle_status_click_interval):
|
2021-02-16 02:14:47 +08:00
|
|
|
logger.warning('Battle Status C')
|
2021-02-28 16:40:01 +08:00
|
|
|
# raise GameStuckError('Battle status C')
|
2021-09-15 21:33:11 +08:00
|
|
|
if drop:
|
2021-09-15 23:07:51 +08:00
|
|
|
drop.handle_add(self)
|
2021-09-15 21:33:11 +08:00
|
|
|
else:
|
|
|
|
|
self.device.sleep((0.25, 0.5))
|
2021-09-15 23:07:51 +08:00
|
|
|
self.device.click(BATTLE_STATUS_C)
|
|
|
|
|
return True
|
|
|
|
|
if self.appear(BATTLE_STATUS_D, interval=self.battle_status_click_interval):
|
2021-02-16 02:14:47 +08:00
|
|
|
logger.warning('Battle Status D')
|
2021-02-28 16:40:01 +08:00
|
|
|
# raise GameStuckError('Battle Status D')
|
2021-09-15 21:33:11 +08:00
|
|
|
if drop:
|
2021-09-15 23:07:51 +08:00
|
|
|
drop.handle_add(self)
|
2021-09-15 21:33:11 +08:00
|
|
|
else:
|
|
|
|
|
self.device.sleep((0.25, 0.5))
|
2021-09-15 23:07:51 +08:00
|
|
|
self.device.click(BATTLE_STATUS_D)
|
|
|
|
|
return True
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2021-09-15 21:33:11 +08:00
|
|
|
def handle_get_items(self, drop=None):
|
2020-03-30 14:00:39 +08:00
|
|
|
"""
|
|
|
|
|
Args:
|
2021-09-15 21:33:11 +08:00
|
|
|
drop (DropImage):
|
2020-03-30 14:00:39 +08:00
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
bool:
|
|
|
|
|
"""
|
2021-09-15 23:07:51 +08:00
|
|
|
if self.appear(GET_ITEMS_1, offset=5, interval=self.battle_status_click_interval):
|
|
|
|
|
if drop:
|
|
|
|
|
drop.handle_add(self)
|
|
|
|
|
self.device.click(GET_ITEMS_1)
|
2020-04-15 21:44:11 +08:00
|
|
|
self.interval_reset(BATTLE_STATUS_S)
|
|
|
|
|
self.interval_reset(BATTLE_STATUS_A)
|
2020-06-08 14:16:00 +08:00
|
|
|
self.interval_reset(BATTLE_STATUS_B)
|
2020-04-15 21:44:11 +08:00
|
|
|
return True
|
2021-09-15 23:07:51 +08:00
|
|
|
if self.appear(GET_ITEMS_2, offset=5, interval=self.battle_status_click_interval):
|
|
|
|
|
if drop:
|
|
|
|
|
drop.handle_add(self)
|
|
|
|
|
self.device.click(GET_ITEMS_1)
|
2020-04-15 21:44:11 +08:00
|
|
|
self.interval_reset(BATTLE_STATUS_S)
|
|
|
|
|
self.interval_reset(BATTLE_STATUS_A)
|
2020-06-08 14:16:00 +08:00
|
|
|
self.interval_reset(BATTLE_STATUS_B)
|
2020-03-30 14:00:39 +08:00
|
|
|
return True
|
2021-12-03 17:32:10 +08:00
|
|
|
if self.appear(GET_ITEMS_3, offset=5, interval=self.battle_status_click_interval):
|
|
|
|
|
if drop:
|
|
|
|
|
drop.handle_add(self)
|
|
|
|
|
self.device.click(GET_ITEMS_1)
|
|
|
|
|
self.interval_reset(BATTLE_STATUS_S)
|
|
|
|
|
self.interval_reset(BATTLE_STATUS_A)
|
|
|
|
|
self.interval_reset(BATTLE_STATUS_B)
|
|
|
|
|
return True
|
2020-03-30 14:00:39 +08:00
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2020-04-16 22:01:52 +08:00
|
|
|
def handle_exp_info(self):
|
2020-04-15 21:44:11 +08:00
|
|
|
"""
|
|
|
|
|
Returns:
|
|
|
|
|
bool:
|
|
|
|
|
"""
|
2020-07-12 22:31:31 +08:00
|
|
|
if self.is_combat_executing():
|
|
|
|
|
return False
|
2020-04-16 22:01:52 +08:00
|
|
|
if self.appear_then_click(EXP_INFO_S):
|
|
|
|
|
self.device.sleep((0.25, 0.5))
|
|
|
|
|
return True
|
|
|
|
|
if self.appear_then_click(EXP_INFO_A):
|
|
|
|
|
self.device.sleep((0.25, 0.5))
|
|
|
|
|
return True
|
2020-06-08 14:16:00 +08:00
|
|
|
if self.appear_then_click(EXP_INFO_B):
|
|
|
|
|
self.device.sleep((0.25, 0.5))
|
|
|
|
|
return True
|
2020-04-15 21:44:11 +08:00
|
|
|
|
2020-04-16 22:01:52 +08:00
|
|
|
return False
|
2020-04-15 21:44:11 +08:00
|
|
|
|
2021-09-15 21:33:11 +08:00
|
|
|
def handle_get_ship(self, drop=None):
|
2020-04-15 21:44:11 +08:00
|
|
|
"""
|
|
|
|
|
Args:
|
2021-09-15 21:33:11 +08:00
|
|
|
drop (DropImage):
|
2020-04-15 21:44:11 +08:00
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
bool:
|
|
|
|
|
"""
|
2022-01-10 00:25:07 +08:00
|
|
|
if self.appear_then_click(GET_SHIP, interval=1):
|
|
|
|
|
if self.appear(NEW_SHIP):
|
2020-10-02 23:56:22 +08:00
|
|
|
logger.info('Get a new SHIP')
|
2021-09-15 23:07:51 +08:00
|
|
|
if drop:
|
|
|
|
|
drop.handle_add(self)
|
2020-10-02 23:56:22 +08:00
|
|
|
self.config.GET_SHIP_TRIGGERED = True
|
2020-03-30 14:00:39 +08:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2021-09-15 21:33:11 +08:00
|
|
|
def combat_status(self, drop=None, expected_end=None):
|
2020-03-29 01:22:46 +08:00
|
|
|
"""
|
|
|
|
|
Args:
|
2021-09-15 21:33:11 +08:00
|
|
|
drop (DropImage):
|
2021-01-26 17:07:34 +08:00
|
|
|
expected_end (str, callable): with_searching, no_searching, in_stage.
|
2020-03-29 01:22:46 +08:00
|
|
|
"""
|
|
|
|
|
logger.info('Combat status')
|
2020-06-25 11:03:44 +08:00
|
|
|
logger.attr('expected_end', expected_end.__name__ if callable(expected_end) else expected_end)
|
2021-10-25 17:46:10 +08:00
|
|
|
battle_status = False
|
2020-06-05 04:28:48 +08:00
|
|
|
exp_info = False # This is for the white screen bug in game
|
2020-03-29 01:22:46 +08:00
|
|
|
while 1:
|
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
2021-11-17 21:27:18 +08:00
|
|
|
# Expected end
|
|
|
|
|
if isinstance(expected_end, str):
|
|
|
|
|
if expected_end == 'in_stage' and self.handle_in_stage():
|
|
|
|
|
break
|
|
|
|
|
if expected_end == 'with_searching' and self.handle_in_map_with_enemy_searching(drop=drop):
|
|
|
|
|
break
|
2022-02-10 18:25:51 +08:00
|
|
|
if expected_end == 'no_searching' and self.handle_in_map_no_enemy_searching(drop=drop):
|
2021-11-17 21:27:18 +08:00
|
|
|
break
|
|
|
|
|
if expected_end == 'in_ui' and self.appear(BACK_ARROW, offset=(20, 20)):
|
|
|
|
|
break
|
|
|
|
|
if callable(expected_end):
|
|
|
|
|
if expected_end():
|
|
|
|
|
break
|
|
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
# Combat status
|
2021-09-15 21:33:11 +08:00
|
|
|
if not exp_info and self.handle_get_ship(drop=drop):
|
2020-04-15 21:44:11 +08:00
|
|
|
continue
|
2021-09-15 21:33:11 +08:00
|
|
|
if self.handle_get_items(drop=drop):
|
2020-03-29 01:22:46 +08:00
|
|
|
continue
|
2021-12-30 17:42:55 +08:00
|
|
|
if not exp_info and self.handle_battle_status(drop=drop):
|
2021-10-25 17:46:10 +08:00
|
|
|
battle_status = True
|
2020-03-29 01:22:46 +08:00
|
|
|
continue
|
2022-03-10 21:07:42 +08:00
|
|
|
if self.handle_popup_confirm('COMBAT_STATUS'):
|
2021-10-25 17:46:10 +08:00
|
|
|
if battle_status and not exp_info:
|
|
|
|
|
logger.info('Locking a new ship')
|
|
|
|
|
self.config.GET_SHIP_TRIGGERED = True
|
2020-04-14 17:32:26 +08:00
|
|
|
continue
|
2020-04-16 22:01:52 +08:00
|
|
|
if self.handle_exp_info():
|
2020-06-05 04:28:48 +08:00
|
|
|
exp_info = True
|
2020-03-29 01:22:46 +08:00
|
|
|
continue
|
2021-09-15 21:33:11 +08:00
|
|
|
if self.handle_urgent_commission(drop=drop):
|
2020-03-29 01:22:46 +08:00
|
|
|
continue
|
2022-02-06 02:35:22 +08:00
|
|
|
if self.handle_story_skip(drop=drop):
|
2020-04-24 15:26:11 +08:00
|
|
|
continue
|
2021-01-15 22:32:06 +08:00
|
|
|
if self.handle_guild_popup_cancel():
|
2021-01-15 03:55:52 +08:00
|
|
|
continue
|
2021-10-14 17:37:02 +08:00
|
|
|
if self.handle_vote_popup():
|
|
|
|
|
continue
|
2021-10-14 17:51:36 +08:00
|
|
|
if self.handle_auto_search_exit(drop=drop):
|
2021-10-14 17:37:02 +08:00
|
|
|
continue
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
# End
|
2020-04-27 22:49:30 +08:00
|
|
|
if self.handle_in_stage():
|
|
|
|
|
break
|
2020-03-29 01:22:46 +08:00
|
|
|
if expected_end is None:
|
2021-10-15 21:55:32 +08:00
|
|
|
if self.handle_in_map_with_enemy_searching(drop=drop):
|
2020-03-29 01:22:46 +08:00
|
|
|
break
|
|
|
|
|
|
2021-09-21 00:56:33 +08:00
|
|
|
def combat(self, balance_hp=None, emotion_reduce=None, auto_mode=None, submarine_mode=None,
|
2020-08-14 06:44:03 +08:00
|
|
|
save_get_items=None, expected_end=None, fleet_index=1):
|
2020-03-29 01:22:46 +08:00
|
|
|
"""
|
|
|
|
|
Execute a combat.
|
2021-09-15 21:33:11 +08:00
|
|
|
Will use user config if argument is None.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
balance_hp (bool):
|
|
|
|
|
emotion_reduce (bool):
|
|
|
|
|
auto_mode (str): combat_auto, combat_manual, stand_still_in_the_middle, hide_in_bottom_left
|
2021-09-21 00:56:33 +08:00
|
|
|
submarine_mode (str): do_not_use, hunt_only, every_combat
|
2022-02-02 16:21:28 +08:00
|
|
|
save_get_items (bool, DropImage):
|
2021-09-15 21:33:11 +08:00
|
|
|
expected_end (str, callable):
|
|
|
|
|
fleet_index (int): 1 or 2
|
2020-03-29 01:22:46 +08:00
|
|
|
"""
|
2021-09-15 21:33:11 +08:00
|
|
|
balance_hp = balance_hp if balance_hp is not None else self.config.HpControl_UseHpBalance
|
|
|
|
|
emotion_reduce = emotion_reduce if emotion_reduce is not None else self.config.Emotion_CalculateEmotion
|
2020-08-14 06:44:03 +08:00
|
|
|
if auto_mode is None:
|
2021-09-15 21:33:11 +08:00
|
|
|
auto_mode = self.config.Fleet_Fleet1Mode if fleet_index == 1 else self.config.Fleet_Fleet2Mode
|
2021-09-21 00:56:33 +08:00
|
|
|
if submarine_mode is None:
|
2021-11-06 22:43:37 +08:00
|
|
|
submarine_mode = 'do_not_use'
|
2021-09-21 00:56:33 +08:00
|
|
|
if self.config.Submarine_Fleet:
|
|
|
|
|
submarine_mode = self.config.Submarine_Mode
|
2020-07-05 04:48:02 +08:00
|
|
|
self.battle_status_click_interval = 7 if save_get_items else 0
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
# if not hasattr(self, 'emotion'):
|
|
|
|
|
# self.emotion = Emotion(config=self.config)
|
|
|
|
|
|
2021-09-15 21:33:11 +08:00
|
|
|
with self.stat.new(
|
2022-05-21 00:53:37 +08:00
|
|
|
genre=self.config.campaign_name, method=self.config.DropRecord_CombatRecord
|
2021-09-15 21:33:11 +08:00
|
|
|
) as drop:
|
|
|
|
|
if save_get_items is False:
|
|
|
|
|
drop = None
|
2022-02-02 16:21:28 +08:00
|
|
|
elif isinstance(save_get_items, DropImage):
|
|
|
|
|
drop = save_get_items
|
2021-09-15 21:33:11 +08:00
|
|
|
self.combat_preparation(
|
|
|
|
|
balance_hp=balance_hp, emotion_reduce=emotion_reduce, auto=auto_mode, fleet_index=fleet_index)
|
|
|
|
|
self.combat_execute(
|
2021-09-21 00:56:33 +08:00
|
|
|
auto=auto_mode, submarine=submarine_mode, drop=drop)
|
2021-09-15 21:33:11 +08:00
|
|
|
self.combat_status(
|
|
|
|
|
drop=drop, expected_end=expected_end)
|
2022-02-10 18:25:51 +08:00
|
|
|
# self.handle_map_after_combat_story()
|
2020-12-25 13:28:45 +08:00
|
|
|
|
|
|
|
|
logger.info('Combat end.')
|