Jelajahi Sumber

每日琐事 增加今忆召唤

ljxun 1 tahun lalu
induk
melakukan
5bb84058a7

+ 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")
 	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_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase
 from tasks.Component.config_base import ConfigBase
+from enum import Enum
 
 
+class SummonType(str, Enum):
+    default = '普通召唤'
+    recall = '今忆召唤'
 
 
 class DailyTriflesConfig(BaseModel):
 class DailyTriflesConfig(BaseModel):
     one_summon: bool = Field(title='One Summon', default=False)
     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)
     guild_wish: bool = Field(title='Guild Wish', default=False)
     friend_love: bool = Field(title='Friend Love', default=False)
     friend_love: bool = Field(title='Friend Love', default=False)
     luck_msg: bool = Field(title='Luck Msg', default=False)
     luck_msg: bool = Field(title='Luck Msg', default=False)

+ 110 - 87
tasks/DailyTrifles/script_task.py

@@ -1,16 +1,14 @@
 # This Python file uses the following encoding: utf-8
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
-import copy
 from time import sleep
 from time import sleep
-from datetime import time, datetime, timedelta
 
 
-from exceptiongroup import catch
-from winerror import NOERROR
+import re
+from datetime import time, datetime, timedelta
 
 
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.page import page_main, page_summon, page_guild, page_mall, page_friends
 from tasks.GameUi.page import page_main, page_summon, page_guild, page_mall, page_friends
-from tasks.DailyTrifles.config import DailyTriflesConfig
+from tasks.DailyTrifles.config import SummonType
 from tasks.DailyTrifles.assets import DailyTriflesAssets
 from tasks.DailyTrifles.assets import DailyTriflesAssets
 from tasks.Component.Summon.summon import Summon
 from tasks.Component.Summon.summon import Summon
 
 
@@ -23,25 +21,114 @@ class ScriptTask(GameUi, Summon, DailyTriflesAssets):
 
 
     def run(self):
     def run(self):
         con = self.config.daily_trifles.trifles_config
         con = self.config.daily_trifles.trifles_config
+        # 每日召唤
         if con.one_summon:
         if con.one_summon:
             self.run_one_summon()
             self.run_one_summon()
         if con.guild_wish:
         if con.guild_wish:
             pass
             pass
+        # 友情点
         if con.friend_love:
         if con.friend_love:
             self.run_friend_love()
             self.run_friend_love()
+        # 吉闻
         if con.luck_msg:
         if con.luck_msg:
             self.run_luck_msg()
             self.run_luck_msg()
-        if con.store_sign or con.buy_sushi_count > 0:
-            self.run_store()
+        # 商店签到
+        if con.store_sign:
+            self.run_store_sign()
+
         self.set_next_run('DailyTrifles', success=True, finish=False)
         self.set_next_run('DailyTrifles', success=True, finish=False)
         raise TaskEnd('DailyTrifles')
         raise TaskEnd('DailyTrifles')
 
 
     def run_one_summon(self):
     def run_one_summon(self):
         self.ui_get_current_page()
         self.ui_get_current_page()
         self.ui_goto(page_summon)
         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()
         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):
     def run_guild_wish(self):
         pass
         pass
 
 
@@ -52,8 +139,6 @@ class ScriptTask(GameUi, Summon, DailyTriflesAssets):
             self.screenshot()
             self.screenshot()
             if self.appear(self.I_LUCK_TITLE):
             if self.appear(self.I_LUCK_TITLE):
                 break
                 break
-            if self.appear_then_click(self.I_FRIENDSHIP_UP, interval=1):
-                continue
             if self.appear_then_click(self.I_LUCK_MSG, interval=1):
             if self.appear_then_click(self.I_LUCK_MSG, interval=1):
                 continue
                 continue
         logger.info('Start luck msg')
         logger.info('Start luck msg')
@@ -67,10 +152,10 @@ class ScriptTask(GameUi, Summon, DailyTriflesAssets):
             if self.appear_then_click(self.I_ONE_CLICK_BLESS, interval=1):
             if self.appear_then_click(self.I_ONE_CLICK_BLESS, interval=1):
                 continue
                 continue
             if self.ui_reward_appear_click():
             if self.ui_reward_appear_click():
-                logger.info('Get reward of luck msg')
+                logger.info('Get reward of friend love')
                 break
                 break
             if check_timer.reached():
             if check_timer.reached():
-                logger.warning('There is no any luck msg')
+                logger.warning('There is no any love')
                 break
                 break
 
 
         self.ui_click(self.I_UI_BACK_RED, self.I_CHECK_MAIN)
         self.ui_click(self.I_UI_BACK_RED, self.I_CHECK_MAIN)
@@ -82,10 +167,10 @@ class ScriptTask(GameUi, Summon, DailyTriflesAssets):
             self.screenshot()
             self.screenshot()
             if self.appear(self.I_L_LOVE):
             if self.appear(self.I_L_LOVE):
                 break
                 break
-            if self.appear_then_click(self.I_FRIENDSHIP_UP, interval=1):
-                continue
             if self.appear_then_click(self.I_L_FRIENDS, interval=1):
             if self.appear_then_click(self.I_L_FRIENDS, interval=1):
                 continue
                 continue
+            if self.appear_then_click(self.I_UI_BACK_RED, interval=1):
+                continue
         logger.info('Start friend love')
         logger.info('Start friend love')
         check_timer = Timer(2)
         check_timer = Timer(2)
         check_timer.start()
         check_timer.start()
@@ -103,21 +188,10 @@ class ScriptTask(GameUi, Summon, DailyTriflesAssets):
 
 
         self.ui_click(self.I_UI_BACK_RED, self.I_CHECK_MAIN)
         self.ui_click(self.I_UI_BACK_RED, self.I_CHECK_MAIN)
 
 
-    def run_store(self):
+    def run_store_sign(self):
         self.ui_get_current_page()
         self.ui_get_current_page()
         self.ui_goto(page_mall, confirm_wait=3)
         self.ui_goto(page_mall, confirm_wait=3)
 
 
-        if self.config.daily_trifles.trifles_config.store_sign:
-            self.run_store_sign()
-        if self.config.daily_trifles.trifles_config.buy_sushi_count > 0:
-            self.run_buy_sushi()
-
-        self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MALL)
-        self.ui_get_current_page()
-        self.ui_goto(page_main)
-
-    def run_store_sign(self):
-
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
             if self.appear(self.I_GIFT_RECOMMEND):
             if self.appear(self.I_GIFT_RECOMMEND):
@@ -131,77 +205,26 @@ class ScriptTask(GameUi, Summon, DailyTriflesAssets):
         self.screenshot()
         self.screenshot()
         if not self.appear(self.I_GIFT_SIGN):
         if not self.appear(self.I_GIFT_SIGN):
             logger.warning('There is no gift sign')
             logger.warning('There is no gift sign')
+            self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MALL)
+            self.ui_get_current_page()
+            self.ui_goto(page_main)
             return
             return
 
 
         if self.ui_get_reward(self.I_GIFT_SIGN, click_interval=2.5):
         if self.ui_get_reward(self.I_GIFT_SIGN, click_interval=2.5):
             logger.info('Get reward of gift sign')
             logger.info('Get reward of gift sign')
 
 
-    def run_buy_sushi(self):
-
-        # 进入Special
-        while 1:
-            from tasks.RichMan.assets import RichManAssets
-            self.screenshot()
-            if self.appear(RichManAssets.I_SIDE_CHECK_SPECIAL):
-                break
-            if self.appear_then_click(RichManAssets.I_MALL_SUNDRY, interval=1):
-                continue
-            if self.appear_then_click(RichManAssets.I_SIDE_SURE_SPECIAL, interval=1):
-                continue
-
-        def detect_buy_count(base_element) -> (int, int):
-            # 返回count,price
-            MAX_PRICE = 9999
-            MAX_COUNT = 9999
-            roi = copy.deepcopy(base_element.roi_front)
-            roi[0] = roi[0] + roi[2]
-            roi[1] = roi[1] + roi[3] - 30
-            roi[2] = 60
-            roi[3] = 30
-            self.O_STORE_SUSHI_PRICE.roi = roi
-            _price = self.O_STORE_SUSHI_PRICE.detect_text(self.device.image)
-            # 保守策略,避免OCR错误购买
-            try:
-                _price = int(_price)
-            except Exception as e:
-                _price = MAX_PRICE
-
-            if _price < 60:
-                return 0, MAX_PRICE
-            _count = (_price - 60) / 20
-            return _count, _price
-
-        roi = None
-        # 购买体力
-        while 1:
-            self.screenshot()
-            # count, price = detect_buy_count(roi)
-            # if count >= self.config.model.daily_trifles.trifles_config.buy_sushi_count:
-            #     break
-            if self.appear(self.I_STORE_COST_TYPE_JADE):
-                count, price = detect_buy_count(self.I_STORE_COST_TYPE_JADE)
-                if count >= self.config.daily_trifles.trifles_config.buy_sushi_count:
-                    break
-                self.ui_click_until_disappear(self.I_STORE_COST_TYPE_JADE, interval=2)
-                logger.info(f"Buy Sushi With {price} Jade")
-                continue
-
-            if self.appear(self.I_SPECIAL_SUSHI):
-                # 此处确定当前购买体力所需勾玉数量的位置,用于后续识别
-                count, price = detect_buy_count(self.I_SPECIAL_SUSHI)
-                if count >= self.config.daily_trifles.trifles_config.buy_sushi_count:
-                    break
-                self.ui_click(self.I_SPECIAL_SUSHI, stop=self.I_STORE_COST_TYPE_JADE, interval=2)
-                continue
-        return
+        self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MALL)
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
 
 
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config
     from module.device.device import Device
     from module.device.device import Device
 
 
-    c = Config('oas1')
+    c = Config('oas2')
     d = Device(c)
     d = Device(c)
     t = ScriptTask(c, d)
     t = ScriptTask(c, d)
-
-    t.run_store()
+    # t.run()
+    t.run_one_summon()
+    # t.run_store_sign()

+ 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"
+  }
+]

TEMPAT SAMPAH
tasks/DailyTrifles/summonRecall/recall_one_ticket.png


TEMPAT SAMPAH
tasks/DailyTrifles/summonRecall/recall_sm_confirm.png


TEMPAT SAMPAH
tasks/DailyTrifles/summonRecall/recall_ticket.png