runhey 3 лет назад
Родитель
Сommit
dc3f7c8f8b

BIN
module/config/i18n/zh_CN.qm


+ 3 - 0
module/config/i18n/zh_CN.ts

@@ -635,5 +635,8 @@ Refresh:直接刷新,如果刷新操作进入CD,将标记为失败并退
 	<message><source>layer_10_help</source><translation>考虑到练度,这将不是默认打开的</translation></message>
 	<message><source>TalismanConfig</source><translation>花合战</translation></message>
 	<message><source>LevelReward</source><translation>选择礼盒</translation></message>
+	<message><source>PetsConfig</source><translation>宠物</translation></message>
+	<message><source>Pets Happy</source><translation>其乐融融</translation></message>
+	<message><source>Pets Feast</source><translation>饕餮大餐</translation></message>
 </context>	
 </TS>

+ 27 - 1
tasks/Pets/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 PetsAssets: 
-	pass
+
+
+	# Image Rule Assets
+	# 宠物小屋 
+	I_PET_HOUSE = RuleImage(roi_front=(1036,420,37,41), roi_back=(998,393,100,100), threshold=0.7, method="Template matching", file="./tasks/Pets/pet/pet_pet_house.png")
+	# 爪印 
+	I_PET_CLAW = RuleImage(roi_front=(1171,625,55,56), roi_back=(1171,625,55,56), threshold=0.8, method="Template matching", file="./tasks/Pets/pet/pet_pet_claw.png")
+	# 其乐融融 
+	I_PET_HAPPY = RuleImage(roi_front=(853,614,67,70), roi_back=(853,614,67,70), threshold=0.8, method="Template matching", file="./tasks/Pets/pet/pet_pet_happy.png")
+	# 大餐 
+	I_PET_FEAST = RuleImage(roi_front=(747,619,69,61), roi_back=(747,619,69,61), threshold=0.8, method="Template matching", file="./tasks/Pets/pet/pet_pet_feast.png")
+	# 玩耍 
+	I_PET_PLAY = RuleImage(roi_front=(788,500,75,75), roi_back=(788,500,75,75), threshold=0.8, method="Template matching", file="./tasks/Pets/pet/pet_pet_play.png")
+	# 投喂 
+	I_PET_FEED = RuleImage(roi_front=(798,497,77,81), roi_back=(798,497,77,81), threshold=0.8, method="Template matching", file="./tasks/Pets/pet/pet_pet_feed.png")
+	# 跳过 
+	I_PET_SKIP = RuleImage(roi_front=(1104,91,72,41), roi_back=(1104,91,72,41), threshold=0.8, method="Template matching", file="./tasks/Pets/pet/pet_pet_skip.png")
+	# 退出 
+	I_PET_EXIT = RuleImage(roi_front=(30,25,39,33), roi_back=(30,25,39,33), threshold=0.8, method="Template matching", file="./tasks/Pets/pet/pet_pet_exit.png")
+
+
+	# Ocr Rule Assets
+	# 投喂的体力 
+	O_PET_FEED_AP = RuleOcr(roi=(730,527,57,33), area=(730,527,57,33), mode="Digit", method="Default", keyword="", name="pet_feed_ap")
+	# 玩耍的体力 
+	O_PET_PLAY_GOLD = RuleOcr(roi=(681,524,74,40), area=(681,524,74,40), mode="Digit", method="Default", keyword="", name="pet_play_gold")
+
 

+ 8 - 0
tasks/Pets/config.py

@@ -7,6 +7,14 @@ from pydantic import BaseModel, Field
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase
 
+class PetsConfig(ConfigBase):
+    # 其乐融融
+    pets_happy: bool = Field(default=True)
+    # 大餐
+    pets_feast: bool = Field(default=True)
+
 class Pets(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
+    pets_config: PetsConfig = Field(default_factory=PetsConfig)
+
 

+ 74 - 0
tasks/Pets/pet/image.json

@@ -0,0 +1,74 @@
+[
+  {
+    "itemName": "pet_house",
+    "imageName": "pet_pet_house.png",
+    "roiFront": "1036,420,37,41",
+    "roiBack": "998,393,100,100",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "宠物小屋"
+  },
+  {
+    "itemName": "pet_claw",
+    "imageName": "pet_pet_claw.png",
+    "roiFront": "1171,625,55,56",
+    "roiBack": "1171,625,55,56",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "爪印"
+  },
+  {
+    "itemName": "pet_happy",
+    "imageName": "pet_pet_happy.png",
+    "roiFront": "853,614,67,70",
+    "roiBack": "853,614,67,70",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "其乐融融"
+  },
+  {
+    "itemName": "pet_feast",
+    "imageName": "pet_pet_feast.png",
+    "roiFront": "747,619,69,61",
+    "roiBack": "747,619,69,61",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "大餐"
+  },
+  {
+    "itemName": "pet_play",
+    "imageName": "pet_pet_play.png",
+    "roiFront": "788,500,75,75",
+    "roiBack": "788,500,75,75",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "玩耍"
+  },
+  {
+    "itemName": "pet_feed",
+    "imageName": "pet_pet_feed.png",
+    "roiFront": "798,497,77,81",
+    "roiBack": "798,497,77,81",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "投喂"
+  },
+  {
+    "itemName": "pet_skip",
+    "imageName": "pet_pet_skip.png",
+    "roiFront": "1104,91,72,41",
+    "roiBack": "1104,91,72,41",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "跳过"
+  },
+  {
+    "itemName": "pet_exit",
+    "imageName": "pet_pet_exit.png",
+    "roiFront": "30,25,39,33",
+    "roiBack": "30,25,39,33",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "退出"
+  }
+]

+ 20 - 0
tasks/Pets/pet/ocr.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "pet_feed_ap",
+    "roiFront": "730,527,57,33",
+    "roiBack": "730,527,57,33",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "投喂的体力"
+  },
+  {
+    "itemName": "pet_play_gold",
+    "roiFront": "681,524,74,40",
+    "roiBack": "681,524,74,40",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "玩耍的体力"
+  }
+]

BIN
tasks/Pets/pet/pet_pet_claw.png


BIN
tasks/Pets/pet/pet_pet_exit.png


BIN
tasks/Pets/pet/pet_pet_feast.png


BIN
tasks/Pets/pet/pet_pet_feed.png


BIN
tasks/Pets/pet/pet_pet_happy.png


BIN
tasks/Pets/pet/pet_pet_house.png


BIN
tasks/Pets/pet/pet_pet_play.png


BIN
tasks/Pets/pet/pet_pet_skip.png


+ 88 - 0
tasks/Pets/script_task.py

@@ -0,0 +1,88 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from module.logger import logger
+from module.exception import TaskEnd
+
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main
+from tasks.Pets.assets import PetsAssets
+from tasks.Pets.config import PetsConfig
+
+class ScriptTask(GameUi, PetsAssets):
+
+    def run(self):
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+        con: PetsConfig = self.config.pets.pets_config
+        # 进入
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_PET_FEAST):
+                break
+            if self.appear_then_click(self.I_PET_HOUSE, interval=1):
+                continue
+            if self.appear_then_click(self.I_PET_CLAW, interval=1):
+                continue
+        logger.info('Enter Pets')
+        if con.pets_happy:
+            self._play()
+        if con.pets_feast:
+            self._feed()
+        self.ui_click(self.I_PET_EXIT, self.I_CHECK_MAIN)
+
+        self.set_next_run(task='Pets', success=True, finish=True)
+        raise TaskEnd('Pets')
+
+    def _feed(self):
+        """
+        投喂
+        :return:
+        """
+        logger.hr('Feed', 3)
+        self.ui_click(self.I_PET_FEAST, self.I_PET_FEED)
+        number = self.O_PET_FEED_AP.ocr(self.device.image)
+        if number == 0:
+            # 已经投喂过了
+            logger.warning('Already feed')
+            return
+        self.ui_click(self.I_PET_FEED, self.I_PET_SKIP)
+        self.wait_until_disappear(self.I_PET_SKIP)
+
+    def _play(self):
+        """
+        玩耍
+        :return:
+        """
+        logger.hr('Play', 3)
+        self.ui_click(self.I_PET_HAPPY, self.I_PET_PLAY)
+        number = self.O_PET_PLAY_GOLD.ocr(self.device.image)
+        if number == 0:
+            # 金币不足
+            logger.warning('Gold not enough')
+            return
+        # 点击玩耍三次不出现就退出
+        play_count = 0
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_PET_SKIP):
+                break
+            if play_count >= 3:
+                logger.warning('Play count > 3')
+                break
+            if self.appear_then_click(self.I_PET_PLAY, interval=1):
+                play_count += 1
+                logger.info(f'Play {play_count}')
+                continue
+        self.wait_until_disappear(self.I_PET_SKIP)
+
+
+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.screenshot()
+
+    t.run()