Эх сурвалжийг харах

feat(KekkaiActivation): 结界挂卡根据每小时收益进行选择

ljxun 1 жил өмнө
parent
commit
5eb72d8763

BIN
tasks/KekkaiActivation/a/a_a_card_fish.png


BIN
tasks/KekkaiActivation/a/a_a_card_kaiko.png


BIN
tasks/KekkaiActivation/a/a_a_harvest_oboroguruma.png


+ 11 - 20
tasks/KekkaiActivation/a/image.json

@@ -3,7 +3,7 @@
     "itemName": "a_harvest_fish4",
     "itemName": "a_harvest_fish4",
     "imageName": "a_a_harvest_fish4.png",
     "imageName": "a_a_harvest_fish4.png",
     "roiFront": "897,159,48,40",
     "roiFront": "897,159,48,40",
-    "roiBack": "872,128,154,174",
+    "roiBack": "872,128,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "斗鱼收获奖励4星"
     "description": "斗鱼收获奖励4星"
@@ -38,8 +38,8 @@
   {
   {
     "itemName": "a_card_kaiko",
     "itemName": "a_card_kaiko",
     "imageName": "a_a_card_kaiko.png",
     "imageName": "a_a_card_kaiko.png",
-    "roiFront": "355,237,169,62",
-    "roiBack": "355,237,169,62",
+    "roiFront": "392,251,112,38",
+    "roiBack": "392,251,112,38",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.9,
     "threshold": 0.9,
     "description": "description"
     "description": "description"
@@ -47,8 +47,8 @@
   {
   {
     "itemName": "a_card_fish",
     "itemName": "a_card_fish",
     "imageName": "a_a_card_fish.png",
     "imageName": "a_a_card_fish.png",
-    "roiFront": "352,303,173,62",
-    "roiBack": "352,303,173,62",
+    "roiFront": "388,318,118,37",
+    "roiBack": "388,318,118,37",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.9,
     "threshold": 0.9,
     "description": "description"
     "description": "description"
@@ -156,7 +156,7 @@
     "itemName": "a_harvest_kaiko_4",
     "itemName": "a_harvest_kaiko_4",
     "imageName": "a_a_harvest_kaiko_4.png",
     "imageName": "a_a_harvest_kaiko_4.png",
     "roiFront": "894,164,48,41",
     "roiFront": "894,164,48,41",
-    "roiBack": "867,132,154,174",
+    "roiBack": "867,132,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "太鼓4"
     "description": "太鼓4"
@@ -165,7 +165,7 @@
     "itemName": "a_harvest_kaiko_3",
     "itemName": "a_harvest_kaiko_3",
     "imageName": "a_a_harvest_kaiko_3.png",
     "imageName": "a_a_harvest_kaiko_3.png",
     "roiFront": "893,163,47,42",
     "roiFront": "893,163,47,42",
-    "roiBack": "865,136,154,174",
+    "roiBack": "865,136,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"
@@ -174,7 +174,7 @@
     "itemName": "a_harvest_kaiko_6",
     "itemName": "a_harvest_kaiko_6",
     "imageName": "a_a_harvest_kaiko_6.png",
     "imageName": "a_a_harvest_kaiko_6.png",
     "roiFront": "898,160,45,38",
     "roiFront": "898,160,45,38",
-    "roiBack": "868,129,154,174",
+    "roiBack": "868,129,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.7,
     "threshold": 0.7,
     "description": "太鼓6"
     "description": "太鼓6"
@@ -183,7 +183,7 @@
     "itemName": "a_harvest_fish_6",
     "itemName": "a_harvest_fish_6",
     "imageName": "a_a_harvest_fish_6.png",
     "imageName": "a_a_harvest_fish_6.png",
     "roiFront": "898,159,45,38",
     "roiFront": "898,159,45,38",
-    "roiBack": "869,131,154,174",
+    "roiBack": "869,131,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.7,
     "threshold": 0.7,
     "description": "斗鱼6"
     "description": "斗鱼6"
@@ -192,7 +192,7 @@
     "itemName": "a_harvest_moon_3",
     "itemName": "a_harvest_moon_3",
     "imageName": "a_a_harvest_moon_3.png",
     "imageName": "a_a_harvest_moon_3.png",
     "roiFront": "897,159,46,40",
     "roiFront": "897,159,46,40",
-    "roiBack": "869,127,154,174",
+    "roiBack": "869,127,100,100",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.7,
     "threshold": 0.7,
     "description": "太阴3"
     "description": "太阴3"
@@ -210,18 +210,9 @@
     "itemName": "a_harvest_fish_3",
     "itemName": "a_harvest_fish_3",
     "imageName": "a_a_harvest_fish_3.png",
     "imageName": "a_a_harvest_fish_3.png",
     "roiFront": "891,165,57,39",
     "roiFront": "891,165,57,39",
-    "roiBack": "854,128,154,174",
+    "roiBack": "854,128,132,124",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "斗鱼3"
     "description": "斗鱼3"
-  },
-  {
-    "itemName": "a_harvest_oboroguruma",
-    "imageName": "a_a_harvest_oboroguruma.png",
-    "roiFront": "891,165,57,39",
-    "roiBack": "854,128,154,174",
-    "method": "Template matching",
-    "threshold": 0.8,
-    "description": "胧车 "
   }
   }
 ]
 ]

+ 13 - 13
tasks/KekkaiActivation/assets.py

@@ -20,6 +20,8 @@ class KekkaiActivationAssets:
 	# Ocr Rule Assets
 	# Ocr Rule Assets
 	# 这张卡一共有多少小时 
 	# 这张卡一共有多少小时 
 	O_CARD_ALL_TIME = RuleOcr(roi=(926,262,95,31), area=(926,262,95,31), mode="Duration", method="Default", keyword="", name="card_all_time")
 	O_CARD_ALL_TIME = RuleOcr(roi=(926,262,95,31), area=(926,262,95,31), mode="Duration", method="Default", keyword="", name="card_all_time")
+	# 识别结界卡每小时收益 
+	O_CHECK_CARD_NUMBER = RuleOcr(roi=(305,153,107,481), area=(305,153,107,481), mode="Single", method="Default", keyword="", name="check_card_number")
 
 
 
 
 	# Swipe Rule Assets
 	# Swipe Rule Assets
@@ -29,7 +31,7 @@ class KekkaiActivationAssets:
 
 
 	# Image Rule Assets
 	# Image Rule Assets
 	# 斗鱼收获奖励4星 
 	# 斗鱼收获奖励4星 
-	I_A_HARVEST_FISH4 = RuleImage(roi_front=(897,159,48,40), roi_back=(872,128,154,174), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish4.png")
+	I_A_HARVEST_FISH4 = RuleImage(roi_front=(897,159,48,40), roi_back=(872,128,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish4.png")
 	# 一般的收获奖励 
 	# 一般的收获奖励 
 	I_A_HARVEST_EXP = RuleImage(roi_front=(891,153,49,43), roi_back=(865,121,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_exp.png")
 	I_A_HARVEST_EXP = RuleImage(roi_front=(891,153,49,43), roi_back=(865,121,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_exp.png")
 	# "结界卡" 
 	# "结界卡" 
@@ -37,9 +39,9 @@ class KekkaiActivationAssets:
 	# description 
 	# description 
 	I_A_CARD_ALL = RuleImage(roi_front=(357,175,167,59), roi_back=(357,175,167,59), threshold=0.9, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_card_all.png")
 	I_A_CARD_ALL = RuleImage(roi_front=(357,175,167,59), roi_back=(357,175,167,59), threshold=0.9, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_card_all.png")
 	# description 
 	# description 
-	I_A_CARD_KAIKO = RuleImage(roi_front=(355,237,169,62), roi_back=(355,237,169,62), threshold=0.9, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_card_kaiko.png")
+	I_A_CARD_KAIKO = RuleImage(roi_front=(392,251,112,38), roi_back=(392,251,112,38), threshold=0.9, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_card_kaiko.png")
 	# description 
 	# description 
-	I_A_CARD_FISH = RuleImage(roi_front=(352,303,173,62), roi_back=(352,303,173,62), threshold=0.9, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_card_fish.png")
+	I_A_CARD_FISH = RuleImage(roi_front=(388,318,118,37), roi_back=(388,318,118,37), threshold=0.9, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_card_fish.png")
 	# description 
 	# description 
 	I_A_CARD_ROOM = RuleImage(roi_front=(355,370,167,59), roi_back=(355,370,167,59), threshold=0.9, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_card_room.png")
 	I_A_CARD_ROOM = RuleImage(roi_front=(355,370,167,59), roi_back=(355,370,167,59), threshold=0.9, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_card_room.png")
 	# description 
 	# description 
@@ -63,21 +65,19 @@ class KekkaiActivationAssets:
 	# description 
 	# description 
 	I_A_CHECK_CARD = RuleImage(roi_front=(513,32,260,49), roi_back=(513,32,260,49), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_check_card.png")
 	I_A_CHECK_CARD = RuleImage(roi_front=(513,32,260,49), roi_back=(513,32,260,49), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_check_card.png")
 	# 太鼓4 
 	# 太鼓4 
-	I_A_HARVEST_KAIKO_4 = RuleImage(roi_front=(894,164,48,41), roi_back=(867,132,154,174), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_4.png")
+	I_A_HARVEST_KAIKO_4 = RuleImage(roi_front=(894,164,48,41), roi_back=(867,132,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_4.png")
 	# description 
 	# description 
-	I_A_HARVEST_KAIKO_3 = RuleImage(roi_front=(893,163,47,42), roi_back=(865,136,154,174), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_3.png")
+	I_A_HARVEST_KAIKO_3 = RuleImage(roi_front=(893,163,47,42), roi_back=(865,136,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_3.png")
 	# 太鼓6 
 	# 太鼓6 
-	I_A_HARVEST_KAIKO_6 = RuleImage(roi_front=(898,160,45,38), roi_back=(868,129,154,174), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_6.png")
+	I_A_HARVEST_KAIKO_6 = RuleImage(roi_front=(898,160,45,38), roi_back=(868,129,100,100), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_kaiko_6.png")
 	# 斗鱼6 
 	# 斗鱼6 
-	I_A_HARVEST_FISH_6 = RuleImage(roi_front=(898,159,45,38), roi_back=(869,131,154,174), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_6.png")
+	I_A_HARVEST_FISH_6 = RuleImage(roi_front=(898,159,45,38), roi_back=(869,131,100,100), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_6.png")
 	# 太阴3 
 	# 太阴3 
-	I_A_HARVEST_MOON_3 = RuleImage(roi_front=(897,159,46,40), roi_back=(869,127,154,174), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_moon_3.png")
+	I_A_HARVEST_MOON_3 = RuleImage(roi_front=(897,159,46,40), roi_back=(869,127,100,100), threshold=0.7, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_moon_3.png")
 	# 卸下 
 	# 卸下 
 	I_A_DEMOUNT = RuleImage(roi_front=(939,575,55,47), roi_back=(903,551,107,91), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_demount.png")
 	I_A_DEMOUNT = RuleImage(roi_front=(939,575,55,47), roi_back=(903,551,107,91), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_demount.png")
 	# 斗鱼3 
 	# 斗鱼3 
-	I_A_HARVEST_FISH_3 = RuleImage(roi_front=(891,165,57,39), roi_back=(854,128,154,174), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_3.png")
-	# 胧车  
-	I_A_HARVEST_OBOROGURUMA = RuleImage(roi_front=(891,165,57,39), roi_back=(854,128,154,174), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_oboroguruma.png")
+	I_A_HARVEST_FISH_3 = RuleImage(roi_front=(891,165,57,39), roi_back=(854,128,132,124), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/a/a_a_harvest_fish_3.png")
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets
@@ -91,9 +91,9 @@ class KekkaiActivationAssets:
 	# description 
 	# description 
 	I_CARDS_KAIKO_5 = RuleImage(roi_front=(191,345,88,58), roi_back=(172,162,126,488), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_kaiko_5.png")
 	I_CARDS_KAIKO_5 = RuleImage(roi_front=(191,345,88,58), roi_back=(172,162,126,488), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_kaiko_5.png")
 	# description 
 	# description 
-	I_CARDS_KAIKO_4 = RuleImage(roi_front=(190,255,90,22), roi_back=(179,165,116,482), threshold=0.85, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_kaiko_4.png")
+	I_CARDS_KAIKO_4 = RuleImage(roi_front=(192,354,90,22), roi_back=(179,165,116,482), threshold=0.85, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_kaiko_4.png")
 	# description 
 	# description 
-	I_CARDS_KAIKO_3 = RuleImage(roi_front=(191,351,89,66), roi_back=(183,169,109,474), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_kaiko_3.png")
+	I_CARDS_KAIKO_3 = RuleImage(roi_front=(192,187,89,66), roi_back=(183,169,109,474), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_kaiko_3.png")
 	# description 
 	# description 
 	I_CARDS_FISH_6 = RuleImage(roi_front=(193,183,87,91), roi_back=(178,169,110,474), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_fish_6.png")
 	I_CARDS_FISH_6 = RuleImage(roi_front=(193,183,87,91), roi_back=(178,169,110,474), threshold=0.8, method="Template matching", file="./tasks/KekkaiActivation/cards/cards_cards_fish_6.png")
 	# description 
 	# description 

BIN
tasks/KekkaiActivation/cards/cards_cards_kaiko_3.png


BIN
tasks/KekkaiActivation/cards/cards_cards_kaiko_4.png


+ 2 - 2
tasks/KekkaiActivation/cards/image.json

@@ -20,7 +20,7 @@
   {
   {
     "itemName": "cards_kaiko_4",
     "itemName": "cards_kaiko_4",
     "imageName": "cards_cards_kaiko_4.png",
     "imageName": "cards_cards_kaiko_4.png",
-    "roiFront": "190,255,90,22",
+    "roiFront": "192,354,90,22",
     "roiBack": "179,165,116,482",
     "roiBack": "179,165,116,482",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.85,
     "threshold": 0.85,
@@ -29,7 +29,7 @@
   {
   {
     "itemName": "cards_kaiko_3",
     "itemName": "cards_kaiko_3",
     "imageName": "cards_cards_kaiko_3.png",
     "imageName": "cards_cards_kaiko_3.png",
-    "roiFront": "191,351,89,66",
+    "roiFront": "192,187,89,66",
     "roiBack": "183,169,109,474",
     "roiBack": "183,169,109,474",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,

+ 14 - 11
tasks/KekkaiActivation/config.py

@@ -1,31 +1,34 @@
 # 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
-from pydantic import BaseModel, Field
 from enum import Enum
 from enum import Enum
-from datetime import datetime, time
-
-from tasks.Component.config_base import MultiLine
-
-from tasks.Component.config_scheduler import Scheduler
+from pydantic import BaseModel, Field
 from tasks.Component.config_base import ConfigBase, TimeDelta
 from tasks.Component.config_base import ConfigBase, TimeDelta
+from tasks.Component.config_scheduler import Scheduler
 from tasks.Utils.config_enum import ShikigamiClass
 from tasks.Utils.config_enum import ShikigamiClass
 
 
+
+class CardType(str, Enum):
+    FISH = '斗鱼'
+    TAIKO = '太鼓'
+    
+
 class ActivationScheduler(Scheduler):
 class ActivationScheduler(Scheduler):
-    priority: int = Field(default=2, description='priority_help')
+    priority = Field(default=2, description='priority_help')
     success_interval: TimeDelta = Field(default=TimeDelta(days=1), description='success_interval_help')
     success_interval: TimeDelta = Field(default=TimeDelta(days=1), description='success_interval_help')
     failure_interval: TimeDelta = Field(default=TimeDelta(hours=10), description='failure_interval_help')
     failure_interval: TimeDelta = Field(default=TimeDelta(hours=10), description='failure_interval_help')
 
 
+
 class ActivationConfig(BaseModel):
 class ActivationConfig(BaseModel):
-    card_rule: MultiLine = Field(default='auto', description='card_rule_help')
+    card_type: CardType = Field(default=CardType.TAIKO, description='card_rule_help')
+    min_taiko_num: int = Field(default=8, description='挂卡太鼓每小时最少收益,低于则不挂卡')
+    min_fish_num: int = Field(default=16, description='挂卡斗鱼每小时最少收益,低于则不挂卡')
     exchange_before: bool = Field(default=True, description='exchange_before_help')
     exchange_before: bool = Field(default=True, description='exchange_before_help')
     exchange_max: bool = Field(default=True, description='exchange_max_help')
     exchange_max: bool = Field(default=True, description='exchange_max_help')
-    exchange_smart: bool = Field(default=False, description='是否启用智能放入')
     shikigami_class: ShikigamiClass = Field(default=ShikigamiClass.N, description='shikigami_class_help')
     shikigami_class: ShikigamiClass = Field(default=ShikigamiClass.N, description='shikigami_class_help')
-
+    card_not_found_count: int = Field(default=0, description='未发现卡次数')
 
 
 
 
 class KekkaiActivation(ConfigBase):
 class KekkaiActivation(ConfigBase):
     scheduler: ActivationScheduler = Field(default_factory=ActivationScheduler)
     scheduler: ActivationScheduler = Field(default_factory=ActivationScheduler)
     activation_config: ActivationConfig = Field(default_factory=ActivationConfig)
     activation_config: ActivationConfig = Field(default_factory=ActivationConfig)
-

+ 9 - 0
tasks/KekkaiActivation/ocr.json

@@ -7,5 +7,14 @@
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",
     "description": "这张卡一共有多少小时"
     "description": "这张卡一共有多少小时"
+  },
+  {
+    "itemName": "check_card_number",
+    "roiFront": "305,153,107,481",
+    "roiBack": "305,153,107,481",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "识别结界卡每小时收益"
   }
   }
 ]
 ]

+ 138 - 134
tasks/KekkaiActivation/script_task.py

@@ -3,12 +3,16 @@
 # github https://github.com/runhey
 # github https://github.com/runhey
 import time
 import time
 
 
+import random
+import re
 from cached_property import cached_property
 from cached_property import cached_property
 from datetime import datetime, timedelta
 from datetime import datetime, timedelta
+from module.atom.click import RuleClick
 
 
 from module.base.timer import Timer
 from module.base.timer import Timer
 from module.atom.image_grid import ImageGrid
 from module.atom.image_grid import ImageGrid
 from module.atom.image import RuleImage
 from module.atom.image import RuleImage
+from module.base.utils import point2str
 from module.logger import logger
 from module.logger import logger
 from module.exception import TaskEnd, GameStuckError
 from module.exception import TaskEnd, GameStuckError
 
 
@@ -19,20 +23,27 @@ from tasks.KekkaiActivation.utils import parse_rule
 from tasks.KekkaiActivation.config import ActivationConfig
 from tasks.KekkaiActivation.config import ActivationConfig
 from tasks.Utils.config_enum import ShikigamiClass
 from tasks.Utils.config_enum import ShikigamiClass
 from tasks.GameUi.page import page_main, page_guild
 from tasks.GameUi.page import page_main, page_guild
+from tasks.KekkaiActivation.config import CardType
 
 
-
+""" 结界挂卡 """
 class ScriptTask(KU, KekkaiActivationAssets):
 class ScriptTask(KU, KekkaiActivationAssets):
 
 
     def run(self):
     def run(self):
         con = self.config.kekkai_activation.activation_config
         con = self.config.kekkai_activation.activation_config
         self.ui_get_current_page()
         self.ui_get_current_page()
         self.ui_goto(page_guild)
         self.ui_goto(page_guild)
+
+        # 在寮的主界面 检查是否有收取体力或者是收取寮资金
+        # self.check_guild_ap_or_assets()
+
         # 进入寮结界
         # 进入寮结界
         self.goto_realm()
         self.goto_realm()
+
         if con.exchange_before:
         if con.exchange_before:
-            self.check_max_lv(con)
+            self.check_max_lv(con.shikigami_class)
+        # 收取经验
         self.harvest_card()
         self.harvest_card()
-
+        # 开始挂卡
         self.run_activation(con)
         self.run_activation(con)
         while 1:
         while 1:
             # 关闭到结界界面
             # 关闭到结界界面
@@ -45,8 +56,10 @@ class ScriptTask(KU, KekkaiActivationAssets):
                 continue
                 continue
 
 
         if con.exchange_max:
         if con.exchange_max:
-            self.check_max_lv(con)
-        self.back_guild()
+            self.check_max_lv(con.shikigami_class)
+        # self.back_guild()
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
 
 
         raise TaskEnd('KekkaiActivation')
         raise TaskEnd('KekkaiActivation')
 
 
@@ -74,16 +87,16 @@ class ScriptTask(KU, KekkaiActivationAssets):
     def dict_image_card(self) -> dict:
     def dict_image_card(self) -> dict:
         return {v: k for k, v in self.dict_card_image.items()}
         return {v: k for k, v in self.dict_card_image.items()}
 
 
-    @cached_property
-    def order_cards(self) -> list[CardClass]:
-        # 重写
-        config = self.config.kekkai_activation.activation_config.card_rule
-        return parse_rule(config)
-
     @cached_property
     @cached_property
     def order_targets(self) -> ImageGrid:
     def order_targets(self) -> ImageGrid:
-        # 重写
-        return ImageGrid([self.dict_card_image[card] for card in self.order_cards])
+        rule = self.config.kekkai_activation.activation_config.card_type
+        if rule == CardType.TAIKO:
+            return ImageGrid([self.I_CARDS_KAIKO_6, self.I_CARDS_KAIKO_5])
+        elif rule == CardType.FISH:
+            return ImageGrid([self.I_CARDS_FISH_6, self.I_CARDS_FISH_5])
+        else:
+            logger.error('Unknown utilize rule')
+            raise ValueError('Unknown utilize rule')
 
 
     def run_activation(self, _config: ActivationConfig) -> bool:
     def run_activation(self, _config: ActivationConfig) -> bool:
         """
         """
@@ -135,12 +148,7 @@ class ScriptTask(KU, KekkaiActivationAssets):
             # 如果是什么都没有,那就是可以开始挂卡了
             # 如果是什么都没有,那就是可以开始挂卡了
             if not card_status and not card_effect:
             if not card_status and not card_effect:
                 logger.info('Card is not selected also not using')
                 logger.info('Card is not selected also not using')
-                self.screening_card(_config.card_rule)
-
-
-
-
-
+                self.screening_card(_config.card_type)
 
 
     def goto_cards(self):
     def goto_cards(self):
         """
         """
@@ -189,7 +197,6 @@ class ScriptTask(KU, KekkaiActivationAssets):
                 return False
                 return False
             elif self.appear(self.I_A_ACTIVATE_GRAY):
             elif self.appear(self.I_A_ACTIVATE_GRAY):
                 return False
                 return False
-        return False
 
 
     def ocr_time(self, screenshot=False) -> timedelta or None:
     def ocr_time(self, screenshot=False) -> timedelta or None:
         if screenshot:
         if screenshot:
@@ -210,35 +217,15 @@ class ScriptTask(KU, KekkaiActivationAssets):
         :return:
         :return:
         """
         """
 
 
-        def run_auto():
-            while 1:
-                self.screenshot()
-                if not self.appear(self.I_A_EMPTY) and self.appear(self.I_A_ACTIVATE_YELLOW, threshold=0.9):
-                    break
-                if self.click(self.C_A_SELECT_AUTO, interval=1):
-                    continue
-
-        if rule == "auto":
-            logger.info('Auto select card')
-            run_auto()
-            return
-
-        card_class = None
-        target_class = None
-        top_card = self.order_cards[0]
-        if top_card.startswith(CardClass.TAIKO):  # 太鼓
+        if rule == CardType.TAIKO:
             card_class = CardClass.TAIKO
             card_class = CardClass.TAIKO
             target_class = self.I_A_CARD_KAIKO
             target_class = self.I_A_CARD_KAIKO
-        elif top_card.startswith(CardClass.MOON):  # 太阴
-            card_class = CardClass.MOON
-            target_class = self.I_A_CARD_MOON
-        elif top_card.startswith(CardClass.FISH):  # 斗鱼
+        elif rule == CardType.FISH:
             card_class = CardClass.FISH
             card_class = CardClass.FISH
             target_class = self.I_A_CARD_FISH
             target_class = self.I_A_CARD_FISH
-
-        if card_class is None:
-            logger.warning('Unknown card class')
-            run_auto()
+        else:
+            logger.warning('Unknown card rule')
+            self.push_notify(content='Unknown card rule')
             return
             return
 
 
         while 1:
         while 1:
@@ -260,108 +247,129 @@ class ScriptTask(KU, KekkaiActivationAssets):
                 continue
                 continue
         logger.info('Selected card class: {}'.format(card_class))
         logger.info('Selected card class: {}'.format(card_class))
 
 
-        # 得了开始一直往下滑动 找最优卡
-        card_best = None
-        swipe_count = 0
+        # 找最优卡
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
-            current_best = self._current_select_best(card_best)
-            if current_best is None:
-                logger.warning('There is no card in the list')
-                break
-            # Record best card for future comparison
-            if(card_best is None):
-                card_best = current_best
-            elif self.order_cards.index(current_best) <= self.order_cards.index(card_best):
-                break
-            if current_best == self.order_cards[0]:
-                break
-            # 为什么找到第二个最优解也是会退出呢???
-            # 这个是因为一般是从高星到低星来找, 基本上第二个最优解就是最优解了
-            elif current_best == self.order_cards[1]:
-                break
+            target = self.check_card_num()
+            if target is None:
+                # 未发现卡,处理逻辑
+                self._card_not_found()
+            if self.appear(self.I_A_EMPTY):
+                while 1:
+                    self.screenshot()
+                    if not self.appear(self.I_A_EMPTY):
+                        self.config.kekkai_activation.activation_config.card_not_found_count = 0
+                        self.config.save()
+                        message = f'✅ 确认挂卡: {rule}'
+                        self.save_image(content=message, push_flag=False, wait_time=0)
+                        return
+                    if self.click(target, interval=1):
+                        continue
 
 
-            # 滑到底就退出
-            if self.appear(self.I_AA_SWIPE_BLOCK):
-                logger.warning('Swipe to the end but no card is found')
-                break
-            # 超过十次就退出
-            if swipe_count > 15:
-                logger.warning('Swipe count is more than 10')
-                break
-            # 一直向下滑动
-            self.swipe(self.S_CARDS_SWIPE, interval=0.9)
-            swipe_count += 1
-            time.sleep(2)
+    def check_card_num(self):
+        rule = self.config.kekkai_activation.activation_config.card_type
+        if rule == CardType.TAIKO:
+            min_card_num = self.config.kekkai_activation.activation_config.min_taiko_num
+            check_card = "勾玉"
+        elif rule == CardType.FISH:
+            min_card_num = self.config.kekkai_activation.activation_config.min_fish_num
+            check_card = "体力"
+        else:
+            logger.error('Unknown utilize rule')
+            raise ValueError('Unknown utilize rule')
 
 
-    def _image_convert_card(self, target: RuleImage) -> CardClass:
-        """
-        就是把一张图转化 到某个具体的类
-        :return:
-        """
-        try:
-            return self.dict_image_card[target]
-        except KeyError:
-            logger.warning(f'Unknown card class: {target}')
-            return CardClass.UNKNOWN
-
-    def _current_select_best(self, last_best: CardClass or None) -> CardClass | None:
-        self.screenshot()
-        target = self.order_targets.find_anyone(self.device.image)
-        if target is None:
-            logger.info('No target card found')
-            return None
-        current_card = self._image_convert_card(target)
-        if current_card == CardClass.UNKNOWN:
-            logger.info('Unknown card class')
-            return None
-        logger.info(f'Current best card class: {current_card}')
-
-        # 如果当前的最好的卡,不比上一次最好的卡,那就退出
-        if last_best is not None:
-            last_index = self.order_cards.index(last_best)
-            current_index = self.order_cards.index(current_card)
-            if current_index >= last_index:
-                # 不比上一张卡好就退出不执行操作,相同星级卡亦跳过
-                logger.info('Current card is not better than last best card')
-                return last_best
-
-        # 否则就是比上一张卡好,那就执行操作 点击操作
-        logger.info('Current select card: %s', current_card)
-        # 如果一开始是没有选择中的,那就稳定点否则就是只管点击
-        self.screenshot()
-        if self.appear(self.I_A_EMPTY):
-            while 1:
-                self.screenshot()
-                if not self.appear(self.I_A_EMPTY):
-                    return current_card
-                if self.appear_then_click(target, interval=1):
-                    continue
-        self.appear_then_click(target, interval=0.5)
-        return current_card
+        ocr_count = 0
+        while 1:
+            self.screenshot()
+            results = self.O_CHECK_CARD_NUMBER.detect_and_ocr(self.device.image)
+            ocr_count += 1
+            # 第一步:筛选出包含 "体力或者勾玉" 的结果
+            filtered_results = [result for result in results if check_card in result.ocr_text]
+            logger.info(f"识别到卡: {[result.ocr_text for result in filtered_results]}")
+
+            # 第二步:提取数字并按数字排序
+            numeric_results = []
+            for result in filtered_results:
+                # 使用正则表达式提取所有数字
+                numbers = [int(num) for num in re.findall(r'\d+', result.ocr_text)]
+                if numbers:  # 如果提取到数字
+                    if numbers[0] < min_card_num:
+                        continue
+                    numeric_results.append((numbers[0], result))  # 按第一个数字排序
+
+            if numeric_results:
+                # 按数字大到小排序
+                sorted_results = [result for _, result in sorted(numeric_results, key=lambda x: x[0], reverse=True)]
+                max_result = sorted_results[0]  # 获取数字最大的结果对象
+                target = RuleClick(roi_front=max_result.after_box, roi_back=max_result.after_box, name="tmpclick")
+                logger.info(f"选择挂卡: [{max_result.ocr_text}] {max_result.after_box}")
+                return target
+            else:
+                if ocr_count > 3:
+                    logger.error('多次未找到符合条件的结果, 退出')
+                    return None
+                logger.warning("未找到符合条件的结果, 准备往上滑动")
+                duration = 2
+                safe_pos_x = random.randint(200, 400)
+                safe_pos_y = random.randint(580, 600)
+                p1 = (safe_pos_x, safe_pos_y)
+                p2 = (safe_pos_x, safe_pos_y - 410)
+                logger.info('Swipe %s -> %s, %sS ' % (point2str(*p1), point2str(*p2), duration))
+                self.device.swipe_adb(p1, p2, duration=duration)
+                time.sleep(1)
+                continue
 
 
-    def check_max_lv(self, con: ActivationConfig):
+    def _card_not_found(self):
+        # 获取配置引用
+        activation_config = self.config.kekkai_activation.activation_config
+        # 多少分钟后重试
+        retry_minutes = 180
+        retry_count = 3
+        # 递增未找到卡的计数器
+        activation_config.card_not_found_count += 1
+
+        if activation_config.card_not_found_count >= retry_count:
+            # 达到重试上限时的处理
+            log_msg = f"⚠️{activation_config.card_type}卡未检出(累计{retry_count}次),{retry_minutes}分钟后重试"
+            activation_config.card_not_found_count = 0  # 重置计数器并延长下次执行时间
+            next_run = datetime.now() + timedelta(minutes=retry_minutes)
+        else:
+            # # 未达上限切换卡类型
+            new_type = (
+                CardType.FISH
+                if activation_config.card_type == CardType.TAIKO
+                else CardType.TAIKO
+            )
+            log_msg = f"🔄{activation_config.card_type}卡未检出 → 切换{new_type}"
+            activation_config.card_type = new_type
+            next_run = datetime.now()
+
+        # 统一记录日志和推送
+        self.save_image(content=log_msg, push_flag=True)
+
+        # 保存配置并设置下次执行
+        self.config.save()
+        self.set_next_run("KekkaiActivation", success=True, finish=True, target=next_run)
+        raise TaskEnd
+
+    def check_max_lv(self, shikigami_class: ShikigamiClass = ShikigamiClass.N):
         """
         """
         在结界界面,进入式神育成,检查是否有满级的,如果有就换下一个
         在结界界面,进入式神育成,检查是否有满级的,如果有就换下一个
         退出的时候还是结界界面
         退出的时候还是结界界面
         :return:
         :return:
         """
         """
         self.realm_goto_grown()
         self.realm_goto_grown()
-        # 直接进行智能放入
-        if con.exchange_smart:
-            logger.info('Smart exchange')
-            self.ui_click_until_disappear(self.I_RS_SMART_EXCHANGE)
         if self.appear(self.I_RS_LEVEL_MAX):
         if self.appear(self.I_RS_LEVEL_MAX):
             # 存在满级的式神
             # 存在满级的式神
             logger.info('Exist max level shikigami and replace it')
             logger.info('Exist max level shikigami and replace it')
             self.unset_shikigami_max_lv()
             self.unset_shikigami_max_lv()
-            self.switch_shikigami_class(con.shikigami_class)
+            self.switch_shikigami_class(shikigami_class)
             self.set_shikigami(shikigami_order=7, stop_image=self.I_RS_NO_ADD)
             self.set_shikigami(shikigami_order=7, stop_image=self.I_RS_NO_ADD)
         else:
         else:
             logger.info('No max level shikigami')
             logger.info('No max level shikigami')
         if self.detect_no_shikigami():
         if self.detect_no_shikigami():
             logger.warning('There are no any shikigami grow room')
             logger.warning('There are no any shikigami grow room')
-            self.switch_shikigami_class(con.shikigami_class)
+            self.switch_shikigami_class(shikigami_class)
             self.set_shikigami(shikigami_order=7, stop_image=self.I_RS_NO_ADD)
             self.set_shikigami(shikigami_order=7, stop_image=self.I_RS_NO_ADD)
 
 
         # 回到结界界面
         # 回到结界界面
@@ -373,10 +381,7 @@ class ScriptTask(KU, KekkaiActivationAssets):
                 if not self.appear(self.I_REALM_SHIN):
                 if not self.appear(self.I_REALM_SHIN):
                     continue
                     continue
                 break
                 break
-            # 有时候退出动画太久点了两次退出,需要重新进入
-            if self.appear_then_click(self.I_GUILD_REALM, interval=1.5):
-                continue
-            if self.appear_then_click(self.I_UI_BACK_BLUE, interval=5.5):
+            if self.appear_then_click(self.I_UI_BACK_BLUE, interval=2.5):
                 continue
                 continue
 
 
     def harvest_card(self):
     def harvest_card(self):
@@ -392,7 +397,6 @@ class ScriptTask(KU, KekkaiActivationAssets):
         self.appear_then_click(self.I_A_HARVEST_FISH_6)  # 斗鱼6
         self.appear_then_click(self.I_A_HARVEST_FISH_6)  # 斗鱼6
         self.appear_then_click(self.I_A_HARVEST_MOON_3)  # 太阴3
         self.appear_then_click(self.I_A_HARVEST_MOON_3)  # 太阴3
         self.appear_then_click(self.I_A_HARVEST_FISH_3)  # 斗鱼三
         self.appear_then_click(self.I_A_HARVEST_FISH_3)  # 斗鱼三
-        self.appear_then_click(self.I_A_HARVEST_OBOROGURUMA)  # 胧车
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
@@ -400,9 +404,9 @@ if __name__ == "__main__":
     from module.device.device import Device
     from module.device.device import Device
     import cv2
     import cv2
 
 
-    c = Config('oas1')
+    c = Config('switch')
     d = Device(c)
     d = Device(c)
 
 
     t = ScriptTask(c, d)
     t = ScriptTask(c, d)
-    t.run()
+    t.check_card_num()
     # t.run_activation(t.config.kekkai_activation.activation_config)
     # t.run_activation(t.config.kekkai_activation.activation_config)

BIN
tasks/KekkaiUtilize/ku/ku_guild_collapse.png


BIN
tasks/KekkaiUtilize/ku/ku_guild_expand.png


+ 32 - 0
tasks/KekkaiUtilize/utilize/click.json

@@ -0,0 +1,32 @@
+[
+  {
+    "itemName": "select_realm_1",
+    "roiFront": "300,200,200,50",
+    "roiBack": "300,200,200,50",
+    "description": "选择结界区域1"
+  },
+  {
+    "itemName": "select_realm_2",
+    "roiFront": "300,307,200,50",
+    "roiBack": "300,307,200,50",
+    "description": "选择结界区域2"
+  },
+  {
+    "itemName": "select_realm_3",
+    "roiFront": "300,415,200,50",
+    "roiBack": "300,415,200,50",
+    "description": "选择结界区域3"
+  },
+  {
+    "itemName": "select_realm_4",
+    "roiFront": "300,520,200,50",
+    "roiBack": "300,520,200,50",
+    "description": "选择结界区域4"
+  },
+  {
+    "itemName": "select_card",
+    "roiFront": "0,0,0,0",
+    "roiBack": "0,0,0,0",
+    "description": "点击识别到的卡(用识别到的坐标填充作用)"
+  }
+]

BIN
tasks/KekkaiUtilize/utilize/select_realm_on_1.png


BIN
tasks/KekkaiUtilize/utilize/select_realm_on_2.png


BIN
tasks/KekkaiUtilize/utilize/select_realm_on_3.png


BIN
tasks/KekkaiUtilize/utilize/select_realm_on_4.png


+ 7 - 1
tasks/base_task.py

@@ -639,4 +639,10 @@ class BaseTask(GlobalGameAssets, CostumeBase):
                 continue
                 continue
             if isinstance(click, RuleOcr):
             if isinstance(click, RuleOcr):
                 self.click(click)
                 self.click(click)
-                continue
+                continue
+
+    def push_notify(self, content='', title=None, level=3):
+        logger.info(f'Push notify: {content}')
+
+    def save_image(self, task_name=None, content=None, wait_time=2, image_type=False, push_flag=False, level=3):
+        logger.info(f'Save image: {task_name}')