Judge LocalMP battle awards in the local service

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.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 08:32:35 +08:00
1 parent 1803cc00da
commit 8febf2d94e
17 files changed
+925 -25

No files matched your search

@@ -1,14 +1,18 @@
// Record the local player's lives and combat events in a LocalMP battle and show their reward banner.
// Why the client: online the battle server prices each event and sends the banner (packet 0xb03d);
// a LocalMP host has no battle server, so the native bridge reports the facts as the HUD event
// "wtoLocalMpExpEvent" and only the client sees when the player spawns and dies.
// Without it: no reward banners in battle and nothing to settle after it.
// 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.
// 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,
// deaths and the kill log.
// Without it: no reward or award banners in battle and nothing to settle after it.
{
"id": "battle/record-local-battle-awards",
"title": "Record LocalMP combat events and lives, and show their reward banner",
"title": "Record LocalMP battle facts and show their reward and award banners",
"file": "scripts/hud/hudrewardmessage.nut",
"features": [
"K-击杀、助攻、占点计分"
"K-击杀、助攻、占点计分",
"L-战斗奖章"
],
"verified_on": [
"2.61.0.37"
@@ -3,6 +3,43 @@
// HUD event "wtoLocalMpExpEvent" with the facts, the banner amount comes from the parameters the
// local service sent at launch (nestdb wto.activeBattle.awards, battle-economy.ts BannerParams), and
// the record (nestdb wto.battleLog) is settled by the local service after the battle.
// Each fact is also sent to the local service as it happens (matching request wto_battle.fact);
// the battle awards (streaks) it completed come back and are shown with the stock award banner,
// as the battle server's award messages are online.
function wtoShowLiveStreaks(resp) {
let streaks = resp?.streaks ?? []
if (streaks.len() == 0)
return
let { add_streak_message, getLocForStreak } = require("%scripts/streaks.nut")
let { SNT_MY_STREAK_HEADER } = require("%globalScripts/battleMetaConsts.nut")
let { HUD_MSG_STREAK } = require("hudMessages")
let { g_hud_event_manager } = require("%scripts/hud/hudEventManager.nut")
let localId = require("mission").get_local_mplayer()?.id ?? -1
foreach (streak in streaks) {
let stageParam = streak?.stageParam ?? 0
add_streak_message({
header = getLocForStreak(SNT_MY_STREAK_HEADER, streak.id, stageParam)
wp = streak?.wp ?? 0
exp = streak?.exp ?? 0
id = streak.id
})
g_hud_event_manager.onHudEvent("HudMessage", { type = HUD_MSG_STREAK, unlockId = streak.id, stage = stageParam, playerId = localId })
}
}
function wtoSendLiveFact(kind, fact) {
let battle = require("nestdb").ndbTryRead(["wto", "activeBattle"])
if (battle == null)
return
let { matchingApiFunc } = require("%scripts/matching/api.nut")
matchingApiFunc("wto_battle.fact", wtoShowLiveStreaks, fact.__merge({
sessionId = battle.sessionId
kind
localPlayerId = require("mission").get_local_mplayer()?.id ?? -1
localTeam = require("mission").get_mp_local_team()
}))
}
function wtoAppendBattleLog(key, entry) {
let { ndbTryRead, ndbWrite } = require("nestdb")
let list = (ndbTryRead(["wto", "battleLog", key]) ?? []).map(@(v) v)
@@ -37,7 +74,7 @@ function wtoOnLocalMpExpEvent(ev) {
return
let wtoMission = require("mission")
let unit = ndbTryRead(["wto", "battleLog", "openLife"])?.unit ?? require("unit").get_player_unit_name()
wtoAppendBattleLog("events", {
let entry = {
time = wtoMission.get_mission_time()
unit
code = ev?.messageCode ?? -1
@@ -47,7 +84,9 @@ function wtoOnLocalMpExpEvent(ev) {
friendly = (ev?.friendly ?? 0) != 0
modifier = ev?.messageModifier ?? ""
damage = ev?.damage ?? 0
})
}
wtoAppendBattleLog("events", entry)
wtoSendLiveFact("event", entry)
let reward = wtoBannerReward(battle?.awards, unit, ev)
if (reward == null)
return
@@ -62,20 +101,22 @@ function wtoOnLocalMpExpEvent(ev) {
})
}
function wtoCloseBattleLife() {
function wtoCloseBattleLife(died) {
let { ndbTryRead, ndbDelete } = require("nestdb")
let life = ndbTryRead(["wto", "battleLog", "openLife"])
if (life == null)
return
ndbDelete(["wto", "battleLog", "openLife"])
wtoAppendBattleLog("lives", life.__merge({ end = require("mission").get_mission_time() }))
let closed = life.__merge({ end = require("mission").get_mission_time(), died })
wtoAppendBattleLog("lives", closed)
wtoSendLiveFact("life", closed)
}
function wtoOnLocalPlayerAlive(_ev) {
let { ndbExists, ndbWrite } = require("nestdb")
if (!ndbExists(["wto", "activeBattle"]))
return
wtoCloseBattleLife()
wtoCloseBattleLife(false)
let unit = require("unit").get_player_unit_name()
if ((unit ?? "") != "")
ndbWrite(["wto", "battleLog", "openLife"], { unit, start = require("mission").get_mission_time() })
@@ -83,7 +124,31 @@ function wtoOnLocalPlayerAlive(_ev) {
function wtoOnLocalPlayerDead(_ev) {
if (require("nestdb").ndbExists(["wto", "activeBattle"]))
wtoCloseBattleLife()
wtoCloseBattleLife(true)
}
// Every kill of the HUD kill log, for the awards that depend on who killed whom (first kill,
// avenging). A message without player ids is about the local player (scripts/hud/hudBattleLog.nut).
function wtoOnHudMessage(msg) {
let { HUD_MSG_MULTIPLAYER_DMG } = require("hudMessages")
if (msg?.type != HUD_MSG_MULTIPLAYER_DMG || !(msg?.isKill ?? true))
return
if (!require("nestdb").ndbExists(["wto", "activeBattle"]))
return
let wtoMission = require("mission")
let localId = wtoMission.get_local_mplayer()?.id ?? -1
let localTeam = wtoMission.get_mp_local_team()
let killer = msg?.playerId ?? localId
let victim = msg?.victimPlayerId ?? localId
let kill = {
time = wtoMission.get_mission_time()
killer
killerTeam = msg?.team ?? (killer == localId ? localTeam : 0)
victim
victimTeam = msg?.victimTeam ?? (victim == localId ? localTeam : 0)
}
wtoAppendBattleLog("feed", kill)
wtoSendLiveFact("kill", kill)
}
function wtoSubscribeBattleAwards() {
@@ -91,6 +156,7 @@ function wtoSubscribeBattleAwards() {
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)
}
// The battle ends for the local player here: close the open life and keep the end time, which the
@@ -99,7 +165,7 @@ function wtoOnQuitToDebriefing(_p) {
let { ndbExists, ndbWrite } = require("nestdb")
if (!ndbExists(["wto", "activeBattle"]))
return
wtoCloseBattleLife()
wtoCloseBattleLife(false)
ndbWrite(["wto", "battleLog", "sessionEnd"], require("mission").get_mission_time())
}
@@ -8,7 +8,8 @@
"title": "Report LocalMP battle facts to local-service and show the settled debriefing",
"file": "scripts/debriefing/debriefingmodal.nut",
"features": [
"L-结算页"
"L-结算页",
"L-战斗奖章"
],
"verified_on": [
"2.61.0.37"
@@ -19,12 +19,31 @@ function buildWtoBattleReport(wtoBattle, res) {
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 ?? [])) {