Jelajahi Sumber

doc[(your part)]: Finished Task.DevRyouToppa(2023.11.25)
feat[(module name)]: Task.DevRyouToppa
perf[(module name)]: None
fix[(module name)]: None

zhaiyujia 3 tahun lalu
induk
melakukan
7bc9b5e82c

+ 42 - 0
tasks/DevRyouToppa/assets.py

@@ -10,6 +10,25 @@ from module.atom.list import RuleList
 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")
+	# 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")
+
+
 	# Image Rule Assets
 	# 区域1攻略失败 
 	I_AREA_1_IS_FAILURE = RuleImage(roi_front=(673,146,63,32), roi_back=(421,138,325,123), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/loser_sign_2.png")
@@ -43,5 +62,28 @@ class DevRyouToppaAssets:
 	I_AREA_7_IS_FAILURE_NEW = RuleImage(roi_front=(672,556,61,37), roi_back=(420,543,326,114), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/loser_sign_1.png")
 	# 区域8攻略失败(最近一次) 
 	I_AREA_8_IS_FAILURE_NEW = RuleImage(roi_front=(1004,556,64,29), roi_back=(756,541,327,113), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/loser_sign_1.png")
+	# 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/DevRyouToppa/res/res_toppa_record.png")
+	# 区域1已攻破 
+	I_AREA_1_FINISHED = RuleImage(roi_front=(658,141,93,91), roi_back=(658,141,93,91), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/finished.png")
+	# 区域2已攻破 
+	I_AREA_2_FINISHED = RuleImage(roi_front=(983,137,100,100), roi_back=(983,137,100,100), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/finished.png")
+	# 区域3已攻破 
+	I_AREA_3_FINISHED = RuleImage(roi_front=(650,270,100,100), roi_back=(650,270,100,100), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/finished.png")
+	# 区域4已攻破 
+	I_AREA_4_FINISHED = RuleImage(roi_front=(996,271,100,100), roi_back=(996,271,100,100), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/finished.png")
+	# 区域5已攻破 
+	I_AREA_5_FINISHED = RuleImage(roi_front=(647,404,100,100), roi_back=(647,404,100,100), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/finished.png")
+	# 区域6已攻破 
+	I_AREA_6_FINISHED = RuleImage(roi_front=(982,403,100,100), roi_back=(982,403,100,100), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/finished.png")
+	# 区域7已攻破 
+	I_AREA_7_FINISHED = RuleImage(roi_front=(643,543,100,100), roi_back=(643,543,100,100), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/finished.png")
+	# 区域8已攻破 
+	I_AREA_8_FINISHED = RuleImage(roi_front=(983,541,100,100), roi_back=(983,541,100,100), threshold=0.8, method="Template matching", file="./tasks/DevRyouToppa/res/finished.png")
+
+
+	# Ocr Rule Assets
+	# 进攻回合数 
+	O_NUMBER = RuleOcr(roi=(271,560,48,31), area=(271,560,48,31), mode="DigitCounter", method="Default", keyword="", name="number")
 
 

+ 50 - 0
tasks/DevRyouToppa/res/click.json

@@ -0,0 +1,50 @@
+[
+  {
+    "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"
+  }
+]

TEMPAT SAMPAH
tasks/DevRyouToppa/res/finished.png


+ 81 - 0
tasks/DevRyouToppa/res/image.json

@@ -142,5 +142,86 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "区域8攻略失败(最近一次)"
+  },
+  {
+    "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": "area_1_finished",
+    "imageName": "finished.png",
+    "roiFront": "658,141,93,91",
+    "roiBack": "658,141,93,91",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域1已攻破"
+  },
+  {
+    "itemName": "area_2_finished",
+    "imageName": "finished.png",
+    "roiFront": "983,137,100,100",
+    "roiBack": "983,137,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域2已攻破"
+  },
+  {
+    "itemName": "area_3_finished",
+    "imageName": "finished.png",
+    "roiFront": "650,270,100,100",
+    "roiBack": "650,270,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域3已攻破"
+  },
+  {
+    "itemName": "area_4_finished",
+    "imageName": "finished.png",
+    "roiFront": "996,271,100,100",
+    "roiBack": "996,271,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域4已攻破"
+  },
+  {
+    "itemName": "area_5_finished",
+    "imageName": "finished.png",
+    "roiFront": "647,404,100,100",
+    "roiBack": "647,404,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域5已攻破"
+  },
+  {
+    "itemName": "area_6_finished",
+    "imageName": "finished.png",
+    "roiFront": "982,403,100,100",
+    "roiBack": "982,403,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域6已攻破"
+  },
+  {
+    "itemName": "area_7_finished",
+    "imageName": "finished.png",
+    "roiFront": "643,543,100,100",
+    "roiBack": "643,543,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域7已攻破"
+  },
+  {
+    "itemName": "area_8_finished",
+    "imageName": "finished.png",
+    "roiFront": "983,541,100,100",
+    "roiBack": "983,541,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "区域8已攻破"
   }
 ]

+ 11 - 0
tasks/DevRyouToppa/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": "进攻回合数"
+  }
+]

TEMPAT SAMPAH
tasks/DevRyouToppa/res/res_new.png


TEMPAT SAMPAH
tasks/DevRyouToppa/res/res_toppa_record.png


+ 111 - 33
tasks/DevRyouToppa/script_task.py

@@ -1,9 +1,10 @@
 # This Python file uses the following encoding: utf-8
 
 import time
-
+import random
+from datetime import datetime
+from module.base.utils import point2str
 from module.exception import TaskEnd
-from tasks.Component.GeneralBattle.assets import GeneralBattleAssets
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.GameUi.game_ui import GameUi
@@ -19,39 +20,55 @@ default_index = [0, 1, 2, 3, 4, 5, 6, 7]
 area_map = (
     {
         "fail_sign": (DevRyouToppaAssets.I_AREA_1_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_1_IS_FAILURE),
-        "rule_click": None
+        "rule_click": DevRyouToppaAssets.C_AREA_1,
+        "finished_sign": DevRyouToppaAssets.I_AREA_1_FINISHED
     },
     {
         "fail_sign": (DevRyouToppaAssets.I_AREA_2_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_2_IS_FAILURE),
-        "rule_click": None
+        "rule_click": DevRyouToppaAssets.C_AREA_2,
+        "finished_sign": DevRyouToppaAssets.I_AREA_2_FINISHED
     },
     {
         "fail_sign": (DevRyouToppaAssets.I_AREA_3_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_3_IS_FAILURE),
-        "rule_click": None
+        "rule_click": DevRyouToppaAssets.C_AREA_3,
+        "finished_sign": DevRyouToppaAssets.I_AREA_3_FINISHED
     },
     {
         "fail_sign": (DevRyouToppaAssets.I_AREA_4_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_4_IS_FAILURE),
-        "rule_click": None
+        "rule_click": DevRyouToppaAssets.C_AREA_4,
+        "finished_sign": DevRyouToppaAssets.I_AREA_4_FINISHED
     },
     {
         "fail_sign": (DevRyouToppaAssets.I_AREA_5_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_5_IS_FAILURE),
-        "rule_click": None
+        "rule_click": DevRyouToppaAssets.C_AREA_5,
+        "finished_sign": DevRyouToppaAssets.I_AREA_5_FINISHED
     },
     {
         "fail_sign": (DevRyouToppaAssets.I_AREA_6_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_6_IS_FAILURE),
-        "rule_click": None
+        "rule_click": DevRyouToppaAssets.C_AREA_6,
+        "finished_sign": DevRyouToppaAssets.I_AREA_6_FINISHED
     },
     {
         "fail_sign": (DevRyouToppaAssets.I_AREA_7_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_7_IS_FAILURE),
-        "rule_click": None
+        "rule_click": DevRyouToppaAssets.C_AREA_7,
+        "finished_sign": DevRyouToppaAssets.I_AREA_7_FINISHED
     },
     {
         "fail_sign": (DevRyouToppaAssets.I_AREA_8_IS_FAILURE_NEW, DevRyouToppaAssets.I_AREA_8_IS_FAILURE),
-        "rule_click": None
+        "rule_click": DevRyouToppaAssets.C_AREA_8,
+        "finished_sign": DevRyouToppaAssets.I_AREA_8_FINISHED
     }
 )
 
 
+def random_delay(min_value: float = 2.0, max_value: float = 10.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, DevRyouToppaAssets):
     medal_grid: ImageGrid = None
     area_index: list = []
@@ -61,53 +78,82 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
         执行
         :return:
         """
-        # options = self.config.dev_ryou_toppa
+
+        options = self.config.dev_ryou_toppa
         self.ui_get_current_page()
         self.ui_goto(page_kekkai_toppa)
 
         # 判断阴阳寮是否攻破
         while True:
             self.screenshot()
-            if self.appear(RyouToppaAssets.I_RYOU_REWARD_90, threshold=0.8, interval=1):
+            if self.appear(RyouToppaAssets.I_RYOU_REWARD_90, threshold=0.8):
                 self.exit()
-            if self.appear(RyouToppaAssets.I_RYOU_REWARD, threshold=0.8, interval=1):
+            if self.appear(RyouToppaAssets.I_RYOU_REWARD, threshold=0.8):
                 break
 
         if not self.area_index:
             self.area_index.extend(default_index)
 
-        # 判断突破区域
+        index = self.get_available_area()
+
+        # 开始突破
+        while True:
+            win = self.attack_area(index)
+            delay = random_delay()
+            time.sleep(delay)
+            if not win:
+                try:
+                    idx = self.area_index.index(index)
+                    index = self.area_index[idx + 1]
+                except IndexError:
+                    self.flush_area_cache()
+                    index = self.get_available_area()
+
+    def get_available_area(self):
+        """
+        判断突破区域(忽略失败的目标)
+        :return: index
+        """
         while True:
             try:
-                idx = self.area_index[0]
-                if self.check_area(idx):
-                    break
+                index = self.area_index[0]
+                if self.check_area(index):
+                    return index
                 self.area_index.pop(0)
             except IndexError:
                 # 如果当前页面所有结界都攻破失败,则刷新结界列表。
-                # TO-DO: 需要鼠标中键滑动接口(随机滑动,步长为2)
                 self.flush_area_cache()
 
-        # 开始突破
-        while True:
-            result = self.attack_area(idx)
-
     def check_area(self, index: int):
         """
         检查该区域是否攻略失败
         :return:
         """
         f1, f2 = area_map[index].get("fail_sign")
+        f3 = area_map[index].get("finished_sign")
         self.screenshot()
+        # 如果该区域已经被攻破则退出
+        # Ps: 这时候能打过的都打过了,没有能攻打的结界了
+        if self.appear(f3):
+            self.exit()
+
+        # 如果该区域攻略失败返回 False
         if self.appear(f1, threshold=0.8) or self.appear(f2, threshold=0.8):
-            logger.info('Area [%s] is futile attack, skip.' % index + 1)
+            logger.info('Area [%s] is futile attack, skip.' % str(index + 1))
             return False
         return True
 
     def attack_area(self, index: int):
+        """
+        检查该区域是否攻略失败
+        :return: 战斗成功(True) 或 战斗失败(False)
+        """
+        while True:
+            if self.has_ticket():
+                break
+            time.sleep(60)
         self.screenshot()
-        # TO-DO: 需要更改过程标识
-        if not self.appear(RyouToppaAssets.I_RYOU_TOPPA, threshold=0.8):
+        if not self.appear(self.I_TOPPA_RECORD, threshold=0.8):
             raise Exception("Current page is not RyouToppa.")
         rcl = area_map[index].get("rule_click")
 
@@ -123,13 +169,19 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
         while True:
             self.screenshot()
             # 如果进入战斗
-            if self.appear():
-                logger.info("Start attach area [%s]" % index + 1)
+            if self.appear(self.I_EXIT, threshold=0.8):
+                logger.info("Start attach area [%s]" % str(index + 1))
                 break
-            # 如果该结界已经被攻打过(未刷新)则返回攻打失败
-            if self.ocr_appear():
-                return False
-            if self.appear_then_click(RealmRaidAssets.I_FIRE, threshold=0.8, interval=1.5):
+            if self.appear_then_click(RealmRaidAssets.I_FIRE, threshold=0.8):
+                time.sleep(1.5)
+                self.screenshot()
+                self.appear_then_click(RealmRaidAssets.I_FIRE, threshold=0.8)
+                time.sleep(1.5)
+                self.screenshot()
+                # 点击两次点击后如果还出现进攻按钮则判断该区域已被攻打过
+                # 不使用 ocr 的原因是怕不好识别导致重复点击被检测
+                if self.appear(RealmRaidAssets.I_FIRE):
+                    return False
                 continue
 
         # 等待战斗结束
@@ -137,8 +189,18 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
         return self.battle_wait(random_click_swipt_enable=True)
 
     def flush_area_cache(self):
+        time.sleep(2)
         self.area_index.extend(default_index)
-        pass
+        duration = 0.352
+        count = random.randint(1, 3)
+        for i in range(count):
+            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 exit(self, status: int = 0):
         if status == 0:
@@ -172,12 +234,28 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, DevRyouToppaAssets):
                 self.ui_click_until_disappear(self.I_FALSE)
                 return False
 
+    def has_ticket(self) -> bool:
+        """
+        如果没有票了,那么就返回False
+        :return:
+        """
+        # 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)
+        if cu == 0 and cu + res == total:
+            logger.warning(f'Execute round failed, no ticket')
+            return False
+        return True
+
 
 if __name__ == "__main__":
     from module.config.config import Config
     from module.device.device import Device
 
-    config = Config('oas1')
+    config = Config('oas2')
     device = Device(config)
     t = ScriptTask(config, device)
     t.run()