Keep multi-account refresh responsive and batch monster feeding

This commit is contained in:
AttilaNet
2026-11-08 00:24:21 +08:00
parent 5f0a9eaac3
commit 67b4658e00
23 changed files with 780 additions and 107 deletions
+15
View File
@@ -27,6 +27,7 @@ class Engine:
self.last_draw = ""
self.growth_cache = {}
self.growth_attempts = {}
self.last_executed = False
folder = Path(budget_path).parent if budget_path else None
self.daily_policy = DailyPolicy()
self.daily_ledger = DailyLedger(folder / "daily_claims.json" if folder else None)
@@ -121,6 +122,7 @@ class Engine:
return "会话心跳已更新"
def poll(self):
self.last_executed = False
settled = False
if self.demo:
if self.snapshot is None:
@@ -143,6 +145,7 @@ class Engine:
return self.snapshot, [], "状态已读取;策略暂不可用:" + str(error)
if self.auto and plans:
action = plans[0]
self.last_executed = True
if action.kind == "daily":
entry = next(row for row in selected_entries(self.catalog, self.snapshot, self.daily_policy, self.daily_ledger) if row.action == action)
self.claim_daily_entry(entry)
@@ -164,6 +167,9 @@ class Engine:
if action.kind == "buy":
self.record_draw(response.get("eggs") or [])
self.read_snapshot()
if action.kind == "feed" and any(mid in self.snapshot.monsters for mid in action.payload["foods"]):
self.auto = False
raise ValueError("喂养已返回,但素材状态尚未同步;已停止,请刷新核对后再继续")
message = ("[演示] " if self.demo else "") + action.description
if action.kind == "buy" and self.last_draw:
message += ";" + self.last_draw
@@ -293,6 +299,15 @@ class Engine:
return self.snapshot, self.plans(), ("[演示] " if self.demo else "") + quote.description + ",已完成"
def apply_demo(self, action):
if action.kind == "collect" and sum(len(d["monsterId"]) for d in action.payload["datas"]) > 1:
for data in action.payload["datas"]:
for mid in data["monsterId"]:
self.apply_demo(replace(action, payload={"datas": [{"monsterId": [mid], "roomId": data["roomId"]}]}))
return
if action.kind == "feed" and len(action.payload["foods"]) > 1:
for mid in action.payload["foods"]:
self.apply_demo(replace(action, payload=action.payload | {"foods": [mid]}))
return
raw = self.snapshot.raw
if action.kind.startswith("quest_"):
self.apply_demo_quest(action)