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
+64 -2
View File
@@ -88,6 +88,19 @@ class Catalog:
row = self.monster(mon.get("typeId"))
return int(row.get("sell_exp", 0)) + int(float(mon.get("exp", 0)) * self.data["game_setting"].get("monExpScale", 0.2))
def monster_label(self, mon):
species = self.monster(mon.get("typeId")).get("name", "未知魔物")
nickname = mon.get("nicName")
return f"#{mon['id']} {species}" + (f"({nickname})" if nickname and nickname != species else "")
def feed_remaining(self, mon, stop_level):
table = self.data.get("monster_level", {})
limit = table.get(str(stop_level))
current = table.get(str(mon.get("level", 1)))
if limit is None or current is None:
return None
return max(0, int(limit) - max(int(mon.get("exp") or 0), int(current)))
def max_level(self, mon):
info = self.data.get("potential_info", {})
potential = mon.get("potentialLevel")
@@ -333,6 +346,9 @@ class Planner:
level = int(target.get("level", 1))
reason = f"目标 #{mid} Lv.{level};当前突破上限 {cap};喂养停止等级 {limit}"
if level < limit:
if self.catalog.feed_remaining(target, limit) == 0:
reason = f"目标 #{mid} 经验已达到停止等级,等待服务器同步"
continue
return target, reason
return None, reason
@@ -434,6 +450,14 @@ class Planner:
self.notes.append("请到“背包魔物蛋”勾选要孵化的蛋,并设置优先级和孵出后的去向")
return []
actions = []
free_rooms = {}
for room in snapshot.raw["rooms"]:
rid = int(room["id"])
if policy.room_id and rid != policy.room_id:
continue
capacity = int(self.catalog.data["room_info"].get(str(room.get("typeId")), {}).get("maxNum") or 0)
used = sum(m.get("process") == 3 and int(m.get("roomId") or 0) == rid for m in snapshot.raw["monsters"])
free_rooms[rid] = max(0, capacity - used)
for mon in snapshot.raw["monsters"]:
mid = int(mon["id"])
if mid not in self.managed or mon.get("process") not in (2, 3):
@@ -462,8 +486,9 @@ class Planner:
# NetMonster.sellMonsters, whose active parameter is plural.
actions.append(Action("sell", f"派遣 {name} #{mid}", "monsterService/monsterSell", {"monsterIds": [mid]}))
elif mon.get("process") == 2 and policy.collect:
room = snapshot.room_available(self.catalog, policy.room_id)
room = next((rid for rid, free in free_rooms.items() if free > 0), None)
if room is not None:
free_rooms[room] -= 1
actions.append(Action("collect", f"收取 {name} #{mid} → 牧场 {room}", "stackService/stackTransferMonster", {"datas": [{"monsterId": [mid], "roomId": room}]}))
else:
self.notes.append(f"{name} 等待收取:牧场没有空位")
@@ -476,7 +501,7 @@ class Planner:
elif disposition == "keep":
self.notes.append(f"{name} 已保留:{reason}")
if actions:
return actions
return self.batch_actions(actions, snapshot, policy)
vip_info = snapshot.raw.get("activityHistory", {}).get("vipInfo") or {}
vip = seconds(vip_info.get("vipTime")) > snapshot.now
empty = [s for s in snapshot.raw["stacks"] if policy.fill and int(s.get("monsterId") or 0) <= 0 and (int(s.get("position", -1)) != 3 or vip)]
@@ -502,3 +527,40 @@ class Planner:
if not actions and not self.notes:
self.notes.append("等待孵化 / 成长,成熟后按保护条件处理")
return actions or self.purchase(snapshot, policy, daily_left)
def batch_actions(self, actions, snapshot, policy):
monsters = snapshot.monsters
collects = [a for a in actions if a.kind == "collect"]
if collects:
rooms = {}
for action in collects:
for data in action.payload["datas"]:
rooms.setdefault(data["roomId"], []).extend(data["monsterId"])
ids = [mid for mids in rooms.values() for mid in mids]
description = "批量收取 " + "、".join(self.catalog.monster_label(monsters[mid]) for mid in ids)
merged = Action("collect", description, "stackService/stackTransferMonster", {"datas": [{"monsterId": mids, "roomId": room} for room, mids in rooms.items()]})
return [merged] + [a for a in actions if a.kind != "collect"]
feeds = [a for a in actions if a.kind == "feed"]
if not feeds:
return actions
target_id = feeds[0].payload["targetId"]
target = monsters[target_id]
stop_level = min(policy.target_level, self.catalog.max_level(target))
need = self.catalog.feed_remaining(target, stop_level)
ids, experience = [], 0
for action in feeds:
if action.payload["targetId"] != target_id:
continue
for mid in action.payload["foods"]:
if mid in ids:
continue
ids.append(mid)
experience += self.catalog.feed_exp(monsters[mid])
if need is None or experience >= need:
break
if need is None or experience >= need:
break
label = self.catalog.monster_label(target)
foods = "、".join(self.catalog.monster_label(monsters[mid]) for mid in ids)
merged = Action("feed", f"喂养 {label} ← {len(ids)} 只素材:{foods}(经验 {experience})", "monsterService/monsterIntensify", {"targetId": target_id, "foods": ids})
return [merged] + [a for a in actions if a.kind != "feed"]