From f21c91cae3d14a22803b2a55c560b93b91d1310c Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Sun, 18 Aug 2024 07:37:30 -0500 Subject: [PATCH] fix: Avoid penalizing Improved Heavy Lasers in weapon bays While heavy lasers incur an accuracy penalty, this obviously isn't meant to apply to improved heavy lasers, which are improved specifically by avoiding that. The check has also been made a bit more efficient. --- .../common/actions/WeaponAttackAction.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/megamek/src/megamek/common/actions/WeaponAttackAction.java b/megamek/src/megamek/common/actions/WeaponAttackAction.java index 19a137259b1..fa932c6d0a3 100644 --- a/megamek/src/megamek/common/actions/WeaponAttackAction.java +++ b/megamek/src/megamek/common/actions/WeaponAttackAction.java @@ -3835,15 +3835,12 @@ private static ToHitData compileAeroAttackerToHitMods(Game game, Entity ae, Targ if (ae.usesWeaponBays() && wtype != null && weapon != null) { // any heavy lasers - if (wtype.getAtClass() == WeaponType.CLASS_LASER) { - for (WeaponMounted bweap : weapon.getBayWeapons()) { - WeaponType bwtype = bweap.getType(); - if ((bwtype.getInternalName().contains("Heavy")) - && (bwtype.getInternalName().contains("Laser"))) { - toHit.addModifier(+1, Messages.getString("WeaponAttackAction.HeavyLaserInBay")); - break; - } - } + if (wtype.getAtClass() == WeaponType.CLASS_LASER && + weapon.getBayWeapons().stream() + .map(WeaponMounted::getType) + .map(WeaponType::getInternalName) + .anyMatch(i -> i.startsWith("CLHeavyLaser"))) { + toHit.addModifier(+1, Messages.getString("WeaponAttackAction.HeavyLaserInBay")); } // barracuda missiles else if (wtype.getAtClass() == WeaponType.CLASS_CAPITAL_MISSILE) {