Schedule hatch filling independently every 1-2 seconds
This commit is contained in:
@@ -16,6 +16,8 @@ class Engine:
|
||||
def __init__(self, catalog, client=None, budget_path=None):
|
||||
self.catalog, self.client = catalog, client
|
||||
self.planner = Planner(catalog)
|
||||
self.hatch_planner = Planner(catalog)
|
||||
self.pending_hatches = []
|
||||
self.gift_planner = GiftPlanner(catalog)
|
||||
self.policy = Policy()
|
||||
self.quest_policy = QuestPolicy()
|
||||
@@ -128,7 +130,7 @@ class Engine:
|
||||
self.client.call("heartBeatService/keepAlive")
|
||||
return "会话心跳已更新"
|
||||
|
||||
def poll(self):
|
||||
def poll(self, *, hatch_only=False, defer_hatch=False):
|
||||
self.last_executed = False
|
||||
settled = False
|
||||
if self.demo:
|
||||
@@ -139,7 +141,8 @@ class Engine:
|
||||
mon["mode"] = self.snapshot.expected_growth_mode(mon, self.catalog)
|
||||
else:
|
||||
self.read_snapshot()
|
||||
settled = self.settle_pending_growth()
|
||||
if not hatch_only:
|
||||
settled = self.settle_pending_growth()
|
||||
message = "状态已刷新" + (";已请求孵化 / 成长结算" if settled else "")
|
||||
if self.snapshot.growth_pending(self.catalog):
|
||||
message += ";成长状态等待服务器确认,将自动检查"
|
||||
@@ -148,8 +151,11 @@ class Engine:
|
||||
except (ValueError, TypeError, KeyError, AttributeError) as error:
|
||||
self.auto = False
|
||||
return self.snapshot, [], "状态已读取;策略暂不可用:" + str(error)
|
||||
if self.auto and plans:
|
||||
action = plans[0]
|
||||
actions = self.pending_hatches if hatch_only else plans
|
||||
action = actions[0] if actions else None
|
||||
if action and defer_hatch and action.kind == "hatch":
|
||||
action = None
|
||||
if self.auto and action is not None:
|
||||
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)
|
||||
@@ -172,6 +178,12 @@ class Engine:
|
||||
if action.kind == "buy":
|
||||
self.record_draw(response.get("eggs") or [])
|
||||
self.read_snapshot()
|
||||
if action.kind == "hatch":
|
||||
stack_id = action.payload["eggs"][0]["stackId"]
|
||||
slot = next((slot for slot in self.snapshot.raw["stacks"] if int(slot["id"]) == stack_id), None)
|
||||
if slot is None or int(slot.get("monsterId") or 0) <= 0:
|
||||
self.auto = False
|
||||
raise ValueError("装填已返回,但坑位状态尚未同步;已停止,请刷新核对后再继续")
|
||||
if action.kind == "feed" and any(mid in self.snapshot.monsters for mid in action.payload["foods"]):
|
||||
self.auto = False
|
||||
raise ValueError("喂养已返回,但素材状态尚未同步;已停止,请刷新核对后再继续")
|
||||
@@ -195,6 +207,8 @@ class Engine:
|
||||
for key, count in eggs.items():
|
||||
reserved[key] = max(reserved.get(key, 0), count)
|
||||
policy = replace(self.policy, reserved_types=list(set(self.policy.reserved_types) | types), reserved_eggs=reserved)
|
||||
self.hatch_planner.notes = []
|
||||
self.pending_hatches = self.hatch_planner.hatch_actions(self.snapshot, policy)
|
||||
left = self.purchase_budget.remaining(self.snapshot.now, policy.daily_buy_money)
|
||||
daily = [row.action for row in selected_entries(self.catalog, self.snapshot, self.daily_policy, self.daily_ledger)] if self.daily_policy.enabled else []
|
||||
sweep = self.sweeper.next(self.snapshot, self.sweep_policy) if self.sweep_policy.enabled and not self.demo else None
|
||||
|
||||
Reference in New Issue
Block a user