ソースを参照

Merge branch 'runhey:dev' into dev

TripleEarth 3 年 前
親
コミット
b63778b80b

+ 24 - 3
module/ocr/base_ocr.py

@@ -158,7 +158,6 @@ class BaseCor:
                     text=f'[{result}]')
         return result
 
-
     def detect_and_ocr(self, image) -> list[BoxedResult]:
         """
         注意:这里使用了预处理和后处理
@@ -198,7 +197,6 @@ class BaseCor:
         else:
             return self.keyword == result
 
-
     def filter(self, boxed_results: list[BoxedResult], keyword: str=None) -> list or None:
         """
         使用ocr获取结果后和keyword进行匹配. 返回匹配的index list
@@ -240,7 +238,30 @@ class BaseCor:
         else:
             return None
 
-
+    def detect_text(self, image) -> str:
+        """
+        识别图片中的文字, 会按照顺序拼接起来
+        :param image:
+        :return:
+        """
+        # pre process
+        start_time = time.time()
+        image = self.crop(image, self.roi)
+        image = self.pre_process(image)
+        image = enlarge_canvas(image)
+        # ocr
+        boxed_results: list[BoxedResult] = self.model.detect_and_ocr(image)
+        results = ''
+        # after proces
+        for result in boxed_results:
+            # logger.info("ocr result score: %s" % result.score)
+            if result.score < self.score:
+                continue
+            results += result.ocr_text
+        # logger.info("ocr result score: %s" % score)
+        logger.attr(name='%s %ss' % (self.name, float2str(time.time() - start_time)),
+                    text=f'[{results}]')
+        return results
 
 
 # def test():

+ 14 - 1
tasks/AreaBoss/assets.py

@@ -27,7 +27,20 @@ class AreaBossAssets:
 	I_BATTLE_3 = RuleImage(roi_front=(1071,521,100,100), roi_back=(1071,521,100,100), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_battle_3.png")
 	# 点击挑战 
 	I_FIRE = RuleImage(roi_front=(1108,492,100,100), roi_back=(1108,492,100,100), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_fire.png")
-	# 红色的关闭 
+	# 跟buff冲突弃用 
 	I_CLOSE_RED = RuleImage(roi_front=(1190,24,37,38), roi_back=(1190,24,37,38), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_close_red.png")
+	# 红色关闭 
+	I_AB_CLOSE_RED = RuleImage(roi_front=(1194,24,38,37), roi_back=(1194,24,38,37), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_ab_close_red.png")
+
+
+	# Ocr Rule Assets
+	# 击杀最多 
+	O_AB_KILL_BEST = RuleOcr(roi=(942,123,157,52), area=(942,123,157,52), mode="Single", method="Default", keyword="击杀最多", name="ab_kill_best")
+	# 我的收藏 
+	O_AB_MY_COLLECT = RuleOcr(roi=(949,124,129,53), area=(949,124,129,53), mode="Single", method="Default", keyword="我的收藏", name="ab_my_collect")
+	# 热门 
+	O_AB_FAMOUS = RuleOcr(roi=(1188,181,78,82), area=(1188,181,78,82), mode="Single", method="Default", keyword="热门", name="ab_famous")
+	# 收藏 
+	O_AB_COLLECTING = RuleOcr(roi=(1163,522,88,100), area=(1163,522,88,100), mode="Single", method="Default", keyword="收藏", name="ab_collecting")
 
 

+ 4 - 1
tasks/AreaBoss/config.py

@@ -6,10 +6,13 @@ from pydantic import BaseModel, Field
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
 from tasks.Component.config_scheduler import Scheduler
 from tasks.Component.config_base import ConfigBase
+from tasks.Component.SwitchSoul.switch_soul_config import SwitchSoulConfig
 from tasks.AreaBoss.config_boss import Boss
 
 
 class AreaBoss(ConfigBase):
     scheduler: Scheduler = Field(default_factory=Scheduler)
-    general_battle: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
     boss: Boss = Field(default_factory=Boss)
+    general_battle: GeneralBattleConfig = Field(default_factory=GeneralBattleConfig)
+    switch_soul: SwitchSoulConfig = Field(default_factory=SwitchSoulConfig)
+

+ 2 - 1
tasks/AreaBoss/config_boss.py

@@ -8,5 +8,6 @@ from pydantic import BaseModel, ValidationError, validator, Field
 class Boss(BaseModel):
     boss_number: int = Field(title='Boss Number',
                              default=3,
-                             description='默认为3 可选[1-3]',
+                             description='默认为3 可选[1-3], 当你设置为三时默认你拥有全部的挑战资格,会挑战热门的前三个,\n'
+                                         '如果不是请将你可以挑战的boss进行收藏',
                              ge=1, le=3)

+ 92 - 1
tasks/AreaBoss/res/image.json

@@ -1 +1,92 @@
-[{"itemName":"explore","imageName":"res_explore.png","roiFront":"758,122,66,77","roiBack":"339,104,836,120","method":"Template matching","threshold":0.8,"description":"探索图标"},{"itemName":"area_boss","imageName":"res_area_boss.png","roiFront":"639,636,65,68","roiBack":"606,619,145,100","method":"Template matching","threshold":0.8,"description":"地狱鬼王图标"},{"itemName":"back_blue","imageName":"res_back_blue.png","roiFront":"51,30,51,52","roiBack":"4,1,128,110","method":"Template matching","threshold":0.8,"description":"蓝色的返回"},{"itemName":"filter","imageName":"res_filter.png","roiFront":"1106,29,48,49","roiBack":"1106,29,48,49","method":"Template matching","threshold":0.8,"description":"右上边选中鬼王的"},{"itemName":"battle_1","imageName":"res_battle_1.png","roiFront":"1066,210,100,100","roiBack":"1066,210,100,100","method":"Template matching","threshold":0.8,"description":"选中第一个鬼王的"},{"itemName":"battle_2","imageName":"res_battle_2.png","roiFront":"1068,364,100,100","roiBack":"1068,364,100,100","method":"Template matching","threshold":0.8,"description":"选中第二个鬼王的"},{"itemName":"battle_3","imageName":"res_battle_3.png","roiFront":"1071,521,100,100","roiBack":"1071,521,100,100","method":"Template matching","threshold":0.8,"description":"选中第三个鬼王的"},{"itemName":"fire","imageName":"res_fire.png","roiFront":"1108,492,100,100","roiBack":"1108,492,100,100","method":"Template matching","threshold":0.8,"description":"点击挑战"},{"itemName":"close_red","imageName":"res_close_red.png","roiFront":"1190,24,37,38","roiBack":"1190,24,37,38","method":"Template matching","threshold":0.8,"description":"红色的关闭"}]
+[
+  {
+    "itemName": "explore",
+    "imageName": "res_explore.png",
+    "roiFront": "758,122,66,77",
+    "roiBack": "339,104,836,120",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "探索图标"
+  },
+  {
+    "itemName": "area_boss",
+    "imageName": "res_area_boss.png",
+    "roiFront": "639,636,65,68",
+    "roiBack": "606,619,145,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "地狱鬼王图标"
+  },
+  {
+    "itemName": "back_blue",
+    "imageName": "res_back_blue.png",
+    "roiFront": "51,30,51,52",
+    "roiBack": "4,1,128,110",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "蓝色的返回"
+  },
+  {
+    "itemName": "filter",
+    "imageName": "res_filter.png",
+    "roiFront": "1106,29,48,49",
+    "roiBack": "1106,29,48,49",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "右上边选中鬼王的"
+  },
+  {
+    "itemName": "battle_1",
+    "imageName": "res_battle_1.png",
+    "roiFront": "1066,210,100,100",
+    "roiBack": "1066,210,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "选中第一个鬼王的"
+  },
+  {
+    "itemName": "battle_2",
+    "imageName": "res_battle_2.png",
+    "roiFront": "1068,364,100,100",
+    "roiBack": "1068,364,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "选中第二个鬼王的"
+  },
+  {
+    "itemName": "battle_3",
+    "imageName": "res_battle_3.png",
+    "roiFront": "1071,521,100,100",
+    "roiBack": "1071,521,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "选中第三个鬼王的"
+  },
+  {
+    "itemName": "fire",
+    "imageName": "res_fire.png",
+    "roiFront": "1108,492,100,100",
+    "roiBack": "1108,492,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "点击挑战"
+  },
+  {
+    "itemName": "close_red",
+    "imageName": "res_close_red.png",
+    "roiFront": "1190,24,37,38",
+    "roiBack": "1190,24,37,38",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "跟buff冲突弃用"
+  },
+  {
+    "itemName": "ab_close_red",
+    "imageName": "res_ab_close_red.png",
+    "roiFront": "1194,24,38,37",
+    "roiBack": "1194,24,38,37",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "红色关闭"
+  }
+]

+ 38 - 0
tasks/AreaBoss/res/ocr.json

@@ -0,0 +1,38 @@
+[
+  {
+    "itemName": "ab_kill_best",
+    "roiFront": "942,123,157,52",
+    "roiBack": "942,123,157,52",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "击杀最多",
+    "description": "击杀最多"
+  },
+  {
+    "itemName": "ab_my_collect",
+    "roiFront": "949,124,129,53",
+    "roiBack": "949,124,129,53",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "我的收藏",
+    "description": "我的收藏"
+  },
+  {
+    "itemName": "ab_famous",
+    "roiFront": "1188,181,78,82",
+    "roiBack": "1188,181,78,82",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "热门",
+    "description": "热门"
+  },
+  {
+    "itemName": "ab_collecting",
+    "roiFront": "1163,522,88,100",
+    "roiBack": "1163,522,88,100",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "收藏",
+    "description": "收藏"
+  }
+]

BIN
tasks/AreaBoss/res/res_ab_close_red.png


+ 61 - 144
tasks/AreaBoss/script_task.py

@@ -6,13 +6,16 @@ import time
 from tasks.base_task import BaseTask
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.GameUi.game_ui import GameUi
-from tasks.GameUi.page import page_area_boss
+from tasks.GameUi.page import page_area_boss, page_shikigami_records
+from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.AreaBoss.assets import AreaBossAssets
+
 from module.logger import logger
 from module.exception import TaskEnd
+from module.atom.image import RuleImage
 
 
-class ScriptTask(GeneralBattle, GameUi, AreaBossAssets):
+class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
 
     def run(self) -> bool:
         """
@@ -21,176 +24,90 @@ class ScriptTask(GeneralBattle, GameUi, AreaBossAssets):
         """
         # 直接手动关闭这个锁定阵容的设置
         self.config.area_boss.general_battle.lock_team_enable = False
+        con = self.config.area_boss.boss
 
+        if self.config.area_boss.switch_soul.enable:
+            self.ui_get_current_page()
+            self.ui_goto(page_shikigami_records)
+            self.run_switch_soul(self.config.area_boss.switch_soul.switch_group_team)
         self.ui_get_current_page()
         self.ui_goto(page_area_boss)
 
-        # # 点击探索
-        # logger.info("Click explore")
-        # while 1:
-        #     self.screenshot()
-        #     if self.appear_then_click(self.I_EXPLORE, threshold=0.6, interval=2):
-        #         continue
-        #     if self.appear(self.I_AREA_BOSS, threshold=0.6):
-        #         break
-        #
-        # # 点击地狱鬼王
-        # logger.info("Click area boss")
-        # while 1:
-        #     self.screenshot()
-        #     if self.appear_then_click(self.I_AREA_BOSS, threshold=0.6, interval=2):
-        #         continue
-        #     if self.appear(self.I_FILTER, threshold=0.6):
-        #         break
+        if con.boss_number == 3:
+            self.boss(self.I_BATTLE_1)
+            self.boss(self.I_BATTLE_2)
+            self.boss(self.I_BATTLE_3)
+        elif con.boss_number == 2:
+            self.boss(self.I_BATTLE_1, collect=True)
+            self.boss(self.I_BATTLE_2, collect=True)
+        elif con.boss_number == 1:
+            self.boss(self.I_BATTLE_1, collect=True)
 
-        # 点击右上角的鬼王选择
-        logger.info("Click filter")
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_FILTER, threshold=0.8, interval=2):
-                continue
-            if self.appear(self.I_BATTLE_1):
-                break
+        # 退出
+        self.go_back()
+        self.set_next_run(task='AreaBoss', success=True, finish=False)
 
-        # 点击第一个鬼王
-        logger.info("Click battle 1")
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_BATTLE_1, threshold=0.8, interval=1):
-                continue
-            if self.appear(self.I_CLOSE_RED):
-                break
+        # 以抛出异常的形式结束
+        raise TaskEnd
 
-        # 点击挑战
-        logger.info("Script fire")
+    def go_back(self) -> None:
+        """
+        返回, 要求这个时候是出现在  地狱鬼王的主界面
+        :return:
+        """
+        # 点击返回
+        logger.info("Script back home")
         while 1:
             self.screenshot()
-            if self.appear_then_click(self.I_FIRE, interval=1):
+            if self.appear_then_click(self.I_BACK_BLUE, threshold=0.6, interval=2):
                 continue
-            if not self.appear(self.I_CLOSE_RED):  # 如果这个红色的关闭不见了才可以进行继续
+            if self.appear(self.I_EXPLORE, threshold=0.6):
                 break
-        logger.info("Script general battle")
-        if not self.run_general_battle(self.config.area_boss.general_battle):
-            logger.info("地狱鬼王第一只战斗失败")
 
-        # 红色关闭
-        logger.info("Script close red")
-        self.wait_until_appear(self.I_CLOSE_RED)
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_CLOSE_RED, interval=1):
-                continue
-            if self.appear(self.I_FILTER):
-                break
-        # 只挑战一只, 退出
-        if self.config.area_boss.boss.boss_number == 1:
-            self.go_back()
-            self.set_next_run(task="AreaBoss", success=True, finish=False)
-            return True
+    def boss(self, battle: RuleImage, collect: bool=False):
+        def switch_collect():
+            while 1:
+                self.screenshot()
+                if self.ocr_appear(self.O_AB_MY_COLLECT):
+                    break
+                if self.ocr_appear_click(self.O_AB_COLLECTING, interval=1):
+                    continue
 
         # 点击右上角的鬼王选择
         logger.info("Script filter")
         while 1:
             self.screenshot()
-            if self.appear_then_click(self.I_FILTER, threshold=0.8, interval=2):
-                continue
-            if self.appear(self.I_BATTLE_2):
+            if self.appear(self.I_BATTLE_1) or self.appear(self.I_BATTLE_2) or self.appear(self.I_BATTLE_3):
                 break
-
-        # 点击第2个鬼王
-        logger.info("Script area boss 2")
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_BATTLE_2, threshold=0.8, interval=1):
+            if self.appear_then_click(self.I_FILTER, interval=2):
                 continue
-            if self.appear(self.I_CLOSE_RED):
-                break
 
+        if collect:
+            switch_collect()
+        # 点击第几个鬼王
+        logger.info(f'Script area boss {battle}')
+        self.ui_click(battle, self.I_AB_CLOSE_RED)
         # 点击挑战
         logger.info("Script fire ")
         while 1:
             self.screenshot()
             if self.appear_then_click(self.I_FIRE, interval=1):
                 continue
-            if not self.appear(self.I_CLOSE_RED):  # 如果这个红色的关闭不见了才可以进行继续
+            if not self.appear(self.I_AB_CLOSE_RED):  # 如果这个红色的关闭不见了才可以进行继续
                 break
-
         if not self.run_general_battle(self.config.area_boss.general_battle):
             logger.info("地狱鬼王第2只战斗失败")
-
         # 红色关闭
         logger.info("Script close red")
-        self.wait_until_appear(self.I_CLOSE_RED)
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_CLOSE_RED, interval=1):
-                continue
-            if self.appear(self.I_FILTER):
-                break
-        # 只挑战2只, 退出
-        if self.config.area_boss.boss.boss_number == 2:
-            self.go_back()
-            self.set_next_run(task="AreaBoss", success=True, finish=False)
-            return True
-
-
-        #---------------------------------------------第三只
-        # 点击右上角的鬼王选择
-        logger.info("Script filter")
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_FILTER, threshold=0.8, interval=2):
-                continue
-            if self.appear(self.I_BATTLE_3):
-                break
-        # 点击第3个鬼王
-        logger.info("Script area boss 3")
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_BATTLE_3, threshold=0.8, interval=1):
-                continue
-            if self.appear(self.I_CLOSE_RED):
-                break
-        # 点击挑战
-        logger.info("Script fire ")
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_FIRE, interval=1):
-                continue
-            if not self.appear(self.I_CLOSE_RED):  # 如果这个红色的关闭不见了才可以进行继续
-                break
-        if not self.run_general_battle(self.config.area_boss.general_battle):
-            logger.info("地狱鬼王第2只战斗失败")
-        # 红色关闭
-        logger.info("Script close red")
-        self.wait_until_appear(self.I_CLOSE_RED)
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_CLOSE_RED, interval=1):
-                continue
-            if self.appear(self.I_FILTER):
-                break
-
-        # 退出
-        self.go_back()
-        self.set_next_run(task='AreaBoss', success=True, finish=False)
-
-        # 以抛出异常的形式结束
-        raise TaskEnd
-
-    def go_back(self) -> None:
-        """
-        返回, 要求这个时候是出现在  地狱鬼王的主界面
-        :return:
-        """
-        # 点击返回
-        logger.info("Script back home")
-        while 1:
-            self.screenshot()
-            if self.appear_then_click(self.I_BACK_BLUE, threshold=0.6, interval=2):
-                continue
-            if self.appear(self.I_EXPLORE, threshold=0.6):
-                break
-
-
-
+        self.wait_until_appear(self.I_AB_CLOSE_RED)
+        self.ui_click(self.I_AB_CLOSE_RED, self.I_FILTER)
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+    from memory_profiler import profile
+    c = Config('oas1')
+    d = Device(c)
+    t = ScriptTask(c, d)
+
+    t.run()

+ 2 - 0
tasks/Component/GeneralBattle/assets.py

@@ -107,6 +107,8 @@ class GeneralBattleAssets:
 	I_REWARD_STATISTICS = RuleImage(roi_front=(51,629,54,59), roi_back=(51,629,54,59), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_reward_statistics.png")
 	# 结算金币 
 	I_REWARD_GOLD = RuleImage(roi_front=(943,312,97,69), roi_back=(943,312,97,69), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_reward_gold.png")
+	# 针对封魔的特殊 
+	I_DE_WIN = RuleImage(roi_front=(481,47,100,100), roi_back=(331,40,301,117), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_de_win.png")
 
 
 	# Image Rule Assets

BIN
tasks/Component/GeneralBattle/gb/gb_de_win.png


+ 9 - 0
tasks/Component/GeneralBattle/gb/image.json

@@ -187,5 +187,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "结算金币"
+  },
+  {
+    "itemName": "de_win",
+    "imageName": "gb_de_win.png",
+    "roiFront": "481,47,100,100",
+    "roiBack": "331,40,301,117",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "针对封魔的特殊"
   }
 ]

+ 2 - 2
tasks/Component/GeneralBattle/general_battle.py

@@ -165,8 +165,8 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
         win: bool = False
         while 1:
             self.screenshot()
-            # 如果出现赢 就点击
-            if self.appear(self.I_WIN, threshold=0.8):
+            # 如果出现赢 就点击, 第二个是针对封魔的图片
+            if self.appear(self.I_WIN, threshold=0.8) or self.appear(self.I_DE_WIN):
                 logger.info("Battle result is win")
                 win = True
                 break

+ 2 - 2
tasks/Component/SwitchSoul/switch_soul.py

@@ -10,11 +10,11 @@ from tasks.Component.SwitchSoul.assets import SwitchSoulAssets
 from module.logger import logger
 
 
-def switch_parser(switch_str: str):
+def switch_parser(switch_str: str) -> tuple:
     switch_list = switch_str.split(',')
     if len(switch_list) != 2:
         raise ValueError('Switch_str must be 2 length')
-    return [int(switch) for switch in switch_list]
+    return int(switch_list[0]), int(switch_list[1])
 
 class SwitchSoul(BaseTask, SwitchSoulAssets):
 

+ 25 - 1
tasks/DemonEncounter/assets.py

@@ -52,7 +52,7 @@ class DemonEncounterAssets:
 
 	# Image Rule Assets
 	# 红色达摩 
-	I_DE_RED_DHARMA = RuleImage(roi_front=(1209,208,51,50), roi_back=(1209,208,51,50), threshold=0.8, method="Template matching", file="./tasks/DemonEncounter/demon/demon_de_red_dharma.png")
+	I_DE_RED_DHARMA = RuleImage(roi_front=(1216,215,32,33), roi_back=(1209,208,51,50), threshold=0.7, method="Template matching", file="./tasks/DemonEncounter/demon/demon_de_red_dharma.png")
 	# 点击右下角的寻找封魔 
 	I_DE_FIND = RuleImage(roi_front=(1136,593,100,100), roi_back=(1136,593,100,100), threshold=0.8, method="Template matching", file="./tasks/DemonEncounter/demon/demon_de_find.png")
 	# 点击首领 
@@ -82,6 +82,8 @@ class DemonEncounterAssets:
 	I_DE_AWARD = RuleImage(roi_front=(1214,210,43,41), roi_back=(1214,210,43,41), threshold=0.8, method="Template matching", file="./tasks/DemonEncounter/demon/demon_de_award.png")
 	# 信 
 	I_DE_LETTER = RuleImage(roi_front=(1236,358,33,35), roi_back=(1177,261,100,294), threshold=0.8, method="Template matching", file="./tasks/DemonEncounter/demon/demon_de_letter.png")
+	# 关闭封魔密信 
+	I_LETTER_CLOSE = RuleImage(roi_front=(851,43,45,45), roi_back=(851,43,45,45), threshold=0.8, method="Template matching", file="./tasks/DemonEncounter/demon/demon_letter_close.png")
 
 
 	# Ocr Rule Assets
@@ -89,3 +91,25 @@ class DemonEncounterAssets:
 	O_DE_COUNTER = RuleOcr(roi=(1204,685,48,34), area=(1204,685,48,34), mode="DigitCounter", method="Default", keyword="", name="de_counter")
 
 
+	# Click Rule Assets
+	# description 
+	C_ANSWER_1 = RuleClick(roi_front=(430,264,440,67), roi_back=(430,264,440,67), name="answer_1")
+	# description 
+	C_ANSWER_2 = RuleClick(roi_front=(428,351,438,70), roi_back=(428,351,438,70), name="answer_2")
+	# description 
+	C_ANSWER_3 = RuleClick(roi_front=(434,435,437,65), roi_back=(434,435,437,65), name="answer_3")
+
+
+	# Ocr Rule Assets
+	# 1/3 
+	O_LETTER_COUNT = RuleOcr(roi=(480,133,55,34), area=(480,133,55,34), mode="DigitCounter", method="Default", keyword="", name="letter_count")
+	# 问题 
+	O_LETTER_QUESTION = RuleOcr(roi=(427,164,447,100), area=(427,164,447,100), mode="Single", method="Default", keyword="", name="letter_question")
+	# 回答一 
+	O_LETTER_ANSWER_1 = RuleOcr(roi=(424,261,450,74), area=(424,261,450,74), mode="Single", method="Default", keyword="", name="letter_answer_1")
+	# 回答二 
+	O_LETTER_ANSWER_2 = RuleOcr(roi=(428,350,438,74), area=(428,350,438,74), mode="Single", method="Default", keyword="", name="letter_answer_2")
+	# 回答三 
+	O_LETTER_ANSWER_3 = RuleOcr(roi=(428,439,443,72), area=(428,439,443,72), mode="Single", method="Default", keyword="", name="letter_answer_3")
+
+

BIN
tasks/DemonEncounter/boss/boss_boss_oboroguruma.png


+ 8 - 5
tasks/DemonEncounter/data/answer.py

@@ -10,7 +10,7 @@ from pathlib import Path
 def answer_one(question: str, options: list[str]) -> int:
     """
 
-    每一个问题有四个选项, 返回选项的序号(1、2、3、4)
+    每一个问题有四个选项, 返回选项的序号(1、2、3)
     :param question:
     :param options:
     :return:
@@ -21,14 +21,17 @@ def answer_one(question: str, options: list[str]) -> int:
         next(reader)
         for row in reader:
             if row[0] == question:
-                return options.index(row[1]) + 1
-        else:
-            return 1
+                try:
+                    return options.index(row[1]) + 1
+                except ValueError:
+                    return 1
+        return 1
 
 
 if __name__ == "__main__":
     question = '以下式神中,手持折扇的是'
-    options = ['生命上限', '鬼王', '荒川之主', '鬼王']
+    options = ['生命上限', '鬼王', '荒川之主']
     start_time = datetime.now()
     print(answer_one(question, options))
     print(datetime.now() - start_time)
+    print(answer_one(question, options))

BIN
tasks/DemonEncounter/demon/demon_de_red_dharma.png


BIN
tasks/DemonEncounter/demon/demon_letter_close.png


+ 2 - 2
tasks/DemonEncounter/demon/image.json

@@ -2,10 +2,10 @@
   {
     "itemName": "de_red_dharma",
     "imageName": "demon_de_red_dharma.png",
-    "roiFront": "1209,208,51,50",
+    "roiFront": "1216,215,32,33",
     "roiBack": "1209,208,51,50",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.7,
     "description": "红色达摩"
   },
   {

+ 9 - 0
tasks/DemonEncounter/demon/image_side.json

@@ -70,5 +70,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "信"
+  },
+  {
+    "itemName": "letter_close",
+    "imageName": "demon_letter_close.png",
+    "roiFront": "851,43,45,45",
+    "roiBack": "851,43,45,45",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "关闭封魔密信"
   }
 ]

+ 20 - 0
tasks/DemonEncounter/mail/click.json

@@ -0,0 +1,20 @@
+[
+  {
+    "itemName": "answer_1",
+    "roiFront": "430,264,440,67",
+    "roiBack": "430,264,440,67",
+    "description": "description"
+  },
+  {
+    "itemName": "answer_2",
+    "roiFront": "428,351,438,70",
+    "roiBack": "428,351,438,70",
+    "description": "description"
+  },
+  {
+    "itemName": "answer_3",
+    "roiFront": "434,435,437,65",
+    "roiBack": "434,435,437,65",
+    "description": "description"
+  }
+]

+ 47 - 0
tasks/DemonEncounter/mail/ocr.json

@@ -0,0 +1,47 @@
+[
+  {
+    "itemName": "letter_count",
+    "roiFront": "480,133,55,34",
+    "roiBack": "480,133,55,34",
+    "mode": "DigitCounter",
+    "method": "Default",
+    "keyword": "",
+    "description": "1/3"
+  },
+  {
+    "itemName": "letter_question",
+    "roiFront": "427,164,447,100",
+    "roiBack": "427,164,447,100",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "问题"
+  },
+  {
+    "itemName": "letter_answer_1",
+    "roiFront": "424,261,450,74",
+    "roiBack": "424,261,450,74",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "回答一"
+  },
+  {
+    "itemName": "letter_answer_2",
+    "roiFront": "428,350,438,74",
+    "roiBack": "428,350,438,74",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "回答二"
+  },
+  {
+    "itemName": "letter_answer_3",
+    "roiFront": "428,439,443,72",
+    "roiBack": "428,439,443,72",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "回答三"
+  }
+]

+ 67 - 16
tasks/DemonEncounter/script_task.py

@@ -8,11 +8,14 @@ from cached_property import cached_property
 
 from module.logger import logger
 from module.exception import TaskEnd
+from module.base.timer import Timer
 
 from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main, page_demon_encounter
 from tasks.DemonEncounter.assets import DemonEncounterAssets
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
+from tasks.DemonEncounter.data.answer import answer_one
 
 class LanternClass(Enum):
     BATTLE = 0  # 打怪  --> 无法判断因为怪的图片不一样,用排除法
@@ -25,6 +28,8 @@ class LanternClass(Enum):
 class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets):
 
     def run(self):
+        self.ui_get_current_page()
+        self.ui_goto(page_demon_encounter)
         self.execute_lantern()
         self.execute_boss()
 
@@ -55,7 +60,7 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets):
                 continue
             if self.appear_then_click(self.I_BOSS_SONGSTRESS, interval=1):
                 continue
-            if self.appear_then_click(self.I_DE_BOSS, interval=2.5):
+            if self.appear_then_click(self.I_DE_BOSS, interval=4):
                 continue
         logger.info('Boss battle start')
         # 点击集结挑战
@@ -70,7 +75,9 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets):
             if self.appear_then_click(self.I_BOSS_FIRE, interval=1):
                 continue
         logger.info('Boss battle confirm and enter')
-        # 等待挑战
+        # 等待挑战, 5秒也是等
+        time.sleep(5)
+        self.device.stuck_record_add('BATTLE_STATUS_S')
         self.wait_until_disappear(self.I_BOSS_GATHER)
         config = self.con
         self.run_general_battle(config)
@@ -93,25 +100,35 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets):
         :return:
         """
         # 先点四次
+        ocr_timer = Timer(0.8)
+        ocr_timer.start()
         while 1:
             self.screenshot()
-            cu, re, total = self.O_DE_COUNTER.count(self.device.image)
+            if not ocr_timer.reached():
+                continue
+            else:
+                ocr_timer.reset()
+            cu, re, total = self.O_DE_COUNTER.ocr(self.device.image)
             if cu + re != total:
                 logger.warning('Lantern count error')
                 continue
             if cu == 0 and re == 4:
                 break
+
             if self.appear_then_click(self.I_DE_FIND, interval=1):
                 continue
+        logger.info('Lantern count success')
         # 然后领取红色达摩
-        self.ui_get_reward(self.I_DE_RED_DHARMA)
+        self.screenshot()
+        if not self.appear(self.I_DE_AWARD):
+            self.ui_get_reward(self.I_DE_RED_DHARMA)
         self.wait_until_appear(self.I_DE_AWARD)
         # 然后到四个灯笼
         match_click = {
             1: self.C_DE_1,
-            2: self.C_DE_1,
-            3: self.C_DE_1,
-            4: self.C_DE_1,
+            2: self.C_DE_2,
+            3: self.C_DE_3,
+            4: self.C_DE_4,
         }
         for i in range(1, 5):
             logger.hr(f'Check lantern {i}', 3)
@@ -120,13 +137,13 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets):
                 case LanternClass.BOX:
                     self._box()
                 case LanternClass.MAIL:
-                    self._mail()
+                    self._mail(match_click[i])
                 case LanternClass.REALM:
-                    self._realm()
+                    self._realm(match_click[i])
                 case LanternClass.EMPTY:
                     logger.warning(f'Lantern {i} is empty')
                 case LanternClass.BATTLE:
-                    self._battle()
+                    self._battle(match_click[i])
             time.sleep(1)
 
     @cached_property
@@ -177,9 +194,43 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets):
         # 宝箱不领
         pass
 
-    def _mail(self):
+    def _mail(self, target_click):
         # 答题,还没有碰到过答题的
-        pass
+        def answer():
+            click_match = {
+                1: self.C_ANSWER_1,
+                2: self.C_ANSWER_2,
+                3: self.C_ANSWER_3,
+            }
+            index = None
+            self.screenshot()
+            question = self.O_LETTER_QUESTION.detect_text(self.device.image)
+            question = question.replace('?', '').replace('?', '')
+            answer_1 = self.O_LETTER_ANSWER_1.detect_text(self.device.image)
+            answer_2 = self.O_LETTER_ANSWER_2.detect_text(self.device.image)
+            answer_3 = self.O_LETTER_ANSWER_3.detect_text(self.device.image)
+            if answer_1 == '其余选项皆对':
+                index = 1
+            elif answer_2 == '其余选项皆对':
+                index = 2
+            elif answer_3 == '其余选项皆对':
+                index = 3
+            if not index:
+                index = answer_one(question=question, options=[answer_1, answer_2, answer_3])
+            logger.info(f'Question: {question}, Answer: {index}')
+            return click_match[index]
+
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_LETTER_CLOSE):
+                break
+            if self.click(target_click, interval=1):
+                continue
+        logger.info('Question answering Start')
+        for i in range(1,4):
+            logger.hr(f'Answer {i}', 3)
+            self.ui_get_reward(answer())
+            time.sleep(0.5)
 
     def _battle(self, target_click):
         config = self.con
@@ -188,14 +239,14 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets):
             if not self.appear(self.I_DE_LOCATION):
                 logger.info('Battle Start')
                 break
-            if self.click(target_click, interval=target_click):
+            if self.click(target_click, interval=1):
                 continue
         if self.run_general_battle(config):
             logger.info('Battle End')
 
-    def _realm(self):
+    def _realm(self, target_click):
         # 结界
-        pass
+        self._battle(target_click)
 
 
 if __name__ == '__main__':
@@ -207,4 +258,4 @@ if __name__ == '__main__':
     d = Device(c)
     t = ScriptTask(c, d)
 
-    t.run()
+    t.execute_lantern()

+ 1 - 1
tasks/GameUi/assets.py

@@ -96,7 +96,7 @@ class GameUiAssets:
 	# description 
 	I_TOWN_GOTO_DUEL = RuleImage(roi_front=(756,142,48,68), roi_back=(357,126,657,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_town_goto_duel.png")
 	# description 
-	I_TOWN_GOTO_DEMON_ENCOUNTER = RuleImage(roi_front=(617,135,51,75), roi_back=(232,121,873,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_town_goto_demon_encounter.png")
+	I_TOWN_GOTO_DEMON_ENCOUNTER = RuleImage(roi_front=(617,135,51,75), roi_back=(232,121,873,100), threshold=0.7, method="Template matching", file="./tasks/GameUi/page/page_town_goto_demon_encounter.png")
 	# description 
 	I_TOWN_GOTO_HUNT = RuleImage(roi_front=(475,138,46,69), roi_back=(275,122,520,100), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_town_goto_hunt.png")
 	# 协同对弈 

+ 1 - 1
tasks/GameUi/page/page_img_2.json

@@ -41,7 +41,7 @@
     "roiFront": "617,135,51,75",
     "roiBack": "232,121,873,100",
     "method": "Template matching",
-    "threshold": 0.8,
+    "threshold": 0.7,
     "description": "description"
   },
   {

+ 10 - 3
tasks/Nian/script_task.py

@@ -73,12 +73,19 @@ class ScriptTask(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, NianAssets):
                 if self.wait_battle(wait_time=time(minute=1)):
                     buff = []
                     if con.buff_gold_50_click:
-                        buff.append(BuffClass.gold_50)
+                        buff.append(BuffClass.GOLD_50)
                     if con.buff_gold_100_click:
-                        buff.append(BuffClass.gold_100)
+                        buff.append(BuffClass.GOLD_100)
                     if buff is []:
                         buff = None
-                    self.run_general_battle(config=self.config.orochi.general_battle_config, buff=buff)
+                    self.run_general_battle(config=self.battle_config, buff=buff)
+                    # 打完后返回庭院,记得关闭buff
+                    self.open_buff()
+                    if con.buff_gold_50_click:
+                        self.gold_50(False)
+                    if con.buff_gold_100_click:
+                        self.gold_100(False)
+                    self.close_buff()
                     break
                 else:
                     break

+ 6 - 0
tasks/Sougenbi/assets.py

@@ -36,6 +36,12 @@ class SougenbiAssets:
 	I_S_FIRE = RuleImage(roi_front=(1105,585,100,100), roi_back=(1105,585,100,100), threshold=0.7, method="Template matching", file="./tasks/Sougenbi/s/s_s_fire.png")
 	# 确认进入业原火 
 	I_S_CHECK_SOUGENBI = RuleImage(roi_front=(772,222,307,292), roi_back=(772,222,307,292), threshold=0.8, method="Template matching", file="./tasks/Sougenbi/s/s_s_check_sougenbi.png")
+	# 贪 
+	I_S_FIRE_GREED = RuleImage(roi_front=(1133,641,21,33), roi_back=(1133,641,21,33), threshold=0.8, method="Template matching", file="./tasks/Sougenbi/s/s_s_fire_greed.png")
+	# description 
+	I_S_FIRE_ANGER = RuleImage(roi_front=(1132,643,21,30), roi_back=(1132,643,21,30), threshold=0.8, method="Template matching", file="./tasks/Sougenbi/s/s_s_fire_anger.png")
+	# 痴 
+	I_S_FIRE_FOOLERY = RuleImage(roi_front=(1130,642,22,31), roi_back=(1130,642,22,31), threshold=0.8, method="Template matching", file="./tasks/Sougenbi/s/s_s_fire_foolery.png")
 
 
 	# Ocr Rule Assets

+ 27 - 0
tasks/Sougenbi/s/image.json

@@ -70,5 +70,32 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "确认进入业原火"
+  },
+  {
+    "itemName": "s_fire_greed",
+    "imageName": "s_s_fire_greed.png",
+    "roiFront": "1133,641,21,33",
+    "roiBack": "1133,641,21,33",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "贪"
+  },
+  {
+    "itemName": "s_fire_anger",
+    "imageName": "s_s_fire_anger.png",
+    "roiFront": "1132,643,21,30",
+    "roiBack": "1132,643,21,30",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_fire_foolery",
+    "imageName": "s_s_fire_foolery.png",
+    "roiFront": "1130,642,22,31",
+    "roiBack": "1130,642,22,31",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "痴"
   }
 ]

BIN
tasks/Sougenbi/s/s_s_fire_anger.png


BIN
tasks/Sougenbi/s/s_s_fire_foolery.png


BIN
tasks/Sougenbi/s/s_s_fire_greed.png


+ 5 - 5
tasks/Sougenbi/script_task.py

@@ -40,15 +40,15 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, SougenbiAssets):
         number_target = None
         match con.sougenbi_config.sougenbi_class:
             case SougenbiClass.GREED:
-                image_target = self.I_S_GREED
+                image_target = self.I_S_FIRE_GREED
                 click_target = self.C_C_GREED
                 number_target = self.O_S_GREED
             case SougenbiClass.Anger:
-                image_target = self.I_S_ANGER
+                image_target = self.I_S_FIRE_ANGER
                 click_target = self.C_C_ANGER
                 number_target = self.O_S_ANGER
             case SougenbiClass.Foolery:
-                image_target = self.I_S_FOOLERY
+                image_target = self.I_S_FIRE_FOOLERY
                 click_target = self.C_C_FOOLERY
                 number_target = self.O_S_FOOLERY
             case _:
@@ -56,10 +56,10 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, SougenbiAssets):
         self.check_lock(con.general_battle_config.lock_team_enable, self.I_S_TEAM_LOCK, self.I_S_TEAM_UNLOCK)
         while 1:
             self.screenshot()
+            if self.appear(image_target):
+                break
             if self.click(click_target, interval=0.5):
                 pass
-            if self.appear(image_target, threshold=0.97):
-                break
 
         # 开始循环
         while 1:

+ 4 - 1
tasks/base_task.py

@@ -441,7 +441,7 @@ class BaseTask(GlobalGameAssets):
             self.screenshot()
         return self.appear_then_click(self.I_UI_REWARD, action=self.C_UI_REWARD, interval=0.4, threshold=0.6)
 
-    def ui_get_reward(self, click_image: RuleImage or RuleOcr):
+    def ui_get_reward(self, click_image: RuleImage or RuleOcr or RuleClick):
         """
         传进来一个点击图片 或是 一个ocr, 会点击这个图片,然后等待‘获得奖励’,
         最后当获得奖励消失后 退出
@@ -471,6 +471,9 @@ class BaseTask(GlobalGameAssets):
             elif isinstance(click_image, RuleOcr):
                 if self.ocr_appear_click(click_image, interval=1):
                     continue
+            elif isinstance(click_image, RuleClick):
+                if self.click(click_image, interval=1):
+                    continue
 
         return True