huangrunheng 2 лет назад
Родитель
Сommit
dd78ba37d8

+ 1 - 1
module/config/config_menu.py

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

+ 2 - 0
module/config/config_model.py

@@ -46,6 +46,7 @@ from tasks.Hunt.config import Hunt
 
 # 这一部分是活动的配置-----------------------------------------------------------------------------------------------------
 from tasks.ActivityShikigami.config import ActivityShikigami
+from tasks.MetaDemon.config import MetaDemon
 # ----------------------------------------------------------------------------------------------------------------------
 
 # 肝帝专属---------------------------------------------------------------------------------------------------------------
@@ -97,6 +98,7 @@ class ConfigModel(ConfigBase):
 
     # 这些是活动的
     activity_shikigami: ActivityShikigami = Field(default_factory=ActivityShikigami)
+    meta_demon: MetaDemon = Field(default_factory=MetaDemon)
 
     # 这些是肝帝专属
     bondling_fairyland: BondlingFairyland = Field(default_factory=BondlingFairyland)

+ 40 - 0
tasks/MetaDemon/assets.py

@@ -0,0 +1,40 @@
+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 MetaDemonAssets: 
+
+
+	# Image Rule Assets
+	# description 
+	I_MD_ENTER = RuleImage(roi_front=(426,463,60,80), roi_back=(239,369,547,215), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_enter.png")
+	# description 
+	I_MD_MAIN = RuleImage(roi_front=(658,156,41,139), roi_back=(636,133,100,245), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_main.png")
+	# description 
+	I_MD_FIND = RuleImage(roi_front=(1112,581,100,100), roi_back=(1112,581,100,100), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_find.png")
+	# 高 
+	I_MD_HARD = RuleImage(roi_front=(513,515,26,27), roi_back=(513,515,26,27), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_hard.png")
+	# description 
+	I_MD_FIRE = RuleImage(roi_front=(1107,563,109,113), roi_back=(1107,563,109,113), threshold=0.7, method="Template matching", file="./tasks/MetaDemon/md/md_md_fire.png")
+	# description 
+	I_MD_GIFT_BOX = RuleImage(roi_front=(1184,182,42,50), roi_back=(1184,182,42,50), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_gift_box.png")
+	# 难度 
+	I_MD_EXTREME = RuleImage(roi_front=(512,516,30,25), roi_back=(512,516,30,25), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_extreme.png")
+	# description 
+	I_MD_FIRE_COMMON = RuleImage(roi_front=(1065,499,100,36), roi_back=(1065,499,100,36), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_fire_common.png")
+	# description 
+	I_MD_FIRE_POWER = RuleImage(roi_front=(1159,498,100,37), roi_back=(1159,498,100,37), threshold=0.8, method="Template matching", file="./tasks/MetaDemon/md/md_md_fire_power.png")
+
+
+	# Ocr Rule Assets
+	# Ocr-description 
+	O_MD_EXHAUSTION = RuleOcr(roi=(1096,18,89,31), area=(1096,18,89,31), mode="DigitCounter", method="Default", keyword="", name="md_exhaustion")
+	# Ocr-description 
+	O_MD_TICKET = RuleOcr(roi=(923,18,82,30), area=(923,18,82,30), mode="DigitCounter", method="Default", keyword="", name="md_ticket")
+
+

+ 26 - 0
tasks/MetaDemon/config.py

@@ -0,0 +1,26 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from tasks.Component.config_base import ConfigBase, TimeDelta, DateTime, Time
+from pydantic import BaseModel, ValidationError, validator, Field
+from enum import Enum
+
+# 鬼王的难度为: 易、中、高、难、极 五个 对应英文:easy、medium、hard、difficult、extreme
+
+class Scheduler(ConfigBase):
+    enable: bool = Field(default=False, description='enable_help')
+    next_run: DateTime = Field(default="2023-01-01 00:00:00", description='next_run_help')
+    interval: TimeDelta = Field(default=TimeDelta(days=1), description='interval_help')
+
+class MetaDemonConfig(ConfigBase):
+    auto_tea: bool = Field(default=False, description='auto_tea_help')
+    extreme_notify: bool = Field(default=False, description='extreme_notify_help')
+
+
+class MetaDemon(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    meta_demon_config: MetaDemonConfig = Field(default_factory=MetaDemonConfig)
+
+
+
+

+ 83 - 0
tasks/MetaDemon/md/image.json

@@ -0,0 +1,83 @@
+[
+  {
+    "itemName": "md_enter",
+    "imageName": "md_md_enter.png",
+    "roiFront": "426,463,60,80",
+    "roiBack": "239,369,547,215",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "md_main",
+    "imageName": "md_md_main.png",
+    "roiFront": "658,156,41,139",
+    "roiBack": "636,133,100,245",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "md_find",
+    "imageName": "md_md_find.png",
+    "roiFront": "1112,581,100,100",
+    "roiBack": "1112,581,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "md_hard",
+    "imageName": "md_md_hard.png",
+    "roiFront": "513,515,26,27",
+    "roiBack": "513,515,26,27",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "高"
+  },
+  {
+    "itemName": "md_fire",
+    "imageName": "md_md_fire.png",
+    "roiFront": "1107,563,109,113",
+    "roiBack": "1107,563,109,113",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "description"
+  },
+  {
+    "itemName": "md_gift_box",
+    "imageName": "md_md_gift_box.png",
+    "roiFront": "1184,182,42,50",
+    "roiBack": "1184,182,42,50",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "md_extreme",
+    "imageName": "md_md_extreme.png",
+    "roiFront": "512,516,30,25",
+    "roiBack": "512,516,30,25",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "难度"
+  },
+  {
+    "itemName": "md_fire_common",
+    "imageName": "md_md_fire_common.png",
+    "roiFront": "1065,499,100,36",
+    "roiBack": "1065,499,100,36",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "md_fire_power",
+    "imageName": "md_md_fire_power.png",
+    "roiFront": "1159,498,100,37",
+    "roiBack": "1159,498,100,37",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

BIN
tasks/MetaDemon/md/md_md_enter.png


BIN
tasks/MetaDemon/md/md_md_extreme.png


BIN
tasks/MetaDemon/md/md_md_find.png


BIN
tasks/MetaDemon/md/md_md_fire.png


BIN
tasks/MetaDemon/md/md_md_fire_common.png


BIN
tasks/MetaDemon/md/md_md_fire_power.png


BIN
tasks/MetaDemon/md/md_md_gift_box.png


BIN
tasks/MetaDemon/md/md_md_hard.png


BIN
tasks/MetaDemon/md/md_md_main.png


+ 20 - 0
tasks/MetaDemon/md/ocr.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "md_exhaustion",
+    "roiFront": "1096,18,89,31",
+    "roiBack": "1096,18,89,31",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "md_ticket",
+    "roiFront": "923,18,82,30",
+    "roiBack": "923,18,82,30",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  }
+]

+ 149 - 0
tasks/MetaDemon/script_task.py

@@ -0,0 +1,149 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from cached_property import cached_property
+from datetime import datetime, time
+
+from tasks.Component.config_base import ConfigBase, TimeDelta, DateTime, Time
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main
+from tasks.MetaDemon.config import MetaDemon
+from tasks.MetaDemon.assets import MetaDemonAssets
+
+from module.logger import logger
+from module.exception import TaskEnd
+
+class ScriptTask(GeneralBattle, SwitchSoul, GameUi, MetaDemonAssets):
+
+    def run(self):
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_MD_FIND):
+                break
+            if self.appear(self.I_MD_FIRE):
+                break
+            if self.appear_then_click(self.I_MD_ENTER, interval=1.5):
+                continue
+            if self.appear_then_click(self.I_MD_MAIN, interval=1.5):
+                continue
+
+        config: MetaDemon = self.config.model.meta_demon
+        # 主循环
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_MD_GIFT_BOX):
+                continue
+            # 检查是否有票
+            if not self.ensure_ticket():
+                logger.info('There is no common ticket')
+                self.set_next_run('MetaDemon', finish=True,
+                                  target=config.scheduler.interval + datetime.now().replace(second=0, microsecond=0))
+                break
+            # 检查疲劳°
+            if not self.check_exhaustion():
+                logger.info('Exhaustion is more than 100')
+                if config.meta_demon_config.auto_tea:
+                    logger.info('Try to buy tea')
+                    self.buy_tea()
+                    continue
+                else:
+                    logger.info('Stop because of exhaustion is more than 100')
+                    interval_delta = TimeDelta(minutes=self.current_exhaustion())
+                    self.set_next_run('MetaDemon', finish=True,
+                                      target=interval_delta + datetime.now().replace(second=0, microsecond=0))
+                    break
+            # 寻找鬼王
+            if self.appear_then_click(self.I_MD_FIND, interval=1.5):
+                continue
+            #
+            if self.appear(self.I_MD_FIRE):
+                self.click_fire()
+                self.run_general_battle(config=self.battle_config)
+        # exit
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_CHECK_MAIN):
+                logger.info('Exit MetaDemon')
+                break
+            if self.appear_then_click(self.I_UI_BACK_YELLOW, interval=1):
+                continue
+        raise TaskEnd
+
+
+
+
+
+    @cached_property
+    def battle_config(self):
+        config = GeneralBattleConfig()
+        config.lock_team_enable = False
+        return config
+
+    def ensure_ticket(self, screenshot: bool = False) -> bool:
+        if screenshot:
+            self.screenshot()
+        cu, res, total = self.O_MD_TICKET.ocr(self.device.image)
+        if cu <= 0:
+            return False
+        return True
+
+    def check_exhaustion(self, screenshot: bool = False) -> bool:
+        # EXHAUSTION
+        if screenshot:
+            self.screenshot()
+        cu, res, total = self.O_MD_EXHAUSTION.ocr(self.device.image)
+        if cu >= 100:
+            return False
+        return True
+
+    def current_exhaustion(self) -> int:
+        self.screenshot()
+        cu, res, total = self.O_MD_EXHAUSTION.ocr(self.device.image)
+        return int(cu)
+
+    def click_fire(self):
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_MD_FIRE):
+                self.screenshot()
+                if not self.appear(self.I_MD_FIRE):
+                    break
+            if self.appear_then_click(self.I_MD_FIRE, interval=1.5):
+                continue
+
+    def buy_tea(self):
+        pass
+
+    def battle_wait(self, random_click_swipt_enable: bool) -> bool:
+        # 重写
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        self.device.click_record_clear()
+        logger.info("Start battle process")
+        while 1:
+            self.screenshot()
+            # if self.appear_then_click(self.I_WIN, interval=1):
+            #     continue
+            if self.appear(self.I_WIN):
+                logger.info('Win battle')
+                self.ui_click_until_disappear(self.I_WIN)
+                return True
+
+            if self.appear(self.I_FALSE):
+                logger.warning('False battle')
+                self.ui_click_until_disappear(self.I_FALSE)
+                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()
+

+ 25 - 0
test_name.py

@@ -0,0 +1,25 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import ctypes
+import time
+import psutil
+
+
+
+# 定义Windows API函数
+kernel32 = ctypes.WinDLL('kernel32')
+SetConsoleTitleW = kernel32.SetConsoleTitleW
+
+# 设置进程名称
+new_title = "Netle"
+SetConsoleTitleW(new_title)
+
+
+processes = psutil.process_iter()
+for process in processes:
+    if not process.name().startswith('python'):
+        continue
+    print(f"进程ID: {process.pid}, 名字: {process.name()}")
+
+time.sleep(3)