fix: keep automatic cultivation on one stable primary per species
This commit is contained in:
@@ -27,7 +27,7 @@ from .progression import ProgressionIntent, ProgressionPlanner, ProgressionPolic
|
||||
from .battle_messages import battle_message
|
||||
from .maps import stages
|
||||
from .exploration import ExplorePlanner, ExplorePolicy
|
||||
from .breakthrough import BreakthroughPlanner
|
||||
from .breakthrough import BreakthroughPlanner, primary_target_reason
|
||||
|
||||
|
||||
def account_serial(method):
|
||||
@@ -87,7 +87,7 @@ class Engine:
|
||||
self.sweeper = SweepRunner(catalog, folder / "sweep_runs.json" if folder else None)
|
||||
self.explore_planner = ExplorePlanner(catalog)
|
||||
self.explore_policy = ExplorePolicy()
|
||||
self.breakthrough_planner = BreakthroughPlanner(catalog)
|
||||
self.breakthrough_planner = BreakthroughPlanner(catalog, self.cultivation)
|
||||
self.automation_state_path = folder / "automation_state.json" if folder else None
|
||||
self._explore_pending_last_check = 0
|
||||
self._explore_pending_confirmed = False
|
||||
@@ -283,9 +283,37 @@ class Engine:
|
||||
self.auto = False
|
||||
raise
|
||||
|
||||
def cultivation_target_reason(self, monster_id, *, primaries=None):
|
||||
return primary_target_reason(self.catalog, self.cultivation, self.snapshot, monster_id, primaries=primaries)
|
||||
|
||||
def _automatic_cultivation_reason(self, action, *, primaries=None):
|
||||
recipient_key = {"feed": "targetId", "gift": "monsterId", "potential": "monId", "breakthrough": "monId"}.get(action.kind)
|
||||
return self.cultivation_target_reason(action.payload.get(recipient_key), primaries=primaries) if recipient_key else ""
|
||||
|
||||
def _admit_automatic_cultivation(self, actions):
|
||||
primaries = self.cultivation.select(self.snapshot)
|
||||
admitted = []
|
||||
for action in actions:
|
||||
reason = self._automatic_cultivation_reason(action, primaries=primaries)
|
||||
if reason:
|
||||
self.planner.notes.append("跳过自动操作:" + reason)
|
||||
else:
|
||||
admitted.append(action)
|
||||
return admitted
|
||||
|
||||
def _skip_automatic_cultivation(self, reason):
|
||||
self.last_executed = False
|
||||
plans = self.plans()
|
||||
self.planner.notes.append("跳过自动操作:" + reason)
|
||||
return self.snapshot, plans, "跳过自动操作:" + reason
|
||||
|
||||
def _execute_breakthrough(self, action):
|
||||
self.last_executed = False
|
||||
if self._breakthrough_pending:
|
||||
return self.snapshot, [], "突破请求待核对,禁止重发"
|
||||
reason = self._automatic_cultivation_reason(action)
|
||||
if reason:
|
||||
return self._skip_automatic_cultivation(reason)
|
||||
mon = self.snapshot.monsters[int(action.payload["monId"])]
|
||||
attribute = action.payload.get("monsterAttr", "")
|
||||
before = mon.get("p" + attribute.capitalize()) if action.kind == "potential" else mon.get("potentialLevel")
|
||||
@@ -305,7 +333,14 @@ class Engine:
|
||||
if not self.auto or self._progression_cancel.is_set():
|
||||
self._discard_unsent_automation()
|
||||
return self.snapshot, self.plans(), "突破请求尚未发送,已取消"
|
||||
reason = self._automatic_cultivation_reason(action)
|
||||
if reason:
|
||||
# Only this newly journaled, unsent request may be discarded. An
|
||||
# older pending request returned above and must retain its evidence.
|
||||
self._discard_unsent_automation()
|
||||
return self._skip_automatic_cultivation(reason)
|
||||
try:
|
||||
self.last_executed = True
|
||||
response = self.client.call(action.path, deepcopy(action.payload))
|
||||
if not isinstance(response, dict) or response.get("resCode", 0) not in (0, "0"):
|
||||
raise ValueError("突破请求尚未确认成功")
|
||||
@@ -1061,6 +1096,9 @@ class Engine:
|
||||
self.last_executed = True
|
||||
return self._execute_breakthrough(action)
|
||||
if self.auto and action is not None:
|
||||
reason = self._automatic_cultivation_reason(action)
|
||||
if reason:
|
||||
return self._skip_automatic_cultivation(reason)
|
||||
self.last_executed = True
|
||||
if action.kind == "progression":
|
||||
return self._run_progression_intent(action.payload["intent"])
|
||||
@@ -1146,8 +1184,14 @@ class Engine:
|
||||
if not self.auto or self._progression_cancel.is_set():
|
||||
return self.snapshot, plans, "策略已停止,快速操作未执行"
|
||||
if action is None:
|
||||
return self.snapshot, plans, {"explore": "探险", "breakthrough": "突破",
|
||||
message = {"explore": "探险", "breakthrough": "突破",
|
||||
"gift": "赠礼", "hatch": "孵化"}[kind] + "当前无可执行动作"
|
||||
if self.planner.notes:
|
||||
message += ";" + ";".join(dict.fromkeys(self.planner.notes))
|
||||
return self.snapshot, plans, message
|
||||
reason = self._automatic_cultivation_reason(action)
|
||||
if reason:
|
||||
return self._skip_automatic_cultivation(reason)
|
||||
self.last_executed = True
|
||||
if kind == "explore":
|
||||
return self._execute_explore(action)
|
||||
@@ -1298,8 +1342,7 @@ class Engine:
|
||||
if self.snapshot is None or self._progression_pending():
|
||||
self.pending_hatches = []
|
||||
return []
|
||||
if self.policy.keep_better_quality or self.policy.gift_auto_representative:
|
||||
self.cultivation.select(self.snapshot)
|
||||
primaries = self.cultivation.select(self.snapshot)
|
||||
# One owner for commission writes; never accept the same offer through
|
||||
# both the legacy planner and the full progression planner.
|
||||
quests = [] if self._commission_planner_available else self.tasks.plan(self.snapshot, self.quest_policy, self.policy)
|
||||
@@ -1318,18 +1361,29 @@ class Engine:
|
||||
ranch = self.planner.plan(self.snapshot, policy, left)
|
||||
explore = self.explore_planner.plan(self.snapshot, self.explore_policy, policy)
|
||||
breakthrough_policy = SimpleNamespace(**(asdict(policy) | {"item_reserves": dict(self.quest_policy.item_reserves)}))
|
||||
self.breakthrough_planner.notes = []
|
||||
breakthrough = self.breakthrough_planner.plan(self.snapshot, breakthrough_policy,
|
||||
targets=policy.breakthrough_targets, enabled=not self._breakthrough_pending) if policy.breakthrough_targets else None
|
||||
self.planner.notes.extend(self.gift_planner.notes)
|
||||
self.planner.notes.extend(self.breakthrough_planner.notes)
|
||||
feed_targets = policy.feed_targets or ({str(policy.feed_target): 1} if policy.feed_target else {})
|
||||
for enabled, targets in (
|
||||
(policy.enabled and policy.feed, feed_targets),
|
||||
(policy.gift_enabled and not policy.gift_auto_representative, policy.gift_targets),
|
||||
(policy.enabled, policy.breakthrough_targets)):
|
||||
if enabled:
|
||||
for mid in targets:
|
||||
reason = self.cultivation_target_reason(mid, primaries=primaries)
|
||||
if reason:
|
||||
self.planner.notes.append("跳过自动目标:" + reason)
|
||||
breakthroughs = [breakthrough] if breakthrough else []
|
||||
progression = [Action("progression", value(intent, "description", "推进任务"), "", {"intent": intent})
|
||||
for intent in self._progression_intents if not value(intent, "block_reason") and self._intent_policy(intent).enabled]
|
||||
commission = [action for action in progression if self._is_commission(action.payload["intent"])]
|
||||
progression = [action for action in progression if not self._is_commission(action.payload["intent"])]
|
||||
if quests and quests[0].kind == "quest_reset":
|
||||
return quests + commission[:1] + daily + progression[:1] + explore + breakthroughs + gifts + ranch + sweep_actions
|
||||
return commission[:1] + quests + daily + progression[:1] + explore + breakthroughs + gifts + ranch + sweep_actions
|
||||
return self._admit_automatic_cultivation(quests + commission[:1] + daily + progression[:1] + explore + breakthroughs + gifts + ranch + sweep_actions)
|
||||
return self._admit_automatic_cultivation(commission[:1] + quests + daily + progression[:1] + explore + breakthroughs + gifts + ranch + sweep_actions)
|
||||
|
||||
@account_serial
|
||||
def claim_daily_entry(self, entry):
|
||||
|
||||
Reference in New Issue
Block a user