fix: keep automatic cultivation on one stable primary per species
This commit is contained in:
+222
-155
@@ -6,6 +6,7 @@ import math
|
||||
from pathlib import Path
|
||||
import time
|
||||
from .cultivation import CultivationSelector, growth_score, quality_rank, quality_summary
|
||||
from .team_availability import _exploring_ids
|
||||
|
||||
WIKI = "https://wiki.biligame.com/myrzx/魔物收益表"
|
||||
|
||||
@@ -369,57 +370,70 @@ class Planner:
|
||||
self.retained = set()
|
||||
self.retention_reasons = {}
|
||||
self.representatives = {}
|
||||
self.backups = {}
|
||||
self.retention_owner = None
|
||||
self.dispatch_extras = set()
|
||||
self.preparing_retention = False
|
||||
self.retention_signature = None
|
||||
self.tp_feed_targets = set()
|
||||
self.food_protection = {}
|
||||
|
||||
def protected(self, mon, snapshot, policy):
|
||||
self.ensure_retention(snapshot, policy)
|
||||
return bool(self.protection_reason(mon, snapshot, policy))
|
||||
|
||||
def ensure_retention(self, snapshot, policy):
|
||||
if not policy.manual_eggs:
|
||||
if self.preparing_retention:
|
||||
return
|
||||
signature = (repr(snapshot.raw.get("monsters")), repr(snapshot.raw.get("teams")),
|
||||
signature = (str(snapshot.raw["master"]["id"]),
|
||||
repr(snapshot.raw.get("monsters")), repr(snapshot.raw.get("teams")),
|
||||
repr(snapshot.raw.get("exploreTeams")),
|
||||
repr((policy.manual_eggs, policy.egg_rules, policy.keep_better_quality,
|
||||
policy.gift_auto_representative, policy.protect_star, policy.protect_quality,
|
||||
policy.feed_target, policy.feed_targets, policy.breakthrough_targets, policy.reserved_types)))
|
||||
policy.feed_target, policy.feed_targets, policy.gift_targets,
|
||||
policy.breakthrough_targets, policy.reserved_types)))
|
||||
if signature != self.retention_signature:
|
||||
self.prepare_retention(snapshot, policy)
|
||||
self.retention_signature = signature
|
||||
|
||||
def protection_reason(self, mon, snapshot, policy):
|
||||
@staticmethod
|
||||
def species_rule(mon, policy):
|
||||
rule = policy.egg_rules.get(str(mon.get("typeId")), {}) if policy.manual_eggs else {}
|
||||
return rule if rule.get("enabled") else {}
|
||||
|
||||
def hard_protection_reason(self, mon, snapshot, policy):
|
||||
"""Explicit reservations and incomplete data are independent of slot limits."""
|
||||
row = self.catalog.monster(mon.get("typeId"))
|
||||
qualities = self.catalog.quality(mon)
|
||||
legacy_protection = not self.species_rule(mon, policy)
|
||||
for condition, reason in ((not row, "魔物资料未知"), (int(mon["id"]) in snapshot.team_ids, "在队魔物"),
|
||||
(mon.get("lock"), "已锁定"), (mon.get("sysLock"), "系统锁定"), (mon.get("entangle"), "羁绊魔物"),
|
||||
(mon.get("inExploreTeam"), "正在探索"), (mon.get("inBuild"), "正在建筑中"),
|
||||
(mon.get("inExploreTeam") or int(mon["id"]) in _exploring_ids(snapshot), "正在探索"),
|
||||
(mon.get("inBuild"), "正在建筑中"),
|
||||
(any(mon.get(f"equip{i}", 0) for i in range(1, 6)), "携带装备"),
|
||||
(int(mon["id"]) == policy.feed_target or str(mon["id"]) in policy.feed_targets, "已选为喂养目标"),
|
||||
(str(mon["id"]) in policy.breakthrough_targets, "已选为自动突破目标"),
|
||||
(legacy_protection and (int(mon["id"]) == policy.feed_target or str(mon["id"]) in policy.feed_targets), "已选为喂养目标"),
|
||||
(legacy_protection and str(mon["id"]) in policy.gift_targets, "已选为赠礼目标"),
|
||||
(legacy_protection and str(mon["id"]) in policy.breakthrough_targets, "已选为自动突破目标"),
|
||||
(str(mon.get("typeId")) in {str(t) for t in policy.reserved_types}, "保留种类或委托保留"),
|
||||
(row.get("star", 0) >= policy.protect_star, f"{row.get('star', '?')}星达到保留星级{policy.protect_star}"),
|
||||
(legacy_protection and row.get("star", 0) >= policy.protect_star, f"{row.get('star', '?')}星达到保留星级{policy.protect_star}"),
|
||||
(any(q is None for q in qualities), "资质尚未确定 / 未同步")):
|
||||
if condition:
|
||||
return reason
|
||||
|
||||
return ""
|
||||
|
||||
def protection_reason(self, mon, snapshot, policy):
|
||||
self.ensure_retention(snapshot, policy)
|
||||
reason = self.hard_protection_reason(mon, snapshot, policy)
|
||||
if reason:
|
||||
return reason
|
||||
if int(mon["id"]) in self.retained:
|
||||
return self.retention_reasons[int(mon["id"])]
|
||||
# Enabled species use fixed primary/backup slots. Automatic grade
|
||||
# thresholds and legacy keep_count must not protect every duplicate.
|
||||
if self.species_rule(mon, policy):
|
||||
return ""
|
||||
qualities = self.catalog.quality(mon)
|
||||
quality = math.ceil(sum(qualities) / 4)
|
||||
if (policy.keep_better_quality or policy.gift_auto_representative) and not policy.manual_eggs:
|
||||
representative = (self.representatives if policy.manual_eggs else self.cultivation.select(snapshot)).get(str(mon.get("typeId")))
|
||||
if policy.gift_auto_representative and representative and int(representative["id"]) == int(mon["id"]):
|
||||
return "同种魔物的唯一培养代表(等级、好感、资质优先)"
|
||||
if policy.keep_better_quality and not self.preparing_retention:
|
||||
if representative is None:
|
||||
return "牧场尚无同种魔物,保留首次获得的魔物"
|
||||
baseline, candidate = quality_rank(self.catalog, representative), quality_rank(self.catalog, mon)
|
||||
if baseline is None:
|
||||
return "同种培养代表的资质尚未同步,暂时保留"
|
||||
if candidate is not None and candidate > baseline:
|
||||
return (f"资质优于同种培养代表 #{representative['id']}"
|
||||
f"({quality_summary(self.catalog, mon)} / S项{candidate[0]} > "
|
||||
f"{quality_summary(self.catalog, representative)} / S项{baseline[0]})")
|
||||
if policy.protect_quality == 6:
|
||||
return "攻/防/生命/敏捷四项资质全S(4S)" if all(q == 4 for q in qualities) else ""
|
||||
if quality >= policy.protect_quality:
|
||||
@@ -427,100 +441,82 @@ class Planner:
|
||||
return ""
|
||||
|
||||
def prepare_retention(self, snapshot, policy):
|
||||
"""Allocate each species quota once for all ranches and this hatch batch."""
|
||||
"""One primary and one strictly better backup across ranches/incubators."""
|
||||
owner = str(snapshot.raw["master"]["id"])
|
||||
previous_backups = self.backups if self.retention_owner == owner else {}
|
||||
self.retention_owner = owner
|
||||
self.backups, self.dispatch_extras = {}, set()
|
||||
self.retained, self.retention_reasons, self.representatives = set(), {}, {}
|
||||
self.retention_signature = None
|
||||
if not policy.manual_eggs:
|
||||
return
|
||||
self.preparing_retention = True
|
||||
try:
|
||||
for mon in snapshot.raw["monsters"]:
|
||||
if mon.get("process") == 3:
|
||||
reason = self.protection_reason(mon, snapshot, policy)
|
||||
if reason:
|
||||
self.retained.add(int(mon["id"]))
|
||||
self.retention_reasons[int(mon["id"])] = reason
|
||||
finally:
|
||||
self.preparing_retention = False
|
||||
self.representatives = self.cultivation.select(snapshot)
|
||||
|
||||
self.representatives = dict(self.cultivation.select(snapshot))
|
||||
groups = {}
|
||||
for mon in snapshot.raw["monsters"]:
|
||||
if mon.get("process") in (2, 3) and int(mon.get("mode") or 0) == 2:
|
||||
if mon.get("process") == 3 or mon.get("process") == 2 and int(mon.get("mode") or 0) == 2:
|
||||
groups.setdefault(str(mon.get("typeId")), []).append(mon)
|
||||
for key, rule in policy.egg_rules.items():
|
||||
if not rule.get("enabled"):
|
||||
for key, members in groups.items():
|
||||
mandatory = bool(self.species_rule(members[0], policy))
|
||||
if not mandatory and not (not policy.manual_eggs and
|
||||
(policy.keep_better_quality or policy.gift_auto_representative)):
|
||||
continue
|
||||
members = groups.get(key, [])
|
||||
representative = self.representatives.get(key)
|
||||
if representative is None and members:
|
||||
representative = min(members, key=lambda row: (quality_rank(self.catalog, row) is None,
|
||||
tuple(-value for value in (quality_rank(self.catalog, row) or ())), int(row["id"])))
|
||||
quota = int(rule.get("keep_count", 1))
|
||||
occupied = sum(row.get("process") == 3 and int(row["id"]) in self.retained for row in members)
|
||||
if quota > 0 and representative is not None and representative.get("process") == 3 and occupied < quota:
|
||||
mid = int(representative["id"])
|
||||
already_retained = mid in self.retained
|
||||
self.retained.add(mid)
|
||||
self.retention_reasons[mid] = f"同种稳定培养代表,牧场保留数量 1 / {quota}"
|
||||
occupied += int(representative.get("process") == 3 and not already_retained)
|
||||
ranch = [row for row in members if row.get("process") == 3 and int(row["id"]) not in self.retained]
|
||||
ranch.sort(key=lambda row: (quality_rank(self.catalog, row) is None,
|
||||
tuple(-value for value in (quality_rank(self.catalog, row) or ())), int(row["id"])))
|
||||
used = occupied
|
||||
quality_baseline = [quality_rank(self.catalog, row) for row in members
|
||||
if row.get("process") == 3 and int(row["id"]) in self.retained]
|
||||
quality_baseline = [value for value in quality_baseline if value is not None]
|
||||
for row in ranch:
|
||||
if used >= quota:
|
||||
break
|
||||
used += 1
|
||||
self.retained.add(int(row["id"]))
|
||||
self.retention_reasons[int(row["id"])] = f"同种牧场保留数量 {used} / {quota}"
|
||||
rank = quality_rank(self.catalog, row)
|
||||
if rank is not None:
|
||||
quality_baseline.append(rank)
|
||||
|
||||
incubator = [row for row in members if row.get("process") == 2 and int(row["id"]) not in self.retained]
|
||||
incubator.sort(key=lambda row: (quality_rank(self.catalog, row) is None,
|
||||
tuple(-value for value in (quality_rank(self.catalog, row) or ())), int(row["id"])))
|
||||
for row in incubator:
|
||||
if used >= quota:
|
||||
break
|
||||
used += 1
|
||||
self.retained.add(int(row["id"]))
|
||||
self.retention_reasons[int(row["id"])] = f"同种牧场及培育室保留数量 {used} / {quota}"
|
||||
rank = quality_rank(self.catalog, row)
|
||||
if rank is not None:
|
||||
quality_baseline.append(rank)
|
||||
|
||||
# Compare with the best retained ranch quality, not repeatedly
|
||||
# with an inferior locked monster. Select at most one improvement
|
||||
# per snapshot, including the newly collected batch as one group.
|
||||
if policy.keep_better_quality and quality_baseline:
|
||||
baseline = max(quality_baseline)
|
||||
candidates = [(quality_rank(self.catalog, row), row) for row in members
|
||||
if int(row["id"]) not in self.retained]
|
||||
candidates = [(rank, row) for rank, row in candidates if rank is not None and rank > baseline]
|
||||
if candidates:
|
||||
rank, row = min(candidates, key=lambda pair: (-pair[0][0], -pair[0][1], -pair[0][2], -pair[0][3], int(pair[1]["id"])))
|
||||
self.retained.add(int(row["id"]))
|
||||
self.retention_reasons[int(row["id"])] = (
|
||||
f"额外保留更优资质 {quality_summary(self.catalog, row)} / S项{rank[0]},"
|
||||
f"牧场已保留最高资质 S项{baseline[0]}")
|
||||
# If the only mature monster is still incubating, it becomes the
|
||||
# representative upon collection rather than being disposed first.
|
||||
if quota > 0 and not any(int(row["id"]) in self.retained for row in members) and members:
|
||||
row = members[0]
|
||||
self.retained.add(int(row["id"]))
|
||||
self.retention_reasons[int(row["id"])] = f"同种本批培养代表,牧场保留数量 1 / {quota}"
|
||||
primary = self.representatives.get(key)
|
||||
if primary is None:
|
||||
saved_id = getattr(self.cultivation, "choices", {}).get(key)
|
||||
saved = snapshot.monsters.get(saved_id)
|
||||
# A saved primary that is still in the roster can be temporarily
|
||||
# unavailable. Only confirmed removal permits a replacement.
|
||||
primary = saved if saved is not None and str(saved.get("typeId")) == key else min(
|
||||
members, key=lambda row: int(row["id"]))
|
||||
self.representatives[key] = primary
|
||||
primary_id = int(primary["id"])
|
||||
self.retained.add(primary_id)
|
||||
self.retention_reasons[primary_id] = ("牧场尚无同种魔物,保留首次成熟的主培养魔物"
|
||||
if primary.get("process") != 3 else "同种稳定主培养代表(等级、好感、资质优先)")
|
||||
baseline = quality_rank(self.catalog, primary)
|
||||
candidates = [(quality_rank(self.catalog, mon), mon) for mon in members
|
||||
if int(mon["id"]) != primary_id]
|
||||
if baseline is None:
|
||||
for _, mon in candidates:
|
||||
mid = int(mon["id"])
|
||||
self.retained.add(mid)
|
||||
self.retention_reasons[mid] = f"同种主培养代表 #{primary_id} 当前不可用或资质尚未同步,暂时保护"
|
||||
continue
|
||||
if mandatory or policy.keep_better_quality:
|
||||
better = [(rank, mon) for rank, mon in candidates if rank is not None and rank > baseline]
|
||||
if better:
|
||||
previous_id = int(previous_backups.get(key, {}).get("id", 0))
|
||||
rank, backup = min(better, key=lambda pair: (
|
||||
tuple(-value for value in pair[0]), pair[1].get("process") != 3,
|
||||
int(pair[1]["id"]) != previous_id, int(pair[1]["id"])))
|
||||
mid = int(backup["id"])
|
||||
self.backups[key] = backup
|
||||
self.retained.add(mid)
|
||||
self.retention_reasons[mid] = (f"唯一资质备用,优于同种培养代表 #{primary_id}:"
|
||||
f"{quality_summary(self.catalog, backup)} / S项{rank[0]};不喂养、不赠礼")
|
||||
for rank, mon in candidates:
|
||||
mid = int(mon["id"])
|
||||
if mid in self.retained:
|
||||
continue
|
||||
reason = self.hard_protection_reason(mon, snapshot, policy)
|
||||
if reason:
|
||||
self.retained.add(mid)
|
||||
self.retention_reasons[mid] = "同种额外魔物受保护:" + reason
|
||||
elif mandatory and (rank is not None and rank >= baseline
|
||||
or mid == int(previous_backups.get(key, {}).get("id", 0))):
|
||||
self.dispatch_extras.add(mid)
|
||||
|
||||
def disposition(self, mon, snapshot, policy):
|
||||
if self.protected(mon, snapshot, policy):
|
||||
return "keep"
|
||||
if policy.manual_eggs:
|
||||
rule = policy.egg_rules.get(str(mon["typeId"]), {})
|
||||
return rule.get("action", "keep") if rule.get("enabled") else "keep"
|
||||
if not rule.get("enabled"):
|
||||
return "keep"
|
||||
# Only recorded hatch ownership authorizes using an old monster as
|
||||
# food. Enabled-species cleanup separately authorizes dispatch.
|
||||
if (int(mon["id"]) in self.dispatch_extras or rule.get("action") != "feed"
|
||||
or int(mon["id"]) not in self.managed):
|
||||
return "sell"
|
||||
return "feed"
|
||||
if policy.strategy == "keep":
|
||||
return "keep"
|
||||
if policy.strategy in ("gold", "experience"):
|
||||
@@ -536,6 +532,10 @@ class Planner:
|
||||
target = snapshot.monsters.get(mid)
|
||||
if not target or target.get("process") != 3:
|
||||
continue
|
||||
blocked = self.primary_target_reason(target, snapshot)
|
||||
if blocked:
|
||||
reason = blocked
|
||||
continue
|
||||
cap = self.catalog.max_level(target)
|
||||
if cap is None:
|
||||
reason = "目标突破上限未知,暂停喂养"
|
||||
@@ -550,6 +550,18 @@ class Planner:
|
||||
return target, reason
|
||||
return None, reason
|
||||
|
||||
def primary_target_reason(self, target, snapshot):
|
||||
"""A backup can be protected as food without being a cultivation target."""
|
||||
primary = self.cultivation.select(snapshot).get(str(target.get("typeId")))
|
||||
if primary is None:
|
||||
return "该种主培养魔物尚未收取到牧场,暂停喂养"
|
||||
if int(primary["id"]) != int(target["id"]):
|
||||
return f"目标 #{target['id']} 不是同种主培养代表 #{primary['id']},保留原勾选并暂停该目标"
|
||||
if (target.get("process") != 3 or target.get("inExploreTeam") or int(target["id"]) in _exploring_ids(snapshot)
|
||||
or target.get("inBuild") or target.get("sysLock")):
|
||||
return f"同种主培养代表 #{target['id']} 当前不可用,暂停喂养"
|
||||
return ""
|
||||
|
||||
def feed_status(self, snapshot, policy):
|
||||
target, reason = self.feeding_target(snapshot, policy)
|
||||
return target is not None, reason
|
||||
@@ -584,44 +596,35 @@ class Planner:
|
||||
return max(0, thresholds[4] - int(target.get("tpExp")))
|
||||
|
||||
def same_species_feeding_target(self, mon, snapshot, policy, exclude=()):
|
||||
"""Prefer an unfinished same-species TP target; never consume a representative."""
|
||||
"""Feed only the primary; its caps never authorize a duplicate target."""
|
||||
self.ensure_retention(snapshot, policy)
|
||||
if mon.get("process") != 3:
|
||||
return None, "素材尚未收取到牧场"
|
||||
excluded = {int(mid) for mid in exclude} | {int(mon["id"])}
|
||||
candidates = [row for row in snapshot.raw["monsters"] if row.get("process") == 3
|
||||
and str(row.get("typeId")) == str(mon.get("typeId"))
|
||||
and int(row["id"]) != int(mon["id"])
|
||||
and not self.food_protection.get(int(row["id"]))
|
||||
and (quality_rank(self.catalog, mon) is None or quality_rank(self.catalog, row) is not None
|
||||
and quality_rank(self.catalog, row) >= quality_rank(self.catalog, mon))
|
||||
and (int(row["id"]) in self.managed or self.protected(row, snapshot, policy))]
|
||||
candidates.sort(key=lambda row: (int(policy.feed_targets.get(str(row["id"]), 9999)),
|
||||
int(policy.breakthrough_targets.get(str(row["id"]), 9999)), -int(row.get("level") or 1), int(row["id"])))
|
||||
unknown = False
|
||||
for target in candidates:
|
||||
remaining = self.tp_feeding_remaining(target)
|
||||
if remaining is None:
|
||||
unknown = True
|
||||
continue
|
||||
# TP food works even at the ordinary experience cap. Do not use
|
||||
# potentialLevel here: it controls the separate material breakthrough.
|
||||
if remaining > 0:
|
||||
self.tp_feed_targets.add(int(target["id"]))
|
||||
return target, f"优先同种突破喂养 #{target['id']}(tpLevel {int(target.get('tpLevel') or 0)} / 4)"
|
||||
cap = self.catalog.max_level(target)
|
||||
if remaining == 0 and cap is not None and int(target.get("level") or 1) < cap and self.catalog.feed_remaining(target, cap) != 0:
|
||||
self.tp_feed_targets.add(int(target["id"]))
|
||||
return target, f"同种突破已满,继续普通经验喂养 #{target['id']}"
|
||||
if unknown:
|
||||
target = self.cultivation.select(snapshot).get(str(mon.get("typeId")))
|
||||
if target is None:
|
||||
return None, "同种主培养魔物尚未收取到牧场,暂停喂养"
|
||||
blocked = self.primary_target_reason(target, snapshot)
|
||||
if blocked:
|
||||
return None, blocked
|
||||
if int(mon["id"]) == int(target["id"]) or self.protected(mon, snapshot, policy):
|
||||
return None, "主培养魔物、资质备用或受保护魔物不能作为喂养素材"
|
||||
if policy.feed_targets or policy.feed_target:
|
||||
selected = {int(key) for key in policy.feed_targets} if policy.feed_targets else {policy.feed_target}
|
||||
if int(target["id"]) not in selected:
|
||||
return None, f"同种主培养代表 #{target['id']} 未勾选为喂养目标,保留原勾选"
|
||||
remaining = self.tp_feeding_remaining(target)
|
||||
if remaining is None:
|
||||
return None, "缺少game_setting.tpExp累计门槛,暂停同种突破喂养"
|
||||
ordinary = [target for target in candidates if self.tp_feeding_remaining(target) == 0
|
||||
and self.catalog.max_level(target) is not None and int(target.get("level") or 1) < self.catalog.max_level(target)
|
||||
and self.catalog.feed_remaining(target, self.catalog.max_level(target)) != 0]
|
||||
if ordinary:
|
||||
target = ordinary[0]
|
||||
# TP and ordinary experience have independent caps. Neither cap
|
||||
# permits falling through to another member of this species.
|
||||
if remaining > 0:
|
||||
self.tp_feed_targets.add(int(target["id"]))
|
||||
return target, f"优先同种主培养突破喂养 #{target['id']}(tpLevel {int(target.get('tpLevel') or 0)} / 4)"
|
||||
cap = self.catalog.max_level(target)
|
||||
if cap is not None and int(target.get("level") or 1) < cap and self.catalog.feed_remaining(target, cap) != 0:
|
||||
self.tp_feed_targets.add(int(target["id"]))
|
||||
return target, f"同种突破已满,继续普通经验喂养 #{target['id']}"
|
||||
return None, "同种魔物均已完成突破,不继续消耗同种素材"
|
||||
return None, f"同种主培养代表 #{target['id']} 突破及当前经验已满或上限未知,暂停喂养"
|
||||
|
||||
def is_same_species_tp_feed(self, target, food):
|
||||
return self.tp_food_value(target, food) > 0 and (self.tp_feeding_remaining(target) or 0) > 0
|
||||
@@ -732,6 +735,11 @@ class Planner:
|
||||
self.notes.append("请到“背包魔物蛋”勾选要孵化的蛋,并设置优先级和孵出后的去向")
|
||||
return []
|
||||
actions = []
|
||||
ranch_counts = {}
|
||||
for mon in snapshot.raw["monsters"]:
|
||||
if mon.get("process") == 3:
|
||||
key = str(mon.get("typeId"))
|
||||
ranch_counts[key] = ranch_counts.get(key, 0) + 1
|
||||
free_rooms = {}
|
||||
for room in snapshot.raw["rooms"]:
|
||||
rid = int(room["id"])
|
||||
@@ -742,7 +750,8 @@ class Planner:
|
||||
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):
|
||||
rule = self.species_rule(mon, policy)
|
||||
if (mid not in self.managed and not rule) or mon.get("process") not in (2, 3):
|
||||
continue
|
||||
if policy.manual_eggs and not policy.egg_rules.get(str(mon["typeId"]), {}).get("enabled"):
|
||||
self.statuses[mid] = "该魔物未启用孵蛋规则"
|
||||
@@ -762,15 +771,33 @@ class Planner:
|
||||
if disposition == "sell" and not policy.dispatch or disposition == "feed" and not policy.feed:
|
||||
reason = "自动派遣开关已关闭" if disposition == "sell" else "自动喂养开关已关闭"
|
||||
disposition = "keep"
|
||||
if disposition == "keep" and self.hard_protection_reason(mon, snapshot, policy):
|
||||
reason = "受保护:" + reason
|
||||
self.statuses[mid] = "保留:" + reason if disposition == "keep" else "待派遣" if disposition == "sell" else "待喂养"
|
||||
if disposition == "sell":
|
||||
# MonsterCenter also routes mature incubator monsters through
|
||||
# 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:
|
||||
key = str(mon.get("typeId"))
|
||||
primary = self.representatives.get(key)
|
||||
if rule and primary and primary.get("process") != 3 and mid != int(primary["id"]):
|
||||
self.statuses[mid] = f"等待先收取首次主培养魔物 #{primary['id']},刷新后再处理备用"
|
||||
self.notes.append(f"{name}:" + self.statuses[mid])
|
||||
continue
|
||||
if rule and ranch_counts.get(key, 0) >= 2:
|
||||
if disposition == "feed" and policy.dispatch:
|
||||
actions.append(Action("sell", f"同种已达两只,派遣多余素材 {name} #{mid}",
|
||||
"monsterService/monsterSell", {"monsterIds": [mid]}))
|
||||
self.statuses[mid] = "同种牧场已达两只,待派遣多余素材"
|
||||
else:
|
||||
self.statuses[mid] = "等待收取:同种牧场已达两只,需先派遣多余魔物;受保护魔物不自动解除保护"
|
||||
self.notes.append(f"{name}:" + self.statuses[mid])
|
||||
continue
|
||||
room = next((rid for rid, free in free_rooms.items() if free > 0), None)
|
||||
if room is not None:
|
||||
free_rooms[room] -= 1
|
||||
ranch_counts[key] = ranch_counts.get(key, 0) + 1
|
||||
actions.append(Action("collect", f"收取 {name} #{mid} → 牧场 {room}", "stackService/stackTransferMonster", {"datas": [{"monsterId": [mid], "roomId": room}]}))
|
||||
else:
|
||||
self.notes.append(f"{name} 等待收取:牧场没有空位")
|
||||
@@ -785,6 +812,10 @@ class Planner:
|
||||
actions.append(Action("feed", f"{name} #{mid} → 喂养 #{target['id']}", "monsterService/monsterIntensify", {"targetId": int(target["id"]), "foods": [mid]}))
|
||||
else:
|
||||
self.notes.append("暂停喂养:" + reason)
|
||||
self.statuses[mid] = "暂停喂养:" + reason
|
||||
if rule and policy.dispatch:
|
||||
actions.append(Action("sell", f"主培养暂不可喂养,派遣多余素材 {name} #{mid}",
|
||||
"monsterService/monsterSell", {"monsterIds": [mid]}))
|
||||
elif disposition == "keep":
|
||||
self.notes.append(f"{name} 已保留:{reason}")
|
||||
if actions:
|
||||
@@ -828,6 +859,13 @@ class Planner:
|
||||
def batch_actions(self, actions, snapshot, policy):
|
||||
monsters = snapshot.monsters
|
||||
collects = [a for a in actions if a.kind == "collect"]
|
||||
species_dispatches = [a for a in actions if a.kind == "sell" and any(
|
||||
mid in monsters and self.species_rule(monsters[mid], policy)
|
||||
for mid in a.payload["monsterIds"])]
|
||||
if collects and species_dispatches:
|
||||
# Dispose of rejected duplicates before admitting another monster.
|
||||
# The next plan must use a refreshed snapshot after this write.
|
||||
return [a for a in actions if a.kind == "sell"]
|
||||
merged_collect = None
|
||||
if collects:
|
||||
rooms = {}
|
||||
@@ -845,21 +883,50 @@ class Planner:
|
||||
feeds = [a for a in actions if a.kind == "feed"]
|
||||
if not feeds:
|
||||
return ([merged_collect] if merged_collect else []) + actions
|
||||
target_id = feeds[0].payload["targetId"]
|
||||
target = monsters[target_id]
|
||||
feeds = [action for action in feeds if action.payload["targetId"] == target_id
|
||||
and all(mid != target_id and mid in self.managed and not self.protected(monsters[mid], snapshot, policy)
|
||||
for mid in action.payload["foods"])]
|
||||
if not feeds:
|
||||
return ([merged_collect] if merged_collect else [])
|
||||
stop_level = self.catalog.max_level(target)
|
||||
need = self.catalog.feed_remaining(target, stop_level)
|
||||
same_species = target_id in self.tp_feed_targets and all(self.is_same_species_tp_feed(target, monsters[mid])
|
||||
for action in feeds if action.payload["targetId"] == target_id for mid in action.payload["foods"])
|
||||
tp_need = self.tp_feeding_remaining(target) if same_species else 0
|
||||
ids, experience, tp_experience = [], 0, 0
|
||||
feeding = self._batch_feeding(feeds, snapshot, policy)
|
||||
return feeding + [a for a in actions if a.kind != "feed"]
|
||||
|
||||
def _batch_feeding(self, feeds, snapshot, policy):
|
||||
"""Revalidate the primary and every material at the final batch boundary."""
|
||||
if not policy.enabled or not policy.feed:
|
||||
return []
|
||||
self.ensure_retention(snapshot, policy)
|
||||
monsters = snapshot.monsters
|
||||
selected, selected_reason = self.feeding_target(snapshot, policy) if policy.feed_targets or policy.feed_target else (None, "")
|
||||
valid = []
|
||||
for action in feeds:
|
||||
for mid in action.payload["foods"]:
|
||||
target_id = int(action.payload["targetId"])
|
||||
target = monsters.get(target_id)
|
||||
reason = self.primary_target_reason(target, snapshot) if target else "喂养目标已不存在"
|
||||
if not reason and (policy.feed_targets or policy.feed_target) and (selected is None or int(selected["id"]) != target_id):
|
||||
reason = selected_reason or "目标未勾选为喂养目标"
|
||||
if reason:
|
||||
self.notes.append("暂停喂养:" + reason)
|
||||
continue
|
||||
foods = [int(mid) for mid in action.payload["foods"] if int(mid) != target_id
|
||||
and int(mid) in self.managed and int(mid) in monsters
|
||||
and monsters[int(mid)].get("process") == 3
|
||||
and not self.protected(monsters[int(mid)], snapshot, policy)
|
||||
and int(mid) not in self.dispatch_extras]
|
||||
if foods:
|
||||
valid.append((target_id, foods))
|
||||
if not valid:
|
||||
return []
|
||||
target_id = valid[0][0]
|
||||
target = monsters[target_id]
|
||||
stop_level = self.catalog.max_level(target)
|
||||
need = self.catalog.feed_remaining(target, stop_level) if stop_level is not None else None
|
||||
same_species = target_id in self.tp_feed_targets and all(self.is_same_species_tp_feed(target, monsters[mid])
|
||||
for mid_target, foods in valid if mid_target == target_id for mid in foods)
|
||||
tp_need = self.tp_feeding_remaining(target) if same_species else 0
|
||||
if not same_species and (need is None or need == 0 or int(target.get("level") or 1) >= stop_level):
|
||||
self.notes.append(f"暂停喂养:主培养目标 #{target_id} 当前经验已满或突破上限未知")
|
||||
return []
|
||||
ids, experience, tp_experience = [], 0, 0
|
||||
for mid_target, food_ids in valid:
|
||||
if mid_target != target_id:
|
||||
continue
|
||||
for mid in food_ids:
|
||||
if mid in ids or mid == target_id:
|
||||
continue
|
||||
ids.append(mid)
|
||||
@@ -872,6 +939,6 @@ class Planner:
|
||||
label = self.catalog.monster_label(target)
|
||||
foods = "、".join(self.catalog.monster_label(monsters[mid]) for mid in ids)
|
||||
if not ids:
|
||||
return ([merged_collect] if merged_collect else []) + [a for a in actions if a not in feeds]
|
||||
return []
|
||||
merged = Action("feed", f"喂养 {label} ← {len(ids)} 只素材:{foods}(经验 {experience})", "monsterService/monsterIntensify", {"targetId": target_id, "foods": ids})
|
||||
return ([merged_collect] if merged_collect else []) + [merged] + [a for a in actions if a not in feeds]
|
||||
return [merged]
|
||||
|
||||
Reference in New Issue
Block a user