Files
WT-Offline/gui-patches/battle/launch-local-battle-from-queue/patch.json
T
N0VAN0M4LY b260d2899e chore(battle): snapshot the LocalMP rework baseline
Records the uncommitted battle-session work exactly as it was left
(local service matchmaking, settlement, chat, native LocalMP hooks,
battle gui/exe patches) so the following review and rework commits
show every correction as a diff against this state.

This commit is not reviewed and is known to be incomplete: in-game
testing reported wrong settlement rewards, single-country teams,
missing random/fixed supplement slots, misattributed hit messages and
other regressions. Do not merge this branch before the rework lands.
2026-11-28 03:15:47 +08:00

12 lines
9.1 KiB
JSON

{
"id": "battle/launch-local-battle-from-queue",
"title": "Launch local authoritative multiplayer battle on queue notification",
"file": "scripts/matching/servicenotifications/match.nut",
"reason": "Start an authoritative LocalMP host session from matching notifications with multi-nation coalition room state, per-difficulty mission ticket overrides, persistent killstreak spawn costs, and extra battle slot metadata.",
"features": ["battle-matchmaking", "mission-launch", "ai-bots"],
"edit": {
"find": " matchingApiFunc(\"match.enqueue\", cb, params)\r\n}\r\n\r\nmatchingRpcSubscribe(\"match.notify_clusters_changed\", onClustersChanged)",
"replace": " matchingApiFunc(\"match.enqueue\", cb, params)\r\n}\r\n\r\nfunction fillWtoBotEntries(parentBlk, blockName, entries) {\r\n if (entries == null)\r\n return\r\n foreach (entry in entries) {\r\n let b = parentBlk.addNewBlock(blockName)\r\n b.name = entry.name\r\n b.weight = (entry?.weight ?? 1.0).tofloat()\r\n b.country = entry.country\r\n }\r\n}\r\n\r\nfunction copyWtoMissionMetadata(misBlk, missionFile, difficulty) {\r\n if (missionFile == null || missionFile == \"\")\r\n return\r\n let { blkOptFromPath } = require(\"%sqstd/datablock.nut\")\r\n let rawMis = blkOptFromPath(missionFile)?.mission_settings?.mission\r\n if (rawMis == null)\r\n return\r\n let ruleKeys = [\r\n \"scoreLimit\", \"timeLimit\", \"killLimit\", \"deathPenaltyMul\",\r\n \"ctaCaptureZoneEqualPenaltyMul\", \"ctaCaptureZonePenaltyMul\",\r\n \"captureZonePenaltyMul\", \"scorePerSec\",\r\n \"ctaInstantDecreaseTicketsWhenNoRespawn\",\r\n \"randomSpawnTeams\", \"remapAiTankModels\", \"useAlternativeMapCoord\"\r\n ]\r\n foreach (key in [\r\n \"locName\", \"locDesc\", \"locNameTeamA\", \"locNameTeamB\",\r\n \"locDescTeamA\", \"locDescTeamB\", \"loc_name\", \"postfix\", \"restoreType\"\r\n ].extend(ruleKeys)) {\r\n let val = rawMis?[key]\r\n if (val != null)\r\n misBlk[key] = val\r\n }\r\n let targetDiff = (difficulty == \"simulator\" || difficulty == \"fullreal\") ? \"hardcore\"\r\n : (difficulty == \"historical\" ? \"realistic\" : difficulty)\r\n foreach (sub in (rawMis % \"mission\")) {\r\n let subDiff = sub?.difficulty\r\n if (subDiff != difficulty && subDiff != targetDiff)\r\n continue\r\n foreach (dKey in ruleKeys) {\r\n let dVal = sub?[dKey]\r\n if (dVal != null)\r\n misBlk[dKey] = dVal\r\n }\r\n }\r\n}\r\n\r\nfunction toWtoPrefixedCountries(list, fallback) {\r\n let src = (list != null && list.len() > 0) ? list : [fallback]\r\n return src.map(@(c) c.indexof(\"country_\") == 0 ? c : $\"country_{c}\")\r\n}\r\n\r\nfunction buildWtoMissionBlk(ev, gmConsts, guiMis) {\r\n let DataBlock = require(\"DataBlock\")\r\n let misBlk = DataBlock()\r\n let baseBlk = guiMis.get_meta_mission_info_by_gm_and_name(gmConsts.GM_SKIRMISH, ev.missionName)\r\n ?? guiMis.get_meta_mission_info_by_name(ev.missionName)\r\n copyWtoMissionMetadata(misBlk, ev?.missionFile, ev.difficulty)\r\n let levelVal = ev?.level ?? baseBlk?.level ?? misBlk?.level\r\n let envVal = ev?.environment ?? baseBlk?.environment ?? misBlk?.environment\r\n let weatherVal = ev?.weather ?? baseBlk?.weather ?? misBlk?.weather\r\n if (levelVal != null)\r\n misBlk.level = levelVal\r\n if (envVal != null)\r\n misBlk.environment = envVal\r\n if (weatherVal != null)\r\n misBlk.weather = weatherVal\r\n\r\n misBlk.localMP = true\r\n misBlk._gameMode = gmConsts.GM_DOMINATION\r\n misBlk.name = ev.missionName\r\n misBlk.economicName = ev.economicName\r\n misBlk.mis_file = ev.missionFile\r\n misBlk.chapter = \"skirmish\"\r\n misBlk.type = ev.missionType\r\n misBlk.difficulty = ev.difficulty\r\n misBlk.country_allies = ev.countryAllies\r\n misBlk.country_axis = ev.countryAxis\r\n misBlk.arcadeCountry = true\r\n misBlk.symmetricTeams = ev?.symmetricTeams ?? false\r\n misBlk.gt_versus = true\r\n misBlk.gt_mp_tickets = true\r\n misBlk.gt_mp_capture = true\r\n misBlk.gt_mp_solo = false\r\n misBlk.gt_use_wp = true\r\n misBlk.gt_use_xp = true\r\n misBlk.gt_use_stats = true\r\n misBlk.gt_use_unlocks = true\r\n misBlk.useSpawnScore = ev?.useSpawnScore ?? false\r\n misBlk.allowSpare = true\r\n misBlk.isLimitedAmmo = true\r\n misBlk.allowUseArtillerySupport = true\r\n misBlk.isBotsAllowed = true\r\n misBlk.useTankBots = ev?.useTankBots ?? false\r\n misBlk.useShipBots = ev?.useShipBots ?? false\r\n misBlk.autoBalance = true\r\n misBlk.maxPlayers = ev.maxPlayers\r\n misBlk.maxBots = ev.maxBots\r\n\r\n let extraSlots = ev?.extraBattleSlots ?? []\r\n local persistentBlk = null\r\n foreach (slot in extraSlots) {\r\n let cost = slot?.persistentCost ?? 0\r\n let uName = slot?.unitName ?? \"\"\r\n if (cost > 0 && uName != \"\") {\r\n if (persistentBlk == null)\r\n persistentBlk = misBlk.addNewBlock(\"customSpawnScore\").addNewBlock(\"persistent_costs\")\r\n persistentBlk[uName] = cost.tointeger()\r\n }\r\n }\r\n\r\n foreach (tag in [\"ranks\", \"forcedRanks\"]) {\r\n let rBlk = misBlk.addNewBlock(tag)\r\n rBlk.min = ev.minMrank\r\n rBlk.max = ev.maxMrank\r\n }\r\n let alliesBare = ev?.countriesAllies ?? [ev.countryAllies]\r\n let axisBare = ev?.countriesAxis ?? [ev.countryAxis]\r\n let botsBlk = misBlk.addNewBlock(\"customBots\")\r\n botsBlk.wtoPlayerTeam = $\"{ev?.playerTeam ?? 1}\"\r\n botsBlk.wtoTeamACountries = \";\".join(alliesBare)\r\n botsBlk.wtoTeamBCountries = \";\".join(axisBare)\r\n botsBlk.numBotRespawnsInMultiSlot = ev.airBotRespawns\r\n botsBlk.numTankBotRespawnsInMultiSlot = ev.tankBotRespawns\r\n botsBlk.numBotRespawnsInVersus = ev.airBotRespawns\r\n botsBlk.numTankBotRespawnsInVersus = ev.tankBotRespawns\r\n fillWtoBotEntries(botsBlk.addNewBlock(\"allowedTanks\"), \"tank\", ev?.customBots?.tanks)\r\n fillWtoBotEntries(botsBlk.addNewBlock(\"allowedAircrafts\"), \"aircraft\", ev?.customBots?.aircrafts)\r\n fillWtoBotEntries(botsBlk.addNewBlock(\"allowedShips\"), \"ship\", ev?.customBots?.ships)\r\n return misBlk\r\n}\r\n\r\nfunction enterWtoSessionRoom(ev, gmConsts) {\r\n let lobbyStates = require(\"%scripts/matchingRooms/lobbyStates.nut\")\r\n let { setSessionLobbySettings, switchSessionLobbyStatus } = require(\"%scripts/matchingRooms/sessionLobbyManager.nut\")\r\n let alliesCountries = toWtoPrefixedCountries(ev?.countriesAllies, ev.countryAllies)\r\n let axisCountries = toWtoPrefixedCountries(ev?.countriesAxis, ev.countryAxis)\r\n setSessionLobbySettings({\r\n game_mode_id = ev.modeId\r\n game_mode_name = ev.modeName\r\n economicName = ev.economicName\r\n symmetricTeams = ev?.symmetricTeams ?? false\r\n country_allies = alliesCountries\r\n country_axis = axisCountries\r\n mission = {\r\n name = ev.missionName\r\n _gameMode = gmConsts.GM_DOMINATION\r\n difficulty = ev.difficulty\r\n }\r\n }, true, false)\r\n switchSessionLobbyStatus(lobbyStates.IN_SESSION)\r\n}\r\n\r\nfunction onWtoBattleNotify(ev) {\r\n if (ev?.func != \"launch\" || isInFlight())\r\n return\r\n let { ndbWrite } = require(\"nestdb\")\r\n let guiMis = require(\"guiMission\")\r\n let missionMod = require(\"mission\")\r\n let gmConsts = require(\"%globalScripts/gameModeNativeConsts.nut\")\r\n let { reset_cur_mission_mode } = require(\"%appGlobals/ranks_common_shared.nut\")\r\n let { notifyQueueLeave } = require(\"%scripts/queue/queueManager.nut\")\r\n let destroySessionScripted = require(\"%scripts/matchingRooms/destroySessionScripted.nut\")\r\n let { invalidateCrewsList } = require(\"%scripts/slotbar/crewsList.nut\")\r\n let { guiStartFlight } = require(\"%scripts/missions/startMissionsList.nut\")\r\n let { currentCampaignMission } = require(\"%scripts/missions/missionsStates.nut\")\r\n\r\n notifyQueueLeave({})\r\n destroySessionScripted(\"on start wto local battle\")\r\n ndbWrite([\"wto\", \"activeBattle\"], {\r\n sessionId = ev.sessionId\r\n modeName = ev.modeName\r\n economicName = ev.economicName\r\n country = ev.country\r\n missionName = ev.missionName\r\n extraBattleSlots = ev?.extraBattleSlots ?? []\r\n randomUnits = ev?.randomUnits ?? {}\r\n randomUnitsEventName = ev?.randomUnitsEventName ?? \"\"\r\n })\r\n invalidateCrewsList(true)\r\n let misBlk = buildWtoMissionBlk(ev, gmConsts, guiMis)\r\n currentCampaignMission.set(ev.missionName)\r\n missionMod.set_game_mode(gmConsts.GM_DOMINATION)\r\n enterWtoSessionRoom(ev, gmConsts)\r\n reset_cur_mission_mode()\r\n guiMis.select_training_mission(misBlk)\r\n reset_cur_mission_mode()\r\n guiStartFlight()\r\n}\r\n\r\nrequire(\"%sqStdLibs/helpers/subscriptions.nut\").addListenersWithoutEnv({\r\n SessionDestroyed = function(_p) {\r\n if (!isInFlight()) {\r\n let { ndbExists, ndbDelete } = require(\"nestdb\")\r\n if (ndbExists([\"wto\", \"activeBattle\"])) {\r\n ndbDelete([\"wto\", \"activeBattle\"])\r\n require(\"%scripts/slotbar/crewsList.nut\").invalidateCrewsList(true)\r\n }\r\n }\r\n }\r\n})\r\n\r\nrequire(\"%scripts/matching/serviceNotifications/mrpc.nut\").mnSubscribe(\"wto_battle\", onWtoBattleNotify)\r\n\r\nmatchingRpcSubscribe(\"match.notify_clusters_changed\", onClustersChanged)"
}
}