Jelajahi Sumber

feat(Costume): Add task-scoped battle scene skin support #1843

neptine 1 bulan lalu
induk
melakukan
08079eaf54

+ 5 - 1
assets/i18n/zh-CN.json

@@ -138,7 +138,11 @@
   "enable_ap100_anti_detect": "100体爬塔防检测",
   "enable_ap100_anti_detect_help": "100体爬塔战斗过程是否随机点击或滑动",
   "costume_battle_15": "灵狐寄愿",
+  "costume_battle_scene_default": "默认",
+  "costume_battle_scene_1": "鎏金圣域",
+  "costume_battle_scene_type": "战斗场景",
+  "costume_battle_scene_type_help": "",
   "costume_shikigami_12": "拾光之窗",
   "save_touch_fish": "惠比寿的摸鱼行动",
   "save_touch_fish_help": "默认使用全部存储按钮,主要目的是为了配合真蛇每周打一次即可获得俩次奖励(并不会节省体力)"
-}
+}

+ 3 - 2
config/template.json

@@ -74,7 +74,8 @@
       "costume_theme_type": "costume_theme_default",
       "costume_shikigami_type": "costume_shikigami_default",
       "costume_sign_type": "costume_sign_default",
-      "costume_battle_type": "costume_battle_default"
+      "costume_battle_type": "costume_battle_default",
+      "costume_battle_scene_type": "costume_battle_scene_default"
     },
     "team_flow": {
       "enable": false,
@@ -1578,4 +1579,4 @@
       "team_name": ""
     }
   }
-}
+}

+ 6 - 1
tasks/Component/Costume/config.py

@@ -79,6 +79,11 @@ class BattleType(str, Enum):
     COSTUME_BATTLE_14 = 'costume_battle_14'  # 茸茨跃动
     COSTUME_BATTLE_15 = 'costume_battle_15'  # 灵狐寄愿
 
+# 战斗场景
+class BattleSceneType(str, Enum):
+    COSTUME_BATTLE_SCENE_DEFAULT = 'costume_battle_scene_default'  # 默认
+    COSTUME_BATTLE_SCENE_1 = 'costume_battle_scene_1'  # 鎏金圣域
+
 
 class CostumeConfig(BaseModel):
     # 皮肤配置
@@ -89,6 +94,7 @@ class CostumeConfig(BaseModel):
     costume_shikigami_type: ShikigamiType = Field(default=ShikigamiType.COSTUME_SHIKIGAMI_DEFAULT, description='costume_shikigami_type_help')
     costume_sign_type: SignType = Field(default=SignType.COSTUME_SIGN_DEFAULT, description='costume_sign_type_help')
     costume_battle_type: BattleType = Field(default=BattleType.COSTUME_BATTLE_DEFAULT, description='costume_battle_type_help')
+    costume_battle_scene_type: BattleSceneType = Field(default=BattleSceneType.COSTUME_BATTLE_SCENE_DEFAULT, description='costume_battle_scene_type_help')
 
     @field_validator('costume_realm_type', mode='before')
     @classmethod
@@ -103,4 +109,3 @@ class CostumeConfig(BaseModel):
 
 
 
-

+ 35 - 2
tasks/Component/Costume/costume_base.py

@@ -6,12 +6,16 @@ from module.atom.image import RuleImage
 from module.atom.gif import RuleGif
 from module.logger import logger
 
-from tasks.Component.Costume.config import (MainType, CostumeConfig, RealmType,
-                                            ThemeType, ShikigamiType, SignType, BattleType, CarpBannerType)
+from tasks.Component.Costume.config import (
+    MainType, CostumeConfig, RealmType,
+    ThemeType, ShikigamiType, SignType,
+    BattleType, BattleSceneType, CarpBannerType
+)
 from tasks.Component.Costume.assets import CostumeAssets
 from tasks.Component.CostumeBattle.assets import CostumeBattleAssets
 from tasks.Component.CostumeShikigami.assets import CostumeShikigamiAssets
 from tasks.Component.CostumeCarpBanner.assets import CostumeCarpBannerAssets
+from tasks.Component.CostumeBattleScene.assets import CostumeBattleSceneAssets
 
 # 庭院皮肤
 # 主界面皮肤(使用字典推导式动态生成)
@@ -66,6 +70,13 @@ battle_theme_model = {
     } for i in range(1, 16)
 }
 
+# 战斗场景皮肤。图片资源待补充,先保留空映射。
+battle_scene_model = {
+    BattleSceneType.COSTUME_BATTLE_SCENE_1: {
+        'I_REWARD': 'I_REWARD_1',
+    },
+}
+
 # 幕间主题
 shikigami_costume_model = {
     getattr(ShikigamiType, f"COSTUME_SHIKIGAMI_{i}"): {
@@ -93,9 +104,12 @@ class CostumeBase:
     def check_costume(self, config: CostumeConfig=None):
         if config is None:
             config: CostumeConfig = self.config.model.global_game.costume_config
+        current_task = self.get_task_name()
+        logger.info(f'Current task: {current_task}')
         self.check_costume_main(config.costume_main_type)
         self.check_costume_carpbanner(config.costume_carpbanner_type)
         self.check_costume_battle(config.costume_battle_type)
+        self.check_costume_battle_scene(config.costume_battle_scene_type)
         self.check_costume_shikigami(config.costume_shikigami_type)
 
     def replace_img(self,
@@ -157,6 +171,25 @@ class CostumeBase:
             else:
                 self.replace_img(key, assert_value)
 
+    def check_costume_battle_scene(self, scene_type: BattleSceneType):
+        if scene_type == BattleSceneType.COSTUME_BATTLE_SCENE_DEFAULT:
+            return
+        logger.info(f'Switch battle scene skin {scene_type}')
+        current_task = self.get_task_name()
+        allowed_tasks = {
+            'Orochi',
+        }
+        if current_task not in allowed_tasks:
+            return
+
+        costume_assets = CostumeBattleSceneAssets()
+        for key, value in battle_scene_model.get(scene_type, {}).items():
+            if not hasattr(costume_assets, value):
+                # 尚未采集完成的资产,跳过
+                continue
+            assert_value: RuleImage = getattr(costume_assets, value)
+            self.replace_img(key, assert_value)
+
     def check_costume_shikigami(self, shikigami_type: ShikigamiType):
         if shikigami_type == ShikigamiType.COSTUME_SHIKIGAMI_DEFAULT:
             return

+ 17 - 0
tasks/Component/CostumeBattleScene/assets.py

@@ -0,0 +1,17 @@
+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 CostumeBattleSceneAssets: 
+
+
+	# Image Rule Assets
+	#  
+	I_REWARD_1 = RuleImage(roi_front=(551,505,165,84), roi_back=(451,413,372,226), threshold=0.8, method="Template matching", file="./tasks/Component/CostumeBattleScene/bs1/bs1_reward_1.png")
+
+

TEMPAT SAMPAH
tasks/Component/CostumeBattleScene/bs1/bs1_reward_1.png


+ 11 - 0
tasks/Component/CostumeBattleScene/bs1/image.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "reward_1",
+    "imageName": "bs1_reward_1.png",
+    "roiFront": "551,505,165,84",
+    "roiBack": "451,413,372,226",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": ""
+  }
+]

+ 28 - 3
tasks/base_task.py

@@ -2,10 +2,14 @@
 # @author runhey
 # github https://github.com/runhey
 
-from time import sleep, time
-
+import inspect
+import inflection
 import random
+from typing import Union
 from datetime import datetime, timedelta
+from pathlib import Path
+from time import sleep, time
+
 from module.atom.animate import RuleAnimate
 from module.atom.click import RuleClick
 from module.atom.gif import RuleGif
@@ -20,11 +24,12 @@ from module.device.device import Device
 from module.exception import ScriptError
 from module.logger import logger
 from module.ocr.base_ocr import OcrMode
+
 from tasks.Component.Costume.costume_base import CostumeBase
 from tasks.Component.config_base import Time
 from tasks.GlobalGame.assets import GlobalGameAssets
 from tasks.GlobalGame.config_emergency import FriendInvitation
-from typing import Union
+
 
 
 class BaseTask(GlobalGameAssets, CostumeBase):
@@ -61,6 +66,26 @@ class BaseTask(GlobalGameAssets, CostumeBase):
         self.current_count = 0  # 战斗次数
         self._boss_mark_flag = False
 
+    def get_task_name(self) -> str:
+        model_task_name = getattr(self.config.model, 'running_task', '')
+        class_file = inspect.getfile(type(self))
+        path_task_name = Path(class_file).parent.name
+
+        model_task_name = (
+            inflection.camelize(model_task_name, uppercase_first_letter=True)
+            if model_task_name else ''
+        )
+        path_task_name = inflection.camelize(
+            path_task_name,
+            uppercase_first_letter=True,
+        )
+
+        if model_task_name and model_task_name != path_task_name:
+            raise ScriptError(
+                f'Task name mismatch: model={model_task_name}, path={path_task_name}'
+            )
+        return model_task_name or path_task_name
+
     def _burst(self) -> bool:
         """
         游戏界面突发异常检测