diff --git a/assets/share/combat/prepare/FUEL_MINUS.png b/assets/share/combat/prepare/FUEL_MINUS.png new file mode 100644 index 000000000..ed2382221 Binary files /dev/null and b/assets/share/combat/prepare/FUEL_MINUS.png differ diff --git a/assets/share/combat/prepare/FUEL_PLUS.png b/assets/share/combat/prepare/FUEL_PLUS.png new file mode 100644 index 000000000..97bbce249 Binary files /dev/null and b/assets/share/combat/prepare/FUEL_PLUS.png differ diff --git a/assets/share/combat/prepare/FUEL_SLIDER.png b/assets/share/combat/prepare/FUEL_SLIDER.png new file mode 100644 index 000000000..ba1e610e9 Binary files /dev/null and b/assets/share/combat/prepare/FUEL_SLIDER.png differ diff --git a/assets/share/combat/prepare/OCR_EXTRACT_RESERVED_TRAILBLAZE_POWER_COUNT.png b/assets/share/combat/prepare/OCR_EXTRACT_RESERVED_TRAILBLAZE_POWER_COUNT.png new file mode 100644 index 000000000..dfb042972 Binary files /dev/null and b/assets/share/combat/prepare/OCR_EXTRACT_RESERVED_TRAILBLAZE_POWER_COUNT.png differ diff --git a/assets/share/combat/prepare/OCR_FUEL_COUNT.png b/assets/share/combat/prepare/OCR_FUEL_COUNT.png new file mode 100644 index 000000000..4f304588a Binary files /dev/null and b/assets/share/combat/prepare/OCR_FUEL_COUNT.png differ diff --git a/assets/share/combat/prepare/RESERVED_MINUS.png b/assets/share/combat/prepare/RESERVED_MINUS.png new file mode 100644 index 000000000..674a78685 Binary files /dev/null and b/assets/share/combat/prepare/RESERVED_MINUS.png differ diff --git a/assets/share/combat/prepare/RESERVED_PLUS.png b/assets/share/combat/prepare/RESERVED_PLUS.png new file mode 100644 index 000000000..d6fe7bf76 Binary files /dev/null and b/assets/share/combat/prepare/RESERVED_PLUS.png differ diff --git a/assets/share/combat/prepare/RESERVED_SLIDER.png b/assets/share/combat/prepare/RESERVED_SLIDER.png new file mode 100644 index 000000000..8de0e9f36 Binary files /dev/null and b/assets/share/combat/prepare/RESERVED_SLIDER.png differ diff --git a/assets/share/combat/prepare/USING_FUEL.png b/assets/share/combat/prepare/USING_FUEL.png new file mode 100644 index 000000000..b9d962e7a Binary files /dev/null and b/assets/share/combat/prepare/USING_FUEL.png differ diff --git a/tasks/combat/assets/assets_combat_prepare.py b/tasks/combat/assets/assets_combat_prepare.py index 9360001ff..31ecca11a 100644 --- a/tasks/combat/assets/assets_combat_prepare.py +++ b/tasks/combat/assets/assets_combat_prepare.py @@ -50,6 +50,26 @@ FUEL_ENTRANCE = ButtonWrapper( button=(1035, 26, 1056, 48), ), ) +FUEL_MINUS = ButtonWrapper( + name='FUEL_MINUS', + share=Button( + file='./assets/share/combat/prepare/FUEL_MINUS.png', + area=(472, 425, 510, 450), + search=(452, 405, 530, 470), + color=(236, 236, 236), + button=(472, 425, 510, 450), + ), +) +FUEL_PLUS = ButtonWrapper( + name='FUEL_PLUS', + share=Button( + file='./assets/share/combat/prepare/FUEL_PLUS.png', + area=(967, 426, 1005, 449), + search=(947, 406, 1025, 469), + color=(232, 232, 232), + button=(967, 426, 1005, 449), + ), +) FUEL_SELECTED = ButtonWrapper( name='FUEL_SELECTED', share=Button( @@ -60,6 +80,26 @@ FUEL_SELECTED = ButtonWrapper( button=(587, 271, 692, 395), ), ) +FUEL_SLIDER = ButtonWrapper( + name='FUEL_SLIDER', + share=Button( + file='./assets/share/combat/prepare/FUEL_SLIDER.png', + area=(561, 434, 916, 441), + search=(541, 414, 936, 461), + color=(215, 185, 154), + button=(561, 434, 916, 441), + ), +) +OCR_EXTRACT_RESERVED_TRAILBLAZE_POWER_COUNT = ButtonWrapper( + name='OCR_EXTRACT_RESERVED_TRAILBLAZE_POWER_COUNT', + share=Button( + file='./assets/share/combat/prepare/OCR_EXTRACT_RESERVED_TRAILBLAZE_POWER_COUNT.png', + area=(425, 415, 688, 436), + search=(405, 395, 708, 456), + color=(192, 192, 192), + button=(425, 415, 688, 436), + ), +) OCR_FUEL = ButtonWrapper( name='OCR_FUEL', share=Button( @@ -70,6 +110,16 @@ OCR_FUEL = ButtonWrapper( button=(605, 369, 678, 386), ), ) +OCR_FUEL_COUNT = ButtonWrapper( + name='OCR_FUEL_COUNT', + share=Button( + file='./assets/share/combat/prepare/OCR_FUEL_COUNT.png', + area=(686, 409, 881, 425), + search=(666, 389, 901, 445), + color=(205, 205, 205), + button=(686, 409, 881, 425), + ), +) OCR_RESERVED_TRAILBLAZE_POWER = ButtonWrapper( name='OCR_RESERVED_TRAILBLAZE_POWER', share=Button( @@ -110,6 +160,36 @@ OCR_WAVE_COUNT = ButtonWrapper( button=(911, 555, 1151, 581), ), ) +RESERVED_MINUS = ButtonWrapper( + name='RESERVED_MINUS', + share=Button( + file='./assets/share/combat/prepare/RESERVED_MINUS.png', + area=(248, 474, 281, 498), + search=(228, 454, 301, 518), + color=(238, 238, 238), + button=(248, 474, 281, 498), + ), +) +RESERVED_PLUS = ButtonWrapper( + name='RESERVED_PLUS', + share=Button( + file='./assets/share/combat/prepare/RESERVED_PLUS.png', + area=(938, 475, 974, 498), + search=(918, 455, 994, 518), + color=(232, 232, 232), + button=(938, 475, 974, 498), + ), +) +RESERVED_SLIDER = ButtonWrapper( + name='RESERVED_SLIDER', + share=Button( + file='./assets/share/combat/prepare/RESERVED_SLIDER.png', + area=(334, 483, 873, 489), + search=(314, 463, 893, 509), + color=(212, 173, 130), + button=(334, 483, 873, 489), + ), +) RESERVED_TRAILBLAZE_POWER_ENTRANCE = ButtonWrapper( name='RESERVED_TRAILBLAZE_POWER_ENTRANCE', share=Button( @@ -120,6 +200,16 @@ RESERVED_TRAILBLAZE_POWER_ENTRANCE = ButtonWrapper( button=(895, 26, 916, 48), ), ) +USING_FUEL = ButtonWrapper( + name='USING_FUEL', + share=Button( + file='./assets/share/combat/prepare/USING_FUEL.png', + area=(263, 265, 363, 365), + search=(243, 245, 383, 385), + color=(161, 116, 129), + button=(263, 265, 363, 365), + ), +) WAVE_MINUS = ButtonWrapper( name='WAVE_MINUS', share=Button( diff --git a/tasks/combat/combat.py b/tasks/combat/combat.py index 2f044d1ba..250d693dd 100644 --- a/tasks/combat/combat.py +++ b/tasks/combat/combat.py @@ -54,11 +54,7 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo # Check limits if self.config.stored.TrailblazePower.value < self.combat_wave_cost: - if self.config.Dungeon_ExtractReservedTrailblazePower or self.config.Dungeon_UseFuel: - return self._try_get_more_trablaize_power(self.config.stored.TrailblazePower, self.combat_wave_cost) - else: - logger.info('Trailblaze power exhausted, cannot continue combat') - return False + return self._try_get_more_trablaize_power(self.config.stored.TrailblazePower.value, self.combat_wave_cost) if self.combat_waves <= 0: logger.info('Combat wave limited, cannot continue combat') return False @@ -218,11 +214,8 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo if current >= self.combat_wave_cost * self.combat_waves: logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can run again') return True - elif self.config.Dungeon_ExtractReservedTrailblazePower or self.config.Dungeon_UseFuel: - return self._try_get_more_trablaize_power(current, self.combat_wave_cost * self.combat_waves) else: - logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can not run again') - return False + return self._try_get_more_trablaize_power(current, self.combat_wave_cost * self.combat_waves) elif self.combat_wave_cost <= 0: logger.info(f'Free combat, combat costs {self.combat_wave_cost}, can not run again') return False @@ -230,22 +223,24 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo if current >= self.combat_wave_cost: logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can run again') return True - elif self.config.Dungeon_ExtractReservedTrailblazePower or self.config.Dungeon_UseFuel: - return self._try_get_more_trablaize_power(current, self.combat_wave_cost * self.combat_waves) else: - logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can not run again') - return False + return self._try_get_more_trablaize_power(current, self.combat_wave_cost * self.combat_waves) def _try_get_more_trablaize_power(self, current, cost): - if self.config.Dungeon_ExtractReservedTrailblazePower: + if self.config.TrailblazePower_ExtractReservedTrailblazePower: logger.info('Extract reserved trailblaze power to get more trailblaze power') - self.extract_reserved_trailblaze_power() + self.extract_reserved_trailblaze_power(current) current = self.combat_get_trailblaze_power() - if self.config.Dungeon_UseFuel: + if self.config.TrailblazePower_UseFuel: logger.info('Use fuel to get more trailblaze power') - self.use_fuel() + self.use_fuel(current) current = self.combat_get_trailblaze_power() - return current >= cost + + if current >= cost: + return True + else: + logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can not run again') + return False def _combat_should_reenter(self): """ diff --git a/tasks/combat/fuel.py b/tasks/combat/fuel.py index 321ee61b3..272aa10b4 100644 --- a/tasks/combat/fuel.py +++ b/tasks/combat/fuel.py @@ -1,22 +1,38 @@ + +import module.config.server as server + 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.item.slider import Slider from tasks.combat.assets.assets_combat_finish import COMBAT_AGAIN from tasks.combat.assets.assets_combat_prepare import ( COMBAT_PREPARE, EXTRACT_RESERVED_TRAILBLAZE_POWER, FUEL, + FUEL_MINUS, + FUEL_PLUS, FUEL_SELECTED, OCR_FUEL, + OCR_FUEL_COUNT, OCR_RESERVED_TRAILBLAZE_POWER, + OCR_EXTRACT_RESERVED_TRAILBLAZE_POWER_COUNT, RESERVED_TRAILBLAZE_POWER_ENTRANCE, + RESERVED_MINUS, + RESERVED_PLUS, + RESERVED_SLIDER, FUEL_ENTRANCE, + USING_FUEL, + FUEL_SLIDER ) class Fuel(UI): + fuel_trailblaze_power = 60 + trailblaze_max_limit = 240 + def _use_fuel_finish(self): """ Two possible finish states after using fuel/extract trailblaze power: @@ -25,7 +41,7 @@ class Fuel(UI): """ return self.appear(COMBAT_PREPARE) or self.appear(COMBAT_AGAIN) - def extract_reserved_trailblaze_power(self, skip_first_screenshot=True): + def extract_reserved_trailblaze_power(self, current, skip_first_screenshot=True): """ Extract reserved trailblaze power from previous combat. @@ -33,11 +49,29 @@ class Fuel(UI): 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: + reserved = Digit(OCR_RESERVED_TRAILBLAZE_POWER).ocr_single_line(self.device.image) + if reserved == 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(POPUP_CONFIRM): + break + if self.appear_then_click(EXTRACT_RESERVED_TRAILBLAZE_POWER): + continue + if self.appear_then_click(RESERVED_TRAILBLAZE_POWER_ENTRANCE): + continue + + count = min(reserved, self.trailblaze_max_limit - current) + self.set_reserved_trailblaze_power(count, total=reserved) + + skip_first_screenshot = True + while 1: if skip_first_screenshot: skip_first_screenshot = False @@ -46,17 +80,35 @@ class Fuel(UI): if self._use_fuel_finish(): break - - 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(): continue - def use_fuel(self, skip_first_screenshot=True): + def set_reserved_trailblaze_power(self, count, total): + slider = Slider(main=self, slider=RESERVED_SLIDER) + slider.set(count, total) + self.ui_ensure_index( + count, letter=Digit(OCR_EXTRACT_RESERVED_TRAILBLAZE_POWER_COUNT, lang=server.lang), + next_button=RESERVED_PLUS, prev_button=RESERVED_MINUS, + skip_first_screenshot=True + ) + + def set_fuel_count(self, count, total): + slider = Slider(main=self, slider=FUEL_SLIDER) + slider.set(count, total) + self.ui_ensure_index( + count, letter=Digit(OCR_FUEL_COUNT, lang=server.lang), + next_button=FUEL_PLUS, prev_button=FUEL_MINUS, + skip_first_screenshot=True + ) + + def use_fuel(self, current, skip_first_screenshot=True): + need = (self.trailblaze_max_limit - current) // self.fuel_trailblaze_power + if need == 0: + logger.info(f"Current trailblaze power is near {self.trailblaze_max_limit}, no need to use fuel") + return + logger.info("Use Fuel") while 1: if skip_first_screenshot: @@ -77,7 +129,10 @@ class Fuel(UI): 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: + + available_count = count - self.config.TrailblazePower_UseFuelUntilRemainCount + need = min(need, available_count) + if need <= 0: logger.info("Fuel remain is under the threshold, stop using fuel") while 1: self.device.screenshot() @@ -86,6 +141,21 @@ class Fuel(UI): skip_first_screenshot = True + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + if self.appear(USING_FUEL): + break + if self.appear(FUEL) and self.appear_then_click(POPUP_CONFIRM): + continue + + self.set_fuel_count(need, count) + + skip_first_screenshot = True + while 1: if skip_first_screenshot: skip_first_screenshot = False @@ -94,9 +164,7 @@ class Fuel(UI): if self._use_fuel_finish(): break - - if self.handle_reward(): - continue - # by default, use one fuel each time if self.appear_then_click(POPUP_CONFIRM): + continue + if self.handle_reward(): continue \ No newline at end of file