mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
fixed effects counting opponents no longer in the game
This commit is contained in:
parent
a69f6b38d9
commit
7778e867f8
3 changed files with 20 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MageObjectReference> 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<UUID> 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(
|
||||
|
|
Loading…
Reference in a new issue