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

Merge remote-tracking branch 'origin/dev' into dev

neptine 2 сар өмнө
parent
commit
4dda29b565

+ 1 - 1
tasks/DemonEncounter/assets.py

@@ -126,7 +126,7 @@ class DemonEncounterAssets:
 	# 计数已经开启多少的 
 	# 计数已经开启多少的 
 	O_DE_COUNTER = RuleOcr(roi=(1204,685,48,34), area=(1204,685,48,34), mode="DigitCounter", method="Default", keyword="", name="de_counter")
 	O_DE_COUNTER = RuleOcr(roi=(1204,685,48,34), area=(1204,685,48,34), mode="DigitCounter", method="Default", keyword="", name="de_counter")
 	# 现世逢魔顶部今日挑战次数X/1的最小识别区, 0/1表示已打过直接结束 
 	# 现世逢魔顶部今日挑战次数X/1的最小识别区, 0/1表示已打过直接结束 
-	O_DE_CHALLENGE_COUNT = RuleOcr(roi=(680,68,75,36), area=(680,68,75,36), mode="Full", method="Default", keyword="", name="de_challenge_count")
+	O_DE_CHALLENGE_COUNT = RuleOcr(roi=(705,68,45,36), area=(705,68,45,36), mode="Full", method="Default", keyword="", name="de_challenge_count")
 
 
 
 
 	# Click Rule Assets
 	# Click Rule Assets

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

@@ -10,8 +10,8 @@
   },
   },
   {
   {
     "itemName": "de_challenge_count",
     "itemName": "de_challenge_count",
-    "roiFront": "680,68,75,36",
-    "roiBack": "680,68,75,36",
+    "roiFront": "705,68,45,36",
+    "roiBack": "705,68,45,36",
     "mode": "Full",
     "mode": "Full",
     "method": "Default",
     "method": "Default",
     "keyword": "",
     "keyword": "",

+ 5 - 0
tasks/RichMan/assets.py

@@ -150,6 +150,11 @@ class RichManAssets:
 	I_ME_CHECK_SOULS = RuleImage(roi_front=(611,225,100,100), roi_back=(507,199,272,175), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/medal/medal_me_check_souls.png")
 	I_ME_CHECK_SOULS = RuleImage(roi_front=(611,225,100,100), roi_back=(507,199,272,175), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/medal/medal_me_check_souls.png")
 
 
 
 
+	# Ocr Rule Assets
+	# Count sold-out labels in medal shop page 
+	O_SOLD_OUT = RuleOcr(roi=(0,100,1280,500), area=(0,100,1280,500), mode="Full", method="Default", keyword="售", name="sold_out")
+
+
 	# Image Rule Assets
 	# Image Rule Assets
 	# 寄售屋 
 	# 寄售屋 
 	I_MALL_CONSIGNMENT = RuleImage(roi_front=(207,639,56,59), roi_back=(175,610,120,103), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/navbar/navbar_mall_consignment.png")
 	I_MALL_CONSIGNMENT = RuleImage(roi_front=(207,639,56,59), roi_back=(175,610,120,103), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/navbar/navbar_mall_consignment.png")

+ 77 - 18
tasks/RichMan/mall/medal.py

@@ -23,43 +23,102 @@ class Medal(FriendshipPoints):
             return
             return
         self._enter_medal()
         self._enter_medal()
 
 
+        # 记录识别失败的商品,用于事后核对是否为售罄
+        not_found = []
+
         # 黑蛋
         # 黑蛋
         if con.black_daruma:
         if con.black_daruma:
-            self.buy_mall_one(buy_button=self.I_ME_BLACK, buy_check=self.I_ME_CHECK_BLACK,
-                              money_ocr=self.O_MALL_RESOURCE_3, buy_money=480)
+            self.screenshot()
+            if self.appear(self.I_ME_BLACK):
+                self.buy_mall_one(buy_button=self.I_ME_BLACK, buy_check=self.I_ME_CHECK_BLACK,
+                                  money_ocr=self.O_MALL_RESOURCE_3, buy_money=480)
+            else:
+                not_found.append('black_daruma')
         # 蓝票
         # 蓝票
         if con.mystery_amulet:
         if con.mystery_amulet:
-            self.buy_mall_one(buy_button=self.I_ME_BLUE, buy_check=self.I_ME_CHECK_BLUE,
-                              money_ocr=self.O_MALL_RESOURCE_3, buy_money=180)
+            self.screenshot()
+            if self.appear(self.I_ME_BLUE):
+                self.buy_mall_one(buy_button=self.I_ME_BLUE, buy_check=self.I_ME_CHECK_BLUE,
+                                  money_ocr=self.O_MALL_RESOURCE_3, buy_money=180)
+            else:
+                not_found.append('mystery_amulet')
         # 体力100
         # 体力100
         if con.ap_100:
         if con.ap_100:
-            self.buy_mall_one(buy_button=self.I_ME_AP, buy_check=self.I_ME_CHECK_AP,
-                              money_ocr=self.O_MALL_RESOURCE_3, buy_money=120)
+            self.screenshot()
+            if self.appear(self.I_ME_AP):
+                self.buy_mall_one(buy_button=self.I_ME_AP, buy_check=self.I_ME_CHECK_AP,
+                                  money_ocr=self.O_MALL_RESOURCE_3, buy_money=120)
+            else:
+                not_found.append('ap_100')
         # 随机御魂
         # 随机御魂
         if con.random_soul:
         if con.random_soul:
-            self.buy_mall_one(buy_button=self.I_ME_SOULS, buy_check=self.I_ME_CHECK_SOULS,
-                              money_ocr=self.O_MALL_RESOURCE_3, buy_money=320)
+            self.screenshot()
+            if self.appear(self.I_ME_SOULS):
+                self.buy_mall_one(buy_button=self.I_ME_SOULS, buy_check=self.I_ME_CHECK_SOULS,
+                                  money_ocr=self.O_MALL_RESOURCE_3, buy_money=320)
+            else:
+                not_found.append('random_soul')
         # 两颗白蛋
         # 两颗白蛋
         if con.white_daruma:
         if con.white_daruma:
-            self.buy_mall_more(buy_button=self.I_ME_WHITE, remain_number=True, money_ocr=self.I_MALL_RESOURCE_MEDAL.build_mall_resource_ocr(self.device.image),
-                               buy_number=2, buy_max=2, buy_money=100)
+            self.screenshot()
+            if self.appear(self.I_ME_WHITE):
+                self.buy_mall_more(buy_button=self.I_ME_WHITE, remain_number=True, money_ocr=self.I_MALL_RESOURCE_MEDAL.build_mall_resource_ocr(self.device.image),
+                                   buy_number=2, buy_max=2, buy_money=100)
+            else:
+                not_found.append('white_daruma')
         # 十张挑战券
         # 十张挑战券
         if con.challenge_pass:
         if con.challenge_pass:
-            self.buy_mall_more(buy_button=self.I_ME_CHALLENGE_PASS, remain_number=True, money_ocr=self.I_MALL_RESOURCE_MEDAL.build_mall_resource_ocr(self.device.image),
-                               buy_number=con.challenge_pass, buy_max=10, buy_money=30)
+            self.screenshot()
+            if self.appear(self.I_ME_CHALLENGE_PASS):
+                self.buy_mall_more(buy_button=self.I_ME_CHALLENGE_PASS, remain_number=True, money_ocr=self.I_MALL_RESOURCE_MEDAL.build_mall_resource_ocr(self.device.image),
+                                   buy_number=con.challenge_pass, buy_max=10, buy_money=30)
+            else:
+                not_found.append('challenge_pass')
         # 红蛋
         # 红蛋
         if con.red_daruma:
         if con.red_daruma:
-            self.buy_mall_more(buy_button=self.I_ME_RED, remain_number=False,
-                               money_ocr=self.I_MALL_RESOURCE_MEDAL.build_mall_resource_ocr(self.device.image),
-                               buy_number=con.red_daruma, buy_max=99, buy_money=30)
+            self.screenshot()
+            if self.appear(self.I_ME_RED):
+                self.buy_mall_more(buy_button=self.I_ME_RED, remain_number=False,
+                                   money_ocr=self.I_MALL_RESOURCE_MEDAL.build_mall_resource_ocr(self.device.image),
+                                   buy_number=con.red_daruma, buy_max=99, buy_money=30)
+            else:
+                not_found.append('red_daruma')
         # 破碎的咒符
         # 破碎的咒符
         if con.broken_amulet:
         if con.broken_amulet:
-            self.buy_mall_more(buy_button=self.I_ME_BROKEN, remain_number=False,
-                               money_ocr=self.I_MALL_RESOURCE_MEDAL.build_mall_resource_ocr(self.device.image),
-                               buy_number=con.broken_amulet, buy_max=99, buy_money=20)
+            self.screenshot()
+            if self.appear(self.I_ME_BROKEN):
+                self.buy_mall_more(buy_button=self.I_ME_BROKEN, remain_number=False,
+                                   money_ocr=self.I_MALL_RESOURCE_MEDAL.build_mall_resource_ocr(self.device.image),
+                                   buy_number=con.broken_amulet, buy_max=99, buy_money=20)
+            else:
+                not_found.append('broken_amulet')
+
+        # 有识别失败的商品:核对售罄数量,确认失败是否为"商品售罄"(正常情况),而非页面异常。
+        # 注意:页面上的售罄标签可能包含未配置购买的商品,因此用 >= 而非 ==,避免误报。
+        if not_found:
+            self.screenshot()
+            soldout_count = self.count_soldout()
+            if soldout_count >= len(not_found):
+                logger.info(f'Medal: {len(not_found)} item(s) not detected, sold out count is {soldout_count}, '
+                            f'the not-detected items are sold out, skip normally')
+            else:
+                logger.warning(f'Medal: {len(not_found)} item(s) not detected, but sold out count is only {soldout_count}, '
+                               f'some items may not be sold out, page may be abnormal, please check manually')
 
 
         time.sleep(1)
         time.sleep(1)
 
 
+    def count_soldout(self) -> int:
+        """
+        统计勋章商店页面中"售罄"标签的数量。
+        通过 OCR 检测商品区域内含"售"字的文本块(售罄标签),用于核对识别失败的商品是否均为售罄。
+        需要先调用 screenshot 保证 self.device.image 为最新画面。
+        :return: 售罄标签数量
+        """
+        results = self.O_SOLD_OUT.detect_and_ocr(self.device.image, logDisplay=False)
+        count = sum(1 for r in results if '售' in r.ocr_text)
+        logger.info(f'Medal sold out count: {count}')
+        return count
+
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config

+ 11 - 0
tasks/RichMan/mall/medal/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "sold_out",
+    "roiFront": "0,100,1280,500",
+    "roiBack": "0,100,1280,500",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "售",
+    "description": "Count sold-out labels in medal shop page"
+  }
+]

+ 2 - 1
tasks/RichMan/mall/navbar.py

@@ -74,7 +74,7 @@ class MallNavbar(GameUi, RichManAssets):
         :return:
         :return:
         """
         """
         self._enter_sundry()
         self._enter_sundry()
-        self.ui_click(self.I_SIDE_SURE_MEDAL, self.I_SIDE_CHECK_MEDAL)
+        self.ui_click(self.I_SIDE_SURE_MEDAL, self.I_SIDE_CHECK_MEDAL, interval=3, timeout=15)
 
 
     def _enter_charisma(self):
     def _enter_charisma(self):
         """
         """
@@ -91,6 +91,7 @@ class MallNavbar(GameUi, RichManAssets):
         """
         """
         self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MALL, interval=3, timeout=6)
         self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MALL, interval=3, timeout=6)
 
 
+
     def mall_resource(self, index: int) -> int:
     def mall_resource(self, index: int) -> int:
         """
         """
         获取商城资源,
         获取商城资源,