diff --git a/gui-patches/battle/record-local-battle-awards/replace.nut b/gui-patches/battle/record-local-battle-awards/replace.nut index 271dee9..dec89ff 100644 --- a/gui-patches/battle/record-local-battle-awards/replace.nut +++ b/gui-patches/battle/record-local-battle-awards/replace.nut @@ -160,43 +160,29 @@ function wtoOnLocalMpNuclearStrike(_ev) { wtoSendLiveFact("strike", strike) } -// 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) g_hud_event_manager.subscribe("wtoLocalMpNuclearStrike", wtoOnLocalMpNuclearStrike) } -// Leaving the battle from the menu before it has ended. +// The local player leaves the battle, after its end (the fade to the debriefing) or from the menu +// before it. The mission still exists here and is unloaded before the debriefing opens, so this is +// where the settlement report gets the end time and the outcome, as the stock debriefing gathers +// its result on this event (debriefingFull.nut). Leaving a running battle records no outcome. function wtoOnQuitToDebriefing(_p) { - wtoEndBattleRecord() + let { ndbExists, ndbWrite } = require("nestdb") + if (!ndbExists(["wto", "activeBattle"]) || ndbExists(["wto", "battleLog", "sessionEnd"])) + return + wtoCloseBattleLife(false) + ndbWrite(["wto", "battleLog", "sessionEnd"], require("mission").get_mission_time()) + let guiMis = require("guiMission") + let status = guiMis.get_mission_status() + if (status == guiMis.MISSION_STATUS_SUCCESS || status == guiMis.MISSION_STATUS_FAIL) + ndbWrite(["wto", "battleLog", "outcome"], status == guiMis.MISSION_STATUS_SUCCESS ? "win" : "lose") } wtoSubscribeBattleAwards()