Add v1.2 development quest progression and experimental battle runtime
This commit is contained in:
@@ -6,6 +6,7 @@ from .model import Policy
|
||||
from .daily import DailyPolicy
|
||||
from .quests import QuestPolicy
|
||||
from .sweeping import SweepPolicy
|
||||
from .progression import ProgressionPolicy
|
||||
|
||||
FORMAT = "ranch-helper-policies"
|
||||
VERSION = 1
|
||||
@@ -31,6 +32,23 @@ def checked_policy(cls, data):
|
||||
raise ValueError("策略字段格式错误") from error
|
||||
|
||||
|
||||
def checked_progression_policy(data):
|
||||
"""Reject ambiguous or unsafe task choices before applying any settings."""
|
||||
if not isinstance(data, dict):
|
||||
raise ValueError("主线策略必须是对象")
|
||||
raw = asdict(ProgressionPolicy()) | data
|
||||
for key in ("reserve_ti", "max_money"):
|
||||
if type(raw[key]) is not int or not 0 <= raw[key] <= 1_000_000_000:
|
||||
raise ValueError("主线策略数量超出范围:" + key)
|
||||
if type(raw["stop_after_loss"]) is not int or not 1 <= raw["stop_after_loss"] <= 999:
|
||||
raise ValueError("连续失败停止次数须为1至999")
|
||||
if not isinstance(raw["item_reserves"], dict) or any(not isinstance(key, str) or not key.isdigit() or int(key) <= 0
|
||||
or type(count) is not int or not 0 <= count <= 1_000_000_000
|
||||
for key, count in raw["item_reserves"].items()):
|
||||
raise ValueError("主线保留物品须为正整数编号和非负整数数量")
|
||||
return checked_policy(ProgressionPolicy, data)
|
||||
|
||||
|
||||
def portable_policy(policy, snapshot=None):
|
||||
value = asdict(policy)
|
||||
value["enabled"] = False
|
||||
@@ -45,7 +63,7 @@ def portable_policy(policy, snapshot=None):
|
||||
for key, priority in sorted(value.pop(field).items(), key=lambda pair: pair[1]):
|
||||
mon = snapshot.monsters.get(int(key)) if snapshot else None
|
||||
targets[kind].append({"typeId": str(mon.get("typeId")) if mon else "", "priority": priority})
|
||||
return {"format": FORMAT, "schema": VERSION, "assistantVersion": "1.1.1", "gameVersion": "1.9.68",
|
||||
return {"format": FORMAT, "schema": VERSION, "assistantVersion": "1.2.0.dev1", "gameVersion": "1.9.68",
|
||||
"policy": value, "targetSpecies": targets}
|
||||
|
||||
|
||||
@@ -87,6 +105,7 @@ def portable_config(config, snapshot=None):
|
||||
value["policy"][field] = getattr(policy, field)
|
||||
for key, cls in (("quest_policy", QuestPolicy), ("daily_policy", DailyPolicy), ("sweep_policy", SweepPolicy)):
|
||||
value[key] = asdict(cls(**config.get(key, {})))
|
||||
value["progression_policy"] = asdict(checked_progression_policy(config.get("progression_policy", {})))
|
||||
value["interval"] = config.get("interval", 30)
|
||||
value["overrides"] = copy.deepcopy(config.get("overrides", {}))
|
||||
value["yield_stars"] = list(config.get("yield_stars", [1, 2, 3, 4, 5]))
|
||||
@@ -105,6 +124,9 @@ def import_config(value, snapshot=None):
|
||||
if not isinstance(value.get(key), dict):
|
||||
raise ValueError("策略文件缺少 " + key)
|
||||
config[key] = asdict(checked_policy(cls, value[key]))
|
||||
# An additive section preserves schema-2 compatibility with older bundles.
|
||||
if "progression_policy" in value:
|
||||
config["progression_policy"] = asdict(checked_progression_policy(value["progression_policy"]))
|
||||
interval = value.get("interval", 30)
|
||||
if interval not in (30, 60, 120, 300):
|
||||
raise ValueError("刷新间隔须为30、60、120或300秒")
|
||||
|
||||
Reference in New Issue
Block a user