Add automatic mining and ticket resource stages

This commit is contained in:
AttilaNet
2026-11-10 12:54:48 +08:00
parent 0109cc0d1c
commit 5082c2df5c
20 changed files with 1615 additions and 67 deletions
+69 -1
View File
@@ -54,29 +54,97 @@ class Stage:
sweep: bool = False
drops: str = ""
reason: str = ""
category: str = "ordinary"
battle_available: bool = False
def resource_mines(catalog):
"""Only original mine1 nodes, excluding their guardian and dungeon stages."""
mine = (catalog.data.get("mine_info") or {}).get("mines", {}).get("mine1") or {}
return {str(obj["stageId"]) for layer in mine.get("layers") or []
for obj in layer.get("objs") or [] if obj.get("type") == "stage" and obj.get("stageId")}
def stage_category(catalog, stage_id, row, metadata=None):
stage_id, row = str(stage_id), row or {}
if row.get("posmode"):
return "special"
items = (row.get("cost") or {}).get("items") or []
mines, sp_children = (metadata or _stage_metadata(catalog))[:2]
if stage_id in mines and items and all(
str(item.get("typeId")) in {"20009", "20010", "20011"} for item in items):
return "mine"
if row.get("special") and items and (stage_id in catalog.data.get("stage_sp", {}) or stage_id in sp_children):
names = catalog.data.get("item_names") or {}
if all("券" in names.get(str(item.get("typeId")), "") or "门票" in names.get(str(item.get("typeId")), "") for item in items):
return "ticket"
return "special" if row.get("special") else "ordinary"
def _stage_metadata(catalog):
table = catalog.data
if getattr(catalog, "_resource_metadata", None) is None:
catalog._resource_metadata = (resource_mines(catalog),
{str(obj.get("stageId")) for key, special in table.get("stage_sp", {}).items()
if not special.get("tag") and not (table.get("stage_info", {}).get(key) or {}).get("special")
for obj in special.get("stages") or [] if isinstance(obj, dict)},
{str(obj.get("stageId")): (key, special) for key, special in table.get("stage_sp", {}).items()
if not special.get("tag") and not (table.get("stage_info", {}).get(key) or {}).get("special")
for obj in special.get("stages") or [] if isinstance(obj, dict)})
return catalog._resource_metadata
def resource_stages(catalog, snapshot):
"""Classified level-one resource candidates; runtime capability is separate."""
return [stage for stage in stages(catalog, snapshot)
if stage.category in ("mine", "ticket") and stage.level == "1"]
def stages(catalog, snapshot):
history = snapshot.raw.get("history") or {}
cities = catalog.data["game_setting"].get("cityInfo", {})
result = []
metadata = _stage_metadata(catalog)
for key, row in catalog.data["stage_info"].items():
special = catalog.data.get("stage_sp", {}).get(key, {})
category = stage_category(catalog, key, row, metadata)
parent = metadata[2].get(key) if category == "ticket" else None
if parent:
parent_key, special = parent
parent_row = catalog.data.get("stage_info", {}).get(parent_key, {})
if parent_row.get("closed") or not condition_ok(special.get("condition"), snapshot):
for level, info in row.get("level", {}).items():
result.append(Stage(key, str(level), row.get("name") or key, int(row.get("city") or 0),
stage_has_level(history, "unlockStage", key, level), stage_has_level(history, "passStage", key, level),
False, int((row.get("cost") or {}).get("ti") or 0) + int(info.get("cost") or 0),
", ".join(f"{catalog.data.get('item_names', {}).get(str(i['typeId']), i['typeId'])}×{i['num']}"
for i in (row.get("cost") or {}).get("items", [])), row.get("tagname") or key,
cities.get(str(int(row.get("city") or 0)), {}).get("name", f"地区 {int(row.get('city') or 0)}"),
0, False, reward_summary(catalog, info.get("reward")), "所属活动当前未开放", category,
bool(info.get("battle_available"))))
continue
opened = not row.get("closed") and condition_ok(special.get("condition"), snapshot)
city = int(row.get("city") or 0)
city_info = cities.get(str(city), {})
passed_levels = [i for i in (1, 2, 3) if stage_has_level(history, "passStage", key, i)]
sweep = not row.get("special") and not row.get("posmode") and len(passed_levels) == 3
mine_unlocked = bool(category == "mine" and (history.get("unlockStage") or {}).get(key) is not None)
for level, info in row.get("level", {}).items():
unlocked = stage_has_level(history, "unlockStage", key, level)
unlocked = unlocked or (mine_unlocked and str(level) == "1")
passed = stage_has_level(history, "passStage", key, level)
gate = city_info.get({"2": "openHardModeStage", "3": "openExtraModeStage"}.get(str(level), ""))
unlocked = unlocked and not info.get("levelLock") and (not gate or stage_has_level(history, "passStage", gate, 1))
base = row.get("cost") or {}
tickets = ", ".join(f"{catalog.data.get('item_names', {}).get(str(i['typeId']), i['typeId'])}×{i['num']}" for i in base.get("items", []))
reason = "未解锁" if not unlocked else "当前未开放" if not opened else "特殊关卡需手机实战" if row.get("special") or row.get("posmode") else "需三个难度全部通关" if not sweep else "可扫荡"
if category in ("mine", "ticket") and str(level) != "1":
reason = "矿点仅支持原入口难度1" if category == "mine" else "门票关卡仅支持原入口难度1"
elif category in ("mine", "ticket") and not info.get("battle_available"):
reason = "该资源关卡缺少已提取的战斗配置,未启用"
result.append(Stage(key, str(level), row.get("name") or key, city, unlocked, passed, opened,
int(base.get("ti") or 0) + int(info.get("cost") or 0), tickets,
row.get("tagname") or key, city_info.get("name", f"地区 {city}"), max(passed_levels, default=0),
sweep and unlocked and opened, reward_summary(catalog, info.get("reward")), reason))
sweep and unlocked and opened, reward_summary(catalog, info.get("reward")), reason,
category, bool(info.get("battle_available"))))
return result