Use the signed i64 profile encoding identified in PR #13. Make attached backups selectable in LocalMP after the daily quota, and debit backups only after the engine confirms the selected slot entered play. Record the stock daily allowance once per room and slot. Settle owned backups using the confirmed spawn facts and keep repeat settlement from charging the same battle again. Verified server and launcher types, MSVC compilation, three client builds for patch and Quirrel checks, and a temporary 2.61.0.58 build. In-game acceptance is pending. Co-authored-by: duduyagame <[email protected]>
144 lines
5.8 KiB
Plaintext
144 lines
5.8 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 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) {
|
|
let source = this.getWtoBackupSourceForRequest(requestData)
|
|
let backup = this.getWtoBackupToken(requestData, source)
|
|
if (backup == null)
|
|
return -1
|
|
if (backup != "") {
|
|
requestData.wtoBackup <- backup
|
|
wtoBlk.wtoBackup = backup
|
|
}
|
|
if (source == "vehicle")
|
|
requestData.spareUid = ""
|
|
}
|
|
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
|
|
}
|
|
}
|