Fix exploration member selection and automatic reward collection
This commit is contained in:
@@ -621,8 +621,8 @@ class ExplorePlanner:
|
||||
teams = [team for team in snapshot.raw.get("exploreTeams") or [] if isinstance(team, dict)]
|
||||
for team in teams:
|
||||
team_id = _integer(team.get("id"), -1)
|
||||
if (team_id > 0 and self.team_rule(policy, team_id).enabled
|
||||
and _integer(team.get("status")) == 1 and self.remaining(snapshot, team) == 0):
|
||||
if (team_id > 0 and _integer(team.get("status")) == 1
|
||||
and self.remaining(snapshot, team) == 0):
|
||||
return [self._issue(scope, Action("explore_finish", f"领取探险队 {team_id} 的奖励",
|
||||
"exploreService/finish", {"exploreTeamId": team_id}))]
|
||||
stamina = _integer((snapshot.raw.get("master") or {}).get("ti"))
|
||||
@@ -663,6 +663,8 @@ class ExplorePlanner:
|
||||
state = "空闲"
|
||||
if not self.open(snapshot):
|
||||
state, reason = "未解锁", "完成指定主线后解锁探险"
|
||||
elif status == 1 and not rule.enabled:
|
||||
reason = "未启用再次出发;完成时仍会自动领取奖励"
|
||||
elif not rule.enabled:
|
||||
state, reason = "未启用", "勾选此队伍后参与自动探险"
|
||||
elif status != 0:
|
||||
|
||||
@@ -33,12 +33,12 @@ def prepare_exploration_rows(engine):
|
||||
return prepared
|
||||
|
||||
|
||||
def prepare_exploration_members(engine, team_id):
|
||||
def prepare_exploration_members(engine, team_id, policy=None):
|
||||
"""Worker candidate DTOs include protected monsters with exclusion reasons."""
|
||||
if engine.snapshot is None:
|
||||
return []
|
||||
return engine.explore_planner.member_options(engine.snapshot, int(team_id),
|
||||
engine.explore_policy, engine.policy)
|
||||
engine.explore_policy if policy is None else policy, engine.policy)
|
||||
|
||||
|
||||
class ExplorationTable(W.QTableWidget):
|
||||
@@ -263,6 +263,10 @@ class ExplorationPages:
|
||||
self._exploration_drafts.pop(key, None)
|
||||
self._exploration_policy.teams[key] = rule
|
||||
self._save_exploration_policy()
|
||||
self._exploration_member_options.pop(key, None)
|
||||
self._exploration_member_queue = [queued for queued in self._exploration_member_queue if queued != key]
|
||||
self._exploration_member_queue.insert(0, key)
|
||||
self._request_next_exploration_members()
|
||||
elif field == "monster":
|
||||
position, mid = value
|
||||
if not 0 <= position < 3:
|
||||
@@ -384,11 +388,14 @@ class ExplorationPages:
|
||||
return
|
||||
self._exploration_member_busy = True
|
||||
generation = self._exploration_generation
|
||||
policy = self.read_explore_policy()
|
||||
area = policy.teams.get(key, ExploreTeamRule()).area
|
||||
self.submit("exploration_members:" + key,
|
||||
lambda key=key: (generation, key, prepare_exploration_members(self.engine, key)))
|
||||
lambda key=key: (generation, key, area, prepare_exploration_members(self.engine, key, policy)))
|
||||
|
||||
def accept_exploration_members(self, generation, key, options):
|
||||
if generation == self._exploration_generation:
|
||||
def accept_exploration_members(self, generation, key, area, options):
|
||||
current_area = self._exploration_policy.teams.get(key, ExploreTeamRule()).area
|
||||
if generation == self._exploration_generation and area == current_area:
|
||||
self._exploration_member_options[key] = options
|
||||
self.render_exploration(self._exploration_rows)
|
||||
self._exploration_complete_member_request()
|
||||
|
||||
+13
-3
@@ -1615,15 +1615,25 @@ class Window(ExplorationPages, ProgressionPages, ActivityPages, W.QMainWindow):
|
||||
def arm_extended_automation(self):
|
||||
active = self.monitoring and self.strategy_toggle.isChecked() and not self.closed and self.engine.snapshot is not None
|
||||
plans = self.latest_render[1] if self.latest_render else []
|
||||
explore = active and self.explore_enabled.isChecked() and any(
|
||||
explore_ready = active and self.explore_enabled.isChecked() and any(
|
||||
action.kind in ("explore_start", "explore_finish") and action.path for action in plans)
|
||||
breakthrough = active and bool(self.breakthrough_targets) and any(
|
||||
action.kind in ("potential", "breakthrough") for action in plans)
|
||||
now = time.monotonic()
|
||||
for kind, enabled in (("explore", explore), ("breakthrough", breakthrough)):
|
||||
explore_delay = 1.0 if explore_ready else None
|
||||
if active and self.explore_enabled.isChecked() and self.engine.snapshot is not None:
|
||||
for team in self.engine.snapshot.raw.get("exploreTeams") or []:
|
||||
if not isinstance(team, dict) or team.get("status") not in (1, "1"):
|
||||
continue
|
||||
remaining = self.engine.explore_planner.remaining(self.engine.snapshot, team)
|
||||
if remaining is not None:
|
||||
delay = max(1.0, remaining + 1)
|
||||
explore_delay = delay if explore_delay is None else min(explore_delay, delay)
|
||||
for kind, enabled, dispatch_delay in (("explore", explore_delay is not None, explore_delay or 1.0),
|
||||
("breakthrough", breakthrough, 1.0)):
|
||||
attribute = "next_" + kind
|
||||
deadline = getattr(self, attribute)
|
||||
setattr(self, attribute, (now + 1 if deadline == float("inf") else deadline) if enabled else float("inf"))
|
||||
setattr(self, attribute, (now + dispatch_delay if deadline == float("inf") else deadline) if enabled else float("inf"))
|
||||
|
||||
def poll_delay(self):
|
||||
return random.uniform(0, self.interval.currentData())
|
||||
|
||||
@@ -136,6 +136,17 @@ class ExplorationTests(unittest.TestCase):
|
||||
self.assertEqual(self.action().kind, "explore_finish")
|
||||
self.assertEqual(self.planner.rows(self.snapshot, policy(), self.ranch)[0]["monster_ids"], [1, 2, 3])
|
||||
|
||||
def test_finished_team_rewards_without_reenabling_restart(self):
|
||||
team = self.snapshot.raw["exploreTeams"][0]
|
||||
self.start_confirmed(team, end=NOW - 1)
|
||||
disabled = ExplorePolicy(True, {"1": ExploreTeamRule(enabled=False, area="1")})
|
||||
actions = self.planner.plan(self.snapshot, disabled, self.ranch)
|
||||
self.assertEqual([(action.kind, action.path) for action in actions],
|
||||
[("explore_finish", "exploreService/finish")])
|
||||
row = self.planner.rows(self.snapshot, disabled, self.ranch)[0]
|
||||
self.assertEqual(row["state"], "可领取")
|
||||
self.assertIn("仍会自动领取奖励", row["reason"])
|
||||
|
||||
def test_active_zero_or_missing_deadline_is_unknown_and_never_finished(self):
|
||||
for value in (None, 0, "", "not-a-time"):
|
||||
with self.subTest(value=value):
|
||||
|
||||
@@ -14,7 +14,7 @@ from PySide6.QtTest import QTest
|
||||
from ranch_assistant import gui
|
||||
from ranch_assistant.exploration import ExplorePlanner
|
||||
from ranch_assistant.tests.test_core import workspace_temp
|
||||
from ranch_assistant.tests.test_exploration import AREAS, make_snapshot, policy
|
||||
from ranch_assistant.tests.test_exploration import AREAS, NOW, make_snapshot, policy
|
||||
|
||||
|
||||
class ExplorationGuiTests(unittest.TestCase):
|
||||
@@ -61,6 +61,56 @@ class ExplorationGuiTests(unittest.TestCase):
|
||||
def controls(self):
|
||||
return self.window.exploration_table._controls["1"]
|
||||
|
||||
def test_initial_area_selection_loads_members_then_preserves_draft_on_refresh(self):
|
||||
window = self.window
|
||||
window.apply_explore_policy(policy(area=""))
|
||||
window.engine.explore_policy = policy(area="")
|
||||
window.refresh_exploration()
|
||||
self.wait(window, lambda: not window.busy)
|
||||
control = self.controls()
|
||||
self.assertEqual(control["area"].currentData(), "")
|
||||
self.assertTrue(all(combo.count() == 1 for combo in control["members"]))
|
||||
|
||||
control["area"].setCurrentIndex(control["area"].findData("1"))
|
||||
self.wait(window, lambda: all(combo.findData(1) >= 0 for combo in control["members"]))
|
||||
saved = []
|
||||
with patch.object(window, "settings_changed", side_effect=lambda: saved.append(window.read_explore_policy().to_dict())):
|
||||
control["members"][0].setCurrentIndex(control["members"][0].findData(1))
|
||||
self.assertEqual(window._exploration_drafts["1"], [1, None, None])
|
||||
self.assertEqual(window.read_explore_policy().teams["1"].monsters, [])
|
||||
|
||||
window.refresh_exploration()
|
||||
self.wait(window)
|
||||
control = self.controls()
|
||||
self.assertEqual([combo.currentData() for combo in control["members"]], [1, None, None])
|
||||
self.assertEqual(window._exploration_drafts["1"], [1, None, None])
|
||||
self.assertFalse(saved)
|
||||
|
||||
control["members"][1].setCurrentIndex(control["members"][1].findData(2))
|
||||
self.assertFalse(saved)
|
||||
control["members"][2].setCurrentIndex(control["members"][2].findData(3))
|
||||
|
||||
self.assertEqual([combo.currentData() for combo in control["members"]], [1, 2, 3])
|
||||
self.assertEqual(window.read_explore_policy().teams["1"].monsters, [1, 2, 3])
|
||||
self.assertNotIn("1", window._exploration_drafts)
|
||||
self.assertEqual(len(saved), 1)
|
||||
self.assertEqual(saved[0]["teams"]["1"]["monsters"], [1, 2, 3])
|
||||
|
||||
def test_active_snapshot_deadline_arms_without_an_existing_plan(self):
|
||||
window = self.window
|
||||
snapshot = window.engine.snapshot
|
||||
snapshot.raw["exploreTeams"][0].update(
|
||||
status=1, area="1", monsters="1,2,3", endTime=(NOW + 60) * 1000)
|
||||
window.latest_render = (snapshot, [])
|
||||
window.monitoring = True
|
||||
window.set_strategy_checked(True)
|
||||
window.explore_enabled.setChecked(True)
|
||||
window.next_explore = float("inf")
|
||||
now = time.monotonic()
|
||||
with patch.object(gui.time, "monotonic", return_value=now):
|
||||
window.arm_extended_automation()
|
||||
self.assertAlmostEqual(window.next_explore, now + 61, places=2)
|
||||
|
||||
def test_real_window_three_selections_and_busy_policy_queue(self):
|
||||
window = self.window
|
||||
window.refresh_exploration()
|
||||
|
||||
Reference in New Issue
Block a user