fix: keep automatic cultivation on one stable primary per species

This commit is contained in:
AttilaNet
2026-11-13 08:51:03 +08:00
parent 01ad2e3ab9
commit 4fbe895999
35 changed files with 2069 additions and 322 deletions
+41 -11
View File
@@ -55,13 +55,12 @@ def _strategy_fields(catalog):
hatch += [_policy_field("protect_star", "保留此星级及以上", "integer", min=1, max=6, group="牧场策略"),
_policy_field("protect_quality", "资质保留条件", "select", group="牧场策略", options=_options([
(4, "S及以上"), (3, "A及以上"), (2, "B及以上"), (1, "全部资质"), (5, "不按资质保留"), (6, "四项全S(4S)才保留")])),
_policy_field("keep_better_quality", "保留资质高于牧场同种培养代表的新魔物", group="牧场策略"),
_policy_field("room_id", "收取到牧场", "select", options=_options([(0, "自动选择有空位的牧场")]), group="牧场策略"),
_policy_field("reserved_types", "额外保留魔物编号", "id_list", group="牧场策略"),
_policy_field("reserved_eggs", "保留蛋数量", "id_counts", group="牧场策略"),
_policy_field("feed", "按策略喂养选定目标(受当前突破上限限制)", group="喂养策略")]
gift = [_policy_field(key, label) for key, label in (
("gift_enabled", "启用自动赠礼"), ("gift_auto_representative", "每种魔物只培养一只,自动选择培养代表"),
("gift_enabled", "启用自动赠礼"), ("gift_auto_representative", "自动选择各类主培养赠礼(关闭时按已勾选主培养)"),
("gift_liked_only", "仅赠送目标喜欢的物品"))]
quest = [_field(["quest_policy", key], label) for key, label in (
("enabled", "启用委托自动接取 / 推进 / 领奖"), ("accept", "按氪金奖励优先接取(20 → 15 → 10)"), ("allow_items", "允许提交道具(遵守保留数量)"),
@@ -234,8 +233,7 @@ def _egg_rows(dto, engine, config, query):
dto["columns"] += [_column(k, label) for k, label in (
("time_text", "培育时间"), ("sell_money", "派遣金币"), ("sell_exp", "基础经验"),
("gold_per_hour", "金币/小时"), ("exp_per_hour", "经验/小时"), ("inventory_text", "物品ID"))]
dto["columns"].append(_row_column("keep_count", "牧场保留", ["policy", "egg_rules"], min=0, max=1000,
help="已启用规则跨牧场至少保留此数量;0不保留名额,硬保护仍有效"))
dto["columns"].append(_column("retention_text", "牧场保留"))
for key in dict.fromkeys([*groups, *rules]):
info = catalog.monster(key)
if not info or search and search not in (key + str(info.get("name", ""))).casefold():
@@ -250,13 +248,14 @@ def _egg_rows(dto, engine, config, query):
**groups.get(key, {"count": 0, "inventory_ids": []}), **rule, "time_total": total, "time_text": duration(total),
"sell_money": money, "sell_exp": exp, "gold_per_hour": round(money * 3600 / total, 2), "exp_per_hour": round(exp * 3600 / total, 2),
"inventory_text": ", ".join(map(str, groups.get(key, {}).get("inventory_ids", []))),
"rule_defaults": defaults, "rule_path": ["policy", "egg_rules", key],
"rule_defaults": defaults, "rule_path": ["policy", "egg_rules", key], "retention_text": "主培养1 + 更优备选≤1",
"edits": {"market_id": _edit(["policy", "egg_rules", key, "market_id"], "select", options=options or _options([("", "金币市场无此蛋")]))}})
dto["summary"] = f"{len(dto['rows'])} 种魔物蛋规则;已启用 {sum(row['enabled'] for row in dto['rows'])} 种"
dto["summary"] = (f"{len(dto['rows'])} 种魔物蛋规则;已启用 {sum(row['enabled'] for row in dto['rows'])} 种;"
"启用规则固定主培养1 + 更优备选≤1;锁定等硬保护仍有效")
dto["form"].append(_field(["policy", "egg_rules"], "添加魔物蛋规则", "add_rule", value=None,
options=_options([(key, row.get("name", key)) for key, row in catalog.monsters.items()]), defaults=asdict(EggRule()),
defaults_by_id={key: _default_egg_rule(catalog, key, config["policy"]["market_id"]) for key in catalog.monsters},
help="可配置背包当前没有的蛋;按孵化优先级、去向、补货和牧场保留规则自动执行"))
help="可配置背包当前没有的蛋;启用规则固定主培养1 + 更优资质备选≤1,备选不接受自动喂养、赠礼或突破"))
def _bag(dto, engine, config, query):
@@ -300,6 +299,9 @@ def _bag(dto, engine, config, query):
def _ranch(dto, engine, config, query):
snapshot, catalog = engine.snapshot, engine.catalog
engine.plans() # Refresh pure planner statuses, including existing enabled-rule duplicates.
primaries = engine.cultivation.select(snapshot)
backups = engine.planner.backups
grouped = _boolean(query.get("grouped"), False)
try:
room_id = int(query.get("room_id") or 0)
@@ -315,6 +317,7 @@ def _ranch(dto, engine, config, query):
"喂养目标", "喂养优先级", "潜能阶段", "参考攻击", "参考防御", "参考生命", "参考敏捷", "好感 / 当前上限", "喜欢的物品",
"赠礼", "赠礼优先级", "自动突破目标", "突破优先级", "同种突破", "突破经验"]
dto["columns"] = [_column(key, label) for key, label in zip(keys, labels)]
dto["columns"].insert(8, _column("cultivation_role", "培养角色"))
for prefix, mapping in (("feed", "feed_targets"), ("gift", "gift_targets"), ("breakthrough", "breakthrough_targets")):
for column in dto["columns"]:
if column["key"] == prefix + "_selected":
@@ -343,24 +346,51 @@ def _ranch(dto, engine, config, query):
key = str(int(mon["id"]))
row = dict(zip(keys, values)) | {"id": key, "type_id": str(mon["typeId"]), "level": int(mon.get("level") or 1), "max_level": catalog.max_level(mon),
"process": mon.get("process"), "room_id": int(mon.get("roomId") or 0), "group": "incubator" if mon.get("process") == 2 else f"room:{int(mon.get('roomId') or 0)}", "edits": {}}
primary, backup = primaries.get(row["type_id"]), backups.get(row["type_id"])
reason = engine.cultivation_target_reason(mon["id"], primaries=primaries)
retained_primary = engine.planner.representatives.get(row["type_id"])
if primary and int(primary["id"]) == int(mon["id"]):
role, role_label = "primary", "主培养"
elif backup and int(backup["id"]) == int(mon["id"]):
role, role_label = "backup", "更优资质备选" + ("(待收取)" if mon.get("process") == 2 else "")
elif mon.get("process") == 2:
pending_primary = retained_primary and int(retained_primary["id"]) == int(mon["id"])
role, role_label = ("primary_pending", "主培养待收取") if pending_primary else ("incubator", "培育中")
else:
role, role_label = ("duplicate", "同种重复") if primary else ("unconfirmed", "主培养待确认")
row.update(cultivation_role=role_label,
cultivation_role_key=role, primary_id=int(primary["id"]) if primary else None,
automatic_eligible=not reason, automatic_reason=reason, tooltips={"cultivation_role": reason or "同种唯一自动培养对象"})
rule_enabled = engine.policy.manual_eggs and config["policy"]["egg_rules"].get(row["type_id"], {}).get("enabled")
status = engine.planner.statuses.get(int(mon["id"]), "")
if rule_enabled or int(mon["id"]) in managed:
row["scope"] = status or "启用规则管理"
if not engine.policy.enabled:
row["scope"] = "自动管理已关闭;" + row["scope"]
elif role == "duplicate" and not engine.policy.dispatch:
row["scope"] = "自动派遣已关闭;" + row["scope"]
elif engine.policy.manual_eggs:
row["scope"] = "规则未启用:不自动清理"
for prefix, mapping in (("feed", "feed_targets"), ("gift", "gift_targets"), ("breakthrough", "breakthrough_targets")):
targets = config["policy"][mapping]
selected = key in targets
row[prefix + "_selected"], row[prefix + "_priority"] = selected, targets.get(key, 100)
row["edits"][prefix + "_selected"] = _edit(["policy", mapping, key], "target", default=100, unchecked="delete", disabled=mon.get("process") != 3)
row["edits"][prefix + "_priority"] = _edit(["policy", mapping, key], "integer", min=1, max=999, optional=True, disabled=not selected or mon.get("process") != 3)
row["edits"][prefix + "_selected"] = _edit(["policy", mapping, key], "target", default=100, unchecked="delete", disabled=bool(reason), reason=reason)
row["edits"][prefix + "_priority"] = _edit(["policy", mapping, key], "integer", min=1, max=999, optional=True, disabled=not selected or bool(reason), reason=reason)
dto["rows"].append(row)
dto["details"][key] = {"name": row["name"], "species": catalog.monster(mon["typeId"]).get("name", "未知"), "id": int(mon["id"]),
"level": row["level_text"], "quality": row["quality"], "reference_stats": catalog.reference_stats(mon),
"growth": {name: mon.get("g" + name.capitalize()) for name in ("atk", "def", "hp", "dex")},
"likes": row["likes"], "feel": row["feel_text"], "feed_exp": catalog.feed_exp(mon), "scope": row["scope"]}
"likes": row["likes"], "feel": row["feel_text"], "feed_exp": catalog.feed_exp(mon), "scope": row["scope"],
"培养角色": row["cultivation_role"], "主培养ID": row["primary_id"], "自动培养": reason or "同种唯一自动培养对象"}
if grouped:
known = {group["id"] for group in dto["groups"]}
for row in dto["rows"]:
if row["group"] not in known:
known.add(row["group"])
dto["groups"].append({"id": row["group"], "label": "培育室" if row["group"] == "incubator" else "未归属牧场", "count": counts[row["group"]], "collapsed": False})
dto["summary"] = f"{len(snapshot.raw['rooms'])} 座牧场;显示 {len(dto['rows'])} 只魔物"
dto["summary"] = (f"{len(snapshot.raw['rooms'])} 座牧场;显示 {len(dto['rows'])} 只魔物;"
"自动喂养 / 赠礼 / 突破仅限各类主培养;备选 / 重复项原勾选保留但不执行")
targets = [{"value": int(mon["id"]), "label": f"{catalog.monster_label(mon)} Lv.{mon.get('level', 1)}/{catalog.max_level(mon)}"}
for mon in snapshot.raw["monsters"] if mon.get("process") == 3 and catalog.max_level(mon) is not None and int(mon.get("level", 1)) < catalog.max_level(mon)]
dto["feed_targets"] = targets