Pārlūkot izejas kodu

feat(Quiz): Add the option to set max number of questions in quiz per round

huangrunheng 2 gadi atpakaļ
vecāks
revīzija
f058aedba0

+ 2 - 0
tasks/DemonEncounter/data/data.csv

@@ -1567,3 +1567,5 @@ SSR式神可以通过多少个对应的式神碎片召唤获得,50
 在炎热的夏天狗通过什么方式散热,张口呼吸
 灶门祢豆子通过哪种方式恢复体力,睡觉
 每个式神最多可以装备几个御魂,6
+剧情中阁魔要求晴明镇压的妖怪是谁,傀儡师
+百鬼夜行中非鬼尺级式神每次可以提供多少碎片,3片

+ 3 - 1
tasks/Quiz/config.py

@@ -7,8 +7,10 @@ from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase
 
 class QuizConfig(ConfigBase):
-    #
+    # 打多少轮
     quiz_cnt: int = Field(default=1, description='quiz_cnt_help')
+    # 每轮多少道题
+    quiz_per_round: int = Field(default=150, description='quiz_per_round_help')
 
 class Quiz(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)

+ 20 - 1
tasks/Quiz/script_task.py

@@ -1,6 +1,7 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
+import random
 from cached_property import cached_property
 
 from tasks.GameUi.game_ui import GameUi
@@ -21,6 +22,7 @@ class NoTicket(Exception):
 
 class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
 
+    answer_cnt = 0
     last_select_1 = ''
     last_select_2 = ''
     last_select_3 = ''
@@ -35,6 +37,10 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
     def click_options(self) -> list:
         return [self.O_ANSWER1, self.O_ANSWER2, self.O_ANSWER3, self.O_ANSWER4]
 
+    @cached_property
+    def _config(self):
+        return self.config.model.quiz.quiz_config
+
     def run(self):
         self.ui_get_current_page()
         self.ui_goto(page_main)
@@ -69,6 +75,7 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
     def once(self) -> bool:
         logger.hr('Quiz', 3)
         start_cnt = 0
+        self.answer_cnt = 0
         while 1:
             self.screenshot()
             if self.appear(self.I_MESSAGE):
@@ -84,6 +91,8 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
         while 1:
             self.screenshot()
 
+            if self.ui_reward_appear_click():
+                continue
             if self.appear(self.I_FAIL_QUIT):
                 # 失败
                 logger.info('Quiz Fail and exit')
@@ -112,11 +121,15 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
         answer_4 = self.O_ANSWER4.detect_text(self.device.image)
         if answer_1 == '' and answer_2 == '' and answer_3 == '' and answer_4 == '':
             return False
-        if not self.detect_new(answer_1, answer_2, answer_3, answer_4) and\
+        new_question = self.detect_new(answer_1, answer_2, answer_3, answer_4)
+        if not new_question and\
                 not self.ocr_appear(self.O_COUNTDOWN) and\
                 not self.ocr_appear(self.O_COUNTDOWN3):
             # 第一次换题目的时候 和 最后两秒钟的时候 进行选择
             return False
+        if new_question:
+            self.answer_cnt += 1
+            logger.info(f'Question count: {self.answer_cnt}')
 
         self.last_select_1, self.last_select_2, self.last_select_3, self.last_select_4 = \
             answer_1, answer_2, answer_3, answer_4
@@ -132,8 +145,14 @@ class ScriptTask(GameUi, QuizAssets, ActivityShikigamiAssets, Debugger):
             self.config.notifier.push(title='Quiz',
                                       content=f"New question: \n{question} \n{[answer_1, answer_2, answer_3, answer_4]}")
             index = 1
+
+        if self._config.quiz_per_round < 150 and self.answer_cnt > self._config.quiz_per_round:
+            index_options = {1, 2, 3, 4}
+            index_options.remove(index)
+            index = random.choice(list(index_options))
         logger.info(f'Question: {question}, Answer: {index}')
         self.click(self.click_options[index-1])
+        self.device.click_record_clear()
         return True