Improve task filters, exploration rewards and V4 battle simulation

This commit is contained in:
AttilaNet
2026-11-10 14:09:53 +08:00
parent 5082c2df5c
commit 6d74730735
20 changed files with 1129 additions and 42 deletions
+43 -1
View File
@@ -30,6 +30,8 @@ FPS = 50 # Original MYRMain.app SWF header: 50 fps.
MAX_TRACE = 10000
MAX_UNITS = 1024
MAX_WIRE_BYTES = 16 * 1024 * 1024
DEFAULT_DAMAGE_PROFILE = "original_1x"
DESKTOP_DAMAGE_PROFILE = "client_v4_x10"
LIMITATIONS = (
"Experimental fixed clock: not validated against original AIR battle trajectories.",
"Straight-line ground movement; collision, inertia, flight height and animation joins are approximated.",
@@ -75,6 +77,15 @@ def _freeze(value):
return value
DAMAGE_PROFILES = _freeze({
DEFAULT_DAMAGE_PROFILE: {"multiplier": 1, "cap": None},
DESKTOP_DAMAGE_PROFILE: {"multiplier": 10, "cap": 50000},
})
DAMAGE_PROFILE_DIGESTS = _freeze({name: hashlib.sha256(json.dumps(
{"name": name, **config}, sort_keys=True, separators=(",", ":")).encode("ascii")).hexdigest()
for name, config in DAMAGE_PROFILES.items()})
def _plain(value):
if isinstance(value, Mapping):
return {str(k): _plain(v) for k, v in value.items()}
@@ -83,6 +94,20 @@ def _plain(value):
return value
def _damage_profile(request):
name = _get(request, "damage_profile", DEFAULT_DAMAGE_PROFILE)
if not isinstance(name, str) or name not in DAMAGE_PROFILES:
raise SimulationInputError("Unknown damage profile")
return name, DAMAGE_PROFILES[name]
def _damage_profile_report(name, config):
return {"damage_profile": name, "damage_multiplier": config["multiplier"],
"damage_cap": config["cap"], "damage_profile_digest": DAMAGE_PROFILE_DIGESTS[name],
"damage_profile_scope": "team1 attacker to team2 target, after hurt controllers and before HP deduction"
if name == DESKTOP_DAMAGE_PROFILE else "unchanged original final damage"}
def _position(value):
if value is None:
return None
@@ -408,6 +433,8 @@ def _prepare(request, tables):
report["reasons"].append(message)
try:
profile_name, profile_config = _damage_profile(request)
report.update(_damage_profile_report(profile_name, profile_config))
if _get(request, "context") not in CONTEXTS:
raise SimulationInputError("Context must be ordinary_stage, task_battle or task_pass_stage")
original = _get(request, "original_data", {})
@@ -651,6 +678,8 @@ class _Battle:
def __init__(self, scenario, report, tables):
self.s = scenario
self.report = report
self.damage_profile = report["damage_profile"]
self.damage_config = DAMAGE_PROFILES[self.damage_profile]
self.tables = tables
self.game = tables["game_setting"]
self.rng = random.Random(scenario.seed)
@@ -684,6 +713,9 @@ class _Battle:
def event(self, kind, **fields):
record = {"at_ms": self.now, "type": kind, **fields}
if kind == "damage":
record.update(damage_profile=self.damage_profile,
damage_cap=self.damage_config["cap"])
if len(self.events) < self.s.trace_limit:
self.events.append(record)
else:
@@ -923,6 +955,7 @@ class _Battle:
amount = int(amount * actor.unit.hurt_types[str(attacker.unit.species)])
if real_attack:
amount = max(0, int(amount * (1 - actor.unit.stats.damage_reduction)))
amount = self.final_damage(amount, attacker, actor)
lost = min(actor.hp, amount)
actor.hp -= lost
actor.total_hurt += amount
@@ -940,6 +973,7 @@ class _Battle:
self.finish_death(actor)
return amount
amount = max(0, int(int(amount) * (1 - actor.unit.stats.damage_reduction)))
amount = self.final_damage(amount, attacker, actor)
lost = min(actor.hp, amount)
actor.hp -= lost
actor.total_hurt += amount
@@ -957,6 +991,13 @@ class _Battle:
self.finish_death(actor)
return amount
def final_damage(self, amount, attacker, actor):
"""V4's insertion: after every existing modifier, immediately before HP loss."""
if (self.damage_profile == DESKTOP_DAMAGE_PROFILE and attacker is not None
and attacker.unit.team == 1 and actor.unit.team == 2):
return int(min(amount * self.damage_config["multiplier"], self.damage_config["cap"]))
return amount
def finish_death(self, actor):
actor.state = "dead"
actor.died_ms = self.now
@@ -1278,7 +1319,8 @@ def _transport_request(request):
raw["master"] = {k: v for k, v in raw["master"].items()
if k in ("level", "globalAtk", "globalDef", "globalHp", "globalDex")}
original = _get(request, "original_data", {})
return {"context": _get(request, "context"), "original_data": {"battle": _plain(_get(original, "battle"))},
return {"context": _get(request, "context"), "damage_profile": _damage_profile(request)[0],
"original_data": {"battle": _plain(_get(original, "battle"))},
"roster": raw, "team": _get(request, "team", "teamA"),
"seed": _get(request, "seed", 0), "trace_limit": _get(request, "trace_limit", 2000),
"battle_position": _position(_get(request, "battle_position"))}