fix(battle): record LocalMP outcomes when the mission ends

The settlement report read get_mission_status() when the debriefing
opened. By then the mission scene has been unloaded and the status reads
as running, so every battle that ended on its own (tickets or nuclear
strike) was settled as not won. The end time was lost the same way and
the last life was never closed: onQuitToDebriefing is only raised when
the battle is left from the menu, not by the automatic FadeToDebriefing.

AcesMission::endFinally (2.61.0.37 0x11203f0) raises the HUD event
MissionResult with the local team's result while the mission still
exists. Record the outcome, the end time and the closing life there;
leaving from the menu still records the end time without an outcome.

Checked with check-gui; not yet verified in game.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 19:01:15 +08:00
1 parent e023ae5c58
commit 8494269c55
3 files changed
+32 -15

No files matched your search

@@ -1,6 +1,6 @@
// Record the local player's lives, combat events and the battle's kill log in a LocalMP battle,
// show the reward banner, and pass each fact to the local service live to show the battle awards
// (streaks) it completes.
// Record the local player's lives, combat events, the battle's kill log and how the battle ended
// in a LocalMP battle, show the reward banner, and pass each fact to the local service live to
// show the battle awards (streaks) it completes.
// Why the client: online the battle server prices each event, judges the awards and sends both
// banners (packet 0xb03d, streak messages); a LocalMP host has no battle server, so the native
// bridge reports the facts as the HUD event "wtoLocalMpExpEvent" and only the client sees spawns,
@@ -151,22 +151,42 @@ function wtoOnHudMessage(msg) {
wtoSendLiveFact("kill", kill)
}
// The battle ends for the local player: close the open life and keep the end time, which the
// settlement report needs after the mission has been left (the mission is unloaded before the
// debriefing, so its time and status are gone by then). The first end counts.
function wtoEndBattleRecord() {
let { ndbExists, ndbWrite } = require("nestdb")
if (!ndbExists(["wto", "activeBattle"]) || ndbExists(["wto", "battleLog", "sessionEnd"]))
return false
wtoCloseBattleLife(false)
ndbWrite(["wto", "battleLog", "sessionEnd"], require("mission").get_mission_time())
return true
}
// AcesMission::endFinally raises this HUD event with the result for the local player's team on
// every end of the battle (tickets, nuclear strike, empty team), while the mission still exists.
// The end that follows on its own (FadeToDebriefing) raises no script event.
function wtoOnMissionResult(ev) {
let { GO_WIN, GO_FAIL } = require("guiMission")
let result = ev?.resultNum
if (result != GO_WIN && result != GO_FAIL)
return
if (wtoEndBattleRecord())
require("nestdb").ndbWrite(["wto", "battleLog", "outcome"], result == GO_WIN ? "win" : "lose")
}
function wtoSubscribeBattleAwards() {
let { g_hud_event_manager } = require("%scripts/hud/hudEventManager.nut")
g_hud_event_manager.subscribe("wtoLocalMpExpEvent", wtoOnLocalMpExpEvent)
g_hud_event_manager.subscribe("LocalPlayerAlive", wtoOnLocalPlayerAlive)
g_hud_event_manager.subscribe("LocalPlayerDead", wtoOnLocalPlayerDead)
g_hud_event_manager.subscribe("HudMessage", wtoOnHudMessage)
g_hud_event_manager.subscribe("MissionResult", wtoOnMissionResult)
}
// The battle ends for the local player here: close the open life and keep the end time, which the
// settlement report needs after the mission has been left.
// Leaving the battle from the menu before it has ended.
function wtoOnQuitToDebriefing(_p) {
let { ndbExists, ndbWrite } = require("nestdb")
if (!ndbExists(["wto", "activeBattle"]))
return
wtoCloseBattleLife(false)
ndbWrite(["wto", "battleLog", "sessionEnd"], require("mission").get_mission_time())
wtoEndBattleRecord()
}
wtoSubscribeBattleAwards()
@@ -4,14 +4,11 @@
// no rewards itself.
function buildWtoBattleReport(wtoBattle, res) {
let { ndbTryRead } = require("nestdb")
let guiMis = require("guiMission")
let battleLog = ndbTryRead(["wto", "battleLog"]) ?? {}
let mStatus = guiMis.get_mission_status()
let blk = DataBlock()
blk.sessionId = wtoBattle.sessionId
blk.outcome = mStatus == guiMis.MISSION_STATUS_SUCCESS ? "win"
: mStatus == guiMis.MISSION_STATUS_FAIL ? "lose"
: "running"
// Recorded when the battle ended (record-local-battle-awards); none when it was left before.
blk.outcome = battleLog?.outcome ?? "running"
blk.localTeam = (res?.localTeam ?? 1).tointeger()
blk.teamAScore = (res?.mpTblTeams?[0]?.score ?? 0).tointeger()
blk.teamBScore = (res?.mpTblTeams?[1]?.score ?? 0).tointeger()