Kaynağa Gözat

Merge pull request #405 from runhey/dev

Dev
huangrunheng 2 yıl önce
ebeveyn
işleme
257607222a
54 değiştirilmiş dosya ile 1456 ekleme ve 319 silme
  1. 47 0
      dev_tools/get_images.py
  2. 57 0
      module/atom/gif.py
  3. 47 2
      module/atom/image.py
  4. 7 0
      module/device/env.py
  5. 3 0
      tasks/Component/GeneralInvite/general_invite.py
  6. 5 0
      tasks/Exploration/READMD.md
  7. 60 0
      tasks/Exploration/assets.py
  8. 353 0
      tasks/Exploration/base.py
  9. 30 18
      tasks/Exploration/config.py
  10. BIN
      tasks/Exploration/highlight/highlight_light1.png
  11. BIN
      tasks/Exploration/highlight/highlight_light10.png
  12. BIN
      tasks/Exploration/highlight/highlight_light11.png
  13. BIN
      tasks/Exploration/highlight/highlight_light12.png
  14. BIN
      tasks/Exploration/highlight/highlight_light13.png
  15. BIN
      tasks/Exploration/highlight/highlight_light14.png
  16. BIN
      tasks/Exploration/highlight/highlight_light2.png
  17. BIN
      tasks/Exploration/highlight/highlight_light3.png
  18. BIN
      tasks/Exploration/highlight/highlight_light4.png
  19. BIN
      tasks/Exploration/highlight/highlight_light5.png
  20. BIN
      tasks/Exploration/highlight/highlight_light6.png
  21. BIN
      tasks/Exploration/highlight/highlight_light7.png
  22. BIN
      tasks/Exploration/highlight/highlight_light8.png
  23. BIN
      tasks/Exploration/highlight/highlight_light9.png
  24. BIN
      tasks/Exploration/highlight/highlight_lighttest.png
  25. BIN
      tasks/Exploration/highlight/highlight_up_coin - 副本.png
  26. BIN
      tasks/Exploration/highlight/highlight_up_coin.png
  27. BIN
      tasks/Exploration/highlight/highlight_up_daruma - 副本.png
  28. BIN
      tasks/Exploration/highlight/highlight_up_daruma.png
  29. BIN
      tasks/Exploration/highlight/highlight_up_exp - 副本.png
  30. BIN
      tasks/Exploration/highlight/highlight_up_exp.png
  31. 164 0
      tasks/Exploration/highlight/image.json
  32. 6 0
      tasks/Exploration/res/click.json
  33. 36 0
      tasks/Exploration/res/image.json
  34. 30 0
      tasks/Exploration/res/long_click.json
  35. BIN
      tasks/Exploration/res/res_exp_create_ensure.png
  36. BIN
      tasks/Exploration/res/res_exp_create_team.png
  37. BIN
      tasks/Exploration/res/res_swipe_end.png
  38. BIN
      tasks/Exploration/res/res_team_emoji.png
  39. 4 282
      tasks/Exploration/script_task.py
  40. 466 0
      tasks/Exploration/solo.py
  41. 94 0
      tasks/Exploration/version.py
  42. 1 1
      tasks/GameUi/assets.py
  43. BIN
      tasks/GameUi/page/page_check_realm_raid.png
  44. 2 2
      tasks/GameUi/page/page_img.json
  45. BIN
      tasks/GameUi/page/page_ryoutoppa_goto_realmraid.png
  46. 3 1
      tasks/KekkaiUtilize/assets.py
  47. 6 3
      tasks/KekkaiUtilize/script_task.py
  48. 10 1
      tasks/KekkaiUtilize/utilize/ocr.json
  49. 1 4
      tasks/RealmRaid/script_task.py
  50. 3 1
      tasks/RyouToppa/script_task.py
  51. 2 0
      tasks/SoulsTidy/assets.py
  52. 2 0
      tasks/SoulsTidy/script_task.py
  53. 9 0
      tasks/SoulsTidy/simple/ocr.json
  54. 8 4
      tasks/base_task.py

+ 47 - 0
dev_tools/get_images.py

@@ -0,0 +1,47 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import cv2
+import time
+from datetime import timedelta, datetime
+from cached_property import cached_property
+from random import choice
+from pathlib import Path
+
+
+from module.exception import TaskEnd
+from module.logger import logger
+from module.base.timer import Timer
+
+from tasks.Script.config_device import ScreenshotMethod, ControlMethod
+from tasks.base_task import BaseTask
+from tasks.Exploration.version import highlight
+
+class GetAnimation(BaseTask):
+
+    @cached_property
+    def save_folder(self) -> Path:
+        save_time = datetime.now().strftime('%Y%m%dT%H%M%S')
+        save_folder = Path(f'./log/temp/{save_time}')
+        save_folder.mkdir(parents=True, exist_ok=True)
+        return save_folder
+
+    def run_screenshot(self):
+        self.config.model.script.device.screenshot_method = ScreenshotMethod.WINDOW_BACKGROUND
+        run_timer = Timer(3)
+        sho_timer = Timer(0.1)
+        run_timer.start()
+        sho_timer.start()
+        save_images = {}
+        while 1:
+            if run_timer.reached():
+                break
+            if sho_timer.reached():
+                sho_timer.reset()
+                image = self.device.screenshot_window_background()
+                # image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
+                image = highlight(image)
+                time_now1 = int(time.time() * 1000)
+                save_images[time_now1] = image
+        for time_now, image in save_images.items():
+            cv2.imwrite(str(self.save_folder / f'all{time_now}.png'), image)

+ 57 - 0
module/atom/gif.py

@@ -0,0 +1,57 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import numpy as np
+
+from module.atom.image import RuleImage
+
+
+
+class RuleGif:
+    # 大部分实现同RuleImage 的接口
+
+    @property
+    def name(self) -> str:
+        return self.appear_target.name
+
+    def __init__(self, targets: list[RuleImage]):
+        self.targets = targets
+        self.roi_front: list = [0, 0, 0, 0]
+        self.appear_target = targets[0]
+
+    def pre_process(self, image):
+        return image
+
+
+    def search(self, image, roi: list = None, threshold: float = None) -> tuple:
+        """
+
+        :param image:
+        :param roi:
+        :param threshold:
+        :return: bool
+        第一项是否为出现, 第二项为匹配的RuleImage
+        """
+        image = self.pre_process(image)
+        #
+        threshold = self.targets[0].threshold if threshold is None else threshold
+        roi = self.targets[0].roi_back if roi is None else roi
+        for target in self.targets:
+            target.roi_back = roi
+            if target.match(image, threshold):
+                self.roi_front = target.roi_front
+                self.appear_target = target
+                return True, target
+        return False, None
+
+    def match(self, image, threshold: float = None) -> bool:
+        return self.search(image, threshold=threshold)[0]
+
+
+    def coord(self) -> tuple:
+        x, y, w, h = self.roi_front
+        return x + np.random.randint(0, w), y + np.random.randint(0, h)
+
+    def front_center(self) -> tuple:
+        x, y, w, h = self.roi_front
+        return int(x + w//2), int(y + h//2)

+ 47 - 2
module/atom/image.py

@@ -143,7 +143,8 @@ class RuleImage:
             threshold = self.threshold
 
         if not self.is_template_match:
-            raise Exception(f"unknown method {self.method}")
+            return self.sift_match(image)
+            # raise Exception(f"unknown method {self.method}")
 
         source = self.corp(image)
         mat = self.image
@@ -157,6 +158,34 @@ class RuleImage:
         else:
             return False
 
+    def match_all(self, image: np.array, threshold: float = None, roi: list = None) -> list[tuple]:
+        """
+        区别于match,这个是返回所有的匹配结果
+        :param roi:
+        :param image:
+        :param threshold:
+        :return:
+        """
+        if roi is not None:
+            self.roi_back = roi
+        if threshold is None:
+            threshold = self.threshold
+        if not self.is_template_match:
+            raise Exception(f"unknown method {self.method}")
+        source = self.corp(image)
+        mat = self.image
+        results = cv2.matchTemplate(source, mat, cv2.TM_CCOEFF_NORMED)
+        locations = np.where(results >= threshold)
+        matches = []
+        for pt in zip(*locations[::-1]):  # (x, y) coordinates
+            score = results[pt[1], pt[0]]
+            # 得分, x, y, w, h
+            x = self.roi_back[0] + pt[0]
+            y = self.roi_back[1] + pt[1]
+            matches.append((score, x, y, mat.shape[1], mat.shape[0]))
+        return matches
+
+
     def coord(self) -> tuple:
         """
         获取roi_front的随机的点击的坐标
@@ -215,7 +244,7 @@ class RuleImage:
             # 设定阈值, 距离小于对方的距离的0.7倍我们认为是好的匹配点.
             if m.distance < 0.6 * n.distance:
                 good.append(m)
-        if len(good) >= 4:
+        if len(good) >= 10:
             src_pts = float32([self.kp[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)
             dst_pts = float32([kp[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)
 
@@ -252,6 +281,22 @@ class RuleImage:
             cv2.destroyAllWindows()
         return result
 
+    def match_mean_color(self, image, color: tuple, bias=10) -> bool:
+        """
+
+        :param image:
+        :param color:  rgb
+        :param bias:
+        :return:
+        """
+        image = self.corp(image)
+        average_color = cv2.mean(image)
+        logger.info(f'{self.name} average_color: {average_color}')
+        for i in range(3):
+            if abs(average_color[i] - color[i]) > bias:
+                return False
+        return True
+
 
 if __name__ == "__main__":
     from dev_tools.assets_test import detect_image

+ 7 - 0
module/device/env.py

@@ -0,0 +1,7 @@
+# This Python file uses the following encoding: utf-8
+# https://github.com/LmeSzinc/StarRailCopilot/blob/master/module/device/env.py
+import sys
+
+IS_WINDOWS = sys.platform == 'win32'
+IS_MACINTOSH = sys.platform == 'darwin'
+IS_LINUX = sys.platform == 'linux'

+ 3 - 0
tasks/Component/GeneralInvite/general_invite.py

@@ -351,6 +351,9 @@ class GeneralInvite(BaseTask, GeneralInviteAssets):
         list_2 = self.O_F_LIST_2.ocr(self.device.image)
         list_3 = self.O_F_LIST_3.ocr(self.device.image)
         list_4 = self.O_F_LIST_4.ocr(self.device.image)
+        list_1 = list_1.replace(' ', '').replace('、', '')
+        list_2 = list_2.replace(' ', '').replace('、', '')
+        list_3 = list_3.replace(' ', '').replace('、', '')
         if list_1 is not None and list_1 != '' and list_1 in self.friend_class:
             friend_class.append(list_1)
         if list_2 is not None and list_2 != '' and list_2 in self.friend_class:

+ 5 - 0
tasks/Exploration/READMD.md

@@ -0,0 +1,5 @@
+- 必须支持多人,队员队长和单人 三个模式
+- 无脑启动
+- 可选buff
+- 绘卷模式
+- 

+ 60 - 0
tasks/Exploration/assets.py

@@ -10,6 +10,45 @@ from module.atom.list import RuleList
 class ExplorationAssets: 
 
 
+	# Image Rule Assets
+	# description 
+	I_LIGHTTEST = RuleImage(roi_front=(550,288,85,82), roi_back=(97,182,1130,409), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_lighttest.png")
+	# description 
+	I_LIGHT1 = RuleImage(roi_front=(498,297,86,87), roi_back=(97,182,1130,409), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light1.png")
+	# description 
+	I_LIGHT2 = RuleImage(roi_front=(497,300,86,82), roi_back=(97,182,1130,409), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light2.png")
+	# description 
+	I_LIGHT3 = RuleImage(roi_front=(495,301,85,77), roi_back=(97,182,1130,409), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light3.png")
+	# description 
+	I_LIGHT4 = RuleImage(roi_front=(496,296,85,85), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light4.png")
+	# description 
+	I_LIGHT5 = RuleImage(roi_front=(494,296,82,86), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light5.png")
+	# description 
+	I_LIGHT6 = RuleImage(roi_front=(490,295,83,85), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light6.png")
+	# description 
+	I_LIGHT7 = RuleImage(roi_front=(486,295,84,87), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light7.png")
+	# description 
+	I_LIGHT8 = RuleImage(roi_front=(485,298,84,81), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light8.png")
+	# description 
+	I_LIGHT9 = RuleImage(roi_front=(484,295,85,84), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light9.png")
+	# description 
+	I_LIGHT10 = RuleImage(roi_front=(479,297,84,78), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light10.png")
+	# description 
+	I_LIGHT11 = RuleImage(roi_front=(479,296,83,82), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light11.png")
+	# description 
+	I_LIGHT12 = RuleImage(roi_front=(477,290,85,90), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light12.png")
+	# description 
+	I_LIGHT13 = RuleImage(roi_front=(478,293,82,87), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light13.png")
+	# description 
+	I_LIGHT14 = RuleImage(roi_front=(474,290,82,87), roi_back=(0,0,100,100), threshold=0.6, method="Template matching", file="./tasks/Exploration/highlight/highlight_light14.png")
+	# 经验怪 
+	I_UP_EXP = RuleImage(roi_front=(471,518,74,71), roi_back=(1,225,1278,410), threshold=0.8, method="Sift Flann", file="./tasks/Exploration/highlight/highlight_up_exp.png")
+	# 金币怪 
+	I_UP_COIN = RuleImage(roi_front=(330,529,74,74), roi_back=(1,317,1278,316), threshold=0.8, method="Sift Flann", file="./tasks/Exploration/highlight/highlight_up_coin.png")
+	# 达摩怪 
+	I_UP_DARUMA = RuleImage(roi_front=(1146,510,80,80), roi_back=(1,265,1278,369), threshold=0.8, method="Sift Flann", file="./tasks/Exploration/highlight/highlight_up_daruma.png")
+
+
 	# Click Rule Assets
 	# 点击设置按钮 
 	C_CLICK_SETTINGS = RuleClick(roi_front=(55,662,21,21), roi_back=(55,662,21,21), name="click_settings")
@@ -27,6 +66,8 @@ class ExplorationAssets:
 	C_CLICK_ROTATE_3 = RuleClick(roi_front=(785,587,21,21), roi_back=(785,587,21,21), name="click_rotate_3")
 	# 位置4 
 	C_CLICK_ROTATE_4 = RuleClick(roi_front=(921,590,21,21), roi_back=(921,590,21,21), name="click_rotate_4")
+	# 随机点 
+	C_SAFE_RANDOM = RuleClick(roi_front=(0,0,111,12), roi_back=(0,0,111,12), name="safe_random")
 
 
 	# Image Rule Assets
@@ -70,6 +111,25 @@ class ExplorationAssets:
 	I_E_EXIT_CONFIRM = RuleImage(roi_front=(694,380,163,49), roi_back=(694,380,163,49), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_e_exit_confirm.png")
 	# 宝箱 
 	I_TREASURE_BOX_CLICK = RuleImage(roi_front=(33,476,70,49), roi_back=(2,130,135,406), threshold=0.7, method="Template matching", file="./tasks/Exploration/res/res_treasure_box_click.png")
+	# 困28滚动到最后 
+	I_SWIPE_END = RuleImage(roi_front=(994,234,119,100), roi_back=(968,196,311,165), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_swipe_end.png")
+	# 队伍的表情标志 
+	I_TEAM_EMOJI = RuleImage(roi_front=(36,437,44,46), roi_back=(4,407,100,100), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_team_emoji.png")
+	# 组队按钮 
+	I_EXP_CREATE_TEAM = RuleImage(roi_front=(590,514,122,52), roi_back=(543,490,192,100), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_exp_create_team.png")
+	# 创建确认 
+	I_EXP_CREATE_ENSURE = RuleImage(roi_front=(534,486,218,59), roi_back=(516,475,244,85), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_exp_create_ensure.png")
+
+
+	# Long Click Rule Assets
+	# description 
+	L_ROTATE_1 = RuleLongClick(roi_front=(516,582,22,21), roi_back=(516,582,22,21), duration=1500, name="rotate_1")
+	# description 
+	L_ROTATE_2 = RuleLongClick(roi_front=(650,587,21,21), roi_back=(650,587,21,21), duration=1500, name="rotate_2")
+	# description 
+	L_ROTATE_3 = RuleLongClick(roi_front=(785,587,21,21), roi_back=(785,587,21,21), duration=1500, name="rotate_3")
+	# description 
+	L_ROTATE_4 = RuleLongClick(roi_front=(921,590,21,21), roi_back=(921,590,21,21), duration=1500, name="rotate_4")
 
 
 	# Ocr Rule Assets

+ 353 - 0
tasks/Exploration/base.py

@@ -0,0 +1,353 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+import numpy as np
+import random
+from enum import Enum
+from cached_property import cached_property
+from datetime import timedelta, datetime
+
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
+from tasks.Component.GeneralRoom.general_room import GeneralRoom
+from tasks.Component.GeneralInvite.general_invite import GeneralInvite
+from tasks.Component.ReplaceShikigami.replace_shikigami import ReplaceShikigami
+from tasks.Exploration.assets import ExplorationAssets
+from tasks.Exploration.config import ChooseRarity, AutoRotate, AttackNumber, UpType
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_exploration, page_shikigami_records, page_main
+from tasks.RealmRaid.script_task import ScriptTask as RealmRaidScriptTask
+from tasks.Utils.config_enum import ShikigamiClass
+
+from module.logger import logger
+from module.exception import RequestHumanTakeover, TaskEnd
+from module.atom.image_grid import ImageGrid
+from module.base.utils import load_image
+
+class Scene(Enum):
+    UNKNOWN = 0  #
+    WORLD = 1  # 探索大世界
+    ENTRANCE = 2  # 入口弹窗
+    MAIN = 3  # 探索里面
+    BATTLE_PREPARE = 4  # 战斗准备
+    BATTLE_FIGHTING = 5  # 战斗中
+    TEAM = 6  # 组队
+
+
+
+
+class BaseExploration(GeneralBattle, GeneralRoom, GeneralInvite, ReplaceShikigami, GameUi, SwitchSoul, ExplorationAssets):
+    minions_cnt = 0
+
+    @cached_property
+    def _config(self):
+        self.config.exploration.general_battle_config.lock_team_enable = True
+        limit_time = self.config.exploration.exploration_config.limit_time
+        self.limit_time: timedelta = timedelta(
+            hours=limit_time.hour,
+            minutes=limit_time.minute,
+            seconds=limit_time.second
+        )
+        return self.config.model.exploration
+
+    def get_current_scene(self, reuse_screenshot: bool = True) -> Scene:
+        if not reuse_screenshot:
+            self.screenshot()
+
+        if self.appear(self.I_CHECK_EXPLORATION):
+            return Scene.WORLD
+        elif self.appear(self.I_UI_BACK_RED) and self.appear(self.I_E_EXPLORATION_CLICK):
+            return Scene.ENTRANCE
+        elif self.appear(self.I_E_SETTINGS_BUTTON) or self.appear(self.I_E_AUTO_ROTATE_ON) or self.appear(self.I_E_AUTO_ROTATE_OFF):
+            return Scene.MAIN
+        elif self.is_in_prepare():
+            return Scene.BATTLE_PREPARE
+        elif self.is_in_battle():
+            return Scene.BATTLE_FIGHTING
+        elif self.is_in_room() or self.appear(self.I_CREATE_ENSURE):
+            return Scene.TEAM
+
+        logger.info("Unknown scene")
+        return Scene.UNKNOWN
+
+    def pre_process(self):
+        explorationConfig = self._config
+        if explorationConfig.switch_soul_config.enable:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul(explorationConfig.switch_soul_config.switch_group_team)
+
+        if explorationConfig.switch_soul_config.enable_switch_by_name:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul_by_name(explorationConfig.switch_soul_config.group_name,
+                                         explorationConfig.switch_soul_config.team_name)
+
+        # 开启加成
+        con = self.config.exploration.exploration_config
+        if con.buff_gold_50_click or con.buff_gold_100_click or con.buff_exp_50_click or con.buff_exp_100_click:
+            self.ui_get_current_page()
+            self.ui_goto(page_main)
+            self.open_buff()
+            if con.buff_gold_50_click:
+                self.gold_50()
+            if con.buff_gold_100_click:
+                self.gold_100()
+            if con.buff_exp_50_click:
+                self.exp_50()
+            if con.buff_exp_100_click:
+                self.exp_100()
+            self.close_buff()
+
+        self.ui_get_current_page()
+        # 探索页面
+        self.ui_goto(page_exploration)
+
+    def post_process(self):
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+        con = self._config.exploration_config
+        if con.buff_gold_50_click or con.buff_gold_100_click or con.buff_exp_50_click or con.buff_exp_100_click:
+            self.open_buff()
+            self.gold_50(is_open=False)
+            self.gold_100(is_open=False)
+            self.exp_50(is_open=False)
+            self.exp_100(is_open=False)
+            self.close_buff()
+        self.set_next_run(task='Exploration', success=True, finish=False)
+        raise TaskEnd
+
+    # 打开指定的章节:
+    def open_expect_level(self):
+        swipeCount = 0
+        while 1:
+            # 探索的 config
+            explorationConfig = self.config.exploration
+
+            # 判断有无目标章节
+            self.screenshot()
+            # 获取当前章节名
+            results = self.O_E_EXPLORATION_LEVEL_NUMBER.detect_and_ocr(self.device.image)
+            text1 = [result.ocr_text for result in results]
+            # 判断当前章节有无目标章节
+            result = set(text1).intersection({explorationConfig.exploration_config.exploration_level})
+            # 有则跳出检测
+            if self.appear(self.I_E_EXPLORATION_CLICK) or result and len(result) > 0:
+                break
+            self.device.click_record_clear()
+            self.swipe(self.S_SWIPE_LEVEL_UP)
+            swipeCount += 1
+            if swipeCount >= 25:
+                return False
+
+        # 选中对应章节
+        while 1:
+            self.screenshot()
+            self.O_E_EXPLORATION_LEVEL_NUMBER.keyword = explorationConfig.exploration_config.exploration_level
+            if self.ocr_appear_click(self.O_E_EXPLORATION_LEVEL_NUMBER):
+                self.wait_until_appear(self.I_E_EXPLORATION_CLICK, wait_time=3)
+            if self.appear(self.I_E_EXPLORATION_CLICK):
+                break
+
+        return True
+
+    # 候补:
+    def enter_settings_and_do_operations(self):
+        # 打开设置
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_E_OPEN_SETTINGS):
+                logger.info("Open settings")
+                break
+            if self.is_in_battle():
+                logger.warning('Opening settings failed due to now in battle')
+                return
+            if self.click(self.C_CLICK_SETTINGS, interval=2):
+                continue
+
+        # 候补出战数量识别
+        self.screenshot()
+        if not self.appear(self.I_E_OPEN_SETTINGS):
+            logger.warning('Opening settings failed due to now in battle')
+            return
+        cu, res, total = self.O_E_ALTERNATE_NUMBER.ocr(self.device.image)
+        if cu >= 40:
+            logger.info("Alternate number is full")
+            self.ui_click_until_disappear(self.I_E_SURE_BUTTON)
+            return
+        else:
+            self.add_shiki()
+
+    # 添加式神
+    def add_shiki(self, screenshot=True):
+        if screenshot:
+            self.screenshot()
+            if not self.appear(self.I_E_OPEN_SETTINGS):
+                logger.warning('Opening settings failed due to now in battle')
+                return
+        choose_rarity = self._config.exploration_config.choose_rarity
+        rarity = ShikigamiClass.N if choose_rarity == ChooseRarity.N else ShikigamiClass.MATERIAL
+        self.switch_shikigami_class(rarity)
+
+        self.click(self.C_CLICK_STANDBY_TEAM)
+        # 移动至未候补的狗粮
+        while 1:
+            # 慢一点
+            time.sleep(0.5)
+            self.screenshot()
+            if not self.appear(self.I_E_OPEN_SETTINGS):
+                logger.warning('Opening settings failed due to now in battle')
+                return
+            if self.appear(self.I_E_RATATE_EXSIT):
+                self.swipe(self.S_SWIPE_SHIKI_TO_LEFT)
+            else:
+                break
+        while 1:
+            # 候补出战数量识别
+            self.screenshot()
+            if not self.appear(self.I_E_OPEN_SETTINGS):
+                logger.warning('Opening settings failed due to now in battle')
+                return
+            cu, res, total = self.O_E_ALTERNATE_NUMBER.ocr(self.device.image)
+            if cu >= 40:
+                break
+            self.swipe(self.S_SWIPE_SHIKI_TO_LEFT_ONE)
+            # 慢一点
+            time.sleep(0.5)
+            self.screenshot()
+            self.click(self.L_ROTATE_1)
+            self.device.click_record_clear()
+
+        self.appear_then_click(self.I_E_SURE_BUTTON)
+
+    # 找up按钮
+    def search_up_fight(self, up_type: UpType = None):
+        if up_type is None:
+            up_type = self._config.exploration_config.up_type
+        if up_type != UpType.ALL:
+            match up_type:
+                case UpType.EXP:
+                    find_flag = self.I_UP_EXP
+                case UpType.COIN:
+                    find_flag = self.I_UP_COIN
+                case UpType.DARUMAA:
+                    find_flag = self.I_UP_DARUMA
+                case _:
+                    find_flag = self.I_UP_EXP
+            appear = self.appear(find_flag)
+            if not appear:
+                return None
+            logger.info(f'Found up type: {up_type} at  {find_flag.roi_front}')
+            x, y, _, _ = find_flag.roi_front
+            x_center, y_center = find_flag.front_center()
+            roi_back_y = max(0, y - 300)
+            roi_back_h = y - 20 - roi_back_y
+            roi_back_x = max(0, x - 160)
+            roi_back_w = min(1280, x + 200) - roi_back_x
+            # self.I_NORMAL_BATTLE_BUTTON.roi_back = [roi_back_x, roi_back_y, roi_back_w, roi_back_h]
+            logger.info(f'It will search normal battle button at {roi_back_x, roi_back_y, roi_back_w, roi_back_h}')
+            matches = self.I_NORMAL_BATTLE_BUTTON.match_all(
+                image=self.device.image,
+                threshold=0.9,
+                roi=[roi_back_x, roi_back_y, roi_back_w, roi_back_h]
+            )
+            if not matches:
+                return None
+            distances = []
+            for match in matches:
+                x_match, y_match = match[1], match[2]
+                distance = np.linalg.norm(
+                    np.array([x_center, y_center]) - np.array([x_match, y_match])
+                )
+                distances.append((distance, match))
+            distances.sort(key=lambda x: x[0], reverse=False)
+            match = distances[0][1]
+            roi_front = list(match[1:])  # x,y,w,h
+            self.I_NORMAL_BATTLE_BUTTON.roi_front = roi_front
+            logger.info(f"Found normal battle button at {roi_front}")
+            return self.I_NORMAL_BATTLE_BUTTON
+        if self.appear(self.I_NORMAL_BATTLE_BUTTON):
+            return self.I_NORMAL_BATTLE_BUTTON
+        return None
+
+    def activate_realm_raid(self, con_scrolls, con) -> None:
+        # 判断是否开启突破票检测
+        if not con_scrolls.scrolls_enable:
+            return
+        self.screenshot()
+        if self.appear(self.I_E_EXPLORATION_CLICK) and self.appear(self.I_EXP_CREATE_TEAM):
+            cu, res, total = self.O_REALM_RAID_NUMBER1.ocr(self.device.image)
+        else:
+            cu, res, total = self.O_REALM_RAID_NUMBER.ocr(self.device.image)
+        # 判断突破票数量
+        if cu < con_scrolls.scrolls_threshold:
+            return
+
+        # 关闭加成
+        if self.appear(self.I_RED_CLOSE):
+            self.ui_click_until_disappear(self.I_RED_CLOSE)
+        if self.appear(self.I_UI_CANCEL):
+            self.ui_click_until_disappear(self.I_UI_CANCEL)
+        if self.appear(self.I_UI_CANCEL_SAMLL):
+            self.ui_click_until_disappear(self.I_UI_CANCEL_SAMLL)
+        self.ui_goto(page_main)
+        if con.buff_gold_50_click or con.buff_gold_100_click or con.buff_exp_50_click or con.buff_exp_100_click:
+            self.open_buff()
+            self.gold_50(is_open=False)
+            self.gold_100(is_open=False)
+            self.exp_50(is_open=False)
+            self.exp_100(is_open=False)
+            self.close_buff()
+
+        # 设置下次执行行时间
+        logger.info("RealmRaid and Exploration  set_next_run !")
+        next_run = datetime.now() + con_scrolls.scrolls_cd
+        self.set_next_run(task='Exploration', success=False, finish=False, target=next_run)
+        self.set_next_run(task='RealmRaid', success=False, finish=False, target=datetime.now())
+        raise TaskEnd
+
+    #
+    def check_exit(self) -> bool:
+        # True 表示要退出这个任务
+        if self.minions_cnt >= self._config.exploration_config.minions_cnt:
+            logger.info('Minions count is enough, exit')
+            return True
+        if datetime.now() - self.start_time >= self.limit_time:
+            logger.info('Exploration time limit out')
+            return True
+        self.activate_realm_raid(self._config.scrolls, self._config.exploration_config)
+        return False
+
+    def quit_explore(self):
+        logger.info('Quit explore')
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_UI_BACK_RED) and self.appear(self.I_E_EXPLORATION_CLICK):
+                break
+            if self.appear_then_click(self.I_E_EXIT_CONFIRM, interval=0.8):
+                continue
+            if self.appear_then_click(self.I_UI_BACK_BLUE, interval=1.5):
+                continue
+
+
+if __name__ == "__main__":
+    from module.config.config import Config
+    from module.device.device import Device
+
+    config = Config('oas1')
+    device = Device(config)
+    t = BaseExploration(config, device)
+    t.screenshot()
+
+    # IMAGE_FILE = r"C:\Users\萌萌哒\Desktop\QQ20240818-163854.png"
+    # image = load_image(IMAGE_FILE)
+    # t.device.image = image
+    while 1:
+    # print(t.search_up_fight(UpType.EXP))
+        t.screenshot()
+        print(t.I_UP_DARUMA.test_match(t.device.image))
+        time.sleep(0.2)
+    from PIL import Image
+    # Image.fromarray(t.device.image.astype(np.uint8)).show()
+

+ 30 - 18
tasks/Exploration/config.py

@@ -1,8 +1,11 @@
 from pydantic import BaseModel, Field
 from enum import Enum
+from datetime import datetime, time
+
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
 from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
-from tasks.Component.config_base import ConfigBase, TimeDelta
+from tasks.Component.GeneralInvite.config_invite import FindMode
+from tasks.Component.config_base import ConfigBase, TimeDelta, Time
 from tasks.Component.config_scheduler import Scheduler
 
 
@@ -42,11 +45,16 @@ class AttackNumber(str, Enum):
     ALL = 'all'
 
 
-# class AttackRole(str, Enum):
-#     exp = '经验'
-#     gold = '金币'
-#     box = '奖励'
-#     ALL = '无所谓'
+class UpType(str, Enum):
+    ALL = 'up_all'  # 全部
+    EXP = 'up_exp'  # 经验
+    COIN = 'up_coin'  # 金币
+    DARUMAA = 'up_daruma'  # 达摩
+
+class UserStatus(str, Enum):
+    LEADER = 'leader'
+    MEMBER = 'member'
+    ALONE = 'alone'
 
 
 # 是否自动添加候补式神
@@ -59,6 +67,12 @@ class ChooseRarity(str, Enum):
     N = 'N卡'
     S = '素材'
 
+class InviteConfig(BaseModel):
+
+    friend_1: str = Field(default='', description='friend_name_help')
+    find_mode: FindMode = Field(default=FindMode.AUTO_FIND, description='find_mode_help')
+    wait_time: Time = Field(default=Time(minute=2), description='wait_time_help')
+
 
 class Scrolls(BaseModel):
     # 绘卷模式
@@ -73,28 +87,26 @@ class ExplorationConfig(BaseModel):
     buff_exp_50_click: bool = Field(default=False)
     buff_exp_100_click: bool = Field(default=False)
 
-    # attack_number: AttackNumber = Field(title='探索次数', default=AttackNumber.SEVEN,
-    #                                     description='默认探索7次')
-
-    current_exploration_count: int = Field(title='探索次数', default='7', description='默认探索7次')
+    user_status: UserStatus = Field(default=UserStatus.ALONE, description='user_status_help_')
+    # current_exploration_count: int = Field(title='探索次数', default='7', description='默认探索7次')
+    limit_time: Time = Field(default=Time(minute=30), description='limit_time_help')
+    minions_cnt: int = Field(title='战斗次数', default='30', ge=0, description='minions_cnt_help')
 
     exploration_level: ExplorationLevel = Field(title='探索等级', default=ExplorationLevel.EXPLORATION_28,
-                                                description='探索等级 默认二十八')
+                                                description='exploration_level_help')
 
     auto_rotate: AutoRotate = Field(title='自动添加候补式神', default=AutoRotate.no,
-                                    description='自动添加候补式神 默认 否')
-
-    # attack_role: AttackRole = Field(title='进攻的类型',
-    #                                 default=AttackRole.ALL, description='攻击的类型')
+                                    description='auto_rotate_help')
 
-    choose_rarity: ChooseRarity = Field(title='选择狗粮稀有度', default=ChooseRarity.N, description='N')
+    choose_rarity: ChooseRarity = Field(title='选择狗粮稀有度', default=ChooseRarity.N, description='choose_rarity_help')
 
+    up_type: UpType = Field(title='UpType', default=UpType.ALL, description='up_type_help')
 
 class Exploration(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
     exploration_config: ExplorationConfig = Field(default_factory=ExplorationConfig)
     scrolls: Scrolls = Field(default_factory=Scrolls)
+    invite_config: InviteConfig = Field(default_factory=InviteConfig)
     general_battle_config: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
     switch_soul_config: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)
-    # auto_rotate_after_times: str = Field(default='30', description='探索30次后, 检测是否需要添加候补式神')
-    # go_to_realm_after_times: str = Field(default='5', description='探索5次后, 检测是否需要进行结界突破')
+

BIN
tasks/Exploration/highlight/highlight_light1.png


BIN
tasks/Exploration/highlight/highlight_light10.png


BIN
tasks/Exploration/highlight/highlight_light11.png


BIN
tasks/Exploration/highlight/highlight_light12.png


BIN
tasks/Exploration/highlight/highlight_light13.png


BIN
tasks/Exploration/highlight/highlight_light14.png


BIN
tasks/Exploration/highlight/highlight_light2.png


BIN
tasks/Exploration/highlight/highlight_light3.png


BIN
tasks/Exploration/highlight/highlight_light4.png


BIN
tasks/Exploration/highlight/highlight_light5.png


BIN
tasks/Exploration/highlight/highlight_light6.png


BIN
tasks/Exploration/highlight/highlight_light7.png


BIN
tasks/Exploration/highlight/highlight_light8.png


BIN
tasks/Exploration/highlight/highlight_light9.png


BIN
tasks/Exploration/highlight/highlight_lighttest.png


BIN
tasks/Exploration/highlight/highlight_up_coin - 副本.png


BIN
tasks/Exploration/highlight/highlight_up_coin.png


BIN
tasks/Exploration/highlight/highlight_up_daruma - 副本.png


BIN
tasks/Exploration/highlight/highlight_up_daruma.png


BIN
tasks/Exploration/highlight/highlight_up_exp - 副本.png


BIN
tasks/Exploration/highlight/highlight_up_exp.png


+ 164 - 0
tasks/Exploration/highlight/image.json

@@ -0,0 +1,164 @@
+[
+  {
+    "itemName": "lighttest",
+    "imageName": "highlight_lighttest.png",
+    "roiFront": "550,288,85,82",
+    "roiBack": "97,182,1130,409",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light1",
+    "imageName": "highlight_light1.png",
+    "roiFront": "498,297,86,87",
+    "roiBack": "97,182,1130,409",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light2",
+    "imageName": "highlight_light2.png",
+    "roiFront": "497,300,86,82",
+    "roiBack": "97,182,1130,409",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light3",
+    "imageName": "highlight_light3.png",
+    "roiFront": "495,301,85,77",
+    "roiBack": "97,182,1130,409",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light4",
+    "imageName": "highlight_light4.png",
+    "roiFront": "496,296,85,85",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light5",
+    "imageName": "highlight_light5.png",
+    "roiFront": "494,296,82,86",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light6",
+    "imageName": "highlight_light6.png",
+    "roiFront": "490,295,83,85",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light7",
+    "imageName": "highlight_light7.png",
+    "roiFront": "486,295,84,87",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light8",
+    "imageName": "highlight_light8.png",
+    "roiFront": "485,298,84,81",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light9",
+    "imageName": "highlight_light9.png",
+    "roiFront": "484,295,85,84",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light10",
+    "imageName": "highlight_light10.png",
+    "roiFront": "479,297,84,78",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light11",
+    "imageName": "highlight_light11.png",
+    "roiFront": "479,296,83,82",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light12",
+    "imageName": "highlight_light12.png",
+    "roiFront": "477,290,85,90",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light13",
+    "imageName": "highlight_light13.png",
+    "roiFront": "478,293,82,87",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "light14",
+    "imageName": "highlight_light14.png",
+    "roiFront": "474,290,82,87",
+    "roiBack": "0,0,100,100",
+    "method": "Template matching",
+    "threshold": 0.6,
+    "description": "description"
+  },
+  {
+    "itemName": "up_exp",
+    "imageName": "highlight_up_exp.png",
+    "roiFront": "471,518,74,71",
+    "roiBack": "1,225,1278,410",
+    "method": "Sift Flann",
+    "threshold": 0.8,
+    "description": "经验怪"
+  },
+  {
+    "itemName": "up_coin",
+    "imageName": "highlight_up_coin.png",
+    "roiFront": "330,529,74,74",
+    "roiBack": "1,317,1278,316",
+    "method": "Sift Flann",
+    "threshold": 0.8,
+    "description": "金币怪"
+  },
+  {
+    "itemName": "up_daruma",
+    "imageName": "highlight_up_daruma.png",
+    "roiFront": "1146,510,80,80",
+    "roiBack": "1,265,1278,369",
+    "method": "Sift Flann",
+    "threshold": 0.8,
+    "description": "达摩怪"
+  }
+]

+ 6 - 0
tasks/Exploration/res/click.json

@@ -46,5 +46,11 @@
     "roiFront": "921,590,21,21",
     "roiBack": "921,590,21,21",
     "description": "位置4"
+  },
+  {
+    "itemName": "safe_random",
+    "roiFront": "0,0,111,12",
+    "roiBack": "0,0,111,12",
+    "description": "随机点"
   }
 ]

+ 36 - 0
tasks/Exploration/res/image.json

@@ -178,5 +178,41 @@
     "method": "Template matching",
     "threshold": 0.7,
     "description": "宝箱"
+  },
+  {
+    "itemName": "swipe_end",
+    "imageName": "res_swipe_end.png",
+    "roiFront": "994,234,119,100",
+    "roiBack": "968,196,311,165",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "困28滚动到最后"
+  },
+  {
+    "itemName": "team_emoji",
+    "imageName": "res_team_emoji.png",
+    "roiFront": "36,437,44,46",
+    "roiBack": "4,407,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "队伍的表情标志"
+  },
+  {
+    "itemName": "exp_create_team",
+    "imageName": "res_exp_create_team.png",
+    "roiFront": "590,514,122,52",
+    "roiBack": "543,490,192,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "组队按钮"
+  },
+  {
+    "itemName": "exp_create_ensure",
+    "imageName": "res_exp_create_ensure.png",
+    "roiFront": "534,486,218,59",
+    "roiBack": "516,475,244,85",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "创建确认"
   }
 ]

+ 30 - 0
tasks/Exploration/res/long_click.json

@@ -0,0 +1,30 @@
+[
+  {
+    "itemName": "rotate_1",
+    "roiFront": "516,582,22,21",
+    "roiBack": "516,582,22,21",
+    "duration": 1500,
+    "description": "description"
+  },
+  {
+    "itemName": "rotate_2",
+    "roiFront": "650,587,21,21",
+    "roiBack": "650,587,21,21",
+    "duration": 1500,
+    "description": "description"
+  },
+  {
+    "itemName": "rotate_3",
+    "roiFront": "785,587,21,21",
+    "roiBack": "785,587,21,21",
+    "duration": 1500,
+    "description": "description"
+  },
+  {
+    "itemName": "rotate_4",
+    "roiFront": "921,590,21,21",
+    "roiBack": "921,590,21,21",
+    "duration": 1500,
+    "description": "description"
+  }
+]

BIN
tasks/Exploration/res/res_exp_create_ensure.png


BIN
tasks/Exploration/res/res_exp_create_team.png


BIN
tasks/Exploration/res/res_swipe_end.png


BIN
tasks/Exploration/res/res_team_emoji.png


+ 4 - 282
tasks/Exploration/script_task.py

@@ -11,292 +11,15 @@ from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.page import page_exploration, page_shikigami_records, page_main
 from tasks.RealmRaid.script_task import ScriptTask as RealmRaidScriptTask
+from tasks.Exploration.solo import ScriptTask as SoloScriptTask
 
 from module.logger import logger
 from module.exception import RequestHumanTakeover, TaskEnd
 from module.atom.image_grid import ImageGrid
 
 
-class ScriptTask(GeneralBattle, GameUi, SwitchSoul, ExplorationAssets):
-    medal_grid: ImageGrid = None
-
-    def run(self):
-        """
-        执行
-        :return:
-        """
-        # 探索的 config
-        explorationConfig = self.config.exploration
-
-        # 切换御魂
-        if explorationConfig.switch_soul_config.enable:
-            self.ui_get_current_page()
-            self.ui_goto(page_shikigami_records)
-            self.run_switch_soul(explorationConfig.switch_soul_config.switch_group_team)
-
-        if explorationConfig.switch_soul_config.enable_switch_by_name:
-            self.ui_get_current_page()
-            self.ui_goto(page_shikigami_records)
-            self.run_switch_soul_by_name(explorationConfig.switch_soul_config.group_name,
-                                         explorationConfig.switch_soul_config.team_name)
-
-        # 开启加成
-        con = self.config.exploration.exploration_config
-        if con.buff_gold_50_click or con.buff_gold_100_click or con.buff_exp_50_click or con.buff_exp_100_click:
-            self.ui_get_current_page()
-            self.ui_goto(page_main)
-            self.open_buff()
-            if con.buff_gold_50_click:
-                self.gold_50()
-            if con.buff_gold_100_click:
-                self.gold_100()
-            if con.buff_exp_50_click:
-                self.exp_50()
-            if con.buff_exp_100_click:
-                self.exp_100()
-            self.close_buff()
-
-        self.ui_get_current_page()
-        # 探索页面
-        self.ui_goto(page_exploration)
-
-        # ************************* 跳转至对应指定章节并进入 *******************
-        # 默认全部解锁, 当前处于第二十八章
-        # 查找指定的章节:
-        if not self.open_expect_level():
-            logger.critical(f'Not find {explorationConfig.exploration_config.exploration_level} or'
-                            f' Enter {explorationConfig.exploration_config.exploration_level} failed!')
-            raise RequestHumanTakeover
-        con_scrolls = self.config.exploration.scrolls
-        # 判断是否绘卷模式,设置探索次数
-        if con_scrolls.scrolls_enable:
-            exploration_count = 50
-        else:
-            exploration_count = explorationConfig.exploration_config.current_exploration_count
-
-        logger.info("exploration_count:" + str(exploration_count))
-        if exploration_count > 0:
-            count = 0
-            while count < exploration_count:
-                if self.wait_until_appear(self.I_E_EXPLORATION_CLICK, wait_time=1):
-                    # 绘卷模式
-                    self.activate_realm_raid(con_scrolls,con)
-
-                    self.click(self.I_E_EXPLORATION_CLICK)
-                    count += 1
-                    logger.info("exploration count :" + str(count))
-                    # 进入战斗环节
-                    self.battle_process()
-                # 判断宝箱
-                if self.appear(self.I_TREASURE_BOX_CLICK):
-                    self.click(self.I_TREASURE_BOX_CLICK)
-                    self.open_expect_level()
-                # 判断妖气
-                elif self.appear(self.I_EXPLORATION_TITLE):
-                    self.open_expect_level()
-
-            if self.wait_until_appear(self.I_RED_CLOSE, wait_time=2):
-                self.appear_then_click(self.I_RED_CLOSE)
-            self.ui_goto(page_main)
-            # 关闭 buff
-            if con.buff_gold_50_click or con.buff_gold_100_click or con.buff_exp_50_click or con.buff_exp_100_click:
-                self.open_buff()
-                self.gold_50(is_open=False)
-                self.gold_100(is_open=False)
-                self.exp_50(is_open=False)
-                self.exp_100(is_open=False)
-                self.close_buff()
-            self.set_next_run(task='Exploration', success=True, finish=False)
-        raise TaskEnd
-
-    # 查找指定的章节:
-    def open_expect_level(self):
-        swipeCount = 0
-        while 1:
-            # 探索的 config
-            explorationConfig = self.config.exploration
-
-            # 判断有无目标章节
-            self.screenshot()
-            # 获取当前章节名
-            results = self.O_E_EXPLORATION_LEVEL_NUMBER.detect_and_ocr(self.device.image)
-            text1 = [result.ocr_text for result in results]
-            # 判断当前章节有无目标章节
-            result = set(text1).intersection({explorationConfig.exploration_config.exploration_level})
-            # 有则跳出检测
-            if self.appear(self.I_E_EXPLORATION_CLICK) or result and len(result) > 0:
-                break
-            self.device.click_record_clear()
-            self.swipe(self.S_SWIPE_LEVEL_UP)
-            swipeCount += 1
-            if swipeCount >= 25:
-                return False
-
-        # 选中对应章节
-        while 1:
-            self.screenshot()
-            self.O_E_EXPLORATION_LEVEL_NUMBER.keyword = explorationConfig.exploration_config.exploration_level
-            if self.ocr_appear_click(self.O_E_EXPLORATION_LEVEL_NUMBER):
-                self.wait_until_appear(self.I_E_EXPLORATION_CLICK, wait_time=3)
-            if self.appear(self.I_E_EXPLORATION_CLICK):
-                break
-
-        return True
-
-    # 候补:
-    def enter_settings_and_do_operations(self):
-        # 打开设置
-        self.click(self.C_CLICK_SETTINGS)
-        while 1:
-            self.screenshot()
-            if self.appear(self.I_E_OPEN_SETTINGS):
-                break
-            else:
-                self.click(self.C_CLICK_SETTINGS)
-                if self.wait_until_appear(self.I_E_OPEN_SETTINGS):
-                    break
-        # 候补出战数量识别
-        self.screenshot()
-        cu, res, total = self.O_E_ALTERNATE_NUMBER.ocr(self.device.image)
-        if cu >= 40:
-            self.appear_then_click(self.I_E_SURE_BUTTON)
-            return
-        else:
-            self.add_shiki()
-
-    # 添加式神
-    def add_shiki(self):
-        self.screenshot()
-        # 点击展开式神稀有度选择界面
-        self.click(self.C_CLICK_ALL_SHIKI)
-        while 1:
-            self.screenshot()
-            # 成功进入稀有度选择界面
-            if self.appear(self.I_E_ENTER_CHOOSE_RARITY):
-                if self.config.exploration.exploration_config.choose_rarity == ChooseRarity.N:
-                    # N 卡
-                    self.click(self.C_CLICK_N_SHIKI)
-                else:
-                    # 素材卡
-                    self.appear_then_click(self.I_E_ENTER_CHOOSE_RARITY)
-            self.screenshot()
-            if self.appear(self.I_E_N_RARITY):
-                # 进入N卡添加界面  退出
-                break
-            if self.appear(self.I_E_S_RARITY):
-                # 进入素材添加界面 退出
-                break
-        # 选中候补出战框
-        self.click(self.C_CLICK_STANDBY_TEAM)
-        # 移动至未候补的狗粮
-        while 1:
-            # 慢一点
-            time.sleep(0.5)
-            self.screenshot()
-            if self.appear(self.I_E_RATATE_EXSIT):
-                self.swipe(self.S_SWIPE_SHIKI_TO_LEFT)
-            else:
-                break
-        while 1:
-            # 候补出战数量识别
-            self.screenshot()
-            cu, res, total = self.O_E_ALTERNATE_NUMBER.ocr(self.device.image)
-            if cu >= 40:
-                break
-            self.swipe(self.S_SWIPE_SHIKI_TO_LEFT_ONE)
-            # 慢一点
-            time.sleep(0.5)
-            self.screenshot()
-            self.click(self.C_CLICK_ROTATE_1)
-            self.device.click_record_clear()
-
-        self.appear_then_click(self.I_E_SURE_BUTTON)
-
-    # 探索战斗流程
-    def do_battle(self):
-        while 1:
-            self.screenshot()
-            # 战后奖励
-            if self.appear(self.I_BATTLE_REWARD) and not self.appear(self.I_GET_REWARD):
-                self.click(self.I_BATTLE_REWARD)
-            # boss 战
-            if self.appear_then_click(self.I_BOSS_BATTLE_BUTTON):
-                if self.wait_until_appear(self.I_BATTLE_START, wait_time=5):
-                    self.run_general_battle(self.config.exploration.general_battle_config)
-                else:
-                    continue
-            # 小怪 战
-            if self.appear_then_click(self.I_NORMAL_BATTLE_BUTTON):
-                if self.wait_until_appear(self.I_BATTLE_START, wait_time=5):
-                    self.run_general_battle(self.config.exploration.general_battle_config)
-                else:
-                    continue
-            # 滑动
-            elif self.appear(self.I_E_AUTO_ROTATE_ON) or self.appear(self.I_GET_REWARD):
-                self.swipe(self.S_SWIPE_BACKGROUND_RIGHT)
-            # 结束流程
-            if self.appear(self.I_E_EXPLORATION_CLICK) or self.appear(self.I_EXPLORATION_TITLE):
-                break
-
-    # 战斗流程
-    def battle_process(self):
-        # 进入指定章节
-        self.screenshot()
-        if self.appear_then_click(self.I_E_EXPLORATION_CLICK):
-            self.appear_then_click(self.I_E_SETTINGS_BUTTON)
-
-        # ************************* 进入设置并操作 *******************
-        # 候补以及自动轮换打开:
-        # 自动轮换功能打开
-        while 1:
-            self.screenshot()
-            # 自动轮换开着 则跳过
-            if self.appear(self.I_E_AUTO_ROTATE_ON):
-                break
-            # 自动轮换关着 则打开
-            if self.appear_then_click(self.I_E_AUTO_ROTATE_OFF):
-                if self.appear(self.I_E_AUTO_ROTATE_ON):
-                    break
-
-        # 自动添加候补式神
-        if self.config.exploration.exploration_config.auto_rotate == AutoRotate.yes:
-            self.enter_settings_and_do_operations()
-        
-        # 修复卡结算问题
-        # 卡结算是因为没有设置锁定队伍,修改后无论是否锁定都不会因为没有锁定队伍而卡在结算界面
-        if not self.config.exploration.general_battle_config.lock_team_enable:
-            self.config.exploration.general_battle_config.lock_team_enable = True
-
-        # 进入战斗环节
-        self.do_battle()
-
-    def activate_realm_raid(self, con_scrolls, con) -> None:
-        # 判断是否开启突破票检测
-        if not con_scrolls.scrolls_enable:
-            return
-        self.screenshot()
-        cu, res, total = self.O_REALM_RAID_NUMBER1.ocr(self.device.image)
-        # 判断突破票数量
-        if cu < con_scrolls.scrolls_threshold:
-            return
-
-        # 关闭加成
-        self.appear_then_click(self.I_RED_CLOSE)
-        self.ui_goto(page_main)
-        if con.buff_gold_50_click or con.buff_gold_100_click or con.buff_exp_50_click or con.buff_exp_100_click:
-            self.open_buff()
-            self.gold_50(is_open=False)
-            self.gold_100(is_open=False)
-            self.exp_50(is_open=False)
-            self.exp_100(is_open=False)
-            self.close_buff()
-
-        # 设置下次执行行时间
-        logger.info("RealmRaid and Exploration  set_next_run !")
-        next_run = datetime.now() + con_scrolls.scrolls_cd
-        self.set_next_run(task='Exploration', success=False, finish=False, target=next_run)
-        self.set_next_run(task='RealmRaid', success=False, finish=False, target=datetime.now())
-        raise TaskEnd
+class ScriptTask(SoloScriptTask):
+    pass
 
 
 if __name__ == "__main__":
@@ -308,5 +31,4 @@ if __name__ == "__main__":
     t = ScriptTask(config, device)
     t.config.exploration.exploration_config.exploration_level = '第二十八章'
     t.run()
-    # t.battle_process()
-    # t.enter_settings_and_do_operations()
+

+ 466 - 0
tasks/Exploration/solo.py

@@ -0,0 +1,466 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from time import sleep
+from cached_property import cached_property
+
+from module.logger import logger
+from module.base.timer import Timer
+
+
+from tasks.Component.GeneralInvite.config_invite import InviteConfig, InviteNumber, FindMode
+from tasks.Exploration.base import BaseExploration, UpType, Scene
+from tasks.Exploration.config import ChooseRarity, AutoRotate, UserStatus
+
+class SoloExploration(BaseExploration):
+    INVITE_FLAG_OFF = (157, 109, 83)
+    INVITE_FLAG_ON = (227, 193, 153)
+
+    @cached_property
+    def _invite_config(self) -> InviteConfig:
+        return InviteConfig(
+            invite_number=InviteNumber.ONE,
+            friend_1=self._config.invite_config.friend_1,
+            friend_2='',
+            find_mode=self._config.invite_config.find_mode,
+            wait_time=self._config.invite_config.wait_time,
+            default_invite=False
+        )
+
+    def run_solo(self):
+        logger.hr('solo')
+        explore_init = False
+        search_fail_cnt = 0
+
+        while 1:
+            self.screenshot()
+            scene = self.get_current_scene()
+
+            #
+            if scene == Scene.WORLD:
+                if self.appear(self.I_TREASURE_BOX_CLICK):
+                    # 宝箱
+                    logger.info('Treasure box appear, get it.')
+                    self.ui_click_until_disappear(self.I_TREASURE_BOX_CLICK)
+                if self.check_exit():
+                    break
+                self.open_expect_level()
+                explore_init = False
+                continue
+            #
+            elif scene == Scene.ENTRANCE:
+                if self.check_exit():
+                    break
+                self.ui_click(self.I_E_EXPLORATION_CLICK, stop=self.I_E_SETTINGS_BUTTON)
+                explore_init = False
+                continue
+            #
+            elif scene == Scene.MAIN:
+                if not explore_init:
+                    self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON)
+                    if self._config.exploration_config.auto_rotate == AutoRotate.yes:
+                        self.enter_settings_and_do_operations()
+                    explore_init = True
+                    continue
+                # 小纸人
+                if self.appear(self.I_BATTLE_REWARD):
+                    if self.ui_get_reward(self.I_BATTLE_REWARD):
+                        continue
+                # boss
+                if self.appear(self.I_BOSS_BATTLE_BUTTON):
+                    self.ui_click_until_disappear(self.I_BOSS_BATTLE_BUTTON)
+                    self.run_general_battle(self._config.general_battle_config)
+                    self.minions_cnt += 1
+                    logger.info(f'Boss battle, minions cnt {self.minions_cnt}')
+                    continue
+                # 小怪
+                fight_button = self.search_up_fight()
+                if fight_button is not None:
+                    self.ui_click_until_disappear(fight_button)
+                    self.run_general_battle(self._config.general_battle_config)
+                    self.minions_cnt += 1
+                    logger.info(f'Fight, minions cnt {self.minions_cnt}')
+                    continue
+                # 向后拉,寻找怪
+                if search_fail_cnt >= 4:
+                    search_fail_cnt = 0
+                    if self.appear(self.I_SWIPE_END):
+                        self.quit_explore()
+                        continue
+                    if self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3):
+                        continue
+                else:
+                    search_fail_cnt += 1
+            #
+            elif scene == Scene.BATTLE_PREPARE or scene == Scene.BATTLE_FIGHTING:
+                self.check_take_over_battle(is_screenshot=False, config=self._config.general_battle_config)
+            elif scene == Scene.UNKNOWN:
+                continue
+
+    def run_leader(self):
+        logger.hr('leader')
+        explore_init = False
+        search_fail_cnt = 0
+        friend_leave_timer = Timer(10)
+
+        while 1:
+            self.screenshot()
+            scene = self.get_current_scene()
+            # 探索大世界
+            if scene == Scene.WORLD:
+                self.wait_until_stable(self.I_CHECK_EXPLORATION)
+                if self.appear(self.I_TREASURE_BOX_CLICK):
+                    # 宝箱
+                    logger.info('Treasure box appear, get it.')
+                    self.wait_until_stable(self.I_UI_CANCEL, timer=Timer(0.6, 1))
+                    while 1:
+                        self.screenshot()
+                        if self.appear(self.I_REWARD):
+                            self.ui_click_until_disappear(self.I_REWARD)
+                            logger.info('Get reward.')
+                            break
+                        if self.ui_reward_appear_click():
+                            continue
+                        if self.appear_then_click(self.I_UI_CANCEL, interval=0.8):
+                            continue
+                        if self.appear_then_click(self.I_TREASURE_BOX_CLICK, interval=1):
+                            continue
+                if self.check_exit():
+                    self.wait_until_stable(self.I_UI_CANCEL, timer=Timer(0.6, 2))
+                    if self.appear(self.I_UI_CANCEL):
+                        self.ui_click_until_disappear(self.I_UI_CANCEL)
+                    break
+                if self.appear(self.I_UI_CONFIRM):
+                    self.ui_click_until_disappear(self.I_UI_CONFIRM)
+                    # 可以加一下,清空第一次 explore_init
+                    continue
+                self.open_expect_level()
+                explore_init = False
+                continue
+
+            # 邀请好友, 非常有可能是后面邀请好友,然后直接跳到组队了
+            elif scene == Scene.ENTRANCE:
+                while 1:
+                    self.screenshot()
+                    if self.is_in_room():
+                        break
+                    if self.appear_then_click(self.I_ENSURE_PRIVATE_FALSE, interval=0.5):
+                        continue
+                    if self.appear_then_click(self.I_ENSURE_PRIVATE_FALSE_2, interval=0.5):
+                        continue
+                    if self.appear_then_click(self.I_EXP_CREATE_TEAM, interval=1):
+                        continue
+                    if self.appear_then_click(self.I_EXP_CREATE_ENSURE, interval=2):
+                        continue
+            #
+            elif scene == Scene.TEAM:
+                self.wait_until_stable(self.I_ADD_2, timer=Timer(0.8, 1))
+                if self.appear(self.I_FIRE, threshold=0.8) and not self.appear(self.I_ADD_2):
+                    self.ui_click_until_disappear(self.I_FIRE, interval=1)
+                    continue
+                if self.run_invite(config=self._invite_config, is_first=True):
+                    continue
+                else:
+                    logger.warning('Invite failed, quit')
+                    while 1:
+                        self.screenshot()
+                        if self.appear(self.I_CHECK_EXPLORATION):
+                            break
+                        if self.appear_then_click(self.I_UI_CONFIRM, interval=0.5):
+                            continue
+                        if self.appear_then_click(self.I_UI_BACK_RED, interval=0.7):
+                            continue
+                        if self.appear_then_click(self.I_UI_BACK_YELLOW, interval=1):
+                            continue
+                    break
+            ##
+            elif scene == Scene.MAIN:
+                if not explore_init:
+                    self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON)
+                    if self._config.exploration_config.auto_rotate == AutoRotate.yes:
+                        self.enter_settings_and_do_operations()
+                    friend_leave_timer = Timer(10)
+                    explore_init = True
+                    continue
+                # 小纸人
+                if self.appear(self.I_BATTLE_REWARD):
+                    if self.ui_get_reward(self.I_BATTLE_REWARD):
+                        continue
+                # 中途有人跑路
+                if not self.appear(self.I_TEAM_EMOJI):
+                    if not friend_leave_timer.started():
+                        logger.warning('Mate leave, start timer')
+                        friend_leave_timer = Timer(10)
+                        friend_leave_timer.start()
+                    elif friend_leave_timer.started() and friend_leave_timer.reached():
+                        logger.warning('Mate leave timer reached')
+                        logger.warning('Exit team')
+                        self.quit_explore()
+                        continue
+                # boss
+                if self.appear(self.I_BOSS_BATTLE_BUTTON):
+                    self.ui_click_until_disappear(self.I_BOSS_BATTLE_BUTTON, interval=4)
+                    self.run_general_battle(self._config.general_battle_config)
+                    self.minions_cnt += 1
+                    friend_leave_timer = Timer(10)
+                    logger.info(f'Boss battle, minions cnt {self.minions_cnt}')
+                    continue
+                # 小怪
+                fight_button = self.search_up_fight()
+                if fight_button is not None:
+                    self.ui_click_until_disappear(fight_button, interval=3)
+                    self.run_general_battle(self._config.general_battle_config)
+                    self.minions_cnt += 1
+                    logger.info(f'Fight, minions cnt {self.minions_cnt}')
+                    continue
+                # 向后拉,寻找怪
+                if search_fail_cnt >= 4:
+                    search_fail_cnt = 0
+                    if self.appear(self.I_SWIPE_END):
+                        self.quit_explore()
+                        continue
+                    if self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=4.5):
+                        continue
+                else:
+                    search_fail_cnt += 1
+            #
+            elif scene == Scene.BATTLE_PREPARE or scene == Scene.BATTLE_FIGHTING:
+                self.check_take_over_battle(is_screenshot=False, config=self._config.general_battle_config)
+            elif scene == Scene.UNKNOWN:
+                continue
+
+    def run_member(self):
+        logger.hr('member')
+        explore_init = False
+        wait_timer = Timer(50)
+        friend_leave_timer = Timer(10)
+
+        while 1:
+            self.screenshot()
+            scene = self.get_current_scene()
+            #
+            if scene == Scene.WORLD:
+                if self.appear(self.I_TREASURE_BOX_CLICK):
+                    # 宝箱
+                    logger.info('Treasure box appear, get it.')
+                    self.ui_click_until_disappear(self.I_TREASURE_BOX_CLICK)
+                if self.check_exit():
+                    break
+                if self.check_then_accept():
+                    pass
+                if wait_timer.started() and wait_timer.reached():
+                    logger.warning('Wait timer reached')
+                    break
+
+                explore_init = False
+                continue
+            #
+            elif scene == Scene.ENTRANCE:
+                self.ui_click_until_disappear(self.I_UI_BACK_RED)
+            #
+            elif scene == Scene.TEAM:
+                continue
+            #
+            elif scene == Scene.MAIN:
+                if not explore_init:
+                    self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON)
+                    if self._config.exploration_config.auto_rotate == AutoRotate.yes:
+                        self.enter_settings_and_do_operations()
+                    explore_init = True
+                    continue
+                # 小纸人
+                if self.appear(self.I_BATTLE_REWARD):
+                    if self.ui_get_reward(self.I_BATTLE_REWARD):
+                        continue
+                #
+                if not self.appear(self.I_TEAM_EMOJI):
+                    logger.warning('Team emoji not appear')
+                    if not friend_leave_timer.started():
+                        logger.warning('Mate leave, start timer')
+                        friend_leave_timer = Timer(10)
+                        friend_leave_timer.start()
+                    elif friend_leave_timer.started() and friend_leave_timer.reached():
+                        logger.warning('Mate leave timer reached')
+                        logger.warning('Exit team')
+                        self.quit_explore()
+                        wait_timer = Timer(50)
+                        wait_timer.start()
+                        continue
+            #
+            elif scene == Scene.BATTLE_PREPARE or scene == Scene.BATTLE_FIGHTING:
+                self.check_take_over_battle(is_screenshot=False, config=self._config.general_battle_config)
+            elif scene == Scene.UNKNOWN:
+                continue
+
+    def invite_friend(self, name: str = None, find_mode: FindMode = FindMode.AUTO_FIND) -> bool:
+        logger.info('Click add to invite friend')
+        # 点击+号
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_LOAD_FRIEND):
+                break
+            if self.appear(self.I_INVITE_ENSURE):
+                break
+            if self.appear_then_click(self.I_ADD_2, interval=1):
+                continue
+            if self.appear_then_click(self.I_ADD_5_4, interval=1):
+                continue
+
+        friend_class = []
+        class_ocr = [self.O_F_LIST_1, self.O_F_LIST_2, self.O_F_LIST_3, self.O_F_LIST_4]
+        class_index = 0
+        list_1 = self.O_F_LIST_1.ocr(self.device.image)
+        list_2 = self.O_F_LIST_2.ocr(self.device.image)
+        list_3 = self.O_F_LIST_3.ocr(self.device.image)
+        list_4 = self.O_F_LIST_4.ocr(self.device.image)
+        list_1 = list_1.replace(' ', '').replace('、', '')
+        list_2 = list_2.replace(' ', '').replace('、', '')
+        list_3 = list_3.replace(' ', '').replace('、', '')
+        if list_1 is not None and list_1 != '' and list_1 in self.friend_class:
+            friend_class.append(list_1)
+        if list_2 is not None and list_2 != '' and list_2 in self.friend_class:
+            friend_class.append(list_2)
+        if list_3 is not None and list_3 != '' and list_3 in self.friend_class:
+            friend_class.append(list_3)
+        if list_4 is not None and list_4 != '' and list_4 in self.friend_class:
+            friend_class.append(list_4)
+        for i in range(len(friend_class)):
+            if friend_class[i] == '蔡友':
+                friend_class[i] = '寮友'
+            elif friend_class[i] == '路区':
+                friend_class[i] = '跨区'
+            elif friend_class[i] == '察友':
+                friend_class[i] = '寮友'
+            elif friend_class[i] == '区':
+                friend_class[i] = '跨区'
+        logger.info(f'Friend class: {friend_class}')
+
+        is_select: bool = False  # 是否选中了好友
+        if find_mode == FindMode.RECENT_FRIEND:
+            logger.info('Find recent friend')
+            # 获取’最近‘在friend_class中的index
+            if '最近' not in friend_class:
+                logger.warning('No recent friend')
+                return False
+            recent_index = friend_class.index('最近')
+            while recent_index == 1:
+                self.screenshot()
+                if self.appear(self.I_FLAG_2_ON):
+                    break
+                if self.appear_then_click(self.I_FLAG_2_OFF, interval=1):
+                    continue
+
+            logger.info(f'Now find friend in ”最近“')
+            sleep(1)
+            if not is_select:
+                if self.detect_select(name):
+                    is_select = True
+            sleep(1)
+            if not is_select:
+                if self.detect_select(name):
+                    is_select = True
+
+        for index in range(len(friend_class)):
+            # 如果不是自动寻找,就跳过
+            if find_mode != FindMode.AUTO_FIND:
+                continue
+            # 如果已经选中了好友,就不需要再选中了
+            if is_select:
+                continue
+            # 首先切换到不同的好友列表
+            while index == 0:
+                self.screenshot()
+                if self.I_FLAG_1_ON.match_mean_color(self.device.image, self.INVITE_FLAG_ON, 10):
+                    break
+                if self.click(self.I_FLAG_1_OFF, interval=1):
+                    continue
+            while index == 1:
+                self.screenshot()
+                if self.I_FLAG_2_ON.match_mean_color(self.device.image, self.INVITE_FLAG_ON, 10):
+                    break
+                if self.click(self.I_FLAG_2_OFF, interval=1):
+                    continue
+            while index == 2:
+                self.screenshot()
+                if self.I_FLAG_3_ON.match_mean_color(self.device.image, self.INVITE_FLAG_ON, 10):
+                    break
+                if self.click(self.I_FLAG_3_OFF, interval=1):
+                    continue
+            while index == 3:
+                self.screenshot()
+                if self.I_FLAG_4_ON.match_mean_color(self.device.image, self.INVITE_FLAG_ON, 10):
+                    break
+                if self.click(self.I_FLAG_4_OFF, interval=1):
+                    continue
+
+            # 选中好友, 在这里游戏获取在线的好友并不是很快,根据不同的设备会有不同的时间,而且没有什么元素提供我们来判断
+            # 所以这里就直接等待一段时间
+            logger.info(f'Now find friend in {friend_class[index]}')
+            sleep(1)
+            if not is_select:
+                if self.detect_select(name):
+                    is_select = True
+            sleep(1)
+            if not is_select:
+                if self.detect_select(name):
+                    is_select = True
+
+        # 点击确定
+        logger.info('Click invite ensure')
+        if not self.appear(self.I_INVITE_ENSURE):
+            logger.warning('No appear invite ensure while invite friend')
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_INVITE_ENSURE):
+                break
+            if self.appear_then_click(self.I_INVITE_ENSURE):
+                continue
+        # 哪怕没有找到好友也有点击 确认 以退出好友列表
+        if not is_select:
+            logger.warning('No find friend')
+            # 这个时候任务运行失败
+            logger.info('Task failed')
+            return False
+
+        return True
+
+
+class ScriptTask(SoloExploration):
+    def run(self):
+        logger.hr('exploration')
+        random_click_cnt = 0
+        while 1:
+            self.screenshot()
+            scene = self.get_current_scene()
+            if random_click_cnt >= 2:
+                break
+            if scene == Scene.UNKNOWN:
+                logger.warning('Unknown scene, random click')
+                if self.click(self.C_SAFE_RANDOM, interval=1.5):
+                    random_click_cnt += 1
+                continue
+            else:
+                break
+
+        if scene == Scene.UNKNOWN:
+            self.pre_process()
+
+        match self._config.exploration_config.user_status:
+            case UserStatus.ALONE: self.run_solo()
+            case UserStatus.LEADER: self.run_leader()
+            case UserStatus.MEMBER: self.run_member()
+            case _: self.run_solo()
+
+
+        self.post_process()
+
+
+if __name__ == "__main__":
+    from module.config.config import Config
+    from module.device.device import Device
+
+    config = Config('oas1')
+    device = Device(config)
+    t = ScriptTask(config, device)
+    t.run()
+

+ 94 - 0
tasks/Exploration/version.py

@@ -0,0 +1,94 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import cv2
+import numpy as np
+
+from pathlib import Path
+from cached_property import cached_property
+
+from module.base.utils import color_similarity_2d, load_image, save_image
+from module.atom.gif import RuleGif
+from module.atom.image import RuleImage
+
+from tasks.base_task import BaseTask
+from tasks.Exploration.assets import ExplorationAssets
+from dev_tools.assets_test import detect_image
+
+
+class Version(BaseTask):
+    pass
+
+
+def apply_mask(image, mask):
+    image16 = image.astype(np.uint16)
+    mask16 = mask.astype(np.uint16)
+    mask16 = cv2.merge([mask16, mask16, mask16])
+    image16 = cv2.multiply(image16, mask16)
+    # cv2.multiply(image16, mask16, dst=image16)
+    image16 = cv2.convertScaleAbs(image16, alpha=1 / 255)
+    # cv2.convertScaleAbs(image16, alpha=1 / 255, dst=image16)
+    # Image.fromarray(image16.astype(np.uint8)).show()
+    return image16.astype(np.uint8)
+
+def highlight(image):
+    yuv = cv2.cvtColor(image, cv2.COLOR_RGB2YUV)
+    _, u, _ = cv2.split(yuv)
+    cv2.subtract(128, u, dst=u)
+    cv2.multiply(u, 8, dst=u)
+
+    color = color_similarity_2d(image, color=(255,255,255))
+    hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
+    _, _, v = cv2.split(hsv)
+    image = apply_mask(image, u)
+    image = apply_mask(image, color)
+    image = apply_mask(image, v)
+
+    cv2.convertScaleAbs(image, alpha=3, dst=image)
+    cv2.subtract((255, 255, 255, 0), image, dst=image)
+
+    # from PIL import Image
+    # Image.fromarray(image.astype(np.uint8)).show()
+    return image
+
+
+class HighlightGif(RuleGif):
+    def pre_process(self, image):
+        return highlight(image)
+
+class HighLight(BaseTask, ExplorationAssets):
+
+    @cached_property
+    def TEMPLATE_GIF(self) -> RuleGif:
+        return HighlightGif(
+            targets=[
+                self.I_LIGHT1, self.I_LIGHT2, self.I_LIGHT3, self.I_LIGHT4, self.I_LIGHT5,
+                self.I_LIGHT6, self.I_LIGHT7, self.I_LIGHT8, self.I_LIGHT9, self.I_LIGHT10,
+                self.I_LIGHT11, self.I_LIGHT12, self.I_LIGHT13, self.I_LIGHT14,
+            ],
+        )
+
+
+if __name__ == '__main__':
+    # image = load_image(r'C:\Users\萌萌哒\Desktop\屏幕截图 2024-08-17 175713.png')
+    # image = highlight(image)
+    # save_image(image, r'C:\Users\萌萌哒\Desktop\1345.png')
+    #
+    IMAGE_FILE = r"C:\Users\萌萌哒\Desktop\QQ20240818-163854.png"
+    image = load_image(IMAGE_FILE)
+    from tasks.Exploration.assets import ExplorationAssets
+    targe = ExplorationAssets.I_UP_COIN
+    print(targe.test_match(image))
+
+    # from dev_tools.get_images import GetAnimation
+    # from module.config.config import Config
+    # from module.device.device import Device
+    # c = Config('oas1')
+    # d = Device(c)
+    # t = HighLight(c, d)
+    # t.screenshot()
+    #
+    # t.screenshot()
+    # t.appear_then_click(t.TEMPLATE_GIF)
+
+

+ 1 - 1
tasks/GameUi/assets.py

@@ -63,7 +63,7 @@ class GameUiAssets:
 	# description 
 	I_CHECK_SOUL_ZONES = RuleImage(roi_front=(49,105,298,405), roi_back=(49,105,298,405), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_soul_zones.png")
 	# description 
-	I_CHECK_REALM_RAID = RuleImage(roi_front=(507,72,261,46), roi_back=(507,72,261,46), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_realm_raid.png")
+	I_CHECK_REALM_RAID = RuleImage(roi_front=(113,625,86,77), roi_back=(113,625,86,77), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_realm_raid.png")
 	# description 
 	I_CHECK_GORYOU = RuleImage(roi_front=(881,17,30,39), roi_back=(881,17,30,39), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_goryou.png")
 	# description 

BIN
tasks/GameUi/page/page_check_realm_raid.png


+ 2 - 2
tasks/GameUi/page/page_img.json

@@ -146,8 +146,8 @@
   {
     "itemName": "check_realm_raid",
     "imageName": "page_check_realm_raid.png",
-    "roiFront": "507,72,261,46",
-    "roiBack": "507,72,261,46",
+    "roiFront": "113,625,86,77",
+    "roiBack": "113,625,86,77",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"

BIN
tasks/GameUi/page/page_ryoutoppa_goto_realmraid.png


+ 3 - 1
tasks/KekkaiUtilize/assets.py

@@ -115,8 +115,10 @@ class KekkaiUtilizeAssets:
 	# Ocr Rule Assets
 	# 这个寄养的剩余时间 
 	O_UTILIZE_RES_TIME = RuleOcr(roi=(1140,117,100,30), area=(1140,117,100,30), mode="Duration", method="Default", keyword="", name="utilize_res_time")
-	# 今日以领取经验 
+	# 今日已领取经验 
 	O_BOX_EXP = RuleOcr(roi=(654,538,179,39), area=(654,538,179,39), mode="DigitCounter", method="Default", keyword="", name="box_exp")
+	# 今日已领取经验(招财上宾) 
+	O_BOX_EXP_ZCSB = RuleOcr(roi=(584,542,181,35), area=(584,542,181,35), mode="DigitCounter", method="Default", keyword="", name="box_exp_zcsb")
 
 
 	# Swipe Rule Assets

+ 6 - 3
tasks/KekkaiUtilize/script_task.py

@@ -202,9 +202,12 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
                 if self.appear(self.I_EXP_EXTRACT):
                     # 如果达到今日领取的最大,就不领取了
                     cur, res, totol = self.O_BOX_EXP.ocr(self.device.image)
-                    if cur == res == totol == 0:
-                        continue
-                    if cur == totol and cur + res == totol:
+                    if cur != 0 and totol != 0 and cur == totol and cur + res == totol:
+                        logger.info('Exp box reach max do not collect')
+                        break
+                    # 开启招财上宾后,上限增加20%,数值位置有偏移
+                    cur, res, totol = self.O_BOX_EXP_ZCSB.ocr(self.device.image)
+                    if cur != 0 and totol != 0 and cur == totol * 1.2 and cur + res == totol:
                         logger.info('Exp box reach max do not collect')
                         break
                 if self.appear_then_click(self.I_BOX_EXP, threshold=0.6, interval=1):

+ 10 - 1
tasks/KekkaiUtilize/utilize/ocr.json

@@ -15,6 +15,15 @@
     "mode": "DigitCounter",
     "method": "Default",
     "keyword": "",
-    "description": "今日以领取经验"
+    "description": "今日已领取经验"
+  },
+  {
+    "itemName": "box_exp_zcsb",
+    "roiFront": "584,542,181,35",
+    "roiBack": "584,542,181,35",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "今日已领取经验(招财上宾)"
   }
 ]

+ 1 - 4
tasks/RealmRaid/script_task.py

@@ -519,8 +519,5 @@ if __name__ == "__main__":
     device = Device(config)
     t = ScriptTask(config, device)
 
-    # t.run()
+    t.run()
 
-    print(t.find_one())
-    # target, order = t.find_one()
-    # print(t.check_medal_is_frog(True, target, order))

+ 3 - 1
tasks/RyouToppa/script_task.py

@@ -101,6 +101,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
         self.ui_goto(page_kekkai_toppa)
         ryou_toppa_start_flag = True
         ryou_toppa_success_penetration = False
+        ryou_toppa_admin_flag = False
         # 点击突破
         while 1:
             self.screenshot()
@@ -117,6 +118,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
             # 出现选择寮突说明寮突未开
             elif self.appear(self.I_SELECT_RYOU_BUTTON, threshold=0.8):
                 ryou_toppa_start_flag = False
+                ryou_toppa_admin_flag = True
                 break
             # 出现晴明说明寮突未开
             elif self.appear(self.I_NO_SELECT_RYOU, threshold=0.8):
@@ -131,7 +133,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
         logger.attr('ryou_toppa_success_penetration', ryou_toppa_success_penetration)
         # 寮突未开 并且有权限, 开开寮突,没有权限则标记失败
         if not ryou_toppa_start_flag:
-            if ryou_config.raid_config.ryou_access:
+            if ryou_config.raid_config.ryou_access and ryou_toppa_admin_flag:
                 # 作为寮管理,开启今天的寮突
                 logger.info("As the manager of the ryou, try to start ryou toppa.")
                 self.start_ryou_toppa()

+ 2 - 0
tasks/SoulsTidy/assets.py

@@ -64,5 +64,7 @@ class SoulsTidyAssets:
 	O_ST_SORT_TYPE = RuleOcr(roi=(414,118,64,43), area=(414,118,64,43), mode="Single", method="Default", keyword="类型", name="st_sort_type")
 	# 位置 
 	O_ST_SORT_LOCATION = RuleOcr(roi=(415,119,61,39), area=(415,119,61,39), mode="Single", method="Default", keyword="位置", name="st_sort_location")
+	# Ocr-description 
+	O_ST_OVERFLOW = RuleOcr(roi=(686,397,109,48), area=(686,397,109,48), mode="Single", method="Default", keyword="知道了", name="st_overflow")
 
 

+ 2 - 0
tasks/SoulsTidy/script_task.py

@@ -43,6 +43,8 @@ class ScriptTask(GameUi, SoulsTidyAssets):
                 continue
             if self.click(self.C_ST_DETAIL, interval=1.5):
                 continue
+        # 御魂超过上限的提示
+        self.ocr_appear_click(self.O_ST_OVERFLOW)
         logger.info('Enter souls page')
 
     def back_records(self):

+ 9 - 0
tasks/SoulsTidy/simple/ocr.json

@@ -61,5 +61,14 @@
     "method": "Default",
     "keyword": "位置",
     "description": "位置"
+  },
+  {
+    "itemName": "st_overflow",
+    "roiFront": "686,397,109,48",
+    "roiBack": "686,397,109,48",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "知道了",
+    "description": "Ocr-description"
   }
 ]

+ 8 - 4
tasks/base_task.py

@@ -16,6 +16,7 @@ from module.atom.long_click import RuleLongClick
 from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
+from module.atom.gif import RuleGif
 from module.ocr.base_ocr import OcrMode, OcrMethod
 from module.atom.animate import RuleAnimate
 from module.logger import logger
@@ -136,7 +137,10 @@ class BaseTask(GlobalGameAssets, CostumeBase):
 
         return self.device.image
 
-    def appear(self, target: RuleImage, interval: float = None, threshold: float = None):
+    def appear(self,
+               target: RuleImage | RuleGif,
+               interval: float = None,
+               threshold: float = None):
         """
 
         :param target: 匹配的目标可以是RuleImage, 也可以是RuleOcr
@@ -144,7 +148,7 @@ class BaseTask(GlobalGameAssets, CostumeBase):
         :param threshold:
         :return:
         """
-        if not isinstance(target, RuleImage):
+        if not isinstance(target, RuleImage) and not isinstance(target, RuleGif):
             return False
 
         if interval:
@@ -164,7 +168,7 @@ class BaseTask(GlobalGameAssets, CostumeBase):
         return appear
 
     def appear_then_click(self,
-                          target: RuleImage,
+                          target: RuleImage | RuleGif,
                           action: Union[RuleClick, RuleLongClick] = None,
                           interval: float = None,
                           threshold: float = None,
@@ -178,7 +182,7 @@ class BaseTask(GlobalGameAssets, CostumeBase):
         :param threshold:
         :return: True or False
         """
-        if not isinstance(target, RuleImage):
+        if not isinstance(target, RuleImage) and not isinstance(target, RuleGif):
             return False
 
         appear = self.appear(target, interval=interval, threshold=threshold)