diff --git a/patches/gui/battle/pass-spawn-modifications-blk/replace.nut b/patches/gui/battle/pass-spawn-modifications-blk/replace.nut index 16d21d9..d5112e2 100644 --- a/patches/gui/battle/pass-spawn-modifications-blk/replace.nut +++ b/patches/gui/battle/pass-spawn-modifications-blk/replace.nut @@ -18,18 +18,68 @@ 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 (wtoMod in (wtoUnit?.getModifications() ?? [])) { - let wtoModName = wtoMod?.name ?? "" - if (wtoModName == "") - continue + foreach (wtoModName in wtoModNames) { let wtoIsEnabled = wtoExtraSlot == null ? wtoChardRes.shopIsModificationEnabled(wtoUnitName, wtoModName) : (wtoExtraSlot?.allModifications == true || wtoSlotMods.contains(wtoModName)) - if (wtoIsEnabled) + 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 (wtoExtraSlot == null && wtoChardRes.shopIsModificationPurchased(wtoUnitName, wtoModName)) + else if (wtoHasDisableEffects) wtoDisabledMods.append(wtoModName) } let wtoBlk = DataBlock()