1
0
mirror of https://github.com/sui-feng-cb/AzurLaneAutoScript1.git synced 2026-07-06 13:09:46 +08:00
Files
AzurLaneAutoScript/module/combat/submarine.py
2026-07-02 23:44:34 +08:00

81 lines
2.9 KiB
Python

from module.base.base import ModuleBase
from module.base.timer import Timer
from module.base.utils import color_similar, crop, get_color, image_color_count
from module.combat.assets import *
from module.logger import logger
# BOSS detection areas
# Classic UI: BOSS avatar frame right border
BOSS_AVATAR_FRAME_RIGHT = (301, 13, 303, 89)
BOSS_AVATAR_FRAME_COLOR = (24, 28, 24)
# New UI: BOSS HP bar bottom border, middle-left portion
# Color targets deep blue themes; need adjustment for other color schemes
BOSS_HP_BAR_BORDER = (420, 48, 620, 50)
BOSS_HP_BAR_COLOR = (31, 39, 61)
class SubmarineCall(ModuleBase):
submarine_call_flag = False
submarine_call_timer = Timer(5)
submarine_call_click_timer = Timer(1)
def submarine_call_reset(self):
"""
Call this method after in battle_execute.
"""
self.submarine_call_timer.reset()
self.submarine_call_flag = False
def boss_appeared(self):
"""
Detect whether BOSS has appeared by checking stable BOSS UI elements.
"""
# New UI: BOSS HP bar bottom border
avg = get_color(self.device.image, BOSS_HP_BAR_BORDER)
if color_similar(avg, BOSS_HP_BAR_COLOR, threshold=40):
return True
# Classic UI: BOSS avatar frame right border
frame = crop(self.device.image, BOSS_AVATAR_FRAME_RIGHT, copy=False)
if image_color_count(frame, color=BOSS_AVATAR_FRAME_COLOR, count=55):
return True
return False
def handle_submarine_call(self, call_mode='do_not_use', is_boss=False):
"""
Args:
call_mode (str): do_not_use, boss_only, every_combat
is_boss (bool): True on BOSS battle
Returns:
bool: If clicked submarine call button.
"""
if self.submarine_call_flag:
return False
if call_mode == 'do_not_use' or (call_mode == 'boss_only' and not is_boss):
self.submarine_call_flag = True
return False
if self.config.Submarine_Timing == 'wait_for_boss' and is_boss:
if not self.boss_appeared():
self.submarine_call_timer.reset()
return False
if self.submarine_call_timer.reached():
logger.info('Submarine call timer reached')
self.submarine_call_flag = True
return False
if not self.appear(SUBMARINE_AVAILABLE_CHECK_1) or not self.appear(SUBMARINE_AVAILABLE_CHECK_2):
return False
if self.appear(SUBMARINE_CALLED):
logger.info('Submarine called')
self.submarine_call_flag = True
return False
elif self.submarine_call_click_timer.reached():
if not self.appear_then_click(SUBMARINE_READY):
logger.info('Incorrect submarine icon')
self.device.click(SUBMARINE_READY)
logger.info('Call submarine')
self.submarine_call_click_timer.reset()
return True