Просмотр исходного кода

feat(tasks): Add new task feature, KittyShop &
fix(module): rename error for 'platform'

huangrunheng 1 год назад
Родитель
Сommit
651df6a415

+ 3 - 3
dev_tools/assets_test.py

@@ -34,10 +34,10 @@ def detect_ocr(file: str, target: RuleOcr):
 
 
 
 
 # 图片文件路径 可以是相对路径
 # 图片文件路径 可以是相对路径
-IMAGE_FILE = r"C:\Users\Ryland\Desktop\Weixin Screenshot_20241225220524.png"
+IMAGE_FILE = r"C:\Users\萌萌哒\Desktop\QQ20250105-160854.png"
 if __name__ == '__main__':
 if __name__ == '__main__':
-    from tasks.KekkaiActivation.assets import KekkaiActivationAssets
-    targe = KekkaiActivationAssets.I_CARDS_KAIKO_3
+    from tasks.KittyShop.script_task import ScriptTask
+    targe = ScriptTask.I_MAIN_BUSY_2
     print(detect_image(IMAGE_FILE, targe))
     print(detect_image(IMAGE_FILE, targe))
 
 
     # ocr demo
     # ocr demo

+ 1 - 1
module/config/config_manual.py

@@ -18,7 +18,7 @@ class ConfigManual:
         > TrueOrochi > RichMan
         > TrueOrochi > RichMan
         > CollectiveMissions
         > CollectiveMissions
         > Pets > TalismanPass > Delegation > Hyakkiyakou
         > Pets > TalismanPass > Delegation > Hyakkiyakou
-        > Secret > WeeklyTrifles > MysteryShop > Duel > MetaDemon > FrogBoss > FloatParade > Quiz
+        > Secret > WeeklyTrifles > MysteryShop > Duel > MetaDemon > FrogBoss > FloatParade > Quiz > KittyShop
         """
         """
 
 
     DEVICE_OVER_HTTP = False
     DEVICE_OVER_HTTP = False

+ 1 - 1
module/config/config_menu.py

@@ -40,7 +40,7 @@ class ConfigMenu:
         # 每周任务
         # 每周任务
         self.menu["Weekly Task"] = ['TrueOrochi', 'RichMan', 'Secret', 'WeeklyTrifles', 'MysteryShop', 'Duel']
         self.menu["Weekly Task"] = ['TrueOrochi', 'RichMan', 'Secret', 'WeeklyTrifles', 'MysteryShop', 'Duel']
         # 活动的任务
         # 活动的任务
-        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon', 'FrogBoss', 'FloatParade', 'Quiz']
+        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon', 'FrogBoss', 'FloatParade', 'Quiz', 'KittyShop']
         # 开发工具
         # 开发工具
         self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule', 'List Rule']
         self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule', 'List Rule']
 
 

+ 2 - 0
module/config/config_model.py

@@ -53,6 +53,7 @@ from tasks.MetaDemon.config import MetaDemon
 from tasks.FrogBoss.config import FrogBoss
 from tasks.FrogBoss.config import FrogBoss
 from tasks.FloatParade.config import FloatParade
 from tasks.FloatParade.config import FloatParade
 from tasks.Quiz.config import Quiz
 from tasks.Quiz.config import Quiz
+from tasks.KittyShop.config import KittyShop
 # ----------------------------------------------------------------------------------------------------------------------
 # ----------------------------------------------------------------------------------------------------------------------
 
 
 # 肝帝专属---------------------------------------------------------------------------------------------------------------
 # 肝帝专属---------------------------------------------------------------------------------------------------------------
@@ -113,6 +114,7 @@ class ConfigModel(ConfigBase):
     frog_boss: FrogBoss = Field(default_factory=FrogBoss)
     frog_boss: FrogBoss = Field(default_factory=FrogBoss)
     float_parade: FloatParade = Field(default_factory=FloatParade)
     float_parade: FloatParade = Field(default_factory=FloatParade)
     quiz: Quiz = Field(default_factory=Quiz)
     quiz: Quiz = Field(default_factory=Quiz)
+    kitty_shop: KittyShop = Field(default_factory=KittyShop)
 
 
     # 这些是肝帝专属
     # 这些是肝帝专属
     bondling_fairyland: BondlingFairyland = Field(default_factory=BondlingFairyland)
     bondling_fairyland: BondlingFairyland = Field(default_factory=BondlingFairyland)

+ 2 - 2
module/device/connection.py

@@ -1,7 +1,7 @@
 # This Python file uses the following encoding: utf-8
 # This Python file uses the following encoding: utf-8
 import ipaddress
 import ipaddress
 import logging
 import logging
-import platform2
+import platform
 import re
 import re
 import socket
 import socket
 import subprocess
 import subprocess
@@ -301,7 +301,7 @@ class Connection(ConnectionAttr):
                 logger.error(e)
                 logger.error(e)
                 logger.error(f'Unknown host name: {socket.gethostname()}')
                 logger.error(f'Unknown host name: {socket.gethostname()}')
                 host = '127.0.0.1'
                 host = '127.0.0.1'
-            if platform2.system() == 'Linux' and host == '127.0.1.1':
+            if platform.system() == 'Linux' and host == '127.0.1.1':
                 host = '127.0.0.1'
                 host = '127.0.0.1'
             logger.info(f'Connecting to local emulator, using host {host}')
             logger.info(f'Connecting to local emulator, using host {host}')
             port = random_port(self.config.FORWARD_PORT_RANGE)
             port = random_port(self.config.FORWARD_PORT_RANGE)

+ 0 - 1
tasks/BondlingFairyland/assets.py

@@ -57,7 +57,6 @@ class BondlingFairylandAssets:
 	I_CREATE_TEAM = RuleImage(roi_front=(569,491,141,50), roi_back=(569,491,141,50), threshold=0.8, method="Template matching", file="./tasks/BondlingFairyland/ball/create_team.png")
 	I_CREATE_TEAM = RuleImage(roi_front=(569,491,141,50), roi_back=(569,491,141,50), threshold=0.8, method="Template matching", file="./tasks/BondlingFairyland/ball/create_team.png")
 
 
 
 
-
 	# Image Rule Assets
 	# Image Rule Assets
 	# description 
 	# description 
 	I_BF_SEARSH = RuleImage(roi_front=(1133,577,100,100), roi_back=(1133,577,100,100), threshold=0.8, method="Template matching", file="./tasks/BondlingFairyland/bf/bf_bf_searsh.png")
 	I_BF_SEARSH = RuleImage(roi_front=(1133,577,100,100), roi_back=(1133,577,100,100), threshold=0.8, method="Template matching", file="./tasks/BondlingFairyland/bf/bf_bf_searsh.png")

+ 71 - 0
tasks/KittyShop/assets.py

@@ -0,0 +1,71 @@
+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 KittyShopAssets: 
+
+
+	# Click Rule Assets
+	# description 
+	C_SELECT_1 = RuleClick(roi_front=(225,215,242,303), roi_back=(225,215,242,303), name="select_1")
+	# description 
+	C_SELECT_2 = RuleClick(roi_front=(471,216,250,300), roi_back=(471,216,250,300), name="select_2")
+	# description 
+	C_SELECT_3 = RuleClick(roi_front=(735,213,252,307), roi_back=(735,213,252,307), name="select_3")
+	# description 
+	C_SELECT_4 = RuleClick(roi_front=(990,216,181,303), roi_back=(990,216,181,303), name="select_4")
+	# description 
+	C_RUN_1 = RuleClick(roi_front=(240,571,154,143), roi_back=(240,571,154,143), name="run_1")
+	# description 
+	C_RUN_2 = RuleClick(roi_front=(394,569,169,148), roi_back=(394,569,169,148), name="run_2")
+	# description 
+	C_RUN_3 = RuleClick(roi_front=(563,567,171,141), roi_back=(563,567,171,141), name="run_3")
+	# description 
+	C_RUN_4 = RuleClick(roi_front=(731,572,170,142), roi_back=(731,572,170,142), name="run_4")
+	# description 
+	C_RUN_5 = RuleClick(roi_front=(900,571,165,136), roi_back=(900,571,165,136), name="run_5")
+
+
+	# Image Rule Assets
+	# 进入经营 
+	I_GO1 = RuleImage(roi_front=(350,136,46,185), roi_back=(315,76,100,342), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_go1.png")
+	# 点击经营 
+	I_START_FARMING = RuleImage(roi_front=(1131,579,100,100), roi_back=(995,484,279,234), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_start_farming.png")
+	# 开启 
+	I_START_ENSURE = RuleImage(roi_front=(1094,583,82,78), roi_back=(954,522,322,196), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_start_ensure.png")
+	# 没有选择 
+	I_UNSELECTED = RuleImage(roi_front=(247,562,76,70), roi_back=(143,524,941,127), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_unselected.png")
+	# 里面的 
+	I_MAIN_FLAG = RuleImage(roi_front=(13,102,61,50), roi_back=(1,34,279,247), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_flag.png")
+	# 加号 
+	I_MAIN_ADD = RuleImage(roi_front=(159,178,46,50), roi_back=(125,50,1078,491), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_add.png")
+	# 收菜按钮 
+	I_MAIN_GIFT = RuleImage(roi_front=(155,185,55,46), roi_back=(89,52,1184,506), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_gift.png")
+	# 营业中,不可使用 
+	I_MAIN_BUSY = RuleImage(roi_front=(452,626,64,24), roi_back=(237,549,832,170), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_busy.png")
+	# 结束后的分享 
+	I_MAIN_SHARE = RuleImage(roi_front=(1156,595,68,77), roi_back=(839,474,440,245), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_share.png")
+	# 里面没有选猫咪 
+	I_MAIN_FLAG1 = RuleImage(roi_front=(1065,681,89,37), roi_back=(1065,681,89,37), threshold=0.95, method="Template matching", file="./tasks/KittyShop/ks/ks_main_flag1.png")
+	# description 
+	I_MAIN_BUSY_1 = RuleImage(roi_front=(292,633,64,24), roi_back=(240,571,154,143), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_busy_1.png")
+	# description 
+	I_MAIN_BUSY_2 = RuleImage(roi_front=(452,626,64,24), roi_back=(394,569,169,148), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_busy_2.png")
+	# description 
+	I_MAIN_BUSY_3 = RuleImage(roi_front=(630,623,64,24), roi_back=(563,567,171,141), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_busy_3.png")
+	# description 
+	I_MAIN_BUSY_4 = RuleImage(roi_front=(781,634,64,24), roi_back=(731,572,170,142), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_busy_4.png")
+	# description 
+	I_MAIN_BUSY_5 = RuleImage(roi_front=(961,626,64,24), roi_back=(900,571,165,136), threshold=0.8, method="Template matching", file="./tasks/KittyShop/ks/ks_main_busy_5.png")
+
+
+	# Swipe Rule Assets
+	# description 
+	S_SELECTION = RuleSwipe(roi_front=(589,239,21,258), roi_back=(459,234,22,270), mode="default", name="selection")
+
+

+ 15 - 0
tasks/KittyShop/config.py

@@ -0,0 +1,15 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from pydantic import BaseModel, Field
+
+from tasks.Component.config_scheduler import Scheduler
+from tasks.Component.config_base import ConfigBase
+
+class KittyShopConfig(BaseModel):
+    kitty_attempts: int = Field(default=1, description='kitty_attempts_help')
+
+
+class KittyShop(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    kitty_shop_config: KittyShopConfig = Field(default_factory=KittyShopConfig)

+ 56 - 0
tasks/KittyShop/ks/click.json

@@ -0,0 +1,56 @@
+[
+  {
+    "itemName": "select_1",
+    "roiFront": "225,215,242,303",
+    "roiBack": "225,215,242,303",
+    "description": "description"
+  },
+  {
+    "itemName": "select_2",
+    "roiFront": "471,216,250,300",
+    "roiBack": "471,216,250,300",
+    "description": "description"
+  },
+  {
+    "itemName": "select_3",
+    "roiFront": "735,213,252,307",
+    "roiBack": "735,213,252,307",
+    "description": "description"
+  },
+  {
+    "itemName": "select_4",
+    "roiFront": "990,216,181,303",
+    "roiBack": "990,216,181,303",
+    "description": "description"
+  },
+  {
+    "itemName": "run_1",
+    "roiFront": "240,571,154,143",
+    "roiBack": "240,571,154,143",
+    "description": "description"
+  },
+  {
+    "itemName": "run_2",
+    "roiFront": "394,569,169,148",
+    "roiBack": "394,569,169,148",
+    "description": "description"
+  },
+  {
+    "itemName": "run_3",
+    "roiFront": "563,567,171,141",
+    "roiBack": "563,567,171,141",
+    "description": "description"
+  },
+  {
+    "itemName": "run_4",
+    "roiFront": "731,572,170,142",
+    "roiBack": "731,572,170,142",
+    "description": "description"
+  },
+  {
+    "itemName": "run_5",
+    "roiFront": "900,571,165,136",
+    "roiBack": "900,571,165,136",
+    "description": "description"
+  }
+]

+ 137 - 0
tasks/KittyShop/ks/image.json

@@ -0,0 +1,137 @@
+[
+  {
+    "itemName": "go1",
+    "imageName": "ks_go1.png",
+    "roiFront": "350,136,46,185",
+    "roiBack": "315,76,100,342",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "进入经营"
+  },
+  {
+    "itemName": "start_farming",
+    "imageName": "ks_start_farming.png",
+    "roiFront": "1131,579,100,100",
+    "roiBack": "995,484,279,234",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "点击经营"
+  },
+  {
+    "itemName": "start_ensure",
+    "imageName": "ks_start_ensure.png",
+    "roiFront": "1094,583,82,78",
+    "roiBack": "954,522,322,196",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "开启"
+  },
+  {
+    "itemName": "unselected",
+    "imageName": "ks_unselected.png",
+    "roiFront": "247,562,76,70",
+    "roiBack": "143,524,941,127",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "没有选择"
+  },
+  {
+    "itemName": "main_flag",
+    "imageName": "ks_main_flag.png",
+    "roiFront": "13,102,61,50",
+    "roiBack": "1,34,279,247",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "里面的"
+  },
+  {
+    "itemName": "main_add",
+    "imageName": "ks_main_add.png",
+    "roiFront": "159,178,46,50",
+    "roiBack": "125,50,1078,491",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "加号"
+  },
+  {
+    "itemName": "main_gift",
+    "imageName": "ks_main_gift.png",
+    "roiFront": "155,185,55,46",
+    "roiBack": "89,52,1184,506",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "收菜按钮"
+  },
+  {
+    "itemName": "main_busy",
+    "imageName": "ks_main_busy.png",
+    "roiFront": "452,626,64,24",
+    "roiBack": "237,549,832,170",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "营业中,不可使用"
+  },
+  {
+    "itemName": "main_share",
+    "imageName": "ks_main_share.png",
+    "roiFront": "1156,595,68,77",
+    "roiBack": "839,474,440,245",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "结束后的分享"
+  },
+  {
+    "itemName": "main_flag1",
+    "imageName": "ks_main_flag1.png",
+    "roiFront": "1065,681,89,37",
+    "roiBack": "1065,681,89,37",
+    "method": "Template matching",
+    "threshold": 0.95,
+    "description": "里面没有选猫咪"
+  },
+  {
+    "itemName": "main_busy_1",
+    "imageName": "ks_main_busy_1.png",
+    "roiFront": "292,633,64,24",
+    "roiBack": "240,571,154,143",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_busy_2",
+    "imageName": "ks_main_busy_2.png",
+    "roiFront": "452,626,64,24",
+    "roiBack": "394,569,169,148",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_busy_3",
+    "imageName": "ks_main_busy_3.png",
+    "roiFront": "630,623,64,24",
+    "roiBack": "563,567,171,141",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_busy_4",
+    "imageName": "ks_main_busy_4.png",
+    "roiFront": "781,634,64,24",
+    "roiBack": "731,572,170,142",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "main_busy_5",
+    "imageName": "ks_main_busy_5.png",
+    "roiFront": "961,626,64,24",
+    "roiBack": "900,571,165,136",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

BIN
tasks/KittyShop/ks/image_name.png


BIN
tasks/KittyShop/ks/ks_go1.png


BIN
tasks/KittyShop/ks/ks_main_add.png


BIN
tasks/KittyShop/ks/ks_main_busy.png


BIN
tasks/KittyShop/ks/ks_main_busy_1.png


BIN
tasks/KittyShop/ks/ks_main_busy_2.png


BIN
tasks/KittyShop/ks/ks_main_busy_3.png


BIN
tasks/KittyShop/ks/ks_main_busy_4.png


BIN
tasks/KittyShop/ks/ks_main_busy_5.png


BIN
tasks/KittyShop/ks/ks_main_flag.png


BIN
tasks/KittyShop/ks/ks_main_flag1.png


BIN
tasks/KittyShop/ks/ks_main_gift.png


BIN
tasks/KittyShop/ks/ks_main_share.png


BIN
tasks/KittyShop/ks/ks_start_ensure.png


BIN
tasks/KittyShop/ks/ks_start_farming.png


BIN
tasks/KittyShop/ks/ks_unselected.png


+ 9 - 0
tasks/KittyShop/ks/swipe.json

@@ -0,0 +1,9 @@
+[
+  {
+    "itemName": "selection",
+    "roiFront": "589,239,21,258",
+    "roiBack": "459,234,22,270",
+    "mode": "default",
+    "description": "description"
+  }
+]

+ 115 - 0
tasks/KittyShop/script_task.py

@@ -0,0 +1,115 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from cached_property import cached_property
+
+from module.exception import TaskEnd
+from module.logger import logger
+from module.base.timer import Timer
+from module.atom.image import RuleImage
+
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main
+from tasks.ActivityShikigami.assets import ActivityShikigamiAssets
+from tasks.KittyShop.assets import KittyShopAssets
+
+class ScriptTask(GameUi, ActivityShikigamiAssets, KittyShopAssets):
+
+    MAIN_BUSY: list = [KittyShopAssets.I_MAIN_BUSY_1,
+                       KittyShopAssets.I_MAIN_BUSY_2,
+                       KittyShopAssets.I_MAIN_BUSY_3,
+                       KittyShopAssets.I_MAIN_BUSY_4,
+                       KittyShopAssets.I_MAIN_BUSY_5]
+
+    def run(self) -> None:
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_START_FARMING):
+                break
+            if self.appear_then_click(self.I_GO1, interval=2):
+                continue
+            if self.appear_then_click(self.I_SHI, interval=2):
+                continue
+        logger.hr('Start Kitty Shop')
+        attempts = int(self.config.model.kitty_shop.kitty_shop_config.kitty_attempts)
+        for _ in range(max(attempts, 0)):
+            self._run()
+
+        self.set_next_run(task="KittyShop", success=True)
+        raise TaskEnd
+
+    def _run(self):
+        logger.hr('Kitty Shop', level=1)
+        self.ui_click(self.I_START_FARMING, stop=self.I_START_ENSURE)
+
+        index_timer = Timer(1).start()
+        index_cnt = 0
+        while 1:
+            self.screenshot()
+            if index_timer.reached():
+                index_cnt += 1
+                index_timer.reset()
+
+            if not self.appear(self.I_UNSELECTED):
+                break
+            match index_cnt:
+                case 0:
+                    self.click(self.C_SELECT_1, interval=1)
+                case 1:
+                    self.click(self.C_SELECT_2, interval=1)
+                case 2:
+                    self.click(self.C_SELECT_3, interval=1)
+                case 3 | 7 | 9 | 11 | 13 | 15 | 17:
+                    self.click(self.C_SELECT_4, interval=1)
+                case 5 | 10 | 14:
+                    self.swipe(self.S_SELECTION, interval=1.5)
+        logger.info('Select all kitties done')
+        import time
+        time.sleep(5)
+        self.ui_click(self.I_START_ENSURE, stop=self.I_MAIN_FLAG)
+        logger.info('Start farming')
+        while 1:
+            # 哪里亮了点哪里
+            self.screenshot()
+            if self.appear(self.I_MAIN_SHARE):
+                break
+
+            if not self.appear(self.I_MAIN_FLAG):
+                continue
+            if self.appear_then_click(self.I_MAIN_GIFT, interval=0.7):
+                continue
+            if self.appear_then_click(self.I_MAIN_ADD, interval=0.6):
+                continue
+            if self.appear(self.I_MAIN_FLAG1):
+                self._main_select_kitty()
+                continue
+
+        logger.info('Farming done')
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_START_FARMING):
+                break
+            self.click(self.I_MAIN_FLAG1, interval=2)
+
+    def _main_select_kitty(self):
+        for busy in self.MAIN_BUSY:
+            if self.appear(busy):
+                continue
+            self.click(busy, interval=1.3)
+            break
+
+
+
+
+
+
+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()