fixed effects counting opponents no longer in the game

This commit is contained in:
Evan Kranzler 2021-04-28 08:18:07 -04:00
parent a69f6b38d9
commit 7778e867f8
3 changed files with 20 additions and 21 deletions

View file

@ -1,15 +1,12 @@
package mage.abilities.condition.common; package mage.abilities.condition.common;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.condition.Condition; import mage.abilities.condition.Condition;
import mage.game.Game; import mage.game.Game;
import mage.players.Player;
import java.util.UUID; import java.util.Objects;
/** /**
*
* @author TheElk801 * @author TheElk801
*/ */
public enum OneOpponentCondition implements Condition { public enum OneOpponentCondition implements Condition {
@ -18,20 +15,11 @@ public enum OneOpponentCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); return game.getOpponents(source.getControllerId())
int opponentCount = 0; .stream()
if (controller != null) { .map(game::getPlayer)
for (UUID uuid : game.getOpponents(controller.getId())) { .filter(Objects::nonNull)
Player opponent = game.getPlayer(uuid); .count() <= 1;
if (opponent != null) {
opponentCount++;
if (opponentCount > 1) {
return false;
}
}
}
}
return true;
} }
@Override @Override

View file

@ -5,6 +5,8 @@ import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.game.Game; import mage.game.Game;
import java.util.Objects;
/** /**
* @author JayDi85 * @author JayDi85
*/ */
@ -13,7 +15,12 @@ public enum OpponentsCount implements DynamicValue {
@Override @Override
public int calculate(Game game, Ability sourceAbility, Effect effect) { 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 @Override

View file

@ -6,6 +6,7 @@ import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.costs.common.ExileSourceFromGraveCost; import mage.abilities.costs.common.ExileSourceFromGraveCost;
import mage.abilities.dynamicvalue.common.OpponentsCount;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.RequirementEffect; import mage.abilities.effects.RequirementEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect; import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
@ -87,7 +88,7 @@ class EncoreEffect extends OneShotEffect {
EmptyToken token = new EmptyToken(); EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card, game); CardUtil.copyTo(token).from(card, game);
Set<MageObjectReference> addedTokens = new HashSet<>(); Set<MageObjectReference> addedTokens = new HashSet<>();
int opponentCount = game.getOpponents(source.getControllerId()).size(); int opponentCount = OpponentsCount.instance.calculate(game, source, this);
if (opponentCount < 1) { if (opponentCount < 1) {
return false; return false;
} }
@ -95,6 +96,9 @@ class EncoreEffect extends OneShotEffect {
Iterator<UUID> it = token.getLastAddedTokenIds().iterator(); Iterator<UUID> it = token.getLastAddedTokenIds().iterator();
while (it.hasNext()) { while (it.hasNext()) {
for (UUID playerId : game.getOpponents(source.getControllerId())) { for (UUID playerId : game.getOpponents(source.getControllerId())) {
if (game.getPlayer(playerId) == null) {
continue;
}
UUID tokenId = it.next(); UUID tokenId = it.next();
MageObjectReference mageObjectReference = new MageObjectReference(tokenId, game); MageObjectReference mageObjectReference = new MageObjectReference(tokenId, game);
game.addEffect(new EncoreRequirementEffect( game.addEffect(new EncoreRequirementEffect(