Parcourir la source

Merge pull request #42 from TripleEarth/dev

fix RyouToppa, add attack chance detect, and will attack all the target after penetration
huangrunheng il y a 3 ans
Parent
commit
d500c736ae

+ 155 - 0
config/deploy.yaml

@@ -0,0 +1,155 @@
+Deploy:
+  Git:
+    # URL of AzurLaneAutoScript repository
+    # [CN user] Use 'https://gitee.com/lmeszinc/azur-lane-auto-script-mirror' for faster and more stable download
+    # [Other] Use 'https://github.com/LmeSzinc/AzurLaneAutoScript'
+    Repository: https://github.com/TripleEarth/OnmyojiAutoScript.git
+    # Branch of Alas
+    # [Developer] Use 'dev', 'app', etc, to try new features
+    # [Other] Use 'master', the stable branch
+    Branch: dev
+    # Filepath of git executable `git.exe`
+    # [Easy installer] Use './toolkit/Git/mingw64/bin/git.exe'
+    # [Other] Use you own git
+    GitExecutable: ./toolkit/Git/mingw64/bin/git.exe
+    # Set git proxy
+    # [CN user] Use your local http proxy (http://127.0.0.1:{port}) or socks5 proxy (socks5://127.0.0.1:{port})
+    # [Other] Use null
+    GitProxy: null
+    # Update Alas at startup
+    # [In most cases] Use true
+    AutoUpdate: true
+    # Whether to keep local changes during update
+    # User settings, logs and screenshots will be kept, no mather this is true or false
+    # [Developer] Use true, if you modified the code
+    # [Other] Use false
+    KeepLocalChanges: false
+
+  Python:
+    # Filepath of python executable `python.exe`
+    # [Easy installer] Use './toolkit/python.exe'
+    # [Other] Use you own python, and its version should be 3.7.6 64bit
+    PythonExecutable: ./toolkit/python.exe
+    # URL of pypi mirror
+    # [CN user] Use 'https://pypi.tuna.tsinghua.edu.cn/simple' for faster and more stable download
+    # [Other] Use null
+    PypiMirror: null
+    # Install dependencies at startup
+    # [In most cases] Use true
+    InstallDependencies: true
+    # Path to requirements.txt
+    # [In most cases] Use 'requirements.txt'
+    # [In AidLux] Use './deploy/AidLux/{version}/requirements.txt', version is default to 0.92
+    RequirementsFile: requirements.txt
+
+  Adb:
+    # Filepath of ADB executable `adb.exe`
+    # [Easy installer] Use './toolkit/Lib/site-packages/adbutils/binaries/adb.exe'
+    # [Other] Use you own latest ADB, but not the ADB in your emulator
+    AdbExecutable: ./toolkit/Lib/site-packages/adbutils/binaries/adb.exe
+    # Whether to replace ADB
+    # Chinese emulators (NoxPlayer, LDPlayer, MemuPlayer, MuMuPlayer) use their own ADB, instead of the latest.
+    # Different ADB servers will terminate each other at startup, resulting in disconnection.
+    # For compatibility, we have to replace them all.
+    # This will do:
+    #   1. Terminate current ADB server
+    #   2. Rename ADB from all emulators to *.bak and replace them by the AdbExecutable set above
+    #   3. Brute-force connect to all available emulator instances
+    # [In most cases] Use true
+    # [In few cases] Use false, if you have other programs using ADB.
+    ReplaceAdb: true
+    # Brute-force connect to all available emulator instances
+    # [In most cases] Use true
+    AutoConnect: true
+    # Re-install uiautomator2
+    # [In most cases] Use true
+    InstallUiautomator2: true
+
+  Ocr:
+    # Run Ocr as a service, can reduce memory usage by not import mxnet everytime you start an alas instance
+
+    # Whether to use ocr server
+    # [Default] false
+    UseOcrServer: false
+    # Whether to start ocr server when start GUI
+    # [Default] false
+    StartOcrServer: false
+    # Port of ocr server runs by GUI
+    # [Default] 22268
+    OcrServerPort: 22268
+    # Address of ocr server for alas instance to connect
+    # [Default] 127.0.0.1:22268
+    OcrClientAddress: 127.0.0.1:22268
+
+  Update:
+    # Use auto update and builtin updater feature
+    # This may cause problem https://github.com/LmeSzinc/AzurLaneAutoScript/issues/876
+    EnableReload: true
+    # Check update every X minute
+    # [Disable] 0
+    # [Default] 5
+    CheckUpdateInterval: 5
+    # Scheduled restart time
+    # If there are updates, Alas will automatically restart and update at this time every day
+    # and run all alas instances that running before restarted
+    # [Disable] null
+    # [Default] 03:50
+    AutoRestartTime: 03:50
+
+  Misc:
+    # Enable discord rich presence
+    DiscordRichPresence: false
+
+  RemoteAccess:
+    # Enable remote access (using ssh reverse tunnel serve by https://github.com/wang0618/localshare)
+    # ! You need to set Password below to enable remote access since everyone can access to your alas if they have your url.
+    # See here (http://app.azurlane.cloud/en.html) for more infomation.
+    EnableRemoteAccess: false
+    # Username when login into ssh server
+    # [Default] null (will generate a random one when startup)
+    SSHUser: null
+    # Server to connect
+    # [Default] null
+    # [Format] host:port
+    SSHServer: null
+    # Filepath of SSH executable `ssh.exe`
+    # [Default] ssh (find ssh in system PATH)
+    # If you don't have one, install OpenSSH or download it here (https://github.com/PowerShell/Win32-OpenSSH/releases)
+    SSHExecutable: ssh
+
+  Webui:
+    # --host. Host to listen
+    # [Use IPv6] '::'
+    # [In most cases] Default to '0.0.0.0'
+    WebuiHost: 0.0.0.0
+    # --port. Port to listen
+    # You will be able to access webui via `http://{host}:{port}`
+    # [In most cases] Default to 22267
+    WebuiPort: 22267
+    # Language to use on web ui
+    # 'zh-CN' for Chinese simplified
+    # 'en-US' for English
+    # 'ja-JP' for Japanese
+    # 'zh-TW' for Chinese traditional
+    Language: zh-CN
+    # Theme of web ui
+    # 'default' for light theme
+    # 'dark' for dark theme
+    Theme: default
+    # Follow system DPI scaling
+    # [In most cases] true
+    # [In few cases] false to make Alas smaller, if you have a low resolution but high DPI scaling.
+    DpiScaling: true
+    # --key. Password of web ui
+    # Useful when expose Alas to the public network
+    Password: null
+    # --cdn. Use jsdelivr cdn for pywebio static files (css, js).
+    # 'true' for jsdelivr cdn
+    # 'false' for self host cdn (automatically)
+    # 'https://path.to.your/cdn' to use custom cdn
+    CDN: false
+    # --run. Auto-run specified config when startup
+    # 'null' default no specified config
+    # '["alas"]' specified "alas" config
+    # '["alas","alas2"]' specified "alas" "alas2" configs
+    Run: null

+ 7 - 0
tasks/RyouToppa/assets.py

@@ -28,5 +28,12 @@ class RyouToppaAssets:
 	I_GUILD_ORDERS_REWARDS = RuleImage(roi_front=(1123,31,115,56), roi_back=(1123,31,115,56), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/res/res_guild_orders_rewards.png")
 	# 攻破阴阳寮 
 	I_SUCCESS_PENETRATION = RuleImage(roi_front=(206,149,100,100), roi_back=(206,149,100,100), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/res/res_success_penetration.png")
+	# 个人突破刷新按钮 
+	I_REAL_RAID_REFRESH = RuleImage(roi_front=(963,569,174,60), roi_back=(963,569,174,60), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/res/res_real_raid_refresh.png")
+
+
+	# Ocr Rule Assets
+	# 寮突破进攻机会数 
+	O_NUMBER = RuleOcr(roi=(271,560,48,31), area=(271,560,48,31), mode="DigitCounter", method="Default", keyword="", name="number")
 
 

+ 9 - 0
tasks/RyouToppa/res/image.json

@@ -52,5 +52,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "攻破阴阳寮"
+  },
+  {
+    "itemName": "real_raid_refresh",
+    "imageName": "res_real_raid_refresh.png",
+    "roiFront": "963,569,174,60",
+    "roiBack": "963,569,174,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "个人突破刷新按钮"
   }
 ]

+ 11 - 0
tasks/RyouToppa/res/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "number",
+    "roiFront": "271,560,48,31",
+    "roiBack": "271,560,48,31",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "寮突破进攻机会数"
+  }
+]

BIN
tasks/RyouToppa/res/res_real_raid_refresh.png


+ 91 - 28
tasks/RyouToppa/script_task.py

@@ -6,12 +6,14 @@ import time
 from tasks.RyouToppa.assets import RyouToppaAssets
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.GameUi.game_ui import GameUi
-from tasks.GameUi.page import page_realm_raid, page_main, page_ryou_toppa
+from tasks.GameUi.page import page_realm_raid, page_main
 from tasks.RealmRaid.assets import RealmRaidAssets
 from module.logger import logger
 from module.exception import TaskEnd
 from module.atom.image_grid import ImageGrid
-
+from module.base.timer import Timer
+from module.exception import GamePageUnknownError
+from tasks.RyouToppa.config import RaidMode, AttackNumber, HaveManageAccess, RaidConfig, RyouToppa
 
 class ScriptTask(GeneralBattle, GameUi, RyouToppaAssets):
     medal_grid: ImageGrid = None
@@ -26,53 +28,44 @@ class ScriptTask(GeneralBattle, GameUi, RyouToppaAssets):
                                      RealmRaidAssets.I_MEDAL_2, RealmRaidAssets.I_MEDAL_1, RealmRaidAssets.I_MEDAL_0])
         self.ui_get_current_page()
         self.ui_goto(page_realm_raid)
-
+        ryou_toppa_start_flag = True
         # 点击突破
         while 1:
             self.screenshot()
             if self.appear_then_click(RealmRaidAssets.I_REALM_RAID, interval=1):
+                logger.info(f'Click {RealmRaidAssets.I_REALM_RAID.name}')
                 continue
-            if self.appear(RealmRaidAssets.I_BACK_RED, threshold=0.6):
+            if self.appear(self.I_REAL_RAID_REFRESH, threshold=0.8):
+                if self.appear_then_click(self.I_RYOU_TOPPA, interval=1):
+                    logger.info(f'Click {self.I_RYOU_TOPPA.name}')
+                    continue
+            # 攻破阴阳寮,说明寮突已开,则退出
+            elif self.appear(self.I_SUCCESS_PENETRATION, threshold=0.8):
+                ryou_toppa_start_flag = True
                 break
-        logger.info(f'Click {RealmRaidAssets.I_REALM_RAID.name}')
-
-        ryou_toppa_start_flag = True
-
-        # 点击寮突
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_RYOU_TOPPA, interval=1):
-                continue
             # 出现选择寮突说明寮突未开
-            if self.appear(self.I_SELECT_RYOU_BUTTON, threshold=0.8):
+            elif self.appear(self.I_SELECT_RYOU_BUTTON, threshold=0.8):
                 ryou_toppa_start_flag = False
                 break
             # 出现寮奖励, 说明寮突已开
-            if self.appear(self.I_RYOU_REWARD, threshold=0.8):
+            elif self.appear(self.I_RYOU_REWARD, threshold=0.8):
                 ryou_toppa_start_flag = True
                 break
-            # 攻破阴阳寮,说明寮突已开,则退出
-            if self.appear(self.I_SUCCESS_PENETRATION, threshold=0.8):
-                ryou_toppa_start_flag = True
-                break
-        logger.info(f'Click {self.I_RYOU_TOPPA.name}')
 
         # 寮突未开 并且有权限, 开开寮突
         if not ryou_toppa_start_flag and config.raid_config.ryou_access == 'yes':
             # 开寮突
             self.start_ryou_toppa()
 
-        # 切换阵容 再说
+        # 切换阵容 待实现
 
         # 开始突破
         while 1:
-            # 攻破阴阳寮,则退出
-            if self.appear(self.I_SUCCESS_PENETRATION, threshold=0.8):
+            if self.execute_round(config):
+                continue
+            else:
                 break
-            # 点击结界, 并挑战
-            self.medal_fire()
-            self.run_general_battle(config.general_battle_config)
-            self.wait_until_appear(RealmRaidAssets.I_BACK_RED)
+
 
         # 回 page_main 失败
         # self.ui_current = page_ryou_toppa
@@ -117,6 +110,20 @@ class ScriptTask(GeneralBattle, GameUi, RyouToppaAssets):
                 break
         logger.info(f'Click {self.I_START_TOPPA_BUTTON.name}')
 
+    def is_ticket(self) -> bool:
+        """
+        如果没有票了,那么就返回False
+        :return:
+        """
+        self.wait_until_appear(RealmRaidAssets.I_BACK_RED)
+        self.screenshot()
+        cu, res, total = self.O_NUMBER.ocr(self.device.image)
+        logger.info(f"cu = {cu}, res = {res}, total = {total}")
+        if cu == 0 and cu+res == total:
+            logger.warning(f'Execute round failed, no chance to attack')
+            return False
+        return True
+
     def medal_fire(self) -> bool:
         """
         点击勋章
@@ -156,4 +163,60 @@ class ScriptTask(GeneralBattle, GameUi, RyouToppaAssets):
                 continue
             if not self.appear(RealmRaidAssets.I_FIRE, threshold=0.8):
                 break
-        logger.info(f'Click {RealmRaidAssets.I_FIRE.name}')
+        logger.info(f'Click {RealmRaidAssets.I_FIRE.name}')
+
+    def execute_round(self, config: RaidMode) -> bool:
+        """
+        执行一轮 除非票不够,一直到到九次
+        :return:
+        """
+        # 如果没有票了,就退出
+        if not self.is_ticket():
+            return False
+        if not self.is_target_available():
+            return False
+        # # 判断是退四打九还是全部打
+        # if config.raid_config.raid_mode == RaidMode.NORMAL:
+        #     logger.info(f'Execute round, retreat four attack nine')
+        #     self.medal_fire()
+        #     self.run_general_battle_back(config.general_battle_config)
+        #
+        #     self.medal_fire()
+        #     self.run_general_battle_back(config.general_battle_config)
+        #
+        #     self.medal_fire()
+        #     self.run_general_battle_back(config.general_battle_config)
+        #
+        #     self.medal_fire()
+        #     self.run_general_battle_back(config.general_battle_config)
+
+        # 打20次
+        for i in range(20):
+            if not self.is_ticket():
+                return False
+            if not self.is_target_available():
+                return False
+            self.medal_fire()
+            self.run_general_battle(config.general_battle_config)
+            self.wait_until_appear(RealmRaidAssets.I_BACK_RED)
+
+        return True
+
+    # 判断是否还有可进攻的目标
+    def is_target_available(self) -> bool:
+        """
+            如果没有可进攻目标了,那么就返回False
+            :return:
+            """
+        self.wait_until_appear(RealmRaidAssets.I_BACK_RED)
+        self.screenshot()
+        # 有徽章被检测到
+        if self.medal_grid.find_anyone(self.device.image):
+            return True
+        # 没有徽章被检测到,且目标寮已被攻破
+        elif self.appear(self.I_SUCCESS_PENETRATION, threshold=0.8):
+            logger.info(f'Execute round failed, no target')
+            return False
+        else:
+            raise GamePageUnknownError
+