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

Merge pull request #61 from endlesswxk/dev

update ryotoppa
huangrunheng 3 лет назад
Родитель
Сommit
3f7e46699e

+ 4 - 1
module/config/i18n/zh_CN.ts

@@ -201,6 +201,7 @@
 	<message><source>GlobalGame</source><translation>全局游戏设置</translation></message>
 	<message><source>RealmRaid</source><translation>个人突破</translation></message>
 	<message><source>RyouToppa</source><translation>寮突破</translation></message>
+	<message><source>Exploration</source><translation>探索</translation></message>
 	<message><source>List Rule</source><translation>列表规则</translation></message>
 	<message><source>Activity Task</source><translation>限时活动</translation></message>
 	<message><source>ActivityShikigami</source><translation>当期式神爬塔</translation></message>
@@ -512,7 +513,9 @@ mode_3策略是刷到五个契灵后开始结契,选择高级、中级盘来
 	<message><source>switch_group_team_help</source><translation>初始值是不合适的,你需要根据自己的情况设置
 "1,2"表示第一个预设组,第二个队伍
 请使用英文输入法下的逗号
-预设组支持[1-7], 预设队伍支持[1-4]</translation></message>	
+预设组支持[1-7], 预设队伍支持[1-4]</translation></message>
+	<message><source>group_name</source><translation>御魂分组名</translation></message>
+	<message><source>team_name</source><translation>队伍名</translation></message>
 </context>
 <context>
     <name>Args</name>

+ 22 - 0
tasks/Component/SwitchSoul/assets.py

@@ -58,5 +58,27 @@ class SwitchSoulAssets:
 	I_SOU_CHECK_GROUP_6 = RuleImage(roi_front=(1085,443,23,54), roi_back=(1085,443,23,54), threshold=0.8, method="Template matching", file="./tasks/Component/SwitchSoul/ss/ss_sou_check_group_6.png")
 	# description 
 	I_SOU_CHECK_GROUP_7 = RuleImage(roi_front=(1088,512,21,54), roi_back=(1088,512,21,54), threshold=0.8, method="Template matching", file="./tasks/Component/SwitchSoul/ss/ss_sou_check_group_7.png")
+	# 匹配队伍预设 
+	I_SOU_TEAM_PRESENT = RuleImage(roi_front=(737,82,148,43), roi_back=(727,71,165,63), threshold=0.8, method="Template matching", file="./tasks/Component/SwitchSoul/ss/ss_sou_team_present.png")
+	# 需要切换的预设按钮(颜色深一点) 
+	I_SOU_CLICK_PRESENT = RuleImage(roi_front=(967,305,43,22), roi_back=(965,142,48,480), threshold=0.9, method="Template matching", file="./tasks/Component/SwitchSoul/ss/ss_sou_click_present.png")
+
+
+	# Ocr Rule Assets
+	# 队伍预设分组 
+	O_SS_GROUP_NAME = RuleOcr(roi=(1087,91,155,566), area=(1110,94,116,533), mode="Full", method="Default", keyword="", name="ss_group_name")
+	# 阵容匹配 
+	O_SS_TEAM_NAME = RuleOcr(roi=(573,140,277,481), area=(667,144,32,475), mode="Full", method="Default", keyword="", name="ss_team_name")
+
+
+	# Swipe Rule Assets
+	# 列表的向上滑动 
+	S_SS_GROUP_SWIPE_UP = RuleSwipe(roi_front=(1154,180,23,21), roi_back=(1153,322,21,21), mode="default", name="ss_group_swipe_up")
+	# 列表的向下滑动 
+	S_SS_GROUP_SWIPE_DOWN = RuleSwipe(roi_front=(1155,388,21,22), roi_back=(1152,177,22,24), mode="default", name="ss_group_swipe_down")
+	# 阵容向上滑动 
+	S_SS_TEAM_SWIPE_UP = RuleSwipe(roi_front=(720,439,21,21), roi_back=(717,308,21,21), mode="default", name="ss_team_swipe_up")
+	# 阵容向上滑动 
+	S_SS_TEAM_SWIPE_DOWN = RuleSwipe(roi_front=(709,308,21,21), roi_back=(709,449,21,21), mode="default", name="ss_team_swipe_down")
 
 

+ 18 - 0
tasks/Component/SwitchSoul/ss/image.json

@@ -133,5 +133,23 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
+  },
+  {
+    "itemName": "sou_team_present",
+    "imageName": "ss_sou_team_present.png",
+    "roiFront": "737,82,148,43",
+    "roiBack": "727,71,165,63",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "匹配队伍预设"
+  },
+  {
+    "itemName": "sou_click_present",
+    "imageName": "ss_sou_click_present.png",
+    "roiFront": "967,305,43,22",
+    "roiBack": "965,142,48,480",
+    "method": "Template matching",
+    "threshold": 0.9,
+    "description": "需要切换的预设按钮(颜色深一点)"
   }
 ]

+ 20 - 0
tasks/Component/SwitchSoul/ss/ocr.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "ss_group_name",
+    "roiFront": "1087,91,155,566",
+    "roiBack": "1110,94,116,533",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "",
+    "description": "队伍预设分组"
+  },
+  {
+    "itemName": "ss_team_name",
+    "roiFront": "573,140,277,481",
+    "roiBack": "667,144,32,475",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "",
+    "description": "阵容匹配"
+  }
+]

BIN
tasks/Component/SwitchSoul/ss/ss_sou_click_present.png


BIN
tasks/Component/SwitchSoul/ss/ss_sou_team_present.png


+ 30 - 0
tasks/Component/SwitchSoul/ss/swipe.json

@@ -0,0 +1,30 @@
+[
+  {
+    "itemName": "ss_group_swipe_up",
+    "roiFront": "1154,180,23,21",
+    "roiBack": "1153,322,21,21",
+    "mode": "default",
+    "description": "列表的向上滑动"
+  },
+  {
+    "itemName": "ss_group_swipe_down",
+    "roiFront": "1155,388,21,22",
+    "roiBack": "1152,177,22,24",
+    "mode": "default",
+    "description": "列表的向下滑动"
+  },
+  {
+    "itemName": "ss_team_swipe_up",
+    "roiFront": "720,439,21,21",
+    "roiBack": "717,308,21,21",
+    "mode": "default",
+    "description": "阵容向上滑动"
+  },
+  {
+    "itemName": "ss_team_swipe_down",
+    "roiFront": "709,308,21,21",
+    "roiBack": "709,449,21,21",
+    "mode": "default",
+    "description": "阵容向上滑动"
+  }
+]

+ 89 - 1
tasks/Component/SwitchSoul/switch_soul.py

@@ -47,6 +47,8 @@ class SwitchSoul(BaseTask, SwitchSoulAssets):
                 break
             if self.appear(self.I_SOU_SWITCH_4):
                 break
+            if self.appear(self.I_SOU_TEAM_PRESENT):
+                break
             if self.appear_then_click(self.I_SOUL_PRESET, interval=1):
                 continue
         logger.info('Click preset in switch soul')
@@ -102,7 +104,6 @@ class SwitchSoul(BaseTask, SwitchSoulAssets):
                 logger.warning(f'Click team {team} failed in group {group}')
         logger.info(f'Switch soul_one group {group} team {team}')
 
-
     def switch_souls(self, target: tuple or list[tuple]) -> None:
         """
         切换御魂
@@ -129,8 +130,95 @@ class SwitchSoul(BaseTask, SwitchSoulAssets):
                 continue
         logger.info('Exit shikigami records')
 
+    def run_switch_soul_by_name(self, groupName, teamName):
+        """
+        保证在式神录的界面
+        :return:
+        """
+        if isinstance(groupName, str) and isinstance(teamName, str):
+            self.click_preset()
+            self.switch_soul_by_name(groupName, teamName)
+
+    def switch_soul_by_name(self, groupName, teamName):
+        """
+        保证在式神录的界面
+        :return:
+        """
+        # 滑动至分组最上层
+        while 1:
+            self.screenshot()
+            compare1 = self.O_SS_GROUP_NAME.detect_and_ocr(self.device.image)
+            text1 = str([result.ocr_text for result in compare1])
+            # 向上滑动
+            self.swipe(self.S_SS_GROUP_SWIPE_UP, 6)
+            self.screenshot()
+            compare2 = self.O_SS_GROUP_NAME.detect_and_ocr(self.device.image)
+            text2 = str([result.ocr_text for result in compare2])
+            # 相等时 滑动到最上层
+            if text1 == text2:
+                break
+
+        # 判断有无目标分组
+        while 1:
+            self.screenshot()
+            # 获取当前分组名
+            results = self.O_SS_GROUP_NAME.detect_and_ocr(self.device.image)
+            text1 = [result.ocr_text for result in results]
+            # 判断当前分组有无目标分组
+            result = set(text1).intersection({groupName})
+            # 有则跳出检测
+            if result and len(result) > 0:
+                break
+            self.swipe(self.S_SS_GROUP_SWIPE_DOWN)
+
+        # 选中分组
+        while 1:
+            self.screenshot()
+            self.O_SS_GROUP_NAME.keyword = groupName
+            if self.ocr_appear_click(self.O_SS_GROUP_NAME):
+                break
 
+        # 滑动至阵容最上层
+        while 1:
+            self.screenshot()
+            compare1 = self.O_SS_TEAM_NAME.detect_and_ocr(self.device.image)
+            text1 = str([result.ocr_text for result in compare1])
+            # 向上滑动
+            self.swipe(self.S_SS_TEAM_SWIPE_DOWN, 6)
+            self.screenshot()
+            compare2 = self.O_SS_TEAM_NAME.detect_and_ocr(self.device.image)
+            text2 = str([result.ocr_text for result in compare2])
+            # 相等时 说明滑动到最上层
+            if text1 == text2:
+                break
+        # 判断当前分组有无目标阵容
+        while 1:
+            self.screenshot()
+            # 获取当前阵容名
+            results = self.O_SS_TEAM_NAME.detect_and_ocr(self.device.image)
+            text1 = [result.ocr_text for result in results]
+            # 判断当前分组有无目标阵容
+            result = set(text1).intersection({teamName})
+            # 有则跳出检测
+            if result and len(result) > 0:
+                break
+            self.swipe(self.S_SS_TEAM_SWIPE_UP)
 
+        # 选中分组
+        while 1:
+            self.screenshot()
+            self.O_SS_TEAM_NAME.keyword = teamName
+            if self.ocr_appear_click(self.O_SS_TEAM_NAME):
+                break
+        # 切换御魂
+        for i in range(6):
+            sleep(0.8)
+            self.screenshot()
+            if self.appear_then_click(self.I_SOU_CLICK_PRESENT, interval=1):
+                continue
+            if self.appear_then_click(self.I_SOU_SWITCH_SURE, interval=1):
+                break
+        logger.info(f'Switch soul_one group {groupName} team {teamName}')
 
 if __name__ == '__main__':
     from module.config.config import Config

+ 3 - 1
tasks/Component/SwitchSoul/switch_soul_config.py

@@ -10,4 +10,6 @@ from datetime import datetime, time
 class SwitchSoulConfig(BaseModel):
     enable: bool = Field(default=False)
     switch_group_team: str = Field(default='-1,-1', description='switch_group_team_help')
-
+    enable_switch_by_name: bool = Field(default=False)
+    group_name: str = Field(default='', description='group_name')
+    team_name: str = Field(default='', description='team_name')

+ 1 - 1
tasks/RyouToppa/assets.py

@@ -21,7 +21,7 @@ class RyouToppaAssets:
 	# 寮突选择阴阳寮按钮 
 	I_SELECT_RYOU_BUTTON = RuleImage(roi_front=(560,577,156,46), roi_back=(560,577,156,46), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/res/res_select_ryou_button.png")
 	# 开始寮突按钮 
-	I_START_TOPPA_BUTTON = RuleImage(roi_front=(812,497,171,55), roi_back=(812,497,171,55), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/res/res_start_toppa_button.png")
+	I_START_TOPPA_BUTTON = RuleImage(roi_front=(834,504,127,38), roi_back=(4,3,1056,716), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/res/res_start_toppa_button.png")
 	# 寮击破奖励 
 	I_RYOU_REWARD = RuleImage(roi_front=(134,417,241,40), roi_back=(134,417,241,40), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/res/res_ryou_reward.png")
 	# 勋章奖励标题 

+ 2 - 0
tasks/RyouToppa/config.py

@@ -1,6 +1,7 @@
 from pydantic import BaseModel, Field
 from enum import Enum
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
+from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
 from tasks.Component.config_base import ConfigBase
 from tasks.Component.config_scheduler import Scheduler
 
@@ -31,3 +32,4 @@ class RyouToppa(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
     raid_config: RaidConfig = Field(default_factory=RaidConfig)
     general_battle_config: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
+    switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)

+ 2 - 2
tasks/RyouToppa/res/image.json

@@ -20,8 +20,8 @@
   {
     "itemName": "start_toppa_button",
     "imageName": "res_start_toppa_button.png",
-    "roiFront": "812,497,171,55",
-    "roiBack": "812,497,171,55",
+    "roiFront": "834,504,127,38",
+    "roiBack": "4,3,1056,716",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "开始寮突按钮"

BIN
tasks/RyouToppa/res/res_start_toppa_button.png


+ 27 - 13
tasks/RyouToppa/script_task.py

@@ -3,10 +3,11 @@
 # github https://github.com/runhey
 import time
 
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 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_kekkai_toppa
+from tasks.GameUi.page import page_realm_raid, page_main, page_kekkai_toppa, page_shikigami_records
 from tasks.RealmRaid.assets import RealmRaidAssets
 from module.logger import logger
 from module.exception import TaskEnd
@@ -15,7 +16,8 @@ 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):
+
+class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
     medal_grid: ImageGrid = None
 
     def run(self):
@@ -26,6 +28,17 @@ class ScriptTask(GeneralBattle, GameUi, RyouToppaAssets):
         config = self.config.ryou_toppa
         self.medal_grid = ImageGrid([RealmRaidAssets.I_MEDAL_5, RealmRaidAssets.I_MEDAL_4, RealmRaidAssets.I_MEDAL_3,
                                      RealmRaidAssets.I_MEDAL_2, RealmRaidAssets.I_MEDAL_1, RealmRaidAssets.I_MEDAL_0])
+
+        # if config.switch_soul_config.enable:
+        #     self.ui_get_current_page()
+        #     self.ui_goto(page_shikigami_records)
+        #     self.run_switch_soul(config.switch_soul_config.switch_group_team)
+
+        if config.switch_soul_config.enable_switch_by_name:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul_by_name(config.switch_soul_config.group_name, config.switch_soul_config.team_name)
+
         self.ui_get_current_page()
         self.ui_goto(page_kekkai_toppa)
         ryou_toppa_start_flag = True
@@ -66,12 +79,11 @@ class ScriptTask(GeneralBattle, GameUi, RyouToppaAssets):
             else:
                 break
 
-
         # 回 page_main 失败
         # self.ui_current = page_ryou_toppa
         # self.ui_goto(page_main)
 
-        self.set_next_run(task='RyouToppa', success=True)
+        self.set_next_run(task='RyouToppa', finish=True, success=True)
         raise TaskEnd
 
     def start_ryou_toppa(self):
@@ -83,20 +95,13 @@ class ScriptTask(GeneralBattle, GameUi, RyouToppaAssets):
         while 1:
             self.screenshot()
             if self.appear_then_click(self.I_SELECT_RYOU_BUTTON, interval=1):
-                continue
-            # 出现勋章奖励标题,说明已进入,则退出
-            if self.appear(self.I_GUILD_ORDERS_REWARDS, threshold=0.8):
                 break
         logger.info(f'Click {self.I_SELECT_RYOU_BUTTON.name}')
 
         # 选择第一个寮
         while 1:
             self.screenshot()
-            if self.appear(self.I_RYOU_TOPPA, interval=1):
-                self.click(self.C_SELECT_FIRST_RYOU)
-                continue
-            # 出现突入开始,则退出
-            if self.appear(self.I_START_TOPPA_BUTTON, threshold=0.8):
+            if self.appear_then_click(self.I_GUILD_ORDERS_REWARDS, action=self.C_SELECT_FIRST_RYOU, interval=1):
                 break
         logger.info(f'Click {self.C_SELECT_FIRST_RYOU.name}')
 
@@ -119,7 +124,7 @@ class ScriptTask(GeneralBattle, GameUi, RyouToppaAssets):
         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:
+        if cu == 0 and cu + res == total:
             logger.warning(f'Execute round failed, no chance to attack')
             return False
         return True
@@ -220,3 +225,12 @@ class ScriptTask(GeneralBattle, GameUi, RyouToppaAssets):
         else:
             raise GamePageUnknownError
 
+
+if __name__ == "__main__":
+    from module.config.config import Config
+    from module.device.device import Device
+
+    config = Config('oas1')
+    device = Device(config)
+    t = ScriptTask(config, device)
+    t.run()