Allowed getOpponents to filter out players who have lost the game. Fixes Corrupt mechanic, Mycosynth Fiend, etc

This commit is contained in:
PurpleCrowbar 2023-02-03 02:23:10 +00:00
parent 97b2ab0b26
commit 725c29182b
4 changed files with 11 additions and 8 deletions

View file

@ -6,7 +6,6 @@ import mage.abilities.hint.ConditionHint;
import mage.abilities.hint.Hint;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.players.Player;
import java.util.Objects;
@ -21,7 +20,7 @@ public enum CorruptedCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return game.getOpponents(source.getControllerId())
return game.getOpponents(source.getControllerId(), true)
.stream()
.map(game::getPlayer)
.filter(Objects::nonNull)

View file

@ -15,11 +15,10 @@ public enum OneOpponentCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return game.getOpponents(source.getControllerId())
return game.getOpponents(source.getControllerId(), true)
.stream()
.map(game::getPlayer)
.filter(Objects::nonNull)
.filter(player -> !player.hasLost())
.count() <= 1;
}

View file

@ -16,7 +16,7 @@ public enum OpponentsPoisonCountersCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int amount = 0;
Set<UUID> playerList = game.getOpponents(sourceAbility.getControllerId());
Set<UUID> playerList = game.getOpponents(sourceAbility.getControllerId(), true);
for (UUID playerUUID : playerList) {
Player player = game.getPlayer(playerUUID);
if (player != null) {

View file

@ -136,14 +136,18 @@ public interface Game extends MageItem, Serializable, Copyable<Game> {
PlayerList getPlayerList();
default Set<UUID> getOpponents(UUID playerId) {
return getOpponents(playerId, false);
}
/**
* Returns a Set of opponents in range for the given playerId This return
* also a player, that has dies this turn.
* Returns a Set of opponents in range for the given playerId
*
* @param playerId
* @param excludeDeadPlayers Determines if players who have lost are excluded from the list
* @return
*/
default Set<UUID> getOpponents(UUID playerId) {
default Set<UUID> getOpponents(UUID playerId, boolean excludeDeadPlayers) {
Player player = getPlayer(playerId);
if (player == null) {
return new HashSet<>();
@ -151,6 +155,7 @@ public interface Game extends MageItem, Serializable, Copyable<Game> {
return player.getInRange().stream()
.filter(opponentId -> !opponentId.equals(playerId))
.filter(opponentId -> !excludeDeadPlayers || !getPlayer(opponentId).hasLost())
.collect(Collectors.toSet());
}