Просмотр исходного кода

pref(TrueOrochi): Optimize the counting

Neptine 1 год назад
Родитель
Сommit
92f19363ef

+ 0 - 8
module/config/config.py

@@ -290,11 +290,6 @@ class Config(ConfigState, ConfigManual, ConfigWatcher, ConfigMenu):
         :param finish: 是完成任务后的时间为基准还是开始任务的时间为基准
         :return:
         """
-        # 获取真蛇成功次数
-        global current_success, true_orochi_config
-        if task == 'TrueOrochi':
-            current_success = self.model.true_orochi.true_orochi_config.current_success
-
         # 加载配置文件
         self.reload()
         # 任务预处理
@@ -371,9 +366,6 @@ class Config(ConfigState, ConfigManual, ConfigWatcher, ConfigMenu):
         self.lock_config.acquire()
         try:
             scheduler.next_run = next_run
-            if task == 'true_orochi':
-                true_orochi_config = getattr(task_object, 'true_orochi_config', None)
-                true_orochi_config.current_success = current_success
             self.save()
         finally:
             self.lock_config.release()

+ 5 - 0
tasks/TrueOrochi/assets.py

@@ -60,3 +60,8 @@ class TrueOrochiAssets:
 	I_ST_FRAME = RuleImage(roi_front=(571,442,135,65), roi_back=(571,442,135,65), threshold=0.8, method="Template matching", file="./tasks/TrueOrochi/st/st_st_frame.png")
 
 
+	# Ocr Rule Assets
+	# 本周剩余奖励次数 
+	O_TIMES = RuleOcr(roi=(461,388,40,26), area=(461,388,40,26), mode="DigitCounter", method="Default", keyword="", name="times")
+
+

+ 1 - 1
tasks/TrueOrochi/config.py

@@ -23,7 +23,7 @@ class GreenMarkType(str, Enum):
 
 class TrueOrochiScheduler(Scheduler):
     priority: int = Field(default=10, description='priority_help')
-    success_interval: TimeDelta = Field(default=TimeDelta(days=7), description='success_interval_help')
+    success_interval: TimeDelta = Field(default=TimeDelta(days=3), description='success_interval_help')
     failure_interval: TimeDelta = Field(default=TimeDelta(days=1), description='failure_interval_help')
 
 class TrueOrochiConfig(BaseModel):

+ 26 - 21
tasks/TrueOrochi/script_task.py

@@ -24,12 +24,6 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
     
         conf = self.config.true_orochi.true_orochi_config
 
-        # 周一重置真蛇次数
-        now = datetime.now()
-        day_of_week = now.weekday()
-        if day_of_week == 0:
-            conf.current_success = 0
-
         if conf.current_success >= 2:
             # 超过两次就说明这周打完了没有必要再打了
             logger.warning('This week is full')
@@ -101,6 +95,13 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
             if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
                 continue
             if self.appear_then_click(self.I_ST_FIRE, interval=4):
+                # 修正已经挑战的次数, 注意这个是战斗开始之前的次数
+                current, current_success, total = self.O_TIMES.ocr(self.device.image)
+                if current_success < 0 or current_success > 2:
+                    continue
+                logger.info(f'current: {current}, current_success: {current_success}, total: {total}')
+                conf.current_success = current_success
+                self.config.save()
                 continue
             if self.appear_then_click(self.I_FIND_TS, interval=1):
                 continue
@@ -179,21 +180,25 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
         :param current_success: 这周的成功次数
         :return:
         """
-        # now = datetime.now()
-        # now_year, now_week_number, now_weekday = now.isocalendar()
-        # if battle:
-        #     next_run = now + self.config.true_orochi.scheduler.success_interval
-        # else:
-        #     next_run = now + self.config.true_orochi.scheduler.failure_interval
-        # next_run_year, next_run_week_number, next_run_weekday = next_run.isocalendar()
-        # # 如果下次运行的时间是下一周,那么就重置成功次数
-        # if now_week_number != next_run_week_number:
-        #     self.config.true_orochi.true_orochi_config.current_success = 0
-        # else:
-        #     # 如果不是下一周,那么就加一
-        #     self.config.true_orochi.true_orochi_config.current_success += 1
-        # self.set_next_run(task='TrueOrochi', target=next_run)
-        self.set_next_run('TrueOrochi', finish=True, success=True)
+        now = datetime.now()
+        now_year, now_week_number, now_weekday = now.isocalendar()
+        if battle:
+            next_run = now + self.config.true_orochi.scheduler.success_interval
+        else:
+            next_run = now + self.config.true_orochi.scheduler.failure_interval
+        next_run_year, next_run_week_number, next_run_weekday = next_run.isocalendar()
+        # 如果下次运行的时间是下一周,那么就重置成功次数
+        if now_week_number != next_run_week_number:
+            logger.info('Reset current_success')
+            self.config.true_orochi.true_orochi_config.current_success = 0
+        else:
+            # 如果不是下一周,那么就加一
+            logger.info('Add current_success by 1')
+            self.config.true_orochi.true_orochi_config.current_success += 1
+            self.config.true_orochi.true_orochi_config.current_success = min(2, self.config.true_orochi.true_orochi_config.current_success)
+        self.config.save()
+        self.set_next_run(task='TrueOrochi', target=next_run)
+        # self.set_next_run('TrueOrochi', finish=True, success=True)
 
     def run_true_orochi(self) -> bool:
         pass

+ 11 - 0
tasks/TrueOrochi/st/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "times",
+    "roiFront": "461,388,40,26",
+    "roiBack": "461,388,40,26",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "本周剩余奖励次数"
+  }
+]