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

Merge branch 'dev' into dev_fix

# Conflicts:
#	tasks/GameUi/page.py
Azure 1 год назад
Родитель
Сommit
2260d9129f
33 измененных файлов с 524 добавлено и 51 удалено
  1. 3 0
      deploy/docker/.dockerignore
  2. 37 0
      deploy/docker/Dockerfile
  3. 32 0
      deploy/docker/Dockerfile.cn
  4. 172 0
      deploy/docker/requirements.txt
  5. 62 0
      deploy/docker/requirements_generator.py
  6. 13 0
      docker-compose.yaml
  7. 29 0
      module/config/config_model.py
  8. 1 1
      module/device/control.py
  9. 0 1
      module/device/device.py
  10. 19 0
      module/device/method/windows.py
  11. 4 0
      module/device/method/windows_impl.py
  12. 2 1
      module/device/screenshot.py
  13. 21 0
      module/server/script_router.py
  14. 2 6
      module/server/updater.py
  15. 5 3
      script.py
  16. 2 2
      tasks/AbyssShadows/config.py
  17. 1 1
      tasks/DailyTrifles/assets.py
  18. 1 1
      tasks/DailyTrifles/store/image.json
  19. BIN
      tasks/DailyTrifles/store/store_gift_sign.png
  20. 2 1
      tasks/GameUi/page.py
  21. 1 0
      tasks/KekkaiUtilize/config.py
  22. 3 3
      tasks/KekkaiUtilize/script_task.py
  23. 13 1
      tasks/Restart/assets.py
  24. BIN
      tasks/Restart/harvest/harvest_harvest_mail_all.png
  25. BIN
      tasks/Restart/harvest/harvest_read_all_mail.png
  26. BIN
      tasks/Restart/harvest/harvest_special_mail_close.png
  27. BIN
      tasks/Restart/harvest/harvest_special_mail_open.png
  28. BIN
      tasks/Restart/harvest/harvest_system_mail_close.png
  29. BIN
      tasks/Restart/harvest/harvest_system_mail_open.png
  30. 47 2
      tasks/Restart/harvest/image.json
  31. 43 28
      tasks/Restart/login.py
  32. 9 0
      tasks/Restart/login/image.json
  33. BIN
      tasks/Restart/login/login_cancel_battle.png

+ 3 - 0
deploy/docker/.dockerignore

@@ -0,0 +1,3 @@
+
+requirements_generator.py
+

+ 37 - 0
deploy/docker/Dockerfile

@@ -0,0 +1,37 @@
+# docker build -t qwerty/oas:latest .
+# docker run -v ${PWD}:/app/OnmyojiAutoScript -p 22288:22288 --name oas -it --rm qwerty/oas
+
+
+FROM python:3.10-slim-bookworm
+
+WORKDIR /app/OnmyojiAutoScript
+
+COPY requirements.txt /tmp/requirements.txt
+
+# python:3.10-slim is based on debian:12, apt source from https://developer.aliyun.com/mirror/debian
+RUN echo "\
+deb https://mirrors.cloud.tencent.com/debian/ bookworm main non-free non-free-firmware contrib \n\
+deb-src https://mirrors.cloud.tencent.com/debian/ bookworm main non-free non-free-firmware contrib \n\
+deb https://mirrors.cloud.tencent.com/debian-security/ bookworm-security main \n\
+deb-src https://mirrors.cloud.tencent.com/debian-security/ bookworm-security main \n\
+deb https://mirrors.cloud.tencent.com/debian/ bookworm-updates main non-free non-free-firmware contrib \n\
+deb-src https://mirrors.cloud.tencent.com/debian/ bookworm-updates main non-free non-free-firmware contrib \n\
+deb https://mirrors.cloud.tencent.com/debian/ bookworm-backports main non-free non-free-firmware contrib \n\
+deb-src https://mirrors.cloud.tencent.com/debian/ bookworm-backports main non-free non-free-firmware contrib \
+    "\
+> /etc/apt/sources.list\
+ && apt update \
+ && apt install -y git adb libgomp1 openssh-client \
+ && git config --global --add safe.directory '*' \
+ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
+ && echo 'Asia/Shanghai' > /etc/timezone \
+ && pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
+ && pip install -r /tmp/requirements.txt \
+ && pip uninstall -y opencv-python\
+ && pip uninstall -y opencv-python-headless\
+ && pip install opencv-python-headless==4.7.0.72\
+ && rm /tmp/requirements.txt \
+ && rm -r ~/.cache/pip
+
+CMD python server.py
+#CMD /bin/bash

+ 32 - 0
deploy/docker/Dockerfile.cn

@@ -0,0 +1,32 @@
+# docker build -t qwerty/oas:latest .
+# docker run -v ${PWD}:/app/OnmyojiAutoScript -p 22288:22288 --name oas -it --rm qwerty/oas
+
+
+FROM python:3.10-slim-bullseye
+
+WORKDIR /app/OnmyojiAutoScript
+
+COPY requirements.txt /tmp/requirements.txt
+
+# python:3.10-slim is based on debian:11, apt source from https://developer.aliyun.com/mirror/debian
+RUN echo "\
+deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib\n\
+deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib\n\
+deb https://mirrors.aliyun.com/debian-security/ bullseye-security main\n\
+deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main\n\
+deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib\n\
+deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib\n\
+# deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib\n\
+# deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib" \
+> /etc/apt/sources.list \
+ && apt update \
+ && apt install -y git adb libgomp1 openssh-client \
+ && git config --global --add safe.directory '*' \
+ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
+ && echo 'Asia/Shanghai' > /etc/timezone \
+ && pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
+ && pip install -r /tmp/requirements.txt \
+ && rm /tmp/requirements.txt \
+ && rm -r ~/.cache/pip
+
+ CMD python --version

+ 172 - 0
deploy/docker/requirements.txt

@@ -0,0 +1,172 @@
+#
+
+# This file is autogenerated by pip-compile with Python 3.10
+
+# by the following command:
+
+#    pip-compile --annotation-style=line --output-file=requirements.txt requirements-in.txt
+adbutils==0.11.0          
+# via -r requirements-in.txt, uiautomator2
+annotated-types==0.7.0    
+# via pydantic
+anyio==3.7.1              
+# via fastapi, starlette
+anytree==2.8.0            
+# via -r requirements-in.txt
+apkutils2==1.0.0          
+# via adbutils
+cached-property==1.5.2    
+# via uiautomator2
+certifi==2023.11.17       
+# via requests
+cffi==1.16.0              
+# via cryptography, gevent
+charset-normalizer==3.3.2  
+# via requests
+cigam==0.0.3              
+# via apkutils2
+click==8.1.7              
+# via uvicorn
+cn2an==0.5.23             
+# via -r requirements-in.txt
+colorama==0.4.6           
+# via click, logzero, tqdm
+coloredlogs==15.0.1       
+# via onnxruntime
+cryptography==42.0.8      
+# via -r requirements-in.txt
+decorator==5.1.1          
+# via retry
+deprecated==1.2.14        
+# via uiautomator2
+deprecation==2.1.0        
+# via adbutils
+exceptiongroup==1.2.0     
+# via anyio
+fastapi==0.104.1          
+# via -r requirements-in.txt
+filelock==3.13.1          
+# via uiautomator2
+flatbuffers==23.5.26      
+# via onnxruntime
+future==0.18.3            
+# via zerorpc
+gevent==23.9.1            
+# via zerorpc
+greenlet==3.0.3           
+# via gevent
+h11==0.14.0               
+# via uvicorn
+humanfriendly==10.0       
+# via coloredlogs
+idna==3.6                 
+# via anyio, requests
+inflection==0.5.1         
+# via -r requirements-in.txt
+logzero==1.7.0            
+# via uiautomator2
+lxml==5.0.0               
+# via uiautomator2
+markdown-it-py==2.2.0     
+# via rich
+mdurl==0.1.2              
+# via markdown-it-py
+mpmath==1.3.0             
+# via sympy
+msgpack==1.0.7            
+# via zerorpc
+numpy==1.24.3             
+# via -r requirements-in.txt, onnxruntime, opencv-python, ppocr-onnx, shapely
+oashya==0.0.7             
+# via -r requirements-in.txt
+onepush==1.3.0            
+# via -r requirements-in.txt
+onnxruntime==1.16.3       
+# via ppocr-onnx
+opencv-python-headless==4.7.0.72
+packaging==20.9           
+# via deprecation, onnxruntime, uiautomator2
+paho-mqtt==1.6.1          
+# via -r requirements-in.txt
+pillow==10.2.0            
+# via ppocr-onnx, uiautomator2
+ppocr-onnx==0.0.3.9       
+# via -r requirements-in.txt
+proces==0.1.7             
+# via cn2an
+progress==1.6             
+# via uiautomator2
+protobuf==4.25.1          
+# via onnxruntime
+psutil==6.1.1             
+# via -r requirements-in.txt
+py==1.11.0                
+# via retry
+pyclipper==1.3.0.post5    
+# via ppocr-onnx
+pycparser==2.21           
+# via cffi
+pycryptodome==3.21.0      
+# via onepush
+pydantic==2.10.0          
+# via -r requirements-in.txt, fastapi
+pydantic-core==2.27.0     
+# via pydantic
+pyelftools==0.30          
+# via apkutils2
+pygments==2.17.2          
+# via rich
+pyparsing==3.1.1          
+# via packaging
+pyreadline3==3.4.1        
+# via humanfriendly
+pyyaml==6.0               
+# via -r requirements-in.txt
+pyzmq==25.1.2             
+# via zerorpc
+requests==2.31.0          
+# via adbutils, onepush, ppocr-onnx, uiautomator2
+retry==0.9.2              
+# via adbutils, uiautomator2
+rich==13.3.5              
+# via -r requirements-in.txt
+shapely==2.0.2            
+# via ppocr-onnx
+six==1.16.0               
+# via adbutils, anytree, uiautomator2
+sniffio==1.3.0            
+# via anyio
+starlette==0.27.0         
+# via fastapi
+sympy==1.12               
+# via onnxruntime
+tqdm==4.65.0              
+# via -r requirements-in.txt
+typing-extensions==4.12.2  
+# via fastapi, pydantic, pydantic-core, uvicorn
+uiautomator2==2.16.17     
+# via -r requirements-in.txt
+uiautomator2cache==0.3.0.1  
+# via -r requirements-in.txt
+urllib3==2.1.0            
+# via requests
+uvicorn==0.23.2           
+# via -r requirements-in.txt
+websockets==11.0.3        
+# via -r requirements-in.txt
+whichcraft==0.6.1         
+# via adbutils, uiautomator2
+wrapt==1.15.0             
+# via -r requirements-in.txt, deprecated
+xmltodict==0.13.0         
+# via apkutils2
+zerorpc==0.6.3            
+# via -r requirements-in.txt
+zope-event==5.0           
+# via gevent
+zope-interface==6.1       
+# via gevent
+
+# The following packages are considered to be unsafe in a requirements file:
+
+# setuptools

+ 62 - 0
deploy/docker/requirements_generator.py

@@ -0,0 +1,62 @@
+import os
+
+from deploy.logger import logger
+
+BASE_FOLDER = os.path.dirname(os.path.abspath(__file__))
+logger.info(BASE_FOLDER)
+
+
+def read_file(file):
+    out = {}
+    with open(file, 'r', encoding='utf-8') as f:
+        for line in f.readlines():
+            if not line.strip():
+                continue
+            res = [s.strip() for s in line.split('==')]
+            if len(res) > 1:
+                name, version = res
+            else:
+                name, version = res[0], None
+            out[name] = version
+
+    return out
+
+
+def write_file(file, data):
+    lines = []
+    for name, version in data.items():
+        if version:
+            lines.append(f'{name}=={version}')
+        else:
+            lines.append(str(name))
+
+    with open(file, 'w', encoding='utf-8', newline='') as f:
+        text = '\n'.join(lines)
+        text = text.replace('#', '\n#').strip()
+        f.write(text)
+
+
+def docker_requirements_generate(requirements_in='requirements.txt'):
+    requirements = read_file(requirements_in)
+
+    logger.info(f'Generate requirements for Docker image')
+    lock = {}
+    new = {}
+    logger.info(requirements)
+    for name, version in requirements.items():
+        # alas-webapp is for windows only
+        if name == 'alas-webapp' or name == 'pywin32':
+            continue
+        if name == 'opencv-python':
+            name = 'opencv-python-headless'
+            version = '4.7.0.72'
+        if name in lock:
+            version = lock[name] if not isinstance(lock[name], dict) else lock[name]['version']
+            name = name if not isinstance(lock[name], dict) else lock[name]['name']
+        new[name] = version
+
+    write_file(os.path.join(BASE_FOLDER, f'./requirements.txt'), data=new)
+
+
+if __name__ == '__main__':
+    docker_requirements_generate()

+ 13 - 0
docker-compose.yaml

@@ -0,0 +1,13 @@
+
+services:
+    OAS:
+        network_mode: host
+        volumes:
+            - '.:/app/OnmyojiAutoScript:rw'
+            - '/etc/localtime:/etc/localtime:ro'
+        container_name: 'oas-env'
+        image: 'oas-env'
+        build:
+            context: ./deploy/docker/
+            dockerfile: ./Dockerfile
+            # dockerfile: ./Dockerfile

+ 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):

+ 1 - 1
module/device/control.py

@@ -7,7 +7,7 @@ from module.base.utils import *
 from module.device.method.minitouch import Minitouch
 from module.device.method.adb import Adb
 from module.device.method.scrcpy import Scrcpy
-from module.device.method.window import Window
+from module.device.method.windows import Window
 from module.logger import logger
 
 

+ 0 - 1
module/device/device.py

@@ -22,7 +22,6 @@ from module.exception import (GameNotRunningError,
 from module.logger import logger
 
 
-
 class Device(Platform, Screenshot, Control, AppControl):
     _screen_size_checked = False
     detect_record = set()

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

@@ -0,0 +1,19 @@
+
+
+from module.device.env import IS_WINDOWS
+
+
+if IS_WINDOWS:
+    from module.device.method.windows_impl import Window
+    print("dd")
+
+else:
+    class Window:
+        pass
+
+
+
+
+
+
+

+ 4 - 0
module/device/method/window.py → module/device/method/windows_impl.py

@@ -21,6 +21,7 @@ from win32ui import CreateDCFromHandle, CreateBitmap
 from win32api import GetSystemMetrics, SendMessage, MAKELONG, PostMessage
 from win32con import SRCCOPY
 
+
 from module.base.cBezier import BezierTrajectory
 from module.exception import RequestHumanTakeover, ScriptError
 from module.base.decorator import Config
@@ -29,6 +30,8 @@ from module.logger import logger
 from module.device.handle import Handle, window_scale_rate, EmulatorFamily
 
 
+
+
 class Window(Handle):
 
     def __init__(self, *args, **kwargs):
@@ -357,6 +360,7 @@ class Window(Handle):
 
 
 
+
 if __name__ == "__main__":
     w = Window(config='oas1')
     # img = w.screenshot_window_background()

+ 2 - 1
module/device/screenshot.py

@@ -12,7 +12,7 @@ from module.base.decorator import cached_property
 from module.base.timer import Timer
 from module.base.utils import get_color, image_size, limit_in, save_image
 from module.device.method.adb import Adb
-from module.device.method.window import Window
+from module.device.method.windows import Window
 from module.device.method.droidcast import DroidCast
 from module.device.method.scrcpy import Scrcpy
 from module.device.method.nemu_ipc import NemuIpc
@@ -272,4 +272,5 @@ class Screenshot(Adb, DroidCast, Scrcpy, Window, NemuIpc):
 if __name__ == "__main__":
     s = Screenshot(config="oas1")
     s.screenshot()
+
     s.image_show()

+ 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()

+ 5 - 3
script.py

@@ -29,12 +29,13 @@ from module.config.utils import convert_to_underscore
 from module.config.config import Config
 from module.config.config_model import ConfigModel
 from module.device.device import Device
+from module.device.env import IS_WINDOWS
 from module.base.utils import load_module
 from module.base.decorator import del_cached_property
 from module.logger import logger
 from module.exception import *
 from module.server.i18n import I18n
-from module.device.platform2.platform_windows import minimize_by_name,show_window_by_name
+
 
 
 _log_switch_lock = threading.Lock()#线程锁
@@ -442,7 +443,8 @@ class Script:
         self.config.model.running_task = ''
 
         # Update GUI 防呆, 读取设置并立刻显示后台模拟器到前台
-        if not self.config.script.device.run_background_only:
+        if not self.config.script.device.run_background_only and IS_WINDOWS:
+            from module.device.platform2.platform_windows import minimize_by_name, show_window_by_name
             target_window_name = self.config.script.device.handle  # 在这里输入你的具体窗口名称
             if self.config.script.device.emulator_window_minimize:
                 minimize_by_name(target_window_name)
@@ -539,5 +541,5 @@ class Script:
 
 
 if __name__ == "__main__":
-    script = Script("oas2")
+    script = Script("oas1")
     script.loop()

+ 2 - 2
tasks/AbyssShadows/config.py

@@ -5,8 +5,8 @@
 # github    https://github.com/roarhill/oas
 
 from pydantic import BaseModel, Field
-from pygments.lexer import default
-from scripts.regsetup import description
+# from pygments.lexer import default
+# from scripts.regsetup import description
 from sympy.testing.pytest import Failed
 
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig

+ 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


+ 2 - 1
tasks/GameUi/page.py

@@ -37,7 +37,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, RestartAssets.I_LOGIN_SCROOLL_CLOSE]
+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