Просмотр исходного кода

feat(task): kekkai uilize done!

runhey 3 лет назад
Родитель
Сommit
fbbfe598b9

BIN
module/config/i18n/zh_CN.qm


+ 12 - 4
module/config/i18n/zh_CN.ts

@@ -222,6 +222,11 @@
 	<message><source>ActivityShikigami</source><translation>当期式神爬塔</translation></message>
 	<message><source>Liver Emperor Exclusive</source><translation>肝帝专属</translation></message>
 	<message><source>BondlingFairyland</source><translation>契灵之境</translation></message>
+	<message><source>Weekly Task</source><translation>每周任务</translation></message>
+	<message><source>TrueOrochi</source><translation>真·八岐大蛇</translation></message>
+	<message><source>KekkaiUtilize</source><translation>结界蹭卡</translation></message>
+	<message><source>KekkaiActivation</source><translation>结界挂卡</translation></message>
+	<message><source>DemonEncounter</source><translation>封魔之时</translation></message>
 </context>
 <context>
     <name>Args</name>
@@ -457,21 +462,21 @@ mode_3策略是刷到五个契灵后开始结契,选择高级、中级盘来
 	<message><source>Enable Sign 999</source><translation>签到999天后的签到福袋</translation></message>
 	<message><source>Enable Mail</source><translation>邮件</translation></message>
 	<message><source>Enable Soul</source><translation>御魂或者觉醒加成</translation></message>
+	<message><source>Enable Ap</source><translation>体力</translation></message>
 </context>	
 <context>
     <name>Args</name>
 	<message><source>UtilizeScheduler</source><translation>任务调度</translation></message>
 	<message><source>UtilizeConfig</source><translation>寄养</translation></message>
-	<message><source>Utilize Rule</source><translation>寄养规则</translation></message>
+	<message><source>UtilizeRule</source><translation>寄养规则</translation></message>
 	<message><source>Auto Switch Sort</source><translation>切换好友列表以游戏刷新高星排序</translation></message>
-	<message><source>Shikigami Class</source><translation>寄养式神类型</translation></message>
+	<message><source>ShikigamiClass</source><translation>寄养式神类型</translation></message>
 	<message><source>Shikigami Order</source><translation>选中第几个式神寄养</translation></message>
 	<message><source>Guild Ap Enable</source><translation>顺路收取寮补给</translation></message>
 	<message><source>Guild Assets Enable</source><translation>顺路收取寮资金</translation></message>
 	<message><source>Box Ap Enable</source><translation>顺路收取体力盒子</translation></message>
 	<message><source>Box Exp Enable</source><translation>顺路收取经验盒子</translation></message>
-	<message><source>utilize_rule_help</source><translation>挑选结界卡的规则,使用默认auto即可,当然你也可以使用过滤器自定义:
-以auto为例 "太鼓6>太鼓5>斗鱼6>斗鱼5>太鼓4>太鼓3>斗鱼4>斗鱼3"</translation></message>
+	<message><source>utilize_rule_help</source><translation>挑选结界卡的规则,使用默认default即可,具体规则看文档[任务列表],不可以选auto,已经弃置了。</translation></message>
 	<message><source>auto_switch_sort_help</source><translation>会自动寻找最优的坑位</translation></message>
 	<message><source>shikigami_class_help</source><translation>选择的式神类别(寄养默认选择N卡,且不建议选别的)</translation></message>
 	<message><source>shikigami_order_help</source><translation>从左开始选第几个式神</translation></message>
@@ -479,6 +484,9 @@ mode_3策略是刷到五个契灵后开始结契,选择高级、中级盘来
 	<message><source>guild_assets_enable_help</source><translation>必选项</translation></message>
 	<message><source>box_ap_enable_help</source><translation>必选项</translation></message>
 	<message><source>box_exp_enable_help</source><translation>必选项</translation></message>
+	<message><source>SelectFriendList</source><translation>选择同区还是跨区好友</translation></message>
+	<message><source>select_friend_list_help</source><translation>由于该死的游戏制作水准,无论任何方式都不可以稳定的对结界卡进行排序,需要从头到尾遍历一遍。
+且切换好友列表时候会丢失原先选定的好友卡,为此同时选择两个好友列表的最优解是会花费更多的时间,不打算支持</translation></message>
 </context>	
 <context>
     <name>Args</name>

+ 5 - 0
tasks/Component/ReplaceShikigami/assets.py

@@ -64,3 +64,8 @@ class ReplaceShikigamiAssets:
 	I_RS_LEVEL_MAX = RuleImage(roi_front=(487,248,23,21), roi_back=(52,238,1118,37), threshold=0.8, method="Template matching", file="./tasks/Component/ReplaceShikigami/rs/rs_rs_level_max.png")
 
 
+	# Image Rule Assets
+	# 小一个尺寸的 确认按钮 
+	I_U_CONFIRM_SMALL = RuleImage(roi_front=(672,513,131,60), roi_back=(672,513,131,60), threshold=0.8, method="Template matching", file="./tasks/Component/ReplaceShikigami/rs/utilize_u_confirm_small.png")
+
+

+ 4 - 0
tasks/Component/ReplaceShikigami/replace_shikigami.py

@@ -90,6 +90,10 @@ class ReplaceShikigami(BaseTask, ReplaceShikigamiAssets):
 
             if not self.appear(stop_image):
                 break
+
+            if self.appear_then_click(self.I_U_CONFIRM_SMALL, interval=0.5):
+                continue
+
             if self.click(click_match, interval=1.5):
                 continue
         logger.info('Set shikigami: %d' % shikigami_order)

+ 11 - 0
tasks/Component/ReplaceShikigami/rs/supplement.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "u_confirm_small",
+    "imageName": "utilize_u_confirm_small.png",
+    "roiFront": "672,513,131,60",
+    "roiBack": "672,513,131,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "小一个尺寸的 确认按钮"
+  }
+]

BIN
tasks/Component/ReplaceShikigami/rs/utilize_u_confirm_small.png


+ 5 - 5
tasks/KekkaiUtilize/assets.py

@@ -20,9 +20,9 @@ class KekkaiUtilizeAssets:
 	# 神灶 
 	I_GUILD_SHIRNE = RuleImage(roi_front=(872,624,60,62), roi_back=(872,624,60,62), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/ku/ku_guild_shirne.png")
 	# description 
-	I_GUILD_AP = RuleImage(roi_front=(483,314,22,22), roi_back=(297,232,229,132), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/ku/ku_guild_ap.png")
+	I_GUILD_AP = RuleImage(roi_front=(483,314,22,22), roi_back=(225,224,301,167), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/ku/ku_guild_ap.png")
 	# description 
-	I_GUILD_ASSETS = RuleImage(roi_front=(315,311,23,28), roi_back=(304,301,50,50), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/ku/ku_guild_assets.png")
+	I_GUILD_ASSETS = RuleImage(roi_front=(315,311,23,28), roi_back=(227,262,354,136), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/ku/ku_guild_assets.png")
 	# 领取寮资金 
 	I_GUILD_ASSETS_RECEIVE = RuleImage(roi_front=(565,426,144,63), roi_back=(565,426,144,63), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/ku/ku_guild_assets_receive.png")
 
@@ -37,11 +37,11 @@ class KekkaiUtilizeAssets:
 	# 收取经验(没有满的图) 
 	I_CARD_EXP = RuleImage(roi_front=(889,151,57,54), roi_back=(863,118,124,121), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_card_exp.png")
 	# 收取体力(没有满) 
-	I_BOX_AP = RuleImage(roi_front=(815,435,57,51), roi_back=(778,411,130,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_ap.png")
+	I_BOX_AP = RuleImage(roi_front=(815,435,57,51), roi_back=(778,411,130,100), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_ap.png")
 	# 收取盒子的经验(没有满) 
-	I_BOX_EXP = RuleImage(roi_front=(894,433,50,55), roi_back=(866,407,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp.png")
+	I_BOX_EXP = RuleImage(roi_front=(894,442,42,46), roi_back=(866,407,100,100), threshold=0.7, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_box_exp.png")
 	# 结界皮肤 
-	I_REALM_SHIN = RuleImage(roi_front=(175,460,54,58), roi_back=(147,443,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_realm_shin.png")
+	I_REALM_SHIN = RuleImage(roi_front=(175,460,54,58), roi_back=(147,443,100,100), threshold=0.9, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_realm_shin.png")
 	# 寄养别人的经验 
 	I_UTILIZE_EXP = RuleImage(roi_front=(583,144,58,43), roi_back=(531,112,156,123), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/realm/realm_utilize_exp.png")
 	# 取出 

+ 2 - 2
tasks/KekkaiUtilize/ku/image.json

@@ -39,7 +39,7 @@
     "itemName": "guild_ap",
     "imageName": "ku_guild_ap.png",
     "roiFront": "483,314,22,22",
-    "roiBack": "297,232,229,132",
+    "roiBack": "225,224,301,167",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"
@@ -48,7 +48,7 @@
     "itemName": "guild_assets",
     "imageName": "ku_guild_assets.png",
     "roiFront": "315,311,23,28",
-    "roiBack": "304,301,50,50",
+    "roiBack": "227,262,354,136",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"

BIN
tasks/KekkaiUtilize/ku/ku_guild_assets_receive.png


+ 4 - 4
tasks/KekkaiUtilize/realm/image.json

@@ -41,16 +41,16 @@
     "roiFront": "815,435,57,51",
     "roiBack": "778,411,130,100",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.7,
     "description": "收取体力(没有满)"
   },
   {
     "itemName": "box_exp",
     "imageName": "realm_box_exp.png",
-    "roiFront": "894,433,50,55",
+    "roiFront": "894,442,42,46",
     "roiBack": "866,407,100,100",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.7,
     "description": "收取盒子的经验(没有满)"
   },
   {
@@ -59,7 +59,7 @@
     "roiFront": "175,460,54,58",
     "roiBack": "147,443,100,100",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.9,
     "description": "结界皮肤"
   },
   {

BIN
tasks/KekkaiUtilize/realm/realm_box_exp.png


+ 134 - 23
tasks/KekkaiUtilize/script_task.py

@@ -3,6 +3,7 @@
 # github https://github.com/runhey
 import time
 from cached_property import cached_property
+from datetime import timedelta
 
 from module.base.timer import Timer
 from module.atom.image_grid import ImageGrid
@@ -15,12 +16,49 @@ from tasks.KekkaiUtilize.assets import KekkaiUtilizeAssets
 from tasks.KekkaiUtilize.config import UtilizeRule, SelectFriendList
 from tasks.KekkaiUtilize.utils import CardClass, target_to_card_class
 from tasks.Component.ReplaceShikigami.replace_shikigami import ReplaceShikigami
+from tasks.GameUi.page import page_main, page_guild
 
 
 class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
 
     def run(self):
-        pass
+        con = self.config.kekkai_utilize.utilize_config
+        self.ui_get_current_page()
+        self.ui_goto(page_guild)
+        # 收体力或者资金
+        # 进入寮主页会有一个动画,等一等
+        time.sleep(1)
+        self.check_guild_ap_or_assets(ap_enable=con.guild_ap_enable, assets_enable=con.guild_assets_enable)
+        # 进入寮结界
+        self.goto_realm()
+        # 顺带收体力盒子或者是经验盒子
+        time.sleep(0.5)
+        self.check_box_ap_or_exp(con.box_ap_enable, con.box_exp_enable)
+
+        # 收菜看看
+        self.check_utilize_harvest()
+        self.realm_goto_grown()
+        # 无论收不收到菜,都会进入看看至少看一眼时间还剩多少
+        self.screenshot()
+        if not self.appear(self.I_UTILIZE_ADD):
+            remaining_time = self.O_UTILIZE_RES_TIME.ocr(self.device.image)
+            if not isinstance(remaining_time, timedelta):
+                logger.warning('ocr remaining time error')
+            logger.info(f'Utilize remaining time: {remaining_time}')
+            # 执行失败,推出下一次执行为失败的时间间隔
+            logger.info('Utilize failed, exit')
+            self.back_guild()
+            self.set_next_run(task='KekkaiUtilize', success=False, finish=True)
+            raise TaskEnd
+        if not self.grown_goto_utilize():
+            logger.info('Utilize failed, exit')
+        self.run_utilize(con.select_friend_list, con.shikigami_class, con.shikigami_order)
+        self.back_guild()
+        self.set_next_run(task='KekkaiUtilize', success=True, finish=True)
+        raise TaskEnd
+
+
+
 
 
     def check_guild_ap_or_assets(self, ap_enable: bool=True, assets_enable: bool=True) -> bool:
@@ -32,6 +70,7 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
         if ap_enable or assets_enable:
             self.screenshot()
             if not self.appear(self.I_GUILD_AP) and not self.appear(self.I_GUILD_ASSETS):
+                logger.info('No ap or assets to collect')
                 return False
         else:
             return False
@@ -45,23 +84,24 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
             # 获得奖励
             if self.ui_reward_appear_click():
                 timer_check.reset()
-                continue
+
             # 资金收取确认
             if self.appear_then_click(self.I_GUILD_ASSETS_RECEIVE, interval=0.5):
                 timer_check.reset()
                 continue
 
             # 收体力
-            if self.appear_then_click(self.I_GUILD_AP, interval=0.5):
+            if self.appear_then_click(self.I_GUILD_AP, interval=1.5, threshold=0.7):
                 timer_check.reset()
                 continue
             # 收资金
-            if self.appear_then_click(self.I_GUILD_ASSETS, interval=0.5):
+            if self.appear_then_click(self.I_GUILD_ASSETS, interval=1.5, threshold=0.6):
                 timer_check.reset()
                 continue
 
             if timer_check.reached():
                 break
+        logger.info('Collect ap or assets success')
         return True
 
     def goto_realm(self):
@@ -98,14 +138,12 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
                     continue
 
         # 先是体力盒子
-        def _check_ap_box():
-            self.screenshot()
-            appear = False
-            if self.appear(self.I_BOX_AP):
-                appear = True
+        def _check_ap_box(appear: bool=False):
             if not appear:
                 return False
             # 点击盒子
+            timer_ap = Timer(12)
+            timer_ap.start()
             while 1:
                 self.screenshot()
 
@@ -119,19 +157,20 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
                     continue
                 if self.appear_then_click(self.I_AP_EXTRACT, interval=2):
                     continue
+                if timer_ap.reached():
+                    logger.warning('Extract ap box timeout')
+                    break
             logger.info('Extract AP box finished')
             _exit_to_realm()
 
-
         # 经验盒子
-        def _check_exp_box():
-            self.screenshot()
-            appear = False
-            if self.appear(self.I_BOX_EXP):
-                appear = True
+        def _check_exp_box(appear: bool=False):
             if not appear:
+                logger.info('No exp box')
                 return False
 
+            time_exp = Timer(12)
+            time_exp.start()
             while 1:
                 self.screenshot()
 
@@ -143,12 +182,17 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
                 # 如果出现结界皮肤, 表示收取好了
                 if self.appear(self.I_REALM_SHIN) and not self.appear(self.I_BOX_EXP):
                     break
+
+                if time_exp.reached():
+                    logger.warning('Extract exp box timeout')
+                    break
             _exit_to_realm()
 
+        self.screenshot()
         if ap_enable:
-            _check_ap_box()
+            _check_ap_box(self.appear(self.I_BOX_AP))
         if exp_enable:
-            _check_exp_box()
+            _check_exp_box(self.appear(self.I_BOX_EXP, threshold=0.6))
 
     def check_utilize_harvest(self) -> bool:
         """
@@ -187,7 +231,7 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
         """
         self.screenshot()
         if not self.appear(self.I_UTILIZE_ADD):
-            logger.info('No utilize add')
+            logger.warning('No utilize add')
             return False
 
         while 1:
@@ -195,9 +239,10 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
 
             if self.appear(self.I_U_ENTER_REALM):
                 break
-            if self.appear_then_click(self.I_UTILIZE_ADD, interval=1):
+            if self.appear_then_click(self.I_UTILIZE_ADD, interval=1.5):
                 continue
         logger.info('Enter utilize')
+        return True
 
     def switch_friend_list(self, friend: SelectFriendList = SelectFriendList.SAME_SERVER) -> bool:
         """
@@ -257,9 +302,12 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
             raise ValueError('Unknown utilize rule')
         return result
 
-    def run_utilize(self, friend: SelectFriendList = SelectFriendList.SAME_SERVER):
+    def run_utilize(self, friend: SelectFriendList = SelectFriendList.SAME_SERVER,
+                    shikigami_class: ShikigamiClass = ShikigamiClass.N,
+                    shikigami_order: int = 7):
         """
         执行寄养
+        :param shikigami_class:
         :param friend:
         :param rule:
         :return:
@@ -293,8 +341,10 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
             #     self.screenshot()
             return card_class
 
+        logger.hr('Start utilize')
         self.switch_friend_list(friend)
         card_best = None
+        swipe_count = 0
         while 1:
             self.screenshot()
             current_card = _current_select_best(card_best)
@@ -304,9 +354,70 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
             else:
                 card_best = current_card
 
+            # 超过十次就退出
+            if swipe_count > 10:
+                logger.warning('Swipe count is more than 10')
+                break
+
             # 一直向下滑动
             self.swipe(self.S_U_UP, interval=0.9)
+            swipe_count += 1
             time.sleep(3)
+        # 最好的结界卡
+        logger.info('End best card is %s', card_best)
+
+        # 进入结界
+        self.screenshot()
+        if not self.appear(self.I_U_ENTER_REALM):
+            logger.warning('Cannot find enter realm button')
+            # 可能是滑动的时候出错
+            logger.warning('The best reason is that the swipe is wrong')
+            return
+        while 1:
+            self.screenshot()
+
+            if not self.appear(self.I_U_ENTER_REALM):
+                break
+
+            if self.appear_then_click(self.I_U_ENTER_REALM, interval=1):
+                continue
+        logger.info('Enter friend realm')
+
+        # 切换式神的类型
+        self.switch_shikigami_class(shikigami_class)
+        # 判断好友的有两个位置还是一个坑位
+        stop_image = None
+        self.screenshot()
+        if self.appear(self.I_U_ADD_1):  # 右侧第一个有(无论左侧有没有)
+            stop_image = self.I_U_ADD_1
+        elif self.appear(self.I_U_ADD_2) and not self.appear(self.I_U_ADD_1):  # 右侧第二个有 但是最左边的没有,这表示只留有一个坑位
+            stop_image = self.I_U_ADD_2
+        if not stop_image:
+            # 没有坑位可能是其他人的手速太快了抢占了
+            logger.warning('Cannot find stop image')
+            logger.warning('Maybe other people is faster than you')
+            return
+
+        self.set_shikigami(shikigami_order, stop_image)
+
+
+    def back_guild(self):
+        """
+        回到寮的界面
+        :return:
+        """
+        while 1:
+            self.screenshot()
+
+            if self.appear(self.I_GUILD_INFO):
+                break
+            if self.appear(self.I_GUILD_REALM):
+                break
+
+            if self.appear_then_click(self.I_UI_BACK_RED, interval=1):
+                continue
+            if self.appear_then_click(self.I_UI_BACK_BLUE, interval=1):
+                continue
 
 if __name__ == "__main__":
     from module.config.config import Config
@@ -316,7 +427,7 @@ if __name__ == "__main__":
     d = Device(c)
     t = ScriptTask(c, d)
 
-    t.swipe(t.S_U_UP, interval=0.9)
-    # t.run_utilize(SelectFriendList.SAME_SERVER)
-    # t.device.scroll_window_message(x=400, y=400)
+    t.run()
+
+