瀏覽代碼

refactor(RyouToppa):

ryland 2 年之前
父節點
當前提交
2720e68791

+ 1 - 2
module/config/config_menu.py

@@ -25,8 +25,7 @@ class ConfigMenu:
                                    'TalismanPass', 'DemonEncounter', 'Pets', 'SoulsTidy', 'Delegation', 'WantedQuests',
                                    'Tako']
         # 很肝的任务
-        self.menu["Liver Emperor Exclusive"] = ['BondlingFairyland', 'EvoZone', 'GoryouRealm', 'Exploration',
-                                                'DevExploration']
+        self.menu["Liver Emperor Exclusive"] = ['BondlingFairyland', 'EvoZone', 'GoryouRealm', 'Exploration',]
         # 阴阳寮
         self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'CollectiveMissions',
                               'Hunt']

+ 2 - 1
tasks/DevRyouToppa/assets.py

@@ -8,7 +8,8 @@ from module.atom.list import RuleList
 # This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class DevRyouToppaAssets: 
-  
+
+
 	# Click Rule Assets
 	# area1 
 	C_AREA_1 = RuleClick(roi_front=(533,162,177,74), roi_back=(533,162,177,74), name="area_1")

+ 1 - 1
tasks/DevRyouToppa/script_task.py

@@ -101,7 +101,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
                     self.flush_area_cache()
                     index = 0
 
-    def check_area(self, index: int):
+    def check_area(self, index: int) -> bool:
         """
         检查该区域是否攻略失败
         :return:

+ 1 - 1
tasks/Orochi/assets.py

@@ -20,7 +20,7 @@ class OrochiAssets:
 	# description 
 	I_OROCHI_UNLOCK = RuleImage(roi_front=(562,564,26,29), roi_back=(550,553,100,51), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_orochi_unlock.png")
 	# 点击挑战 
-	I_OROCHI_FIRE = RuleImage(roi_front=(1095,577,131,124), roi_back=(1095,577,131,124), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_orochi_wild_fire.png")
+	I_OROCHI_FIRE = RuleImage(roi_front=(1095,577,131,124), roi_back=(1095,577,131,124), threshold=0.6, method="Template matching", file="./tasks/Orochi/o/o_orochi_fire.png")
 	# 式神录 
 	I_SHI_RECORDS = RuleImage(roi_front=(821,638,48,45), roi_back=(821,638,48,45), threshold=0.8, method="Template matching", file="./tasks/Orochi/o/o_shi_records.png")
 	# description 

+ 100 - 0
tasks/RyouToppa/assets.py

@@ -10,6 +10,106 @@ from module.atom.list import RuleList
 class RyouToppaAssets: 
 
 
+	# Click Rule Assets
+	# area1 
+	C_AREA_1 = RuleClick(roi_front=(533,162,177,74), roi_back=(533,162,177,74), name="area_1")
+	# area2 
+	C_AREA_2 = RuleClick(roi_front=(863,164,181,71), roi_back=(863,164,181,71), name="area_2")
+	# area3 
+	C_AREA_3 = RuleClick(roi_front=(532,292,181,87), roi_back=(532,292,181,87), name="area_3")
+	# area4 
+	C_AREA_4 = RuleClick(roi_front=(863,301,171,62), roi_back=(863,301,171,62), name="area_4")
+	# area5 
+	C_AREA_5 = RuleClick(roi_front=(540,432,169,68), roi_back=(540,432,169,68), name="area_5")
+	# area6 
+	C_AREA_6 = RuleClick(roi_front=(876,432,165,74), roi_back=(876,432,165,74), name="area_6")
+	# area7 
+	C_AREA_7 = RuleClick(roi_front=(538,557,149,71), roi_back=(538,557,149,71), name="area_7")
+	# area8 
+	C_AREA_8 = RuleClick(roi_front=(876,562,150,67), roi_back=(876,562,150,67), name="area_8")
+	# 在点击进攻后如果未进入战斗画面则点击的安全区域 
+	C_SAFE_AREA = RuleClick(roi_front=(182,213,160,229), roi_back=(182,213,160,229), name="safe_area")
+
+
+	# Image Rule Assets
+	# 区域1攻略失败 
+	I_AREA_1_IS_FAILURE = RuleImage(roi_front=(673,146,63,32), roi_back=(421,127,325,134), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_1.png")
+	# 区域2攻略失败 
+	I_AREA_2_IS_FAILURE = RuleImage(roi_front=(1011,146,63,30), roi_back=(757,125,327,140), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_1.png")
+	# 区域3攻略失败 
+	I_AREA_3_IS_FAILURE = RuleImage(roi_front=(665,283,73,40), roi_back=(419,254,327,144), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_1.png")
+	# 区域4攻略失败 
+	I_AREA_4_IS_FAILURE = RuleImage(roi_front=(1000,283,72,38), roi_back=(756,260,325,139), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_1.png")
+	# 区域5攻略失败 
+	I_AREA_5_IS_FAILURE = RuleImage(roi_front=(669,419,65,29), roi_back=(418,392,328,142), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_1.png")
+	# 区域6攻略失败 
+	I_AREA_6_IS_FAILURE = RuleImage(roi_front=(988,416,84,37), roi_back=(755,395,328,141), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_1.png")
+	# 区域7攻略失败 
+	I_AREA_7_IS_FAILURE = RuleImage(roi_front=(672,556,61,37), roi_back=(420,530,326,127), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_1.png")
+	# 区域8攻略失败 
+	I_AREA_8_IS_FAILURE = RuleImage(roi_front=(1004,556,64,29), roi_back=(756,530,327,124), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_1.png")
+	# 区域1攻略失败(最近一次) 
+	I_AREA_1_IS_FAILURE_NEW = RuleImage(roi_front=(673,146,63,32), roi_back=(421,123,325,138), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_2.png")
+	# 区域2攻略失败(最近一次) 
+	I_AREA_2_IS_FAILURE_NEW = RuleImage(roi_front=(1011,146,63,30), roi_back=(757,126,327,139), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_2.png")
+	# 区域3攻略失败(最近一次) 
+	I_AREA_3_IS_FAILURE_NEW = RuleImage(roi_front=(665,283,73,40), roi_back=(419,261,327,137), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_2.png")
+	# 区4攻略失败(最近一次) 
+	I_AREA_4_IS_FAILURE_NEW = RuleImage(roi_front=(1000,283,72,38), roi_back=(756,258,325,141), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_2.png")
+	# 区域5攻略失败(最近一次) 
+	I_AREA_5_IS_FAILURE_NEW = RuleImage(roi_front=(669,419,65,29), roi_back=(418,394,328,140), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_2.png")
+	# 区域6攻略失败(最近一次) 
+	I_AREA_6_IS_FAILURE_NEW = RuleImage(roi_front=(988,416,84,37), roi_back=(755,395,328,141), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_2.png")
+	# 区域7攻略失败(最近一次) 
+	I_AREA_7_IS_FAILURE_NEW = RuleImage(roi_front=(672,556,61,37), roi_back=(420,533,326,124), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_2.png")
+	# 区域8攻略失败(最近一次) 
+	I_AREA_8_IS_FAILURE_NEW = RuleImage(roi_front=(1004,556,64,29), roi_back=(756,532,327,122), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/loser_sign_2.png")
+
+
+	# Image Rule Assets
+	# 区域1已攻破 
+	I_AREA_1_FINISHED = RuleImage(roi_front=(658,141,93,91), roi_back=(421,127,325,134), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_1.png")
+	# 区域2已攻破 
+	I_AREA_2_FINISHED = RuleImage(roi_front=(983,137,100,100), roi_back=(757,125,327,140), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_1.png")
+	# 区域3已攻破 
+	I_AREA_3_FINISHED = RuleImage(roi_front=(681,312,47,37), roi_back=(419,254,327,144), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_1.png")
+	# 区域4已攻破 
+	I_AREA_4_FINISHED = RuleImage(roi_front=(996,271,100,100), roi_back=(756,260,325,139), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_1.png")
+	# 区域5已攻破 
+	I_AREA_5_FINISHED = RuleImage(roi_front=(647,404,100,100), roi_back=(418,392,328,142), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_1.png")
+	# 区域6已攻破 
+	I_AREA_6_FINISHED = RuleImage(roi_front=(1015,448,56,35), roi_back=(755,395,328,141), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_1.png")
+	# 区域7已攻破 
+	I_AREA_7_FINISHED = RuleImage(roi_front=(643,543,100,100), roi_back=(420,530,326,127), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_1.png")
+	# 区域8已攻破 
+	I_AREA_8_FINISHED = RuleImage(roi_front=(983,541,100,100), roi_back=(756,530,327,124), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_1.png")
+	# 区域1已攻破新 
+	I_AREA_1_FINISHED_NEW = RuleImage(roi_front=(658,141,93,91), roi_back=(421,127,325,134), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_2.png")
+	# 区域2已攻破新 
+	I_AREA_2_FINISHED_NEW = RuleImage(roi_front=(983,137,100,100), roi_back=(757,125,327,140), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_2.png")
+	# 区域3已攻破新 
+	I_AREA_3_FINISHED_NEW = RuleImage(roi_front=(681,312,47,37), roi_back=(419,254,327,144), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_2.png")
+	# 区域4已攻破新 
+	I_AREA_4_FINISHED_NEW = RuleImage(roi_front=(996,271,100,100), roi_back=(756,260,325,139), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_2.png")
+	# 区域5已攻破新 
+	I_AREA_5_FINISHED_NEW = RuleImage(roi_front=(647,404,100,100), roi_back=(418,392,328,142), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_2.png")
+	# 区域6已攻破新 
+	I_AREA_6_FINISHED_NEW = RuleImage(roi_front=(1015,448,56,35), roi_back=(755,395,328,141), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_2.png")
+	# 区域7已攻破新 
+	I_AREA_7_FINISHED_NEW = RuleImage(roi_front=(643,543,100,100), roi_back=(420,530,326,127), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_2.png")
+	# 区域8已攻破新 
+	I_AREA_8_FINISHED_NEW = RuleImage(roi_front=(983,541,100,100), roi_back=(756,530,327,124), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/finished_2.png")
+
+
+	# Image Rule Assets
+	# description 
+	I_TOPPA_RECORD = RuleImage(roi_front=(66,628,64,39), roi_back=(66,628,64,39), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/res_toppa_record.png")
+	# description 
+	I_TOPPA_LOCK_TEAM = RuleImage(roi_front=(201,601,30,36), roi_back=(201,601,30,36), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/dev_toppa_lock_team.png")
+	# description 
+	I_TOPPA_UNLOCK_TEAM = RuleImage(roi_front=(199,603,31,31), roi_back=(199,603,31,31), threshold=0.8, method="Template matching", file="./tasks/RyouToppa/dev/dev_toppa_unlock_team.png")
+
+
 	# Click Rule Assets
 	# 选择第一个寮 
 	C_SELECT_FIRST_RYOU = RuleClick(roi_front=(1148,138,21,22), roi_back=(1148,138,21,22), name="select_first_ryou")

+ 23 - 19
tasks/RyouToppa/config.py

@@ -2,30 +2,34 @@ 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_base import ConfigBase, Time
 from tasks.Component.config_scheduler import Scheduler
 
 
-class RaidMode(str, Enum):
-    ATTACK_ALL = 'attack_all'
-
-
-class AttackNumber(str, Enum):
-    ALL = 'all'
-
-
-class HaveManageAccess(str, Enum):
-    YES = 'yes'
-    NO = 'no'
-
 
 class RaidConfig(BaseModel):
-    raid_mode: RaidMode = Field(title='Raid Mode', default=RaidMode.ATTACK_ALL,
-                                description='raid_mode_help')
-    attack_number: AttackNumber = Field(title='Attack Number', default=AttackNumber.ALL,
-                                        description='')
-    ryou_access: HaveManageAccess = Field(title='Ryou Access', default=HaveManageAccess.YES,
-                                          description='是否是寮管理')
+    # 限制时间
+    limit_time: Time = Field(default=Time(minute=30), description='limit_time_help')
+    # 限制次数
+    limit_count: int = Field(default=50, description='limit_count_help')
+    # 是否跳过难度较高的结界,失败后不再攻打该结界
+    skip_difficult: bool = Field(default=True, description='skip_difficult_help')
+    # 寮管理开启寮突破
+    ryou_access: bool = Field(default=False, description='ryou_access_help')
+    # 正式进攻会设定 2s - 10s 的随机延迟,避免攻击间隔及其相近被检测为脚本。
+    random_delay: bool = Field(default=False, description='random_delay_help')
+
+
+    # raid_mode: RaidMode = Field(title='Raid Mode', default=RaidMode.ATTACK_ALL,
+    #                             description='raid_mode_help')
+    # attack_number: AttackNumber = Field(title='Attack Number', default=AttackNumber.ALL,
+    #                                     description='')
+    # 打完没票了 0/6 => 失败
+    # 突破压根没开  +> 失败
+    # 时间打满了  成功
+    # 次数打满了  成功
+    # 打完了(有失败的但是大不了) 成功
+
 
 
 class RyouToppa(ConfigBase):

+ 56 - 0
tasks/RyouToppa/dev/click.json

@@ -0,0 +1,56 @@
+[
+  {
+    "itemName": "area_1",
+    "roiFront": "533,162,177,74",
+    "roiBack": "533,162,177,74",
+    "description": "area1"
+  },
+  {
+    "itemName": "area_2",
+    "roiFront": "863,164,181,71",
+    "roiBack": "863,164,181,71",
+    "description": "area2"
+  },
+  {
+    "itemName": "area_3",
+    "roiFront": "532,292,181,87",
+    "roiBack": "532,292,181,87",
+    "description": "area3"
+  },
+  {
+    "itemName": "area_4",
+    "roiFront": "863,301,171,62",
+    "roiBack": "863,301,171,62",
+    "description": "area4"
+  },
+  {
+    "itemName": "area_5",
+    "roiFront": "540,432,169,68",
+    "roiBack": "540,432,169,68",
+    "description": "area5"
+  },
+  {
+    "itemName": "area_6",
+    "roiFront": "876,432,165,74",
+    "roiBack": "876,432,165,74",
+    "description": "area6"
+  },
+  {
+    "itemName": "area_7",
+    "roiFront": "538,557,149,71",
+    "roiBack": "538,557,149,71",
+    "description": "area7"
+  },
+  {
+    "itemName": "area_8",
+    "roiFront": "876,562,150,67",
+    "roiBack": "876,562,150,67",
+    "description": "area8"
+  },
+  {
+    "itemName": "safe_area",
+    "roiFront": "182,213,160,229",
+    "roiBack": "182,213,160,229",
+    "description": "在点击进攻后如果未进入战斗画面则点击的安全区域"
+  }
+]

二進制
tasks/RyouToppa/dev/dev_toppa_lock_team.png


二進制
tasks/RyouToppa/dev/dev_toppa_unlock_team.png


+ 146 - 0
tasks/RyouToppa/dev/failure.json

@@ -0,0 +1,146 @@
+[
+  {
+    "itemName": "area_1_is_failure",
+    "imageName": "loser_sign_1.png",
+    "roiFront": "673,146,63,32",
+    "roiBack": "421,127,325,134",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域1攻略失败"
+  },
+  {
+    "itemName": "area_2_is_failure",
+    "imageName": "loser_sign_1.png",
+    "roiFront": "1011,146,63,30",
+    "roiBack": "757,125,327,140",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域2攻略失败"
+  },
+  {
+    "itemName": "area_3_is_failure",
+    "imageName": "loser_sign_1.png",
+    "roiFront": "665,283,73,40",
+    "roiBack": "419,254,327,144",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域3攻略失败"
+  },
+  {
+    "itemName": "area_4_is_failure",
+    "imageName": "loser_sign_1.png",
+    "roiFront": "1000,283,72,38",
+    "roiBack": "756,260,325,139",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域4攻略失败"
+  },
+  {
+    "itemName": "area_5_is_failure",
+    "imageName": "loser_sign_1.png",
+    "roiFront": "669,419,65,29",
+    "roiBack": "418,392,328,142",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域5攻略失败"
+  },
+  {
+    "itemName": "area_6_is_failure",
+    "imageName": "loser_sign_1.png",
+    "roiFront": "988,416,84,37",
+    "roiBack": "755,395,328,141",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域6攻略失败"
+  },
+  {
+    "itemName": "area_7_is_failure",
+    "imageName": "loser_sign_1.png",
+    "roiFront": "672,556,61,37",
+    "roiBack": "420,530,326,127",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域7攻略失败"
+  },
+  {
+    "itemName": "area_8_is_failure",
+    "imageName": "loser_sign_1.png",
+    "roiFront": "1004,556,64,29",
+    "roiBack": "756,530,327,124",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域8攻略失败"
+  },
+  {
+    "itemName": "area_1_is_failure_new",
+    "imageName": "loser_sign_2.png",
+    "roiFront": "673,146,63,32",
+    "roiBack": "421,123,325,138",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域1攻略失败(最近一次)"
+  },
+  {
+    "itemName": "area_2_is_failure_new",
+    "imageName": "loser_sign_2.png",
+    "roiFront": "1011,146,63,30",
+    "roiBack": "757,126,327,139",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域2攻略失败(最近一次)"
+  },
+  {
+    "itemName": "area_3_is_failure_new",
+    "imageName": "loser_sign_2.png",
+    "roiFront": "665,283,73,40",
+    "roiBack": "419,261,327,137",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域3攻略失败(最近一次)"
+  },
+  {
+    "itemName": "area_4_is_failure_new",
+    "imageName": "loser_sign_2.png",
+    "roiFront": "1000,283,72,38",
+    "roiBack": "756,258,325,141",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区4攻略失败(最近一次)"
+  },
+  {
+    "itemName": "area_5_is_failure_new",
+    "imageName": "loser_sign_2.png",
+    "roiFront": "669,419,65,29",
+    "roiBack": "418,394,328,140",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域5攻略失败(最近一次)"
+  },
+  {
+    "itemName": "area_6_is_failure_new",
+    "imageName": "loser_sign_2.png",
+    "roiFront": "988,416,84,37",
+    "roiBack": "755,395,328,141",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域6攻略失败(最近一次)"
+  },
+  {
+    "itemName": "area_7_is_failure_new",
+    "imageName": "loser_sign_2.png",
+    "roiFront": "672,556,61,37",
+    "roiBack": "420,533,326,124",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域7攻略失败(最近一次)"
+  },
+  {
+    "itemName": "area_8_is_failure_new",
+    "imageName": "loser_sign_2.png",
+    "roiFront": "1004,556,64,29",
+    "roiBack": "756,532,327,122",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域8攻略失败(最近一次)"
+  }
+]

+ 146 - 0
tasks/RyouToppa/dev/finished.json

@@ -0,0 +1,146 @@
+[
+  {
+    "itemName": "area_1_finished",
+    "imageName": "finished_1.png",
+    "roiFront": "658,141,93,91",
+    "roiBack": "421,127,325,134",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域1已攻破"
+  },
+  {
+    "itemName": "area_2_finished",
+    "imageName": "finished_1.png",
+    "roiFront": "983,137,100,100",
+    "roiBack": "757,125,327,140",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域2已攻破"
+  },
+  {
+    "itemName": "area_3_finished",
+    "imageName": "finished_1.png",
+    "roiFront": "681,312,47,37",
+    "roiBack": "419,254,327,144",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域3已攻破"
+  },
+  {
+    "itemName": "area_4_finished",
+    "imageName": "finished_1.png",
+    "roiFront": "996,271,100,100",
+    "roiBack": "756,260,325,139",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域4已攻破"
+  },
+  {
+    "itemName": "area_5_finished",
+    "imageName": "finished_1.png",
+    "roiFront": "647,404,100,100",
+    "roiBack": "418,392,328,142",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域5已攻破"
+  },
+  {
+    "itemName": "area_6_finished",
+    "imageName": "finished_1.png",
+    "roiFront": "1015,448,56,35",
+    "roiBack": "755,395,328,141",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域6已攻破"
+  },
+  {
+    "itemName": "area_7_finished",
+    "imageName": "finished_1.png",
+    "roiFront": "643,543,100,100",
+    "roiBack": "420,530,326,127",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域7已攻破"
+  },
+  {
+    "itemName": "area_8_finished",
+    "imageName": "finished_1.png",
+    "roiFront": "983,541,100,100",
+    "roiBack": "756,530,327,124",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域8已攻破"
+  },
+  {
+    "itemName": "area_1_finished_new",
+    "imageName": "finished_2.png",
+    "roiFront": "658,141,93,91",
+    "roiBack": "421,127,325,134",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域1已攻破新"
+  },
+  {
+    "itemName": "area_2_finished_new",
+    "imageName": "finished_2.png",
+    "roiFront": "983,137,100,100",
+    "roiBack": "757,125,327,140",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域2已攻破新"
+  },
+  {
+    "itemName": "area_3_finished_new",
+    "imageName": "finished_2.png",
+    "roiFront": "681,312,47,37",
+    "roiBack": "419,254,327,144",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域3已攻破新"
+  },
+  {
+    "itemName": "area_4_finished_new",
+    "imageName": "finished_2.png",
+    "roiFront": "996,271,100,100",
+    "roiBack": "756,260,325,139",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域4已攻破新"
+  },
+  {
+    "itemName": "area_5_finished_new",
+    "imageName": "finished_2.png",
+    "roiFront": "647,404,100,100",
+    "roiBack": "418,392,328,142",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域5已攻破新"
+  },
+  {
+    "itemName": "area_6_finished_new",
+    "imageName": "finished_2.png",
+    "roiFront": "1015,448,56,35",
+    "roiBack": "755,395,328,141",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域6已攻破新"
+  },
+  {
+    "itemName": "area_7_finished_new",
+    "imageName": "finished_2.png",
+    "roiFront": "643,543,100,100",
+    "roiBack": "420,530,326,127",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域7已攻破新"
+  },
+  {
+    "itemName": "area_8_finished_new",
+    "imageName": "finished_2.png",
+    "roiFront": "983,541,100,100",
+    "roiBack": "756,530,327,124",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域8已攻破新"
+  }
+]

二進制
tasks/RyouToppa/dev/finished_1.png


二進制
tasks/RyouToppa/dev/finished_2.png


+ 29 - 0
tasks/RyouToppa/dev/image.json

@@ -0,0 +1,29 @@
+[
+  {
+    "itemName": "toppa_record",
+    "imageName": "res_toppa_record.png",
+    "roiFront": "66,628,64,39",
+    "roiBack": "66,628,64,39",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "toppa_lock_team",
+    "imageName": "dev_toppa_lock_team.png",
+    "roiFront": "201,601,30,36",
+    "roiBack": "201,601,30,36",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "toppa_unlock_team",
+    "imageName": "dev_toppa_unlock_team.png",
+    "roiFront": "199,603,31,31",
+    "roiBack": "199,603,31,31",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

二進制
tasks/RyouToppa/dev/loser_sign_1.png


二進制
tasks/RyouToppa/dev/loser_sign_2.png


二進制
tasks/RyouToppa/dev/res_toppa_record.png


+ 156 - 86
tasks/RyouToppa/script_task.py

@@ -2,21 +2,77 @@
 # @author runhey
 # github https://github.com/runhey
 import time
+from datetime import datetime, timedelta
+from random import random
 
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.RyouToppa.assets import RyouToppaAssets
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.config_base import ConfigBase, Time
 from tasks.GameUi.game_ui import GameUi
 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
 from module.atom.image_grid import ImageGrid
+from module.base.utils import point2str
 from module.base.timer import Timer
 from module.exception import GamePageUnknownError
-from tasks.RyouToppa.config import RaidMode, AttackNumber, HaveManageAccess, RaidConfig, RyouToppa
 
 
+
+area_map = (
+    {
+        "fail_sign": (RyouToppaAssets.I_AREA_1_IS_FAILURE_NEW, RyouToppaAssets.I_AREA_1_IS_FAILURE),
+        "rule_click": RyouToppaAssets.C_AREA_1,
+        "finished_sign": (RyouToppaAssets.I_AREA_1_FINISHED, RyouToppaAssets.I_AREA_1_FINISHED_NEW)
+    },
+    {
+        "fail_sign": (RyouToppaAssets.I_AREA_2_IS_FAILURE_NEW, RyouToppaAssets.I_AREA_2_IS_FAILURE),
+        "rule_click": RyouToppaAssets.C_AREA_2,
+        "finished_sign": (RyouToppaAssets.I_AREA_2_FINISHED, RyouToppaAssets.I_AREA_2_FINISHED_NEW)
+    },
+    {
+        "fail_sign": (RyouToppaAssets.I_AREA_3_IS_FAILURE_NEW, RyouToppaAssets.I_AREA_3_IS_FAILURE),
+        "rule_click": RyouToppaAssets.C_AREA_3,
+        "finished_sign": (RyouToppaAssets.I_AREA_3_FINISHED, RyouToppaAssets.I_AREA_3_FINISHED_NEW)
+    },
+    {
+        "fail_sign": (RyouToppaAssets.I_AREA_4_IS_FAILURE_NEW, RyouToppaAssets.I_AREA_4_IS_FAILURE),
+        "rule_click": RyouToppaAssets.C_AREA_4,
+        "finished_sign": (RyouToppaAssets.I_AREA_4_FINISHED, RyouToppaAssets.I_AREA_4_FINISHED_NEW)
+    },
+    {
+        "fail_sign": (RyouToppaAssets.I_AREA_5_IS_FAILURE_NEW, RyouToppaAssets.I_AREA_5_IS_FAILURE),
+        "rule_click": RyouToppaAssets.C_AREA_5,
+        "finished_sign": (RyouToppaAssets.I_AREA_5_FINISHED, RyouToppaAssets.I_AREA_5_FINISHED_NEW)
+    },
+    {
+        "fail_sign": (RyouToppaAssets.I_AREA_6_IS_FAILURE_NEW, RyouToppaAssets.I_AREA_6_IS_FAILURE),
+        "rule_click": RyouToppaAssets.C_AREA_6,
+        "finished_sign": (RyouToppaAssets.I_AREA_6_FINISHED, RyouToppaAssets.I_AREA_6_FINISHED_NEW)
+    },
+    {
+        "fail_sign": (RyouToppaAssets.I_AREA_7_IS_FAILURE_NEW, RyouToppaAssets.I_AREA_7_IS_FAILURE),
+        "rule_click": RyouToppaAssets.C_AREA_7,
+        "finished_sign": (RyouToppaAssets.I_AREA_7_FINISHED, RyouToppaAssets.I_AREA_7_FINISHED_NEW)
+    },
+    {
+        "fail_sign": (RyouToppaAssets.I_AREA_8_IS_FAILURE_NEW, RyouToppaAssets.I_AREA_8_IS_FAILURE),
+        "rule_click": RyouToppaAssets.C_AREA_8,
+        "finished_sign": (RyouToppaAssets.I_AREA_8_FINISHED, RyouToppaAssets.I_AREA_8_FINISHED_NEW)
+    }
+)
+
+
+def random_delay(min_value: float = 1.0, max_value: float = 2.0, decimal: int = 1):
+    """
+    生成一个指定范围内的随机小数
+    """
+    random_float_in_range = random.uniform(min_value, max_value)
+    return (round(random_float_in_range, decimal))
+
 class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
     medal_grid: ImageGrid = None
 
@@ -26,6 +82,8 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
         :return:
         """
         ryou_config = self.config.ryou_toppa
+        time_limit: Time = ryou_config.raid_config.limit_time
+        time_delta = timedelta(hours=time_limit.hour, minutes=time_limit.minute, seconds=time_limit.second)
         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])
 
@@ -47,11 +105,9 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
         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(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):
@@ -68,7 +124,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
                 break
 
         # 寮突未开 并且有权限, 开开寮突
-        if not ryou_toppa_start_flag and ryou_config.raid_config.ryou_access == 'yes':
+        if not ryou_toppa_start_flag and ryou_config.raid_config.ryou_access:
             # 开寮突
             self.start_ryou_toppa()
 
@@ -76,19 +132,45 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
         if ryou_toppa_success_penetration:
             self.set_next_run(task='RyouToppa', finish=True, success=True)
             raise TaskEnd
-
+        if self.config.ryou_toppa.general_battle_config.lock_team_enable:
+            self.ui_click(self.I_TOPPA_UNLOCK_TEAM, self.I_TOPPA_LOCK_TEAM)
+        else:
+            self.ui_click(self.I_TOPPA_LOCK_TEAM, self.I_TOPPA_UNLOCK_TEAM)
+        # --------------------------------------------------------------------------------------------------------------
         # 开始突破
+        # --------------------------------------------------------------------------------------------------------------
+        area_index = 0
+        success = True
         while 1:
-            if self.execute_round():
-                continue
-            else:
+            if not self.has_ticket():
+                logger.info("We have no chance to attack. Try again after 1 hour.")
+                success = False
+                break
+            if self.current_count >= ryou_config.raid_config.limit_count:
+                logger.warning("We have attacked the limit count.")
                 break
+            if datetime.now() >= self.start_time + time_delta:
+                logger.warning("We have attacked the limit time.")
+                break
+            # 进攻
+            res = self.attack_area(area_index)
+            # 如果战斗失败或区域不可用,则弹出当前区域索引,开始进攻下一个
+            if not res:
+                area_index += 1
+                if area_index >= len(area_map):
+                    logger.warning('All areas are not available, it will flush the area cache')
+                    area_index = 0
+                    self.flush_area_cache()
+                continue
+
 
         # 回 page_main 失败
         # self.ui_current = page_ryou_toppa
         # self.ui_goto(page_main)
-
-        self.set_next_run(task='RyouToppa', finish=True, server=False, success=True)
+        if success:
+            self.set_next_run(task='RyouToppa', finish=True, server=False, success=True)
+        else:
+            self.set_next_run(task='RyouToppa', finish=True, server=False, success=False)
         raise TaskEnd
 
     def start_ryou_toppa(self):
@@ -120,103 +202,91 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
                 break
         logger.info(f'Click {self.I_START_TOPPA_BUTTON.name}')
 
-    def is_ticket(self) -> bool:
+    def has_ticket(self) -> bool:
         """
         如果没有票了,那么就返回False
         :return:
         """
-        self.wait_until_appear(RealmRaidAssets.I_BACK_RED)
+        # 21点后无限进攻机会
+        if datetime.now().hour >= 21:
+            return True
+        self.wait_until_appear(self.I_TOPPA_RECORD)
         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')
+            logger.warning(f'Execute round failed, no ticket')
             return False
         return True
 
-    def medal_fire(self):
+    def check_area(self, index: int) -> bool:
         """
-        点击勋章
+        检查该区域是否攻略失败
         :return:
         """
-        # 点击勋章的挑战 和挑战
-        time.sleep(0.2)
-        is_click = False
-        while 1:
-            self.screenshot()
-            if self.appear(RealmRaidAssets.I_FIRE, threshold=0.8):
-                break
-
-            if self.appear_then_click(RealmRaidAssets.I_SOUL_RAID, interval=1.5):
-                while 1:
-                    self.screenshot()
-                    if self.appear_then_click(RealmRaidAssets.I_SOUL_RAID, interval=1.5):
-                        continue
-                    if not self.appear(RealmRaidAssets.I_SOUL_RAID, threshold=0.6):
-                        break
-                continue
-
-            target = self.medal_grid.find_anyone(self.device.image)
-            if target:
-                self.appear_then_click(target, interval=2)  # 点击勋章,但是设置为两秒的间隔,适应不同的模拟器速度
-                is_click = not is_click
-
-            if is_click:
-                continue
-        logger.info(f'Click Medal')
-
-        # 点击挑战
-        self.wait_until_appear(RealmRaidAssets.I_FIRE)
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(RealmRaidAssets.I_FIRE, interval=2):
-                continue
-            if not self.appear(RealmRaidAssets.I_FIRE, threshold=0.8):
-                break
-        logger.info(f'Click {RealmRaidAssets.I_FIRE.name}')
+        f1, f2 = area_map[index].get("fail_sign")
+        f3, f4 = area_map[index].get("finished_sign")
+        self.screenshot()
+        # 如果该区域已经被攻破则退出
+        # Ps: 这时候能打过的都打过了,没有能攻打的结界了, 代表任务已经完成,set_next_run time=1d
+        if self.appear(f3, threshold=0.8) or self.appear(f4, threshold=0.8):
+            self.set_next_run(task='DevRyouToppa', finish=True, success=True)
+            raise TaskEnd
+        # 如果该区域攻略失败返回 False
+        if self.appear(f1, threshold=0.8) or self.appear(f2, threshold=0.8):
+            logger.info('Area [%s] is futile attack, skip.' % str(index + 1))
+            return False
+        return True
 
-    def execute_round(self) -> bool:
+    def flush_area_cache(self):
+        time.sleep(2)
+        duration = 0.352
+        count = random.randint(1, 3)
+        for i in range(count):
+            # 测试过很多次 win32api, win32gui 的 MOUSEEVENTF_WHEEL, WM_MOUSEWHEEL
+            # 都出现过很多次离奇的事件,索性放弃了使用以下方法,参数是精心调试的
+            # 每次执行刚好刷新一组(2个)设定随机刷新 1 - 3 次
+            safe_pos_x = random.randint(540, 1000)
+            safe_pos_y = random.randint(320, 540)
+            p1 = (safe_pos_x, safe_pos_y)
+            p2 = (safe_pos_x, safe_pos_y - 101)
+            logger.info('Swipe %s -> %s, %s ' % (point2str(*p1), point2str(*p2), duration))
+            self.device.swipe_adb(p1, p2, duration=duration)
+            time.sleep(2)
+    def attack_area(self, index: int):
         """
-        执行一轮 除非票不够,一直到到九次
-        :return:
+        :return: 战斗成功(True) or 战斗失败(False) or 区域不可用(False) or 没有进攻机会(设定下次运行并退出)
         """
-        ryou_config = self.config.ryou_toppa
-        # 如果没有票了,就退出
-        if not self.is_ticket():
-            return False
-        if not self.is_target_available():
+        # 每次进攻前检查区域可用性
+        if not self.check_area(index):
             return False
 
+        # 正式进攻会设定 2s - 10s 的随机延迟,避免攻击间隔及其相近被检测为脚本。
+        if self.config.ryou_toppa.raid_config.random_delay:
+            delay = random_delay()
+            time.sleep(delay)
 
-        # 打20次
-        for i in range(30):
-            if not self.is_ticket():
-                return False
-            if not self.is_target_available():
-                return False
-            self.medal_fire()
-            self.run_general_battle(ryou_config.general_battle_config)
-            self.wait_until_appear(RealmRaidAssets.I_BACK_RED)
 
-        return True
+        rcl = area_map[index].get("rule_click")
+        # 点击攻击区域,等待攻击按钮出现。
+        self.ui_click(rcl, stop=RealmRaidAssets.I_FIRE, interval=2)
+        # 塔塔开!
+        click_failure_count = 0
+        while True:
+            self.screenshot()
+            if click_failure_count >= 3:
+                logger.warning("Click failure, check your click position")
+                return False
+            if not self.appear(self.I_TOPPA_RECORD, threshold=0.85):
+                time.sleep(1)
+                self.screenshot()
+                if self.appear(self.I_TOPPA_RECORD, threshold=0.85):
+                    continue
+                logger.info("Start attach area [%s]" % str(index + 1))
+                return self.run_general_battle(config=self.config.ryou_toppa.general_battle_config)
 
-    # 判断是否还有可进攻的目标
-    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
+            if self.appear_then_click(RealmRaidAssets.I_FIRE, interval=2, threshold=0.8):
+                click_failure_count += 1
+                continue
 
 
 if __name__ == "__main__":