diff --git a/Mage/src/main/java/mage/abilities/condition/common/OneOpponentCondition.java b/Mage/src/main/java/mage/abilities/condition/common/OneOpponentCondition.java index 36b8354885..21aac3c45f 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/OneOpponentCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/OneOpponentCondition.java @@ -1,15 +1,12 @@ - package mage.abilities.condition.common; import mage.abilities.Ability; import mage.abilities.condition.Condition; import mage.game.Game; -import mage.players.Player; -import java.util.UUID; +import java.util.Objects; /** - * * @author TheElk801 */ public enum OneOpponentCondition implements Condition { @@ -18,20 +15,11 @@ public enum OneOpponentCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - int opponentCount = 0; - if (controller != null) { - for (UUID uuid : game.getOpponents(controller.getId())) { - Player opponent = game.getPlayer(uuid); - if (opponent != null) { - opponentCount++; - if (opponentCount > 1) { - return false; - } - } - } - } - return true; + return game.getOpponents(source.getControllerId()) + .stream() + .map(game::getPlayer) + .filter(Objects::nonNull) + .count() <= 1; } @Override diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/OpponentsCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/OpponentsCount.java index d8eee3f627..d66a296b86 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/OpponentsCount.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/OpponentsCount.java @@ -5,6 +5,8 @@ import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; import mage.game.Game; +import java.util.Objects; + /** * @author JayDi85 */ @@ -13,7 +15,12 @@ public enum OpponentsCount implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - return game.getOpponents(sourceAbility.getControllerId()).size(); + return game.getOpponents(sourceAbility.getControllerId()) + .stream() + .map(game::getPlayer) + .map(Objects::nonNull) + .mapToInt(x -> x ? 1 : 0) + .sum(); } @Override @@ -30,4 +37,4 @@ public enum OpponentsCount implements DynamicValue { public String toString() { return "1"; } -} \ No newline at end of file +} diff --git a/Mage/src/main/java/mage/abilities/keyword/EncoreAbility.java b/Mage/src/main/java/mage/abilities/keyword/EncoreAbility.java index 472a684bde..237e7acbf8 100644 --- a/Mage/src/main/java/mage/abilities/keyword/EncoreAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/EncoreAbility.java @@ -6,6 +6,7 @@ import mage.abilities.ActivatedAbilityImpl; import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; import mage.abilities.costs.Cost; import mage.abilities.costs.common.ExileSourceFromGraveCost; +import mage.abilities.dynamicvalue.common.OpponentsCount; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.RequirementEffect; import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; @@ -87,7 +88,7 @@ class EncoreEffect extends OneShotEffect { EmptyToken token = new EmptyToken(); CardUtil.copyTo(token).from(card, game); Set addedTokens = new HashSet<>(); - int opponentCount = game.getOpponents(source.getControllerId()).size(); + int opponentCount = OpponentsCount.instance.calculate(game, source, this); if (opponentCount < 1) { return false; } @@ -95,6 +96,9 @@ class EncoreEffect extends OneShotEffect { Iterator it = token.getLastAddedTokenIds().iterator(); while (it.hasNext()) { for (UUID playerId : game.getOpponents(source.getControllerId())) { + if (game.getPlayer(playerId) == null) { + continue; + } UUID tokenId = it.next(); MageObjectReference mageObjectReference = new MageObjectReference(tokenId, game); game.addEffect(new EncoreRequirementEffect(