Selaa lähdekoodia

Merge upstream dev through de497a3f with bounded island entry

Integrate 8b4dc669..de497a3f (five commits, including two merges).
Adopt SixRealms unknown-island round-robin clicks with a shared one-second
interval and a 15-second deadline. Adopt Flower Pass task-tab recognition
before reward collection and its updated PNG/ROI.

Complete related omissions: recognized-island entry now has the same
15-second deadline, while the random-entry fallback also shares a click
interval and handles cancellation without extending the deadline. Three
failing offline replays demonstrated these remaining loops/click bursts.
Register the task-tab rule in assets.py and its missing JSON metadata,
retaining upstream matching coordinates and threshold exactly.

Preserve existing local fixes: mail/raid/exploration recovery, cropped
confirm/cancel and exit priority, battle isolation, activity navigation,
AreaBoss returns, purchase limits, costume caches and desktop cleanup/
first-login restart exemption. No incoming patch skipped wholesale.

Validation: 505 pytest tests passed (tests and both FrogBoss suites),
including four upstream cases and five added island/task-tab cases.
Five Python syntax checks, three production imports, one JSON and PNG,
asset metadata and four synthetic image matches passed. Ten sensitive
local files/rule sets unchanged; git diff --check passed.
Three dependency deprecation warnings. No emulator or desktop game run.
unknown 2 viikkoa sitten
vanhempi
sitoutus
4c0161fc24

+ 32 - 16
tasks/SixRealms/moon_sea/map.py

@@ -2,6 +2,8 @@ import cv2
 import re
 import re
 import numpy as np
 import numpy as np
 from numpy import uint8, fromfile
 from numpy import uint8, fromfile
+from module.base.timer import Timer
+from module.exception import GameStuckError
 from module.logger import logger
 from module.logger import logger
 
 
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
@@ -81,32 +83,38 @@ class MoonSeaMap(MoonSeaSkills):
         if isl_type == MoonSeaType.island100:
         if isl_type == MoonSeaType.island100:
             logger.warning('The island type was not recognized')
             logger.warning('The island type was not recognized')
             logger.warning('Pick one at random, starting from the right')
             logger.warning('Pick one at random, starting from the right')
+            timeout = Timer(15).start()
+            click_timer = Timer(1)
+            entrances = (
+                self.C_ISLAND_ENTER_1, self.C_ISLAND_ENTER_2, self.C_ISLAND_ENTER_3,
+                self.C_ISLAND_ENTER_4, self.C_ISLAND_ENTER_5, self.C_ISLAND_ENTER_6,
+            )
+            entrance_index = 0
             while 1:
             while 1:
                 self.screenshot()
                 self.screenshot()
                 if not self.in_main() and self.appear(self.I_BACK_EXIT):
                 if not self.in_main() and self.appear(self.I_BACK_EXIT):
                     break
                     break
-                if self.appear_then_click(self.I_UI_CANCEL, interval=1):
-                    continue
-                if self.click(self.C_ISLAND_ENTER_1, interval=2):
-                    continue
-                if self.click(self.C_ISLAND_ENTER_2, interval=2):
-                    continue
-                if self.click(self.C_ISLAND_ENTER_3, interval=2):
+                if timeout.reached():
+                    raise GameStuckError('Enter unknown island timeout')
+                if not click_timer.reached():
                     continue
                     continue
-                if self.click(self.C_ISLAND_ENTER_4, interval=2):
-                    continue
-                if self.click(self.C_ISLAND_ENTER_5, interval=2):
-                    continue
-                if self.click(self.C_ISLAND_ENTER_6, interval=2):
+                if self.appear_then_click(self.I_UI_CANCEL, interval=1):
+                    click_timer.reset()
                     continue
                     continue
+                self.click(entrances[entrance_index])
+                entrance_index = (entrance_index + 1) % len(entrances)
+                click_timer.reset()
             logger.info('Entering island randomly')
             logger.info('Entering island randomly')
             return
             return
         isl_roi = [isl_roi[0]-40, isl_roi[1] + 70, isl_roi[2] + 40, isl_roi[3]+40]
         isl_roi = [isl_roi[0]-40, isl_roi[1] + 70, isl_roi[2] + 40, isl_roi[3]+40]
         self.C_ISLAND_ENTER.roi_front = isl_roi
         self.C_ISLAND_ENTER.roi_front = isl_roi
+        timeout = Timer(15).start()
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
             if not self.in_main() and self.appear(self.I_BACK_EXIT):
             if not self.in_main() and self.appear(self.I_BACK_EXIT):
                 break
                 break
+            if timeout.reached():
+                raise GameStuckError('Enter recognized island timeout')
             if self.click(self.C_ISLAND_ENTER, interval=2.5):
             if self.click(self.C_ISLAND_ENTER, interval=2.5):
                 continue
                 continue
         logger.info('Entering island')
         logger.info('Entering island')
@@ -145,16 +153,24 @@ class MoonSeaMap(MoonSeaSkills):
         # if not isinstance(area, list):
         # if not isinstance(area, list):
         #     area = list(area)
         #     area = list(area)
         logger.info('Entry island randomly')
         logger.info('Entry island randomly')
+        timeout = Timer(15).start()
+        click_timer = Timer(1)
+        entrances = (self.C_ISLAND_ENTER_4, self.C_ISLAND_ENTER_5, self.C_ISLAND_ENTER_6)
+        entrance_index = 0
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
             if not self.in_main() and self.appear(self.I_BACK_EXIT):
             if not self.in_main() and self.appear(self.I_BACK_EXIT):
                 break
                 break
-            if self.click(self.C_ISLAND_ENTER_4, interval=2):
-                continue
-            if self.click(self.C_ISLAND_ENTER_5, interval=2):
+            if timeout.reached():
+                raise GameStuckError('Enter random island timeout')
+            if not click_timer.reached():
                 continue
                 continue
-            if self.click(self.C_ISLAND_ENTER_6, interval=2):
+            if self.appear_then_click(self.I_UI_CANCEL, interval=1):
+                click_timer.reset()
                 continue
                 continue
+            self.click(entrances[entrance_index])
+            entrance_index = (entrance_index + 1) % len(entrances)
+            click_timer.reset()
         return
         return
 
 
 
 

+ 2 - 0
tasks/TalismanPass/assets.py

@@ -11,6 +11,8 @@ class TalismanPassAssets:
 
 
 
 
 	# Image Rule Assets
 	# Image Rule Assets
+	# 花合战任务页签
+	I_TASK_TAB = RuleImage(roi_front=(1198,328,36,73), roi_back=(1185,307,64,117), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_task_tab.png")
 	# 领取全部 
 	# 领取全部 
 	I_TP_GET_ALL = RuleImage(roi_front=(903,599,70,71), roi_back=(903,599,70,71), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_tp_get_all.png")
 	I_TP_GET_ALL = RuleImage(roi_front=(903,599,70,71), roi_back=(903,599,70,71), threshold=0.8, method="Template matching", file="./tasks/TalismanPass/tp/tp_tp_get_all.png")
 	# 任务 的右上方红点 
 	# 任务 的右上方红点 

+ 1 - 0
tasks/TalismanPass/script_task.py

@@ -17,6 +17,7 @@ class ScriptTask(GameUi, TalismanPassAssets):
 
 
     def run(self):
     def run(self):
         self.goto_page(page_daily)
         self.goto_page(page_daily)
+        self.appear_then_click(self.I_TASK_TAB)
         con: TalismanConfig = self.config.talisman_pass.talisman
         con: TalismanConfig = self.config.talisman_pass.talisman
 
 
         # 收取全部奖励
         # 收取全部奖励

+ 10 - 1
tasks/TalismanPass/tp/image.json

@@ -1,4 +1,13 @@
 [
 [
+  {
+    "itemName": "task_tab",
+    "imageName": "tp_task_tab.png",
+    "roiFront": "1198,328,36,73",
+    "roiBack": "1185,307,64,117",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "花合战任务页签"
+  },
   {
   {
     "itemName": "tp_get_all",
     "itemName": "tp_get_all",
     "imageName": "tp_tp_get_all.png",
     "imageName": "tp_tp_get_all.png",
@@ -125,4 +134,4 @@
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "六星御魂标志"
     "description": "六星御魂标志"
   }
   }
-]
+]

BIN
tasks/TalismanPass/tp/tp_task_tab.png


+ 125 - 0
tests/test_six_realms_island_entry.py

@@ -0,0 +1,125 @@
+"""Exercise bounded island entry without a game or OCR service."""
+
+import unittest
+from types import SimpleNamespace
+from unittest.mock import patch
+
+from module.exception import GameStuckError
+from tasks.SixRealms.common import MoonSeaType
+from tasks.SixRealms.moon_sea.map import MoonSeaMap
+
+
+class OfflineMoonSea(MoonSeaMap):
+    def __init__(self, enter_after=None, cancel_visible=False):
+        # Skip Config/Device initialization, retaining the production click method.
+        self.device = SimpleNamespace(click=self.record_click)
+        self.now = 100.0
+        self.frames = 0
+        self.interval_timer = {}
+        self.events = []
+        self.enter_after = enter_after
+        self.cancel_visible = cancel_visible
+
+    def record_click(self, x, y, control_name):
+        self.events.append((self.now, control_name))
+
+    def screenshot(self):
+        self.now += 0.25
+        self.frames += 1
+        if self.frames > 80:
+            raise AssertionError("Island entry exceeded its timeout")
+
+    def in_main(self):
+        return self.enter_after is None or len(self.events) < self.enter_after
+
+    def appear(self, rule, **kwargs):
+        if rule is self.I_BACK_EXIT:
+            return not self.in_main()
+        if rule is self.I_UI_CANCEL:
+            return self.cancel_visible
+        return False
+
+    def appear_then_click(self, rule, **kwargs):
+        if not self.appear(rule):
+            return False
+        self.click(rule)
+        return True
+
+
+class IslandEntryTests(unittest.TestCase):
+    def enter_unknown(self, task):
+        with patch("module.base.timer.time.time", side_effect=lambda: task.now):
+            task.enter_island(MoonSeaType.island100, (0, 0, 0, 0))
+
+    def test_entry_stops_without_clicking_when_already_inside(self):
+        task = OfflineMoonSea(enter_after=0)
+        self.enter_unknown(task)
+        self.assertEqual(task.events, [])
+
+    def test_entry_cycles_in_order_with_one_shared_interval(self):
+        task = OfflineMoonSea(enter_after=8)
+        self.enter_unknown(task)
+        self.assertEqual(
+            [name for _, name in task.events],
+            [f"island_enter_{number}" for number in (1, 2, 3, 4, 5, 6, 1, 2)],
+        )
+        for earlier, later in zip(task.events, task.events[1:]):
+            self.assertGreaterEqual(later[0] - earlier[0], 1)
+
+    def test_unrecognized_page_times_out_instead_of_clicking_forever(self):
+        task = OfflineMoonSea()
+        with self.assertRaisesRegex(GameStuckError, "Enter unknown island timeout"):
+            self.enter_unknown(task)
+        self.assertGreater(task.now, 115)
+        self.assertLessEqual(task.now, 115.25)
+        self.assertLessEqual(len(task.events), 15)
+
+    def test_cancel_popup_obeys_interval_and_does_not_reset_timeout(self):
+        task = OfflineMoonSea(cancel_visible=True)
+        with self.assertRaises(GameStuckError):
+            self.enter_unknown(task)
+        self.assertTrue(task.events)
+        self.assertTrue(all(name == task.I_UI_CANCEL.name for _, name in task.events))
+        self.assertLessEqual(task.now, 115.25)
+        for earlier, later in zip(task.events, task.events[1:]):
+            self.assertGreaterEqual(later[0] - earlier[0], 1)
+
+    def test_recognized_island_stops_or_times_out(self):
+        for enter_after in (0, 2, None):
+            with self.subTest(enter_after=enter_after):
+                task = OfflineMoonSea(enter_after=enter_after)
+                with patch("module.base.timer.time.time", side_effect=lambda: task.now):
+                    if enter_after is None:
+                        with self.assertRaises(GameStuckError):
+                            task.enter_island(MoonSeaType.island101, (100, 100, 40, 40))
+                    else:
+                        task.enter_island(MoonSeaType.island101, (100, 100, 40, 40))
+                        self.assertEqual(len(task.events), enter_after)
+                self.assertLessEqual(task.now, 115.25)
+                for earlier, later in zip(task.events, task.events[1:]):
+                    self.assertGreaterEqual(later[0] - earlier[0], 2.5)
+
+    def test_random_entry_uses_shared_interval_and_stops(self):
+        task = OfflineMoonSea(enter_after=5)
+        with patch("module.base.timer.time.time", side_effect=lambda: task.now):
+            task.entry_island_random()
+        self.assertEqual([name for _, name in task.events],
+                         [f"island_enter_{n}" for n in (4, 5, 6, 4, 5)])
+        for earlier, later in zip(task.events, task.events[1:]):
+            self.assertGreaterEqual(later[0] - earlier[0], 1)
+
+    def test_random_entry_timeout_including_persistent_cancel(self):
+        for cancel in (False, True):
+            with self.subTest(cancel=cancel):
+                task = OfflineMoonSea(cancel_visible=cancel)
+                with patch("module.base.timer.time.time", side_effect=lambda: task.now):
+                    with self.assertRaises(GameStuckError):
+                        task.entry_island_random()
+                self.assertLessEqual(task.now, 115.25)
+                self.assertLessEqual(len(task.events), 15)
+                if cancel:
+                    self.assertTrue(all(name == task.I_UI_CANCEL.name for _, name in task.events))
+
+
+if __name__ == "__main__":
+    unittest.main()

+ 41 - 0
tests/test_talisman_task_tab.py

@@ -0,0 +1,41 @@
+from types import SimpleNamespace
+
+import numpy as np
+import pytest
+
+from module.exception import TaskEnd
+from tasks.GameUi.page import page_daily
+from tasks.TalismanPass.script_task import ScriptTask
+
+
+@pytest.mark.parametrize('tab_visible', [False, True])
+def test_task_tab_is_matched_before_claiming(tab_visible):
+    task = object.__new__(ScriptTask)
+    events = []
+    screen = np.zeros((720, 1280, 3), dtype=np.uint8)
+    if tab_visible:
+        rule = task.I_TASK_TAB
+        x, y = rule.roi_front[:2]
+        h, w = rule.image.shape[:2]
+        screen[y:y+h, x:x+w] = rule.image
+    task.device = SimpleNamespace(
+        image=screen, click=lambda x, y, control_name: events.append('tab'),
+    )
+    task.interval_timer = {}
+    task.config = SimpleNamespace(talisman_pass=SimpleNamespace(
+        talisman=SimpleNamespace(level_reward=2, harvest_soul=False)))
+    task.goto_page = lambda page: events.append('daily') if page == page_daily else None
+
+    def in_task():
+        # Clicking the visible tab opens the task panel; an absent tab is not clicked.
+        events.append('check')
+        return tab_visible
+
+    task.in_task = in_task
+    task.get_all = lambda: events.append('claim')
+    task.get_flower = lambda level: events.append('flower')
+    task.set_next_run = lambda **kwargs: events.append('scheduled')
+    with pytest.raises(TaskEnd):
+        task.run()
+    assert events == (['daily', 'tab', 'check', 'claim', 'flower', 'scheduled']
+                      if tab_visible else ['daily', 'check', 'flower', 'scheduled'])