Settle player level and stamina; unify strategy configuration

This commit is contained in:
AttilaNet
2026-11-08 10:46:25 +08:00
parent d0fd15c785
commit 2498f1f98f
10 changed files with 550 additions and 48 deletions
+15 -3
View File
@@ -10,6 +10,7 @@ from .quests import QuestPolicy, TaskPlanner
from .market import PurchaseBudget
from .management import expansion_quote, manual_monster_actions
from .gifts import GiftPlanner
from .master_sync import MasterSync
class Engine:
@@ -31,6 +32,7 @@ class Engine:
self.last_draw = ""
self.growth_cache = {}
self.growth_attempts = {}
self.master_sync = MasterSync(catalog)
self.last_executed = False
folder = Path(budget_path).parent if budget_path else None
self.daily_policy = DailyPolicy()
@@ -38,8 +40,11 @@ class Engine:
self.sweep_policy = SweepPolicy()
self.sweeper = SweepRunner(catalog, folder / "sweep_runs.json" if folder else None)
def read_snapshot(self):
def read_snapshot(self, *, sync_master=True):
self.snapshot = self.client.snapshot()
self.master_sync.apply(self.snapshot)
if sync_master:
self.master_sync.settle(self.client, self.snapshot)
present = self.snapshot.monsters
self.growth_cache = {mid: entry for mid, entry in self.growth_cache.items() if mid in present}
self.growth_attempts = {key: stamp for key, stamp in self.growth_attempts.items() if key[0] in present}
@@ -69,6 +74,13 @@ class Engine:
self.snapshot.raw["monsters"] = rows
return self.snapshot
def master_sync_due(self):
return not self.demo and bool(self.master_sync.pending(self.snapshot))
def sync_master(self):
self.read_snapshot()
return self.snapshot, self.plans(), "已同步等级 / 体力"
def remember_growth(self, response):
# MonsterCenter.checkGrowUpHandler treats these two arrays as the
# authoritative stage and growth values, including after a stale read.
@@ -140,7 +152,7 @@ class Engine:
if mon.get("process") == 2:
mon["mode"] = self.snapshot.expected_growth_mode(mon, self.catalog)
else:
self.read_snapshot()
self.read_snapshot(sync_master=not hatch_only)
if not hatch_only:
settled = self.settle_pending_growth()
message = "状态已刷新" + (";已请求孵化 / 成长结算" if settled else "")
@@ -177,7 +189,7 @@ class Engine:
response = self.client.call(action.path, action.payload)
if action.kind == "buy":
self.record_draw(response.get("eggs") or [])
self.read_snapshot()
self.read_snapshot(sync_master=not hatch_only)
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)