|
41 | 41 | import java.io.Serializable;
|
42 | 42 | import java.util.*;
|
43 | 43 | import java.util.stream.Stream;
|
| 44 | +import java.util.stream.IntStream; |
44 | 45 | import java.util.stream.Collectors;
|
45 | 46 |
|
46 | 47 | /**
|
@@ -2437,21 +2438,28 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
|
2437 | 2438 | }
|
2438 | 2439 |
|
2439 | 2440 | // Protomechs cannot fire arm weapons and main gun in the same turn
|
2440 |
| - if ((ae instanceof Protomech) |
2441 |
| - && ((weapon.getLocation() == Protomech.LOC_MAINGUN) |
2442 |
| - || (weapon.getLocation() == Protomech.LOC_RARM) |
2443 |
| - || (weapon.getLocation() == Protomech.LOC_LARM))) { |
2444 |
| - final boolean firingMainGun = weapon.getLocation() == Protomech.LOC_MAINGUN; |
2445 |
| - for (EntityAction ea : game.getActionsVector()) { |
2446 |
| - if ((ea.getEntityId() == attackerId) && (ea instanceof WeaponAttackAction)) { |
2447 |
| - WeaponAttackAction otherWAA = (WeaponAttackAction) ea; |
2448 |
| - final Mounted otherWeapon = ae.getEquipment(otherWAA.getWeaponId()); |
2449 |
| - if ((firingMainGun && ((otherWeapon.getLocation() == Protomech.LOC_RARM) |
2450 |
| - || (otherWeapon.getLocation() == Protomech.LOC_LARM))) |
2451 |
| - || !firingMainGun && (otherWeapon.getLocation() == Protomech.LOC_MAINGUN)) { |
| 2441 | + if (ae instanceof Protomech) { |
| 2442 | + // A lazy stream that evaluates to the locations of weapons already fired by the attacker. |
| 2443 | + IntStream firedWeaponLocations = game.getActionsVector().stream() |
| 2444 | + .filter(ea -> ea.getEntityId() == attackerId) |
| 2445 | + .filter(WeaponAttackAction.class::isInstance) |
| 2446 | + .map(WeaponAttackAction.class::cast) |
| 2447 | + .map(otherWAA -> ae.getEquipment(otherWAA.getWeaponId())) |
| 2448 | + .mapToInt(Mounted::getLocation); |
| 2449 | + |
| 2450 | + switch (weapon.getLocation()) { |
| 2451 | + case Protomech.LOC_MAINGUN: |
| 2452 | + if (firedWeaponLocations.anyMatch(otherWeaponLocation -> |
| 2453 | + otherWeaponLocation == Protomech.LOC_LARM || otherWeaponLocation == Protomech.LOC_RARM |
| 2454 | + )) { |
| 2455 | + return Messages.getString("WeaponAttackAction.CantFireArmsAndMainGun"); |
| 2456 | + } |
| 2457 | + break; |
| 2458 | + case Protomech.LOC_LARM: |
| 2459 | + case Protomech.LOC_RARM: |
| 2460 | + if (firedWeaponLocations.anyMatch(otherWeaponLocation -> otherWeaponLocation == Protomech.LOC_MAINGUN)) { |
2452 | 2461 | return Messages.getString("WeaponAttackAction.CantFireArmsAndMainGun");
|
2453 | 2462 | }
|
2454 |
| - } |
2455 | 2463 | }
|
2456 | 2464 | }
|
2457 | 2465 |
|
|
0 commit comments