Преглед изворни кода

feat(task): Update TalismanPass to get reward of level

runhey пре 3 година
родитељ
комит
864d3d0aba

BIN
module/config/i18n/zh_CN.qm


+ 2 - 0
module/config/i18n/zh_CN.ts

@@ -633,5 +633,7 @@ Refresh:直接刷新,如果刷新操作进入CD,将标记为失败并退
 	<message><source>secret_gold_50_help</source><translation>这将会在低层[1-5]自动打开加成并且自动关闭加成</translation></message>
 	<message><source>secret_gold_50_help</source><translation>这将会在低层[1-5]自动打开加成并且自动关闭加成</translation></message>
 	<message><source>secret_gold_100_help</source><translation>同上</translation></message>
 	<message><source>secret_gold_100_help</source><translation>同上</translation></message>
 	<message><source>layer_10_help</source><translation>考虑到练度,这将不是默认打开的</translation></message>
 	<message><source>layer_10_help</source><translation>考虑到练度,这将不是默认打开的</translation></message>
+	<message><source>TalismanConfig</source><translation>花合战</translation></message>
+	<message><source>LevelReward</source><translation>选择礼盒</translation></message>
 </context>	
 </context>	
 </TS>
 </TS>

+ 1 - 1
tasks/GameUi/assets.py

@@ -127,7 +127,7 @@ class GameUiAssets:
 	# description 
 	# description 
 	I_MAIN_GOTO_FRIENDS = RuleImage(roi_front=(878,623,55,55), roi_back=(878,623,55,55), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_friends.png")
 	I_MAIN_GOTO_FRIENDS = RuleImage(roi_front=(878,623,55,55), roi_back=(878,623,55,55), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_friends.png")
 	# description 
 	# description 
-	I_MAIN_GOTO_DAILY = RuleImage(roi_front=(769,623,52,54), roi_back=(769,623,52,54), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_daily.png")
+	I_MAIN_GOTO_DAILY = RuleImage(roi_front=(778,612,52,54), roi_back=(759,595,84,84), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_main_goto_daily.png")
 	# description 
 	# description 
 	I_MAIN_GOTO_MALL = RuleImage(roi_front=(657,624,47,52), roi_back=(657,624,47,52), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_mall.png")
 	I_MAIN_GOTO_MALL = RuleImage(roi_front=(657,624,47,52), roi_back=(657,624,47,52), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_mall.png")
 	# description 
 	# description 

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

@@ -29,10 +29,10 @@
   {
   {
     "itemName": "main_goto_daily",
     "itemName": "main_goto_daily",
     "imageName": "page_main_goto_daily.png",
     "imageName": "page_main_goto_daily.png",
-    "roiFront": "769,623,52,54",
-    "roiBack": "769,623,52,54",
+    "roiFront": "778,612,52,54",
+    "roiBack": "759,595,84,84",
     "method": "Template matching",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.7,
     "description": "description"
     "description": "description"
   },
   },
   {
   {

BIN
tasks/GameUi/page/page_main_goto_daily.png


+ 10 - 0
tasks/TalismanPass/assets.py

@@ -19,5 +19,15 @@ class TalismanPassAssets:
 	I_RED_POINT_DAY = RuleImage(roi_front=(632,157,23,26), roi_back=(632,157,23,26), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_red_point_day.png")
 	I_RED_POINT_DAY = RuleImage(roi_front=(632,157,23,26), roi_back=(632,157,23,26), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_red_point_day.png")
 	# 本周 的右上方红点 
 	# 本周 的右上方红点 
 	I_RED_POINT_WEEK = RuleImage(roi_front=(795,156,24,25), roi_back=(795,156,24,25), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_red_point_week.png")
 	I_RED_POINT_WEEK = RuleImage(roi_front=(795,156,24,25), roi_back=(795,156,24,25), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_red_point_week.png")
+	# 等级奖励 
+	I_RED_POINT_LEVEL = RuleImage(roi_front=(1222,174,23,24), roi_back=(1222,174,23,24), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_red_point_level.png")
+	# 选择一号奖励 
+	I_TP_LEVEL_1 = RuleImage(roi_front=(203,435,122,59), roi_back=(203,435,122,59), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_tp_level_1.png")
+	# 选择二号奖励 
+	I_TP_LEVEL_2 = RuleImage(roi_front=(577,435,122,55), roi_back=(577,435,122,55), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_tp_level_2.png")
+	# 选择三号奖励 
+	I_TP_LEVEL_3 = RuleImage(roi_front=(967,433,109,61), roi_back=(967,433,109,61), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_tp_level_3.png")
+	# 前往 
+	I_TP_GOTO = RuleImage(roi_front=(995,254,85,34), roi_back=(928,219,206,315), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_tp_goto.png")
 
 
 
 

+ 9 - 0
tasks/TalismanPass/config.py

@@ -2,6 +2,7 @@
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
 from datetime import timedelta
 from datetime import timedelta
+from enum import Enum
 from pydantic import BaseModel, Field
 from pydantic import BaseModel, Field
 
 
 from tasks.Component.config_scheduler import Scheduler as BaseScheduler
 from tasks.Component.config_scheduler import Scheduler as BaseScheduler
@@ -11,7 +12,15 @@ class Scheduler(BaseScheduler):
     success_interval: TimeDelta = Field(default=TimeDelta(hours=6), description='success_interval_help')
     success_interval: TimeDelta = Field(default=TimeDelta(hours=6), description='success_interval_help')
     failure_interval: TimeDelta = Field(default=TimeDelta(hours=6), description='failure_interval_help')
     failure_interval: TimeDelta = Field(default=TimeDelta(hours=6), description='failure_interval_help')
 
 
+class LevelReward(str, Enum):
+    ONE = '蛇皮/青吉鬼'
+    TWO = '金币/勾玉'
+    THREE = '体力/樱饼'
+
+class TalismanConfig(BaseModel):
+    level_reward: LevelReward = Field(default=LevelReward.TWO)
 
 
 class TalismanPass(ConfigBase):
 class TalismanPass(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
     scheduler: Scheduler = Field(default_factory=Scheduler)
+    talisman: TalismanConfig = Field(default_factory=TalismanConfig)
 
 

+ 50 - 4
tasks/TalismanPass/script_task.py

@@ -6,9 +6,11 @@ import time
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.page import page_main, page_daily
 from tasks.GameUi.page import page_main, page_daily
 from tasks.TalismanPass.assets import TalismanPassAssets
 from tasks.TalismanPass.assets import TalismanPassAssets
+from tasks.TalismanPass.config import TalismanConfig, LevelReward
 
 
 from module.logger import logger
 from module.logger import logger
 from module.exception import TaskEnd
 from module.exception import TaskEnd
+from module.base.timer import Timer
 
 
 class ScriptTask(GameUi, TalismanPassAssets):
 class ScriptTask(GameUi, TalismanPassAssets):
 
 
@@ -16,11 +18,13 @@ class ScriptTask(GameUi, TalismanPassAssets):
         self.ui_get_current_page()
         self.ui_get_current_page()
         self.ui_goto(page_main)
         self.ui_goto(page_main)
         self.main_goto_daily()
         self.main_goto_daily()
+        con: TalismanConfig = self.config.talisman_pass.talisman
 
 
         # 收取全部奖励
         # 收取全部奖励
-        self.get_all()
+        if self.in_task():
+            self.get_all()
         # 收取花合战等级奖励
         # 收取花合战等级奖励
-        self.get_flower()
+        self.get_flower(con.level_reward)
 
 
         self.set_next_run(task='TalismanPass', success=True, finish=True)
         self.set_next_run(task='TalismanPass', success=True, finish=True)
         raise TaskEnd('TalismanPass')
         raise TaskEnd('TalismanPass')
@@ -36,13 +40,55 @@ class ScriptTask(GameUi, TalismanPassAssets):
             logger.info('No appear get all button')
             logger.info('No appear get all button')
         self.ui_get_reward(self.I_TP_GET_ALL)
         self.ui_get_reward(self.I_TP_GET_ALL)
         logger.info('Get all reward')
         logger.info('Get all reward')
+        time.sleep(0.5)
 
 
-    def get_flower(self):
+    def get_flower(self, level: LevelReward = LevelReward.TWO):
         """
         """
         收取花合战等级奖励
         收取花合战等级奖励
         :return:
         :return:
         """
         """
-        pass
+        match_level = {
+            LevelReward.ONE: self.I_TP_LEVEL_1,
+            LevelReward.TWO: self.I_TP_LEVEL_2,
+            LevelReward.THREE: self.I_TP_LEVEL_3,
+        }
+        self.screenshot()
+        if not self.appear(self.I_RED_POINT_LEVEL):
+            logger.info('No any level reward')
+            return
+        logger.info('Appear level reward')
+        self.ui_click(self.I_RED_POINT_LEVEL, self.I_TP_GET_ALL)
+        logger.info('Click level reward')
+        check_timer = Timer(2)
+        check_timer.start()
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(match_level[level], interval=0.8):
+                logger.info(f'Select {level} reward')
+                check_timer.reset()
+                continue
+
+            if self.ui_reward_appear_click(False):
+                logger.info('Get reward')
+                check_timer.reset()
+                continue
+            if check_timer.reached():
+                logger.warning('No reward and break')
+                break
+            if self.appear_then_click(self.I_TP_GET_ALL, interval=2.1):
+                logger.info('Get all reward')
+                check_timer.reset()
+                continue
+
+    def in_task(self) -> bool:
+        """
+        判断是否在任务的界面
+        :return:
+        """
+        self.screenshot()
+        return self.appear(self.I_TP_GOTO)
+
+
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config

+ 45 - 0
tasks/TalismanPass/tp/image.json

@@ -34,5 +34,50 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "本周 的右上方红点"
     "description": "本周 的右上方红点"
+  },
+  {
+    "itemName": "red_point_level",
+    "imageName": "tp_red_point_level.png",
+    "roiFront": "1222,174,23,24",
+    "roiBack": "1222,174,23,24",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "等级奖励"
+  },
+  {
+    "itemName": "tp_level_1",
+    "imageName": "tp_tp_level_1.png",
+    "roiFront": "203,435,122,59",
+    "roiBack": "203,435,122,59",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "选择一号奖励"
+  },
+  {
+    "itemName": "tp_level_2",
+    "imageName": "tp_tp_level_2.png",
+    "roiFront": "577,435,122,55",
+    "roiBack": "577,435,122,55",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "选择二号奖励"
+  },
+  {
+    "itemName": "tp_level_3",
+    "imageName": "tp_tp_level_3.png",
+    "roiFront": "967,433,109,61",
+    "roiBack": "967,433,109,61",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "选择三号奖励"
+  },
+  {
+    "itemName": "tp_goto",
+    "imageName": "tp_tp_goto.png",
+    "roiFront": "995,254,85,34",
+    "roiBack": "928,219,206,315",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "前往"
   }
   }
 ]
 ]

BIN
tasks/TalismanPass/tp/tp_red_point_level.png


BIN
tasks/TalismanPass/tp/tp_tp_goto.png


BIN
tasks/TalismanPass/tp/tp_tp_level_1.png


BIN
tasks/TalismanPass/tp/tp_tp_level_2.png


BIN
tasks/TalismanPass/tp/tp_tp_level_3.png