The battle awards (streaks) of unlocks.blk are now judged by the local service from the battle's facts: the player's combat events, each life and whether it ended in death, the HUD kill log and the final scoreboard. The record patch also sends each fact live over the matching connection (wto_battle.fact); the awards it completes come back and are shown with the stock award banner and kill log entry. After the battle the awards become EULT_NEW_STREAK logs, which the stock debriefing lists on its left, and their Silver Lions are paid and shown in the Unlocks row. Modes whose facts are not reported, and best-player awards limited by battle rating, are never given.
122 lines
4.9 KiB
Plaintext
122 lines
4.9 KiB
Plaintext
// WTOffline: report a finished LocalMP battle to the local service as facts (lives and combat events
|
|
// recorded by record-local-battle-awards, the outcome and the team scores), then build the debriefing
|
|
// from the statistics the service settled (see use-settled-debriefing-stats). The client computes
|
|
// 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"
|
|
blk.localTeam = (res?.localTeam ?? 1).tointeger()
|
|
blk.teamAScore = (res?.mpTblTeams?[0]?.score ?? 0).tointeger()
|
|
blk.teamBScore = (res?.mpTblTeams?[1]?.score ?? 0).tointeger()
|
|
let lives = battleLog?.lives ?? []
|
|
let sessionEnd = battleLog?.sessionEnd ?? lives.reduce(@(acc, life) life.end > acc ? life.end : acc, 0.0)
|
|
blk.sessionStart = 0.0
|
|
blk.sessionEnd = sessionEnd.tofloat()
|
|
blk.localPlayerId = (require("mission").get_local_mplayer()?.id ?? -1).tointeger()
|
|
let livesBlk = blk.addNewBlock("lives")
|
|
foreach (life in lives) {
|
|
let lifeBlk = livesBlk.addNewBlock("life")
|
|
lifeBlk.unit = life.unit
|
|
lifeBlk.start = life.start.tofloat()
|
|
lifeBlk.end = life.end.tofloat()
|
|
lifeBlk.died = life?.died ?? false
|
|
}
|
|
let feedBlk = blk.addNewBlock("feed")
|
|
foreach (kill in (battleLog?.feed ?? [])) {
|
|
let killBlk = feedBlk.addNewBlock("k")
|
|
killBlk.time = kill.time.tofloat()
|
|
foreach (key in ["killer", "killerTeam", "victim", "victimTeam"])
|
|
killBlk[key] = kill[key].tointeger()
|
|
}
|
|
// The final scoreboard, for the awards given to the best player of the battle.
|
|
let playersBlk = blk.addNewBlock("players")
|
|
foreach (player in (res?.mplayers_list ?? [])) {
|
|
let playerBlk = playersBlk.addNewBlock("p")
|
|
playerBlk.id = (player?.id ?? -1).tointeger()
|
|
playerBlk.team = (player?.team ?? 0).tointeger()
|
|
foreach (key in ["score", "kills", "groundKills", "humanKills", "navalKills", "aiKills", "aiGroundKills",
|
|
"aiNavalKills", "assists", "deaths"])
|
|
playerBlk[key] = (player?[key] ?? 0).tointeger()
|
|
}
|
|
let eventsBlk = blk.addNewBlock("events")
|
|
foreach (ev in (battleLog?.events ?? [])) {
|
|
let evBlk = eventsBlk.addNewBlock("e")
|
|
evBlk.time = ev.time.tofloat()
|
|
evBlk.unit = ev.unit
|
|
evBlk.code = ev.code.tointeger()
|
|
evBlk.expClass = ev.expClass
|
|
evBlk.victim = ev.victim
|
|
evBlk.victimIsPlayer = ev.victimIsPlayer
|
|
evBlk.friendly = ev.friendly
|
|
evBlk.modifier = ev.modifier
|
|
evBlk.damage = ev.damage.tointeger()
|
|
}
|
|
let sparesBlk = blk.addNewBlock("spares")
|
|
foreach (spUnit, spCnt in (wtoBattle?.usedSpares ?? {}))
|
|
if (spUnit != "" && spCnt > 0)
|
|
sparesBlk[spUnit] = spCnt.tointeger()
|
|
return blk
|
|
}
|
|
|
|
function applyWtoSettledDebriefing(wtoBattle) {
|
|
let { ndbWrite, ndbDelete } = require("nestdb")
|
|
let sessionLog = getUserLogsList({ show = [EULT_SESSION_RESULT], disableVisible = true })
|
|
.findvalue(@(l) l?.wtoSessionId == wtoBattle.sessionId)
|
|
if (sessionLog?.wtoDebriefing == null)
|
|
return
|
|
ndbWrite(["wto", "settled"], { exp = sessionLog.wtoDebriefing, roomId = sessionLog.roomId })
|
|
gatherDebriefingResult()
|
|
ndbDelete(["wto", "settled"])
|
|
let cur = getDebriefingResult()
|
|
cur.isSucceed = sessionLog?.win ?? false
|
|
let evObj = events.getEvent(wtoBattle?.modeName ?? "")
|
|
if (evObj != null && cur.roomEvent == null)
|
|
cur.roomEvent = {
|
|
name = evObj?.name
|
|
economicName = evObj?.economicName
|
|
difficulty = evObj?.difficulty
|
|
chapter = evObj?.chapter
|
|
gameModeId = evObj?.gameModeId
|
|
}
|
|
}
|
|
|
|
function settleWtoBattleAndOpen(wtoBattle, params) {
|
|
let { charSendBlk } = require("chard")
|
|
let { addTask } = require("%scripts/tasker.nut")
|
|
let openModal = function() {
|
|
updateGamercards()
|
|
loadHandler(get_gui_handler("DebriefingModal"), params)
|
|
}
|
|
let onSuccess = function() {
|
|
applyWtoSettledDebriefing(wtoBattle)
|
|
openModal()
|
|
}
|
|
let taskId = charSendBlk("cln_wto_finish_battle", buildWtoBattleReport(wtoBattle, getDebriefingResult()))
|
|
if (taskId < 0 || !addTask(taskId, { showProgressBox = true, showErrorMsgBox = true }, onSuccess, @(_) openModal()))
|
|
openModal()
|
|
}
|
|
|
|
function guiStartDebriefingFull(params = {}) {
|
|
let { ndbTryRead, ndbDelete } = require("nestdb")
|
|
let wtoBattle = ndbTryRead(["wto", "activeBattle"])
|
|
if (wtoBattle != null) {
|
|
ndbDelete(["wto", "activeBattle"])
|
|
if (getDebriefingResult() == null)
|
|
gatherDebriefingResult()
|
|
let curMis = getDebriefingResult()?.missionName ?? ""
|
|
let expectedMis = wtoBattle?.missionName ?? ""
|
|
if (get_game_mode() == GM_DOMINATION && (expectedMis == "" || curMis == expectedMis)) {
|
|
settleWtoBattleAndOpen(wtoBattle, params)
|
|
return
|
|
}
|
|
}
|
|
loadHandler(get_gui_handler("DebriefingModal"), params)
|
|
}
|