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 wtoGlobalModsBlk = require("blkGetters").get_modifications_blk()?.modifications let wtoUnitModsBlk = wtoUnitName != "" ? require("%scripts/unit/unitParams.nut").getFullUnitBlk(wtoUnitName)?.modifications : null // Only the bulletMod belts chosen in this spawn request may enter enabledMods; sending every // unlocked belt lets the last belt in wpcost.blk (usually stealth) overwrite single-belt guns. let wtoSelectedBullets = {} for (local wtoBi = 0; wtoBi < BULLETS_SETS_QUANTITY; wtoBi++) { let wtoBulName = requestData?[$"bullets{wtoBi}"] ?? "" if (wtoBulName != "") wtoSelectedBullets[wtoBulName] <- true } let wtoModNames = [] let wtoSeenMods = {} foreach (wtoMod in (wtoUnit?.getModifications() ?? [])) { let wtoName = wtoMod?.name ?? "" if (wtoName != "" && !(wtoName in wtoSeenMods)) { wtoSeenMods[wtoName] <- true wtoModNames.append(wtoName) } } if (wtoUnitModsBlk != null) { for (local wtoMi = 0; wtoMi < wtoUnitModsBlk.blockCount(); wtoMi++) { let wtoName = wtoUnitModsBlk.getBlock(wtoMi).getBlockName() if (wtoName != "" && !(wtoName in wtoSeenMods)) { wtoSeenMods[wtoName] <- true wtoModNames.append(wtoName) } } } let wtoEnabledMods = [] let wtoDisabledMods = [] foreach (wtoModName in wtoModNames) { let wtoIsEnabled = wtoExtraSlot == null ? wtoChardRes.shopIsModificationEnabled(wtoUnitName, wtoModName) : (wtoExtraSlot?.allModifications == true || wtoSlotMods.contains(wtoModName)) let wtoGlobalModBlk = wtoGlobalModsBlk?.getBlockByName(wtoModName) let wtoUnitModBlk = wtoUnitModsBlk?.getBlockByName(wtoModName) let wtoHasBulletMod = (wtoUnitModBlk?.getBlockByName("effects")?.paramExists("bulletMod") ?? false) || (wtoGlobalModBlk?.getBlockByName("effects")?.paramExists("bulletMod") ?? false) if (wtoHasBulletMod) { if (wtoIsEnabled && (wtoModName in wtoSelectedBullets)) wtoEnabledMods.append(wtoModName) continue } // Match UnitModifications::initFromSave / initFromLists: invertEnableLogic mods encode stock // penalties in effects{} and must move to disabledMods once enabled; normal unequipped mods // only enter disabledMods when they define disableModEffects{}. local wtoInvert = wtoGlobalModBlk?.getBool("invertEnableLogic", false) ?? false if (wtoUnitModBlk != null) wtoInvert = wtoUnitModBlk.getBool("invertEnableLogic", wtoInvert) let wtoHasDisableEffects = wtoUnitModBlk?.getBlockByName("disableModEffects") != null || wtoGlobalModBlk?.getBlockByName("disableModEffects") != null if (wtoInvert) { if (wtoIsEnabled) wtoDisabledMods.append(wtoModName) else wtoEnabledMods.append(wtoModName) } else if (wtoIsEnabled) wtoEnabledMods.append(wtoModName) else if (wtoHasDisableEffects) 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 } }