Add hatch retention, automatic breakthroughs and exploration
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
"""Extract the original normal-team exploration areas for offline planning."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT))
|
||||
from tools.research_battle_v12 import recover_table
|
||||
from ranch_assistant.game_data import ORIGINAL_APK_SHA256
|
||||
|
||||
|
||||
def repair(value):
|
||||
if isinstance(value, dict):
|
||||
return {str(key): repair(item) for key, item in value.items()}
|
||||
if isinstance(value, list):
|
||||
return [repair(item) for item in value]
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
return value.encode("latin1").decode("gbk")
|
||||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
pass
|
||||
return value
|
||||
|
||||
|
||||
def build(apk, output):
|
||||
import hashlib
|
||||
with Path(apk).open("rb") as stream:
|
||||
if hashlib.file_digest(stream, "sha256").hexdigest() != ORIGINAL_APK_SHA256:
|
||||
raise ValueError("Only the verified original 1.9.68 APK is accepted")
|
||||
with zipfile.ZipFile(apk) as archive:
|
||||
original, metadata = recover_table(archive, "explore_info")
|
||||
source = original.get("datas", original)["areas"]
|
||||
fields = ("id", "name", "passStage", "costTi", "costTime", "level", "team", "monExpMin", "monExpMax", "dlevel", "reward")
|
||||
areas = [{key: repair(row.get(key)) for key in fields} for row in source.values() if row.get("team") == "normal"]
|
||||
document = {"schema": 1, "source_apk_sha256": ORIGINAL_APK_SHA256,
|
||||
"source_table_sha256": metadata.get("sha256"), "areas": areas}
|
||||
Path(output).write_text(json.dumps(document, ensure_ascii=False, indent=2, sort_keys=True) + "\n", encoding="utf-8", newline="\n")
|
||||
return document
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--apk", type=Path)
|
||||
parser.add_argument("--output", type=Path, default=ROOT / "ranch_assistant/data/exploration.json")
|
||||
arguments = parser.parse_args()
|
||||
if arguments.apk is None:
|
||||
candidates = list(ROOT.glob("*_1.9.68.apk"))
|
||||
if len(candidates) != 1:
|
||||
parser.error("Pass --apk with the original 1.9.68 APK")
|
||||
arguments.apk = candidates[0]
|
||||
result = build(arguments.apk, arguments.output)
|
||||
print(json.dumps({"areas": len(result["areas"]), "output": str(arguments.output)}, ensure_ascii=True))
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Recover factual game tables from the user-supplied APK; no network access."""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import zipfile
|
||||
@@ -8,6 +9,7 @@ import zlib
|
||||
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(root))
|
||||
os.environ["PYTHONUTF8"] = "1"
|
||||
from ranch_assistant.amf import Reader
|
||||
|
||||
|
||||
@@ -24,7 +26,13 @@ def repair_names(value):
|
||||
return value
|
||||
return value
|
||||
|
||||
apk = next(p for p in root.glob("*.apk") if p.name.endswith("_1.9.68.apk"))
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--apk", type=Path, help="Read-only local 1.9.68 APK")
|
||||
parser.add_argument("--output", type=Path, help="catalog.json output path")
|
||||
options = parser.parse_args()
|
||||
apk = options.apk or next(p for p in root.glob("*.apk") if p.name.endswith("_1.9.68.apk"))
|
||||
tables = {}
|
||||
with zipfile.ZipFile(apk) as archive:
|
||||
tables["tjchannel"] = json.loads(archive.read("assets/tjchannel.json")) if "assets/tjchannel.json" in archive.namelist() else {"tjchannel": "unknow"}
|
||||
@@ -40,6 +48,7 @@ with zipfile.ZipFile(apk) as archive:
|
||||
tables["stack_meta"] = {"total": int(value["total"])}
|
||||
print(name, len(tables[name]))
|
||||
fields = {"type", "name", "star", "time_1", "time_2", "sell_money", "sell_exp", "hideLib", "npc", "atk", "def", "hp", "dex", "like"}
|
||||
fields |= {"job", "element"}
|
||||
fields |= {p + "_grow_" + bound for p in ("atk", "def", "hp", "dex") for bound in ("min", "max")}
|
||||
tables["monster_info"] = {str(k): {f: v for f, v in row.items() if f in fields} for k, row in tables["monster_info"].items()}
|
||||
tables = repair_names(tables)
|
||||
@@ -53,7 +62,8 @@ tables["entangle_info"] = {"haoganMax": tables["entangle_info"]["haoganMax"]}
|
||||
tables["markets"] = {row["id"]: {k: row.get(k) for k in ("id", "money", "ke", "max", "eggs", "freegift")} |
|
||||
{"city": int(row["id"][7:]), "name": tables["game_setting"]["cityInfo"][row["id"][7:]]["name"]}
|
||||
for row in tables.pop("gacha_machine") if row["id"].startswith("sc_city")}
|
||||
tables["potential_info"] = {k: tables["potential_info"][k] for k in ("potentialLevelMaxAdd", "maxPotentialLevel")}
|
||||
tables["potential_info"] = {k: tables["potential_info"][k] for k in
|
||||
("potentialLevelMaxAdd", "maxPotentialLevel", "potential", "potentialAdd", "potentialLevelItem", "elementItem", "potentialElementItem")}
|
||||
tables["stage_info"] = {r["id"]: {f: r.get(f) for f in ("id", "name", "city", "closed", "cost", "tagname", "special", "posmode")} |
|
||||
{"level": {k: {f: v for f, v in level.items() if f in ("cost", "levelLock", "reward", "monExp")} for k, level in r.get("level", {}).items()}}
|
||||
for r in tables["stage_info"]}
|
||||
@@ -61,15 +71,25 @@ tables["activity_info"] = {k: v for k, v in tables["activity_info"].items() if k
|
||||
# Only positions are needed to avoid starting a sweep through an active story task.
|
||||
tables["stage_task_positions"] = {str(k): [s.get("position", "") for s in r.get("steps", [])] for k, r in tables["task_info"].items()
|
||||
if any(str(s.get("position", "")).startswith("city") for s in r.get("steps", []))}
|
||||
tables["game_setting"] = {k: v for k, v in tables["game_setting"].items() if k in ("monExpScale", "xyz", "xyz1", "cityInfo", "upStarAdd", "maxLike", "vipReward", "monGiftTime", "monGiftMax", "masterMaxLevel", "tiCD", "tiFirst", "tiLevelAdd", "tiTotalMax") or k.startswith("loopTask") or k.endswith("_xyz")}
|
||||
tables["game_setting"] = {k: v for k, v in tables["game_setting"].items() if k in ("monExpScale", "xyz", "xyz1", "cityInfo", "upStarAdd", "maxLike", "vipReward", "monGiftTime", "monGiftMax", "masterMaxLevel", "tiCD", "tiFirst", "tiLevelAdd", "tiTotalMax", "tpExp", "specialFood", "specialFood14") or k.startswith("loopTask") or k.endswith("_xyz")}
|
||||
# This is a GameMath constant, not a server-supplied game_setting field.
|
||||
tables["client_constants"] = {"maxTpLevel": 4}
|
||||
task_fields = {"type", "typeId", "name", "des", "city", "closed", "condition", "startStep", "reward"}
|
||||
step_fields = {"statusType", "statusValue", "condition", "des", "position", "npc", "afterStory", "auto"}
|
||||
tables["task_info"] = {str(k): {f: v for f, v in row.items() if f in task_fields} |
|
||||
{"steps": [{f: v for f, v in step.items() if f in step_fields} for step in row.get("steps", [])]}
|
||||
for k, row in tables["task_info"].items() if int(row.get("type", 0)) == 4}
|
||||
output = root / "ranch_assistant" / "data"
|
||||
output.mkdir(exist_ok=True)
|
||||
(output / "catalog.json").write_text(json.dumps(tables, ensure_ascii=False, separators=(",", ":")), encoding="utf-8")
|
||||
catalog_path = options.output or root / "ranch_assistant" / "data" / "catalog.json"
|
||||
catalog_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
text = json.dumps(tables, ensure_ascii=False, separators=(",", ":"))
|
||||
if catalog_path.exists():
|
||||
# Keep unrelated and locally maintained catalog data out of this table update.
|
||||
previous = json.loads(catalog_path.read_text(encoding="utf-8"))
|
||||
for key in ("monster_info", "potential_info", "game_setting"):
|
||||
previous[key] = tables[key]
|
||||
previous["client_constants"] = tables["client_constants"]
|
||||
text = json.dumps(previous, ensure_ascii=False, separators=(",", ":"))
|
||||
catalog_path.write_text(text, encoding="utf-8")
|
||||
for table in ("monster_info", "stage_info"):
|
||||
values = tables[table].items() if isinstance(tables[table], dict) else enumerate(tables[table])
|
||||
for key, row in values:
|
||||
|
||||
Reference in New Issue
Block a user