Ver Fonte

Merge pull request #637 from ljxun/days111

每日召唤 增加票数判断(愿礼) 增加今忆召唤
huangrunheng há 1 ano atrás
pai
commit
0efe58206d

+ 44 - 32
tasks/Component/Summon/summon.py

@@ -8,7 +8,7 @@ import random
 from tasks.Component.Summon.assets import SummonAssets
 from tasks.base_task import BaseTask
 from module.logger import logger
-
+import re
 
 class Summon(BaseTask, SummonAssets):
 
@@ -39,39 +39,51 @@ class Summon(BaseTask, SummonAssets):
         """
         logger.info('Summon one')
         self.wait_until_appear(self.I_BLUE_TICKET)
-        ticket_info = self.O_ONE_TICKET.ocr(self.device.image)
-        if '1' not in ticket_info:
-            logger.warning('There is no any one blue ticket')
-            return
-        # 某些情况下滑动异常
-        self.S_RANDOM_SWIPE_1.name = 'S_RANDOM_SWIPE'
-        self.S_RANDOM_SWIPE_2.name = 'S_RANDOM_SWIPE'
-        self.S_RANDOM_SWIPE_3.name = 'S_RANDOM_SWIPE'
-        self.S_RANDOM_SWIPE_4.name = 'S_RANDOM_SWIPE'
-        while 1:
-            self.screenshot()
-            if self.appear(self.I_ONE_TICKET):
-                break
-            if self.appear_then_click(self.I_BLUE_TICKET, interval=1):
-                continue
+        while True:
+            ticket_info = self.O_ONE_TICKET.ocr(self.device.image)
+            # 处理 None 和空字符串
+            if ticket_info is None or ticket_info == '':
+                ticket_info = 0
+            else:
+                # 使用正则表达式提取字符串中的数字
+                match = re.search(r'\d+', ticket_info)
+                if match:
+                    ticket_info = int(match.group())
+                else:
+                    logger.warning(f'Invalid ticket_info value: {ticket_info}, expected a numeric string')
+                    ticket_info = 0  # 将无效值设置为默认值 0
+            if ticket_info <= 0:
+                logger.warning('There is no any one blue ticket')
+                return
+            # 某些情况下滑动异常
+            self.S_RANDOM_SWIPE_1.name = 'S_RANDOM_SWIPE'
+            self.S_RANDOM_SWIPE_2.name = 'S_RANDOM_SWIPE'
+            self.S_RANDOM_SWIPE_3.name = 'S_RANDOM_SWIPE'
+            self.S_RANDOM_SWIPE_4.name = 'S_RANDOM_SWIPE'
+            while 1:
+                self.screenshot()
+                if self.appear(self.I_ONE_TICKET):
+                    break
+                if self.appear_then_click(self.I_BLUE_TICKET, interval=1):
+                    continue
 
-        # 画一张票
-        time.sleep(0.5)
-        while 1:
-            self.screenshot()
-            if self.appear(self.I_SM_CONFIRM, interval=0.6):
-                self.ui_click_until_disappear(self.I_SM_CONFIRM)
-                break
-            if self.appear(self.I_SM_CONFIRM_2, interval=0.6):
-                self.ui_click_until_disappear(self.I_SM_CONFIRM_2)
-                break
-            if self.appear(self.I_ONE_TICKET, interval=1):
-                # 某些时候会点击到 “语言召唤”
-                if self.appear_then_click(self.I_UI_CANCEL, interval=0.8):
+            # 画一张票
+            time.sleep(0.5)
+            while 1:
+                self.screenshot()
+                if self.appear(self.I_SM_CONFIRM, interval=0.6):
+                    self.ui_click_until_disappear(self.I_SM_CONFIRM)
+                    break
+                if self.appear(self.I_SM_CONFIRM_2, interval=0.6):
+                    self.ui_click_until_disappear(self.I_SM_CONFIRM_2)
+                    break
+                if self.appear(self.I_ONE_TICKET, interval=1):
+                    # 某些时候会点击到 “语言召唤”
+                    if self.appear_then_click(self.I_UI_CANCEL, interval=0.8):
+                        continue
+                    self.summon()
                     continue
-                self.summon()
-                continue
-        logger.info('Summon one success')
+            logger.info('Summon one success')
 
 
     def back_summon_main(self):

+ 26 - 0
tasks/DailyTrifles/assets.py

@@ -47,3 +47,29 @@ class DailyTriflesAssets:
 	O_STORE_SUSHI_PRICE = RuleOcr(roi=(0,0,0,0), area=(0,0,0,0), mode="Digit", method="Default", keyword="", name="store_sushi_price")
 
 
+	# Image Rule Assets
+	# 点击今忆召唤票 
+	I_RECALL_TICKET = RuleImage(roi_front=(595,586,65,76), roi_back=(595,586,65,76), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/summonRecall/recall_ticket.png")
+	# 今忆召唤单抽 
+	I_RECALL_ONE_TICKET = RuleImage(roi_front=(459,604,76,76), roi_back=(459,604,76,76), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/summonRecall/recall_one_ticket.png")
+	# description 
+	I_RECALL_SM_CONFIRM = RuleImage(roi_front=(424,628,174,61), roi_back=(424,628,174,61), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/summonRecall/recall_sm_confirm.png")
+	# 抽到的时候出现的 
+	I_SM_CONFIRM_2 = RuleImage(roi_front=(377,630,206,62), roi_back=(377,630,206,62), threshold=0.8, method="Template matching", file="./tasks/DailyTrifles/summonRecall/sm_sm_confirm_2.png")
+
+
+	# Ocr Rule Assets
+	# 今忆抽卡区域 
+	O_RECALL_TICKET_AREA = RuleOcr(roi=(590,660,100,32), area=(590,660,100,32), mode="Single", method="Default", keyword="", name="recall_ticket_area")
+	# 选择抽卡区域 
+	O_SELECT_SM = RuleOcr(roi=(0,0,100,720), area=(0,0,100,720), mode="Single", method="Default", keyword="", name="select_sm")
+	# description 
+	O_SELECT_SM1 = RuleOcr(roi=(27,130,45,38), area=(27,130,45,38), mode="Single", method="Default", keyword="", name="select_sm1")
+	# description 
+	O_SELECT_SM2 = RuleOcr(roi=(26,216,45,38), area=(26,216,45,38), mode="Single", method="Default", keyword="", name="select_sm2")
+	# description 
+	O_SELECT_SM3 = RuleOcr(roi=(26,304,45,38), area=(26,304,45,38), mode="Single", method="Default", keyword="", name="select_sm3")
+	# description 
+	O_SELECT_SM4 = RuleOcr(roi=(26,397,45,38), area=(26,397,45,38), mode="Single", method="Default", keyword="", name="select_sm4")
+
+

+ 6 - 0
tasks/DailyTrifles/config.py

@@ -6,10 +6,16 @@ from pydantic import BaseModel, Field
 
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase
+from enum import Enum
 
+class SummonType(str, Enum):
+    default = '普通召唤'
+    recall = '今忆召唤'
 
 class DailyTriflesConfig(BaseModel):
     one_summon: bool = Field(title='One Summon', default=False)
+    # 召唤类型
+    summon_type: SummonType = Field(default=SummonType.default, description='召唤类型')
     guild_wish: bool = Field(title='Guild Wish', default=False)
     friend_love: bool = Field(title='Friend Love', default=False)
     luck_msg: bool = Field(title='Luck Msg', default=False)

+ 91 - 2
tasks/DailyTrifles/script_task.py

@@ -17,20 +17,25 @@ from tasks.Component.Summon.summon import Summon
 from module.logger import logger
 from module.exception import TaskEnd
 from module.base.timer import Timer
-
+from tasks.DailyTrifles.config import SummonType
+import re
 
 class ScriptTask(GameUi, Summon, DailyTriflesAssets):
 
     def run(self):
         con = self.config.daily_trifles.trifles_config
+        # 每日召唤
         if con.one_summon:
             self.run_one_summon()
         if con.guild_wish:
             pass
+        # 友情点
         if con.friend_love:
             self.run_friend_love()
+        # 吉闻
         if con.luck_msg:
             self.run_luck_msg()
+        # 商店签到 or 购买寿司
         if con.store_sign or con.buy_sushi_count > 0:
             self.run_store()
         self.set_next_run('DailyTrifles', success=True, finish=False)
@@ -39,9 +44,93 @@ class ScriptTask(GameUi, Summon, DailyTriflesAssets):
     def run_one_summon(self):
         self.ui_get_current_page()
         self.ui_goto(page_summon)
-        self.summon_one()
+        if self.config.daily_trifles.trifles_config.summon_type == SummonType.default:
+            self.summon_one()
+        elif self.config.daily_trifles.trifles_config.summon_type == SummonType.recall:
+            self.summon_recall()
         self.back_summon_main()
 
+    def summon_recall(self):
+        """
+        确保在召唤界面,每日召唤一次
+        召唤结束后回到 召唤主界面
+        :return:
+        """
+        list = [self.O_SELECT_SM2, self.O_SELECT_SM3, self.O_SELECT_SM4]
+        count = 0
+        while True:
+            count += 1
+
+            for i in range(len(list)):
+                sleep(1)
+                self.ui_get_current_page()
+                self.ui_goto(page_main)
+                self.ui_get_current_page()
+                self.ui_goto(page_summon)
+                self.appear_then_click(self.I_UI_BACK_RED, interval=1)
+                x, y = list[i].coord()
+                self.device.click(x, y)
+                sleep(1)
+                self.screenshot()
+                if self.appear(self.I_RECALL_TICKET):
+                    break
+                logger.info("Select preset group RECALL")
+
+            self.screenshot()
+            if self.appear(self.I_RECALL_TICKET):
+                break
+            if count >= 3:
+                self.config.notifier.push(title='今忆召唤抽卡失败', content='每日任务,今忆召唤抽卡失败!!!')
+                return
+
+        logger.info('Summon one RECALL')
+        self.wait_until_appear(self.I_RECALL_TICKET)
+        while True:
+            ticket_info = self.O_RECALL_TICKET_AREA.ocr(self.device.image)
+            # 处理 None 和空字符串
+            if ticket_info is None or ticket_info == '':
+                ticket_info = 0
+            else:
+                # 使用正则表达式提取字符串中的数字
+                match = re.search(r'\d+', ticket_info)
+                if match:
+                    ticket_info = int(match.group())
+                else:
+                    logger.warning(f'Invalid ticket_info value: {ticket_info}, expected a numeric string')
+                    ticket_info = 0  # 将无效值设置为默认值 0
+            if ticket_info <= 0:
+                logger.warning('There is no any one RECALL ticket')
+                return
+            # 某些情况下滑动异常
+            self.S_RANDOM_SWIPE_1.name = 'S_RANDOM_SWIPE'
+            self.S_RANDOM_SWIPE_2.name = 'S_RANDOM_SWIPE'
+            self.S_RANDOM_SWIPE_3.name = 'S_RANDOM_SWIPE'
+            self.S_RANDOM_SWIPE_4.name = 'S_RANDOM_SWIPE'
+            while 1:
+                self.screenshot()
+                if self.appear(self.I_RECALL_ONE_TICKET):
+                    break
+                if self.appear_then_click(self.I_RECALL_TICKET, interval=1):
+                    continue
+
+            # 画一张票
+            sleep(1)
+            while 1:
+                self.screenshot()
+                if self.appear(self.I_RECALL_SM_CONFIRM, interval=0.6):
+                    self.ui_click_until_disappear(self.I_RECALL_SM_CONFIRM)
+                    break
+                if self.appear(self.I_SM_CONFIRM_2, interval=0.6):
+                    self.ui_click_until_disappear(self.I_SM_CONFIRM_2)
+                    break
+                if self.appear(self.I_RECALL_ONE_TICKET, interval=1):
+                    # 某些时候会点击到 “语言召唤”
+                    if self.appear_then_click(self.I_UI_CANCEL, interval=0.8):
+                        continue
+                    self.summon()
+                    continue
+            logger.info('Summon one success')
+
     def run_guild_wish(self):
         pass
 

+ 38 - 0
tasks/DailyTrifles/summonRecall/image.json

@@ -0,0 +1,38 @@
+[
+  {
+    "itemName": "recall_ticket",
+    "imageName": "recall_ticket.png",
+    "roiFront": "595,586,65,76",
+    "roiBack": "595,586,65,76",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "点击今忆召唤票"
+  },
+  {
+    "itemName": "recall_one_ticket",
+    "imageName": "recall_one_ticket.png",
+    "roiFront": "459,604,76,76",
+    "roiBack": "459,604,76,76",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "今忆召唤单抽"
+  },
+  {
+    "itemName": "recall_sm_confirm",
+    "imageName": "recall_sm_confirm.png",
+    "roiFront": "424,628,174,61",
+    "roiBack": "424,628,174,61",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "sm_confirm_2",
+    "imageName": "sm_sm_confirm_2.png",
+    "roiFront": "377,630,206,62",
+    "roiBack": "377,630,206,62",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "抽到的时候出现的"
+  }
+]

+ 60 - 0
tasks/DailyTrifles/summonRecall/ocr.json

@@ -0,0 +1,60 @@
+[
+  {
+    "itemName": "recall_ticket_area",
+    "roiFront": "590,660,100,32",
+    "roiBack": "590,660,100,32",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "今忆抽卡区域"
+  },
+  {
+    "itemName": "select_sm",
+    "roiFront": "0,0,100,720",
+    "roiBack": "0,0,100,720",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "选择抽卡区域"
+  },
+  {
+    "itemName": "select_sm1",
+    "roiFront": "27,130,45,38",
+    "roiBack": "27,130,45,38",
+    "method": "Template matching",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "description"
+  },
+  {
+    "itemName": "select_sm2",
+    "roiFront": "26,216,45,38",
+    "roiBack": "26,216,45,38",
+    "method": "Template matching",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "description"
+  },
+  {
+    "itemName": "select_sm3",
+    "roiFront": "26,304,45,38",
+    "roiBack": "26,304,45,38",
+    "method": "Template matching",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "description"
+  },
+  {
+    "itemName": "select_sm4",
+    "roiFront": "26,397,45,38",
+    "roiBack": "26,397,45,38",
+    "method": "Template matching",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "description"
+  }
+]

BIN
tasks/DailyTrifles/summonRecall/recall_one_ticket.png


BIN
tasks/DailyTrifles/summonRecall/recall_sm_confirm.png


BIN
tasks/DailyTrifles/summonRecall/recall_ticket.png