Rebuild the extra vehicles a battle adds to the player's lineup on the game files and the official rules: - Random vehicles (dice slots): one per gameplay.blk RandomSpawnUnits group of the event economic name and country, offered from the group's minPlayerMRank on, with no condition on the lineup. The option window follows the official changelog examples (never the session's top BR, lower BR when nothing fits); its formula is inferred from the group parameters. Only the listed addModification items are enabled. - Nuclear carrier: missionSupportPlane preset of the session rank, cost spawnScoreToUse. - Strike UCAV: offered by an offline tuning rule, priced by the stock spawn score formula, no forced preset. The spawn request enables exactly the slot's modifications, and every forced weapon travels in the slot, so the event-name fallback is gone.
88 lines
3.4 KiB
Plaintext
88 lines
3.4 KiB
Plaintext
function sendWtoAircraftAndWeaponRequest(requestData, isSilent = false) {
|
|
let wtoNdb = require("nestdb")
|
|
if (!wtoNdb.ndbExists(["wto", "activeBattle"]))
|
|
return requestAircraftAndWeaponWithSpare(requestData, requestData.idInCountry,
|
|
requestData.respBaseId, requestData.spareUid)
|
|
let wtoBattle = wtoNdb.ndbTryRead(["wto", "activeBattle"])
|
|
let wtoGuiRespawn = require("guiRespawn")
|
|
let wtoChardRes = require("chardResearch")
|
|
let wtoUnitName = requestData?.name ?? ""
|
|
local wtoExtraSlot = null
|
|
foreach (slot in (wtoBattle?.extraBattleSlots ?? [])) {
|
|
if (slot?.unitName == wtoUnitName) {
|
|
wtoExtraSlot = slot
|
|
break
|
|
}
|
|
}
|
|
if ((wtoExtraSlot?.forceWeapon ?? "") != "")
|
|
requestData.weapon = wtoExtraSlot.forceWeapon
|
|
let wtoSlotMods = wtoExtraSlot?.modifications ?? []
|
|
let wtoUnit = getAircraftByName(wtoUnitName) ?? this.getCurSlotUnit()
|
|
let wtoEnabledMods = []
|
|
let wtoDisabledMods = []
|
|
foreach (wtoMod in (wtoUnit?.getModifications() ?? [])) {
|
|
let wtoModName = wtoMod?.name ?? ""
|
|
if (wtoModName == "")
|
|
continue
|
|
let wtoIsEnabled = wtoExtraSlot == null
|
|
? wtoChardRes.shopIsModificationEnabled(wtoUnitName, wtoModName)
|
|
: (wtoExtraSlot?.allModifications == true || wtoSlotMods.contains(wtoModName))
|
|
if (wtoIsEnabled)
|
|
wtoEnabledMods.append(wtoModName)
|
|
else if (wtoExtraSlot == null && wtoChardRes.shopIsModificationPurchased(wtoUnitName, wtoModName))
|
|
wtoDisabledMods.append(wtoModName)
|
|
}
|
|
let wtoBlk = DataBlock()
|
|
wtoBlk.enabledMods = ";".join(wtoEnabledMods)
|
|
wtoBlk.disabledMods = ";".join(wtoDisabledMods)
|
|
wtoBlk.isSilentPreview = isSilent ? "1" : "0"
|
|
if (!isSilent && (requestData?.spareUid ?? "") != "" && wtoUnitName != "") {
|
|
let prevSpares = wtoBattle?.usedSpares ?? {}
|
|
prevSpares[wtoUnitName] <- (prevSpares?[wtoUnitName] ?? 0) + 1
|
|
wtoBattle.usedSpares <- prevSpares
|
|
wtoNdb.ndbWrite(["wto", "activeBattle"], wtoBattle)
|
|
}
|
|
return wtoGuiRespawn.requestAircraftAndWeaponWithSlots(requestData, requestData.idInCountry,
|
|
requestData.respBaseId, requestData.spareUid, wtoBlk, DataBlock())
|
|
}
|
|
|
|
function requestAircraftAndWeapon(requestData) {
|
|
if (this.requestInProgress)
|
|
return
|
|
|
|
set_aircraft_accepted_cb(this, this.aircraftAcceptedCb);
|
|
let _taskId = this.sendWtoAircraftAndWeaponRequest(requestData, false)
|
|
if (_taskId < 0)
|
|
set_aircraft_accepted_cb(null, null);
|
|
else {
|
|
this.requestInProgress = true
|
|
this.showTaskProgressBox(loc("charServer/purchase0"), function() { this.requestInProgress = false })
|
|
|
|
this.lastRequestData = requestData
|
|
}
|
|
}
|
|
|
|
function requestChangeUnitSilent() {
|
|
let unit = this.getCurSlotUnit()
|
|
if (!unit?.isHuman() || !this.canChangeAircraft || this.isApplyPressed) {
|
|
this.isSilentRequestPending = false
|
|
return
|
|
}
|
|
this.isSilentRequestPending = this.requestInProgress || !canRequestAircraftNow()
|
|
if (this.isSilentRequestPending)
|
|
return
|
|
|
|
let requestData = this.getSelectedRequestData(true)
|
|
if (!requestData)
|
|
return
|
|
|
|
set_aircraft_accepted_cb(this, this.silentAircraftAcceptedCb);
|
|
let _taskId = this.sendWtoAircraftAndWeaponRequest(requestData, true)
|
|
if (_taskId < 0)
|
|
set_aircraft_accepted_cb(null, null);
|
|
else {
|
|
this.requestInProgress = true
|
|
this.lastRequestData = requestData
|
|
}
|
|
}
|