Преглед изворни кода

perf(Restart): Optimize the reward mailbox

ryland пре 1 година
родитељ
комит
7eece2fdb0

+ 0 - 1
module/device/method/windows.py

@@ -5,7 +5,6 @@ from module.device.env import IS_WINDOWS
 
 
 if IS_WINDOWS:
 if IS_WINDOWS:
     from module.device.method.windows_impl import Window
     from module.device.method.windows_impl import Window
-    print("dd")
 
 
 else:
 else:
     class Window:
     class Window:

+ 2 - 1
module/server/i18n.py

@@ -24,5 +24,6 @@ class I18n:
         with open(str(I18n.file_zh_cn), 'r', encoding='utf-8') as f:
         with open(str(I18n.file_zh_cn), 'r', encoding='utf-8') as f:
             return json.load(f)
             return json.load(f)
 
 
+
 if __name__ == '__main__':
 if __name__ == '__main__':
-    print(I18n.load_zh_cn())
+    print(I18n.load_zh_cn())

+ 1 - 1
tasks/Dokan/assets.py

@@ -34,7 +34,7 @@ class DokanAssets:
 
 
 
 
 	# List Rule Assets
 	# List Rule Assets
-	# 前往按钮列表
+	# 前往按钮列表 
 	L_GOTO_CHEERING = RuleList(folder="./tasks/Dokan/res", direction="vertical", mode="ocr", roi_back=(950,172,54,324), size=(53, 62), 
 	L_GOTO_CHEERING = RuleList(folder="./tasks/Dokan/res", direction="vertical", mode="ocr", roi_back=(950,172,54,324), size=(53, 62), 
 					 array=["前往"])
 					 array=["前往"])
 
 

+ 4 - 2
tasks/Restart/assets.py

@@ -22,7 +22,7 @@ class RestartAssets:
 	# 邮件小图标 
 	# 邮件小图标 
 	I_HARVEST_MAIL = RuleImage(roi_front=(337,505,37,25), roi_back=(38,465,880,89), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail.png")
 	I_HARVEST_MAIL = RuleImage(roi_front=(337,505,37,25), roi_back=(38,465,880,89), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail.png")
 	# 全部收取 
 	# 全部收取 
-	I_HARVEST_MAIL_ALL = RuleImage(roi_front=(69,589,64,57), roi_back=(28,572,115,123), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_all.png")
+	I_HARVEST_MAIL_ALL = RuleImage(roi_front=(69,579,80,67), roi_back=(28,551,142,144), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_all.png")
 	# 有些邮件需要点击一次 
 	# 有些邮件需要点击一次 
 	I_HARVEST_MAIL_OPEN = RuleImage(roi_front=(163,367,45,48), roi_back=(139,86,100,487), threshold=0.9, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_open.png")
 	I_HARVEST_MAIL_OPEN = RuleImage(roi_front=(163,367,45,48), roi_back=(139,86,100,487), threshold=0.9, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_open.png")
 	# 确认收取邮件 
 	# 确认收取邮件 
@@ -64,7 +64,9 @@ class RestartAssets:
 	# 特殊邮件打开状态 
 	# 特殊邮件打开状态 
 	I_SPECIAL_MAIL_OPEN = RuleImage(roi_front=(1201,380,55,110), roi_back=(1190,348,79,162), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_special_mail_open.png")
 	I_SPECIAL_MAIL_OPEN = RuleImage(roi_front=(1201,380,55,110), roi_back=(1190,348,79,162), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_special_mail_open.png")
 	# 一键已读所有邮件 
 	# 一键已读所有邮件 
-	I_READ_ALL_MAIL = RuleImage(roi_front=(155,603,166,44), roi_back=(149,588,182,72), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_read_all_mail.png")
+	I_READ_ALL_MAIL = RuleImage(roi_front=(180,605,130,35), roi_back=(149,588,182,72), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_read_all_mail.png")
+	# 邮件红点 
+	I_MAIL_RED_POINT = RuleImage(roi_front=(1229,200,16,21), roi_back=(1159,189,100,317), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_mail_red_point.png")
 
 
 
 
 	# Click Rule Assets
 	# Click Rule Assets

BIN
tasks/Restart/harvest/harvest_harvest_mail_all.png


BIN
tasks/Restart/harvest/harvest_mail_red_point.png


BIN
tasks/Restart/harvest/harvest_read_all_mail.png


+ 12 - 3
tasks/Restart/harvest/image.json

@@ -47,8 +47,8 @@
   {
   {
     "itemName": "harvest_mail_all",
     "itemName": "harvest_mail_all",
     "imageName": "harvest_harvest_mail_all.png",
     "imageName": "harvest_harvest_mail_all.png",
-    "roiFront": "69,589,64,57",
-    "roiBack": "28,572,115,123",
+    "roiFront": "69,579,80,67",
+    "roiBack": "28,551,142,144",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "全部收取"
     "description": "全部收取"
@@ -236,10 +236,19 @@
   {
   {
     "itemName": "read_all_mail",
     "itemName": "read_all_mail",
     "imageName": "harvest_read_all_mail.png",
     "imageName": "harvest_read_all_mail.png",
-    "roiFront": "155,603,166,44",
+    "roiFront": "180,605,130,35",
     "roiBack": "149,588,182,72",
     "roiBack": "149,588,182,72",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "一键已读所有邮件"
     "description": "一键已读所有邮件"
+  },
+  {
+    "itemName": "mail_red_point",
+    "imageName": "harvest_mail_red_point.png",
+    "roiFront": "1229,200,16,21",
+    "roiBack": "1159,189,100,317",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "邮件红点"
   }
   }
 ]
 ]

+ 27 - 28
tasks/Restart/login.py

@@ -270,36 +270,35 @@ class LoginHandler(BaseTask, RestartAssets):
         self.character = character
         self.character = character
         self.O_LOGIN_SPECIFIC_SERVE.keyword = character
         self.O_LOGIN_SPECIFIC_SERVE.keyword = character
 
 
-    def harvest_mail(self, ) -> bool:
-        if ((self.appear(self.I_HARVEST_MAIL) or self.appear(self.I_HARVEST_MAIL_COPY))
-                and not self.appear(self.I_LOGIN_RED_CLOSE)):
-            self.click(self.I_HARVEST_MAIL, interval=2)
-            self.wait_until_appear(self.I_READ_ALL_MAIL, wait_time=2)
-        else:
-            return False
-        logger.info('Harvest system mail')
-        self.click(self.I_SYSTEM_MAIL_CLOSE)
-        self.wait_until_appear(self.I_SYSTEM_MAIL_OPEN, wait_time=2)
-        self.exec_harvest_mail()
-        logger.info('Harvest special mail')
-        self.click(self.I_SPECIAL_MAIL_CLOSE)
-        self.wait_until_appear(self.I_SPECIAL_MAIL_OPEN, wait_time=2)
-        self.exec_harvest_mail()
-        return True
-
-    def exec_harvest_mail(self):
+    def harvest_mail(self) -> bool:
+        if not self.appear(self.I_HARVEST_MAIL) and \
+                not self.appear(self.I_HARVEST_MAIL_COPY):
+            if not self.appear(self.I_READ_ALL_MAIL):
+                return False
+        logger.info('Harvest mail')
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_READ_ALL_MAIL):
+                break
+            if self.appear_then_click(self.I_HARVEST_MAIL, interval=1.5):
+                continue
+            if self.appear_then_click(self.I_HARVEST_MAIL_COPY, interval=1.5):
+                continue
         timeout_timer = Timer(3).start()
         timeout_timer = Timer(3).start()
-        while not timeout_timer.reached():
+        logger.info('Exec harvest mail')
+        while 1:
             self.screenshot()
             self.screenshot()
+            if timeout_timer.reached():
+                break
+            if self.appear_then_click(self.I_HARVEST_MAIL_CONFIRM, interval=0.8):
+                break
+
             if self.appear_then_click(self.I_READ_ALL_MAIL, interval=1.5):
             if self.appear_then_click(self.I_READ_ALL_MAIL, interval=1.5):
                 continue
                 continue
-            if self.appear(self.I_HARVEST_MAIL_CONFIRM):
-                self.click(self.I_HARVEST_MAIL_CONFIRM, interval=2)
-                self.wait_until_disappear(self.I_HARVEST_MAIL_CONFIRM)
-                break
-            if self.appear(self.I_HARVEST_MAIL_ALL, threshold=0.9):
-                time.sleep(random.uniform(0.3, 0.5))
-                self.click(self.I_HARVEST_MAIL_ALL, interval=2)
-                self.wait_until_appear(self.I_HARVEST_MAIL_CONFIRM, wait_time=1)
-                timeout_timer.reset()
+            if self.appear_then_click(self.I_HARVEST_MAIL_ALL, interval=1.5):
                 continue
                 continue
+            if self.appear_then_click(self.I_MAIL_RED_POINT, interval=4):
+                continue
+        self.ui_click_until_disappear(self.I_LOGIN_RED_CLOSE)
+        return True
+

+ 5 - 1
tasks/TrueOrochi/script_task.py

@@ -5,7 +5,7 @@ from time import sleep
 from datetime import datetime, time
 from datetime import datetime, time
 
 
 from module.logger import logger
 from module.logger import logger
-from module.exception import TaskEnd
+from module.exception import TaskEnd, GameStuckError
 from module.base.timer import Timer
 from module.base.timer import Timer
 
 
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.game_ui import GameUi
@@ -135,6 +135,7 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
         logger.info("Start battle process")
         logger.info("Start battle process")
         check_timer = Timer(280)
         check_timer = Timer(280)
         check_timer.start()
         check_timer.start()
+        check_count = 0
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
             if self.appear(self.I_GREED_GHOST):
             if self.appear(self.I_GREED_GHOST):
@@ -155,6 +156,9 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
             if self.appear_then_click(self.I_ST_FRAME, interval=1):
             if self.appear_then_click(self.I_ST_FRAME, interval=1):
                 continue
                 continue
             if check_timer.reached():
             if check_timer.reached():
+                if check_count > 3:
+                    raise GameStuckError
+                check_count += 1
                 logger.warning('Battle timeout')
                 logger.warning('Battle timeout')
                 check_timer.reset()
                 check_timer.reset()
                 self.device.stuck_record_clear()
                 self.device.stuck_record_clear()