2020-04-12 05:54:06 +00:00
|
|
|
import numpy as np
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.base.timer import Timer
|
2020-04-13 08:07:32 +00:00
|
|
|
from module.base.utils import color_bar_percentage
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.combat.assets import *
|
2020-04-11 13:12:54 +00:00
|
|
|
from module.combat.combat_auto import CombatAuto
|
|
|
|
from module.combat.combat_manual import CombatManual
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.combat.emotion import Emotion
|
|
|
|
from module.combat.hp_balancer import HPBalancer
|
2020-04-10 04:05:16 +00:00
|
|
|
from module.combat.submarine import SubmarineCall
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.handler.enemy_searching import EnemySearchingHandler
|
Add: 适配第一章, 修复大量bug
- 修复处理夜间委托时, 出现递归调用的问题
- 增加红脸出击确认的功能
- 增加了透视识别错误图片保存的开关
- 修复了地图太小时, 透视识别报错的问题
- 修复了相机位于地图外时, 透视识别出错的问题
- 修复了离开退役时, 会连击的问题
- 修复了同时出现低心情和船坞已满弹窗时, 卡住的问题
- 更新了一键退役实装后的安全点击的位置
- 修复了换装滑动失败时, 卡住的问题
- 修复了关闭自动收获后, 出现委托完成的提示是, 进图卡住的问题
- 修复了, 无正在跑的委托时, 报错的问题
2020-04-11 07:23:51 +00:00
|
|
|
from module.handler.low_emotion import LowEmotionHandler
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.handler.urgent_commission import UrgentCommissionHandler
|
|
|
|
from module.logger import logger
|
|
|
|
from module.map.assets import MAP_OFFENSIVE
|
|
|
|
from module.retire.retirement import Retirement
|
|
|
|
from module.ui.assets import BACK_ARROW
|
|
|
|
|
|
|
|
|
2020-04-11 13:12:54 +00:00
|
|
|
class Combat(HPBalancer, UrgentCommissionHandler, EnemySearchingHandler, Retirement, SubmarineCall, LowEmotionHandler,
|
2020-04-29 09:45:35 +00:00
|
|
|
CombatAuto, CombatManual):
|
2020-03-28 17:22:46 +00:00
|
|
|
_automation_set_timer = Timer(1)
|
|
|
|
_emotion: Emotion
|
2020-04-15 13:44:11 +00:00
|
|
|
battle_status_click_interval = 0
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def emotion(self):
|
|
|
|
if not hasattr(self, '_emotion'):
|
|
|
|
self._emotion = Emotion(config=self.config)
|
|
|
|
return self._emotion
|
|
|
|
|
|
|
|
def combat_appear(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
bool: If enter combat.
|
|
|
|
"""
|
|
|
|
if self.config.ENABLE_MAP_FLEET_LOCK and not self.is_in_map():
|
|
|
|
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
|
|
|
|
|
|
|
|
def map_offensive(self):
|
|
|
|
while 1:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if self.appear_then_click(MAP_OFFENSIVE, interval=1):
|
|
|
|
continue
|
2020-04-25 12:51:15 +00:00
|
|
|
if self.handle_combat_low_emotion():
|
|
|
|
continue
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
# Break
|
|
|
|
if self.combat_appear():
|
|
|
|
break
|
|
|
|
|
|
|
|
def is_combat_loading(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
bool:
|
|
|
|
"""
|
|
|
|
left = color_bar_percentage(self.device.image, area=LOADING_BAR.area, prev_color=(99, 150, 255))
|
|
|
|
right = color_bar_percentage(self.device.image, area=LOADING_BAR.area, prev_color=(225, 225, 225), reverse=True)
|
|
|
|
if 0.15 < left < 0.95 and right > 0.15 and left + right <= 1.2:
|
|
|
|
logger.attr('Loading', f'{int(left * 100)}%({int(right * 100)}%)')
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def is_combat_executing(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
bool:
|
|
|
|
"""
|
2020-04-13 08:07:32 +00:00
|
|
|
return self.appear(PAUSE) and np.max(self.device.image.crop(PAUSE_DOUBLE_CHECK.area)) < 153
|
2020-03-28 17:22:46 +00: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
|
|
|
|
|
|
|
|
def combat_preparation(self, balance_hp=False, emotion_reduce=False, auto=True, fleet_index=1):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
balance_hp (bool):
|
|
|
|
emotion_reduce (bool):
|
|
|
|
auto (bool):
|
|
|
|
fleet_index (int):
|
|
|
|
"""
|
|
|
|
logger.info('Combat preparation.')
|
|
|
|
|
2020-04-07 14:08:06 +00:00
|
|
|
if emotion_reduce:
|
2020-04-06 17:52:47 +00:00
|
|
|
self.emotion.wait(fleet=fleet_index)
|
2020-03-28 17:22:46 +00:00
|
|
|
if balance_hp:
|
2020-04-07 14:08:06 +00:00
|
|
|
self.hp_balance()
|
2020-03-28 17:22:46 +00:00
|
|
|
# logger.info('start combat')
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
# Automation.
|
|
|
|
if self.appear(BATTLE_PREPARATION):
|
|
|
|
# if self.handle_combat_automation_confirm():
|
|
|
|
# continue
|
|
|
|
if self.handle_combat_automation_set(auto=auto):
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Retirement
|
|
|
|
if self.handle_retirement():
|
|
|
|
continue
|
|
|
|
|
Add: 适配第一章, 修复大量bug
- 修复处理夜间委托时, 出现递归调用的问题
- 增加红脸出击确认的功能
- 增加了透视识别错误图片保存的开关
- 修复了地图太小时, 透视识别报错的问题
- 修复了相机位于地图外时, 透视识别出错的问题
- 修复了离开退役时, 会连击的问题
- 修复了同时出现低心情和船坞已满弹窗时, 卡住的问题
- 更新了一键退役实装后的安全点击的位置
- 修复了换装滑动失败时, 卡住的问题
- 修复了关闭自动收获后, 出现委托完成的提示是, 进图卡住的问题
- 修复了, 无正在跑的委托时, 报错的问题
2020-04-11 07:23:51 +00:00
|
|
|
# Emotion
|
2020-04-12 05:54:06 +00:00
|
|
|
if self.handle_combat_low_emotion():
|
|
|
|
continue
|
Add: 适配第一章, 修复大量bug
- 修复处理夜间委托时, 出现递归调用的问题
- 增加红脸出击确认的功能
- 增加了透视识别错误图片保存的开关
- 修复了地图太小时, 透视识别报错的问题
- 修复了相机位于地图外时, 透视识别出错的问题
- 修复了离开退役时, 会连击的问题
- 修复了同时出现低心情和船坞已满弹窗时, 卡住的问题
- 更新了一键退役实装后的安全点击的位置
- 修复了换装滑动失败时, 卡住的问题
- 修复了关闭自动收获后, 出现委托完成的提示是, 进图卡住的问题
- 修复了, 无正在跑的委托时, 报错的问题
2020-04-11 07:23:51 +00:00
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
# Combat start
|
2020-04-14 09:32:26 +00:00
|
|
|
if self.appear_then_click(BATTLE_PREPARATION, interval=2):
|
2020-03-28 17:22:46 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
if self.handle_combat_automation_confirm():
|
|
|
|
continue
|
|
|
|
|
|
|
|
# End
|
|
|
|
if self.is_combat_executing():
|
|
|
|
if emotion_reduce:
|
|
|
|
self.emotion.reduce(fleet_index)
|
|
|
|
break
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def combat_execute(self, func=None, call_submarine_at_boss=False, save_get_items=False):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
func: Funtion to run when in combat.
|
|
|
|
call_submarine_at_boss (bool):
|
|
|
|
save_get_items (bool)
|
|
|
|
"""
|
|
|
|
logger.info('Combat execute')
|
2020-04-10 04:05:16 +00:00
|
|
|
self.submarine_call_reset()
|
2020-04-11 13:12:54 +00:00
|
|
|
self.combat_auto_reset()
|
|
|
|
self.combat_manual_reset()
|
2020-03-28 17:22:46 +00:00
|
|
|
confirm_timer = Timer(10)
|
|
|
|
confirm_timer.start()
|
2020-04-27 15:59:51 +00:00
|
|
|
self.device.screenshot_interval_set(self.config.COMBAT_SCREENSHOT_INTERVAL)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
while 1:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if not confirm_timer.reached() and self.appear_then_click(AUTOMATION_CONFIRM, offset=True):
|
|
|
|
continue
|
|
|
|
|
2020-04-24 07:26:11 +00:00
|
|
|
if self.handle_story_skip():
|
|
|
|
continue
|
2020-04-11 13:12:54 +00:00
|
|
|
if self.handle_combat_auto():
|
|
|
|
continue
|
|
|
|
if self.handle_combat_manual():
|
|
|
|
continue
|
2020-03-28 17:22:46 +00:00
|
|
|
if call_submarine_at_boss:
|
|
|
|
pass
|
2020-04-10 04:05:16 +00:00
|
|
|
else:
|
|
|
|
if self.handle_submarine_call():
|
|
|
|
continue
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
# End
|
|
|
|
if self.handle_battle_status(save_get_items=save_get_items):
|
2020-04-27 15:59:51 +00:00
|
|
|
self.device.screenshot_interval_set(0)
|
2020-03-28 17:22:46 +00:00
|
|
|
break
|
|
|
|
|
2020-03-30 06:00:39 +00:00
|
|
|
def handle_battle_status(self, save_get_items=False):
|
2020-03-28 17:22:46 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
save_get_items (bool):
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool:
|
|
|
|
"""
|
2020-04-15 13:44:11 +00:00
|
|
|
if self.appear_then_click(BATTLE_STATUS_S, screenshot=save_get_items, genre='status',
|
|
|
|
interval=self.battle_status_click_interval):
|
|
|
|
if not save_get_items:
|
|
|
|
self.device.sleep((0.25, 0.5))
|
2020-03-28 17:22:46 +00:00
|
|
|
return True
|
2020-04-15 13:44:11 +00:00
|
|
|
if self.appear_then_click(BATTLE_STATUS_A, screenshot=save_get_items, genre='status',
|
|
|
|
interval=self.battle_status_click_interval):
|
2020-03-28 17:22:46 +00:00
|
|
|
logger.warning('Battle status: A')
|
2020-04-15 13:44:11 +00:00
|
|
|
if not save_get_items:
|
|
|
|
self.device.sleep((0.25, 0.5))
|
2020-03-28 17:22:46 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2020-03-30 06:00:39 +00:00
|
|
|
def handle_get_items(self, save_get_items=False):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
save_get_items (bool):
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool:
|
|
|
|
"""
|
2020-04-15 13:44:11 +00:00
|
|
|
if self.appear_then_click(GET_ITEMS_1, screenshot=save_get_items, genre='get_items', offset=5,
|
|
|
|
interval=self.battle_status_click_interval):
|
|
|
|
self.interval_reset(BATTLE_STATUS_S)
|
|
|
|
self.interval_reset(BATTLE_STATUS_A)
|
|
|
|
return True
|
|
|
|
if self.appear_then_click(GET_ITEMS_2, screenshot=save_get_items, genre='get_items', offset=5,
|
|
|
|
interval=self.battle_status_click_interval):
|
|
|
|
self.interval_reset(BATTLE_STATUS_S)
|
|
|
|
self.interval_reset(BATTLE_STATUS_A)
|
2020-03-30 06:00:39 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2020-04-16 14:01:52 +00:00
|
|
|
def handle_exp_info(self):
|
2020-04-15 13:44:11 +00:00
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
bool:
|
|
|
|
"""
|
2020-04-16 14:01:52 +00: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-04-15 13:44:11 +00:00
|
|
|
|
2020-04-16 14:01:52 +00:00
|
|
|
return False
|
2020-04-15 13:44:11 +00:00
|
|
|
|
|
|
|
def handle_get_ship(self, save_get_items=False):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
save_get_items (bool):
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool:
|
|
|
|
"""
|
|
|
|
if self.appear_then_click(GET_SHIP, screenshot=save_get_items, genre='get_ship'):
|
2020-03-30 06:00:39 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
def combat_status(self, save_get_items=False, expected_end=None):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
save_get_items (bool):
|
|
|
|
expected_end (str): with_searching, no_searching, in_stage.
|
|
|
|
"""
|
|
|
|
logger.info('Combat status')
|
2020-04-17 15:35:20 +00:00
|
|
|
logger.attr('expected_end', expected_end)
|
2020-03-28 17:22:46 +00:00
|
|
|
while 1:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
# Combat status
|
2020-04-15 13:44:11 +00:00
|
|
|
if self.handle_get_ship(save_get_items=save_get_items):
|
|
|
|
continue
|
2020-03-30 06:00:39 +00:00
|
|
|
if self.handle_get_items(save_get_items=save_get_items):
|
2020-03-28 17:22:46 +00:00
|
|
|
continue
|
|
|
|
if self.handle_battle_status(save_get_items=save_get_items):
|
|
|
|
continue
|
2020-04-14 09:32:26 +00:00
|
|
|
if self.handle_popup_confirm():
|
|
|
|
continue
|
2020-04-16 14:01:52 +00:00
|
|
|
if self.handle_exp_info():
|
2020-03-28 17:22:46 +00:00
|
|
|
continue
|
|
|
|
if self.handle_urgent_commission(save_get_items=save_get_items):
|
|
|
|
continue
|
2020-04-24 07:26:11 +00:00
|
|
|
if self.handle_story_skip():
|
|
|
|
continue
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
# End
|
2020-04-27 14:49:30 +00:00
|
|
|
if self.handle_in_stage():
|
|
|
|
break
|
2020-03-28 17:22:46 +00:00
|
|
|
if expected_end is None:
|
2020-04-22 17:58:35 +00:00
|
|
|
if self.handle_in_map_with_enemy_searching():
|
2020-03-28 17:22:46 +00:00
|
|
|
break
|
|
|
|
if isinstance(expected_end, str):
|
|
|
|
if expected_end == 'in_stage' and self.handle_in_stage():
|
2020-04-22 17:58:35 +00:00
|
|
|
break
|
2020-03-28 17:22:46 +00:00
|
|
|
if expected_end == 'with_searching' and self.handle_in_map_with_enemy_searching():
|
|
|
|
break
|
2020-04-27 11:32:58 +00:00
|
|
|
if expected_end == 'no_searching' and self.handle_in_map_no_enemy_searching():
|
2020-03-28 17:22:46 +00: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-04-06 17:52:47 +00:00
|
|
|
def combat(self, balance_hp=None, emotion_reduce=None, func=None, call_submarine_at_boss=None, save_get_items=None,
|
|
|
|
expected_end=None, fleet_index=1):
|
2020-03-28 17:22:46 +00:00
|
|
|
"""
|
|
|
|
Execute a combat.
|
|
|
|
"""
|
2020-04-06 17:52:47 +00:00
|
|
|
balance_hp = balance_hp if balance_hp is not None else self.config.ENABLE_HP_BALANCE
|
2020-03-28 17:22:46 +00:00
|
|
|
emotion_reduce = emotion_reduce if emotion_reduce is not None else self.config.ENABLE_EMOTION_REDUCE
|
2020-04-14 09:32:26 +00:00
|
|
|
auto = self.config.COMBAT_AUTO_MODE == 'combat_auto'
|
2020-03-28 17:22:46 +00:00
|
|
|
call_submarine_at_boss = call_submarine_at_boss if call_submarine_at_boss is not None else self.config.SUBMARINE_CALL_AT_BOSS
|
|
|
|
save_get_items = save_get_items if save_get_items is not None else self.config.ENABLE_SAVE_GET_ITEMS
|
2020-04-15 13:44:11 +00:00
|
|
|
self.battle_status_click_interval = 3 if save_get_items else 0
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
# if not hasattr(self, 'emotion'):
|
|
|
|
# self.emotion = Emotion(config=self.config)
|
|
|
|
|
|
|
|
self.combat_preparation(
|
2020-04-06 17:52:47 +00:00
|
|
|
balance_hp=balance_hp, emotion_reduce=emotion_reduce, auto=auto, fleet_index=fleet_index)
|
2020-03-28 17:22:46 +00:00
|
|
|
self.combat_execute(
|
|
|
|
func=func, call_submarine_at_boss=call_submarine_at_boss, save_get_items=save_get_items)
|
|
|
|
self.combat_status(
|
|
|
|
save_get_items=save_get_items, expected_end=expected_end)
|