mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-16 06:25:24 +00:00
Fix: Check assignment status with timeout
This commit is contained in:
parent
aad72ea533
commit
afdef03711
@ -1,12 +1,10 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from tasks.assignment.assets.assets_assignment_claim import CLAIM
|
|
||||||
from tasks.assignment.assets.assets_assignment_dispatch import EMPTY_SLOT
|
|
||||||
from tasks.assignment.assets.assets_assignment_ui import DISPATCHED
|
|
||||||
from tasks.assignment.claim import AssignmentClaim
|
from tasks.assignment.claim import AssignmentClaim
|
||||||
from tasks.assignment.keywords import (KEYWORDS_ASSIGNMENT_GROUP,
|
from tasks.assignment.keywords import (KEYWORDS_ASSIGNMENT_GROUP,
|
||||||
AssignmentEntry, AssignmentEventGroup)
|
AssignmentEntry, AssignmentEventGroup)
|
||||||
|
from tasks.assignment.ui import AssignmentStatus
|
||||||
from tasks.base.page import page_assignment, page_menu
|
from tasks.base.page import page_assignment, page_menu
|
||||||
from tasks.battle_pass.keywords import KEYWORD_BATTLE_PASS_QUEST
|
from tasks.battle_pass.keywords import KEYWORD_BATTLE_PASS_QUEST
|
||||||
from tasks.daily.keywords import KEYWORDS_DAILY_QUEST
|
from tasks.daily.keywords import KEYWORDS_DAILY_QUEST
|
||||||
@ -105,13 +103,15 @@ class Assignment(AssignmentClaim, SynthesizeUI):
|
|||||||
logger.hr('Assignment inlist', level=2)
|
logger.hr('Assignment inlist', level=2)
|
||||||
logger.info(f'Check assignment inlist: {assignment}')
|
logger.info(f'Check assignment inlist: {assignment}')
|
||||||
self.goto_entry(assignment)
|
self.goto_entry(assignment)
|
||||||
if self.appear(CLAIM):
|
status = self._check_assignment_status()
|
||||||
|
if status == AssignmentStatus.CLAIMABLE:
|
||||||
self.claim(assignment, duration, should_redispatch=True)
|
self.claim(assignment, duration, should_redispatch=True)
|
||||||
continue
|
continue
|
||||||
if self.appear(DISPATCHED):
|
if status == AssignmentStatus.DISPATCHED:
|
||||||
self.dispatched[assignment] = datetime.now() + \
|
self.dispatched[assignment] = datetime.now() + \
|
||||||
self._get_assignment_time()
|
self._get_assignment_time()
|
||||||
continue
|
continue
|
||||||
|
# General assignments must be dispatchable here
|
||||||
if remain > 0:
|
if remain > 0:
|
||||||
self.dispatch(assignment, duration)
|
self.dispatch(assignment, duration)
|
||||||
remain -= 1
|
remain -= 1
|
||||||
@ -138,11 +138,12 @@ class Assignment(AssignmentClaim, SynthesizeUI):
|
|||||||
logger.hr('Assignment all', level=2)
|
logger.hr('Assignment all', level=2)
|
||||||
logger.info(f'Check assignment all: {assignment}')
|
logger.info(f'Check assignment all: {assignment}')
|
||||||
self.goto_entry(assignment)
|
self.goto_entry(assignment)
|
||||||
if self.appear(CLAIM):
|
status = self._check_assignment_status()
|
||||||
|
if status == AssignmentStatus.CLAIMABLE:
|
||||||
self.claim(assignment, None, should_redispatch=False)
|
self.claim(assignment, None, should_redispatch=False)
|
||||||
remain += 1
|
remain += 1
|
||||||
continue
|
continue
|
||||||
if self.appear(DISPATCHED):
|
if status == AssignmentStatus.DISPATCHED:
|
||||||
self.dispatched[assignment] = datetime.now() + \
|
self.dispatched[assignment] = datetime.now() + \
|
||||||
self._get_assignment_time()
|
self._get_assignment_time()
|
||||||
if total == len(self.dispatched):
|
if total == len(self.dispatched):
|
||||||
@ -196,13 +197,13 @@ class Assignment(AssignmentClaim, SynthesizeUI):
|
|||||||
logger.hr('Assignment event', level=2)
|
logger.hr('Assignment event', level=2)
|
||||||
logger.info(f'Check assignment event: {assignment}')
|
logger.info(f'Check assignment event: {assignment}')
|
||||||
self.goto_entry(assignment)
|
self.goto_entry(assignment)
|
||||||
# No need to check dispatched here, should have been checked in _check_all
|
status = self._check_assignment_status()
|
||||||
if self.appear(EMPTY_SLOT):
|
# Should only be dispatchable or locked after _check_all
|
||||||
|
if status == AssignmentStatus.DISPATCHABLE:
|
||||||
self.dispatch(assignment, None)
|
self.dispatch(assignment, None)
|
||||||
remain -= 1
|
remain -= 1
|
||||||
if remain <= 0:
|
if remain <= 0:
|
||||||
return remain
|
return remain
|
||||||
continue
|
continue
|
||||||
logger.info('Assignment is locked')
|
|
||||||
break
|
break
|
||||||
return remain
|
return remain
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from enum import Enum
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
|
|
||||||
from module.base.timer import Timer
|
from module.base.timer import Timer
|
||||||
@ -8,11 +9,20 @@ from module.exception import ScriptError
|
|||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from module.ocr.ocr import DigitCounter, Duration, Ocr
|
from module.ocr.ocr import DigitCounter, Duration, Ocr
|
||||||
from module.ui.draggable_list import DraggableList
|
from module.ui.draggable_list import DraggableList
|
||||||
|
from tasks.assignment.assets.assets_assignment_claim import CLAIM
|
||||||
|
from tasks.assignment.assets.assets_assignment_dispatch import EMPTY_SLOT
|
||||||
from tasks.assignment.assets.assets_assignment_ui import *
|
from tasks.assignment.assets.assets_assignment_ui import *
|
||||||
from tasks.assignment.keywords import *
|
from tasks.assignment.keywords import *
|
||||||
from tasks.base.ui import UI
|
from tasks.base.ui import UI
|
||||||
|
|
||||||
|
|
||||||
|
class AssignmentStatus(Enum):
|
||||||
|
CLAIMABLE = 0
|
||||||
|
DISPATCHED = 1
|
||||||
|
DISPATCHABLE = 2
|
||||||
|
LOCKED = 3
|
||||||
|
|
||||||
|
|
||||||
class AssignmentOcr(Ocr):
|
class AssignmentOcr(Ocr):
|
||||||
# EN has names in multiple rows
|
# EN has names in multiple rows
|
||||||
merge_thres_y = 20
|
merge_thres_y = 20
|
||||||
@ -191,6 +201,28 @@ class AssignmentUI(UI):
|
|||||||
self.config.stored.Assignment.set(0, 0)
|
self.config.stored.Assignment.set(0, 0)
|
||||||
return current, remain, total
|
return current, remain, total
|
||||||
|
|
||||||
|
def _check_assignment_status(self) -> AssignmentStatus:
|
||||||
|
skip_first_screenshot = True
|
||||||
|
timeout = Timer(2, count=3).start()
|
||||||
|
while 1:
|
||||||
|
if skip_first_screenshot:
|
||||||
|
skip_first_screenshot = False
|
||||||
|
else:
|
||||||
|
self.device.screenshot()
|
||||||
|
|
||||||
|
if timeout.reached():
|
||||||
|
logger.info(
|
||||||
|
'Check assignment status timeout, assume LOCKED'
|
||||||
|
)
|
||||||
|
break
|
||||||
|
if self.appear(CLAIM):
|
||||||
|
return AssignmentStatus.CLAIMABLE
|
||||||
|
if self.appear(DISPATCHED):
|
||||||
|
return AssignmentStatus.DISPATCHED
|
||||||
|
if self.appear(EMPTY_SLOT):
|
||||||
|
return AssignmentStatus.DISPATCHABLE
|
||||||
|
return AssignmentStatus.LOCKED
|
||||||
|
|
||||||
def _get_assignment_time(self) -> timedelta:
|
def _get_assignment_time(self) -> timedelta:
|
||||||
return Duration(OCR_ASSIGNMENT_TIME).ocr_single_line(self.device.image)
|
return Duration(OCR_ASSIGNMENT_TIME).ocr_single_line(self.device.image)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user