feat(task): 优化再开中断培育

1. 支持自动检测模式与周数
2. 支持从考试周开始培育
This commit is contained in:
XcantloadX 2025-04-04 21:58:23 +08:00
parent e44a17dbf8
commit c56f9c128f
5 changed files with 61 additions and 22 deletions

View File

@ -1 +1 @@
{"definitions":{"ccbcb114-7f73-43d1-904a-3a7ae660c531":{"name":"Produce.ButtonResume","displayName":"再開する","type":"template","annotationId":"ccbcb114-7f73-43d1-904a-3a7ae660c531","useHintRect":false},"daf3d823-b7f1-4584-acf3-90b9d880332c":{"name":"Produce.BoxResumeDialogProduceType","displayName":"培育再开始对话框 培育类型","type":"hint-box","annotationId":"daf3d823-b7f1-4584-acf3-90b9d880332c","useHintRect":false},"616273d6-49f1-42e5-a6be-df5408d69a4b":{"name":"Produce.BoxResumeDialogIdolTitle","displayName":"培育再开始对话框 偶像名称","type":"hint-box","annotationId":"616273d6-49f1-42e5-a6be-df5408d69a4b","useHintRect":false}},"annotations":[{"id":"ccbcb114-7f73-43d1-904a-3a7ae660c531","type":"rect","data":{"x1":390,"y1":1141,"x2":580,"y2":1181}},{"id":"daf3d823-b7f1-4584-acf3-90b9d880332c","type":"rect","data":{"x1":186,"y1":491,"x2":541,"y2":550}},{"id":"616273d6-49f1-42e5-a6be-df5408d69a4b","type":"rect","data":{"x1":194,"y1":794,"x2":523,"y2":840}}]}
{"definitions":{"ccbcb114-7f73-43d1-904a-3a7ae660c531":{"name":"Produce.ButtonResume","displayName":"再開する","type":"template","annotationId":"ccbcb114-7f73-43d1-904a-3a7ae660c531","useHintRect":false},"daf3d823-b7f1-4584-acf3-90b9d880332c":{"name":"Produce.ResumeDialogRegular","displayName":"培育再开对话框 REGULAR","type":"template","annotationId":"daf3d823-b7f1-4584-acf3-90b9d880332c","useHintRect":false},"deb35d68-bbac-4636-a93a-1b039c5d4fb1":{"name":"Produce.BoxResumeDialogWeeks","displayName":"再开培育对话框 当前周数区域","type":"hint-box","annotationId":"deb35d68-bbac-4636-a93a-1b039c5d4fb1","useHintRect":false},"d5335ad3-8859-4f4f-99b3-c88d2cd2b966":{"name":"Produce.BoxResumeDialogIdolCard","displayName":"再开培育对话框 偶像卡区域","type":"hint-box","annotationId":"d5335ad3-8859-4f4f-99b3-c88d2cd2b966","useHintRect":false}},"annotations":[{"id":"ccbcb114-7f73-43d1-904a-3a7ae660c531","type":"rect","data":{"x1":390,"y1":1141,"x2":580,"y2":1181}},{"id":"daf3d823-b7f1-4584-acf3-90b9d880332c","type":"rect","data":{"x1":399,"y1":510,"x2":501,"y2":532}},{"id":"deb35d68-bbac-4636-a93a-1b039c5d4fb1","type":"rect","data":{"x1":504,"y1":559,"x2":643,"y2":595}},{"id":"d5335ad3-8859-4f4f-99b3-c88d2cd2b966","type":"rect","data":{"x1":53,"y1":857,"x2":197,"y2":1048}}]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 KiB

View File

@ -0,0 +1 @@
{"definitions":{"c954e153-d3e9-4488-869f-d00cfdfac5ee":{"name":"Produce.ResumeDialogPro","displayName":"培育再开对话框 PRO","type":"template","annotationId":"c954e153-d3e9-4488-869f-d00cfdfac5ee","useHintRect":false}},"annotations":[{"id":"c954e153-d3e9-4488-869f-d00cfdfac5ee","type":"rect","data":{"x1":426,"y1":509,"x2":472,"y2":533}}]}

View File

@ -1112,7 +1112,7 @@ def detect_produce_scene(ctx: DispatcherContext) -> ProduceStage:
return 'unknown'
@action('开始 Regular 培育')
def hajime_regular_from_stage(stage: ProduceStage, type: Literal['regular', 'pro']):
def hajime_regular_from_stage(stage: ProduceStage, type: Literal['regular', 'pro'], week: int):
"""
开始 Regular 培育
"""
@ -1137,39 +1137,52 @@ def hajime_regular_from_stage(stage: ProduceStage, type: Literal['regular', 'pro
elif stage == 'exam-start':
device.click_center()
until_exam_scene()
exam()
if type == 'regular':
hajime_regular(start_from=week)
elif type == 'pro':
hajime_pro(start_from=week)
elif stage == 'exam-ongoing':
# TODO: 应该直接调用 week_final_exam 而不是再写一次
logger.info("Exam ongoing. Start exam.")
exam()
result = ocr.expect_wait(contains('中間|最終'))
if '中間' in result.text:
return hajime_regular_from_stage(detect_produce_scene(), type)
elif '最終' in result.text:
produce_end()
else:
raise UnrecoverableError("Failed to detect produce stage.")
if type == 'regular':
if week > 6: # 第六周为期中考试
exam('final')
return produce_end()
else:
exam('mid')
return hajime_regular_from_stage(detect_produce_scene(), type, week)
elif type == 'pro':
if week > 7:
exam('final')
return produce_end()
else:
exam('mid')
return hajime_regular_from_stage(detect_produce_scene(), type, week)
elif stage == 'practice-ongoing':
# TODO: 应该直接调用 week_final_exam 而不是再写一次
logger.info("Practice ongoing. Start practice.")
practice()
return hajime_regular_from_stage(detect_produce_scene(), type)
return hajime_regular_from_stage(detect_produce_scene(), type, week)
else:
raise UnrecoverableError(f'Cannot resume produce REGULAR from stage "{stage}".')
@action('继续 Regular 培育')
def resume_regular_produce():
def resume_regular_produce(week: int):
"""
继续 Regular 培育
:param week: 当前周数
"""
hajime_regular_from_stage(detect_produce_scene(), 'regular')
hajime_regular_from_stage(detect_produce_scene(), 'regular', week)
@action('继续 PRO 培育')
def resume_pro_produce():
def resume_pro_produce(week: int):
"""
继续 PRO 培育
:param week: 当前周数
"""
hajime_regular_from_stage(detect_produce_scene(), 'pro')
hajime_regular_from_stage(detect_produce_scene(), 'pro', week)
if __name__ == '__main__':
from logging import getLogger
@ -1220,7 +1233,7 @@ if __name__ == '__main__':
# hajime_pro(start_from=16)
# exam('mid')
stage = (detect_produce_scene())
hajime_regular_from_stage(stage, 'pro')
hajime_regular_from_stage(stage, 'pro', 0)
# click_recommended_card(card_count=skill_card_count())
# exam('mid')

View File

@ -12,7 +12,7 @@ from .. import R
from ..common import conf
from ..actions.scenes import at_home, goto_home
from ..game_ui.idols_overview import locate_idol
from ..produce.in_purodyuusu import hajime_pro, hajime_regular, resume_regular_produce
from ..produce.in_purodyuusu import hajime_pro, hajime_regular, resume_pro_produce, resume_regular_produce
from kotonebot import device, image, ocr, task, action, sleep, contains
logger = logging.getLogger(__name__)
@ -116,7 +116,7 @@ def select_set(index: int):
logger.error(f'Failed to navigate to set #{index} after {max_retries} retries.')
@action('继续当前培育')
@action('继续当前培育', screenshot_mode='manual-inherit')
def resume_produce():
"""
继续当前培育
@ -124,16 +124,41 @@ def resume_produce():
前置条件游戏首页且当前有进行中培育\n
结束状态游戏首页
"""
device.screenshot()
# 点击 プロデュース中
# [res/sprites/jp/daily/home_1.png]
logger.info('Click ongoing produce button.')
device.click(R.Produce.BoxProduceOngoing)
btn_resume = image.expect_wait(R.Produce.ButtonResume)
# 判断信息
mode_result = image.find_multi([
R.Produce.ResumeDialogRegular,
R.Produce.ResumeDialogPro,
])
if not mode_result:
raise ValueError('Failed to detect produce mode.')
if mode_result.index == 0:
mode = 'regular'
else:
mode = 'pro'
logger.info(f'Produce mode: {mode}')
week_text = ocr.ocr(R.Produce.BoxResumeDialogWeeks).squash().regex(r'\d+/\d+')
if not week_text:
raise ValueError('Failed to detect weeks(1).')
weeks = week_text[0].split('/')
if len(weeks) < 2:
raise ValueError('Failed to detect weeks(2).')
current_week = int(weeks[0])
logger.info(f'Current week: {weeks[0]}/{weeks[1]}')
# 点击 再開する
# [res/sprites/jp/produce/produce_resume.png]
# [kotonebot-resource/sprites/jp/produce/produce_resume.png]
logger.info('Click resume button.')
device.click(image.expect_wait(R.Produce.ButtonResume))
device.click(btn_resume)
# 继续流程
resume_regular_produce()
if mode == 'regular':
resume_regular_produce(current_week)
else:
resume_pro_produce(current_week)
@action('执行培育', screenshot_mode='manual-inherit')
def do_produce(