Add: use reserved trailblaze power/fuels properly
(max count that won't exceed trailblaze power limit)
BIN
assets/share/combat/prepare/FUEL_MINUS.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
assets/share/combat/prepare/FUEL_PLUS.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
assets/share/combat/prepare/FUEL_SLIDER.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
After Width: | Height: | Size: 9.4 KiB |
BIN
assets/share/combat/prepare/OCR_FUEL_COUNT.png
Normal file
After Width: | Height: | Size: 7.9 KiB |
BIN
assets/share/combat/prepare/RESERVED_MINUS.png
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/share/combat/prepare/RESERVED_PLUS.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
assets/share/combat/prepare/RESERVED_SLIDER.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
assets/share/combat/prepare/USING_FUEL.png
Normal file
After Width: | Height: | Size: 29 KiB |
@ -50,6 +50,26 @@ FUEL_ENTRANCE = ButtonWrapper(
|
|||||||
button=(1035, 26, 1056, 48),
|
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(
|
FUEL_SELECTED = ButtonWrapper(
|
||||||
name='FUEL_SELECTED',
|
name='FUEL_SELECTED',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -60,6 +80,26 @@ FUEL_SELECTED = ButtonWrapper(
|
|||||||
button=(587, 271, 692, 395),
|
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(
|
OCR_FUEL = ButtonWrapper(
|
||||||
name='OCR_FUEL',
|
name='OCR_FUEL',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -70,6 +110,16 @@ OCR_FUEL = ButtonWrapper(
|
|||||||
button=(605, 369, 678, 386),
|
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(
|
OCR_RESERVED_TRAILBLAZE_POWER = ButtonWrapper(
|
||||||
name='OCR_RESERVED_TRAILBLAZE_POWER',
|
name='OCR_RESERVED_TRAILBLAZE_POWER',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -110,6 +160,36 @@ OCR_WAVE_COUNT = ButtonWrapper(
|
|||||||
button=(911, 555, 1151, 581),
|
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(
|
RESERVED_TRAILBLAZE_POWER_ENTRANCE = ButtonWrapper(
|
||||||
name='RESERVED_TRAILBLAZE_POWER_ENTRANCE',
|
name='RESERVED_TRAILBLAZE_POWER_ENTRANCE',
|
||||||
share=Button(
|
share=Button(
|
||||||
@ -120,6 +200,16 @@ RESERVED_TRAILBLAZE_POWER_ENTRANCE = ButtonWrapper(
|
|||||||
button=(895, 26, 916, 48),
|
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(
|
WAVE_MINUS = ButtonWrapper(
|
||||||
name='WAVE_MINUS',
|
name='WAVE_MINUS',
|
||||||
share=Button(
|
share=Button(
|
||||||
|
@ -54,11 +54,7 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo
|
|||||||
|
|
||||||
# Check limits
|
# Check limits
|
||||||
if self.config.stored.TrailblazePower.value < self.combat_wave_cost:
|
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.value, self.combat_wave_cost)
|
||||||
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
|
|
||||||
if self.combat_waves <= 0:
|
if self.combat_waves <= 0:
|
||||||
logger.info('Combat wave limited, cannot continue combat')
|
logger.info('Combat wave limited, cannot continue combat')
|
||||||
return False
|
return False
|
||||||
@ -218,11 +214,8 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo
|
|||||||
if current >= self.combat_wave_cost * self.combat_waves:
|
if current >= self.combat_wave_cost * self.combat_waves:
|
||||||
logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can run again')
|
logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can run again')
|
||||||
return True
|
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:
|
else:
|
||||||
logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can not run again')
|
return self._try_get_more_trablaize_power(current, self.combat_wave_cost * self.combat_waves)
|
||||||
return False
|
|
||||||
elif self.combat_wave_cost <= 0:
|
elif self.combat_wave_cost <= 0:
|
||||||
logger.info(f'Free combat, combat costs {self.combat_wave_cost}, can not run again')
|
logger.info(f'Free combat, combat costs {self.combat_wave_cost}, can not run again')
|
||||||
return False
|
return False
|
||||||
@ -230,22 +223,24 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo
|
|||||||
if current >= self.combat_wave_cost:
|
if current >= self.combat_wave_cost:
|
||||||
logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can run again')
|
logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can run again')
|
||||||
return True
|
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:
|
else:
|
||||||
logger.info(f'Current has {current}, combat costs {self.combat_wave_cost}, can not run again')
|
return self._try_get_more_trablaize_power(current, self.combat_wave_cost * self.combat_waves)
|
||||||
return False
|
|
||||||
|
|
||||||
def _try_get_more_trablaize_power(self, current, cost):
|
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')
|
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()
|
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')
|
logger.info('Use fuel to get more trailblaze power')
|
||||||
self.use_fuel()
|
self.use_fuel(current)
|
||||||
current = self.combat_get_trailblaze_power()
|
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):
|
def _combat_should_reenter(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1,22 +1,38 @@
|
|||||||
|
|
||||||
|
import module.config.server as server
|
||||||
|
|
||||||
from module.base.utils import crop, area_offset
|
from module.base.utils import crop, area_offset
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from module.ocr.ocr import Digit
|
from module.ocr.ocr import Digit
|
||||||
from tasks.base.assets.assets_base_popup import POPUP_CONFIRM, POPUP_CANCEL
|
from tasks.base.assets.assets_base_popup import POPUP_CONFIRM, POPUP_CANCEL
|
||||||
from tasks.base.ui import UI
|
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_finish import COMBAT_AGAIN
|
||||||
from tasks.combat.assets.assets_combat_prepare import (
|
from tasks.combat.assets.assets_combat_prepare import (
|
||||||
COMBAT_PREPARE,
|
COMBAT_PREPARE,
|
||||||
EXTRACT_RESERVED_TRAILBLAZE_POWER,
|
EXTRACT_RESERVED_TRAILBLAZE_POWER,
|
||||||
FUEL,
|
FUEL,
|
||||||
|
FUEL_MINUS,
|
||||||
|
FUEL_PLUS,
|
||||||
FUEL_SELECTED,
|
FUEL_SELECTED,
|
||||||
OCR_FUEL,
|
OCR_FUEL,
|
||||||
|
OCR_FUEL_COUNT,
|
||||||
OCR_RESERVED_TRAILBLAZE_POWER,
|
OCR_RESERVED_TRAILBLAZE_POWER,
|
||||||
|
OCR_EXTRACT_RESERVED_TRAILBLAZE_POWER_COUNT,
|
||||||
RESERVED_TRAILBLAZE_POWER_ENTRANCE,
|
RESERVED_TRAILBLAZE_POWER_ENTRANCE,
|
||||||
|
RESERVED_MINUS,
|
||||||
|
RESERVED_PLUS,
|
||||||
|
RESERVED_SLIDER,
|
||||||
FUEL_ENTRANCE,
|
FUEL_ENTRANCE,
|
||||||
|
USING_FUEL,
|
||||||
|
FUEL_SLIDER
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Fuel(UI):
|
class Fuel(UI):
|
||||||
|
fuel_trailblaze_power = 60
|
||||||
|
trailblaze_max_limit = 240
|
||||||
|
|
||||||
def _use_fuel_finish(self):
|
def _use_fuel_finish(self):
|
||||||
"""
|
"""
|
||||||
Two possible finish states after using fuel/extract trailblaze power:
|
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)
|
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.
|
Extract reserved trailblaze power from previous combat.
|
||||||
|
|
||||||
@ -33,11 +49,29 @@ class Fuel(UI):
|
|||||||
int: Reserved trailblaze power
|
int: Reserved trailblaze power
|
||||||
"""
|
"""
|
||||||
logger.info('Extract reserved trailblaze power')
|
logger.info('Extract reserved trailblaze power')
|
||||||
current = Digit(OCR_RESERVED_TRAILBLAZE_POWER).ocr_single_line(self.device.image)
|
reserved = Digit(OCR_RESERVED_TRAILBLAZE_POWER).ocr_single_line(self.device.image)
|
||||||
if current == 0:
|
if reserved == 0:
|
||||||
logger.info('No reserved trailblaze power')
|
logger.info('No reserved trailblaze power')
|
||||||
return
|
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:
|
while 1:
|
||||||
if skip_first_screenshot:
|
if skip_first_screenshot:
|
||||||
skip_first_screenshot = False
|
skip_first_screenshot = False
|
||||||
@ -46,17 +80,35 @@ class Fuel(UI):
|
|||||||
|
|
||||||
if self._use_fuel_finish():
|
if self._use_fuel_finish():
|
||||||
break
|
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):
|
if self.appear_then_click(POPUP_CONFIRM):
|
||||||
continue
|
continue
|
||||||
if self.handle_reward():
|
if self.handle_reward():
|
||||||
continue
|
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")
|
logger.info("Use Fuel")
|
||||||
while 1:
|
while 1:
|
||||||
if skip_first_screenshot:
|
if skip_first_screenshot:
|
||||||
@ -77,7 +129,10 @@ class Fuel(UI):
|
|||||||
offset = FUEL_SELECTED.button_offset
|
offset = FUEL_SELECTED.button_offset
|
||||||
count = Digit(OCR_FUEL).ocr_single_line(crop(self.device.image, area_offset(OCR_FUEL.area, offset)),
|
count = Digit(OCR_FUEL).ocr_single_line(crop(self.device.image, area_offset(OCR_FUEL.area, offset)),
|
||||||
direct_ocr=True)
|
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")
|
logger.info("Fuel remain is under the threshold, stop using fuel")
|
||||||
while 1:
|
while 1:
|
||||||
self.device.screenshot()
|
self.device.screenshot()
|
||||||
@ -86,6 +141,21 @@ class Fuel(UI):
|
|||||||
|
|
||||||
skip_first_screenshot = True
|
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:
|
while 1:
|
||||||
if skip_first_screenshot:
|
if skip_first_screenshot:
|
||||||
skip_first_screenshot = False
|
skip_first_screenshot = False
|
||||||
@ -94,9 +164,7 @@ class Fuel(UI):
|
|||||||
|
|
||||||
if self._use_fuel_finish():
|
if self._use_fuel_finish():
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.handle_reward():
|
|
||||||
continue
|
|
||||||
# by default, use one fuel each time
|
|
||||||
if self.appear_then_click(POPUP_CONFIRM):
|
if self.appear_then_click(POPUP_CONFIRM):
|
||||||
|
continue
|
||||||
|
if self.handle_reward():
|
||||||
continue
|
continue
|