Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:
apps/server the local server (was packages/local-service),
package @wto/server
packages/patcher builds the game copy (was packages/build),
package @wto/patcher
patches/exe exe patch definitions (was exe-patches)
patches/gui GUI script patches (was gui-patches)
Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".
The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.
The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.
Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
126 lines
5.0 KiB
Plaintext
126 lines
5.0 KiB
Plaintext
// WTOffline: report a finished LocalMP battle to the local server 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 battleLog = ndbTryRead(["wto", "battleLog"]) ?? {}
|
|
let blk = DataBlock()
|
|
blk.sessionId = wtoBattle.sessionId
|
|
// 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()
|
|
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 strikesBlk = blk.addNewBlock("strikes")
|
|
foreach (strike in (battleLog?.strikes ?? [])) {
|
|
let strikeBlk = strikesBlk.addNewBlock("s")
|
|
strikeBlk.time = strike.time.tofloat()
|
|
}
|
|
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
|
|
let evObj = events.getEvent(wtoBattle?.modeName ?? "")
|
|
let roomEvent = evObj == null ? null : {
|
|
name = evObj?.name
|
|
economicName = evObj?.economicName
|
|
difficulty = evObj?.difficulty
|
|
chapter = evObj?.chapter
|
|
gameModeId = evObj?.gameModeId
|
|
}
|
|
ndbWrite(["wto", "settled"], {
|
|
exp = sessionLog.wtoDebriefing
|
|
roomId = sessionLog.roomId
|
|
win = sessionLog?.win ?? false
|
|
roomEvent
|
|
})
|
|
gatherDebriefingResult()
|
|
ndbDelete(["wto", "settled"])
|
|
}
|
|
|
|
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)
|
|
}
|