Skip to content

Commit 0e3fc44

Browse files
committed
refactor: Use stream composition when firing solo weapons
1 parent bdfb73b commit 0e3fc44

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

megamek/src/megamek/common/actions/WeaponAttackAction.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -2426,19 +2426,15 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
24262426
}
24272427

24282428
// Handle solo attack weapons.
2429-
if (wtype.hasFlag(WeaponType.F_SOLO_ATTACK)) {
2430-
for (EntityAction ea : game.getActionsVector()) {
2431-
if (!(ea instanceof WeaponAttackAction)) {
2432-
continue;
2433-
}
2434-
WeaponAttackAction prevAttack = (WeaponAttackAction) ea;
2435-
if (prevAttack.getEntityId() == attackerId) {
2436-
// If the attacker fires another weapon, this attack fails.
2437-
if (weaponId != prevAttack.getWeaponId()) {
2438-
return Messages.getString("WeaponAttackAction.CantMixAttacks");
2439-
}
2440-
}
2441-
}
2429+
if (wtype.hasFlag(WeaponType.F_SOLO_ATTACK) && game.getActionsVector().stream()
2430+
.filter(prevAttack -> prevAttack.getEntityId() == attackerId)
2431+
.filter(WeaponAttackAction.class::isInstance)
2432+
.map(WeaponAttackAction.class::cast)
2433+
// If the attacker fires another weapon, this attack fails.
2434+
.filter(prevAttack -> prevAttack.getEntityId() == attackerId && prevAttack.getWeaponId() != weaponId)
2435+
.anyMatch()
2436+
) {
2437+
return Messages.getString("WeaponAttackAction.CantMixAttacks");
24422438
}
24432439

24442440
// Protomechs cannot fire arm weapons and main gun in the same turn

0 commit comments

Comments
 (0)