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

fix(SixRealms): 保留 OCR 已选中的岛屿

leovefy 2 недель назад
Родитель
Сommit
043d3aa922
2 измененных файлов с 23 добавлено и 8 удалено
  1. 4 4
      tasks/SixRealms/moon_sea/map.py
  2. 19 4
      tests/test_six_realms_island_entry.py

+ 4 - 4
tasks/SixRealms/moon_sea/map.py

@@ -55,13 +55,13 @@ class MoonSeaMap(MoonSeaSkills):
             boxes = self._marker_boxes(island)
             if boxes:
                 candidates[island] = boxes
-        if prefer_store and MoonSeaType.island101 in candidates:
+        if prefer_store and kind != MoonSeaType.island101 and MoonSeaType.island101 in candidates:
             kind = MoonSeaType.island101
             roi = max(candidates[kind])
-        elif kind in candidates:
-            roi = self._nearby_marker(candidates[kind], roi) or max(candidates[kind])
+        elif kind != MoonSeaType.island100:
+            roi = self._nearby_marker(candidates.get(kind, []), roi) or roi
         elif candidates:
-            # 没有对应的 OCR 目标时,沿用从右向左的选岛顺序。
+            # OCR 未识别出岛型时,沿用从右向左的选岛顺序。
             kind, roi = max(((island, max(boxes)) for island, boxes in candidates.items()),
                             key=lambda candidate: candidate[1][0])
         logger.info('Island type: {}, Residue: {}, ROI: {}'.format(kind, rounds, roi))

+ 19 - 4
tests/test_six_realms_island_entry.py

@@ -58,15 +58,30 @@ class IslandEntryTests(unittest.TestCase):
 
     def test_known_island_tracks_height_without_switching_columns(self):
         task = OfflineMoonSea(enter_after=2)
-        right = (1040, 300, 20, 90)
-        frames = [[(288, 280, 20, 90), right],
+        left = (288, 280, 20, 90)
+        frames = [[(1040, 300, 20, 90), left],
                   [(288, 320, 20, 90), (1040, 340, 20, 90)]]
         with patch.object(task, "_marker_boxes", side_effect=frames), \
                 patch.object(task, "click", wraps=task.click) as click, \
                 patch("module.base.timer.time.time", side_effect=lambda: task.now):
-            task.enter_island(MoonSeaType.island104, right)
+            task.enter_island(MoonSeaType.island104, left)
         self.assertEqual([call.args[0].roi_front for call in click.call_args_list],
-                         [(1020, 360, 60, 60), (1020, 400, 60, 60)])
+                         [(268, 340, 60, 60), (268, 380, 60, 60)])
+
+    def test_decide_keeps_ocr_target_without_a_nearby_marker(self):
+        task = OfflineMoonSea()
+        roi = (288, 280, 22, 80)
+        for target, marker, prefer_store in (
+            (MoonSeaType.island104, MoonSeaType.island104, False),
+            (MoonSeaType.island104, MoonSeaType.island103, False),
+            (MoonSeaType.island101, MoonSeaType.island101, True),
+        ):
+            ocr = (target, 9, roi)
+            boxes = {marker: [(1040, 300, 20, 90)]}
+            with self.subTest(target=target, marker=marker, prefer_store=prefer_store), \
+                    patch.object(task, "_read_map_ocr", return_value=ocr), \
+                    patch.object(task, "_marker_boxes", side_effect=lambda kind: boxes.get(kind, [])):
+                self.assertEqual(task.decide(prefer_store=prefer_store), ocr)
 
     def test_disappearing_marker_times_out_without_clicking_adjacent_island(self):
         task = OfflineMoonSea()