diff --git a/megamek/src/megamek/common/actions/WeaponAttackAction.java b/megamek/src/megamek/common/actions/WeaponAttackAction.java index f9c1c1c1b60..655f0b2b603 100644 --- a/megamek/src/megamek/common/actions/WeaponAttackAction.java +++ b/megamek/src/megamek/common/actions/WeaponAttackAction.java @@ -1881,20 +1881,16 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta // BA compact narc: we have one weapon for each trooper, but you // can fire only at one target at a time if (wtype.getName().equals("Compact Narc")) { - for (Enumeration i = game.getActions(); i.hasMoreElements();) { - EntityAction ea = i.nextElement(); - if (!(ea instanceof WeaponAttackAction)) { - continue; - } - final WeaponAttackAction prevAttack = (WeaponAttackAction) ea; - if (prevAttack.getEntityId() == attackerId) { - Mounted prevWeapon = ae.getEquipment(prevAttack.getWeaponId()); - if (prevWeapon.getType().getName().equals("Compact Narc")) { - if (prevAttack.getTargetId() != target.getId()) { - return Messages.getString("WeaponAttackAction.OneTargetForCNarc"); - } - } - } + if (game.getActionsVector().stream() + .filter(WeaponAttackAction.class::isInstance) + .map(WeaponAttackAction.class::cast) + .anyMatch(prevAttack -> prevAttack.getEntityId() == attackerId + && ae.getEquipment(prevAttack.getWeaponId()) + .getType().getName().equals("Compact Narc") + && prevAttack.getTargetId() != target.getId() + ) + ) { + return Messages.getString("WeaponAttackAction.OneTargetForCNarc"); } }