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

Merge remote-tracking branch 'origin/dev' into dev

ryland 1 год назад
Родитель
Сommit
ab8d87cf56

+ 29 - 0
module/config/config_model.py

@@ -409,6 +409,35 @@ class ConfigModel(ConfigBase):
             logger.error(e)
             return False
 
+    def copy_script_task(self, task_name: str, source_task: BaseModel) -> bool:
+        model_task_name = convert_to_underscore(task_name)
+        try:
+            setattr(self, model_task_name, source_task)
+            self.save()
+            logger.info(f'Copy task {model_task_name} success')
+            return True
+        except ValidationError as e:
+            logger.error(e)
+            return False
+
+    def copy_task_group(self, task_name: str, group_name: str, source_task: BaseModel) -> bool:
+        model_task_name = convert_to_underscore(task_name)
+        model_group_name = convert_to_underscore(group_name)
+        task_object = getattr(self, model_task_name, None)
+        if not task_object:
+            return False
+        source_group_obj = getattr(source_task, model_group_name, None)
+        if not source_group_obj:
+            return False
+        try:
+            setattr(task_object, model_group_name, source_group_obj)
+            self.save()
+            logger.info(f'Copy task group {model_task_name}.{model_group_name} success')
+            return True
+        except ValidationError as e:
+            logger.error(e)
+            return False
+
     def replace_next_run(self, d, dt: datetime):
         for k, v in d.items():
             if isinstance(v, dict):

+ 21 - 0
module/server/script_router.py

@@ -7,6 +7,7 @@ from fastapi.responses import StreamingResponse
 from fastapi import WebSocket, WebSocketDisconnect
 from datetime import datetime
 from module.config.config import Config
+from module.config.utils import convert_to_underscore
 
 from module.logger import logger
 from module.server.main_manager import MainManager
@@ -81,6 +82,26 @@ async def config_delete(name: str = ''):
     return True
 
 
+@script_app.put('/config/task/copy')
+async def task_copy(task_name: str, dest_config_name: str, source_config_name: str):
+    if dest_config_name not in mm.script_process or source_config_name not in mm.script_process:
+        return False
+    source_task = getattr(mm.config_cache(source_config_name).model, convert_to_underscore(task_name), None)
+    if source_task is None:
+        return False
+    return mm.config_cache(dest_config_name).model.copy_script_task(task_name, source_task)
+
+
+@script_app.put('/config/task/group/copy')
+async def task_group_copy(task_name: str, group_name: str, dest_config_name: str, source_config_name: str):
+    if dest_config_name not in mm.script_process or source_config_name not in mm.script_process:
+        return False
+    source_task = getattr(mm.config_cache(source_config_name).model, convert_to_underscore(task_name), None)
+    if source_task is None:
+        return False
+    return mm.config_cache(dest_config_name).model.copy_task_group(task_name, group_name, source_task)
+
+
 # ---------------------------------   脚本实例管理   ----------------------------------
 @script_app.get('/{script_name}/start')
 async def script_start(script_name: str):

+ 2 - 6
module/server/updater.py

@@ -5,7 +5,6 @@ import time
 import requests
 from typing import Generator, List, Tuple
 
-
 from deploy.config import ExecutionError
 from deploy.git import GitManager
 from deploy.pip import PipManager
@@ -64,11 +63,8 @@ class Updater(DeployConfig, GitManager, PipManager):
             return logs
 
     def current_branch(self) -> str:
-        log : str = subprocess.run(
-            'git branch --show-current', capture_output=True, text=True, encoding="utf8", shell=True
-        ).stdout
-        log = log.replace('\n', '')
-        return log
+        branch = self.execute_output(f'{self.git} branch --show-current')
+        return branch.strip()
 
     def current_commit(self) -> str:
         return self.get_commit()

+ 1 - 1
tasks/DailyTrifles/assets.py

@@ -35,7 +35,7 @@ class DailyTriflesAssets:
 	# description 
 	I_GIFT_RECOMMEND = RuleImage(roi_front=(1183,454,53,64), roi_back=(1162,77,98,457), threshold=0.7, method="Template matching", file="./tasks/DailyTrifles/store/store_gift_recommend.png")
 	# 免费一抽领黑蛋 
-	I_GIFT_SIGN = RuleImage(roi_front=(629,192,129,149), roi_back=(130,129,891,473), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/store/store_gift_sign.png")
+	I_GIFT_SIGN = RuleImage(roi_front=(186,191,115,83), roi_back=(130,129,891,473), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/store/store_gift_sign.png")
 	# 体力 
 	I_SPECIAL_SUSHI = RuleImage(roi_front=(180,130,800,460), roi_back=(180,130,800,460), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/store/store_sushi.png")
 	# 购买时货币类型为勾玉 

+ 1 - 1
tasks/DailyTrifles/store/image.json

@@ -20,7 +20,7 @@
   {
     "itemName": "gift_sign",
     "imageName": "store_gift_sign.png",
-    "roiFront": "629,192,129,149",
+    "roiFront": "186,191,115,83",
     "roiBack": "130,129,891,473",
     "method": "Template matching",
     "threshold": 0.8,

BIN
tasks/DailyTrifles/store/store_gift_sign.png


+ 3 - 1
tasks/GameUi/page.py

@@ -4,6 +4,7 @@ import traceback
 from module.atom.click import RuleClick
 
 from tasks.GameUi.assets import GameUiAssets as G
+from tasks.Restart.assets import RestartAssets
 from tasks.base_task import BaseTask as BT
 from tasks.RyouToppa.assets import RyouToppaAssets
 
@@ -35,7 +36,8 @@ class Page:
 page_login = Page(G.I_CHECK_LOGIN_FORM)
 # Main Home 主页
 page_main = Page(G.I_CHECK_MAIN)
-page_main.additional = [G.I_AD_CLOSE_RED, G.I_BACK_FRIENDS]
+page_main.additional = [G.I_AD_CLOSE_RED, G.I_BACK_FRIENDS, RestartAssets.I_CANCEL_BATTLE,
+                        RestartAssets.I_LOGIN_SCROOLL_CLOSE]
 # 召唤summon
 page_summon = Page(G.I_CHECK_SUMMON)
 page_summon.link(button=G.I_SUMMON_GOTO_MAIN, destination=page_main)

+ 1 - 0
tasks/KekkaiUtilize/config.py

@@ -31,6 +31,7 @@ class UtilizeConfig(BaseModel):
     select_friend_list: SelectFriendList = Field(default=SelectFriendList.SAME_SERVER, description='select_friend_list_help')
     shikigami_class: ShikigamiClass = Field(default=ShikigamiClass.N, description='shikigami_class_help')
     shikigami_order: int = Field(default=4, description='shikigami_order_help')
+    harvest_guild_max_times: int = Field(default=3, description='收取寮资金或体力失败的最大尝试次数')
     utilize_enable: bool = Field(default=True, description='是否蹭卡,小号可以选择不蹭卡')
     guild_ap_enable: bool = Field(default=True, description='guild_ap_enable_help')
     guild_assets_enable: bool = Field(default=True, description='guild_assets_enable_help')

+ 3 - 3
tasks/KekkaiUtilize/script_task.py

@@ -50,13 +50,13 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
         self.check_box_ap_or_exp(con.box_ap_enable, con.box_exp_enable, con.box_exp_waste)
 
         # 收取寮资金和体力
-        self.recive_guild_ap_or_assets()
+        self.recive_guild_ap_or_assets(con.harvest_guild_max_times)
         if not con.utilize_enable:
             self.set_next_run(task='KekkaiUtilize', finish=True, success=True)
         raise TaskEnd
 
-    def recive_guild_ap_or_assets(self):
-        for i in range(1, 5):
+    def recive_guild_ap_or_assets(self, max_tries: int = 3):
+        for i in range(1, max_tries+1):
             self.ui_get_current_page()
             self.ui_goto(page_guild)
             # 在寮的主界面 检查是否有收取体力或者是收取寮资金

+ 13 - 1
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_ALL = RuleImage(roi_front=(80,622,75,64), roi_back=(80,622,75,64), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_all.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_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")
 	# 确认收取邮件 
@@ -55,6 +55,16 @@ class RestartAssets:
 	I_HARVEST_MAIL_COPY = RuleImage(roi_front=(257,509,29,21), roi_back=(192,472,790,100), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_copy.png")
 	# description 
 	I_HARVEST_MAIL_2 = RuleImage(roi_front=(156,125,65,60), roi_back=(120,94,290,536), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_harvest_mail_2.png")
+	# 系统邮件打开状态 
+	I_SYSTEM_MAIL_OPEN = RuleImage(roi_front=(1201,223,51,112), roi_back=(1197,219,59,118), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_system_mail_open.png")
+	# 特殊邮件关闭状态 
+	I_SPECIAL_MAIL_CLOSE = RuleImage(roi_front=(1200,379,53,108), roi_back=(1185,342,80,178), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_special_mail_close.png")
+	# 系统邮件关闭状态 
+	I_SYSTEM_MAIL_CLOSE = RuleImage(roi_front=(1200,222,53,112), roi_back=(1186,193,81,156), threshold=0.8, method="Template matching", file="./tasks/Restart/harvest/harvest_system_mail_close.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")
 
 
 	# Click Rule Assets
@@ -95,6 +105,8 @@ class RestartAssets:
 	I_EARLY_SERVER = RuleImage(roi_front=(596,269,115,33), roi_back=(596,269,115,33), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_early_server.png")
 	# 取消体验服切换弹窗 
 	I_EARLY_SERVER_CANCEL = RuleImage(roi_front=(435,404,172,56), roi_back=(435,404,172,56), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_early_server_cancel.png")
+	# 取消继续战斗 
+	I_CANCEL_BATTLE = RuleImage(roi_front=(471,395,129,55), roi_back=(367,227,545,296), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_cancel_battle.png")
 
 
 	# Ocr Rule Assets

BIN
tasks/Restart/harvest/harvest_harvest_mail_all.png


BIN
tasks/Restart/harvest/harvest_read_all_mail.png


BIN
tasks/Restart/harvest/harvest_special_mail_close.png


BIN
tasks/Restart/harvest/harvest_special_mail_open.png


BIN
tasks/Restart/harvest/harvest_system_mail_close.png


BIN
tasks/Restart/harvest/harvest_system_mail_open.png


+ 47 - 2
tasks/Restart/harvest/image.json

@@ -47,8 +47,8 @@
   {
     "itemName": "harvest_mail_all",
     "imageName": "harvest_harvest_mail_all.png",
-    "roiFront": "80,622,75,64",
-    "roiBack": "80,622,75,64",
+    "roiFront": "69,589,64,57",
+    "roiBack": "28,572,115,123",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "全部收取"
@@ -196,5 +196,50 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
+  },
+  {
+    "itemName": "system_mail_open",
+    "imageName": "harvest_system_mail_open.png",
+    "roiFront": "1201,223,51,112",
+    "roiBack": "1197,219,59,118",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "系统邮件打开状态"
+  },
+  {
+    "itemName": "special_mail_close",
+    "imageName": "harvest_special_mail_close.png",
+    "roiFront": "1200,379,53,108",
+    "roiBack": "1185,342,80,178",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "特殊邮件关闭状态"
+  },
+  {
+    "itemName": "system_mail_close",
+    "imageName": "harvest_system_mail_close.png",
+    "roiFront": "1200,222,53,112",
+    "roiBack": "1186,193,81,156",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "系统邮件关闭状态"
+  },
+  {
+    "itemName": "special_mail_open",
+    "imageName": "harvest_special_mail_open.png",
+    "roiFront": "1201,380,55,110",
+    "roiBack": "1190,348,79,162",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "特殊邮件打开状态"
+  },
+  {
+    "itemName": "read_all_mail",
+    "imageName": "harvest_read_all_mail.png",
+    "roiFront": "155,603,166,44",
+    "roiBack": "149,588,182,72",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "一键已读所有邮件"
   }
 ]

+ 43 - 28
tasks/Restart/login.py

@@ -1,7 +1,7 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
-
+import random
 from module.base.timer import Timer
 from module.exception import RequestHumanTakeover, GameTooManyClickError, GameStuckError
 from module.logger import logger
@@ -38,7 +38,10 @@ class LoginHandler(BaseTask, RestartAssets):
                 orientation_timer.reset()
 
             self.screenshot()
-
+            # 取消继续战斗
+            if self.appear_then_click(self.I_CANCEL_BATTLE, interval=0.8):
+                logger.info('Cancel continue battle')
+                continue
             # 确认进入庭院
             if self.appear_then_click(self.I_LOGIN_SCROOLL_CLOSE, interval=2, threshold=0.9):
                 logger.info('Open scroll')
@@ -227,32 +230,9 @@ class LoginHandler(BaseTask, RestartAssets):
                 timer_harvest.reset()
                 continue
             # 判断是否勾选了收取邮件(不收取邮件可以查看每日收获)
-            if not skip_default and self.config.restart.harvest_config.enable_mail:
-                if self.appear(self.I_HARVEST_MAIL_CONFIRM):
-                    self.click(self.I_HARVEST_MAIL_CONFIRM, interval=2)
-                    timer_harvest.reset()
-                    continue
-                if self.appear(self.I_HARVEST_MAIL_ALL, threshold=0.9):
-                    self.click(self.I_HARVEST_MAIL_ALL, interval=2)
-                    self.wait_until_appear(self.I_HARVEST_MAIL_CONFIRM, wait_time=1)
-                    timer_harvest.reset()
-                    continue
-                # threshold如果是0.9,可能会导致有邮件但无法识别永久卡住
-                if self.appear(self.I_HARVEST_MAIL_OPEN, threshold=0.8):
-                    self.click(self.I_HARVEST_MAIL_OPEN, interval=0.8)
-                    timer_harvest.reset()
-                    continue
-                if self.appear(self.I_HARVEST_MAIL_2):
-                    self.click(self.I_HARVEST_MAIL_2, interval=0.8)
-                    timer_harvest.reset()
-                    continue
-                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_HARVEST_MAIL_ALL, wait_time=2)
-                    timer_harvest.reset()
-                    continue
-
+            if not skip_default and self.config.restart.harvest_config.enable_mail and self.harvest_mail():
+                timer_harvest.reset()
+                continue
             if self.appear_then_click(self.I_HARVEST_AP, interval=1, threshold=0.7):
                 timer_harvest.reset()
                 continue
@@ -289,3 +269,38 @@ class LoginHandler(BaseTask, RestartAssets):
     def set_specific_usr(self, character: str):
         self.character = character
         self.O_LOGIN_SPECIFIC_SERVE.keyword = character
+
+    def harvest_mail(self, skip_first_screenshot: bool = True) -> bool:
+        self.screenshot(skip_first_screenshot)
+        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):
+        timeout_timer = Timer(3).start()
+        while not timeout_timer.reached():
+            self.screenshot()
+            if self.appear_then_click(self.I_READ_ALL_MAIL, interval=1.5):
+                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()
+                continue

+ 9 - 0
tasks/Restart/login/image.json

@@ -142,5 +142,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "取消体验服切换弹窗"
+  },
+  {
+    "itemName": "cancel_battle",
+    "imageName": "login_cancel_battle.png",
+    "roiFront": "471,395,129,55",
+    "roiBack": "367,227,545,296",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "取消继续战斗"
   }
 ]

BIN
tasks/Restart/login/login_cancel_battle.png