Fix: Confirm COMBAT_PREPARE before getting double remain

This commit is contained in:
LmeSzinc 2023-10-05 05:04:10 +08:00
parent c110d640a2
commit 36a452a9d4
4 changed files with 41 additions and 8 deletions

View File

@ -65,6 +65,27 @@ class Combat(CombatInteract, CombatPrepare, CombatState, CombatTeam, CombatSuppo
return False
def combat_enter_from_map(self, skip_first_screenshot=True):
"""
Pages:
in: page_main, DUNGEON_COMBAT_INTERACT
out: COMBAT_PREPARE
"""
logger.info('Combat enter from map')
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if self.appear(COMBAT_PREPARE):
# Confirm page loaded
if self.image_color_count(COMBAT_PREPARE.button, color=(230, 230, 230), threshold=240, count=400):
logger.info(f'At {COMBAT_PREPARE}')
break
if self.handle_combat_interact():
continue
def combat_prepare(self, team=1, support_character: str = None):
"""
Args:

View File

@ -97,9 +97,6 @@ class CombatPrepare(UI):
Pages:
in: COMBAT_PREPARE
"""
multi = self.combat_has_multi_wave()
logger.attr('CombatMultiWave', multi)
timeout = Timer(1.5, count=6).start()
while 1:
if skip_first_screenshot:
@ -115,7 +112,8 @@ class CombatPrepare(UI):
cost = Digit(OCR_WAVE_COST).ocr_single_line(self.device.image)
if cost == 10:
if multi:
logger.attr('CombatMultiWave', self.combat_has_multi_wave())
if self.combat_has_multi_wave():
self.combat_wave_cost = cost
return cost
else:
@ -123,7 +121,7 @@ class CombatPrepare(UI):
self.combat_wave_cost = cost
return cost
elif cost in [30, 40]:
if multi:
if self.combat_has_multi_wave():
logger.warning(f'Combat wave costs {cost} but has multiple waves, '
f'probably wave amount is preset')
self.combat_set_wave(1)
@ -131,13 +129,15 @@ class CombatPrepare(UI):
timeout.reset()
continue
else:
logger.attr('CombatMultiWave', self.combat_has_multi_wave())
self.combat_wave_cost = cost
return cost
else:
logger.warning(f'Unexpected combat wave cost: {cost}')
continue
if multi:
logger.attr('CombatMultiWave', self.combat_has_multi_wave())
if self.combat_has_multi_wave():
cost = 10
else:
cost = 40

View File

@ -32,7 +32,8 @@ class Dungeon(DungeonUI, DungeonEvent, Combat):
int: Run count
Pages:
in: Any
in: page_main, DUNGEON_COMBAT_INTERACT
or COMBAT_PREPARE
out: page_main
"""
if team is None:
@ -51,6 +52,8 @@ class Dungeon(DungeonUI, DungeonEvent, Combat):
if self.handle_destructible_around_blaze():
self.dungeon_tab_goto(KEYWORDS_DUNGEON_TAB.Survival_Index)
self.dungeon_goto(dungeon)
self.combat_enter_from_map()
# Check double event remain before combat
# Conservatively prefer the smaller result
if (dungeon.is_Calyx_Golden or dungeon.is_Calyx_Crimson) and \

View File

@ -52,7 +52,7 @@ class DungeonEvent(UI):
has = self.image_color_count(
OCR_DOUBLE_EVENT_REMAIN_AT_COMBAT,
color=(252, 209, 123),
threshold=221, count=1000
threshold=195, count=1000
)
logger.attr('Double event at combat', has)
return has
@ -84,4 +84,13 @@ class DungeonEvent(UI):
remain = self._get_double_event_remain(
OCR_DOUBLE_EVENT_REMAIN_AT_COMBAT)
logger.attr('Double event remain at combat', remain)
if remain == 0:
self.device.image_save()
exit(1)
return remain
if __name__ == '__main__':
self = DungeonEvent('src')
self.device.screenshot()
self.get_double_event_remain_at_combat()