diff --git a/Mage/src/main/java/mage/abilities/condition/common/OpponentLostLifeCondition.java b/Mage/src/main/java/mage/abilities/condition/common/OpponentLostLifeCondition.java index 66f719acc14..4d4cfbf24c2 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/OpponentLostLifeCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/OpponentLostLifeCondition.java @@ -28,6 +28,7 @@ package mage.abilities.condition.common; import java.util.UUID; + import mage.abilities.Ability; import mage.abilities.condition.Condition; import mage.abilities.condition.IntCompareCondition; @@ -50,7 +51,7 @@ public class OpponentLostLifeCondition extends IntCompareCondition { int maxLostLive = 0; PlayerLostLifeWatcher watcher = (PlayerLostLifeWatcher) game.getState().getWatchers().get("PlayerLostLifeWatcher"); if (watcher != null) { - for (UUID opponentId: game.getOpponents(source.getControllerId())) { + for (UUID opponentId : game.getOpponents(source.getControllerId())) { int lostLive = watcher.getLiveLost(opponentId); if (lostLive > maxLostLive) { maxLostLive = lostLive; @@ -63,9 +64,9 @@ public class OpponentLostLifeCondition extends IntCompareCondition { @Override public String toString() { StringBuilder sb = new StringBuilder("if an opponent lost "); - switch(type) { + switch (type) { case GreaterThan: - sb.append(value+1).append(" or more life this turn "); + sb.append(value + 1).append(" or more life this turn "); break; case Equal: sb.append(value).append(" life this turn "); diff --git a/Mage/src/main/java/mage/game/permanent/Battlefield.java b/Mage/src/main/java/mage/game/permanent/Battlefield.java index 8bfa4251178..a58b5b71ff6 100644 --- a/Mage/src/main/java/mage/game/permanent/Battlefield.java +++ b/Mage/src/main/java/mage/game/permanent/Battlefield.java @@ -134,7 +134,7 @@ public class Battlefield implements Serializable { return field.values() .stream() .filter(permanent -> filter.match(permanent, game) - && permanent.isPhasedIn()).count() == num; + && permanent.isPhasedIn()).count() >= num; } @@ -150,16 +150,13 @@ public class Battlefield implements Serializable { * @return boolean */ public boolean contains(FilterPermanent filter, UUID controllerId, int num, Game game) { - int count = 0; - for (Permanent permanent : field.values()) { - if (permanent.getControllerId().equals(controllerId) && filter.match(permanent, game) && permanent.isPhasedIn()) { - count++; - if (num == count) { - return true; - } - } - } - return false; + return field.values() + .stream() + .filter(permanent -> permanent.getControllerId().equals(controllerId) + && filter.match(permanent, game) + && permanent.isPhasedIn()) + .count() >= num; + } /** @@ -174,24 +171,19 @@ public class Battlefield implements Serializable { * @return boolean */ public boolean contains(FilterPermanent filter, UUID sourcePlayerId, Game game, int num) { - int count = 0; if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) { return field.values().stream() .filter(permanent -> filter.match(permanent, null, sourcePlayerId, game) - && permanent.isPhasedIn()).count() == num; + && permanent.isPhasedIn()).count() >= num; } else { Set range = game.getPlayer(sourcePlayerId).getInRange(); - for (Permanent permanent : field.values()) { - if (range.contains(permanent.getControllerId()) && filter.match(permanent, null, sourcePlayerId, game) && permanent.isPhasedIn()) { - count++; - if (num == count) { - return true; - } - } - } + return field.values().stream() + .filter(permanent -> range.contains(permanent.getControllerId()) + && filter.match(permanent, null, sourcePlayerId, game) + && permanent.isPhasedIn()) + .count() >= num; } - return false; } public void addPermanent(Permanent permanent) { @@ -262,7 +254,10 @@ public class Battlefield implements Serializable { * @see Permanent */ public List getAllActivePermanents(CardType type) { - return field.values().stream().filter(perm -> perm.isPhasedIn() && perm.getCardType().contains(type)).collect(Collectors.toList()); + return field.values() + .stream() + .filter(perm -> perm.isPhasedIn() && perm.getCardType().contains(type)) + .collect(Collectors.toList()); } /** @@ -275,13 +270,10 @@ public class Battlefield implements Serializable { * @see Permanent */ public List getAllActivePermanents(FilterPermanent filter, Game game) { - List active = new ArrayList<>(); - for (Permanent perm : field.values()) { - if (perm.isPhasedIn() && filter.match(perm, game)) { - active.add(perm); - } - } - return active; + return field.values() + .stream() + .filter(perm -> perm.isPhasedIn() && filter.match(perm, game)) + .collect(Collectors.toList()); } /** @@ -295,13 +287,10 @@ public class Battlefield implements Serializable { * @see Permanent */ public List getAllActivePermanents(FilterPermanent filter, UUID controllerId, Game game) { - List active = new ArrayList<>(); - for (Permanent perm : field.values()) { - if (perm.isPhasedIn() && perm.getControllerId().equals(controllerId) && filter.match(perm, game)) { - active.add(perm); - } - } - return active; + return field.values() + .stream() + .filter(perm -> perm.isPhasedIn() && perm.getControllerId().equals(controllerId) && filter.match(perm, game)) + .collect(Collectors.toList()); } /** @@ -332,18 +321,16 @@ public class Battlefield implements Serializable { public List getActivePermanents(FilterPermanent filter, UUID sourcePlayerId, UUID sourceId, Game game) { List active = new ArrayList<>(); if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) { - for (Permanent perm : field.values()) { - if (perm.isPhasedIn() && filter.match(perm, sourceId, sourcePlayerId, game)) { - active.add(perm); - } - } + active = field.values() + .stream() + .filter(perm -> perm.isPhasedIn() && filter.match(perm, sourceId, sourcePlayerId, game)) + .collect(Collectors.toList()); } else { Set range = game.getPlayer(sourcePlayerId).getInRange(); - for (Permanent perm : field.values()) { - if (perm.isPhasedIn() && range.contains(perm.getControllerId()) && filter.match(perm, sourceId, sourcePlayerId, game)) { - active.add(perm); - } - } + active = field.values() + .stream() + .filter(perm -> perm.isPhasedIn() && range.contains(perm.getControllerId()) + && filter.match(perm, sourceId, sourcePlayerId, game)).collect(Collectors.toList()); } return active; } @@ -372,23 +359,19 @@ public class Battlefield implements Serializable { } public List getPhasedIn(UUID controllerId) { - List phasedIn = new ArrayList<>(); - for (Permanent perm : field.values()) { - if (perm.getAbilities().containsKey(PhasingAbility.getInstance().getId()) && perm.isPhasedIn() && perm.getControllerId().equals(controllerId)) { - phasedIn.add(perm); - } - } - return phasedIn; + return field.values() + .stream() + .filter(perm -> perm.getAbilities().containsKey(PhasingAbility.getInstance().getId()) + && perm.isPhasedIn() && + perm.getControllerId().equals(controllerId)) + .collect(Collectors.toList()); } public List getPhasedOut(UUID controllerId) { - List phasedOut = new ArrayList<>(); - for (Permanent perm : field.values()) { - if (!perm.isPhasedIn() && perm.getControllerId().equals(controllerId)) { - phasedOut.add(perm); - } - } - return phasedOut; + return field.values() + .stream() + .filter(perm -> !perm.isPhasedIn() && perm.getControllerId().equals(controllerId)) + .collect(Collectors.toList()); } public void resetPermanentsControl() {