mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-09 10:29:04 +08:00
Fix: infinite loop in _handle_use_box_amount when box count insufficient (#5516)
When requesting more boxes than available (e.g. requesting 8 but only 3 in stack), the amount-setting loop would never exit because the UI caps at the available count while the script keeps clicking AMOUNT_PLUS. Added click_count tracking: if multi_click() has been called 2 times without the amount reaching the target, treat it as the UI cap and break. Also changed the return value from bool to the actual amount set, so _storage_use_one_box tracks the correct number of boxes used.
This commit is contained in:
parent
0a4f2a89fc
commit
a538739910
@ -45,8 +45,12 @@ class StorageHandler(StorageUI):
|
||||
|
||||
def _handle_use_box_amount(self, amount):
|
||||
"""
|
||||
Args:
|
||||
amount (int): Expected amount to set
|
||||
|
||||
Returns:
|
||||
bool: if clicked
|
||||
int: Actual amount set in the UI.
|
||||
May be less than expected if not enough boxes available.
|
||||
|
||||
Pages:
|
||||
in: SHOP_BUY_CONFIRM_AMOUNT
|
||||
@ -84,6 +88,7 @@ class StorageHandler(StorageUI):
|
||||
logger.info(f'Set box amount: {amount}')
|
||||
skip_first = True
|
||||
retry = Timer(1, count=2)
|
||||
click_count = 0
|
||||
for _ in self.loop():
|
||||
if skip_first:
|
||||
skip_first = False
|
||||
@ -92,13 +97,19 @@ class StorageHandler(StorageUI):
|
||||
diff = amount - current
|
||||
if diff == 0:
|
||||
break
|
||||
if click_count >= 2:
|
||||
logger.warning(f'Box amount stuck at {current}, '
|
||||
f'requested {amount} but only {current} available')
|
||||
break
|
||||
|
||||
if retry.reached():
|
||||
button = AMOUNT_PLUS if diff > 0 else AMOUNT_MINUS
|
||||
self.device.multi_click(button, n=abs(diff), interval=(0.1, 0.2))
|
||||
click_count += 1
|
||||
retry.reset()
|
||||
|
||||
return True
|
||||
logger.info(f'Box amount set to {current}')
|
||||
return current
|
||||
|
||||
def _storage_use_one_box(self, button, amount=1):
|
||||
"""
|
||||
@ -155,10 +166,10 @@ class StorageHandler(StorageUI):
|
||||
# use match_template_color on BOX_AMOUNT_CONFIRM
|
||||
# a long animation that opens a box, will be on the top of BOX_AMOUNT_CONFIRM
|
||||
if self.match_template_color(BOX_AMOUNT_CONFIRM, offset=(20, 20), interval=5):
|
||||
self._handle_use_box_amount(amount)
|
||||
actual = self._handle_use_box_amount(amount)
|
||||
self.device.click(BOX_AMOUNT_CONFIRM)
|
||||
self.interval_reset(BOX_AMOUNT_CONFIRM)
|
||||
used = amount
|
||||
used = actual
|
||||
continue
|
||||
if self.appear_then_click(EQUIP_CONFIRM, offset=(20, 20), interval=5):
|
||||
self.interval_reset(MATERIAL_CHECK)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user