Selaa lähdekoodia

feat(tasks): AreaBoss completed!

runhey 3 vuotta sitten
vanhempi
sitoutus
eea13ee191

+ 5 - 1
module/atom/click.py

@@ -8,7 +8,7 @@ from module.logger import logger
 
 class RuleClick:
 
-    def __init__(self, roi_front: tuple, roi_back: tuple) -> None:
+    def __init__(self, roi_front: tuple, roi_back: tuple, name: str=None) -> None:
         """
         初始化
         :param roi_front:
@@ -16,6 +16,10 @@ class RuleClick:
         """
         self.roi_front = roi_front
         self.roi_back = roi_back
+        if name:
+            self.name = name
+        else:
+            self.name = 'click'
 
     def coord(self) -> tuple:
         """

+ 1 - 1
module/atom/image.py

@@ -63,7 +63,7 @@ class RuleImage:
         if self._image is not None:
             return
         img = cv2.imdecode(fromfile(self.file, dtype=uint8), -1)
-        # self._image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
+        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
         self._image = img
 
         height, width, channels = self._image.shape

+ 4 - 2
module/atom/long_click.py

@@ -10,14 +10,16 @@ from module.atom.click import RuleClick
 
 class RuleLongClick(RuleClick):
 
-    def __init__(self, roi_front: tuple, roi_back: tuple, duration: int = 1000) -> None:
+    def __init__(self, roi_front: tuple, roi_back: tuple, duration: int = 1000, name: str=None) -> None:
         """
         初始化
         :param roi_front:
         :param roi_back:
         :param duration:
         """
-        super().__init__(roi_front, roi_back)
+        if not name:
+            name = 'long_click'
+        super().__init__(roi_front, roi_back, name=name)
         self.duration = duration
 
 

+ 5 - 1
module/atom/swipe.py

@@ -13,7 +13,7 @@ from module.logger import logger
 
 class RuleSwipe:
 
-    def __init__(self, roi_front: tuple, roi_back: tuple, mode: str) -> None:
+    def __init__(self, roi_front: tuple, roi_back: tuple, mode: str, name: str =None) -> None:
         """
         初始化
         :param roi_front:
@@ -23,6 +23,10 @@ class RuleSwipe:
         self.roi_front = roi_front
         self.roi_back = roi_back
         self.mode = mode
+        if name:
+            self.name = name
+        else:
+            self.name = 'swipe'
 
         self.interval: int = 8  # 每次移动的间隔时间
 

+ 24 - 12
module/dev_tools/assets_extract.py

@@ -4,7 +4,7 @@
 import json
 import numpy as np
 
-# from tqdm.contrib.concurrent import process_map
+from tqdm.contrib.concurrent import process_map
 from pathlib import Path
 
 from module.logger import logger
@@ -97,7 +97,8 @@ class ClickExtractor:
         description: str = f'\t# {item["description"]} \n'
         name: str = f'\tC_{name_transform(item["itemName"])} = RuleClick(' \
                     f'roi_front=({item["roiFront"]}), ' \
-                    f'roi_back=({item["roiBack"]}))\n'
+                    f'roi_back=({item["roiBack"]}), ' \
+                    f'name="{item["itemName"]}")\n'
         return description + name
 
 class LongClickExtractor:
@@ -125,7 +126,8 @@ class LongClickExtractor:
         name: str = f'\tL_{name_transform(item["itemName"])} = RuleLongClick(' \
                     f'roi_front=({item["roiFront"]}), ' \
                     f'roi_back=({item["roiBack"]}), ' \
-                    f'duration={item["duration"]})\n'
+                    f'duration={item["duration"]}, ' \
+                    f'name="{item["itemName"]}")\n'
         return description + name
 
 class SwipeExtractor:
@@ -153,7 +155,8 @@ class SwipeExtractor:
         name: str = f'\tS_{name_transform(item["itemName"])} = RuleSwipe(' \
                     f'roi_front=({item["roiFront"]}), ' \
                     f'roi_back=({item["roiBack"]}), ' \
-                    f'mode="{item["mode"]}")\n'
+                    f'mode="{item["mode"]}", ' \
+                    f'name="{item["itemName"]}")\n'
         return description + name
 
 
@@ -274,14 +277,23 @@ class AssetsExtractor:
 
 
 class AllAssetsExtractor:
-    pass
+    def __init__(self):
+        """
+        获取./tasks目录下的所有任务文件夹,遍历每一个任务文件夹提取assets
+        """
+        logger.info('All assets extract')
+        self.task_path = Path.cwd() / MODULE_FOLDER
+        self.task_list = [x.name for x in self.task_path.iterdir() if x.is_dir()]
+        process_map(self.work, self.task_list, max_workers=4)
+
+    @staticmethod
+    def work(task_name: str):
+        me = AssetsExtractor(task_name)
+        me.extract()
 
 
-if __name__ == "__main__":
-    c = AssetsExtractor('GeneralBattle')
-    # c = AssetsExtractor('AreaBoss')
-    # print(c.assets_file)
-    # print(c.task_path)
-    # print(c.all_json_file())
 
-    c.extract()
+if __name__ == "__main__":
+    # c = AssetsExtractor('GeneralBattle')
+    # c.extract()
+    AllAssetsExtractor()

+ 1 - 1
module/device/app_control.py

@@ -12,7 +12,7 @@ class AppControl(Adb, Uiautomator2):
     _app_u2_family = ['uiautomator2', 'minitouch', 'scrcpy']
 
     def app_is_running(self) -> bool:
-        method = self.config.script.emulator.control_method
+        method = self.config.script.device.control_method
         # if self.is_wsa:
         #     package = self.app_current_wsa()
         if method in AppControl._app_u2_family:

+ 3 - 3
module/device/method/window.py

@@ -136,19 +136,19 @@ class Window(Handle):
         emulator_type = len(self.control_handle_list)
         if emulator_type == 2:  # mumu模拟器
             SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
-            time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            time.sleep((random.randint(200, 400)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
             SendMessage(self.control_handle_list[1], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
         elif emulator_type > 2:  # 夜神模拟器
             SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, MAKELONG(x, y))  # 模拟鼠标按下 先是父窗口 上面的框高度是57
             SendMessage(self.control_handle_list[1], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[2], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
             SendMessage(self.control_handle_list[3], WM_LBUTTONDOWN, 0, MAKELONG(x, y))
-            time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            time.sleep((random.randint(200, 400)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
             SendMessage(self.control_handle_list[3], WM_LBUTTONUP, 0, MAKELONG(x, y))  # 模拟鼠标弹起 后是子窗口
         elif emulator_type == 1:  # 雷电模拟器
             clickPos = MAKELONG(x, y)
             SendMessage(self.control_handle_list[0], WM_LBUTTONDOWN, 0, clickPos)  # 模拟鼠标按下
-            time.sleep((random.randint(100, 200)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
+            time.sleep((random.randint(200, 400)) / 1000.0)  # 点击弹起改为随机,时间100ms-200ms
             SendMessage(self.control_handle_list[0], WM_LBUTTONUP, 0, clickPos)  # 模拟鼠标弹起
 
     def long_click_window_message(self, x: int, y: int, duration: float):

+ 2 - 1
requirements-in.txt

@@ -12,4 +12,5 @@ pywin32==306
 zerorpc==0.6.3
 wrapt==1.15.0
 pydantic==1.10.7
-inflection==0.5.1
+inflection==0.5.1
+tqdm==4.65.0

+ 1 - 1
tasks/AreaBoss/assets.py

@@ -13,7 +13,7 @@ class AreaBossAssets:
 	# 地狱鬼王图标 
 	I_AREA_BOSS = RuleImage(roi_front=(639,636,65,68), roi_back=(606,619,145,100), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_area_boss.png")
 	# 蓝色的返回 
-	I_BACK_BLUE = RuleImage(roi_front=(43,30,51,52), roi_back=(43,30,51,52), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_back_blue.png")
+	I_BACK_BLUE = RuleImage(roi_front=(51,30,51,52), roi_back=(4,1,128,110), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_back_blue.png")
 	# 右上边选中鬼王的 
 	I_FILTER = RuleImage(roi_front=(1106,29,48,49), roi_back=(1106,29,48,49), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_filter.png")
 	# 选中第一个鬼王的 

+ 1 - 83
tasks/AreaBoss/res/image.json

@@ -1,83 +1 @@
-[
-    {
-        "itemName": "explore",
-        "imageName": "res_explore.png",
-        "roiFront": "758,122,66,77",
-        "roiBack": "339,104,836,120",
-        "method": "Template matching",
-        "threshold": 0.8,
-        "description": "探索图标"
-    },
-    {
-        "itemName": "area_boss",
-        "imageName": "res_area_boss.png",
-        "roiFront": "639,636,65,68",
-        "roiBack": "606,619,145,100",
-        "method": "Template matching",
-        "threshold": 0.8,
-        "description": "地狱鬼王图标"
-    },
-    {
-        "itemName": "back_blue",
-        "imageName": "res_back_blue.png",
-        "roiFront": "43,30,51,52",
-        "roiBack": "43,30,51,52",
-        "method": "Template matching",
-        "threshold": 0.8,
-        "description": "蓝色的返回"
-    },
-    {
-        "itemName": "filter",
-        "imageName": "res_filter.png",
-        "roiFront": "1106,29,48,49",
-        "roiBack": "1106,29,48,49",
-        "method": "Template matching",
-        "threshold": 0.8,
-        "description": "右上边选中鬼王的"
-    },
-    {
-        "itemName": "battle_1",
-        "imageName": "res_battle_1.png",
-        "roiFront": "1066,210,100,100",
-        "roiBack": "1066,210,100,100",
-        "method": "Template matching",
-        "threshold": 0.8,
-        "description": "选中第一个鬼王的"
-    },
-    {
-        "itemName": "battle_2",
-        "imageName": "res_battle_2.png",
-        "roiFront": "1068,364,100,100",
-        "roiBack": "1068,364,100,100",
-        "method": "Template matching",
-        "threshold": 0.8,
-        "description": "选中第二个鬼王的"
-    },
-    {
-        "itemName": "battle_3",
-        "imageName": "res_battle_3.png",
-        "roiFront": "1071,521,100,100",
-        "roiBack": "1071,521,100,100",
-        "method": "Template matching",
-        "threshold": 0.8,
-        "description": "选中第三个鬼王的"
-    },
-    {
-        "itemName": "fire",
-        "imageName": "res_fire.png",
-        "roiFront": "1108,492,100,100",
-        "roiBack": "1108,492,100,100",
-        "method": "Template matching",
-        "threshold": 0.8,
-        "description": "点击挑战"
-    },
-    {
-        "itemName": "close_red",
-        "imageName": "res_close_red.png",
-        "roiFront": "1190,24,37,38",
-        "roiBack": "1190,24,37,38",
-        "method": "Template matching",
-        "threshold": 0.8,
-        "description": "红色的关闭"
-    }
-]
+[{"itemName":"explore","imageName":"res_explore.png","roiFront":"758,122,66,77","roiBack":"339,104,836,120","method":"Template matching","threshold":0.8,"description":"探索图标"},{"itemName":"area_boss","imageName":"res_area_boss.png","roiFront":"639,636,65,68","roiBack":"606,619,145,100","method":"Template matching","threshold":0.8,"description":"地狱鬼王图标"},{"itemName":"back_blue","imageName":"res_back_blue.png","roiFront":"51,30,51,52","roiBack":"4,1,128,110","method":"Template matching","threshold":0.8,"description":"蓝色的返回"},{"itemName":"filter","imageName":"res_filter.png","roiFront":"1106,29,48,49","roiBack":"1106,29,48,49","method":"Template matching","threshold":0.8,"description":"右上边选中鬼王的"},{"itemName":"battle_1","imageName":"res_battle_1.png","roiFront":"1066,210,100,100","roiBack":"1066,210,100,100","method":"Template matching","threshold":0.8,"description":"选中第一个鬼王的"},{"itemName":"battle_2","imageName":"res_battle_2.png","roiFront":"1068,364,100,100","roiBack":"1068,364,100,100","method":"Template matching","threshold":0.8,"description":"选中第二个鬼王的"},{"itemName":"battle_3","imageName":"res_battle_3.png","roiFront":"1071,521,100,100","roiBack":"1071,521,100,100","method":"Template matching","threshold":0.8,"description":"选中第三个鬼王的"},{"itemName":"fire","imageName":"res_fire.png","roiFront":"1108,492,100,100","roiBack":"1108,492,100,100","method":"Template matching","threshold":0.8,"description":"点击挑战"},{"itemName":"close_red","imageName":"res_close_red.png","roiFront":"1190,24,37,38","roiBack":"1190,24,37,38","method":"Template matching","threshold":0.8,"description":"红色的关闭"}]

+ 153 - 32
tasks/AreaBoss/script_task.py

@@ -19,39 +19,88 @@ class ScriptTask(GeneralBattle, AreaBossAssets):
         # 直接手动关闭这个锁定阵容的设置
         self.config.area_boss.general_battle.lock_team_enable = False
 
-        # # 点击探索
-        # while 1:
-        #     self.screenshot()
-        #     if self.appear_then_click(self.I_EXPLORE, threshold=0.6, interval=2):
-        #         continue
-        #     if self.appear(self.I_AREA_BOSS, threshold=0.6):
-        #         break
-        #
-        # # 点击地狱鬼王
-        # while 1:
-        #     self.screenshot()
-        #     if self.appear_then_click(self.I_AREA_BOSS, threshold=0.6, interval=2):
-        #         continue
-        #     if self.appear(self.I_FILTER, threshold=0.6):
-        #         break
-        #
-        # # 点击右上角的鬼王选择
-        # while 1:
-        #     self.screenshot()
-        #     if self.appear_then_click(self.I_FILTER, threshold=0.8, interval=2):
-        #         continue
-        #     if self.appear(self.I_BATTLE_1):
-        #         break
-        #
-        # # 点击第一个鬼王
-        # while 1:
-        #     self.screenshot()
-        #     if self.appear_then_click(self.I_BATTLE_1, threshold=0.8, interval=1):
-        #         continue
-        #     if self.appear(self.I_CLOSE_RED):
-        #         break
+        # 点击探索
+        logger.info("Click explore")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_EXPLORE, threshold=0.6, interval=2):
+                continue
+            if self.appear(self.I_AREA_BOSS, threshold=0.6):
+                break
+
+        # 点击地狱鬼王
+        logger.info("Click area boss")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_AREA_BOSS, threshold=0.6, interval=2):
+                continue
+            if self.appear(self.I_FILTER, threshold=0.6):
+                break
+
+        # 点击右上角的鬼王选择
+        logger.info("Click filter")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_FILTER, threshold=0.8, interval=2):
+                continue
+            if self.appear(self.I_BATTLE_1):
+                break
+
+        # 点击第一个鬼王
+        logger.info("Click battle 1")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_BATTLE_1, threshold=0.8, interval=1):
+                continue
+            if self.appear(self.I_CLOSE_RED):
+                break
+
+        # 点击挑战
+        logger.info("Script fire")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_FIRE, interval=1):
+                continue
+            if not self.appear(self.I_CLOSE_RED):  # 如果这个红色的关闭不见了才可以进行继续
+                break
+        logger.info("Script general battle")
+        if not self.run_general_battle(self.config.area_boss.general_battle):
+            logger.info("地狱鬼王第一只战斗失败")
+
+        # 红色关闭
+        logger.info("Script close red")
+        self.wait_until_appear(self.I_CLOSE_RED)
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_CLOSE_RED, interval=1):
+                continue
+            if self.appear(self.I_FILTER):
+                break
+        # 只挑战一只, 退出
+        if self.config.area_boss.boss.boss_number == 1:
+            self.go_back()
+            return True
+
+        # 点击右上角的鬼王选择
+        logger.info("Script filter")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_FILTER, threshold=0.8, interval=2):
+                continue
+            if self.appear(self.I_BATTLE_2):
+                break
+
+        # 点击第2个鬼王
+        logger.info("Script area boss 2")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_BATTLE_2, threshold=0.8, interval=1):
+                continue
+            if self.appear(self.I_CLOSE_RED):
+                break
 
         # 点击挑战
+        logger.info("Script fire ")
         while 1:
             self.screenshot()
             if self.appear_then_click(self.I_FIRE, interval=1):
@@ -60,5 +109,77 @@ class ScriptTask(GeneralBattle, AreaBossAssets):
                 break
 
         if not self.run_general_battle(self.config.area_boss.general_battle):
-            print('打不过')
+            logger.info("地狱鬼王第2只战斗失败")
+
+        # 红色关闭
+        logger.info("Script close red")
+        self.wait_until_appear(self.I_CLOSE_RED)
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_CLOSE_RED, interval=1):
+                continue
+            if self.appear(self.I_FILTER):
+                break
+        # 只挑战2只, 退出
+        if self.config.area_boss.boss.boss_number == 2:
+            self.go_back()
+            return True
+
+
+        #---------------------------------------------第三只
+        # 点击右上角的鬼王选择
+        logger.info("Script filter")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_FILTER, threshold=0.8, interval=2):
+                continue
+            if self.appear(self.I_BATTLE_3):
+                break
+        # 点击第3个鬼王
+        logger.info("Script area boss 3")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_BATTLE_3, threshold=0.8, interval=1):
+                continue
+            if self.appear(self.I_CLOSE_RED):
+                break
+        # 点击挑战
+        logger.info("Script fire ")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_FIRE, interval=1):
+                continue
+            if not self.appear(self.I_CLOSE_RED):  # 如果这个红色的关闭不见了才可以进行继续
+                break
+        if not self.run_general_battle(self.config.area_boss.general_battle):
+            logger.info("地狱鬼王第2只战斗失败")
+        # 红色关闭
+        logger.info("Script close red")
+        self.wait_until_appear(self.I_CLOSE_RED)
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_CLOSE_RED, interval=1):
+                continue
+            if self.appear(self.I_FILTER):
+                break
+
+        # 退出
+        self.go_back()
         return True
+
+    def go_back(self) -> None:
+        """
+        返回, 要求这个时候是出现在  地狱鬼王的主界面
+        :return:
+        """
+        # 点击返回
+        logger.info("Script back home")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_BACK_BLUE, threshold=0.6, interval=2):
+                continue
+            if self.appear(self.I_EXPLORE, threshold=0.6):
+                break
+
+
+

+ 11 - 11
tasks/CoinChallenge/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 
 # This file was automatically generated by module/dev_tools/assets_extract.py.
 # Don't modify it manually.
-class Assets: 
+class CoinChallengeAssets: 
 
 	# Image Rule Assets
 	# description 
@@ -16,26 +16,26 @@ class Assets:
 	I_NEW3 = RuleImage(roi_front=(568,212,240,220), roi_back=(0,0,100,100), threshold=0.9, method="Template matching", file="./tasks/CoinChallenge/res/res_new3.png")
 	# Click Rule Assets
 	# description 
-	C_NEW1 = RuleClick(roi_front=(268,268,100,100), roi_back=(614,214,100,100))
+	C_NEW1 = RuleClick(roi_front=(268,268,100,100), roi_back=(614,214,100,100), name="new1")
 	# description 
-	C_NEW2 = RuleClick(roi_front=(171,236,100,100), roi_back=(554,225,100,100))
+	C_NEW2 = RuleClick(roi_front=(171,236,100,100), roi_back=(554,225,100,100), name="new2")
 	# desc444n 
-	C_NEW3 = RuleClick(roi_front=(180,150,100,100), roi_back=(596,247,100,100))
+	C_NEW3 = RuleClick(roi_front=(180,150,100,100), roi_back=(596,247,100,100), name="new3")
 	# Long Click Rule Assets
 	# description 
-	L_NEW1 = RuleLongClick(roi_front=(208,151,100,100), roi_back=(542,279,100,100), duration=1500)
+	L_NEW1 = RuleLongClick(roi_front=(208,151,100,100), roi_back=(542,279,100,100), duration=1500, name="new1")
 	# description 
-	L_NEW2 = RuleLongClick(roi_front=(355,191,100,100), roi_back=(526,323,100,100), duration=1500)
+	L_NEW2 = RuleLongClick(roi_front=(355,191,100,100), roi_back=(526,323,100,100), duration=1500, name="new2")
 	# de66666n 
-	L_NEW3 = RuleLongClick(roi_front=(112,156,100,100), roi_back=(469,200,100,100), duration=1000)
+	L_NEW3 = RuleLongClick(roi_front=(112,156,100,100), roi_back=(469,200,100,100), duration=1000, name="new3")
 	# Swipe Rule Assets
 	# description 
-	S_NEW1 = RuleSwipe(roi_front=(253,212,100,100), roi_back=(652,292,100,100), mode="default")
+	S_NEW1 = RuleSwipe(roi_front=(253,212,100,100), roi_back=(652,292,100,100), mode="default", name="new1")
 	# description 
-	S_NEW2 = RuleSwipe(roi_front=(265,272,100,100), roi_back=(622,338,100,100), mode="default")
+	S_NEW2 = RuleSwipe(roi_front=(265,272,100,100), roi_back=(622,338,100,100), mode="default", name="new2")
 	# description 
-	S_NEW3 = RuleSwipe(roi_front=(198,160,100,100), roi_back=(626,305,100,100), mode="default")
+	S_NEW3 = RuleSwipe(roi_front=(198,160,100,100), roi_back=(626,305,100,100), mode="default", name="new3")
 	# description 
-	S_NEW4 = RuleSwipe(roi_front=(150,145,100,100), roi_back=(535,199,100,100), mode="vector")
+	S_NEW4 = RuleSwipe(roi_front=(150,145,100,100), roi_back=(535,199,100,100), mode="vector", name="new4")
 
 

+ 10 - 0
tasks/DemonEncounter/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class DemonEncounterAssets: 
+
+

+ 10 - 0
tasks/EternitySea/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class EternitySeaAssets: 
+
+

+ 10 - 0
tasks/ExperienceYoukai/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class ExperienceYoukaiAssets: 
+
+

+ 10 - 0
tasks/FallenSun/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class FallenSunAssets: 
+
+

+ 10 - 0
tasks/General/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class GeneralAssets: 
+
+

+ 23 - 21
tasks/GeneralBattle/assets.py

@@ -8,45 +8,45 @@ from module.atom.swipe import RuleSwipe
 class GeneralBattleAssets: 
 	# Click Rule Assets
 	# 预设队伍1 
-	C_PRESET_TEAM_1 = RuleClick(roi_front=(196,234,464,114), roi_back=(196,234,464,114))
+	C_PRESET_TEAM_1 = RuleClick(roi_front=(196,234,464,114), roi_back=(196,234,464,114), name="preset_team_1")
 	# 预设队伍2 
-	C_PRESET_TEAM_2 = RuleClick(roi_front=(197,358,465,103), roi_back=(197,358,465,103))
+	C_PRESET_TEAM_2 = RuleClick(roi_front=(197,358,465,103), roi_back=(197,358,465,103), name="preset_team_2")
 	# 预设队伍3 
-	C_PRESET_TEAM_3 = RuleClick(roi_front=(195,480,462,100), roi_back=(195,480,462,100))
+	C_PRESET_TEAM_3 = RuleClick(roi_front=(195,480,462,100), roi_back=(195,480,462,100), name="preset_team_3")
 	# 预设队伍4 
-	C_PRESET_TEAM_4 = RuleClick(roi_front=(193,596,464,35), roi_back=(193,596,464,35))
+	C_PRESET_TEAM_4 = RuleClick(roi_front=(193,596,464,35), roi_back=(193,596,464,35), name="preset_team_4")
 	# 预设组1 
-	C_PRESET_GROUP_1 = RuleClick(roi_front=(28,238,134,56), roi_back=(28,238,134,56))
+	C_PRESET_GROUP_1 = RuleClick(roi_front=(28,238,134,56), roi_back=(28,238,134,56), name="preset_group_1")
 	# 预设组2 
-	C_PRESET_GROUP_2 = RuleClick(roi_front=(31,298,132,60), roi_back=(31,298,132,60))
+	C_PRESET_GROUP_2 = RuleClick(roi_front=(31,298,132,60), roi_back=(31,298,132,60), name="preset_group_2")
 	# 预设组3 
-	C_PRESET_GROUP_3 = RuleClick(roi_front=(31,362,135,59), roi_back=(31,362,135,59))
+	C_PRESET_GROUP_3 = RuleClick(roi_front=(31,362,135,59), roi_back=(31,362,135,59), name="preset_group_3")
 	# 预设组4 
-	C_PRESET_GROUP_4 = RuleClick(roi_front=(29,427,133,57), roi_back=(29,427,133,57))
+	C_PRESET_GROUP_4 = RuleClick(roi_front=(29,427,133,57), roi_back=(29,427,133,57), name="preset_group_4")
 	# 预设组5 
-	C_PRESET_GROUP_5 = RuleClick(roi_front=(31,489,133,60), roi_back=(31,489,133,60))
+	C_PRESET_GROUP_5 = RuleClick(roi_front=(31,489,133,60), roi_back=(31,489,133,60), name="preset_group_5")
 	# 预设组6 
-	C_PRESET_GROUP_6 = RuleClick(roi_front=(31,549,132,63), roi_back=(31,549,132,63))
+	C_PRESET_GROUP_6 = RuleClick(roi_front=(31,549,132,63), roi_back=(31,549,132,63), name="preset_group_6")
 	# 预设组7 
-	C_PRESET_GROUP_7 = RuleClick(roi_front=(29,615,137,63), roi_back=(29,615,137,63))
+	C_PRESET_GROUP_7 = RuleClick(roi_front=(29,615,137,63), roi_back=(29,615,137,63), name="preset_group_7")
 	# 从左开始第一个绿标 
-	C_GREEN_LEFT_1 = RuleClick(roi_front=(128,433,90,150), roi_back=(128,433,90,150))
+	C_GREEN_LEFT_1 = RuleClick(roi_front=(128,433,90,150), roi_back=(128,433,90,150), name="green_left_1")
 	# 从左开始第二个绿标 
-	C_GREEN_LEFT_2 = RuleClick(roi_front=(371,385,81,145), roi_back=(371,385,81,145))
+	C_GREEN_LEFT_2 = RuleClick(roi_front=(371,385,81,145), roi_back=(371,385,81,145), name="green_left_2")
 	# 从左开始第三个绿标 
-	C_GREEN_LEFT_3 = RuleClick(roi_front=(586,328,100,76), roi_back=(586,328,100,76))
+	C_GREEN_LEFT_3 = RuleClick(roi_front=(586,328,100,76), roi_back=(586,328,100,76), name="green_left_3")
 	# 从左开始第四个绿标 
-	C_GREEN_LEFT_4 = RuleClick(roi_front=(817,379,77,133), roi_back=(817,379,77,133))
+	C_GREEN_LEFT_4 = RuleClick(roi_front=(817,379,77,133), roi_back=(817,379,77,133), name="green_left_4")
 	# 从左开始第五个绿标 
-	C_GREEN_LEFT_5 = RuleClick(roi_front=(1059,416,85,145), roi_back=(1059,416,85,145))
+	C_GREEN_LEFT_5 = RuleClick(roi_front=(1059,416,85,145), roi_back=(1059,416,85,145), name="green_left_5")
 	# 绿标阴阳师 
-	C_GREEN_MAIN = RuleClick(roi_front=(590,454,88,178), roi_back=(590,454,88,178))
+	C_GREEN_MAIN = RuleClick(roi_front=(590,454,88,178), roi_back=(590,454,88,178), name="green_main")
 	# 战斗的时候有一定的概率随机点击 
-	C_RANDOM_CLICK = RuleClick(roi_front=(104,79,1050,507), roi_back=(255,65,100,100))
+	C_RANDOM_CLICK = RuleClick(roi_front=(104,79,1050,507), roi_back=(255,65,100,100), name="random_click")
 
 	# Image Rule Assets
 	# 奖励,就是那个魂 
-	I_REWARD = RuleImage(roi_front=(579,514,100,100), roi_back=(579,514,100,100), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_reward.png")
+	I_REWARD = RuleImage(roi_front=(547,518,172,96), roi_back=(547,518,172,96), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_reward.png")
 	# 预设的小图标 
 	I_PRESET = RuleImage(roi_front=(32,650,47,45), roi_back=(32,650,47,45), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_preset.png")
 	# 准备 
@@ -75,10 +75,12 @@ class GeneralBattleAssets:
 	I_BUFF_EXP_100 = RuleImage(roi_front=(372,463,386,50), roi_back=(372,463,386,50), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_buff_exp_100.png")
 	# 左下角的位置指针 
 	I_LOCAL = RuleImage(roi_front=(25,563,30,34), roi_back=(25,563,30,34), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_local.png")
+	# description 
+	I_STATISTICS = RuleImage(roi_front=(61,644,33,28), roi_back=(61,644,33,28), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_statistics.png")
 	# Swipe Rule Assets
 	# description 
-	S_BATTLE_RANDOM_LEFT = RuleSwipe(roi_front=(122,155,480,426), roi_back=(667,147,461,427), mode="default")
+	S_BATTLE_RANDOM_LEFT = RuleSwipe(roi_front=(122,155,480,426), roi_back=(667,147,461,427), mode="default", name="battle_random_left")
 	# description 
-	S_BATTLE_RANDOM_RIGHT = RuleSwipe(roi_front=(719,138,417,392), roi_back=(237,163,387,394), mode="default")
+	S_BATTLE_RANDOM_RIGHT = RuleSwipe(roi_front=(719,138,417,392), roi_back=(237,163,387,394), mode="default", name="battle_random_right")
 
 

+ 43 - 19
tasks/GeneralBattle/general_battle.py

@@ -30,9 +30,12 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
 
         # 如果没有锁定队伍。那么可以根据配置设定队伍
         if not config.lock_team_enable:
+            logger.info("lock team is not enable")
             # 如果启动更换队伍
             if config.preset_enable:
+                logger.info("preset is enable")
                 # 点击预设按钮
+                logger.info("click preset button")
                 while 1:
                     self.screenshot()
                     if self.appear_then_click(self.I_PRESET, threshold=0.8):
@@ -40,6 +43,7 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
                     if self.appear(self.I_PRESET_ENSURE):
                         break
                 # 选择预设组
+                logger.info("select preset group")
                 x, y = None, None
                 match config.preset_group:
                     case 1: x, y = self.C_PRESET_GROUP_1.coord()
@@ -53,6 +57,7 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
                 self.device.click(x, y)
 
                 # 选择预设的队伍
+                logger.info("select preset team")
                 time.sleep(0.5)
                 match config.preset_team:
                     case 1: x, y = self.C_PRESET_TEAM_1.coord()
@@ -63,6 +68,7 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
                 self.device.click(x, y)
 
                 # 点击预设确认
+                logger.info("click preset ensure")
                 while 1:
                     self.screenshot()
                     if self.appear_then_click(self.I_PRESET_ENSURE, threshold=0.8):
@@ -70,8 +76,10 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
                     if not self.appear(self.I_PRESET_ENSURE):
                         break
 
+            # 点击buff按钮
             if config.buff_enable:
-                # 点击buff按钮
+                logger.info("buff is enable")
+                logger.info("click buff button")
                 while 1:
                     self.screenshot()
                     if self.appear_then_click(self.I_BUFF, interval=1.5):
@@ -81,18 +89,21 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
 
 
             # 点击准备按钮
+            self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
+            logger.info("click prepare button")
             while 1:
                 self.screenshot()
-                if self.appear_then_click(self.I_PREPARE_HIGHLIGHT):
+                if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
                     continue
-                if not self.appear(self.I_PREPARE_HIGHLIGHT):
+                if not self.appear(self.I_PRESET):
                     break
 
             # 照顾一下某些模拟器慢的
-            time.sleep(0.2)
+            time.sleep(0.1)
 
         # 绿标
         if config.green_enable:
+            logger.info("green is enable")
             x, y = None, None
             match config.green_mark:
                 case GreenMarkType.GREEN_LEFT1: x, y = self.C_GREEN_LEFT_1.coord()
@@ -109,52 +120,65 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
             self.device.click(x, y)
 
         # 战斗过程 随机点击和滑动 防封
+        logger.info("battle process")
         win: bool = False
         while 1:
+            self.screenshot()
             # 如果出现赢 就点击
-            if self.appear_then_click(self.I_WIN):
+            if self.appear(self.I_WIN, threshold=0.6):
+                logger.info("Battle result is win")
                 win = True
                 break
 
             # 如果出现失败 就点击,返回False
-            if self.appear_then_click(self.I_FALSE):
+            if self.appear(self.I_FALSE, threshold=0.6):
+                logger.info("Battle result is false")
                 win = False
                 break
 
             # 如果领奖励
-            if self.appear_then_click(self.I_REWARD):
+            if self.appear(self.I_REWARD, threshold=0.6):
                 win = True
                 break
-
             # 如果开启战斗过程随机滑动
             if config.random_click_swipt_enable:
+                time.sleep(0.4)  # 这样的好像不对
                 if 0 <= random.randint(0, 500) <= 3:  # 百分之4的概率
                     rand_type = random.randint(0, 2)
-                    x1, y1 = None, None
-                    x2, y2 = None, None
                     match rand_type:
                         case 0:
-                            x1, y1 = self.C_RANDOM_CLICK.coord()
-                            self.device.click(x1, y1)
+                            self.click(self.C_RANDOM_CLICK, interval=20)
                         case 1:
-                            x1, y1, x2, y2 = self.S_BATTLE_RANDOM_LEFT.coord()
-                            self.device.swipe((x1, y1), (x2, y2))
+                            self.swipe(self.S_BATTLE_RANDOM_LEFT, interval=20)
                         case 2:
-                            x1, y1, x2, y2 = self.S_BATTLE_RANDOM_RIGHT.coord()
-                            self.device.swipe((x1, y1), (x2, y2))
+                            self.swipe(self.S_BATTLE_RANDOM_RIGHT, interval=20)
 
         # 再次确认战斗结果
+        logger.info("reconfirm the results of the battle")
         while 1:
+            self.screenshot()
             if win:
+                # 点击赢了
                 if self.appear_then_click(self.I_WIN):
                     continue
                 if not self.appear(self.I_WIN):
                     break
             else:
-                if self.appear_then_click(self.I_FALSE):
+                # 如果失败且 点击失败后
+                if self.appear_then_click(self.I_FALSE, threshold=0.6):
                     continue
-                if not self.appear(self.I_FALSE):
-                    break
+                if not self.appear(self.I_FALSE, threshold=0.6):
+                    return False
+        # 最后保证能点击 获得奖励
+        self.wait_until_appear(self.I_REWARD)
+        logger.info("get reward")
+        while 1:
+            self.screenshot()
+            # 如果出现领奖励
+            if self.appear_then_click(self.I_REWARD, interval=1.5):
+                continue
+            if not self.appear(self.I_REWARD):
+                break
 
         if win:
             return True

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 137
tasks/GeneralBattle/res/image.json


BIN
tasks/GeneralBattle/res/res_reward.png


BIN
tasks/GeneralBattle/res/res_statistics.png


BIN
tasks/GeneralBattle/res/res_win.png


+ 10 - 0
tasks/GlobalGame/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class GlobalGameAssets: 
+
+

+ 10 - 0
tasks/GoldYoukai/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class GoldYoukaiAssets: 
+
+

+ 10 - 0
tasks/Hunt/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class HuntAssets: 
+
+

+ 10 - 0
tasks/Nian/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class NianAssets: 
+
+

+ 10 - 0
tasks/Orochi/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class OrochiAssets: 
+
+

+ 10 - 0
tasks/OrochiJudgement/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class OrochiJudgementAssets: 
+
+

+ 10 - 0
tasks/OrochiMoans/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class OrochiMoansAssets: 
+
+

+ 10 - 0
tasks/RealmRaid/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class RealmRaidAssets: 
+
+

+ 10 - 0
tasks/Restart/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class RestartAssets: 
+
+

+ 10 - 0
tasks/Script/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class ScriptAssets: 
+
+

+ 10 - 0
tasks/Sougenbi/assets.py

@@ -0,0 +1,10 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+
+# This file was automatically generated by module/dev_tools/assets_extract.py.
+# Don't modify it manually.
+class SougenbiAssets: 
+
+

+ 54 - 1
tasks/base_task.py

@@ -63,7 +63,6 @@ class BaseTask:
         appear = target.match(self.device.image, threshold=threshold)
 
         if appear and interval:
-            logger.info(f'Image matches to {target.name}')
             self.interval_timer[target.name].reset()
 
         return appear
@@ -186,3 +185,57 @@ class BaseTask:
         :param swipe:
         :return:
         """
+        if not isinstance(swipe, RuleSwipe):
+            return
+
+        if interval:
+            if swipe.name in self.interval_timer:
+                # 如果传入的限制时间不一样,则替换限制新的传入的时间
+                if self.interval_timer[swipe.name].limit != interval:
+                    self.interval_timer[swipe.name] = Timer(interval)
+            else:
+                # 如果没有限制时间,则创建限制时间
+                self.interval_timer[swipe.name] = Timer(interval)
+            # 如果时间还没到达,则不执行
+            if not self.interval_timer[swipe.name].reached():
+                return
+
+        x1, y1, x2, y2 = swipe.coord()
+        self.device.swipe(p1=(x1, y1), p2=(x2, y2), control_name=swipe.name)
+
+        # 执行后,如果有限制时间,则重置限制时间
+        if interval:
+            # logger.info(f'Swipe {swipe.name}')
+            self.interval_timer[swipe.name].reset()
+
+    def click(self, click: Union[RuleClick, RuleLongClick]=None, interval: float =None) -> None:
+        """
+        点击或者长按
+        :param interval:
+        :param click:
+        :return:
+        """
+        if not click:
+            return
+
+        if interval:
+            if click.name in self.interval_timer:
+                # 如果传入的限制时间不一样,则替换限制新的传入的时间
+                if self.interval_timer[click.name].limit != interval:
+                    self.interval_timer[click.name] = Timer(interval)
+            else:
+                # 如果没有限制时间,则创建限制时间
+                self.interval_timer[click.name] = Timer(interval)
+            # 如果时间还没到达,则不执行
+            if not self.interval_timer[click.name].reached():
+                return
+
+        x, y = click.coord()
+        if isinstance(click, RuleLongClick):
+            self.device.long_click(x=x, y=y, duration=click.duration/1000, control_name=click.name)
+        elif isinstance(click, RuleClick):
+            self.device.click(x=x, y=y, control_name=click.name)
+
+        # 执行后,如果有限制时间,则重置限制时间
+        if interval:
+            self.interval_timer[click.name].reset()

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä