Skip to content

Commit

Permalink
refactor: Use stream composition when firing solo weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
Saklad5 committed Aug 24, 2024
1 parent bdfb73b commit 0e3fc44
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2426,19 +2426,15 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
}

// Handle solo attack weapons.
if (wtype.hasFlag(WeaponType.F_SOLO_ATTACK)) {
for (EntityAction ea : game.getActionsVector()) {
if (!(ea instanceof WeaponAttackAction)) {
continue;
}
WeaponAttackAction prevAttack = (WeaponAttackAction) ea;
if (prevAttack.getEntityId() == attackerId) {
// If the attacker fires another weapon, this attack fails.
if (weaponId != prevAttack.getWeaponId()) {
return Messages.getString("WeaponAttackAction.CantMixAttacks");
}
}
}
if (wtype.hasFlag(WeaponType.F_SOLO_ATTACK) && game.getActionsVector().stream()
.filter(prevAttack -> prevAttack.getEntityId() == attackerId)
.filter(WeaponAttackAction.class::isInstance)
.map(WeaponAttackAction.class::cast)
// If the attacker fires another weapon, this attack fails.
.filter(prevAttack -> prevAttack.getEntityId() == attackerId && prevAttack.getWeaponId() != weaponId)
.anyMatch()
) {
return Messages.getString("WeaponAttackAction.CantMixAttacks");
}

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

0 comments on commit 0e3fc44

Please sign in to comment.