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

Merge login, bounty and store fixes through nearaura b2f9e032

Review 1ad372dc..b2f9e032 after runhey returned Repository not found.
Replay a26cae7e, d4219988 and b2f9e032 with original SHAs recorded on
a branch based on a4d19403, then merge into the shared 76969a01 tip.
The upstream merge commits add no separate changes. Keep the previously
excluded b2f02602 out of this ancestry.

Use the original upstream 16+ and sold-out PNGs with matching rule and
JSON metadata. Keep the shared local login matcher for restart, global
navigation and account switching, its extra 8+ fallback, and the next-frame
guard after server selection. Preserve the AreaBoss navigation fix.

Skip mystery bounty progress and stop the special shop at the sold-out
marker. Count actual guild swipes using the local void-returning swipe
API. Read purchase quantity before adding, stop at the request or stock
limit, and clear only the repeated add-button history for large orders.
Keep existing price and balance safeguards.

Validation: 597 tests passed across tests/ and both FrogBoss suites,
including five new purchase and swipe regression cases. Six deprecation
warnings. Changed Python syntax/imports, upstream PNG identity, dimensions,
runtime template matching, JSON metadata, mystery bounty OCR replays and
git diff --check passed. Offline validation only.
unknown 7 часов назад
Родитель
Сommit
1944831172

+ 10 - 5
tasks/Component/Buy/buy.py

@@ -115,14 +115,13 @@ class Buy(BaseTask, BuyAssets):
         else:
             # 四次截图数字都一样,就可以退出了
             number_record = []
+            add_click_count = 0
+            clear_add_click_record = number > 10
             ocr_timer = Timer(0.8)
             ocr_timer.start()
             while 1:
                 self.screenshot()
 
-                if self.appear_then_click(self.I_BUY_ADD, interval=0.8):
-                    continue
-
                 if not ocr_timer.reached():
                     continue
                 ocr_timer.reset()
@@ -136,6 +135,12 @@ class Buy(BaseTask, BuyAssets):
                     if number_record[0] == number_record[1] == number_record[2] == number_record[3]:
                         break
                     number_record.pop(0)
+                if current > 0 and self.appear_then_click(self.I_BUY_ADD, interval=0.8):
+                    add_click_count += 1
+                    if clear_add_click_record and add_click_count % 7 == 0:
+                        self.device.click_record_remove(self.I_BUY_ADD)
+                    if add_click_count >= number - 1:
+                        break
 
         # 购买确认
         while 1:
@@ -186,7 +191,7 @@ class Buy(BaseTask, BuyAssets):
                 if max_price is not None:
                     return self._buy_with_price(start_click, check_image, True, max_price, money, remain)
                 if number == 1:
-                    # buy_more 指定数量时会先点一次加号再 OCR, 买 1 个会变成买 2 个
+                    # 只买一个时直接验证默认数量
                     return self._buy_more_default(start_click)
                 logger.info('Buy window with number selector, use buy_more')
                 return self.buy_more(start_click, number)
@@ -242,7 +247,7 @@ class Buy(BaseTask, BuyAssets):
             return self._buy_more_default(start_click)
         if number == remain:
             return self.buy_more(start_click, None)
-        # buy_more(start_click, number) 点加号后才读数量, 可能超过 number.
+        # 余额不足以买满时,逐次校验默认数量。
         # 余额不够买满时每次只买 1 个, 调用方循环会重新读余额和剩余次数再买下一个
         logger.info(f'Money is not enough to buy all {remain}, buy one by one')
         return self._buy_more_default(start_click)

+ 3 - 3
tasks/Restart/assets.py

@@ -111,10 +111,10 @@ class RestartAssets:
 	I_LOGIN_RED_CLOSE = RuleImage(roi_front=(800,0,480,290), roi_back=(800,0,480,290), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_red_close.png")
 	# description 
 	I_LOGIN_YELLOW_CLOSE = RuleImage(roi_front=(29,17,46,44), roi_back=(0,0,94,86), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_yellow_close.png")
-	# 用于判断是否出现登录选区的 
+	# Login server selection screen with the 8+ age rating icon
 	I_LOGIN_8 = RuleImage(roi_front=(178,572,53,60), roi_back=(1,547,241,105), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_8.png")
-	# 登录页左下角的 16+ 适龄提示
-	I_LOGIN_16 = RuleImage(roi_front=(13,564,53,70), roi_back=(1,547,241,105), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_16.png")
+	# Login server selection screen with the 16+ age rating icon
+	I_LOGIN_16 = RuleImage(roi_front=(8,558,64,80), roi_back=(1,547,241,105), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_16.png")
 	# 指定角色进入游戏,默认第一个 
 	I_LOGIN_SPECIFIC_SERVE = RuleImage(roi_front=(0,0,120,120), roi_back=(0,0,120,120), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_specific_serve.png")
 	# 下载插画 

+ 3 - 3
tasks/Restart/login/image.json

@@ -51,16 +51,16 @@
     "roiBack": "1,547,241,105",
     "method": "Template matching",
     "threshold": 0.8,
-    "description": "用于判断是否出现登录选区的"
+    "description": "Login server selection screen with the 8+ age rating icon"
   },
   {
     "itemName": "login_16",
     "imageName": "login_login_16.png",
-    "roiFront": "13,564,53,70",
+    "roiFront": "8,558,64,80",
     "roiBack": "1,547,241,105",
     "method": "Template matching",
     "threshold": 0.8,
-    "description": "登录页左下角的 16+ 适龄提示"
+    "description": "Login server selection screen with the 16+ age rating icon"
   },
   {
     "itemName": "login_specific_serve",

BIN
tasks/Restart/login/login_login_16.png


+ 2 - 0
tasks/RichMan/assets.py

@@ -322,6 +322,8 @@ class RichManAssets:
 	I_SP_BUY_LOW = RuleImage(roi_front=(176,148,144,108), roi_back=(128,142,902,449), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/special/special_sp_buy_low.png")
 	# 判断是否滑动到底 
 	I_SP_SWIPE_CHECK = RuleImage(roi_front=(900,164,42,61), roi_back=(173,144,840,379), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/special/special_sp_swipe_check.png")
+	# 售罄
+	I_SOLD_OUT = RuleImage(roi_front=(442,344,54,32), roi_back=(142,312,876,290), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/special/special_sold_out.png")
 
 
 	# Ocr Rule Assets

+ 3 - 4
tasks/RichMan/guild.py

@@ -94,13 +94,12 @@ class Guild(Buy, GameUi, RichManAssets):
                 time.sleep(1)
                 continue
             # 连续多次滑动都没有买到东西, 防止无限滑动触发点击保护
-            swipe_no_progress += 1
             if swipe_no_progress >= 8:
                 logger.warning(f'Swipe {swipe_no_progress} times without buying, stop guild store')
                 break
-            if self.swipe(self.S_GUILD_STORE, interval=1.5):
-                time.sleep(2)
-                continue
+            self.swipe(self.S_GUILD_STORE)
+            swipe_no_progress += 1
+            time.sleep(2)
 
 
         # 回去

+ 1 - 1
tasks/RichMan/mall/special.py

@@ -41,7 +41,7 @@ class Special(Buy, MallNavbar):
             if totem_bought and medium_bought and low_bought:
                 logger.info('All bought')
                 break
-            if self.appear(self.I_SP_SWIPE_CHECK):
+            if self.appear(self.I_SP_SWIPE_CHECK) or self.appear(self.I_SOLD_OUT):
                 # 如果滑动到底了
                 logger.info('Swipe to bottom')
                 break

+ 9 - 0
tasks/RichMan/mall/special/image.json

@@ -34,5 +34,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "判断是否滑动到底"
+  },
+  {
+    "itemName": "sold_out",
+    "imageName": "special_sold_out.png",
+    "roiFront": "442,344,54,32",
+    "roiBack": "142,312,876,290",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "售罄"
   }
 ]

BIN
tasks/RichMan/mall/special/special_sold_out.png


+ 4 - 0
tasks/WantedQuests/script_task.py

@@ -663,6 +663,7 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
         reg_fengyin = re.compile(r'.*[封|野]印.*')
         # 由于斜杠'/'经常被误识别为'7',且悬赏封印悬赏怪物总数没有与‘7’相关的数字
         reg_progress = re.compile(r'^(\d+)([7/])(\d+)$')
+        reg_mystery_monster = re.compile(r'^[??]+$')
         # 没有检测到斜杠,符合格式:前N位与后N位相同,表示已完成
         reg_XX = re.compile(r'^(\d+)\1$')
         # 过滤掉协或者未知悬赏等其他无用字符
@@ -676,6 +677,9 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             if reg_other.search(res.ocr_text):
                 continue
             if (match := reg_progress.match(res.ocr_text)):
+                if index > 0 and reg_mystery_monster.fullmatch(res_list[index - 1].ocr_text.strip()):
+                    logger.info('Skip wanted quest for mystery monster')
+                    continue
                 spliter_index = match.start(2)
                 xywh = calc_xywh(res.box)
                 self.O_WQ_TEXT_ALL.area = xywh

+ 58 - 0
tests/tasks/RichMan/test_purchase_limits.py

@@ -0,0 +1,58 @@
+from types import SimpleNamespace
+from unittest.mock import Mock
+
+import pytest
+
+from tasks.Component.Buy import buy as buy_module
+from tasks.RichMan.guild import Guild
+
+
+@pytest.mark.parametrize('initial,requested,stock', [(1, 18, 30), (9, 12, 30), (1, 18, 5), (1, 1, 30)])
+def test_quantity_selector_stops_at_requested_or_stock(monkeypatch, initial, requested, stock):
+    task = object.__new__(buy_module.Buy)
+    quantity = initial
+    frames = 0
+    task.device = SimpleNamespace(image=None, click_record_remove=Mock())
+    task.O_BUY_NUMBER = SimpleNamespace(ocr=lambda frame: frame)
+    task.appear = lambda rule, **kw: rule is task.I_BUY_PLUS
+    task.ui_reward_appear_click = lambda: True
+
+    def screenshot():
+        nonlocal frames
+        frames += 1
+        assert frames < 35
+        task.device.image = quantity
+
+    def add(rule, **kw):
+        nonlocal quantity
+        assert rule is task.I_BUY_ADD
+        quantity = min(quantity + 1, stock)
+        return True
+
+    task.screenshot = screenshot
+    task.appear_then_click = add
+    monkeypatch.setattr(buy_module.time, 'sleep', lambda _: None)
+    monkeypatch.setattr(buy_module, 'Timer', lambda _: SimpleNamespace(
+        start=lambda: None, reached=lambda: True, reset=lambda: None))
+    assert task.buy_more(None, requested)
+    assert quantity == min(requested, stock)
+    if requested - initial >= 7 and stock >= requested:
+        task.device.click_record_remove.assert_any_call(task.I_BUY_ADD)
+
+
+def test_guild_store_leaves_after_eight_actual_swipes(monkeypatch):
+    task = object.__new__(Guild)
+    task.device = SimpleNamespace(swipe=Mock())
+    frames = 0
+
+    def screenshot():
+        nonlocal frames
+        frames += 1
+        assert frames < 20
+
+    task.goto_page = lambda page: None
+    task.screenshot = screenshot
+    task.appear = lambda rule: rule is task.I_GUILD_CLOSE_RED or rule is task.I_GUILD_SHRINE
+    monkeypatch.setattr('tasks.RichMan.guild.time.sleep', lambda _: None)
+    task.execute_guild(SimpleNamespace(enable=True, mystery_amulet=True, black_daruma_scrap=False, skin_ticket=False))
+    assert task.device.swipe.call_count == 8