runhey 3 лет назад
Родитель
Сommit
541465745b
50 измененных файлов с 1072 добавлено и 47 удалено
  1. 8 2
      module/atom/image.py
  2. 1 1
      module/config/config_menu.py
  3. 2 0
      module/config/config_model.py
  4. 5 2
      module/dev_tools/assets_extract.py
  5. 86 30
      module/device/control.py
  6. 1 0
      module/device/handle.py
  7. 12 0
      module/device/method/adb.py
  8. 9 6
      module/device/method/window.py
  9. 1 1
      module/gui/qml/Component/RuleFile.qml
  10. 1 0
      requirements.txt
  11. 2 1
      script.py
  12. 30 0
      tasks/AreaBoss/assets.py
  13. 4 0
      tasks/AreaBoss/config.py
  14. 12 0
      tasks/AreaBoss/config_boss.py
  15. 1 1
      tasks/AreaBoss/config_scheduler.py
  16. 83 0
      tasks/AreaBoss/res/image.json
  17. BIN
      tasks/AreaBoss/res/res_area_boss.png
  18. BIN
      tasks/AreaBoss/res/res_back_blue.png
  19. BIN
      tasks/AreaBoss/res/res_battle_1.png
  20. BIN
      tasks/AreaBoss/res/res_battle_2.png
  21. BIN
      tasks/AreaBoss/res/res_battle_3.png
  22. BIN
      tasks/AreaBoss/res/res_close_red.png
  23. BIN
      tasks/AreaBoss/res/res_explore.png
  24. BIN
      tasks/AreaBoss/res/res_filter.png
  25. BIN
      tasks/AreaBoss/res/res_fire.png
  26. 49 3
      tasks/AreaBoss/script_task.py
  27. 84 0
      tasks/GeneralBattle/assets.py
  28. 69 0
      tasks/GeneralBattle/config_general_battle.py
  29. 163 0
      tasks/GeneralBattle/general_battle.py
  30. 110 0
      tasks/GeneralBattle/res/click.json
  31. 137 0
      tasks/GeneralBattle/res/image.json
  32. BIN
      tasks/GeneralBattle/res/res_buff.png
  33. BIN
      tasks/GeneralBattle/res/res_buff_awaken.png
  34. BIN
      tasks/GeneralBattle/res/res_buff_exp_100.png
  35. BIN
      tasks/GeneralBattle/res/res_buff_exp_50.png
  36. BIN
      tasks/GeneralBattle/res/res_buff_gold_100.png
  37. BIN
      tasks/GeneralBattle/res/res_buff_gold_50.png
  38. BIN
      tasks/GeneralBattle/res/res_buff_soul.png
  39. BIN
      tasks/GeneralBattle/res/res_false.png
  40. BIN
      tasks/GeneralBattle/res/res_local.png
  41. BIN
      tasks/GeneralBattle/res/res_prepare_dark.png
  42. BIN
      tasks/GeneralBattle/res/res_prepare_highlight.png
  43. BIN
      tasks/GeneralBattle/res/res_preset.png
  44. BIN
      tasks/GeneralBattle/res/res_preset_ensure.png
  45. BIN
      tasks/GeneralBattle/res/res_reward.png
  46. BIN
      tasks/GeneralBattle/res/res_win.png
  47. 16 0
      tasks/GeneralBattle/res/swipe.json
  48. 11 0
      tasks/GlobalGame/config.py
  49. 10 0
      tasks/GlobalGame/config_emergency.py
  50. 165 0
      tasks/base_task.py

+ 8 - 2
module/atom/image.py

@@ -21,12 +21,14 @@ class RuleImage:
         :param threshold: 阈值
         :param file: 相对路径, 带后缀
         """
-        self.roi_front = roi_front
+        self.roi_front: list = list(roi_front)
         self.roi_back = roi_back
         self.method = method
         self.threshold = threshold
         self.file = file
 
+        self._match_init = False  # 这个是给后面的 等待图片稳定
+
         self._image = None  # 这个是匹配的目标
 
     @cached_property
@@ -117,6 +119,8 @@ class RuleImage:
         res = cv2.matchTemplate(source, mat, cv2.TM_CCOEFF_NORMED)
         min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)  # 最小匹配度,最大匹配度,最小匹配度的坐标,最大匹配度的坐标
         if max_val > threshold:
+            self.roi_front[0] = max_loc[0] + self.roi_back[0]
+            self.roi_front[1] = max_loc[1] + self.roi_back[1]
             return True
         else:
             return False
@@ -139,4 +143,6 @@ class RuleImage:
 
 
 if __name__ == "__main__":
-    pass
+    image = cv2.imread("D:/4713.jpg")
+    mat = RuleImage(roi_front=(758,122,66,77), roi_back=(339,104,836,120), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_explore.png")
+    print(mat.match(image))

+ 1 - 1
module/config/config_menu.py

@@ -15,7 +15,7 @@ class ConfigMenu:
         # 总览
         self.menu["Overview"] = []
         # 脚本设置
-        self.menu['Script'] = ['Script', 'General', 'Restart']
+        self.menu['Script'] = ['Script', 'General', 'Restart', 'GlobalGame']
         # 开发工具
         self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule']
         # 刷御魂

+ 2 - 0
module/config/config_model.py

@@ -12,6 +12,7 @@ from module.logger import logger
 # 导入配置的Python文件
 from tasks.Script.config import Script
 from tasks.Restart.config import Restart
+from tasks.GlobalGame.config import GlobalGame
 from tasks.AreaBoss.config import AreaBoss
 from tasks.ExperienceYoukai.config import ExperienceYoukai
 from tasks.GoldYoukai.config import GoldYoukai
@@ -31,6 +32,7 @@ class ConfigModel(BaseModel):
     config_name: str = "oas"
     script: Script = Field(default_factory=Script)
     restart: Restart = Field(default_factory=Restart)
+    global_game: GlobalGame = Field(default_factory=GlobalGame)
 
     # 这些是每日人物的
     area_boss: AreaBoss = Field(default_factory=AreaBoss)

+ 5 - 2
module/dev_tools/assets_extract.py

@@ -168,10 +168,12 @@ class AssetsExtractor:
         self.task_path = Path.cwd() / MODULE_FOLDER / task_name
         self.assets_file = Path.cwd() / MODULE_FOLDER / task_name / ASSETS_FILE
 
+        self.class_name = f'\nclass {task_name}Assets: \n'
+
         self._result = ''
         for import_exp in IMPORT_EXP:
             self._result += import_exp
-        self._result += ASSETS_CLASS
+        self._result += self.class_name
 
 
     def all_json_file(self) -> list:
@@ -276,7 +278,8 @@ class AllAssetsExtractor:
 
 
 if __name__ == "__main__":
-    c = AssetsExtractor('CoinChallenge')
+    c = AssetsExtractor('GeneralBattle')
+    # c = AssetsExtractor('AreaBoss')
     # print(c.assets_file)
     # print(c.task_path)
     # print(c.all_json_file())

+ 86 - 30
module/device/control.py

@@ -11,7 +11,7 @@ from module.device.method.window import Window
 from module.logger import logger
 
 
-class Control(Minitouch, Scrcpy, Window):
+class Control(Minitouch, Adb, Scrcpy, Window):
     def handle_control_check(self, button):
         # Will be overridden in Device
         pass
@@ -27,26 +27,60 @@ class Control(Minitouch, Scrcpy, Window):
             # 'MaaTouch': self.click_maatouch,
         }
 
-    def click(self, button, control_check=True):
+    @cached_property
+    def long_click_methods(self):
+        return {
+            'ADB': self.long_click_adb,
+            'uiautomator2': self.long_click_uiautomator2,
+            'minitouch': self.long_click_minitouch,
+            'window_message': self.long_click_window_message,
+            'scrcpy': self.long_click_scrcpy
+            # 'Hermit': self.click_hermit,
+            # 'MaaTouch': self.click_maatouch,
+        }
+
+    # def click(self, button, control_check=True):
+    #     """
+    #     后面改一改  不用用button的逻辑
+    #     :param button:
+    #     :param control_check:
+    #     :return:
+    #     """
+    #     if control_check:
+    #         self.handle_control_check(button)
+    #     x, y = random_rectangle_point(button.button)
+    #     x, y = ensure_int(x, y)
+    #     logger.info(
+    #         'Click %s @ %s' % (point2str(x, y), button)
+    #     )
+    #     method = self.click_methods.get(
+    #         self.config.script.emulator.control_method,
+    #         self.click_adb
+    #     )
+    #     method(x, y)
+
+    def click(self, x: int, y: int, control_check=True, control_name='Click') -> None:
         """
-        后面改一改  不用用button的逻辑
-        :param button:
+
+        :param control_name:
+        :param x:
+        :param y:
         :param control_check:
         :return:
         """
         if control_check:
-            self.handle_control_check(button)
-        x, y = random_rectangle_point(button.button)
+            self.handle_control_check(control_name)
         x, y = ensure_int(x, y)
         logger.info(
-            'Click %s @ %s' % (point2str(x, y), button)
+            'Click %s ' % (point2str(x, y))
         )
         method = self.click_methods.get(
-            self.config.script.emulator.control_method,
+            self.config.script.device.control_method,
             self.click_adb
         )
         method(x, y)
 
+
     def multi_click(self, button, n, interval=(0.1, 0.2)):
         """
         也是不能用button的逻辑
@@ -65,39 +99,61 @@ class Control(Minitouch, Scrcpy, Window):
 
             self.click(button, control_check=False)
 
-    def long_click(self, button, duration=(1, 1.2)):
+    # def long_click(self, button, duration=(1, 1.2)):
+    #     """
+    #
+    #     :param button:
+    #     :param duration:
+    #     :return:
+    #     """
+    #     self.handle_control_check(button)
+    #     x, y = random_rectangle_point(button.button)
+    #     x, y = ensure_int(x, y)
+    #     duration = ensure_time(duration)
+    #     logger.info(
+    #         'Click %s @ %s, %s' % (point2str(x, y), button, duration)
+    #     )
+    #     method = self.config.script.emulator.control_method
+    #     if method == 'minitouch':
+    #         self.long_click_minitouch(x, y, duration)
+    #     elif method == 'window_message':
+    #         self.long_click_window_message(x, y, duration)
+    #     elif method == 'uiautomator2':
+    #         self.long_click_uiautomator2(x, y, duration)
+    #     elif method == 'scrcpy':
+    #         self.long_click_scrcpy(x, y, duration)
+    #     # elif method == 'MaaTouch':
+    #     #     self.long_click_maatouch(x, y, duration)
+    #     else:
+    #         self.swipe_adb((x, y), (x, y), duration)
+
+    def long_click(self, x: int, y: int, duration=(0.5, 2), control_name='LongClick') -> None:
         """
 
-        :param button:
-        :param duration:
+        :param control_name:
+        :param x:
+        :param y:
+        :param duration: 单位是s
         :return:
         """
-        self.handle_control_check(button)
-        x, y = random_rectangle_point(button.button)
+        self.handle_control_check(control_name)
         x, y = ensure_int(x, y)
+        if duration is None:
+            duration = 0.8
         duration = ensure_time(duration)
         logger.info(
-            'Click %s @ %s, %s' % (point2str(x, y), button, duration)
+            'Click %s @ %s' % (point2str(x, y), duration)
         )
-        method = self.config.script.emulator.control_method
-        if method == 'minitouch':
-            self.long_click_minitouch(x, y, duration)
-        elif method == 'window_message':
-            self.long_click_window_message(x, y, duration)
-        elif method == 'uiautomator2':
-            self.long_click_uiautomator2(x, y, duration)
-        elif method == 'scrcpy':
-            self.long_click_scrcpy(x, y, duration)
-        # elif method == 'MaaTouch':
-        #     self.long_click_maatouch(x, y, duration)
-        else:
-            self.swipe_adb((x, y), (x, y), duration)
+        method = self.long_click_methods.get(
+            self.config.script.emulator.control_method,
+            self.long_click_adb)
+        method(x, y, duration)
 
-    def swipe(self, p1, p2, duration=(0.1, 0.2), name='SWIPE', distance_check=True):
-        self.handle_control_check(name)
+    def swipe(self, p1, p2, duration=(0.1, 0.2), control_name='SWIPE', distance_check=True):
+        self.handle_control_check(control_name)
         p1, p2 = ensure_int(p1, p2)
         duration = ensure_time(duration)
-        method = self.config.script.emulator.control_method
+        method = self.config.script.device.control_method
         if method == 'minitouch':
             logger.info('Swipe %s -> %s' % (point2str(*p1), point2str(*p2)))
         elif method == 'window_message':

+ 1 - 0
module/device/handle.py

@@ -105,6 +105,7 @@ class Handle:
         'bluestacks_5': ['root_handle_title'],
         'bluestacks_family': ['root_handle_title']
     }
+    config: Config = None
 
     def __init__(self, config) -> None:
         """

+ 12 - 0
module/device/method/adb.py

@@ -186,6 +186,18 @@ class Adb(Connection):
         duration = int(duration * 1000)
         self.adb_shell(['input', 'swipe', *p1, *p2, duration])
 
+    def long_click_adb(self, x: float, y: float, duration: float):
+        """
+
+        :param x:
+        :param y:
+        :param duration: 单位是s
+        :return:
+        """
+        if not 0 < duration < 3:
+            duration = duration / 1000
+        self.adb_shell(['input', 'swipe', x, y, x, y, int(duration*1000)])
+
     @retry
     def app_current_adb(self):
         """

+ 9 - 6
module/device/method/window.py

@@ -29,9 +29,9 @@ from module.device.handle import Handle, window_scale_rate
 
 class Window(Handle):
 
-    def __init__(self):
+    def __init__(self, *args, **kwargs):
         logger.info("Window init")
-        super().__init__()
+        super().__init__(*args, **kwargs)
 
     def screenshot_window_background(self):
         """
@@ -61,11 +61,12 @@ class Window(Handle):
         signedIntsArray = saveBitMap.GetBitmapBits(True)
         imgSrceen = frombuffer(signedIntsArray, dtype='uint8')
         imgSrceen.shape = (heightScreen, widthScreen, 4)
-        # imgSrceen = cv2.cvtColor(imgSrceen, cv2.COLOR_BGRA2GRAY)
+        # 这点很重要 在alas中图片以np.ndarray(RGB)的顺序存储。但是opencv是以BGR
+        imgSrceen = cv2.cvtColor(imgSrceen, cv2.COLOR_BGR2RGB)
         # imgSrceen = cv2.resize(imgSrceen, (win_size[0], win_size[1]))
         # 很奇怪的
 
-        # 测试显示截图图片
+        # # 测试显示截图图片
         # cv2.namedWindow('imgSrceen')  # 命名窗口
         # cv2.imshow("imgSrceen", imgSrceen)  # 显示
         # cv2.waitKey(0)
@@ -127,9 +128,11 @@ class Window(Handle):
         #     y = 0
         # 我不知道为什么的使用的pywin32==306的版本会导致获取的图片的是(1024, 576)
         # 所有我在点击的时候会除以这个缩放比例
+        # 但是后面发现又不是影响的很奇怪
+
         x = int(x / self.window_scale_rate)
         y = int(y / self.window_scale_rate)
-        logger.info(self.control_handle_list)
+        # print(f"我点击的x:{x}, y:{y}")
         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
@@ -282,5 +285,5 @@ if __name__ == "__main__":
     w = Window(config='oas1')
     img = w.screenshot_window_background()
     logger.info(img.shape)
-    # w.click_window_message(x=350, y=220)
+    w.click_window_message(x=759, y=184)
     # w.swipe_window_message(startPos=[200, 5], endPos=[300, 300])

+ 1 - 1
module/gui/qml/Component/RuleFile.qml

@@ -181,7 +181,7 @@ FluArea {
                     }
                     placeholderText:"item name"
                     text: model.itemName
-                    validator: RegularExpressionValidator { regularExpression: /^[a-zA-Z0-9]*$/ }
+                    validator: RegularExpressionValidator { regularExpression: /^[a-z0-9_]*$/ }
                     onActiveFocusChanged: {
                         if(activeFocus){
                             currentItem = listModel.get(index)

+ 1 - 0
requirements.txt

@@ -24,6 +24,7 @@ future==0.18.3            # via zerorpc
 gevent==22.10.2           # via zerorpc
 greenlet==2.0.2           # via gevent
 idna==3.4                 # via requests
+inflection==0.5.1         # via -r requirements-in.txt
 logzero==1.7.0            # via uiautomator2
 lxml==4.9.2               # via uiautomator2
 markdown-it-py==2.2.0     # via rich

+ 2 - 1
script.py

@@ -177,7 +177,8 @@ class Script:
         :return: cv2的对象将 numpy 数组转换为字节串。接下来MsgPack 进行序列化发送方将图像数据转换为字节串
         """
         # return msgpack.packb(cv2.imencode('.jpg', self.device.screenshot())[1].tobytes())
-        ret, buffer = cv2.imencode('.jpg', self.device.screenshot())
+        img = cv2.cvtColor(self.device.screenshot(), cv2.COLOR_RGB2BGR)
+        ret, buffer = cv2.imencode('.jpg', img)
         yield buffer.tobytes()
 
     def wait_until(self, future):

+ 30 - 0
tasks/AreaBoss/assets.py

@@ -0,0 +1,30 @@
+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 AreaBossAssets: 
+
+	# Image Rule Assets
+	# 探索图标 
+	I_EXPLORE = RuleImage(roi_front=(758,122,66,77), roi_back=(339,104,836,120), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_explore.png")
+	# 地狱鬼王图标 
+	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_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")
+	# 选中第一个鬼王的 
+	I_BATTLE_1 = RuleImage(roi_front=(1066,210,100,100), roi_back=(1066,210,100,100), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_battle_1.png")
+	# 选中第二个鬼王的 
+	I_BATTLE_2 = RuleImage(roi_front=(1068,364,100,100), roi_back=(1068,364,100,100), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_battle_2.png")
+	# 选中第三个鬼王的 
+	I_BATTLE_3 = RuleImage(roi_front=(1071,521,100,100), roi_back=(1071,521,100,100), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_battle_3.png")
+	# 点击挑战 
+	I_FIRE = RuleImage(roi_front=(1108,492,100,100), roi_back=(1108,492,100,100), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_fire.png")
+	# 红色的关闭 
+	I_CLOSE_RED = RuleImage(roi_front=(1190,24,37,38), roi_back=(1190,24,37,38), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_close_red.png")
+
+

+ 4 - 0
tasks/AreaBoss/config.py

@@ -4,7 +4,11 @@
 from pydantic import BaseModel, Field
 
 from tasks.AreaBoss.config_scheduler import Scheduler
+from tasks.GeneralBattle.config_general_battle import GeneralBattleConfig
+from tasks.AreaBoss.config_boss import Boss
 
 
 class AreaBoss(BaseModel):
     scheduler: Scheduler = Field(default_factory=Scheduler)
+    general_battle: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
+    boss: Boss = Field(default_factory=Boss)

+ 12 - 0
tasks/AreaBoss/config_boss.py

@@ -0,0 +1,12 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from enum import Enum
+from datetime import datetime, time
+from pydantic import BaseModel, ValidationError, validator, Field
+
+class Boss(BaseModel):
+    boss_number: int = Field(title='Boss Number',
+                             default=3,
+                             description='只可选范围1~3',
+                             ge=1, le=3)

+ 1 - 1
tasks/AreaBoss/config_scheduler.py

@@ -11,5 +11,5 @@ class Scheduler(BaseModel):
     next_run: datetime = Field(default="2023-01-01 00:00:00",
                                description='none')
     priority: int = Field(default=3,
-                          description='default 3')
+                          description='已经弃置,不生效')
 

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

@@ -0,0 +1,83 @@
+[
+    {
+        "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": "红色的关闭"
+    }
+]

BIN
tasks/AreaBoss/res/res_area_boss.png


BIN
tasks/AreaBoss/res/res_back_blue.png


BIN
tasks/AreaBoss/res/res_battle_1.png


BIN
tasks/AreaBoss/res/res_battle_2.png


BIN
tasks/AreaBoss/res/res_battle_3.png


BIN
tasks/AreaBoss/res/res_close_red.png


BIN
tasks/AreaBoss/res/res_explore.png


BIN
tasks/AreaBoss/res/res_filter.png


BIN
tasks/AreaBoss/res/res_fire.png


+ 49 - 3
tasks/AreaBoss/script_task.py

@@ -4,15 +4,61 @@
 import time
 
 from tasks.base_task import BaseTask
+from tasks.GeneralBattle.general_battle import GeneralBattle
+from tasks.AreaBoss.assets import AreaBossAssets
 from module.logger import logger
 
 
-class ScriptTask(BaseTask):
+class ScriptTask(GeneralBattle, AreaBossAssets):
 
     def run(self) -> bool:
         """
         运行脚本
         :return:
         """
-        time.sleep(10)
-        logger.info("运行脚本")
+        # 直接手动关闭这个锁定阵容的设置
+        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
+
+        # 点击挑战
+        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):
+            print('打不过')
+        return True

+ 84 - 0
tasks/GeneralBattle/assets.py

@@ -0,0 +1,84 @@
+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 GeneralBattleAssets: 
+	# Click Rule Assets
+	# 预设队伍1 
+	C_PRESET_TEAM_1 = RuleClick(roi_front=(196,234,464,114), roi_back=(196,234,464,114))
+	# 预设队伍2 
+	C_PRESET_TEAM_2 = RuleClick(roi_front=(197,358,465,103), roi_back=(197,358,465,103))
+	# 预设队伍3 
+	C_PRESET_TEAM_3 = RuleClick(roi_front=(195,480,462,100), roi_back=(195,480,462,100))
+	# 预设队伍4 
+	C_PRESET_TEAM_4 = RuleClick(roi_front=(193,596,464,35), roi_back=(193,596,464,35))
+	# 预设组1 
+	C_PRESET_GROUP_1 = RuleClick(roi_front=(28,238,134,56), roi_back=(28,238,134,56))
+	# 预设组2 
+	C_PRESET_GROUP_2 = RuleClick(roi_front=(31,298,132,60), roi_back=(31,298,132,60))
+	# 预设组3 
+	C_PRESET_GROUP_3 = RuleClick(roi_front=(31,362,135,59), roi_back=(31,362,135,59))
+	# 预设组4 
+	C_PRESET_GROUP_4 = RuleClick(roi_front=(29,427,133,57), roi_back=(29,427,133,57))
+	# 预设组5 
+	C_PRESET_GROUP_5 = RuleClick(roi_front=(31,489,133,60), roi_back=(31,489,133,60))
+	# 预设组6 
+	C_PRESET_GROUP_6 = RuleClick(roi_front=(31,549,132,63), roi_back=(31,549,132,63))
+	# 预设组7 
+	C_PRESET_GROUP_7 = RuleClick(roi_front=(29,615,137,63), roi_back=(29,615,137,63))
+	# 从左开始第一个绿标 
+	C_GREEN_LEFT_1 = RuleClick(roi_front=(128,433,90,150), roi_back=(128,433,90,150))
+	# 从左开始第二个绿标 
+	C_GREEN_LEFT_2 = RuleClick(roi_front=(371,385,81,145), roi_back=(371,385,81,145))
+	# 从左开始第三个绿标 
+	C_GREEN_LEFT_3 = RuleClick(roi_front=(586,328,100,76), roi_back=(586,328,100,76))
+	# 从左开始第四个绿标 
+	C_GREEN_LEFT_4 = RuleClick(roi_front=(817,379,77,133), roi_back=(817,379,77,133))
+	# 从左开始第五个绿标 
+	C_GREEN_LEFT_5 = RuleClick(roi_front=(1059,416,85,145), roi_back=(1059,416,85,145))
+	# 绿标阴阳师 
+	C_GREEN_MAIN = RuleClick(roi_front=(590,454,88,178), roi_back=(590,454,88,178))
+	# 战斗的时候有一定的概率随机点击 
+	C_RANDOM_CLICK = RuleClick(roi_front=(104,79,1050,507), roi_back=(255,65,100,100))
+
+	# 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_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")
+	# 准备 
+	I_PREPARE_HIGHLIGHT = RuleImage(roi_front=(1128,536,100,100), roi_back=(1128,536,100,100), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_prepare_highlight.png")
+	# 战斗胜利 
+	I_WIN = RuleImage(roi_front=(427,135,100,100), roi_back=(427,135,100,100), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_win.png")
+	# 准备但是界面还未加载这个时候是黑色的 
+	I_PREPARE_DARK = RuleImage(roi_front=(1131,538,100,100), roi_back=(1131,538,100,100), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_prepare_dark.png")
+	# 失败 
+	I_FALSE = RuleImage(roi_front=(413,124,100,100), roi_back=(413,124,100,100), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_false.png")
+	# 确认预设的队伍 
+	I_PRESET_ENSURE = RuleImage(roi_front=(354,641,141,50), roi_back=(354,641,141,50), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_preset_ensure.png")
+	# 选择buff 
+	I_BUFF = RuleImage(roi_front=(113,653,44,62), roi_back=(113,653,44,62), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_buff.png")
+	# 觉醒加成 
+	I_BUFF_AWAKEN = RuleImage(roi_front=(373,126,383,53), roi_back=(373,126,383,53), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_buff_awaken.png")
+	# 御魂加成 
+	I_BUFF_SOUL = RuleImage(roi_front=(377,192,371,56), roi_back=(377,192,371,56), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_buff_soul.png")
+	# 金币加成50 
+	I_BUFF_GOLD_50 = RuleImage(roi_front=(375,259,373,56), roi_back=(375,259,373,56), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_buff_gold_50.png")
+	# 金币加成100 
+	I_BUFF_GOLD_100 = RuleImage(roi_front=(371,329,389,54), roi_back=(371,329,389,54), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_buff_gold_100.png")
+	# 经验加成50 
+	I_BUFF_EXP_50 = RuleImage(roi_front=(378,400,370,50), roi_back=(378,400,370,50), threshold=0.8, method="Template matching", file="./tasks/GeneralBattle/res/res_buff_exp_50.png")
+	# 经验加成100 
+	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")
+	# Swipe Rule Assets
+	# description 
+	S_BATTLE_RANDOM_LEFT = RuleSwipe(roi_front=(122,155,480,426), roi_back=(667,147,461,427), mode="default")
+	# description 
+	S_BATTLE_RANDOM_RIGHT = RuleSwipe(roi_front=(719,138,417,392), roi_back=(237,163,387,394), mode="default")
+
+

+ 69 - 0
tasks/GeneralBattle/config_general_battle.py

@@ -0,0 +1,69 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from enum import Enum
+from datetime import datetime, time
+from pydantic import BaseModel, ValidationError, validator, Field
+
+class GreenMarkType(str, Enum):
+    GREEN_LEFT1 = 'green_left1'
+    GREEN_LEFT2 = 'green_left2'
+    GREEN_LEFT3 = 'green_left3'
+    GREEN_LEFT4 = 'green_left4'
+    GREEN_LEFT5 = 'green_left5'
+    GREEN_MAIN = 'green_main'
+
+class GeneralBattleConfig(BaseModel):
+
+    # 是否锁定阵容, 有些的战斗是外边的锁定阵容甚至有些的战斗没有锁定阵容的
+    lock_team_enable: bool = Field(default=False,
+                                   description='default is false')
+
+    # 是否启动 预设队伍
+    preset_enable: bool = Field(default=False,
+                                description='default is false')
+    # 选哪一个预设组
+    preset_group: int = Field(default=1,
+                              description='default is 1, max is 7, min is 1',
+                              ge=1, le=7)
+    # 选哪一个队伍
+    preset_team: int = Field(default=1,
+                             description='default is 1, min is 1, max is 4',
+                             ge=1, le=4)
+
+    # 是否启动开启buff
+    buff_enable: bool = Field(default=False,
+                               description='default is false')
+    # 是否点击觉醒Buff
+    buff_awake_click: bool = Field(default=False,
+                                   description='default is false')
+    # 是否点击御魂buff
+    buff_soul_click: bool = Field(default=False,
+                                  description='default is false')
+    # 是否点击金币50buff
+    buff_gold_50_click: bool = Field(default=False,
+                                    description='default is false')
+    # 是否点击金币100buff
+    buff_gold_100_click: bool = Field(default=False,
+                                        description='default is false')
+    # 是否点击经验50buff
+    buff_exp_50_click: bool = Field(default=False,
+                                    description='default is false')
+    # 是否点击经验100buff
+    buff_exp_100_click: bool = Field(default=False,
+                                    description='default is false')
+
+    # 是否开启绿标
+    green_enable: bool = Field(default=False,
+                                 description='default is false')
+    # 选哪一个绿标
+    green_mark: GreenMarkType = Field(default=GreenMarkType.GREEN_LEFT1,
+                                        description='default is GREEN_LEFT1')
+
+    # 是否启动战斗时随机点击或者随机滑动
+    random_click_swipt_enable: bool = Field(default=False,
+                                        description='default is false')
+    # 是否启动战斗时随机滑动
+    # random_swipe_enable: bool = Field(default=False,
+    #                                     description='default is false')
+

+ 163 - 0
tasks/GeneralBattle/general_battle.py

@@ -0,0 +1,163 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+import random
+
+from tasks.base_task import BaseTask
+from tasks.GeneralBattle.config_general_battle import GreenMarkType, GeneralBattleConfig
+from tasks.GeneralBattle.assets import GeneralBattleAssets
+from module.logger import logger
+
+
+
+class GeneralBattle(BaseTask, GeneralBattleAssets):
+    """
+    使用这个通用的战斗必须要求这个任务的config有config_general_battle
+    """
+
+    def run_general_battle(self, config: dict=None) -> bool:
+        """
+        运行脚本
+        :return:
+        """
+        if config is None:
+            config = GeneralBattleConfig().dict()
+
+        # if isinstance(config, GeneralBattle):
+        #     logger.error(f"config is not GeneralBattle type, config: {config}")
+        #     config = GeneralBattle().dict()
+
+        # 如果没有锁定队伍。那么可以根据配置设定队伍
+        if not config.lock_team_enable:
+            # 如果启动更换队伍
+            if config.preset_enable:
+                # 点击预设按钮
+                while 1:
+                    self.screenshot()
+                    if self.appear_then_click(self.I_PRESET, threshold=0.8):
+                        continue
+                    if self.appear(self.I_PRESET_ENSURE):
+                        break
+                # 选择预设组
+                x, y = None, None
+                match config.preset_group:
+                    case 1: x, y = self.C_PRESET_GROUP_1.coord()
+                    case 2: x, y = self.C_PRESET_GROUP_2.coord()
+                    case 3: x, y = self.C_PRESET_GROUP_3.coord()
+                    case 4: x, y = self.C_PRESET_GROUP_4.coord()
+                    case 5: x, y = self.C_PRESET_GROUP_5.coord()
+                    case 6: x, y = self.C_PRESET_GROUP_6.coord()
+                    case 7: x, y = self.C_PRESET_GROUP_7.coord()
+                    case _: x, y = self.C_PRESET_GROUP_1.coord()
+                self.device.click(x, y)
+
+                # 选择预设的队伍
+                time.sleep(0.5)
+                match config.preset_team:
+                    case 1: x, y = self.C_PRESET_TEAM_1.coord()
+                    case 2: x, y = self.C_PRESET_TEAM_2.coord()
+                    case 3: x, y = self.C_PRESET_TEAM_3.coord()
+                    case 4: x, y = self.C_PRESET_TEAM_4.coord()
+                    case _: x, y = self.C_PRESET_TEAM_1.coord()
+                self.device.click(x, y)
+
+                # 点击预设确认
+                while 1:
+                    self.screenshot()
+                    if self.appear_then_click(self.I_PRESET_ENSURE, threshold=0.8):
+                        continue
+                    if not self.appear(self.I_PRESET_ENSURE):
+                        break
+
+            if config.buff_enable:
+                # 点击buff按钮
+                while 1:
+                    self.screenshot()
+                    if self.appear_then_click(self.I_BUFF, interval=1.5):
+                        continue
+                    if self.appear(self.I_BUFF_AWAKEN) or self.appear(self.I_BUFF_SOUL):
+                        break
+
+
+            # 点击准备按钮
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(self.I_PREPARE_HIGHLIGHT):
+                    continue
+                if not self.appear(self.I_PREPARE_HIGHLIGHT):
+                    break
+
+            # 照顾一下某些模拟器慢的
+            time.sleep(0.2)
+
+        # 绿标
+        if config.green_enable:
+            x, y = None, None
+            match config.green_mark:
+                case GreenMarkType.GREEN_LEFT1: x, y = self.C_GREEN_LEFT_1.coord()
+                case GreenMarkType.GREEN_LEFT2: x, y = self.C_GREEN_LEFT_2.coord()
+                case GreenMarkType.GREEN_LEFT3: x, y = self.C_GREEN_LEFT_3.coord()
+                case GreenMarkType.GREEN_LEFT4: x, y = self.C_GREEN_LEFT_4.coord()
+                case GreenMarkType.GREEN_LEFT5: x, y = self.C_GREEN_LEFT_5.coord()
+                case GreenMarkType.GREEN_MAIN: x, y = self.C_GREEN_MAIN.coord()
+
+            # 判断有无坐标的偏移
+            self.appear_then_click(self.I_LOCAL)
+            time.sleep(0.3)
+            # 点击绿标
+            self.device.click(x, y)
+
+        # 战斗过程 随机点击和滑动 防封
+        win: bool = False
+        while 1:
+            # 如果出现赢 就点击
+            if self.appear_then_click(self.I_WIN):
+                win = True
+                break
+
+            # 如果出现失败 就点击,返回False
+            if self.appear_then_click(self.I_FALSE):
+                win = False
+                break
+
+            # 如果领奖励
+            if self.appear_then_click(self.I_REWARD):
+                win = True
+                break
+
+            # 如果开启战斗过程随机滑动
+            if config.random_click_swipt_enable:
+                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)
+                        case 1:
+                            x1, y1, x2, y2 = self.S_BATTLE_RANDOM_LEFT.coord()
+                            self.device.swipe((x1, y1), (x2, y2))
+                        case 2:
+                            x1, y1, x2, y2 = self.S_BATTLE_RANDOM_RIGHT.coord()
+                            self.device.swipe((x1, y1), (x2, y2))
+
+        # 再次确认战斗结果
+        while 1:
+            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):
+                    continue
+                if not self.appear(self.I_FALSE):
+                    break
+
+        if win:
+            return True
+        else:
+            return False
+

+ 110 - 0
tasks/GeneralBattle/res/click.json

@@ -0,0 +1,110 @@
+[
+    {
+        "itemName": "preset_team_1",
+        "roiFront": "196,234,464,114",
+        "roiBack": "196,234,464,114",
+        "description": "预设队伍1"
+    },
+    {
+        "itemName": "preset_team_2",
+        "roiFront": "197,358,465,103",
+        "roiBack": "197,358,465,103",
+        "description": "预设队伍2"
+    },
+    {
+        "itemName": "preset_team_3",
+        "roiFront": "195,480,462,100",
+        "roiBack": "195,480,462,100",
+        "description": "预设队伍3"
+    },
+    {
+        "itemName": "preset_team_4",
+        "roiFront": "193,596,464,35",
+        "roiBack": "193,596,464,35",
+        "description": "预设队伍4"
+    },
+    {
+        "itemName": "preset_group_1",
+        "roiFront": "28,238,134,56",
+        "roiBack": "28,238,134,56",
+        "description": "预设组1"
+    },
+    {
+        "itemName": "preset_group_2",
+        "roiFront": "31,298,132,60",
+        "roiBack": "31,298,132,60",
+        "description": "预设组2"
+    },
+    {
+        "itemName": "preset_group_3",
+        "roiFront": "31,362,135,59",
+        "roiBack": "31,362,135,59",
+        "description": "预设组3"
+    },
+    {
+        "itemName": "preset_group_4",
+        "roiFront": "29,427,133,57",
+        "roiBack": "29,427,133,57",
+        "description": "预设组4"
+    },
+    {
+        "itemName": "preset_group_5",
+        "roiFront": "31,489,133,60",
+        "roiBack": "31,489,133,60",
+        "description": "预设组5"
+    },
+    {
+        "itemName": "preset_group_6",
+        "roiFront": "31,549,132,63",
+        "roiBack": "31,549,132,63",
+        "description": "预设组6"
+    },
+    {
+        "itemName": "preset_group_7",
+        "roiFront": "29,615,137,63",
+        "roiBack": "29,615,137,63",
+        "description": "预设组7"
+    },
+    {
+        "itemName": "green_left_1",
+        "roiFront": "128,433,90,150",
+        "roiBack": "128,433,90,150",
+        "description": "从左开始第一个绿标"
+    },
+    {
+        "itemName": "green_left_2",
+        "roiFront": "371,385,81,145",
+        "roiBack": "371,385,81,145",
+        "description": "从左开始第二个绿标"
+    },
+    {
+        "itemName": "green_left_3",
+        "roiFront": "586,328,100,76",
+        "roiBack": "586,328,100,76",
+        "description": "从左开始第三个绿标"
+    },
+    {
+        "itemName": "green_left_4",
+        "roiFront": "817,379,77,133",
+        "roiBack": "817,379,77,133",
+        "description": "从左开始第四个绿标"
+    },
+    {
+        "itemName": "green_left_5",
+        "roiFront": "1059,416,85,145",
+        "roiBack": "1059,416,85,145",
+        "description": "从左开始第五个绿标"
+    },
+    {
+        "itemName": "green_main",
+        "roiFront": "590,454,88,178",
+        "roiBack": "590,454,88,178",
+        "description": "绿标阴阳师"
+    },
+    {
+        "itemName": "random_click",
+        "roiFront": "104,79,1050,507",
+        "roiBack": "255,65,100,100",
+        "description": "战斗的时候有一定的概率随机点击"
+    }
+]

+ 137 - 0
tasks/GeneralBattle/res/image.json

@@ -0,0 +1,137 @@
+[
+    {
+        "itemName": "reward",
+        "imageName": "res_reward.png",
+        "roiFront": "579,514,100,100",
+        "roiBack": "579,514,100,100",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "奖励,就是那个魂"
+    },
+    {
+        "itemName": "preset",
+        "imageName": "res_preset.png",
+        "roiFront": "32,650,47,45",
+        "roiBack": "32,650,47,45",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "预设的小图标"
+    },
+    {
+        "itemName": "prepare_highlight",
+        "imageName": "res_prepare_highlight.png",
+        "roiFront": "1128,536,100,100",
+        "roiBack": "1128,536,100,100",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "准备"
+    },
+    {
+        "itemName": "win",
+        "imageName": "res_win.png",
+        "roiFront": "427,135,100,100",
+        "roiBack": "427,135,100,100",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "战斗胜利"
+    },
+    {
+        "itemName": "prepare_dark",
+        "imageName": "res_prepare_dark.png",
+        "roiFront": "1131,538,100,100",
+        "roiBack": "1131,538,100,100",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "准备但是界面还未加载这个时候是黑色的"
+    },
+    {
+        "itemName": "false",
+        "imageName": "res_false.png",
+        "roiFront": "413,124,100,100",
+        "roiBack": "413,124,100,100",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "失败"
+    },
+    {
+        "itemName": "preset_ensure",
+        "imageName": "res_preset_ensure.png",
+        "roiFront": "354,641,141,50",
+        "roiBack": "354,641,141,50",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "确认预设的队伍"
+    },
+    {
+        "itemName": "buff",
+        "imageName": "res_buff.png",
+        "roiFront": "113,653,44,62",
+        "roiBack": "113,653,44,62",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "选择buff"
+    },
+    {
+        "itemName": "buff_awaken",
+        "imageName": "res_buff_awaken.png",
+        "roiFront": "373,126,383,53",
+        "roiBack": "373,126,383,53",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "觉醒加成"
+    },
+    {
+        "itemName": "buff_soul",
+        "imageName": "res_buff_soul.png",
+        "roiFront": "377,192,371,56",
+        "roiBack": "377,192,371,56",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "御魂加成"
+    },
+    {
+        "itemName": "buff_gold_50",
+        "imageName": "res_buff_gold_50.png",
+        "roiFront": "375,259,373,56",
+        "roiBack": "375,259,373,56",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "金币加成50"
+    },
+    {
+        "itemName": "buff_gold_100",
+        "imageName": "res_buff_gold_100.png",
+        "roiFront": "371,329,389,54",
+        "roiBack": "371,329,389,54",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "金币加成100"
+    },
+    {
+        "itemName": "buff_exp_50",
+        "imageName": "res_buff_exp_50.png",
+        "roiFront": "378,400,370,50",
+        "roiBack": "378,400,370,50",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "经验加成50"
+    },
+    {
+        "itemName": "buff_exp_100",
+        "imageName": "res_buff_exp_100.png",
+        "roiFront": "372,463,386,50",
+        "roiBack": "372,463,386,50",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "经验加成100"
+    },
+    {
+        "itemName": "local",
+        "imageName": "res_local.png",
+        "roiFront": "25,563,30,34",
+        "roiBack": "25,563,30,34",
+        "method": "Template matching",
+        "threshold": 0.8,
+        "description": "左下角的位置指针"
+    }
+]

BIN
tasks/GeneralBattle/res/res_buff.png


BIN
tasks/GeneralBattle/res/res_buff_awaken.png


BIN
tasks/GeneralBattle/res/res_buff_exp_100.png


BIN
tasks/GeneralBattle/res/res_buff_exp_50.png


BIN
tasks/GeneralBattle/res/res_buff_gold_100.png


BIN
tasks/GeneralBattle/res/res_buff_gold_50.png


BIN
tasks/GeneralBattle/res/res_buff_soul.png


BIN
tasks/GeneralBattle/res/res_false.png


BIN
tasks/GeneralBattle/res/res_local.png


BIN
tasks/GeneralBattle/res/res_prepare_dark.png


BIN
tasks/GeneralBattle/res/res_prepare_highlight.png


BIN
tasks/GeneralBattle/res/res_preset.png


BIN
tasks/GeneralBattle/res/res_preset_ensure.png


BIN
tasks/GeneralBattle/res/res_reward.png


BIN
tasks/GeneralBattle/res/res_win.png


+ 16 - 0
tasks/GeneralBattle/res/swipe.json

@@ -0,0 +1,16 @@
+[
+    {
+        "itemName": "battle_random_left",
+        "roiFront": "122,155,480,426",
+        "roiBack": "667,147,461,427",
+        "mode": "default",
+        "description": "description"
+    },
+    {
+        "itemName": "battle_random_right",
+        "roiFront": "719,138,417,392",
+        "roiBack": "237,163,387,394",
+        "mode": "default",
+        "description": "description"
+    }
+]

+ 11 - 0
tasks/GlobalGame/config.py

@@ -0,0 +1,11 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from pydantic import BaseModel, Field
+
+from tasks.GlobalGame.config_emergency import Emergency
+
+
+class GlobalGame(BaseModel):
+    emergency: Emergency = Field(default_factory=Emergency)
+

+ 10 - 0
tasks/GlobalGame/config_emergency.py

@@ -0,0 +1,10 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from datetime import datetime, time
+from pydantic import BaseModel, ValidationError, validator, Field
+
+
+class Emergency(BaseModel):
+    accept_friend_invitation: bool = Field(default=True,
+                                           description="default is true")

+ 165 - 0
tasks/base_task.py

@@ -2,7 +2,14 @@
 # @author runhey
 # github https://github.com/runhey
 from datetime import datetime
+from typing import Union
 
+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
+from module.logger import logger
+from module.base.timer import Timer
 from module.config.config import Config
 from module.device.device import Device
 
@@ -21,3 +28,161 @@ class BaseTask:
         self.config = config
         self.device = device
 
+        self.interval_timer = {}  # 这个是用来记录每个匹配的运行间隔的,用于控制运行频率
+
+
+
+
+    def screenshot(self):
+        """
+        截图 引入中间函数的目的是 为了解决如协作的这类突发的事件
+        :return:
+        """
+        return self.device.screenshot()
+
+    def appear(self, target: RuleImage, interval: float =None, threshold: float =None):
+        """
+
+        :param target: 匹配的目标可以是RuleImage, 也可以是RuleOcr
+        :param interval:
+        :param threshold:
+        :return:
+        """
+        if not isinstance(target, RuleImage):
+            return False
+
+        if interval:
+            if target.name in self.interval_timer:
+                if self.interval_timer[target.name].limit != interval:
+                    self.interval_timer[target.name] = Timer(interval)
+            else:
+                self.interval_timer[target.name] = Timer(interval)
+            if not self.interval_timer[target.name].reached():
+                return False
+
+        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
+
+    def appear_then_click(self,
+                          target: RuleImage,
+                          action: Union[RuleClick, RuleLongClick]=None,
+                          interval: float=None,
+                          threshold: float=None,
+                          duration: float=None):
+        """
+        出现了就点击,默认点击图片的位置,如果添加了click参数,就点击click的位置
+        :param duration: 如果是长按,可以手动指定duration,不指定默认.单位是ms!!!!
+        :param action: 可以是RuleClick, 也可以是RuleLongClick
+        :param target: 可以是RuleImage后续支持RuleOcr
+        :param interval:
+        :param threshold:
+        :return: True or False
+        """
+        if not isinstance(target, RuleImage):
+            return False
+
+        appear = self.appear(target, interval=interval, threshold=threshold)
+        if appear and not action:
+            x, y = target.coord()
+            self.device.click(x, y, control_name=target.name)
+
+        elif appear and action:
+            x, y = action.coord()
+            if isinstance(action, RuleLongClick):
+                if duration is None:
+                    self.device.long_click(x, y, duration=action.duration/1000, control_name=target.name)
+                else:
+                    self.device.long_click(x, y, duration=duration/1000, control_name=target.name)
+            elif isinstance(action, RuleClick):
+                self.device.click(x, y, control_name=target.name)
+
+        return appear
+
+    def wait_until_appear(self,
+                          target: RuleImage,
+                          skip_first_screenshot=False) -> None:
+        """
+        等待直到出现目标
+        :param target:
+        :param skip_first_screenshot:
+        :return:
+        """
+        while 1:
+            if skip_first_screenshot:
+                skip_first_screenshot = False
+            else:
+                self.screenshot()
+            if self.appear(target):
+                break
+
+    def wait_until_appear_then_click(self,
+                                     target: RuleImage,
+                                     action: Union[RuleClick, RuleLongClick]=None) -> None:
+        """
+        等待直到出现目标,然后点击
+        :param action:
+        :param target:
+        :return:
+        """
+        self.wait_until_appear(target)
+        if action is None:
+            self.device.click(target.coord(), control_name=target.name)
+        elif isinstance(action, RuleLongClick):
+            self.device.long_click(target.coord(), duration=action.duration/1000, control_name=target.name)
+        elif isinstance(action, RuleClick):
+            self.device.click(target.coord(), control_name=target.name)
+
+    def wait_until_disappear(self, target: RuleImage) -> None:
+        while 1:
+            self.screenshot()
+            if not self.appear(target):
+                break
+
+    def wait_until_stable(self,
+                          target: RuleImage,
+                          timer=Timer(0.3, count=1),
+                          timeout=Timer(5, count=10),
+                          skip_first_screenshot=True):
+        """
+        等待目标稳定,即连续多次匹配成功
+        :param target:
+        :param timer:
+        :param timeout:
+        :param skip_first_screenshot:
+        :return:
+        """
+        target._match_init = False
+        timeout.reset()
+        while 1:
+            if skip_first_screenshot:
+                skip_first_screenshot = False
+            else:
+                self.screenshot()
+
+            if target._match_init:
+                if target.match(self.device.image):
+                    if timer.reached():
+                        break
+                else:
+                    # button.load_color(self.device.image)
+                    timer.reset()
+            else:
+                # target.load_color(self.device.image)
+                target._match_init = True
+
+            if timeout.reached():
+                logger.warning(f'wait_until_stable({target}) timeout')
+                break
+
+    def swipe(self, swipe: RuleSwipe, interval: float =None) -> None:
+        """
+
+        :param interval:
+        :param swipe:
+        :return:
+        """