Explorar el Código

feat(task): add nian but no complete test

runhey hace 3 años
padre
commit
ed7c5b6813

+ 15 - 0
tasks/Component/GeneralRoom/assets.py

@@ -10,6 +10,17 @@ from module.atom.list import RuleList
 class GeneralRoomAssets: 
 class GeneralRoomAssets: 
 
 
 
 
+	# List Rule Assets
+	# description 
+	L_TEAM_LIST = RuleList(folder="./tasks/Component/GeneralRoom", direction="vertical", mode="ocr", roi_back=(26,106,360,549), size=(216, 61), 
+					 array=["全部", "探索(困难)", "觉醒业火轮", "觉醒风转符", "觉醒火灵鲤", "觉醒天雷鼓", "御魂", "日轮之陨", "永生之海", "妖气封印", "经验妖怪", "金币妖怪", "年兽", "石距", "愤怒的石距", "结界突破", "真·八岐大蛇", "对弈社", "斗町", "连携召唤", "契灵之境"])
+
+
+	# Ocr Rule Assets
+	# 副本名字 
+	O_GR_ZONES_NAME = RuleOcr(roi=(415,127,160,53), area=(415,127,160,53), mode="Single", method="Default", keyword="", name="gr_zones_name")
+
+
 	# Image Rule Assets
 	# Image Rule Assets
 	# description 
 	# description 
 	I_CREATE_ROOM = RuleImage(roi_front=(985,600,177,58), roi_back=(396,569,813,100), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralRoom/gr/gr_create_room.png")
 	I_CREATE_ROOM = RuleImage(roi_front=(985,600,177,58), roi_back=(396,569,813,100), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralRoom/gr/gr_create_room.png")
@@ -29,5 +40,9 @@ class GeneralRoomAssets:
 	I_GR_MATCHING_NEW = RuleImage(roi_front=(62,571,42,121), roi_back=(62,571,42,121), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralRoom/gr/gr_gr_matching_new.png")
 	I_GR_MATCHING_NEW = RuleImage(roi_front=(62,571,42,121), roi_back=(62,571,42,121), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralRoom/gr/gr_gr_matching_new.png")
 	# description 
 	# description 
 	I_GR_BACK_YELLOW = RuleImage(roi_front=(19,13,53,53), roi_back=(19,13,53,53), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralRoom/gr/gr_gr_back_yellow.png")
 	I_GR_BACK_YELLOW = RuleImage(roi_front=(19,13,53,53), roi_back=(19,13,53,53), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralRoom/gr/gr_gr_back_yellow.png")
+	# 自动匹配 
+	I_GR_AUTO_MATCH = RuleImage(roi_front=(697,598,181,63), roi_back=(697,598,181,63), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralRoom/gr/gr_gr_auto_match.png")
+	# 刷新 
+	I_GR_REFRESH = RuleImage(roi_front=(417,595,176,65), roi_back=(417,595,176,65), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralRoom/gr/gr_gr_refresh.png")
 
 
 
 

+ 29 - 1
tasks/Component/GeneralRoom/general_room.py

@@ -2,15 +2,18 @@
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
 import time
 import time
-
+import random
 import cv2
 import cv2
 import numpy as np
 import numpy as np
 
 
+from random import randint
+
 from tasks.Component.GeneralRoom.assets import GeneralRoomAssets
 from tasks.Component.GeneralRoom.assets import GeneralRoomAssets
 from module.atom.ocr import RuleOcr
 from module.atom.ocr import RuleOcr
 from module.atom.image import RuleImage
 from module.atom.image import RuleImage
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
 from module.logger import logger
 from module.logger import logger
+from module.base.timer import Timer
 
 
 
 
 class GeneralRoom(BaseTask, GeneralRoomAssets):
 class GeneralRoom(BaseTask, GeneralRoomAssets):
@@ -87,3 +90,28 @@ class GeneralRoom(BaseTask, GeneralRoomAssets):
                     return True
                     return True
                 if self.appear_then_click(self.I_GR_BACK_YELLOW, interval=0.5):
                 if self.appear_then_click(self.I_GR_BACK_YELLOW, interval=0.5):
                     continue
                     continue
+
+    def check_zones(self, name: str) -> bool:
+        """
+        确认副本的名称,并选中
+        :param name:
+        :return:
+        """
+        pos = self.list_find(self.L_TEAM_LIST, name)
+        if not pos:
+            return False
+
+        self.O_GR_ZONES_NAME.keyword = name
+        click_timer = Timer(1.1)
+        click_timer.start()
+        while 1:
+            self.screenshot()
+
+            if self.ocr_appear(self.O_GR_ZONES_NAME):
+                break
+            if click_timer.reached():
+                click_timer.reset()
+                self.device.click(x=pos[0] + randint(-5, 5), y=pos[1] + randint(-5, 5))
+
+        return True
+

BIN
tasks/Component/GeneralRoom/gr/gr_gr_auto_match.png


BIN
tasks/Component/GeneralRoom/gr/gr_gr_refresh.png


+ 18 - 0
tasks/Component/GeneralRoom/gr/image.json

@@ -79,5 +79,23 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"
+  },
+  {
+    "itemName": "gr_auto_match",
+    "imageName": "gr_gr_auto_match.png",
+    "roiFront": "697,598,181,63",
+    "roiBack": "697,598,181,63",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "自动匹配"
+  },
+  {
+    "itemName": "gr_refresh",
+    "imageName": "gr_gr_refresh.png",
+    "roiFront": "417,595,176,65",
+    "roiBack": "417,595,176,65",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "刷新"
   }
   }
 ]
 ]

+ 93 - 0
tasks/Component/GeneralRoom/list.json

@@ -0,0 +1,93 @@
+{
+  "name": "team_list",
+  "direction": "vertical",
+  "type": "ocr",
+  "roiBack": "26,106,360,549",
+  "description": "description",
+  "list": [
+    {
+      "itemName": "全部",
+      "roiFront": "138,237,222,59"
+    },
+    {
+      "itemName": "探索(困难)",
+      "roiFront": "145,305,216,53"
+    },
+    {
+      "itemName": "觉醒业火轮",
+      "roiFront": "141,301,224,63"
+    },
+    {
+      "itemName": "觉醒风转符",
+      "roiFront": "146,302,214,65"
+    },
+    {
+      "itemName": "觉醒火灵鲤",
+      "roiFront": "145,304,215,55"
+    },
+    {
+      "itemName": "觉醒天雷鼓",
+      "roiFront": "145,302,216,67"
+    },
+    {
+      "itemName": "御魂",
+      "roiFront": "148,306,211,61"
+    },
+    {
+      "itemName": "日轮之陨",
+      "roiFront": "145,302,213,63"
+    },
+    {
+      "itemName": "永生之海",
+      "roiFront": "139,302,223,64"
+    },
+    {
+      "itemName": "妖气封印",
+      "roiFront": "147,305,213,66"
+    },
+    {
+      "itemName": "经验妖怪",
+      "roiFront": "145,303,218,60"
+    },
+    {
+      "itemName": "金币妖怪",
+      "roiFront": "148,306,214,62"
+    },
+    {
+      "itemName": "年兽",
+      "roiFront": "145,232,218,60"
+    },
+    {
+      "itemName": "石距",
+      "roiFront": "143,231,219,58"
+    },
+    {
+      "itemName": "愤怒的石距",
+      "roiFront": "143,230,214,60"
+    },
+    {
+      "itemName": "结界突破",
+      "roiFront": "147,230,215,63"
+    },
+    {
+      "itemName": "真·八岐大蛇",
+      "roiFront": "145,226,221,64"
+    },
+    {
+      "itemName": "对弈社",
+      "roiFront": "148,228,213,64"
+    },
+    {
+      "itemName": "斗町",
+      "roiFront": "145,155,219,64"
+    },
+    {
+      "itemName": "连携召唤",
+      "roiFront": "145,229,215,63"
+    },
+    {
+      "itemName": "契灵之境",
+      "roiFront": "147,229,211,60"
+    }
+  ]
+}

+ 11 - 0
tasks/Component/GeneralRoom/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "gr_zones_name",
+    "roiFront": "415,127,160,53",
+    "roiBack": "415,127,160,53",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "副本名字"
+  }
+]

BIN
tasks/Component/GeneralRoom/斗町.png


BIN
tasks/Component/GeneralRoom/连携召唤.png


+ 1 - 1
tasks/GameUi/assets.py

@@ -147,7 +147,7 @@ class GameUiAssets:
 	# description 
 	# description 
 	I_CHECK_GUILD = RuleImage(roi_front=(1072,630,49,46), roi_back=(1072,630,49,46), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_guild.png")
 	I_CHECK_GUILD = RuleImage(roi_front=(1072,630,49,46), roi_back=(1072,630,49,46), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_guild.png")
 	# description 
 	# description 
-	I_CHECK_TEAM = RuleImage(roi_front=(1209,108,41,119), roi_back=(1209,108,41,119), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_team.png")
+	I_CHECK_TEAM = RuleImage(roi_front=(53,570,41,119), roi_back=(53,570,41,119), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_team.png")
 	# description 
 	# description 
 	I_CHECK_COLLECTION = RuleImage(roi_front=(471,618,100,100), roi_back=(471,618,100,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_collection.png")
 	I_CHECK_COLLECTION = RuleImage(roi_front=(471,618,100,100), roi_back=(471,618,100,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_collection.png")
 	# description 
 	# description 

BIN
tasks/GameUi/page/page_check_team.png


+ 2 - 2
tasks/GameUi/page/page_img_3.json

@@ -128,8 +128,8 @@
   {
   {
     "itemName": "check_team",
     "itemName": "check_team",
     "imageName": "page_check_team.png",
     "imageName": "page_check_team.png",
-    "roiFront": "1209,108,41,119",
-    "roiBack": "1209,108,41,119",
+    "roiFront": "53,570,41,119",
+    "roiBack": "53,570,41,119",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"

+ 17 - 1
tasks/Nian/assets.py

@@ -8,5 +8,21 @@ from module.atom.list import RuleList
 # This file was automatically generated by ./dev_tools/assets_extract.py.
 # This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 # Don't modify it manually.
 class NianAssets: 
 class NianAssets: 
-	pass
+
+
+	# Image Rule Assets
+	# 自动匹配 
+	I_AUTO_MATCHING = RuleImage(roi_front=(698,598,180,64), roi_back=(698,598,180,64), threshold=0.8, method="Template matching", file="./tasks/Nian/nian/nian_auto_matching.png")
+	# 判断是否在年的界面 
+	I_N_CHECK = RuleImage(roi_front=(793,279,242,246), roi_back=(793,279,242,246), threshold=0.8, method="Template matching", file="./tasks/Nian/nian/nian_n_check.png")
+	# 等待进入,也是关闭按钮 
+	I_N_WAITING = RuleImage(roi_front=(735,28,54,51), roi_back=(735,28,54,51), threshold=0.7, method="Template matching", file="./tasks/Nian/nian/nian_n_waiting.png")
+
+
+	# Ocr Rule Assets
+	# 再次挑战 
+	O_N_BATTLE_AGAIN = RuleOcr(roi=(612,251,123,37), area=(612,251,123,37), mode="Single", method="Default", keyword="再次挑战", name="n_battle_again")
+	# 冷却的时间 
+	O_N_CD = RuleOcr(roi=(578,218,172,41), area=(578,218,172,41), mode="Single", method="Default", keyword="", name="n_cd")
+
 
 

+ 6 - 0
tasks/Nian/config.py

@@ -7,6 +7,12 @@ from pydantic import BaseModel, Field
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase
 from tasks.Component.config_base import ConfigBase
 
 
+class NianConfig(BaseModel):
+    buff_gold_50_click: bool = Field(default=False)
+    buff_gold_100_click: bool = Field(default=False)
+
+
 class Nian(ConfigBase):
 class Nian(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
     scheduler: Scheduler = Field(default_factory=Scheduler)
+    nian_config: NianConfig = Field(default_factory=NianConfig)
 
 

+ 29 - 0
tasks/Nian/nian/image.json

@@ -0,0 +1,29 @@
+[
+  {
+    "itemName": "auto_matching",
+    "imageName": "nian_auto_matching.png",
+    "roiFront": "698,598,180,64",
+    "roiBack": "698,598,180,64",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "自动匹配"
+  },
+  {
+    "itemName": "n_check",
+    "imageName": "nian_n_check.png",
+    "roiFront": "793,279,242,246",
+    "roiBack": "793,279,242,246",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "判断是否在年的界面"
+  },
+  {
+    "itemName": "n_waiting",
+    "imageName": "nian_n_waiting.png",
+    "roiFront": "735,28,54,51",
+    "roiBack": "735,28,54,51",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "等待进入,也是关闭按钮"
+  }
+]

BIN
tasks/Nian/nian/nian_auto_matching.png


BIN
tasks/Nian/nian/nian_n_check.png


BIN
tasks/Nian/nian/nian_n_waiting.png


+ 20 - 0
tasks/Nian/nian/ocr.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "n_battle_again",
+    "roiFront": "612,251,123,37",
+    "roiBack": "612,251,123,37",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "再次挑战",
+    "description": "再次挑战"
+  },
+  {
+    "itemName": "n_cd",
+    "roiFront": "578,218,172,41",
+    "roiBack": "578,218,172,41",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "冷却的时间"
+  }
+]

+ 137 - 0
tasks/Nian/script_task.py

@@ -0,0 +1,137 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import re
+from datetime import timedelta, datetime, time
+from cached_property import cached_property
+
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main, page_team
+from tasks.Component.GeneralBattle.general_battle import GeneralBattle
+from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
+from tasks.Component.GeneralRoom.general_room import GeneralRoom
+from tasks.Component.GeneralInvite.general_invite import GeneralInvite
+from tasks.Nian.assets import NianAssets
+from tasks.Component.GeneralBuff.config_buff import BuffClass
+
+from module.exception import TaskEnd
+from module.logger import logger
+from module.base.timer import Timer
+
+
+class ScriptTask(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, NianAssets):
+
+    def run(self) -> None:
+        def cd_exit(cd: timedelta=False):
+            logger.warning(f'Nian in CD {cd}')
+            if cd is False:
+                self.set_next_run(task='Nian', success=False, finish=True)
+                raise TaskEnd('Nian')
+            next_run = datetime.now() + cd
+            self.set_next_run(task='Nian', success=False, finish=False, target=next_run)
+            raise TaskEnd('Nian')
+
+        self.ui_get_current_page()
+        self.ui_goto(page_team)
+        con = self.config.nian.nian_config
+
+        # 进入
+        self.ui_get_current_page()
+        self.ui_goto(page_team)
+        self.check_zones('年兽')
+        cd = self.check_cd()
+        if cd:
+            cd_exit(cd)
+        # 但是这个时候还不一定可以完全判断有没有进入cd
+        cd_count = 0
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_N_WAITING):
+                break
+            if cd_count >= 4:
+                # 4 x 1.5 = 6秒没有进入说明是在冷却中
+                cd_exit()
+            if self.appear_then_click(self.I_GR_AUTO_MATCH, interval=1.5):
+                cd_count += 1
+                continue
+        # 匹配个8分钟,要是八分钟还没人拿没啥了
+        logger.info('Waiting for match')
+        click_timer = Timer(240)
+        check_timer = Timer(480)
+        click_timer.start()
+        check_timer.start()
+        self.device.stuck_record_add('LOGIN_CHECK')
+        while 1:
+            self.screenshot()
+            # 如果被秒开进入战斗, 被秒开不支持开启buff
+            if self.check_take_over_battle(False, config=self.battle_config):
+                logger.info('Nian take over battle')
+                break
+            # 如果进入房间
+            elif self.is_in_room():
+                self.device.stuck_record_clear()
+                if self.wait_battle(wait_time=time(minute=1)):
+                    buff = []
+                    if con.buff_gold_50_click:
+                        buff.append(BuffClass.gold_50)
+                    if con.buff_gold_100_click:
+                        buff.append(BuffClass.gold_100)
+                    if buff is []:
+                        buff = None
+                    self.run_general_battle(config=self.config.orochi.general_battle_config, buff=buff)
+                    break
+                else:
+                    break
+            # 如果时间到了
+            if check_timer.reached():
+                logger.warning('Nian match timeout')
+                while 1:
+                    self.screenshot()
+                    if not self.appear(self.I_N_WAITING):
+                        break
+                    if self.appear_then_click(self.I_N_WAITING, interval=0.7):
+                        continue
+                logger.info('Nian match timeout, exit')
+                break
+            # 如果还在匹配中
+            if self.appear(self.I_N_WAITING):
+                continue
+
+        # 退出结束
+        self.set_next_run(task='Nian', success=True, finish=False)
+        raise TaskEnd('Nian')
+
+    def check_cd(self) -> False or timedelta:
+        """
+        检查是否在冷却中,
+        :return: 如果是冷却中, 返回剩余时间, 否则返回False
+        """
+        self.screenshot()
+        if not self.appear(self.I_N_CHECK):
+            return False
+        if not self.ocr_appear(self.O_N_BATTLE_AGAIN):
+            return False
+        # 可以判断是在冷却了
+        result = self.O_N_CD.ocr(self.device.image)
+        if not isinstance(result, str):
+            logger.error(f'OCR error {result}')
+            return False
+        result = re.search(r'(\d+)时(\d+)分后可', result)
+        time_delta = timedelta(hours=int(result.group(1)), minutes=int(result.group(2)))
+        return time_delta
+
+    @cached_property
+    def battle_config(self) -> GeneralBattleConfig:
+        conf = GeneralBattleConfig()
+        return conf
+
+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()
+