Fix gift item instance IDs and per-monster cooldown scheduling
Use bag instance IDs required by the client protocol. Apply confirmed feel and giftDate values across stale queries, skip cooling targets, and schedule ready gifts independently of random polling. Replan cultivation locally and retain local strategy errors in diagnostics.
This commit is contained in:
+61
-3
@@ -147,11 +147,13 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
self.engine = Engine(self.catalog)
|
||||
self.busy, self.monitoring = False, False
|
||||
self.active_job = None
|
||||
self.pending_preview = False
|
||||
self.presentation_active = True
|
||||
self.latest_render = None
|
||||
self.prepared_views = None
|
||||
self.next_poll = 0
|
||||
self.next_hatch = float("inf")
|
||||
self.next_gift = float("inf")
|
||||
self.hatch_timer = C.QTimer(self)
|
||||
self.hatch_timer.setSingleShot(True)
|
||||
self.hatch_timer.setTimerType(C.Qt.TimerType.PreciseTimer)
|
||||
@@ -477,6 +479,8 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
self.gift_status.setWordWrap(True)
|
||||
for widget in (self.gift_enabled, self.gift_auto_representative, self.gift_liked_only, self.gift_status):
|
||||
layout.addWidget(widget)
|
||||
self.gift_clock = W.QLabel("策略已关闭")
|
||||
layout.addWidget(self.gift_clock)
|
||||
for widget in (self.gift_enabled, self.gift_auto_representative, self.gift_liked_only):
|
||||
widget.toggled.connect(self.update_gift_status)
|
||||
note = W.QLabel("自动模式按等级 → 好感 → 综合成长资质选择每种魔物的一只代表,全部相同时随机选定并记住;忽略手动勾选的重复目标。\n代表满好感或冷却时不改喂同种另一只,可继续处理其他种类。礼物开关和保留数量仍在“背包”设置。")
|
||||
@@ -629,6 +633,8 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
self.set_strategy_checked(False)
|
||||
self.engine.auto = False
|
||||
self.pending_execute = False
|
||||
self.next_gift = float("inf")
|
||||
self.update_gift_clock()
|
||||
self.arm_hatching()
|
||||
self.update_workflow_status()
|
||||
|
||||
@@ -850,6 +856,8 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
for secret in (self.token.text(), self.key.text(), self.password.text()):
|
||||
if secret:
|
||||
message = message.replace(secret, "<隐藏>")
|
||||
if "策略暂不可用" in message or "页面数据暂不可用" in message:
|
||||
self.trace.emit("error", "本地策略 / 页面处理", scope="local", message=message)
|
||||
self.log.appendPlainText(time.strftime("%H:%M:%S ") + message)
|
||||
|
||||
def remember_log_sizes(self, *args):
|
||||
@@ -1172,6 +1180,8 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
elif self.pending_refresh is not None:
|
||||
tab, self.pending_refresh = self.pending_refresh, None
|
||||
C.QTimer.singleShot(0, lambda: self.refresh_page(tab))
|
||||
elif self.pending_preview and not self.closed:
|
||||
C.QTimer.singleShot(0, self.preview_cultivation)
|
||||
elif self.pending_execute and self.monitoring and self.strategy_toggle.isChecked() and not self.closed:
|
||||
self.pending_execute = False
|
||||
C.QTimer.singleShot(0, lambda: self.refresh(automated=True))
|
||||
@@ -1195,9 +1205,9 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
note="worker总耗时包含网络;大列表在后续短批次更新")
|
||||
|
||||
def apply_result(self, kind, value):
|
||||
if kind in ("poll", "hatch", "monster_lock", "manual_monsters", "expansion", "growth_sync", "master_sync", "map_refresh", "daily_claim"):
|
||||
if kind in ("poll", "hatch", "monster_lock", "manual_monsters", "expansion", "growth_sync", "master_sync", "map_refresh", "daily_claim", "policy_preview"):
|
||||
snapshot, plans, message = value
|
||||
if not self.engine.demo and not self.closed:
|
||||
if kind != "policy_preview" and not self.engine.demo and not self.closed:
|
||||
self.monitoring = True
|
||||
self.engine.heartbeat_enabled = True
|
||||
self.render(snapshot, plans)
|
||||
@@ -1208,6 +1218,7 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
if "策略暂不可用" in message:
|
||||
self.stop_workflow()
|
||||
self.arm_hatching()
|
||||
self.arm_gifting()
|
||||
elif kind == "heartbeat":
|
||||
self.report(value)
|
||||
elif kind == "analysis":
|
||||
@@ -1384,7 +1395,32 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
self.hatch_timer.stop()
|
||||
self.next_hatch = float("inf")
|
||||
|
||||
def arm_gifting(self):
|
||||
ready_at = self.engine.gift_planner.next_ready_at
|
||||
if (self.monitoring and self.strategy_toggle.isChecked() and self.gift_enabled.isChecked()
|
||||
and not self.closed and self.engine.snapshot is not None and ready_at is not None):
|
||||
self.next_gift = time.monotonic() + max(0, ready_at - self.engine.snapshot.now)
|
||||
else:
|
||||
self.next_gift = float("inf")
|
||||
self.update_gift_clock()
|
||||
|
||||
def update_gift_clock(self):
|
||||
if not hasattr(self, "gift_clock"):
|
||||
return
|
||||
if not self.strategy_toggle.isChecked():
|
||||
text = "策略已关闭"
|
||||
elif not self.gift_enabled.isChecked():
|
||||
text = "自动赠礼未启用"
|
||||
elif self.next_gift == float("inf"):
|
||||
text = "当前没有符合条件的赠礼目标或物品,等待状态更新"
|
||||
else:
|
||||
remaining = self.next_gift - time.monotonic()
|
||||
text = "已有可赠礼目标,正在顺序处理" if remaining <= 0 else "下次可赠礼倒计时:" + duration(remaining)
|
||||
if self.gift_clock.text() != text:
|
||||
self.gift_clock.setText(text)
|
||||
|
||||
def schedule(self):
|
||||
self.update_gift_clock()
|
||||
if self.busy or self.closed:
|
||||
return
|
||||
now = time.monotonic()
|
||||
@@ -1399,6 +1435,8 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
self.refresh(automated=True, hatch_only=True)
|
||||
elif self.monitoring and now >= self.next_poll:
|
||||
self.refresh(automated=True)
|
||||
elif self.monitoring and self.strategy_toggle.isChecked() and now >= self.next_gift:
|
||||
self.refresh(automated=True)
|
||||
|
||||
def render(self, snapshot, plans):
|
||||
self.latest_render = (snapshot, plans)
|
||||
@@ -1738,19 +1776,39 @@ class Window(ActivityPages, W.QMainWindow):
|
||||
return
|
||||
changed = any(asdict(getattr(self.engine, key)) != value[key]
|
||||
for key in ("policy", "quest_policy", "daily_policy", "sweep_policy"))
|
||||
local_selection_changed = any(getattr(self.engine.policy, key) != value["policy"][key]
|
||||
for key in ("gift_auto_representative", "keep_better_quality"))
|
||||
self.engine.policy = Policy(**value["policy"])
|
||||
self.engine.quest_policy = QuestPolicy(**value["quest_policy"])
|
||||
self.engine.daily_policy = DailyPolicy(**value["daily_policy"])
|
||||
self.engine.sweep_policy = SweepPolicy(**value["sweep_policy"])
|
||||
if changed and self.monitoring and self.strategy_toggle.isChecked():
|
||||
if local_selection_changed:
|
||||
self.pending_preview = True
|
||||
self.preview_cultivation()
|
||||
elif changed and self.monitoring and self.strategy_toggle.isChecked():
|
||||
if self.busy:
|
||||
self.pending_execute = True
|
||||
else:
|
||||
self.next_poll = 0
|
||||
self.arm_hatching()
|
||||
self.arm_gifting()
|
||||
self.statusBar().showMessage("规则已自动保存并应用", 3000)
|
||||
return value
|
||||
|
||||
def preview_cultivation(self):
|
||||
if self.closed or self.busy:
|
||||
return
|
||||
self.pending_preview = False
|
||||
if self.engine.snapshot is None:
|
||||
return
|
||||
engine = self.engine
|
||||
def preview():
|
||||
try:
|
||||
return engine.snapshot, engine.plans(), "培养对象已根据已有数据在本地更新"
|
||||
except (ValueError, TypeError, KeyError, AttributeError, OSError) as error:
|
||||
return engine.snapshot, [], f"本地策略暂不可用:{type(error).__name__}: {error}"
|
||||
self.submit("policy_preview", preview)
|
||||
|
||||
def save_config(self, *args, quiet=False):
|
||||
try:
|
||||
value = self.config_value()
|
||||
|
||||
Reference in New Issue
Block a user