[PCY] reworked Celestial Convergence

This commit is contained in:
Evan Kranzler 2021-08-21 16:51:22 -04:00
parent 0bd402876d
commit 5547d04938

View file

@ -1,9 +1,5 @@
package mage.cards.c; package mage.cards.c;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.common.EntersBattlefieldAbility;
@ -11,7 +7,6 @@ import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.effects.common.counter.RemoveCounterSourceEffect; import mage.abilities.effects.common.counter.RemoveCounterSourceEffect;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
@ -20,10 +15,12 @@ import mage.constants.TargetController;
import mage.constants.Zone; import mage.constants.Zone;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import java.util.*;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public final class CelestialConvergence extends CardImpl { public final class CelestialConvergence extends CardImpl {
@ -70,11 +67,12 @@ class CelestialConvergenceEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Card sourceObject = game.getCard(source.getSourceId()); Permanent sourcePermanent = source.getSourcePermanentOrLKI(game);
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (sourceObject != null if (sourcePermanent == null || controller == null
&& controller != null || sourcePermanent.getCounters(game).getCount(CounterType.OMEN) > 0) {
&& sourceObject.getCounters(game).getCount(CounterType.OMEN) == 0) { return false;
}
/** /**
* 801.14. If an effect states that a player wins the game, all of * 801.14. If an effect states that a player wins the game, all of
@ -87,32 +85,24 @@ class CelestialConvergenceEffect extends OneShotEffect {
* leave the game. All remaining players continue to play the game. * leave the game. All remaining players continue to play the game.
* *
*/ */
List<UUID> highestLifePlayers = new ArrayList<>(); Map<Integer, Set<UUID>> playerMap = new HashMap<>();
int highLife = Integer.MIN_VALUE; game.getState()
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { .getPlayersInRange(controller.getId(), game)
Player player = game.getPlayer(playerId); .stream()
if (player != null) { .map(game::getPlayer)
if (player.getLife() > highLife) { .filter(Objects::nonNull)
highestLifePlayers.clear(); .forEach(player -> playerMap.computeIfAbsent(
highestLifePlayers.add(player.getId()); player.getLife(), x -> new HashSet<>()
} else if (player.getLife() == highLife) { ).add(player.getId()));
highestLifePlayers.add(player.getId()); int highLife = playerMap.keySet().stream().mapToInt(x -> x).max().orElse(Integer.MIN_VALUE);
} if (playerMap.get(highLife).size() > 1) {
}
}
if (highestLifePlayers.isEmpty()) {
return false;
}
if (highestLifePlayers.size() > 1) {
game.setDraw(controller.getId()); game.setDraw(controller.getId());
} else { return true;
Player winner = game.getPlayer(highestLifePlayers.iterator().next()); }
Player winner = game.getPlayer(playerMap.get(highLife).iterator().next());
if (winner != null) { if (winner != null) {
winner.won(game); winner.won(game);
} }
}
return true; return true;
} }
return false;
}
} }