diff --git a/tasks/combat/assets/assets_combat_prepare.py b/tasks/combat/assets/assets_combat_prepare.py index b94e4030f..9360001ff 100644 --- a/tasks/combat/assets/assets_combat_prepare.py +++ b/tasks/combat/assets/assets_combat_prepare.py @@ -110,16 +110,6 @@ OCR_WAVE_COUNT = ButtonWrapper( button=(911, 555, 1151, 581), ), ) -RESERVED_TRAILBLAZE_POWER = ButtonWrapper( - name='RESERVED_TRAILBLAZE_POWER', - share=Button( - file='./assets/share/combat/prepare/RESERVED_TRAILBLAZE_POWER.png', - area=(480, 276, 576, 388), - search=(474, 271, 811, 396), - color=(111, 115, 148), - button=(480, 276, 576, 388), - ), -) RESERVED_TRAILBLAZE_POWER_ENTRANCE = ButtonWrapper( name='RESERVED_TRAILBLAZE_POWER_ENTRANCE', share=Button( diff --git a/tasks/combat/combat.py b/tasks/combat/combat.py index bdbffebbd..2f044d1ba 100644 --- a/tasks/combat/combat.py +++ b/tasks/combat/combat.py @@ -5,6 +5,7 @@ from tasks.combat.assets.assets_combat_finish import COMBAT_AGAIN, COMBAT_EXIT from tasks.combat.assets.assets_combat_interact import DUNGEON_COMBAT_INTERACT from tasks.combat.assets.assets_combat_prepare import COMBAT_PREPARE from tasks.combat.assets.assets_combat_team import COMBAT_TEAM_PREPARE, COMBAT_TEAM_SUPPORT +from tasks.combat.fuel import Fuel from tasks.combat.interact import CombatInteract from tasks.combat.obtain import CombatObtain from tasks.combat.prepare import CombatPrepare @@ -17,7 +18,7 @@ from tasks.map.control.joystick import MapControlJoystick class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSupport, CombatSkill, CombatObtain, - MapControlJoystick): + MapControlJoystick, Fuel): dungeon: DungeonList | None = None is_doing_planner: bool = False @@ -238,11 +239,11 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo def _try_get_more_trablaize_power(self, current, cost): if self.config.Dungeon_ExtractReservedTrailblazePower: logger.info('Extract reserved trailblaze power to get more trailblaze power') - self.combat_extract_reserved_trailblaze_power() + self.extract_reserved_trailblaze_power() current = self.combat_get_trailblaze_power() if self.config.Dungeon_UseFuel: logger.info('Use fuel to get more trailblaze power') - self.combat_use_fuel() + self.use_fuel() current = self.combat_get_trailblaze_power() return current >= cost diff --git a/tasks/combat/fuel.py b/tasks/combat/fuel.py new file mode 100644 index 000000000..5c7f9bb26 --- /dev/null +++ b/tasks/combat/fuel.py @@ -0,0 +1,88 @@ +from module.base.utils import crop, area_offset +from module.logger import logger +from module.ocr.ocr import Digit +from tasks.base.assets.assets_base_popup import POPUP_CONFIRM, POPUP_CANCEL +from tasks.base.ui import UI +from tasks.combat.assets.assets_combat_prepare import ( + EXTRACT_RESERVED_TRAILBLAZE_POWER, + FUEL, + FUEL_SELECTED, + OCR_FUEL, + OCR_RESERVED_TRAILBLAZE_POWER, + RESERVED_TRAILBLAZE_POWER_ENTRANCE, + FUEL_ENTRANCE, +) + + +class Fuel(UI): + def extract_reserved_trailblaze_power(self, skip_first_screenshot=True): + """ + Extract reserved trailblaze power from previous combat. + + Returns: + int: Reserved trailblaze power + """ + logger.info('Extract reserved trailblaze power') + current = Digit(OCR_RESERVED_TRAILBLAZE_POWER).ocr_single_line(self.device.image) + if current == 0: + logger.info('No reserved trailblaze power') + return + + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + if self.appear_then_click(EXTRACT_RESERVED_TRAILBLAZE_POWER): + continue + if self.appear_then_click(RESERVED_TRAILBLAZE_POWER_ENTRANCE): + continue + if self.appear_then_click(POPUP_CONFIRM): + continue + if self.handle_reward(): + break + + def use_fuel(self, skip_first_screenshot=True): + logger.info("Use Fuel") + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + if not self.appear(FUEL) and not self.appear(FUEL_SELECTED): + logger.info("No fuel found") + return + if self.appear(FUEL_SELECTED): + break + if self.appear_then_click(FUEL): + continue + if self.appear_then_click(FUEL_ENTRANCE): + continue + if self.handle_reward(): + break + + offset = FUEL_SELECTED.button_offset + count = Digit(OCR_FUEL).ocr_single_line(crop(self.device.image, area_offset(OCR_FUEL.area, offset)), + direct_ocr=True) + if count <= self.config.Dungeon_UseFuelUntilRemainCount: + logger.info("Fuel remain is under the threshold, stop using fuel") + while 1: + self.device.screenshot() + if self.appear_then_click(POPUP_CANCEL): + return + + skip_first_screenshot = True + + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + if self.handle_reward(): + break + # by default, use one fuel each time + if self.appear_then_click(POPUP_CONFIRM): + continue \ No newline at end of file diff --git a/tasks/combat/prepare.py b/tasks/combat/prepare.py index a78bd5862..0b47a2c41 100644 --- a/tasks/combat/prepare.py +++ b/tasks/combat/prepare.py @@ -2,22 +2,14 @@ import re import module.config.server as server from module.base.timer import Timer -from module.base.utils import color_similar, get_color, crop, area_offset +from module.base.utils import color_similar, get_color from module.logger import logger from module.ocr.ocr import Digit, DigitCounter -from tasks.base.assets.assets_base_popup import POPUP_CONFIRM, POPUP_CANCEL from tasks.base.ui import UI from tasks.combat.assets.assets_combat_prepare import ( - EXTRACT_RESERVED_TRAILBLAZE_POWER, - FUEL, - FUEL_SELECTED, - OCR_FUEL, OCR_TRAILBLAZE_POWER, - OCR_RESERVED_TRAILBLAZE_POWER, OCR_WAVE_COST, OCR_WAVE_COUNT, - RESERVED_TRAILBLAZE_POWER_ENTRANCE, - FUEL_ENTRANCE, WAVE_MINUS, WAVE_PLUS, WAVE_SLIDER ) @@ -156,72 +148,3 @@ class CombatPrepare(UI): logger.warning(f'Get combat wave cost timeout, assume it costs {cost}') self.combat_wave_cost = cost return cost - - def combat_extract_reserved_trailblaze_power(self, skip_first_screenshot=True): - """ - Extract reserved trailblaze power from previous combat. - - Returns: - int: Reserved trailblaze power - """ - logger.info('Extract reserved trailblaze power') - current = Digit(OCR_RESERVED_TRAILBLAZE_POWER).ocr_single_line(self.device.image) - if current == 0: - logger.info('No reserved trailblaze power') - return - - while 1: - if skip_first_screenshot: - skip_first_screenshot = False - else: - self.device.screenshot() - - if self.appear_then_click(EXTRACT_RESERVED_TRAILBLAZE_POWER): - continue - if self.appear_then_click(RESERVED_TRAILBLAZE_POWER_ENTRANCE): - continue - if self.appear_then_click(POPUP_CONFIRM): - continue - if self.handle_reward(): - break - - def combat_use_fuel(self, skip_first_screenshot=True): - logger.info("Use Fuel") - while 1: - if skip_first_screenshot: - skip_first_screenshot = False - else: - self.device.screenshot() - - if self.appear(FUEL_SELECTED): - break - if self.appear_then_click(FUEL): - continue - if self.appear_then_click(FUEL_ENTRANCE): - continue - if self.handle_reward(): - break - - offset = FUEL_SELECTED.button_offset - count = Digit(OCR_FUEL).ocr_single_line(crop(self.device.image, area_offset(OCR_FUEL.area, offset)), - direct_ocr=True) - if count <= self.config.Dungeon_UseFuelUntilRemainCount: - logger.info("Fuel remain is under the threshold, stop using fuel") - while 1: - self.device.screenshot() - if self.appear_then_click(POPUP_CANCEL): - return - - skip_first_screenshot = True - - while 1: - if skip_first_screenshot: - skip_first_screenshot = False - else: - self.device.screenshot() - - if self.handle_reward(): - break - # by default, use one fuel each time - if self.appear_then_click(POPUP_CONFIRM): - continue