Răsfoiți Sursa

feat(FindJade): 实现自动寻找勾协悬赏任务功能

- 新增 FindJade 任务模块,包括配置文件、脚本和相关资源
- 实现了切换账号、识别悬赏任务、自动邀请好友等功能
- 优化了悬赏任务的处理逻辑,支持只完成协作任务的选项
- 新增了邀请成功后的回调处理,用以更新邀请历史记录
ChengRanORZ 2 ani în urmă
părinte
comite
d20887215d

+ 35 - 0
config/findjade/find_jade.json

@@ -0,0 +1,35 @@
+{
+  "find_jade_accounts_info": [
+    {
+      "character": "小号1",
+      "svr": "万事屋",
+      "account": "150****4444",
+      "accountAlias": "150★***4444#150*★**4444#150**★*4444#150***★4444",
+      "appleOrAndroid": true,
+      "last_complete_time": "2024-11-12 18:02:28.342305"
+    },
+    {
+      "character": "小号2",
+      "svr": "祈世之舞",
+      "account": "150****4444",
+      "accountAlias": "150★***4444#150*★**4444#150**★*4444#150***★4444",
+      "appleOrAndroid": true,
+      "last_complete_time": "2024-11-12 18:03:08.517909"
+    }],
+  "invite_info_list": [
+    {
+      "name": "大号1",
+      "default_invite_type": "JadeAndFood",
+      "invite_history": [
+        {
+          "cooperation_type": 2,
+          "time": "2024-11-05 18:08:53.597534"
+        }]
+    },
+    {
+      "name": "大号2",
+      "default_invite_type": "JadeAndFood",
+      "invite_history": []
+    }],
+  "updateHandle": "<bound method ScriptTask.save_jade_json of <script_task.ScriptTask object at 0x000001C5E7229D50>>"
+}

+ 1 - 0
module/config/config_menu.py

@@ -32,6 +32,7 @@ class ConfigMenu:
             "Exploration",
             "Exploration",
             "Hyakkiyakou",
             "Hyakkiyakou",
             "HeroTest",
             "HeroTest",
+            "FindJade"
         ]
         ]
         # 阴阳寮
         # 阴阳寮
         self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'Dokan', 'CollectiveMissions',
         self.menu["Guild"] = ['KekkaiUtilize', 'KekkaiActivation', 'RealmRaid', 'RyouToppa', 'Dokan', 'CollectiveMissions',

+ 2 - 0
module/config/config_model.py

@@ -62,6 +62,7 @@ from tasks.GoryouRealm.config import GoryouRealm
 from tasks.Hyakkiyakou.config import Hyakkiyakou
 from tasks.Hyakkiyakou.config import Hyakkiyakou
 from tasks.HeroTest.config import HeroTest
 from tasks.HeroTest.config import HeroTest
 
 
+from tasks.FindJade.config import FindJade
 # ----------------------------------------------------------------------------------------------------------------------
 # ----------------------------------------------------------------------------------------------------------------------
 
 
 # 每周任务---------------------------------------------------------------------------------------------------------------
 # 每周任务---------------------------------------------------------------------------------------------------------------
@@ -119,6 +120,7 @@ class ConfigModel(ConfigBase):
     goryou_realm: GoryouRealm = Field(default_factory=GoryouRealm)
     goryou_realm: GoryouRealm = Field(default_factory=GoryouRealm)
     hyakkiyakou: Hyakkiyakou = Field(default_factory=Hyakkiyakou)
     hyakkiyakou: Hyakkiyakou = Field(default_factory=Hyakkiyakou)
     hero_test: HeroTest = Field(default_factory=HeroTest)
     hero_test: HeroTest = Field(default_factory=HeroTest)
+    find_jade: FindJade = Field(default_factory=FindJade)
 
 
     # 这些是每周任务
     # 这些是每周任务
     true_orochi: TrueOrochi = Field(default_factory=TrueOrochi)
     true_orochi: TrueOrochi = Field(default_factory=TrueOrochi)

BIN
tasks/AbyssShadows/__pycache__/assets.cpython-310.pyc


BIN
tasks/AbyssShadows/__pycache__/config.cpython-310.pyc


BIN
tasks/AbyssShadows/__pycache__/script_task.cpython-310.pyc


+ 14 - 0
tasks/FindJade/README.md

@@ -0,0 +1,14 @@
+详细配置文件见config/findjade/find_jade.json
+
+
+### **注意事项:**
+
+1. 可以配置多个被邀请对象,但每次只会按从前到后的顺序邀请一个.
+2. 小号配置相关信息见[这里](../../tasks/Component/SwitchAccount/README.md)
+3. 需要额外开启一个模拟器,用以切换登录小号
+4. 要求被邀请对象处于登录状态,与小号是好友关系
+5. 关于配置文件中的 updateHandle,这..我也不知道为什么方法名会出现在这(配置文件的序列化研究了下,没看出什么端倪),不过删掉会出问题,所以还是留着吧.
+
+### **运行中可能出现的问题:**
+1. 小号存在打不过的情况,导致邀请完成后,无法完成任务,需手动搞一下 
+2. 由于本人电脑配置一般(16GB内存,5个模拟器满载),所以部分延时写的挺长,可以根据情况酌情调整

+ 30 - 0
tasks/FindJade/WantedQuestsEx.py

@@ -0,0 +1,30 @@
+import importlib
+from tasks.WantedQuests.config import WantedQuests, CooperationType, WantedQuestsConfig
+
+
+def need_invite_vip(self):
+    return True
+
+
+def get_invite_vip_name(self, ctype: CooperationType):
+    if not self.fade_conf:
+        return ""
+    return self.fade_conf.get_invite_name(ctype)
+
+
+def next_run(self):
+    pass
+
+
+def invite_success_callback(self, ctype: CooperationType, name: str):
+    if not self.fade_conf:
+        return
+    self.fade_conf.update_invite_history(ctype, name)
+
+
+def get_config(self):
+    config=WantedQuestsConfig()
+    config.invite_friend_name="default"
+    config.cooperation_only=True
+    config.cooperation_type=self.fade_conf.get_cooperation_type_mask()
+    return config

+ 12 - 0
tasks/FindJade/assets.py

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

+ 104 - 0
tasks/FindJade/config.py

@@ -0,0 +1,104 @@
+import json
+from datetime import datetime, timedelta
+from enum import IntEnum
+from pydantic import Field, BaseModel
+from tasks.Component.SwitchAccount.switch_account_config import AccountInfo
+from tasks.Component.config_base import ConfigBase
+from tasks.Component.config_scheduler import Scheduler
+from module.config.utils import write_file
+from tasks.WantedQuests.config import CooperationSelectMaskDescription, CooperationSelectMask, CooperationType
+from typing import List, Any
+
+
+class FindJadeConfig(BaseModel):
+    find_jade_json_path: str = Field(default='./config/findjade/find_jade.json', description='json conf file path')
+    # extra: str = Field(default='')
+
+
+class FindJade(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    find_jade_config: FindJadeConfig = Field(default_factory=FindJadeConfig)
+
+
+class InviteHistoryItem(BaseModel):
+    cooperation_type: CooperationType
+    time: datetime
+
+
+class InviteInfo(BaseModel):
+    # 被邀请人员昵称
+    name: str = "defaultName"
+    default_invite_type: CooperationSelectMaskDescription
+
+    # 协作任务类型   上次邀请时间
+    invite_history: list[InviteHistoryItem]
+
+    def need_invite(self, ctype: CooperationType):
+        if not ctype & CooperationSelectMask[self.default_invite_type.value]:
+            return False
+        # 判断是否邀请过
+        lastTime = max([filtered.time for filtered in
+                        filter(lambda x: x.cooperation_type == ctype, self.invite_history)],
+                       default=datetime(1970, 2, 2))
+
+        now = datetime.now()
+        if now - lastTime > timedelta(hours=13):
+            return True
+        if (lastTime.hour >= 18 or lastTime.hour < 5) and (18 > now.hour >= 5):
+            return True
+        if (5 <= lastTime.hour < 18) and now.hour >= 18:
+            return True
+        return False
+
+    def add_invite_history(self, ctype: CooperationType, name=None):
+        if name != self.name:
+            return
+        self.invite_history.append(InviteHistoryItem(cooperation_type=ctype, time=datetime.now()))
+        pass
+
+
+class FindJadeJSON(BaseModel, extra='allow'):
+    find_jade_accounts_info: list[AccountInfo]
+    invite_info_list: list[InviteInfo]
+
+    def get_invite_name(self, ctype: CooperationType):
+        for info in self.invite_info_list:
+            if info.need_invite(ctype):
+                return info.name
+        return ""
+
+    def update_invite_history(self, ctype: CooperationType, name: str):
+        # 更新邀请信息
+        for info in self.invite_info_list:
+            if info.name != name:
+                continue
+            info.add_invite_history(ctype, name)
+        self.updateHandle()
+
+    def update_account_login_history(self, account: AccountInfo):
+        accountInfoList = self.find_jade_accounts_info
+        for info in accountInfoList:
+            if info.character != account.character or info.svr != account.svr:
+                continue
+            info.last_complete_time = datetime.now()
+        self.updateHandle()
+
+    def get_cooperation_type_mask(self) -> CooperationSelectMaskDescription:
+        """
+            根据配置中各个邀请人 的邀请类型
+            综合得出该值
+        """
+        result = CooperationSelectMask.NoInvite
+        for info in self.invite_info_list:
+            result |= CooperationSelectMask[info.default_invite_type]
+        name = CooperationSelectMask(result).name
+        return CooperationSelectMaskDescription(name)
+
+    def save2file(self, conf_path):
+        write_file(conf_path, self.dict())
+
+    def updateHandle(self):
+        """
+            需要刷新配置到磁盘时调用
+        """
+        pass

+ 122 - 0
tasks/FindJade/script_task.py

@@ -0,0 +1,122 @@
+import importlib
+from datetime import datetime, timedelta
+
+from module.config.utils import read_file
+from module.exception import TaskEnd, RequestHumanTakeover
+from tasks.Component.SwitchAccount.switch_account import SwitchAccount
+from tasks.FindJade import WantedQuestsEx
+from tasks.FindJade.assets import FindJadeAssets
+from tasks.FindJade.config import AccountInfo, FindJadeJSON
+from tasks.GameUi.game_ui import GameUi
+from tasks.WantedQuests.config import CooperationSelectMaskDescription
+from module.logger import logger
+
+
+class ScriptTask(GameUi, FindJadeAssets):
+    fade_conf: FindJadeJSON = None
+
+    def run(self):
+        self.fade_conf = self.parse()
+
+        self.fade_conf.updateHandle = self.save_jade_json
+        for accountInfo in self.fade_conf.find_jade_accounts_info:
+            logger.info("start %s-%s ", accountInfo.character, accountInfo.svr)
+            if not self.is_need_login(accountInfo):
+                logger.warning("%s Skipped last Login Time:%s", accountInfo.character, accountInfo.last_complete_time)
+                continue
+            suc = SwitchAccount(self.config, self.device, accountInfo).switchAccount()
+            if not suc:
+                logger.warning("switch to %s-%s Failed", accountInfo.character, accountInfo.svr)
+                continue
+            #
+            wq = self.CreatObjectFromModule("WantedQuests", config=self.config, device=self.device)
+            wq.fade_conf = self.fade_conf
+
+            try:
+                wq.run()
+            except TaskEnd as e:
+                logger.warning("%s-%s TaskEnd", accountInfo.character, accountInfo.svr)
+                # 更新配置文件中的时间
+                self.fade_conf.update_account_login_history(accountInfo)
+                self.fade_conf.save2file(self.config.find_jade.find_jade_config.find_jade_json_path)
+                continue
+            except RequestHumanTakeover as e:
+                raise
+            except Exception as e:
+                self.next_run("FindJade", success=False)
+        self.next_run("FindJade",success=True)
+        raise TaskEnd("FindJade")
+        pass
+
+    def parse(self) -> FindJadeJSON:
+
+        conf_path = self.config.find_jade.find_jade_config.find_jade_json_path
+        jsonData = read_file(conf_path)
+        fjconf = FindJadeJSON(**jsonData)
+        return fjconf
+
+    def is_need_login(self, item: AccountInfo):
+        """
+            根据上次登陆时间 判断是否需要登录查找
+        @param item:
+        @type item:
+        """
+        lastTime = item.last_complete_time
+        now = datetime.now()
+        if now - lastTime > timedelta(hours=13):
+            return True
+        if (lastTime.hour >= 18 or lastTime.hour < 5) and (18 > now.hour >= 5):
+            return True
+        if (5 <= lastTime.hour < 18) and now.hour >= 18:
+            return True
+        return False
+
+    def CreatObjectFromModule(self, task_name: str, **kwargs):
+        module_name = 'script_task'
+        from pathlib import Path
+        module_path = str(Path.cwd() / 'tasks' / task_name / (module_name + '.py'))
+
+        spec = importlib.util.spec_from_file_location(module_name, module_path)
+        module = importlib.util.module_from_spec(spec)
+        spec.loader.exec_module(module)
+
+        WQEX = type("WQEX", (module.ScriptTask,), {
+            "need_invite_vip": WantedQuestsEx.need_invite_vip,
+            "get_invite_vip_name": WantedQuestsEx.get_invite_vip_name,
+            "next_run": WantedQuestsEx.next_run,
+            "invite_success_callback": WantedQuestsEx.invite_success_callback,
+            "get_config": WantedQuestsEx.get_config
+        })
+        wq = WQEX(**kwargs)
+        return wq
+
+    def save_jade_json(self):
+        conf_path = self.config.find_jade.find_jade_config.find_jade_json_path
+        self.fade_conf.save2file(conf_path)
+
+    def next_run(self, task: str, finish: bool = False,
+                 success: bool = None, server: bool = True, target: datetime = None) -> None:
+        now = datetime.now()
+        if success:
+            if (5 <= now.hour < 18):
+                self.set_next_run(task, target=now.replace(hour=18, minute=5))
+            elif (now.hour < 5):
+                self.set_next_run(task, target=now.replace(hour=5, minute=5))
+            else:
+                self.set_next_run(task, target=now.replace(hour=18, minute=5) + timedelta(days=1))
+        else:
+            self.set_next_run(task, target=now+timedelta(minutes=10))
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+    from mypatch import SimplePatch
+
+    SimplePatch.patch()
+
+    c = Config('oas1')
+    d = Device(c)
+    t = ScriptTask(c, d)
+
+    t.run()

+ 12 - 2
tasks/WantedQuests/assets.py

@@ -15,6 +15,8 @@ class WantedQuestsAssets:
 	C_SECRET_CHAT = RuleClick(roi_front=(597,296,59,100), roi_back=(597,296,59,100), name="secret_chat")
 	C_SECRET_CHAT = RuleClick(roi_front=(597,296,59,100), roi_back=(597,296,59,100), name="secret_chat")
 	# 特殊的庭院需要点击,然后才能找到这个悬赏 
 	# 特殊的庭院需要点击,然后才能找到这个悬赏 
 	C_SPECIAL_MAIN = RuleClick(roi_front=(409,572,32,30), roi_back=(404,569,41,35), name="special_main")
 	C_SPECIAL_MAIN = RuleClick(roi_front=(409,572,32,30), roi_back=(404,569,41,35), name="special_main")
+	# 关闭 单个任务追踪界面 所需点击 的  空白区域 
+	C_WQ_TRACE_ONE_CLOSE = RuleClick(roi_front=(170,30,400,100), roi_back=(170,30,400,100), name="wq_trace_one_close")
 
 
 
 
 	# Ocr Rule Assets
 	# Ocr Rule Assets
@@ -83,7 +85,7 @@ class WantedQuestsAssets:
 	# 悬赏封印邀请取消按钮 
 	# 悬赏封印邀请取消按钮 
 	I_WQ_INVITE_CANCEL = RuleImage(roi_front=(230,540,132,60), roi_back=(230,540,140,65), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/wq_invite_cancel.png")
 	I_WQ_INVITE_CANCEL = RuleImage(roi_front=(230,540,132,60), roi_back=(230,540,140,65), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/wq_invite_cancel.png")
 	# 邀请好友被选中标记 
 	# 邀请好友被选中标记 
-	I_WQ_INVITE_SELECTED = RuleImage(roi_front=(380,170,32,32), roi_back=(380,170,360,375), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/wq_invite_selected.png")
+	I_WQ_INVITE_SELECTED = RuleImage(roi_front=(370,180,32,32), roi_back=(370,180,370,355), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/wq_invite_selected.png")
 	# 邀请同服好友,由于选中与未选中亮度有区别,查找图片可能会出错,建议只使用位置信息 
 	# 邀请同服好友,由于选中与未选中亮度有区别,查找图片可能会出错,建议只使用位置信息 
 	I_WQ_INVITE_SAME_SVR = RuleImage(roi_front=(170,90,60,35), roi_back=(170,90,105,65), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/wq_invite_same_svr.png")
 	I_WQ_INVITE_SAME_SVR = RuleImage(roi_front=(170,90,60,35), roi_back=(170,90,105,65), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/invite/wq_invite_same_svr.png")
 	# 邀请跨服好友,由于选中与未选中亮度有区别,查找图片可能会出错,建议只使用位置信息 
 	# 邀请跨服好友,由于选中与未选中亮度有区别,查找图片可能会出错,建议只使用位置信息 
@@ -135,7 +137,7 @@ class WantedQuestsAssets:
 	# 一键追踪 
 	# 一键追踪 
 	I_TRACE_ENABLE = RuleImage(roi_front=(1097,588,101,70), roi_back=(1097,588,101,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_trace_enable.png")
 	I_TRACE_ENABLE = RuleImage(roi_front=(1097,588,101,70), roi_back=(1097,588,101,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_trace_enable.png")
 	# 取消追踪 
 	# 取消追踪 
-	I_TARCE_DISENABLE = RuleImage(roi_front=(1091,586,108,70), roi_back=(1091,586,108,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_tarce_disenable.png")
+	I_TRACE_DISABLE = RuleImage(roi_front=(1091,586,108,70), roi_back=(1091,586,108,70), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_trace_disable.png")
 	# 奖励宝箱 
 	# 奖励宝箱 
 	I_WQ_BOX = RuleImage(roi_front=(48,187,43,38), roi_back=(20,137,100,397), threshold=0.7, method="Template matching", file="./tasks/WantedQuests/wq/wq_wq_box.png")
 	I_WQ_BOX = RuleImage(roi_front=(48,187,43,38), roi_back=(20,137,100,397), threshold=0.7, method="Template matching", file="./tasks/WantedQuests/wq/wq_wq_box.png")
 	# 小号追踪 
 	# 小号追踪 
@@ -152,6 +154,14 @@ class WantedQuestsAssets:
 	I_GOTO_4 = RuleImage(roi_front=(979,447,87,42), roi_back=(979,447,87,42), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_goto_4.png")
 	I_GOTO_4 = RuleImage(roi_front=(979,447,87,42), roi_back=(979,447,87,42), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_goto_4.png")
 	# 判断是否还有任务 
 	# 判断是否还有任务 
 	I_WQ_CHECK_TASK = RuleImage(roi_front=(110,154,21,125), roi_back=(73,122,69,459), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_wq_check_task.png")
 	I_WQ_CHECK_TASK = RuleImage(roi_front=(110,154,21,125), roi_back=(73,122,69,459), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_wq_check_task.png")
+	# 庭院悬赏任务界面 单个任务点开后 左上角是否追踪 
+	I_WQ_TRACE_ONE_ENABLE = RuleImage(roi_front=(160,175,120,60), roi_back=(160,175,120,60), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_trace_one_enable.png")
+	# 庭院悬赏任务界面 单个任务点开后 左上角是否追踪 
+	I_WQ_TRACE_ONE_DISABLE = RuleImage(roi_front=(160,175,120,60), roi_back=(160,175,120,60), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_trace_one_disable.png")
+	# 庭院悬赏任务界面 单个任务点开后的界面 是否打开的 标志 
+	I_WQ_TRACE_ONE_CHECK_OPENED = RuleImage(roi_front=(510,175,210,60), roi_back=(510,175,210,60), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_trace_one_check_opened.png")
+	# 庭院悬赏任务界面 单个任务点开后的界面 是否为现世任务标志 
+	I_WQ_TRACE_ONE_REALWORLD = RuleImage(roi_front=(850,470,180,180), roi_back=(850,470,180,180), threshold=0.8, method="Template matching", file="./tasks/WantedQuests/wq/wq_trace_one_realworld.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets

+ 6 - 0
tasks/WantedQuests/click.json

@@ -10,5 +10,11 @@
     "roiFront": "409,572,32,30",
     "roiFront": "409,572,32,30",
     "roiBack": "404,569,41,35",
     "roiBack": "404,569,41,35",
     "description": "特殊的庭院需要点击,然后才能找到这个悬赏"
     "description": "特殊的庭院需要点击,然后才能找到这个悬赏"
+  },
+  {
+    "itemName": "wq_trace_one_close",
+    "roiFront": "170,30,400,100",
+    "roiBack": "170,30,400,100",
+    "description": "关闭 单个任务追踪界面 所需点击 的  空白区域"
   }
   }
 ]
 ]

+ 5 - 1
tasks/WantedQuests/config.py

@@ -20,6 +20,9 @@ class CooperationType(int, Enum):
     Food = 4     #狗/猫粮协作   
     Food = 4     #狗/猫粮协作   
     Sushi = 8    #体力协作
     Sushi = 8    #体力协作
 
 
+    def __hash__(self):
+        return self.value
+
 
 
 class CooperationSelectMask(int, Enum):
 class CooperationSelectMask(int, Enum):
     """
     """
@@ -84,7 +87,8 @@ class WantedQuestsConfig(BaseModel):
     cooperation_type: CooperationSelectMaskDescription = Field(default=CooperationSelectMaskDescription.Any, description="cooperation_type_help")
     cooperation_type: CooperationSelectMaskDescription = Field(default=CooperationSelectMaskDescription.Any, description="cooperation_type_help")
     # 找怪优先级  挑战 > 秘闻 > 探索
     # 找怪优先级  挑战 > 秘闻 > 探索
     battle_priority: str = Field(default='挑战 > 秘闻 > 探索', description='battle_priority_help')
     battle_priority: str = Field(default='挑战 > 秘闻 > 探索', description='battle_priority_help')
-
+	# 只完成协作任务
+    cooperation_only: bool = Field(default=False, description="cooperation_only_help")
 
 
 
 
 class WantedQuests(ConfigBase):
 class WantedQuests(ConfigBase):

+ 2 - 2
tasks/WantedQuests/invite/image.json

@@ -92,8 +92,8 @@
   {
   {
     "itemName": "wq_invite_selected",
     "itemName": "wq_invite_selected",
     "imageName": "wq_invite_selected.png",
     "imageName": "wq_invite_selected.png",
-    "roiFront": "380,170,32,32",
-    "roiBack": "380,170,360,375",
+    "roiFront": "370,180,32,32",
+    "roiBack": "370,180,370,355",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "邀请好友被选中标记"
     "description": "邀请好友被选中标记"

BIN
tasks/WantedQuests/invite/wq_invite_cancel.png


+ 115 - 15
tasks/WantedQuests/script_task.py

@@ -43,7 +43,12 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             self.ui_goto(page_shikigami_records)
             self.ui_goto(page_shikigami_records)
             self.run_switch_soul_by_name(con.switch_soul_config.group_name, con.switch_soul_config.team_name)
             self.run_switch_soul_by_name(con.switch_soul_config.group_name, con.switch_soul_config.team_name)
 
 
-        if not self.pre_work():
+        preSuc = False
+        if (self.get_config()).cooperation_only:
+            preSuc = self.pre_work_cooperation_only()
+        else:
+            preSuc = self.pre_work()
+        if not preSuc:
             # 无法完成预处理 很有可能你已经完成了悬赏任务
             # 无法完成预处理 很有可能你已经完成了悬赏任务
             logger.warning('Cannot pre-work')
             logger.warning('Cannot pre-work')
             logger.warning('You may have completed the reward task')
             logger.warning('You may have completed the reward task')
@@ -104,7 +109,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         raise TaskEnd('WantedQuests')
         raise TaskEnd('WantedQuests')
 
 
     def next_run(self):
     def next_run(self):
-        before_end: time = self.config.wanted_quests.wanted_quests_config.before_end
+        before_end: time = self.get_config().before_end
         if before_end == time(hour=0, minute=0, second=0):
         if before_end == time(hour=0, minute=0, second=0):
             self.set_next_run(task='WantedQuests', success=True, finish=True)
             self.set_next_run(task='WantedQuests', success=True, finish=True)
             return
             return
@@ -135,7 +140,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         done_timer = Timer(5)
         done_timer = Timer(5)
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
-            if self.appear(self.I_TARCE_DISENABLE):
+            if self.appear(self.I_TRACE_DISABLE):
                 break
                 break
             if self.appear_then_click(self.I_WQ_SEAL, interval=1):
             if self.appear_then_click(self.I_WQ_SEAL, interval=1):
                 continue
                 continue
@@ -158,14 +163,75 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         # 存在协作任务则邀请
         # 存在协作任务则邀请
         self.screenshot()
         self.screenshot()
         if self.appear(self.I_WQ_INVITE_1) or self.appear(self.I_WQ_INVITE_2) or self.appear(self.I_WQ_INVITE_3):
         if self.appear(self.I_WQ_INVITE_1) or self.appear(self.I_WQ_INVITE_2) or self.appear(self.I_WQ_INVITE_3):
-            if self.config.wanted_quests.wanted_quests_config.invite_friend_name:
-                self.all_cooperation_invite(self.config.wanted_quests.wanted_quests_config.invite_friend_name)
+            if self.need_invite_vip():
+                self.all_cooperation_invite()
             else:
             else:
                 self.invite_five()
                 self.invite_five()
         self.ui_click_until_disappear(self.I_UI_BACK_RED)
         self.ui_click_until_disappear(self.I_UI_BACK_RED)
         self.ui_goto(page_exploration)
         self.ui_goto(page_exploration)
         return True
         return True
 
 
+    def pre_work_cooperation_only(self):
+        #
+        if self.ui_get_current_page() != page_main:
+            self.ui_goto(page_main)
+        # 打开悬赏封印 界面
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_TRACE_ENABLE) or self.appear(self.I_TRACE_DISABLE):
+                break
+            if self.appear_then_click(self.I_WQ_SEAL, interval=1):
+                continue
+            if self.appear_then_click(self.I_WQ_DONE, interval=1):
+                continue
+            if self.special_main and self.click(self.C_SPECIAL_MAIN, interval=3):
+                logger.info('Click special main left to find wanted quests')
+                continue
+        #
+        if not (self.appear(self.I_WQ_INVITE_1) or self.appear(self.I_WQ_INVITE_2) or self.appear(self.I_WQ_INVITE_3)):
+            logger.info("there is no cooperation quest")
+            return False
+
+        # if self.appear(self.I_WQ_INVITE_1):
+        #     self.trace_one(self.I_WQ_INVITE_1)
+        # if self.appear(self.I_WQ_INVITE_2):
+        #     self.trace_one(self.I_WQ_INVITE_2)
+        # if self.appear(self.I_WQ_INVITE_3):
+        #     self.trace_one(self.I_WQ_INVITE_3)
+
+        # 追踪任务 并邀请
+        self.all_cooperation_invite()
+
+        self.ui_click_until_disappear(self.I_UI_BACK_RED)
+        self.ui_goto(page_exploration)
+        return True
+
+    def trace_one(self, btn: RuleImage):
+        """
+            参数必须为邀请按钮(I_WQ_INVITE_n ),特定场景,就不做通用的函数了,怪麻烦的,若还有什么奇葩需求,再扩展吧
+        @param btn: 邀请按钮,
+        @type btn:
+        """
+        self.screenshot()
+        if not self.appear(btn):
+            return
+        while 1:
+            self.screenshot()
+            # 追踪成功  或  是现世任务 不需要追踪
+            if self.appear(self.I_WQ_TRACE_ONE_ENABLE) or self.appear(self.I_WQ_TRACE_ONE_REALWORLD):
+                break
+            if self.appear(self.I_WQ_TRACE_ONE_DISABLE):
+                self.click(self.I_WQ_TRACE_ONE_DISABLE, interval=1.5)
+                continue
+            # 根据邀请按钮位置生成 对应的点击位置 打开追踪界面
+            # NOTE magic Number
+
+            self.device.click(btn.roi_front[0], btn.roi_front[1] - 40, control_name=str(btn) + ' y-40')
+            # 防止点击后界面来不及刷新
+            sleep(1.5)
+        # 关闭单个任务的追踪界面
+        self.ui_click(self.C_WQ_TRACE_ONE_CLOSE, stop=self.I_WQ_TRACE_ONE_CHECK_OPENED, interval=1.5)
+
     def execute_mission(self, ocr, num_want: int, num_challenge: int):
     def execute_mission(self, ocr, num_want: int, num_challenge: int):
         """
         """
 
 
@@ -253,8 +319,8 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             logger.warning('The extreme case. The quest only needs to challenge one final boss, so skip it')
             logger.warning('The extreme case. The quest only needs to challenge one final boss, so skip it')
             self.want_strategy_excluding.append(info_wq_list[0])
             self.want_strategy_excluding.append(info_wq_list[0])
 
 
-    def challenge(self, goto, num):
-        self.ui_click(goto, self.I_WQC_FIRE)
+    def challenge(self, goto_btn, num):
+        self.ui_click(goto_btn, self.I_WQC_FIRE)
         self.ui_click(self.I_WQC_UNLOCK, self.I_WQC_LOCK)
         self.ui_click(self.I_WQC_UNLOCK, self.I_WQC_LOCK)
         self.ui_click_until_disappear(self.I_WQC_FIRE)
         self.ui_click_until_disappear(self.I_WQC_FIRE)
         # 锁定阵容进入战斗
         # 锁定阵容进入战斗
@@ -331,10 +397,10 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         self.invite_random(self.I_WQ_INVITE_2)
         self.invite_random(self.I_WQ_INVITE_2)
         self.invite_random(self.I_WQ_INVITE_3)
         self.invite_random(self.I_WQ_INVITE_3)
 
 
-    def all_cooperation_invite(self, name: str):
+    def all_cooperation_invite(self, name: str=None):
         """
         """
             所有的协作任务依次邀请
             所有的协作任务依次邀请
-        @param name: 被邀请的朋友名
+            如果配置了只完成协作任务 还会将该任务设置为追踪
         @return:
         @return:
 
 
         """
         """
@@ -347,7 +413,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             logger.info("no Cooperation found")
             logger.info("no Cooperation found")
             return False
             return False
         typeMask = 15
         typeMask = 15
-        typeMask = CooperationSelectMask[self.config.wanted_quests.wanted_quests_config.cooperation_type.value]
+        typeMask = CooperationSelectMask[(self.get_config()).cooperation_type.value]
         for item in ret:
         for item in ret:
             # 该任务是需要邀请的任务类型
             # 该任务是需要邀请的任务类型
             if not (item['type'] & typeMask):
             if not (item['type'] & typeMask):
@@ -361,15 +427,26 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
                阴阳师BUG: 好友明明在线 但邀请界面找不到该好友(好友未接受任何协作任务的情况下)
                阴阳师BUG: 好友明明在线 但邀请界面找不到该好友(好友未接受任何协作任务的情况下)
            '''
            '''
             index = 0
             index = 0
+            item['inviteResult'] = False
+            if name is None:
+                name = self.get_invite_vip_name(item['type'])
+            logger.warning("find cooperationType %s ,start invite %s", item['type'], name)
             while index < 5:
             while index < 5:
                 if self.cooperation_invite(item['inviteBtn'], name):
                 if self.cooperation_invite(item['inviteBtn'], name):
                     item['inviteResult'] = True
                     item['inviteResult'] = True
                     index = 5
                     index = 5
+                    continue
                 logger.info("%s not found,Wait 20s,%d invitations left", name, 5 - index - 1)
                 logger.info("%s not found,Wait 20s,%d invitations left", name, 5 - index - 1)
                 index += 1
                 index += 1
                 sleep(20) if index < 5 else sleep(0)
                 sleep(20) if index < 5 else sleep(0)
                 # NOTE 等待过程如果出现协作邀请 将会卡住 为了防止卡住
                 # NOTE 等待过程如果出现协作邀请 将会卡住 为了防止卡住
                 self.screenshot()
                 self.screenshot()
+            # 邀请追踪一起吧,只有邀请成功才追踪
+            if item['inviteResult']:
+                self.invite_success_callback(item['type'], name)
+                if (self.get_config()).cooperation_only:
+                    logger.info("start trace_one")
+                    self.trace_one(item['inviteBtn'])
         return ret
         return ret
 
 
     def cooperation_invite(self, btn: RuleImage, name: str):
     def cooperation_invite(self, btn: RuleImage, name: str):
@@ -380,6 +457,8 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         @return:
         @return:
         """
         """
         self.ui_click(btn, self.I_WQ_INVITE_ENSURE, interval=2.5)
         self.ui_click(btn, self.I_WQ_INVITE_ENSURE, interval=2.5)
+        # 等待好友列表加载
+        sleep(1.5)
 
 
         # 选人
         # 选人
         self.O_WQ_INVITE_COLUMN_1.keyword = name
         self.O_WQ_INVITE_COLUMN_1.keyword = name
@@ -392,22 +471,23 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             in_col_2 = self.ocr_appear_click(self.O_WQ_INVITE_COLUMN_2)
             in_col_2 = self.ocr_appear_click(self.O_WQ_INVITE_COLUMN_2)
             find = in_col_2 or in_col_1
             find = in_col_2 or in_col_1
             if find:
             if find:
+                sleep(4)
                 self.screenshot()
                 self.screenshot()
                 if self.appear(self.I_WQ_INVITE_SELECTED):
                 if self.appear(self.I_WQ_INVITE_SELECTED):
                     logger.info("friend found and selected")
                     logger.info("friend found and selected")
                     break
                     break
                 # TODO OCR识别到文字 但是没有选中 尝试重新选择  (选择好友时,弹出协作邀请导致选择好友失败)
                 # TODO OCR识别到文字 但是没有选中 尝试重新选择  (选择好友时,弹出协作邀请导致选择好友失败)
-            # 在当前服务器没找到,切换服务器
-            self.click(self.I_WQ_INVITE_DIFF_SVR)
+            # 在当前服务器没找到,切换服务器  30s 防止短时间连续点击
+            self.click(self.I_WQ_INVITE_DIFF_SVR, interval=30)
             # NOTE 跨服好友刷新缓慢,切换标签页难以检测,姑且用延时.非常卡的模拟器可能出问题
             # NOTE 跨服好友刷新缓慢,切换标签页难以检测,姑且用延时.非常卡的模拟器可能出问题
-            sleep(2)
+            sleep(4)
         # 没有找到需要邀请的人,点击取消 返回悬赏封印界面
         # 没有找到需要邀请的人,点击取消 返回悬赏封印界面
         if not find:
         if not find:
             self.screenshot()
             self.screenshot()
-            self.click(self.I_WQ_INVITE_CANCEL)
+            self.ui_click_until_disappear(self.I_WQ_INVITE_CANCEL, interval=0.5)
             return False
             return False
         #
         #
-        self.ui_click_until_disappear(self.I_WQ_INVITE_ENSURE)
+        self.ui_click_until_disappear(self.I_WQ_INVITE_ENSURE, interval=1)
         return True
         return True
 
 
     def get_cooperation_info(self) -> List:
     def get_cooperation_info(self) -> List:
@@ -449,6 +529,26 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             return True
             return True
         return False
         return False
 
 
+    def get_config(self):
+        return self.config.wanted_quests.wanted_quests_config
+
+    def need_invite_vip(self):
+        return bool(self.get_config().invite_friend_name)
+
+    def get_invite_vip_name(self, ctype: CooperationType):
+        return self.get_config().invite_friend_name
+
+    def invite_success_callback(self, ctype: CooperationType, name):
+        """
+           邀请成功回调
+        @param ctype:
+        @type ctype:
+        @param name:
+        @type name:
+        """
+
+        return True
+
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config

+ 38 - 2
tasks/WantedQuests/wq/image.json

@@ -27,8 +27,8 @@
     "description": "一键追踪"
     "description": "一键追踪"
   },
   },
   {
   {
-    "itemName": "tarce_disenable",
-    "imageName": "wq_tarce_disenable.png",
+    "itemName": "trace_disable",
+    "imageName": "wq_trace_disable.png",
     "roiFront": "1091,586,108,70",
     "roiFront": "1091,586,108,70",
     "roiBack": "1091,586,108,70",
     "roiBack": "1091,586,108,70",
     "method": "Template matching",
     "method": "Template matching",
@@ -106,5 +106,41 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "判断是否还有任务"
     "description": "判断是否还有任务"
+  },
+  {
+    "itemName": "wq_trace_one_enable",
+    "imageName": "wq_trace_one_enable.png",
+    "roiFront": "160,175,120,60",
+    "roiBack": "160,175,120,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "庭院悬赏任务界面 单个任务点开后 左上角是否追踪"
+  },
+  {
+    "itemName": "wq_trace_one_disable",
+    "imageName": "wq_trace_one_disable.png",
+    "roiFront": "160,175,120,60",
+    "roiBack": "160,175,120,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "庭院悬赏任务界面 单个任务点开后 左上角是否追踪"
+  },
+  {
+    "itemName": "wq_trace_one_check_opened",
+    "imageName": "wq_trace_one_check_opened.png",
+    "roiFront": "510,175,210,60",
+    "roiBack": "510,175,210,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "庭院悬赏任务界面 单个任务点开后的界面 是否打开的 标志"
+  },
+  {
+    "itemName": "wq_trace_one_realworld",
+    "imageName": "wq_trace_one_realworld.png",
+    "roiFront": "850,470,180,180",
+    "roiBack": "850,470,180,180",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "庭院悬赏任务界面 单个任务点开后的界面 是否为现世任务标志"
   }
   }
 ]
 ]

BIN
tasks/WantedQuests/wq/wq_trace_disable.png


BIN
tasks/WantedQuests/wq/wq_trace_one_check_opened.png


BIN
tasks/WantedQuests/wq/wq_trace_one_disable.png


BIN
tasks/WantedQuests/wq/wq_trace_one_enable.png


BIN
tasks/WantedQuests/wq/wq_trace_one_realworld.png