Просмотр исходного кода

feat(Moan): OrochiMoans free rider for test

jackyhwei 2 лет назад
Родитель
Сommit
73990b2227

+ 1 - 1
module/config/config_menu.py

@@ -19,7 +19,7 @@ class ConfigMenu:
         # 脚本设置
         self.menu['Script'] = ['Script', 'Restart', 'GlobalGame']
         # 刷御魂
-        self.menu["Soul Zones"] = ['Orochi', 'Sougenbi', 'FallenSun', 'EternitySea']
+        self.menu["Soul Zones"] = ['Orochi', 'OrochiMoans', 'Sougenbi', 'FallenSun', 'EternitySea']
         # 日常的任务
         self.menu["Daily Task"] = ['DailyTrifles', 'AreaBoss', 'GoldYoukai', 'ExperienceYoukai', 'Nian',
                                    'TalismanPass', 'DemonEncounter', 'Pets', 'SoulsTidy', 'Delegation', 'WantedQuests',

+ 2 - 2
module/config/i18n/zh_CN.ts

@@ -165,7 +165,7 @@
     <message><source>Nian</source><translation>年兽</translation></message>
     <message><source>Soul Zones</source><translation>御魂副本</translation></message>
     <message><source>Orochi</source><translation>八岐大蛇</translation></message>
-	<message><source>OrochiMoans</source><translation>御魂悲鸣</translation></message>
+	<message><source>OrochiMoans</source><translation>魂土司机(测试版)</translation></message>
     <message><source>OrochiJudgement</source><translation>御魂神罚</translation></message>
     <message><source>Sougenbi</source><translation>业原火</translation></message>
     <message><source>FallenSun</source><translation>日轮之城</translation></message>
@@ -212,7 +212,7 @@
     <message><source>Nian</source><translation>年兽</translation></message>
     <message><source>Soul Zones</source><translation>御魂副本</translation></message>
     <message><source>Orochi</source><translation>八岐大蛇</translation></message>
-	<message><source>OrochiMoans</source><translation>御魂悲鸣</translation></message>
+	<message><source>OrochiMoans</source><translation>魂土司机(测试版)</translation></message>
     <message><source>OrochiJudgement</source><translation>御魂神罚</translation></message>
     <message><source>Sougenbi</source><translation>业原火</translation></message>
     <message><source>FallenSun</source><translation>日轮之城</translation></message>

+ 10 - 4
tasks/Component/GeneralInvite/general_invite.py

@@ -60,6 +60,7 @@ class GeneralInvite(BaseTask, GeneralInviteAssets):
             _ = self.room_type
             self.timer_invite = Timer(20)
             self.timer_invite.start()
+            logger.info(f"config.invite_number={config.invite_number}")
             self.ensure_room_type(config.invite_number)
             self.invite_friends(config)
         else:
@@ -219,7 +220,10 @@ class GeneralInvite(BaseTask, GeneralInviteAssets):
 
         def check_3(img) -> bool:
             appear = False
-            if self.I_ADD_1.match(img) and self.I_ADD_2.match(img):
+            # FIXME 三个人的房间,位置1已经有人了,按这个逻辑会变成两个人的房间
+            # if self.I_ADD_1.match(img) and self.I_ADD_2.match(img):
+            logger.warning(f"check_room_type, room3: {self.I_ADD_2.name}")
+            if self.appear(self.I_ADD_2):
                 appear = True
             return appear
 
@@ -255,12 +259,14 @@ class GeneralInvite(BaseTask, GeneralInviteAssets):
                     room_type = RoomType.ETERNITY_SEA if check_eternity_sea(image) else None
         if room_type:
             return room_type
-        if room_type is None and check_2(image):
-            room_type = RoomType.NORMAL_2
-            return room_type
+        
+        # FIXME 在加入自动、手动档结合的逻辑后,需要改变一个3和2的顺序,如果3个坑的队伍如果已经拉了1个人的话,原逻辑会被判定为2个坑的队伍
         if room_type is None and check_3(image):
             room_type = RoomType.NORMAL_3
             return room_type
+        if room_type is None and check_2(image):
+            room_type = RoomType.NORMAL_2
+            return room_type
         if room_type is None and check_5(image):
             room_type = RoomType.NORMAL_5
             return room_type

+ 47 - 14
tasks/Orochi/script_task.py

@@ -75,11 +75,23 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
         logger.info('Enter orochi')
         while True:
             self.screenshot()
+            logger.info("寻找 组队 图片")
             if self.appear(self.I_FORM_TEAM):
+                logger.info("匹配 组队 图片:成功")
                 return True
             if self.appear_then_click(self.I_OROCHI, interval=1):
                 continue
 
+    def check_layer_new(self, layer: str) -> bool:
+        """
+        检查挑战的层数, 并选中挑战的层
+        :return:
+        """
+        pos = self.list_find(self.L_LAYER_LIST_NEW, layer)
+        if pos:
+            self.device.click(x=pos[0], y=pos[1])
+            return True
+
     def check_layer(self, layer: str) -> bool:
         """
         检查挑战的层数, 并选中挑战的层
@@ -119,33 +131,52 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
 
 
 
-
-
-
     def run_leader(self):
         logger.info('Start run leader')
         self.ui_get_current_page()
+        logger.info("界面跳转:探索 --> 御魂 --> 八岐大蛇 ./tasks/GameUi/page/page_check_soul_zones.png")
         self.ui_goto(page_soul_zones)
+        logger.info("定位 组队 图片...")
         self.orochi_enter()
-        layer = self.config.orochi.orochi_config.layer
-        self.check_layer(layer)
-        self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)
-        # 创建队伍
-        logger.info('Create team')
+
+        # logger.debug(f"I_CHECK_TEAM这个图片是同心队,我不需要同心队")
+        # while 1:
+        #     self.screenshot()
+        #     if self.appear(self.I_CHECK_TEAM):
+        #         break
+        #     if self.appear_then_click(self.I_FORM_TEAM, interval=1):
+        #         continue
+
+        # 点击:组队
+        logger.info('点击:组队')
         while 1:
             self.screenshot()
-            if self.appear(self.I_CHECK_TEAM):
-                break
             if self.appear_then_click(self.I_FORM_TEAM, interval=1):
-                continue
+                break
+
+        layer = self.config.orochi.orochi_config.layer
+
+        logger.info(f"查找御魂层数:{layer}")
+        self.check_layer_new(layer)
+
+        logger.info("点击:创建队伍")
         # 创建房间
         self.create_room()
+
+
+        logger.info("设置队伍公开权限")
         self.ensure_private()
+
+        logger.info(f"检查是否锁定队伍:{self.config.orochi.general_battle_config.lock_team_enable},识别有问题,暂跳过")
+        # self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)
+
+        logger.info("点击:创建")
         self.create_ensure()
 
         # 邀请队友
         success = True
         is_first = True
+
         # 这个时候我已经进入房间了哦
         while 1:
             self.screenshot()
@@ -344,6 +375,7 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
         success = True
         while 1:
             self.screenshot()
+
             # 无论胜利与否, 都会出现是否邀请一次队友
             # 区别在于,失败的话不会出现那个勾选默认邀请的框
             if self.check_and_invite(self.config.orochi.invite_config.default_invite):
@@ -355,17 +387,18 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
 
             if self.current_count >= self.limit_count:
                 if self.is_in_room():
-                    logger.info('Orochi count limit out')
+                    logger.info('达到设定次数,御魂任务结束。Orochi count limit out')
                     break
 
             if datetime.now() - self.start_time >= self.limit_time:
                 if self.is_in_room():
-                    logger.info('Orochi time limit out')
+                    logger.info('达到设定的时间限制,御魂任务结束。Orochi time limit out')
                     break
 
             if not self.is_in_room():
+                logger.warning('不在御魂副本?')
                 if self.is_room_dead():
-                    logger.warning('Orochi task failed')
+                    logger.warning('不在御魂副本,并且队伍没了?退出。Orochi task failed')
                     success = False
                     break
                 continue

+ 27 - 1
tasks/OrochiMoans/assets.py

@@ -8,5 +8,31 @@ from module.atom.list import RuleList
 # This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class OrochiMoansAssets: 
-	pass
+
+
+	# Image Rule Assets
+	# 战斗结算中的突破券。需要全图匹配,当前match只返回最高相似度区域,因此不支持多张突破券场景 
+	I_TOPPA_SCROLL = RuleImage(roi_front=(403,179,93,96), roi_back=(0,0,1280,720), threshold=0.8, method="Template matching", file="./tasks/OrochiMoans/res/res_toppa_scroll.png")
+	# 场景检测:组队界面(需要自己预先拉好队友) 
+	I_OROCHI_TEAM = RuleImage(roi_front=(937,591,100,100), roi_back=(937,591,100,100), threshold=0.8, method="Template matching", file="./tasks/OrochiMoans/res/o_form_team.png")
+	# 场景检测:进入战斗,但未点开始 
+	I_OROCHI_IN_FIELD = RuleImage(roi_front=(873,184,62,147), roi_back=(873,184,62,147), threshold=0.8, method="Template matching", file="./tasks/OrochiMoans/res/o_orochi_in_field.png")
+	# 场景检测:战斗胜利 
+	I_OROCHI_SUCCEED = RuleImage(roi_front=(296,33,414,224), roi_back=(296,33,414,224), threshold=0.8, method="Template matching", file="./tasks/OrochiMoans/res/gb_win.png.png")
+	# 场景检测:战斗失败 
+	I_OROCHI_FAILED = RuleImage(roi_front=(413,124,100,100), roi_back=(413,124,100,100), threshold=0.8, method="Template matching", file="./tasks/OrochiMoans/res/gb_false.png")
+	# 场景检测:御魂战斗进行中 
+	I_OROCHI_FIGHTING = RuleImage(roi_front=(89,14,36,36), roi_back=(89,14,36,36), threshold=0.8, method="Template matching", file="./tasks/OrochiMoans/res/gb_friends.png")
+
+
+	# List Rule Assets
+	# 这个是御魂界面选择不同层数的 
+	L_LAYER_LIST_NEW = RuleList(folder="./tasks/OrochiMoans/res", direction="vertical", mode="ocr", roi_back=(430,190,160,370), size=(45, 88), 
+					 array=["壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾", "悲", "神"])
+
+
+	# Ocr Rule Assets
+	# 突破卷的数量 
+	O_TOPPA_SCROLL = RuleOcr(roi=(1143,13,80,39), area=(0,0,100,100), mode="DigitCounter", method="Default", keyword="", name="toppa_scroll")
+
 

+ 47 - 5
tasks/OrochiMoans/config.py

@@ -1,11 +1,53 @@
-# This Python file uses the following encoding: utf-8
-# @author runhey
-# github https://github.com/runhey
 from pydantic import BaseModel, Field
+from enum import Enum
+from datetime import datetime, time
 
+from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
 from tasks.Component.config_scheduler import Scheduler
-from tasks.Component.config_base import ConfigBase
+from tasks.Component.config_base import ConfigBase, Time
+from tasks.Component.GeneralInvite.config_invite import InviteConfig
+from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
+
+
+class UserStatus(str, Enum):
+    LEADER = 'leader'
+    # MEMBER = 'member'
+    # ALONE = 'alone'
+    # WILD = 'wild'
+
+class Layer(str, Enum):
+    ONE = '壹层'
+    TWO = '贰层'
+    THREE = '叁层'
+    FOUR = '肆层'
+    FIVE = '伍层'
+    SIX = '陆层'
+    SEVEN = '柒层'
+    EIGHT = '捌层'
+    NINE = '玖层'
+    TEN = '拾层'
+    ELEVEN = '悲鸣'
+    TWELVE = '神罚'
+
+class OrochiMoansConfig(ConfigBase):
+    # 身份
+    user_status: UserStatus = Field(default=UserStatus.LEADER, description='user_status_help')
+    # 层数
+    layer: Layer = Field(default=Layer.ELEVEN, description='layer_help')
+    # 限制时间
+    limit_time: Time = Field(default=Time(minute=30), description='limit_time_help')
+    # 限制次数
+    limit_count: int = Field(default=30, description='limit_count_help')
+    # 是否开启御魂加成
+    soul_buff_enable: bool = Field(default=False, description='soul_buff_enable_help')
+    # # 是否检测突破券数量(不支持五倍活动)
+    # limit_by_toppa_scrolls_enable: bool = Field(default=False, description='limit_count_by_toppa_scrolls_enable_help')
+    # # 突破券数量上限(不支持五倍活动)
+    # limit_by_toppa_scrolls_count: int = Field(default=30, description='limit_count_by_toppa_scrolls_count_help')
 
 class OrochiMoans(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
-
+    orochi_moans_config: OrochiMoansConfig = Field(default_factory=OrochiMoansConfig)
+    invite_config: InviteConfig = Field(default_factory=InviteConfig)
+    general_battle_config: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
+    switch_soul: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)

+ 56 - 0
tasks/OrochiMoans/res/image.json

@@ -0,0 +1,56 @@
+[
+  {
+    "itemName": "toppa_scroll",
+    "imageName": "res_toppa_scroll.png",
+    "roiFront": "403,179,93,96",
+    "roiBack": "0,0,1280,720",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "战斗结算中的突破券。需要全图匹配,当前match只返回最高相似度区域,因此不支持多张突破券场景"
+  },
+  {
+    "itemName": "orochi_team",
+    "imageName": "o_form_team.png",
+    "roiFront": "937,591,100,100",
+    "roiBack": "937,591,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "场景检测:组队界面(需要自己预先拉好队友)"
+  },
+  {
+    "itemName": "orochi_in_field",
+    "imageName": "o_orochi_in_field.png",
+    "roiFront": "873,184,62,147",
+    "roiBack": "873,184,62,147",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "场景检测:进入战斗,但未点开始"
+  },
+  {
+    "itemName": "orochi_succeed",
+    "imageName": "gb_win.png.png",
+    "roiFront": "296,33,414,224",
+    "roiBack": "296,33,414,224",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "场景检测:战斗胜利"
+  },
+  {
+    "itemName": "orochi_failed",
+    "imageName": "gb_false.png",
+    "roiFront": "413,124,100,100",
+    "roiBack": "413,124,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "场景检测:战斗失败"
+  },
+  {
+    "itemName": "orochi_fighting",
+    "imageName": "gb_friends.png",
+    "roiFront": "89,14,36,36",
+    "roiBack": "89,14,36,36",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "场景检测:御魂战斗进行中"
+  }
+]

+ 57 - 0
tasks/OrochiMoans/res/list.json

@@ -0,0 +1,57 @@
+{
+  "name": "layer_list_new",
+  "direction": "vertical",
+  "type": "ocr",
+  "roiBack": "430,190,160,370",
+  "description": "这个是御魂界面选择不同层数的",
+  "list": [
+    {
+      "itemName": "壹",
+      "roiFront": "281,135,39,102"
+    },
+    {
+      "itemName": "贰",
+      "roiFront": "280,253,39,85"
+    },
+    {
+      "itemName": "叁",
+      "roiFront": "283,422,43,93"
+    },
+    {
+      "itemName": "肆",
+      "roiFront": "280,312,44,90"
+    },
+    {
+      "itemName": "伍",
+      "roiFront": "282,425,43,82"
+    },
+    {
+      "itemName": "陆",
+      "roiFront": "275,316,47,89"
+    },
+    {
+      "itemName": "柒",
+      "roiFront": "279,312,48,93"
+    },
+    {
+      "itemName": "捌",
+      "roiFront": "275,203,51,89"
+    },
+    {
+      "itemName": "玖",
+      "roiFront": "278,206,48,81"
+    },
+    {
+      "itemName": "拾",
+      "roiFront": "282,315,45,84"
+    },
+    {
+      "itemName": "悲",
+      "roiFront": "277,427,47,85"
+    },
+    {
+      "itemName": "神",
+      "roiFront": "277,534,46,86"
+    }
+  ]
+}

+ 11 - 0
tasks/OrochiMoans/res/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "toppa_scroll",
+    "roiFront": "1143,13,80,39",
+    "roiBack": "0,0,100,100",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "突破卷的数量"
+  }
+]

BIN
tasks/OrochiMoans/res/res_toppa_scroll.png


+ 561 - 0
tasks/OrochiMoans/script_task.py

@@ -0,0 +1,561 @@
+import random
+from time import sleep
+from datetime import time, datetime, timedelta
+from enum import Enum
+import numpy as np
+
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.GeneralInvite.general_invite import GeneralInvite
+from tasks.Component.GeneralBuff.general_buff import GeneralBuff
+from tasks.Component.GeneralRoom.general_room import GeneralRoom
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main, page_soul_zones, page_shikigami_records
+from tasks.OrochiMoans.assets import OrochiMoansAssets
+from tasks.OrochiMoans.config import OrochiMoans, UserStatus
+from module.logger import logger
+from module.exception import TaskEnd
+from tasks.Dokan.assets import DokanAssets
+from tasks.Dokan.utils import detect_safe_area2
+from tasks.Orochi.assets import OrochiAssets
+
+class OrochiMoansScene(Enum):
+    '''
+    FIXME 这些状态里,需要一个优先顺序
+    '''
+    # 未知界面(随机点击3次,以便跳过一些不支持的结算界面)
+    OROCHI_SCENE_UNKNOWN = 0
+    # 场景检测:组队界面(需要自己预先拉好队友)
+    OROCHI_SCENE_TEAM = 1
+    # 场景检测:进入御魂战斗,但未点开始
+    OROCHI_SCENE_IN_FIELD = 2
+    # 场景检测:御魂战斗进行中
+    OROCHI_SCENE_FIGHTING = 3
+
+
+class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi, SwitchSoul, OrochiMoansAssets):
+    in_orochi: bool = False
+    current_scene: OrochiMoansScene = OrochiMoansScene.OROCHI_SCENE_UNKNOWN
+    anti_detect_click_fixed_random_area: bool = True
+
+    # 限制时间 
+    limit_time: timedelta
+    # 限制次数 
+    limit_count: int = 30
+    current_count: int = 0
+    # 限制突破券
+    limit_toppa_scrolls_enabled: bool = False
+    limit_toppa_scrolls_count: int = 30
+    current_toppa_scroll_count: int = 0
+    # 只在第一次的时候会去点一下查看一下当前拥有的突破券数量
+    is_first_check_toppa_scrolls: bool = True
+
+    def run(self) -> bool:
+
+        config: OrochiMoans = self.config.orochi_moans
+        limit_time = config.orochi_moans_config.limit_time
+        self.current_count = 0
+        self.limit_count = config.orochi_moans_config.limit_count
+        self.limit_time = timedelta(hours=limit_time.hour, minutes=limit_time.minute, seconds=limit_time.second)
+        # self.limit_toppa_scrolls_enabled = config.orochi_moans_config.limit_by_toppa_scrolls_enable
+        # self.limit_toppa_scrolls_count = config.orochi_moans_config.limit_by_toppa_scrolls_count
+
+        # 检测当前界面的场景(仅支持:组队界面、准备界面和战斗界面), 如果检测到不能识别的场景,先随便点击三下,再次检测
+        detect_count = 0
+        while not self.in_orochi:
+            self.in_orochi, self.current_scene = self.get_orochi_scene(False)
+            logger.warning(f"try {detect_count}/3: self.in_orochi={self.in_orochi}, self.current_scene={self.current_scene}")
+            sleep(1)
+            detect_count += 1
+            if detect_count >= 3:
+                break
+
+        # 如果不在可支持的场景界面,按正常的流程走
+        if not self.in_orochi:
+            self.orochi_switch_soul(config)
+            self.orochi_open_soul_buf(config)
+
+        # 开始战斗
+        success = True
+        match config.orochi_moans_config.user_status:
+            case UserStatus.LEADER: success = self.run_leader(self.current_scene)
+            # case UserStatus.MEMBER: success = self.run_member(self.current_scene)
+            case _: logger.error('current version supports only running leader mode!')
+
+        # 记得关掉
+        if config.orochi_moans_config.soul_buff_enable:
+            self.open_buff()
+            self.soul(is_open=False)
+            self.close_buff()
+        # 下一次运行时间
+        if success:
+            self.set_next_run('OrochiMoans', finish=True, success=True)
+        else:
+            self.set_next_run('OrochiMoans', finish=False, success=False)
+
+        raise TaskEnd
+
+    def orochi_open_soul_buf(self, config: OrochiMoans):
+        '''
+        在庭院界面打开御魂加成(考虑放到组队成功、点击挑战前)
+        '''
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+        if config.orochi_moans_config.soul_buff_enable:
+            self.open_buff()
+            self.soul(is_open=True)
+            self.close_buff()
+
+    def orochi_switch_soul(self, config: OrochiMoans):
+        '''
+        切换御魂
+        '''
+        # 御魂切换方式一
+        if config.switch_soul.enable:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul(config.switch_soul.switch_group_team)
+
+        # 御魂切换方式二
+        if config.switch_soul.enable_switch_by_name:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul_by_name(config.switch_soul.group_name,
+                                         config.switch_soul.team_name)
+
+
+    def orochi_enter(self) -> bool:
+        logger.info('Enter orochi')
+        while True:
+            self.screenshot()
+            if self.appear(OrochiAssets.I_FORM_TEAM):
+                return True
+            if self.appear_then_click(OrochiAssets.I_OROCHI, interval=1):
+                continue
+
+    def check_layer(self, layer: str) -> bool:
+        """
+        检查挑战的层数, 并选中挑战的层
+        :return:
+        """
+        pos = self.list_find(self.L_LAYER_LIST_NEW, layer)
+        if pos:
+            self.device.click(x=pos[0], y=pos[1])
+            return True
+
+    def check_lock(self, lock: bool = True) -> bool:
+        """
+        检查是否锁定阵容, 要求在八岐大蛇界面
+        :param lock:
+        :return:
+        """
+        logger.info('Check lock: %s', lock)
+        if lock:
+            while 1:
+                self.screenshot()
+                if self.appear(OrochiAssets.I_OROCHI_LOCK):
+                    return True
+                if self.appear_then_click(OrochiAssets.I_OROCHI_UNLOCK, interval=1):
+                    continue
+        else:
+            while 1:
+                self.screenshot()
+                if self.appear(OrochiAssets.I_OROCHI_UNLOCK):
+                    return True
+                if self.appear_then_click(OrochiAssets.I_OROCHI_LOCK, interval=1):
+                    continue
+
+    def get_orochi_scene(self, reuse_screenshot: bool = True):
+        '''
+        识别御魂任务场景
+        '''
+        if not reuse_screenshot:
+            self.screenshot()
+        
+        # 场景检测:组队界面(需要自己预先拉好队友)
+        if self.is_in_prepare():
+            return True, OrochiMoansScene.OROCHI_SCENE_IN_FIELD
+        if self.is_in_battle():
+            return True, OrochiMoansScene.OROCHI_SCENE_FIGHTING
+        if self.appear(self.I_ADD_2):
+            return True, OrochiMoansScene.OROCHI_SCENE_TEAM
+
+        # if self.ensure_enter():
+        #     return True, OrochiMoansScene.OROCHI_SCENE_TEAM
+
+        return False, OrochiMoansScene.OROCHI_SCENE_UNKNOWN
+
+
+    def run_leader(self, scene: OrochiMoansScene = OrochiMoansScene.OROCHI_SCENE_UNKNOWN):
+        logger.info(f'Start run leader:scene={scene}')
+
+        manual_start = False
+        is_first = True
+
+        # 未知界面启动,走正常流程
+        if scene == OrochiMoansScene.OROCHI_SCENE_UNKNOWN:
+            self.ui_get_current_page()
+            self.ui_goto(page_soul_zones)
+            self.orochi_enter()
+            # 创建队伍
+            logger.info('Create team')
+            while 1:
+                self.screenshot()
+                if self.appear_then_click(OrochiAssets.I_FORM_TEAM, interval=1):
+                    logger.info("111")
+                    break
+
+            logger.info("23423")
+            layer = self.config.orochi_moans.orochi_moans_config.layer
+            logger.info(f"finding Orochi layer: {layer}")
+            self.check_layer(layer)
+
+            # 创建房间
+            self.create_room()
+            self.ensure_private()
+            self.create_ensure()
+        # elif scene == OrochiMoansScene.OROCHI_SCENE_TEAM:
+        #     is_first = False
+        #     manual_start = True
+        else:
+            is_first = False
+            manual_start = True
+
+        success = True
+
+        # 这个时候我已经进入房间了哦
+        while 1:
+            # logger.warning(f"manual_start={manual_start}, first={is_first}")
+            self.screenshot()
+
+            # 检查猫咪奖励
+            if self.appear_then_click(OrochiAssets.I_PET_PRESENT, action=self.C_WIN_3, interval=1):
+                continue
+
+            if manual_start and not is_first:
+                if self.check_and_skip_battle_result() == True:
+                    self.check_and_invite(self.config.orochi_moans.invite_config.default_invite)
+                    continue
+
+            # 无论胜利与否, 都会出现是否邀请一次队友
+            # 区别在于,失败的话不会出现那个勾选默认邀请的框
+            if self.check_and_invite(self.config.orochi_moans.invite_config.default_invite):
+                continue
+
+            # 次数达到上限
+            if self.current_count >= self.limit_count:
+                if self.is_in_room():
+                    logger.info('Orochi count limit out')
+                    break
+            # 时间达到上限
+            if datetime.now() - self.start_time >= self.limit_time:
+                if self.is_in_room():
+                    logger.info('Orochi time limit out')
+                    break
+            # 突破券达到上限
+            if self.limit_toppa_scrolls_enabled and self.current_toppa_scroll_count >= self.limit_toppa_scrolls_count:
+                if self.is_in_room():
+                    logger.info('Toppa scrolls limit out: current={self.current_toppa_scrolls_count}/{self.limit_toppa_scrolls_limit}')
+                    break
+
+            # 如果没有进入房间那就不需要后面的邀请
+            if not self.is_in_room():
+                if self.is_room_dead():
+                    logger.warning('Orochi task failed')
+                    success = False
+                    break
+                continue
+
+            # 点击挑战
+            if not is_first:
+                if self.run_invite(config=self.config.orochi_moans.invite_config, is_first=False):
+                    self.run_general_battle(config=self.config.orochi_moans.general_battle_config)
+                else:
+                    # 邀请失败,退出任务
+                    logger.warning('Invite failed and exit this orochi task')
+                    success = False
+                    break
+            else:
+                if manual_start:
+                    is_first = False
+                    self.run_general_battle(config=self.config.orochi_moans.general_battle_config)
+                else:
+                    if not self.run_invite(config=self.config.orochi_moans.invite_config, is_first=True):
+                        logger.warning('Invite failed and exit this orochi task')
+                        success = False
+                        break
+                    else:
+                        is_first = False
+                        self.run_general_battle(config=self.config.orochi_moans.general_battle_config)
+
+        # 当结束或者是失败退出循环的时候只有两个UI的可能,在房间或者是在组队界面
+        # 如果在房间就退出
+        if self.exit_room():
+            pass
+        # 如果在组队界面就退出
+        if self.exit_team():
+            pass
+
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+
+        return success
+
+    def run_member(self, scene: OrochiMoansScene = OrochiMoansScene.OROCHI_SCENE_UNKNOWN):
+        logger.info('Start run member')
+        self.ui_get_current_page()
+
+        # 进入战斗流程
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        while 1:
+            self.screenshot()
+
+            # 检查猫咪奖励
+            if self.appear_then_click(OrochiAssets.I_PET_PRESENT, action=self.C_WIN_3, interval=1):
+                continue
+            # 次数达到上限
+            if self.current_count >= self.limit_count:
+                logger.info('Orochi count limit out')
+                break
+            # 时间达到上限
+            if datetime.now() - self.start_time >= self.limit_time:
+                logger.info('Orochi time limit out')
+                break
+            # 突破券达到上限
+            if self.limit_toppa_scrolls_enabled and self.current_toppa_scroll_count >= self.limit_toppa_scrolls_count:
+                logger.info('Orochi task terminated due to toppa scrolls limit: current={self.current_toppa_scrolls_count}/{self.limit_toppa_scrolls_limit}')
+                break
+
+            if self.check_then_accept():
+                continue
+
+            if self.is_in_room():
+                self.device.stuck_record_clear()
+                if self.wait_battle(wait_time=self.config.orochi_moans.invite_config.wait_time):
+                    self.run_general_battle(config=self.config.orochi_moans.general_battle_config)
+                else:
+                    break
+            # 队长秒开的时候,检测是否进入到战斗中
+            elif self.check_take_over_battle(False, config=self.config.orochi_moans.general_battle_config):
+                continue
+
+        while 1:
+            # 有一种情况是本来要退出的,但是队长邀请了进入的战斗的加载界面
+            if self.appear(self.I_GI_HOME) or self.appear(self.I_GI_EXPLORE):
+                break
+            # 如果可能在房间就退出
+            if self.exit_room():
+                pass
+            # 如果还在战斗中,就退出战斗
+            if self.exit_battle():
+                pass
+
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+
+        return True
+
+    def is_room_dead(self) -> bool:
+        '''
+        如果在探索界面或者是出现在组队界面,那就是可能房间死了
+        '''
+        sleep(0.5)
+        if self.appear(self.I_MATCHING) or self.appear(self.I_CHECK_EXPLORATION):
+            sleep(0.5)
+            if self.appear(self.I_MATCHING) or self.appear(self.I_CHECK_EXPLORATION):
+                return True
+        return False
+    
+    def check_and_skip_battle_result(self, reuse_screenshot: bool = True) -> bool:
+        '''
+        检查是否当前为各种战斗结算界面之一,如果是,点击以便跳过该界面。
+        TODO 部分界面有顺序关系,考虑按顺序实现点击以避免不必要的匹配。
+        '''
+        if not reuse_screenshot:
+            self.screenshot()
+
+        # 打完后,第一个界面,左上角有一个统计,但是这个图不对,先跳过(跳过的结果是:会等界面超时自动跳转到:第二个界面,左下角有一个统计)
+        if self.appear(self.I_STATISTICS, threshold=0.8):
+            logger.info("OrochiMoans was started at {self.I_STATISTICS.name}")
+            self.ui_click_until_disappear(self.I_STATISTICS, interval=0.5)
+            return True
+
+        # 打完后,第二个界面,左下角有一个统计
+        if self.appear(self.I_REWARD_STATISTICS, threshold=0.8):
+            logger.info("OrochiMoans was started at {self.I_REWARD_STATISTICS.name}")
+            self.click(click=DokanAssets.C_DOKAN_RANDOM_CLICK_AREA2, interval=0.5)
+            return True
+
+        # 打完后,第三个界面,挑战成功
+        if self.appear(self.I_WIN):
+            action_click = random.choice([self.C_WIN_1, self.C_WIN_2, self.C_WIN_3])
+            self.click(click=action_click, interval=0.8)
+            return True
+
+        # 出现失败 就点击
+        if self.appear_then_click(self.I_FALSE, threshold=0.8):
+            logger.info("OrochiMoans was started at {self.I_FALSE.name}")
+            return True
+
+        # 领奖励
+        if self.appear(self.I_REWARD, threshold=0.65):
+            action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
+            self.click(click=action_click, interval=1.2)
+            logger.info("OrochiMoans was started at {self.I_REWARD.name}")
+            return True
+
+        # 领奖励出现金币
+        if self.appear_then_click(self.I_REWARD_GOLD, threshold=0.8):
+            logger.info("OrochiMoans was started at {self.I_REWARD_GOLD.name}")
+            return True
+
+        # 猫咪奖励
+        if self.appear(OrochiAssets.I_PET_PRESENT):
+            action_click = random.choice([self.C_WIN_1, self.C_WIN_2, self.C_WIN_3])
+            self.click(click=action_click, interval=0.6)
+            return True
+
+        return False
+    
+    def check_toppa_scroll(self, reuse_screenshot: bool = True) -> bool:
+        '''
+        检查突破券掉落
+        '''
+        if not reuse_screenshot:
+            self.screenshot()
+
+        # 匹配突破券
+        if self.I_TOPPA_SCROLL.match(self.device.image):
+            if self.is_first_check_toppa_scrolls:
+                # 仅第一次发现突破券的时候去点击,以查看当前突破券数量
+                self.click(self.I_TOPPA_SCROLL)
+                self.screenshot()
+                cu, res, total = self.O_TOPPA_SCROLL.ocr(self.device.image)
+                logger.warning(f'toppa scroll, cu={cu}, res={res}, total={total}')
+                if cu == 0 and cu + res == total:
+                    self.current_toppa_scroll_count = cu
+                self.is_first_check_toppa_scrolls = False
+            else:
+                self.current_toppa_scroll_count += 1
+            return True
+
+        return False
+
+    def battle_wait(self, random_click_swipt_enable: bool) -> bool:
+        """
+        战斗等待,加入突破券统计
+        :param random_click_swipt_enable: 
+        :return: True 战斗成功, False 战斗失败
+        """
+        # 重写
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        self.device.click_record_clear()
+        self.C_REWARD_1.name = 'C_REWARD'
+        self.C_REWARD_2.name = 'C_REWARD'
+        self.C_REWARD_3.name = 'C_REWARD'
+
+        # 战斗过程 随机点击和滑动 防封
+        # logger.info("OrochiMoans battle_wait")
+
+        while 1:
+            self.screenshot()
+            action_click = random.choice([self.C_WIN_1, self.C_WIN_2, self.C_WIN_3])
+            if self.appear_then_click(self.I_WIN, action=action_click ,interval=0.8):
+                # 赢的那个鼓
+                continue
+            if self.appear(self.I_GREED_GHOST):
+                # 检查突破券
+                self.check_toppa_scroll()
+
+                # 贪吃鬼
+                logger.info('OrochiMoans battle_wait:Win battle')
+                self.wait_until_appear(self.I_REWARD, wait_time=1.5)
+                self.screenshot()
+                if not self.appear(self.I_GREED_GHOST):
+                    logger.warning('OrochiMoans battle_wait: Greedy ghost disappear. Maybe it is a false battle')
+                    continue
+                while 1:
+                    self.screenshot()
+                    action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
+                    if not self.appear(self.I_GREED_GHOST):
+                        break
+                    if self.click(action_click, interval=1.5):
+                        continue
+                return True
+            if self.appear(self.I_REWARD):
+                # 魂
+                logger.info('OrochiMoans battle_wait: Win battle')
+                # appear_greed_ghost = self.appear(self.I_GREED_GHOST)
+                while 1:
+                    self.screenshot()
+                    action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
+                    if self.appear_then_click(self.I_REWARD, action=action_click, interval=1.5):
+                        continue
+                    if not self.appear(self.I_REWARD):
+                        break
+                return True
+
+            if self.appear(self.I_FALSE):
+                logger.warning('OrochiMoans battle_wait: False battle')
+                self.ui_click_until_disappear(self.I_FALSE)
+                return False
+
+            # 如果开启战斗过程随机滑动
+            if random_click_swipt_enable:
+                self.random_click_swipt()
+
+    def anti_detect(self, random_move: bool = True, random_click: bool = True, random_delay: bool = True):
+        '''额外的防封测试
+
+        准备找个号做做爬楼活动的每天300次试试
+        '''
+        res = False
+        # 三个行为中,任何一个生效了都返回True, 否则返回False
+        if random_move:
+            self.random_click_swipt()
+            res = True
+        if random_click:
+            # 0到2秒之间的随机浮点数
+            sleep = random.uniform(0, 2)
+            # 只保留2位小数
+            sleep = round(sleep, 2)
+            if self.anti_detect_click_fixed_random_area:
+                # 多搞几个安全点击区域
+                num = random.randint(0, 5)
+                if num == 0:
+                    self.click(click=DokanAssets.C_DOKAN_RANDOM_CLICK_AREA, interval=sleep)
+                elif num == 1:
+                    self.click(click=DokanAssets.C_DOKAN_RANDOM_CLICK_AREA2, interval=sleep)
+                elif num == 2:
+                    self.click(click=DokanAssets.C_DOKAN_RANDOM_CLICK_AREA3, interval=sleep)
+                elif num == 3:
+                    self.click(click=DokanAssets.C_DOKAN_RANDOM_CLICK_AREA, interval=sleep)
+                else:
+                    self.click(click=DokanAssets.C_DOKAN_RANDOM_CLICK_AREA2, interval=sleep)
+            else:
+                # 假设安全区域是绿色的  
+                safe_color_lower = np.array([45, 25, 25])  # HSV颜色空间的绿色下界  
+                safe_color_upper = np.array([90, 255, 255])  # HSV颜色空间的绿色上界
+                pos = detect_safe_area2(self.device.image, safe_color_lower, safe_color_upper, 3, True)
+                logger.info(f"random click area: {pos}, delay: {sleep}")
+                self.click(pos)
+
+            res = True
+        if random_delay:
+            # 0到2秒之间的随机浮点数
+            sleep = random.uniform(0, 5)
+            # 只保留2位小数
+            sleep = round(sleep, 2)
+            time.sleep(sleep)
+            res = True
+        return res
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+    c = Config('oas1')
+    d = Device(c)
+    t = ScriptTask(c, d)
+
+    t.run()

+ 102 - 0
tasks/OrochiMoans/utils.py

@@ -0,0 +1,102 @@
+import cv2
+# import pytesseract
+
+def find_image(image, pattern, threshold: float = 0.9, top1_only: bool = True, draw_result: bool = False):
+    '''
+    以图搜图
+    使用全图进行模板匹配,来匹配当前画面中有没有输入的pattern
+    :return 匹配到的数量
+    '''
+    results = cv2.matchTemplate(image, pattern, cv2.TM_CCOEFF_NORMED)
+
+    count = 0
+    img_disp = None
+    pos = []
+
+    if draw_result:
+        img_disp = image.copy()
+
+    if top1_only:
+        _, max_val, _, max_loc = cv2.minMaxLoc(results)
+        # 找到最佳匹配位置的坐标
+        if max_val >= threshold:
+            top_left = max_loc
+            bottom_right = (top_left[0] + pattern.shape[1], top_left[1] + pattern.shape[0])
+            count = 1
+            # print(f'top_left={top_left}, similiar={max_val}')
+
+            pos.append((top_left[0], top_left[1], bottom_right[0], bottom_right[1]))
+
+            if draw_result:
+                # 在原始图像上绘制矩形框来突出显示匹配出的图案
+                cv2.rectangle(img_disp, top_left, bottom_right, (0, 255, 0), 2)
+        else:
+            count = 0
+    else:
+        #筛选大于一定匹配值的点
+        val,result = cv2.threshold(results,threshold,1.0,cv2.THRESH_BINARY)
+        match_locs = cv2.findNonZero(result)
+        # print('match_locs.shape:',match_locs.shape) 
+        # print('match_locs:\n',match_locs)
+
+        count = len(match_locs)
+
+        # 找到最佳匹配位置的坐标
+        for match_loc_t in match_locs:
+            #match_locs是一个3维数组,第2维固定长度为1,取其下标0对应数组
+            top_left = match_loc_t[0]
+            bottom_right = (top_left[0] + pattern.shape[1], top_left[1] + pattern.shape[0])
+            # print(f'top_left={top_left}, similar={results[top_left[1],top_left[0]]}')
+
+            pos.append((top_left[0], top_left[1], bottom_right[0], bottom_right[1]))
+
+            if draw_result:
+                # 在原始图像上绘制矩形框来突出显示匹配出的图案
+                cv2.rectangle(img_disp, top_left, bottom_right, (0,255,0), 5, 8, 0 )
+                cv2.circle(result, top_left, 10, (255,0,0), 3 )
+
+        # TODO 去除重叠的区域,只留该区域里相似度最高的
+        
+
+    if draw_result:
+        cv2.imshow('Matched Result', img_disp)
+        cv2.waitKey(0)
+        cv2.destroyAllWindows()
+
+    return count, pos
+ 
+# def find_text(image, text) -> int:
+#     '''
+#     以文搜图
+#     使用图像识别库进行图像识别和文字检测
+#     使用全图进行模板匹配,来匹配当前画面中有没有输入的文字
+#     :return 匹配到的数量
+#     '''
+#     # 
+#     extracted_text = pytesseract.image_to_string(image)
+    
+#     match_indices = [i for i, item in enumerate(extracted_text) if text in item]
+ 
+#     count = len(match_indices)
+#     if count > 0:
+#         print(f'Found {count} locations matches the input pattern.')
+#         # 可以根据需求输出或显示匹配的结果
+#     else:
+#         print('Pattern not found.')
+
+#     return count
+
+if __name__ == '__main__':
+
+    # 读取待搜索的图像和目标图像
+    image_path = "tests/toppa_scrolls/test.png"
+    pattern_path = "tests/toppa_scrolls/res_toppa_scroll.png"
+
+    image = cv2.imread(image_path)
+    pattern = cv2.imread(pattern_path)
+    if image is None or pattern is None:
+        print(f"image file not exists? {image_path}, patter image file: {pattern_path}")
+    else:
+        # find_text(image, "突破")
+        count, pos = find_image(image, pattern, 0.9, False, False)
+        print(f"count={count}, pos={pos}")