|
|
@@ -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
|
|
|
|
|
|
|