Add: Task DailyQuest

This commit is contained in:
LmeSzinc 2023-06-18 18:41:58 +08:00
parent c8fcd5f0f3
commit 74562d03e4
15 changed files with 123 additions and 20 deletions

View File

@ -37,11 +37,19 @@
"Enable": false,
"NextRun": "2020-01-01 00:00:00",
"Command": "Dungeon",
"ServerUpdate": "00:00"
"ServerUpdate": "04:00"
},
"Dungeon": {
"Name": "Calyx_Golden_Memories",
"Team": 1
}
},
"DailyQuest": {
"Scheduler": {
"Enable": false,
"NextRun": "2020-01-01 00:00:00",
"Command": "DailyQuest",
"ServerUpdate": "04:00"
}
}
}

View File

@ -163,7 +163,7 @@
},
"ServerUpdate": {
"type": "input",
"value": "00:00",
"value": "04:00",
"display": "hide"
}
},
@ -212,5 +212,28 @@
]
}
}
},
"DailyQuest": {
"Scheduler": {
"Enable": {
"type": "checkbox",
"value": false
},
"NextRun": {
"type": "datetime",
"value": "2020-01-01 00:00:00",
"validate": "datetime"
},
"Command": {
"type": "input",
"value": "DailyQuest",
"display": "hide"
},
"ServerUpdate": {
"type": "input",
"value": "04:00",
"display": "hide"
}
}
}
}

View File

@ -9,7 +9,7 @@ Scheduler:
NextRun: 2020-01-01 00:00:00
Command: Alas
ServerUpdate:
value: 00:00
value: 04:00
display: hide
Emulator:
Serial:
@ -67,7 +67,7 @@ Optimization:
value: goto_main
option: [ stay_there, goto_main, close_game ]
# ==================== Farm ====================
# ==================== Daily ====================
Dungeon:
Name:
@ -77,9 +77,3 @@ Dungeon:
Team:
value: 1
option: [ 1, 2, 3, 4, 5, 6 ]
# ==================== Daily ====================
# ==================== Tools ====================

View File

@ -11,7 +11,8 @@
"menu": "list",
"page": "setting",
"tasks": [
"Dungeon"
"Dungeon",
"DailyQuest"
]
}
}

View File

@ -25,3 +25,5 @@ Daily:
Dungeon:
- Scheduler
- Dungeon
DailyQuest:
- Scheduler

View File

@ -13,7 +13,7 @@ class GeneratedConfig:
Scheduler_Enable = False
Scheduler_NextRun = datetime.datetime(2020, 1, 1, 0, 0)
Scheduler_Command = 'Alas'
Scheduler_ServerUpdate = '00:00'
Scheduler_ServerUpdate = '04:00'
# Group `Emulator`
Emulator_Serial = 'auto'

View File

@ -10,7 +10,7 @@ class ManualConfig:
SCHEDULER_PRIORITY = """
Restart
> Dungeon
> Dungeon > DailyQuest
"""
"""

View File

@ -21,6 +21,10 @@
"Dungeon": {
"name": "Dungeon",
"help": ""
},
"DailyQuest": {
"name": "Daily Quest",
"help": ""
}
},
"Scheduler": {

View File

@ -21,6 +21,10 @@
"Dungeon": {
"name": "Task.Dungeon.name",
"help": "Task.Dungeon.help"
},
"DailyQuest": {
"name": "Task.DailyQuest.name",
"help": "Task.DailyQuest.help"
}
},
"Scheduler": {

View File

@ -21,6 +21,10 @@
"Dungeon": {
"name": "每日副本",
"help": ""
},
"DailyQuest": {
"name": "每日任务",
"help": ""
}
},
"Scheduler": {

View File

@ -21,6 +21,10 @@
"Dungeon": {
"name": "每日副本",
"help": ""
},
"DailyQuest": {
"name": "每日任務",
"help": ""
}
},
"Scheduler": {

4
src.py
View File

@ -26,6 +26,10 @@ class StarRailCopilot(AzurLaneAutoScript):
from tasks.dungeon.dungeon import Dungeon
Dungeon(config=self.config, device=self.device).run()
def daily_quest(self):
from tasks.daily.daily_quest import DailyQuestUI
DailyQuestUI(config=self.config, device=self.device).run()
if __name__ == '__main__':
src = StarRailCopilot('src')

View File

@ -17,6 +17,7 @@ class CameraUI(UI):
in: Any
out: page_camera, TAKE_PICTURE
"""
logger.hr('Take picture', level=2)
self.ui_ensure(page_camera, skip_first_screenshot)
# Take picture
skip_first_screenshot = True

View File

@ -5,7 +5,9 @@ from module.logger import *
from module.ocr.ocr import Ocr, OcrResultButton
from module.ocr.utils import split_and_pair_buttons
from tasks.daily.assets.assets_daily_reward import *
from tasks.daily.keywords import DailyQuest, DailyQuestState, KEYWORDS_DAILY_QUEST_STATE
from tasks.daily.camera import CameraUI
from tasks.daily.keywords import DailyQuest, DailyQuestState, KEYWORDS_DAILY_QUEST, KEYWORDS_DAILY_QUEST_STATE
from tasks.daily.synthesize import SynthesizeConsumablesUI
from tasks.dungeon.keywords import KEYWORDS_DUNGEON_TAB
from tasks.dungeon.ui import DungeonUI
@ -20,6 +22,11 @@ class DailyQuestOcr(Ocr):
result = result.replace("J", "")
result = result.replace(";", "")
result = result.replace("宇审", "宇宙")
# 进行中」hbadarin
if "进行中" in result:
result = "进行中"
if "已领取" in result:
result = "已领取"
return result
@ -85,8 +92,6 @@ class DailyQuestUI(DungeonUI):
results = [result.matched_keyword for result in results]
logger.info("Daily quests recognition complete")
logger.info(f"Daily quests: {results}")
if len(results) != 6:
logger.warning(f'Unexpected amount of daily quests: {len(results)}')
return results
def _get_quest_reward(self, skip_first_screenshot=True):
@ -111,6 +116,9 @@ class DailyQuestUI(DungeonUI):
and (self.appear(ACTIVE_POINTS_5_LOCKED) or self.appear(ACTIVE_POINTS_5_CHECKED))
)
def _all_reward_got(self):
return self.appear(ACTIVE_POINTS_5_CHECKED)
def _get_active_point_reward(self, skip_first_screenshot=True):
while 1:
if skip_first_screenshot:
@ -134,9 +142,55 @@ class DailyQuestUI(DungeonUI):
continue
def get_daily_rewards(self):
"""
Returns:
int: If all reward got.
Pages:
in: Any
out: page_guide, Daily_Training
"""
logger.hr('Get daily rewards', level=2)
self.dungeon_tab_goto(KEYWORDS_DUNGEON_TAB.Daily_Training)
logger.info("Getting quest rewards")
self._get_quest_reward()
logger.info("Getting active point rewards")
self._get_active_point_reward()
if self._all_reward_got():
logger.info("All daily reward got")
return True
else:
logger.info('Daily reward got but not yet claimed')
return False
def do_daily_quests(self):
"""
Returns:
int: Number of quests done
"""
logger.hr('Recognize quests', level=1)
quests = self.daily_quests_recognition()
done = 0
logger.hr('Do quests', level=1)
if KEYWORDS_DAILY_QUEST.Take_1_photo in quests:
CameraUI(self.config, self.device).take_picture()
done += 1
if KEYWORDS_DAILY_QUEST.Synthesize_Consumable_1_time in quests:
SynthesizeConsumablesUI(self.config, self.device).synthesize_consumables()
done += 1
return done
def run(self):
for _ in range(5):
got = self.get_daily_rewards()
if got:
break
done = self.do_daily_quests()
if not done:
logger.info('No more quests able to do')
break
# Scheduler
self.config.task_delay(server_update=True)

View File

@ -57,7 +57,7 @@ class SynthesizeUI(UI):
class SynthesizeConsumablesUI(SynthesizeUI):
def synthesize(self) -> bool:
def synthesize_consumables(self) -> bool:
"""
Returns:
bool:
@ -65,9 +65,9 @@ class SynthesizeConsumablesUI(SynthesizeUI):
Examples:
self = SynthesizeConsumablesUI('alas')
self.device.screenshot()
result = self.synthesize()
result = self.synthesize_consumables()
"""
logger.hr('Synthesize consumables', level=2)
# If the current page is not the menu page,
# the menu scroll bar must be at the top when opening the menu page from other page,
# so first step is determine whether the scroll bar is at the top