fix(web): finalize quick battle and commission procurement for 2.0.9
This commit is contained in:
@@ -419,11 +419,17 @@ class Scenario:
|
||||
triggers: tuple = ()
|
||||
|
||||
|
||||
def _prepare(request, tables):
|
||||
def _prepare(request, tables, *, quick=False):
|
||||
report = _envelope()
|
||||
report.update(supported=False, reasons=[], implemented_skills=sorted(KNOWN_SKILLS))
|
||||
|
||||
def diagnostic(code, message, *, ignored=False, blocking=False):
|
||||
if quick and code in ("objective", "controller", "triggers", "unit_controller",
|
||||
"unit_objective", "field_effect", "cosmetic_controller"):
|
||||
record = {"code": "aggregate_approximation", "mechanic": code, "message": message}
|
||||
if record not in report["diagnostics"]:
|
||||
report["diagnostics"].append(record)
|
||||
return
|
||||
record = {"code": code, "message": message}
|
||||
if record not in report["diagnostics"]:
|
||||
report["diagnostics"].append(record)
|
||||
@@ -498,7 +504,9 @@ def _prepare(request, tables):
|
||||
units = [] # BattleCenter empties the master team before adding authored allies.
|
||||
configured_mons = [(team, mon) for team in battle.get("teams", ())
|
||||
for mon in team.get("mons", ()) if mon is not None]
|
||||
unit_mids = {_int(mon.get("mid", -1)) for _, mon in configured_mons}
|
||||
# AS3 int('') is zero for an authored default mid; keep stat parsing strict.
|
||||
unit_mids = {_int(0 if mon.get("mid") == "" else mon.get("mid", -1))
|
||||
for _, mon in configured_mons}
|
||||
triggers = []
|
||||
for entry in battle.get("triggers", ()) or ():
|
||||
if mining:
|
||||
@@ -549,24 +557,26 @@ def _prepare(request, tables):
|
||||
if mining:
|
||||
if not any(u.destroy_target for u in units) or not any(u.protect_target for u in units):
|
||||
diagnostic("unit_objective", "Mining requires actual destroy and protect target units", blocking=True)
|
||||
elif not any(u.team != 1 and not u.is_object for u in units):
|
||||
elif not quick and not any(u.team != 1 and not u.is_object for u in units):
|
||||
raise SimulationInputError("Elimination battle must contain configured enemies")
|
||||
for team in teams.values():
|
||||
if team["capacity"] <= 0 or team["initial"] < 0:
|
||||
if (team["capacity"] < 0 if quick else team["capacity"] <= 0) or team["initial"] < 0:
|
||||
raise SimulationInputError("Original team capacity/AP is invalid")
|
||||
field_config = battle.get("battleField")
|
||||
if quick and not isinstance(field_config, Mapping):
|
||||
field_config = {}
|
||||
if not isinstance(field_config, Mapping):
|
||||
raise SimulationInputError("Full original battleField configuration is required")
|
||||
if field_config.get("fieldMode"):
|
||||
name = field_config.get("fieldName", "default")
|
||||
original_field = tables["setting"]["defaultField"].get(name)
|
||||
if original_field is None:
|
||||
if original_field is None and not quick:
|
||||
raise SimulationInputError("Unknown original default battlefield")
|
||||
field_config = dict(original_field, mapObjects=field_config.get("mapObjects", ()),
|
||||
mapAreas=tuple(original_field.get("mapAreas", ())) + tuple(field_config.get("mapAreas", ())))
|
||||
field_config = dict(original_field or {}, mapObjects=field_config.get("mapObjects", ()),
|
||||
mapAreas=tuple((original_field or {}).get("mapAreas", ())) + tuple(field_config.get("mapAreas", ())))
|
||||
points = {p["id"]: p for p in field_config.get("mapPoints", ())}
|
||||
areas = {a["id"]: a for a in field_config.get("mapAreas", ())}
|
||||
if "area_battlefield" not in areas or not points:
|
||||
if not quick and ("area_battlefield" not in areas or not points):
|
||||
raise SimulationInputError("Battlefield needs original points and area_battlefield")
|
||||
for area in areas.values():
|
||||
if area.get("type", "none") not in (("none", "pow") if mining else ("none",)):
|
||||
@@ -582,11 +592,11 @@ def _prepare(request, tables):
|
||||
diagnostic("attack_profile", f"Attack {u.attack_type} has no bundled source profile; original default AttackType1 is approximated", ignored=True)
|
||||
if u.effects.get("sunFire") or u.effects.get("moonHeal") or u.effects.get("deadBoom"):
|
||||
diagnostic("unimplemented_effect", "sunFire, moonHeal and deadBoom effects are omitted where present", ignored=True)
|
||||
if u.attack_area and u.attack_area not in areas:
|
||||
if not quick and u.attack_area and u.attack_area not in areas:
|
||||
raise SimulationInputError("Configured attackArea is absent from original battlefield")
|
||||
if u.join_point and not u.join_point.startswith("mon_") and u.join_point not in points:
|
||||
if not quick and u.join_point and not u.join_point.startswith("mon_") and u.join_point not in points:
|
||||
raise SimulationInputError("Configured joinPoint is absent from original battlefield")
|
||||
if not u.join_point:
|
||||
if not quick and not u.join_point:
|
||||
default_point = f"point_team{u.team}_{'fore' if u.position < 3 else 'back'}{u.position + 1 if u.position < 3 else u.position - 2}"
|
||||
if (u.position >= 6 or default_point not in points) and not any(
|
||||
p.startswith(f"point_team{u.team}_wait") for p in points):
|
||||
@@ -629,7 +639,7 @@ def _unit_preview(unit):
|
||||
|
||||
|
||||
def _snapshot_anomalies(mon, unit, tables):
|
||||
"""Port the observable input checks from BattlePanel.cheatCheck.
|
||||
"""Check source input bounds, using the cultivation potential cap.
|
||||
|
||||
These are a subset of the final original checks, not a claim to have run
|
||||
them all. Keep raw input values; never repair them to make checks pass.
|
||||
@@ -644,7 +654,6 @@ def _snapshot_anomalies(mon, unit, tables):
|
||||
|
||||
row = tables["monster_info"][str(unit.species)]
|
||||
potential_level = _int(mon.get("potentialLevel", 1))
|
||||
tp = min(4, _int(mon.get("tpLevel", 0)))
|
||||
if _number(mon.get("feel", 0)) > 200:
|
||||
add("+15overfeel", 50, feel=mon["feel"])
|
||||
potential = tables["potential_info"]["potential"].get(str(row["job"]), {}).get(str(row["star"]), {})
|
||||
@@ -653,7 +662,9 @@ def _snapshot_anomalies(mon, unit, tables):
|
||||
maximum = row[stat] + row[stat + "_grow_max"] * (_int(mon["level"]) + potential_level) * 4
|
||||
if value > maximum:
|
||||
add("+15overgrow", 25, stat=stat, value=value, source_maximum=maximum)
|
||||
max_potential = potential.get(stat, 0) + potential.get(stat + "TpAdd", 0) * tp
|
||||
# PotentialPanel.as:102,245 uses cultivation, not TP level. The old
|
||||
# BattlePanel.cheatCheck bound can reject normally cultivated values.
|
||||
max_potential = potential.get(stat, 0) + potential.get(stat + "TpAdd", 0) * (potential_level - 1)
|
||||
value_potential = _number(mon.get("p" + stat.capitalize(), 0))
|
||||
if potential and value_potential > max_potential * 1.5:
|
||||
add("+15overpoten", 30, stat=stat, value=value_potential, source_maximum=max_potential * 1.5)
|
||||
@@ -1335,7 +1346,7 @@ def _execution_failure(outcome, reason, *, supported=True):
|
||||
|
||||
|
||||
class ExperimentalBattleRuntime:
|
||||
"""Offline experimental adapter. run always executes a fixed worker module.
|
||||
"""Fast aggregate adapter. run always executes a fixed offline worker module.
|
||||
|
||||
supported means this approximate model is runnable, not server settlement
|
||||
eligibility. Calls do not mutate the request, cache, or input snapshot.
|
||||
@@ -1343,7 +1354,8 @@ class ExperimentalBattleRuntime:
|
||||
|
||||
def inspect(self, request):
|
||||
try:
|
||||
_, report = _prepare(request, combat_tables())
|
||||
from .battle_quick import prepare
|
||||
_, report = prepare(request, combat_tables())
|
||||
return report
|
||||
except SimulationInputError as exc:
|
||||
result = _envelope()
|
||||
@@ -1418,7 +1430,8 @@ def _worker():
|
||||
if len(wire) > MAX_WIRE_BYTES:
|
||||
raise SimulationInputError("Worker input exceeds limit")
|
||||
payload = json.loads(wire)
|
||||
result = simulate(payload["request"], timeout=payload.get("timeout", 30.0))
|
||||
from .battle_quick import simulate_quick
|
||||
result = simulate_quick(payload["request"], timeout=payload.get("timeout", 30.0))
|
||||
if result.get("outcome") == "unsupported":
|
||||
result.update(execution_status="unsupported", terminal=False, terminal_reason="unsupported_scenario")
|
||||
encoded = json.dumps(result, ensure_ascii=True, allow_nan=False,
|
||||
|
||||
Reference in New Issue
Block a user