Explorar el Código

feat: Add Costume

huangrunheng hace 2 años
padre
commit
a0d88230df

+ 5 - 6
module/atom/image.py

@@ -21,15 +21,16 @@ class RuleImage:
         :param threshold: 阈值  0.8
         :param threshold: 阈值  0.8
         :param file: 相对路径, 带后缀
         :param file: 相对路径, 带后缀
         """
         """
+        self._match_init = False  # 这个是给后面的 等待图片稳定
+        self._image = None  # 这个是匹配的目标
+        self.method = method
+
         self.roi_front: list = list(roi_front)
         self.roi_front: list = list(roi_front)
         self.roi_back = roi_back
         self.roi_back = roi_back
-        self.method = method
         self.threshold = threshold
         self.threshold = threshold
         self.file = file
         self.file = file
 
 
-        self._match_init = False  # 这个是给后面的 等待图片稳定
 
 
-        self._image = None  # 这个是匹配的目标
 
 
     @cached_property
     @cached_property
     def name(self) -> str:
     def name(self) -> str:
@@ -90,7 +91,6 @@ class RuleImage:
         """
         """
         return self.method == "Template matching"
         return self.method == "Template matching"
 
 
-
     def corp(self, image: np.array) -> np.array:
     def corp(self, image: np.array) -> np.array:
         """
         """
         截取图片
         截取图片
@@ -101,10 +101,8 @@ class RuleImage:
         x, y, w, h = int(x), int(y), int(w), int(h)
         x, y, w, h = int(x), int(y), int(w), int(h)
         return image[y:y + h, x:x + w]
         return image[y:y + h, x:x + w]
 
 
-
     def match(self, image: np.array, threshold: float = None) -> bool:
     def match(self, image: np.array, threshold: float = None) -> bool:
         """
         """
-
         :param threshold:
         :param threshold:
         :param image:
         :param image:
         :return:
         :return:
@@ -152,6 +150,7 @@ class RuleImage:
         return int(x + w//2), int(y + h//2)
         return int(x + w//2), int(y + h//2)
 
 
 
 
+
 if __name__ == "__main__":
 if __name__ == "__main__":
     image = cv2.imread("D:/4713.jpg")
     image = cv2.imread("D:/4713.jpg")
     mat = RuleImage(roi_front=(758,122,66,77), roi_back=(339,104,836,120), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_explore.png")
     mat = RuleImage(roi_front=(758,122,66,77), roi_back=(339,104,836,120), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_explore.png")

+ 45 - 0
tasks/Component/Costume/README.md

@@ -0,0 +1,45 @@
+## 如何添加自定义庭院
+
+1. 在`./tasks/Component/Costume`文件夹下面新建一个你的这个庭院皮肤文件夹比如`mainxxx`
+
+2. 在你的文件夹下面新增一个`image.json`,启动`gui.py`对应工具添加对应的assets
+
+   **很重要很重要,你不要乱划动庭院,如果你留意到游戏在你的停留位置是默认的**
+
+   **在你生成之前需要点击探索然后在回来、再点击町中然后回来,确保你的当前的位置的默认的**
+
+   你需要生成如下的assets:
+
+   - check_main_xxx:   这张图片用来判断是否在庭院的
+   - main_goto_exploration_xxx:  这张图片是用来点击"探索"图标的
+   - main_goto_summon_xxx:  这张图片是用来点击 ”召唤“
+   - main_goto_town_xxx:   町中知道吧
+   - pet_house_xxx:  进入宠物屋
+
+3. 执行`./dev_tools/assets_extract.py`这个将会更新`./tasks/Component/Costume/assets.py` 你不需要手动修改这个文件
+
+4. 好了你现在以及输出你这个庭院皮肤的assets了,下面是为其加入 OAS 中
+
+5. 打开`./tasks/Component/Costume/config.py`看到类似这种的,照着填进去
+
+   ```python
+   COSTUME_MAIN_2 = 'costume_main_2'  # 琼夜淬光
+   ```
+
+6. 打开`./tasks/Component/Costume/costume_base.py`看到类似这种的,照着填进去。
+
+   解释一下,`COSTUME_MAIN_2` 是你刚刚定义的一个庭院类型,后面的第一个key就是原先的assets, 后面的value就是你刚刚输出的要替换的原先的assets。具体的值在`assets.py`文件有定义。照着填没毛病吧。
+
+   ```python
+   MainType.COSTUME_MAIN_2: {'I_CHECK_MAIN': 'I_CHECK_MAIN_1',
+                                 'I_MAIN_GOTO_EXPLORATION': 'I_MAIN_GOTO_EXPLORATION_1',
+                                 'I_MAIN_GOTO_SUMMON': 'I_MAIN_GOTO_SUMMON_1',
+                                 'I_MAIN_GOTO_TOWN': 'I_MAIN_GOTO_TOWN_1',
+                                 'I_PET_HOUSE': 'I_PET_HOUSE_1', },
+   ```
+
+7. 完事之后,你需要测试一下。执行`./tasks/Component/Costume/costume_test.py` 这个文件。
+
+   **在测试之前你需要打开一次 OASX 修改你对应的庭院皮肤的选项**
+
+8. 完事啦???哪有那么简单,你没有发现打开 OASX 的时候发现你的选项还是 `costume_main_xxx` 这种吗。你还需要添加一个翻译,[点击这儿](https://runhey.github.io/OnmyojiAutoScript-website/docs/development/user-option#7翻译)

+ 38 - 0
tasks/Component/Costume/assets.py

@@ -0,0 +1,38 @@
+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 CostumeAssets: 
+
+
+	# Image Rule Assets
+	# description 
+	I_CHECK_MAIN_1 = RuleImage(roi_front=(1049,146,48,55), roi_back=(880,119,271,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main1/main1_check_main_1.png")
+	# description 
+	I_MAIN_GOTO_EXPLORATION_1 = RuleImage(roi_front=(486,148,50,54), roi_back=(282,127,441,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main1/main1_main_goto_exploration_1.png")
+	# description 
+	I_MAIN_GOTO_SUMMON_1 = RuleImage(roi_front=(818,206,32,37), roi_back=(634,175,388,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main1/main1_main_goto_summon_1.png")
+	# description 
+	I_MAIN_GOTO_TOWN_1 = RuleImage(roi_front=(567,340,36,60), roi_back=(474,325,240,86), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main1/main1_main_goto_town_1.png")
+	# description 
+	I_PET_HOUSE_1 = RuleImage(roi_front=(1250,439,25,26), roi_back=(1198,362,81,147), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main1/main1_pet_house_1.png")
+
+
+	# Image Rule Assets
+	# description 
+	I_CHECK_MAIN_2 = RuleImage(roi_front=(1090,146,48,55), roi_back=(880,108,271,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main2/main2_check_main_2.png")
+	# description 
+	I_MAIN_GOTO_EXPLORATION_2 = RuleImage(roi_front=(749,197,50,54), roi_back=(506,166,441,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main2/main2_main_goto_exploration_2.png")
+	# description 
+	I_MAIN_GOTO_SUMMON_2 = RuleImage(roi_front=(975,238,85,45), roi_back=(752,208,408,100), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main2/main2_main_goto_summon_2.png")
+	# description 
+	I_MAIN_GOTO_TOWN_2 = RuleImage(roi_front=(783,328,47,60), roi_back=(608,310,398,86), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main2/main2_main_goto_town_2.png")
+	# description 
+	I_PET_HOUSE_2 = RuleImage(roi_front=(1243,458,29,40), roi_back=(1198,396,81,147), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main2/main2_pet_house_2.png")
+
+

+ 22 - 0
tasks/Component/Costume/config.py

@@ -0,0 +1,22 @@
+# 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
+
+class MainType(str, Enum):
+    COSTUME_MAIN = 'costume_main'  # 初语谧景
+    COSTUME_MAIN_1 = 'costume_main_1'  # 织梦莲庭
+    COSTUME_MAIN_2 = 'costume_main_2'  # 琼夜淬光
+
+
+class CostumeConfig(BaseModel):
+    # 皮肤配置
+    costume_main_type: MainType = Field(default=MainType.COSTUME_MAIN, description='costume_main_type_help')
+
+
+
+
+
+
+

+ 51 - 0
tasks/Component/Costume/costume_base.py

@@ -0,0 +1,51 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+
+from module.atom.image import RuleImage
+
+from tasks.Component.Costume.config import MainType, CostumeConfig
+from tasks.Component.Costume.assets import CostumeAssets
+
+main_costume_model = {
+    MainType.COSTUME_MAIN_1: {'I_CHECK_MAIN': 'I_CHECK_MAIN_1',
+                              'I_MAIN_GOTO_EXPLORATION': 'I_MAIN_GOTO_EXPLORATION_1',
+                              'I_MAIN_GOTO_SUMMON': 'I_MAIN_GOTO_SUMMON_1',
+                              'I_MAIN_GOTO_TOWN': 'I_MAIN_GOTO_TOWN_1',
+                              'I_PET_HOUSE': 'I_PET_HOUSE_1', },
+    MainType.COSTUME_MAIN_2: {'I_CHECK_MAIN': 'I_CHECK_MAIN_2',
+                              'I_MAIN_GOTO_EXPLORATION': 'I_MAIN_GOTO_EXPLORATION_2',
+                              'I_MAIN_GOTO_SUMMON': 'I_MAIN_GOTO_SUMMON_2',
+                              'I_MAIN_GOTO_TOWN': 'I_MAIN_GOTO_TOWN_2',
+                              'I_PET_HOUSE': 'I_PET_HOUSE_2', },
+}
+
+
+class CostumeBase:
+
+    def check_costume(self, config: CostumeConfig):
+        self.check_costume_main(config.costume_main_type)
+
+    def check_costume_main(self, main_type: MainType):
+        if main_type == MainType.COSTUME_MAIN:
+            return
+        costume_assets = CostumeAssets()
+        for key, value in main_costume_model[main_type].items():
+            assert_value: RuleImage = getattr(costume_assets, value)
+            self.replace_img(key, assert_value)
+
+    def replace_img(self, asset_before: str, asset_after: RuleImage):
+        if not hasattr(self, asset_before):
+            return
+        # setattr(self, asset_before, asset_after)
+        asset_before_object: RuleImage = getattr(self, asset_before)
+        asset_before_object.roi_front = asset_after.roi_front
+        asset_before_object.roi_back = asset_after.roi_back
+        asset_before_object.threshold = asset_after.threshold
+        asset_before_object.file = asset_after.file
+
+
+
+if __name__ == '__main__':
+    c = CostumeBase()
+    c.check_costume_main(MainType.COSTUME_MAIN_1)

+ 41 - 0
tasks/Component/Costume/costume_test.py

@@ -0,0 +1,41 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+
+from module.atom.image import RuleImage
+
+from tasks.GameUi.assets import GameUiAssets
+from tasks.GameUi.game_ui import GameUi
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
+from tasks.Pets.assets import PetsAssets
+from tasks.base_task import BaseTask
+from module.logger import logger
+
+class ScriptTask(GeneralBattle, GameUi, SwitchSoul, PetsAssets, ):
+
+    def run(self):
+        # 探索测试
+        self.ui_click(self.I_MAIN_GOTO_EXPLORATION, self.I_CHECK_EXPLORATION)
+        self.ui_click(self.I_UI_BACK_BLUE, self.I_CHECK_MAIN)
+        # 町中测试
+        self.ui_click(self.I_MAIN_GOTO_TOWN, self.I_CHECK_TOWN)
+        self.ui_click(self.I_TOWN_GOTO_MAIN, self.I_CHECK_MAIN)
+        # 召唤测试
+        self.ui_click(self.I_MAIN_GOTO_SUMMON, self.I_CHECK_SUMMON)
+        self.ui_click(self.I_SUMMON_GOTO_MAIN, self.I_CHECK_MAIN)
+        # 宠物屋测试
+        self.ui_click(self.I_PET_HOUSE, self.I_PET_CLAW)
+        self.ui_click(self.I_PET_EXIT, self.I_CHECK_MAIN)
+        logger.info('Test Success')
+
+
+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()
+

+ 47 - 0
tasks/Component/Costume/main1/image.json

@@ -0,0 +1,47 @@
+[
+  {
+    "itemName": "check_main_1",
+    "imageName": "main1_check_main_1.png",
+    "roiFront": "1049,146,48,55",
+    "roiBack": "880,119,271,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_goto_exploration_1",
+    "imageName": "main1_main_goto_exploration_1.png",
+    "roiFront": "486,148,50,54",
+    "roiBack": "282,127,441,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_goto_summon_1",
+    "imageName": "main1_main_goto_summon_1.png",
+    "roiFront": "818,206,32,37",
+    "roiBack": "634,175,388,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_goto_town_1",
+    "imageName": "main1_main_goto_town_1.png",
+    "roiFront": "567,340,36,60",
+    "roiBack": "474,325,240,86",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "pet_house_1",
+    "imageName": "main1_pet_house_1.png",
+    "roiFront": "1250,439,25,26",
+    "roiBack": "1198,362,81,147",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

BIN
tasks/Component/Costume/main1/image_name.png


BIN
tasks/Component/Costume/main1/main1_check_main_1.png


BIN
tasks/Component/Costume/main1/main1_main_goto_exploration_1.png


BIN
tasks/Component/Costume/main1/main1_main_goto_summon_1.png


BIN
tasks/Component/Costume/main1/main1_main_goto_town_1.png


BIN
tasks/Component/Costume/main1/main1_pet_house_1.png


+ 47 - 0
tasks/Component/Costume/main2/image.json

@@ -0,0 +1,47 @@
+[
+  {
+    "itemName": "check_main_2",
+    "imageName": "main2_check_main_2.png",
+    "roiFront": "1090,146,48,55",
+    "roiBack": "880,108,271,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_goto_exploration_2",
+    "imageName": "main2_main_goto_exploration_2.png",
+    "roiFront": "749,197,50,54",
+    "roiBack": "506,166,441,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_goto_summon_2",
+    "imageName": "main2_main_goto_summon_2.png",
+    "roiFront": "975,238,85,45",
+    "roiBack": "752,208,408,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_goto_town_2",
+    "imageName": "main2_main_goto_town_2.png",
+    "roiFront": "783,328,47,60",
+    "roiBack": "608,310,398,86",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "pet_house_2",
+    "imageName": "main2_pet_house_2.png",
+    "roiFront": "1243,458,29,40",
+    "roiBack": "1198,396,81,147",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

BIN
tasks/Component/Costume/main2/main2_check_main_2.png


BIN
tasks/Component/Costume/main2/main2_main_goto_exploration_2.png


BIN
tasks/Component/Costume/main2/main2_main_goto_summon_2.png


BIN
tasks/Component/Costume/main2/main2_main_goto_town_2.png


BIN
tasks/Component/Costume/main2/main2_pet_house_2.png


+ 2 - 0
tasks/GlobalGame/config.py

@@ -6,6 +6,7 @@ from pydantic import BaseModel, Field
 
 
 from tasks.GlobalGame.config_emergency import Emergency
 from tasks.GlobalGame.config_emergency import Emergency
 from tasks.Component.config_base import ConfigBase
 from tasks.Component.config_base import ConfigBase
+from tasks.Component.Costume.config import CostumeConfig
 
 
 class Transport(str, Enum):
 class Transport(str, Enum):
     TCP = 'TCP'
     TCP = 'TCP'
@@ -24,5 +25,6 @@ class TeamFlow(BaseModel):
 
 
 class GlobalGame(BaseModel):
 class GlobalGame(BaseModel):
     emergency: Emergency = Field(default_factory=Emergency)
     emergency: Emergency = Field(default_factory=Emergency)
+    costume_config: CostumeConfig = Field(default_factory=CostumeConfig)
     team_flow: TeamFlow = Field(default_factory=TeamFlow)
     team_flow: TeamFlow = Field(default_factory=TeamFlow)
 
 

+ 1 - 15
tasks/Orochi/script_task.py

@@ -476,26 +476,12 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config
     from module.device.device import Device
     from module.device.device import Device
-    from memory_profiler import profile
-    c = Config('test')
+    c = Config('oas1')
     d = Device(c)
     d = Device(c)
     t = ScriptTask(c, d)
     t = ScriptTask(c, d)
 
 
     t.run()
     t.run()
 
 
-    # t.check_layer('悲')
-
-    from module.base.timer import timer
-
-    @timer
-    @profile
-    def test_memory():
-        t.screenshot()
-        print(t.ocr_appear(t.O_O_TEST_OCR))
-        print(t.L_LAYER_LIST.image_appear(t.device.image, '悲'))
-    for i in range(4):
-        test_memory()
-        print('=====================')
 
 
 
 
 
 

+ 1 - 0
tasks/RyouToppa/script_task.py

@@ -252,6 +252,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
             logger.info('Swipe %s -> %s, %s ' % (point2str(*p1), point2str(*p2), duration))
             logger.info('Swipe %s -> %s, %s ' % (point2str(*p1), point2str(*p2), duration))
             self.device.swipe_adb(p1, p2, duration=duration)
             self.device.swipe_adb(p1, p2, duration=duration)
             time.sleep(2)
             time.sleep(2)
+
     def attack_area(self, index: int):
     def attack_area(self, index: int):
         """
         """
         :return: 战斗成功(True) or 战斗失败(False) or 区域不可用(False) or 没有进攻机会(设定下次运行并退出)
         :return: 战斗成功(True) or 战斗失败(False) or 区域不可用(False) or 没有进攻机会(设定下次运行并退出)

+ 3 - 3
tasks/base_task.py

@@ -22,11 +22,12 @@ from module.config.utils import get_server_next_update, nearest_future, dict_to_
 from module.device.device import Device
 from module.device.device import Device
 from tasks.GlobalGame.assets import GlobalGameAssets
 from tasks.GlobalGame.assets import GlobalGameAssets
 from tasks.GlobalGame.config_emergency import FriendInvitation, WhenNetworkAbnormal, WhenNetworkError
 from tasks.GlobalGame.config_emergency import FriendInvitation, WhenNetworkAbnormal, WhenNetworkError
+from tasks.Component.Costume.costume_base import CostumeBase
 
 
 from module.exception import GameStuckError, ScriptError
 from module.exception import GameStuckError, ScriptError
 
 
 
 
-class BaseTask(GlobalGameAssets):
+class BaseTask(GlobalGameAssets, CostumeBase):
     config: Config = None
     config: Config = None
     device: Device = None
     device: Device = None
 
 
@@ -43,9 +44,8 @@ class BaseTask(GlobalGameAssets):
         self.device = device
         self.device = device
 
 
         self.interval_timer = {}  # 这个是用来记录每个匹配的运行间隔的,用于控制运行频率
         self.interval_timer = {}  # 这个是用来记录每个匹配的运行间隔的,用于控制运行频率
-
         self.start_time = datetime.now()  # 启动的时间
         self.start_time = datetime.now()  # 启动的时间
-
+        self.check_costume(self.config.global_game.costume_config)
         self.friend_timer = None  # 这个是用来记录勾协的时间的
         self.friend_timer = None  # 这个是用来记录勾协的时间的
         if self.config.global_game.emergency.invitation_detect_interval:
         if self.config.global_game.emergency.invitation_detect_interval:
             self.interval_time = self.config.global_game.emergency.invitation_detect_interval
             self.interval_time = self.config.global_game.emergency.invitation_detect_interval