Browse Source

feat(OtherWorldTwilight): 新增御魂副本任务彼世逢魔

- 新增 tasks/OtherWorldTwilight/,支持队长/队员/单人三种模式
- script_task: 队长建房邀请、队员接受邀请、单人直接挑战三种流程
- 注册 config_model / config_menu(Soul Zones) / config_manual
- 补充 zh_CN.xml 与 assets/i18n/zh-CN.json 翻译

来自 mine
User 1 month ago
parent
commit
78083db2ec

+ 2 - 0
assets/i18n/zh-CN.json

@@ -60,6 +60,8 @@
   "enable_switch_cultivation_drills": "修行合训开启切换御魂",
   "demon_battle_config": "逢魔战斗内切换阵容",
   "best_demon_battle_config": "极逢魔战斗内切换阵容",
+  "OtherWorldTwilight": "彼世逢魔",
+  "other_world_twilight_config": "彼世逢魔配置",
   "anti_ban": "防风控作息",
   "antiban_enable_help": "开启后启用作息约束(睡眠时间窗、累计活跃上限、强制休息),用于避免24小时不间断/深夜连续运行这类服务端可见的异常行为特征。\n注意:点击/滑动的拟人化(真实按压时长、坐标高斯化、微动、压力抖动)始终生效,不受此开关控制。",
   "sleep_start": "睡眠开始时间",

+ 1 - 1
module/config/config_manual.py

@@ -12,7 +12,7 @@ class ConfigManual:
         > KekkaiUtilize > KekkaiActivation > DemonEncounter
         > AreaBoss > GoldYoukai > ExperienceYoukai > Nian > Tako > AutoCheckinBigGod > RealmRaid > RyouToppa > DailyTrifles > Exploration
         > Dokan > AbyssShadows > Hunt > GuildBanquet > DemonRetreat > GuildActivityMonitor
-        > Orochi > OrochiMoans > OrochiJudgement > Sougenbi > FallenSun > EternitySea > SixRealms
+        > Orochi > OrochiMoans > OrochiJudgement > Sougenbi > FallenSun > EternitySea > SixRealms > OtherWorldTwilight
         > ActivityShikigami > BudokaiTournament > WantedQuests
         > BondlingFairyland > EvoZone > GoryouRealm > HeroTest
         > CollectiveMissions

+ 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', 'SixRealms']
+        self.menu["Soul Zones"] = ['Orochi', 'Sougenbi', 'FallenSun', 'EternitySea', 'SixRealms', 'OtherWorldTwilight']
         # 日常的任务
         self.menu["Daily Task"] = ['DailyTrifles', 'AreaBoss', 'GoldYoukai', 'ExperienceYoukai', 'Nian',
                                    'TalismanPass', 'DemonEncounter', 'Pets', 'SoulsTidy', 'Delegation', 'WantedQuests',

+ 2 - 0
module/config/config_model.py

@@ -44,6 +44,7 @@ from tasks.Sougenbi.config import Sougenbi
 from tasks.FallenSun.config import FallenSun
 from tasks.EternitySea.config import EternitySea
 from tasks.SixRealms.config import SixRealms
+from tasks.OtherWorldTwilight.config import OtherWorldTwilight
 from tasks.RealmRaid.config import RealmRaid
 from tasks.CollectiveMissions.config import CollectiveMissions
 from tasks.Hunt.config import Hunt
@@ -116,6 +117,7 @@ class ConfigModel(ConfigBase):
     fallen_sun: FallenSun = Field(default_factory=FallenSun)
     eternity_sea: EternitySea = Field(default_factory=EternitySea)
     six_realms: SixRealms = Field(default_factory=SixRealms)
+    other_world_twilight: OtherWorldTwilight = Field(default_factory=OtherWorldTwilight)
 
     # 这些是活动的
     activity_shikigami: ActivityShikigami = Field(default_factory=ActivityShikigami)

+ 2 - 0
module/config/i18n/zh_CN.xml

@@ -170,6 +170,7 @@
     <message><source>Sougenbi</source><translation>业原火</translation></message>
     <message><source>FallenSun</source><translation>日轮之城</translation></message>
     <message><source>EternitySea</source><translation>永生之海</translation></message>
+    <message><source>OtherWorldTwilight</source><translation>彼世逢魔</translation></message>
 	<message><source>GlobalGame</source><translation>全局游戏设置</translation></message>
 	<message><source>RealmRaid</source><translation>个人突破</translation></message>
 	<message><source>RyouToppa</source><translation>寮突破</translation></message>
@@ -218,6 +219,7 @@
     <message><source>Sougenbi</source><translation>业原火</translation></message>
     <message><source>FallenSun</source><translation>日轮之城</translation></message>
     <message><source>EternitySea</source><translation>永生之海</translation></message>
+    <message><source>OtherWorldTwilight</source><translation>彼世逢魔</translation></message>
 	<message><source>GlobalGame</source><translation>全局游戏设置</translation></message>
 	<message><source>RealmRaid</source><translation>个人突破</translation></message>
 	<message><source>RyouToppa</source><translation>寮突破</translation></message>

+ 25 - 0
tasks/OtherWorldTwilight/assets.py

@@ -0,0 +1,25 @@
+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 OtherWorldTwilightAssets: 
+
+
+	# Image Rule Assets
+	# 逢魔之时前往彼世逢魔标志 
+	I_DE_TO_OTHER_WORLD = RuleImage(roi_front=(485,130,84,94), roi_back=(416,82,228,225), threshold=0.8, method="Template matching", file="./tasks/OtherWorldTwilight/owt/owt_de_to_other_world.png")
+	# 挑战标志 
+	I_OWT_FIRE = RuleImage(roi_front=(1142,603,82,74), roi_back=(1088,561,181,159), threshold=0.8, method="Template matching", file="./tasks/OtherWorldTwilight/owt/owt_owt_fire.png")
+	# 组队标志 
+	I_OWT_TEAM = RuleImage(roi_front=(959,605,82,74), roi_back=(905,561,181,159), threshold=0.8, method="Template matching", file="./tasks/OtherWorldTwilight/owt/owt_owt_team.png")
+	# 锁定阵容标志 
+	I_OWT_LOCK = RuleImage(roi_front=(679,650,20,30), roi_back=(593,633,228,87), threshold=0.8, method="Template matching", file="./tasks/OtherWorldTwilight/owt/owt_owt_lock.png")
+	# 解锁阵容标志 
+	I_OWT_UNLOCK = RuleImage(roi_front=(679,650,20,30), roi_back=(593,633,228,87), threshold=0.8, method="Template matching", file="./tasks/OtherWorldTwilight/owt/owt_owt_unlock.png")
+
+

+ 44 - 0
tasks/OtherWorldTwilight/config.py

@@ -0,0 +1,44 @@
+# This Python file uses the following encoding: utf-8
+# @author AzurTian
+from datetime import timedelta, time
+
+from pydantic import Field, field_validator
+from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig, GreenMarkEnum
+from tasks.Component.GeneralInvite.config_invite import InviteConfig
+from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
+from tasks.Component.config_base import ConfigBase, Time, dynamic_hide
+from tasks.Component.config_scheduler import Scheduler
+from tasks.Orochi.config import UserStatus
+
+
+class OtherWorldTwilightConfig(ConfigBase):
+    # 身份
+    user_status: UserStatus = Field(default=UserStatus.LEADER, description='user_status_help')
+    # 限制时间
+    limit_time: Time = Field(default=Time(minute=30), description='limit_time_help')
+    # 限制次数
+    limit_count: int = Field(default=30, description='limit_count_help')
+
+    @property
+    def limit_time_v(self) -> timedelta:
+        if isinstance(self.limit_time, time):
+            return timedelta(hours=self.limit_time.hour, minutes=self.limit_time.minute,
+                             seconds=self.limit_time.second)
+        return self.limit_time
+
+
+class OWTBattleConfig(GeneralBattleConfig):
+    hide_fields = dynamic_hide('preset_enable', 'preset_group', 'preset_team', 'green_mark', 'green_mark_type')
+
+    @field_validator('green_mark_type')
+    @classmethod
+    def green_mark_type_validator(cls, v):
+        return GreenMarkEnum.NAME
+
+
+class OtherWorldTwilight(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    other_world_twilight_config: OtherWorldTwilightConfig = Field(default_factory=OtherWorldTwilightConfig)
+    invite_config: InviteConfig = Field(default_factory=InviteConfig)
+    general_battle_config: OWTBattleConfig = Field(default_factory=OWTBattleConfig)
+    switch_soul: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)

+ 47 - 0
tasks/OtherWorldTwilight/owt/image.json

@@ -0,0 +1,47 @@
+[
+  {
+    "itemName": "de_to_other_world",
+    "imageName": "owt_de_to_other_world.png",
+    "roiFront": "485,130,84,94",
+    "roiBack": "416,82,228,225",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "逢魔之时前往彼世逢魔标志"
+  },
+  {
+    "itemName": "owt_fire",
+    "imageName": "owt_owt_fire.png",
+    "roiFront": "1142,603,82,74",
+    "roiBack": "1088,561,181,159",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "挑战标志"
+  },
+  {
+    "itemName": "owt_team",
+    "imageName": "owt_owt_team.png",
+    "roiFront": "959,605,82,74",
+    "roiBack": "905,561,181,159",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "组队标志"
+  },
+  {
+    "itemName": "owt_lock",
+    "imageName": "owt_owt_lock.png",
+    "roiFront": "679,650,20,30",
+    "roiBack": "593,633,228,87",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "锁定阵容标志"
+  },
+  {
+    "itemName": "owt_unlock",
+    "imageName": "owt_owt_unlock.png",
+    "roiFront": "679,650,20,30",
+    "roiBack": "593,633,228,87",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "解锁阵容标志"
+  }
+]

BIN
tasks/OtherWorldTwilight/owt/owt_de_to_other_world.png


BIN
tasks/OtherWorldTwilight/owt/owt_owt_fire.png


BIN
tasks/OtherWorldTwilight/owt/owt_owt_lock.png


BIN
tasks/OtherWorldTwilight/owt/owt_owt_team.png


BIN
tasks/OtherWorldTwilight/owt/owt_owt_unlock.png


+ 10 - 0
tasks/OtherWorldTwilight/page.py

@@ -0,0 +1,10 @@
+from tasks.GameUi.default_pages import page_demon_encounter
+from tasks.GameUi.matcher import any_of
+from tasks.GameUi.page_definition import Page
+from tasks.GlobalGame.assets import GlobalGameAssets
+from tasks.OtherWorldTwilight.assets import OtherWorldTwilightAssets
+
+page_owt = Page(any_of(OtherWorldTwilightAssets.I_OWT_FIRE, OtherWorldTwilightAssets.I_OWT_TEAM))
+page_owt.connect(page_demon_encounter, GlobalGameAssets.I_UI_BACK_YELLOW, key="page_owt->page_demon_encounter")
+page_demon_encounter.connect(page_owt, OtherWorldTwilightAssets.I_DE_TO_OTHER_WORLD,
+                             key="page_demon_encounter->page_owt")

+ 194 - 0
tasks/OtherWorldTwilight/script_task.py

@@ -0,0 +1,194 @@
+# This Python file uses the following encoding: utf-8
+# @author AzurTian
+from time import sleep
+from datetime import datetime
+
+from module.base.timer import Timer
+
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.GeneralInvite.general_invite import GeneralInvite
+from tasks.Component.GeneralRoom.general_room import GeneralRoom
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
+from tasks.GameUi.game_ui import GameUi
+from module.logger import logger
+from module.exception import TaskEnd
+from tasks.GameUi.page import (
+    page_main, page_battle, page_battle_prepare, page_reward, page_shikigami_records,
+)
+from tasks.OtherWorldTwilight.assets import OtherWorldTwilightAssets
+from tasks.OtherWorldTwilight.page import page_owt
+from tasks.OtherWorldTwilight.config import OtherWorldTwilight
+from tasks.Orochi.config import UserStatus
+
+
+class ScriptTask(GeneralBattle, GeneralInvite, GeneralRoom, GameUi, SwitchSoul, OtherWorldTwilightAssets):
+
+    conf: OtherWorldTwilight = None
+
+    def run(self) -> bool:
+        self.conf = self.config.other_world_twilight
+        if self.conf.switch_soul.enable:
+            self.goto_page(page_shikigami_records)
+            self.run_switch_soul(self.conf.switch_soul.switch_group_team)
+        if self.conf.switch_soul.enable_switch_by_name:
+            self.goto_page(page_shikigami_records)
+            self.run_switch_soul_by_name(self.conf.switch_soul.group_name, self.conf.switch_soul.team_name)
+        success = True
+        match self.conf.other_world_twilight_config.user_status:
+            case UserStatus.LEADER: success = self.run_leader()
+            case UserStatus.MEMBER: success = self.run_member()
+            case UserStatus.ALONE: self.run_alone()
+            case _: logger.error('Unknown user status')
+        self.goto_page(page_main)
+        if success:
+            self.set_next_run('OtherWorldTwilight', finish=True, success=True)
+        else:
+            self.set_next_run('OtherWorldTwilight', finish=True, success=False)
+        raise TaskEnd('OtherWorldTwilight')
+
+    def run_leader(self):
+        logger.info('Start run leader')
+        self.goto_page(page_owt)
+        self.check_lock(self.conf.general_battle_config.lock_team_enable, self.I_OWT_LOCK, self.I_OWT_UNLOCK)
+        # 创建队伍
+        logger.info('Create team')
+        self.ui_click(self.I_OWT_TEAM, self.I_CHECK_TEAM, interval=1)
+        # 创建房间
+        self.create_room()
+        self.ensure_private()
+        self.create_ensure()
+        # 邀请队友
+        success = True
+        is_first = True
+        # 这个时候我已经进入房间了哦
+        while 1:
+            self.screenshot()
+            # 无论胜利与否, 都会出现是否邀请一次队友
+            # 区别在于,失败的话不会出现那个勾选默认邀请的框
+            if self.check_and_invite(self.conf.invite_config.default_invite):
+                continue
+            if self.current_count >= self.conf.other_world_twilight_config.limit_count:
+                if self.is_in_room():
+                    logger.info('Count limit out')
+                    break
+            if datetime.now() - self.start_time >= self.conf.other_world_twilight_config.limit_time_v:
+                if self.is_in_room():
+                    logger.info('Time limit out')
+                    break
+            # 如果没有进入房间那就不需要后面的邀请
+            if not self.is_in_room(False):
+                if self.is_room_dead():
+                    logger.warning('Task failed')
+                    success = False
+                    break
+                continue
+            # 点击挑战
+            if not is_first:
+                if self.run_invite(config=self.conf.invite_config):
+                    self.run_general_battle(config=self.conf.general_battle_config)
+                else:
+                    # 邀请失败,退出任务
+                    logger.warning('Invite failed and exit this task')
+                    success = False
+                    break
+            # 第一次会邀请队友
+            if is_first:
+                if not self.run_invite(config=self.conf.invite_config, is_first=True):
+                    logger.warning('Invite failed and exit this task')
+                    success = False
+                    break
+                else:
+                    is_first = False
+                    self.run_general_battle(config=self.conf.general_battle_config)
+
+        # 当结束或者是失败退出循环的时候只有两个UI的可能,在房间或者是在组队界面
+        # 两者都是幂等的,不在对应界面时直接返回
+        self.exit_room()
+        self.exit_team()
+        return success
+
+    def run_member(self):
+        logger.info('Start run member')
+        self.goto_page(page_main)
+        # 进入战斗流程
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        while 1:
+            self.screenshot()
+            if self.current_count >= self.conf.other_world_twilight_config.limit_count:
+                logger.info('Count limit out')
+                break
+            if datetime.now() - self.start_time >= self.conf.other_world_twilight_config.limit_time_v:
+                logger.info('Time limit out')
+                break
+            if self.check_then_accept():
+                continue
+            if self.is_in_room(False):
+                self.device.stuck_record_clear()
+                if self.wait_battle(wait_time=self.conf.invite_config.wait_time):
+                    self.run_general_battle(config=self.conf.general_battle_config)
+                else:
+                    break
+            # 队长秒开的时候,检测是否加入到战斗中
+            if self.is_in_battle(False):
+                self.run_general_battle(config=self.conf.general_battle_config)
+
+        # 有一种情况是本来要退出的,但是队长邀请了进入的战斗的加载界面
+        while 1:
+            if self.appear(self.I_CHECK_MAIN) or self.appear(self.I_OWT_FIRE):
+                break
+            # 可能在房间就退出,可能还在战斗中就退出战斗,两者都是幂等的
+            self.exit_room()
+            self.exit_battle()
+        return True
+
+    def run_alone(self):
+        logger.info('Start run alone')
+        self.goto_page(page_owt)
+        self.check_lock(self.conf.general_battle_config.lock_team_enable, self.I_OWT_LOCK, self.I_OWT_UNLOCK)
+        unknown_page_timer = Timer(10)
+        while 1:
+            if self.current_count >= self.conf.other_world_twilight_config.limit_count:
+                logger.info('Count limit out')
+                break
+            if datetime.now() - self.start_time >= self.conf.other_world_twilight_config.limit_time_v:
+                logger.info('Time limit out')
+                break
+            self.screenshot()
+            current_page = self.get_current_page(False)
+            # session 返回的 Page 是 clone,与模块级 page_owt 不是同一对象,
+            # 必须用 == (Page.__eq__ 比 key),is 恒为 False
+            if current_page is None:
+                sleep(0.5)
+            elif current_page == page_owt:
+                unknown_page_timer.clear()
+                self.appear_then_click(self.I_OWT_FIRE, interval=1.2)
+            elif current_page in (page_battle_prepare, page_battle, page_reward):
+                unknown_page_timer.clear()
+                self.run_general_battle(self.conf.general_battle_config)
+            else:
+                # 未知页面, 可能是从别处进来的, 超时后拉回彼世逢魔页面
+                if not unknown_page_timer.started():
+                    unknown_page_timer.start()
+                elif unknown_page_timer.reached():
+                    logger.warning(f'Unknown page: {current_page}, goto page_owt')
+                    self.goto_page(page_owt)
+                    unknown_page_timer.clear()
+
+    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
+
+
+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()