This commit is contained in:
Jeff 2019-03-19 16:39:10 -05:00
parent 468ad04255
commit f74e4118e0

View file

@ -1,10 +1,8 @@
package mage.cards.p; package mage.cards.p;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.SacrificeSourceCost; import mage.abilities.costs.common.SacrificeSourceCost;
@ -17,6 +15,7 @@ import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.ExileZone; import mage.game.ExileZone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
@ -27,12 +26,19 @@ import mage.util.CardUtil;
public final class PyxisOfPandemonium extends CardImpl { public final class PyxisOfPandemonium extends CardImpl {
public PyxisOfPandemonium(UUID ownerId, CardSetInfo setInfo) { public PyxisOfPandemonium(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{1}"); super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{1}");
// {T}: Each player exiles the top card of their library face down. // {T}: Each player exiles the top card of their library face down.
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PyxisOfPandemoniumExileEffect(), new TapSourceCost())); this.addAbility(new SimpleActivatedAbility(
Zone.BATTLEFIELD,
new PyxisOfPandemoniumExileEffect(),
new TapSourceCost()));
// {7}, {T}, Sacrifice Pyxis of Pandemonium: Each player turns face up all cards he or she owns exiled with Pyxis of Pandemonium, then puts all permanent cards among them onto the battlefield. // {7}, {T}, Sacrifice Pyxis of Pandemonium: Each player turns face up all cards he or she owns exiled with Pyxis of Pandemonium, then puts all permanent cards among them onto the battlefield.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PyxisOfPandemoniumPutOntoBattlefieldEffect(), new GenericManaCost(7)); Ability ability = new SimpleActivatedAbility(
Zone.BATTLEFIELD,
new PyxisOfPandemoniumPutOntoBattlefieldEffect(),
new GenericManaCost(7));
ability.addCost(new TapSourceCost()); ability.addCost(new TapSourceCost());
ability.addCost(new SacrificeSourceCost()); ability.addCost(new SacrificeSourceCost());
this.addAbility(ability); this.addAbility(ability);
@ -68,10 +74,11 @@ class PyxisOfPandemoniumExileEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game); Permanent pyxis = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourceObject != null && controller != null) { if (pyxis != null
&& controller != null) {
Map<String, UUID> exileIds; Map<String, UUID> exileIds;
String valueKey = CardUtil.getObjectZoneString("exileIds", sourceObject, game); String valueKey = CardUtil.getObjectZoneString("exileIds", pyxis, game);
Object object = game.getState().getValue(valueKey); Object object = game.getState().getValue(valueKey);
if (object instanceof Map) { if (object instanceof Map) {
exileIds = (Map<String, UUID>) object; exileIds = (Map<String, UUID>) object;
@ -79,20 +86,22 @@ class PyxisOfPandemoniumExileEffect extends OneShotEffect {
exileIds = new HashMap<>(); exileIds = new HashMap<>();
game.getState().setValue(valueKey, exileIds); game.getState().setValue(valueKey, exileIds);
} }
game.getState().getPlayersInRange(controller.getId(), game).forEach((playerId) -> {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null) { if (player != null) {
if (player.getLibrary().hasCards()) { if (player.getLibrary().hasCards()) {
Card card = player.getLibrary().getFromTop(game); Card card = player.getLibrary().getFromTop(game);
String exileKey = playerId.toString() + CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()).toString(); String exileKey = playerId.toString()
+ CardUtil.getExileZoneId(game,
source.getSourceId(),
pyxis.getZoneChangeCounter(game));
UUID exileId = exileIds.computeIfAbsent(exileKey, k -> UUID.randomUUID()); UUID exileId = exileIds.computeIfAbsent(exileKey, k -> UUID.randomUUID());
player.moveCardsToExile(card, source, game, false, exileId, sourceObject.getIdName() + " (" + player.getName() + ')'); player.moveCardsToExile(card, source, game, false,
exileId, pyxis.getIdName() + " (" + player.getName() + ')');
card.setFaceDown(true, game); card.setFaceDown(true, game);
} }
} }
} });
return true; return true;
} }
return false; return false;
@ -103,7 +112,8 @@ class PyxisOfPandemoniumPutOntoBattlefieldEffect extends OneShotEffect {
public PyxisOfPandemoniumPutOntoBattlefieldEffect() { public PyxisOfPandemoniumPutOntoBattlefieldEffect() {
super(Outcome.PutCardInPlay); super(Outcome.PutCardInPlay);
this.staticText = "Each player turns face up all cards he or she owns exiled with {this}, then puts all permanent cards among them onto the battlefield"; this.staticText = "Each player turns face up all cards he or she owns exiled with {this}, "
+ "then puts all permanent cards among them onto the battlefield";
} }
public PyxisOfPandemoniumPutOntoBattlefieldEffect(final PyxisOfPandemoniumPutOntoBattlefieldEffect effect) { public PyxisOfPandemoniumPutOntoBattlefieldEffect(final PyxisOfPandemoniumPutOntoBattlefieldEffect effect) {
@ -118,10 +128,11 @@ class PyxisOfPandemoniumPutOntoBattlefieldEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game); Permanent pyxis = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && sourceObject != null) { if (controller != null
&& pyxis != null) {
Map<String, UUID> exileIds; Map<String, UUID> exileIds;
String valueKey = CardUtil.getObjectZoneString("exileIds", sourceObject, game); String valueKey = CardUtil.getObjectZoneString("exileIds", pyxis, game);
Object object = game.getState().getValue(valueKey); Object object = game.getState().getValue(valueKey);
if (object instanceof Map) { if (object instanceof Map) {
exileIds = (Map<String, UUID>) object; exileIds = (Map<String, UUID>) object;
@ -129,24 +140,26 @@ class PyxisOfPandemoniumPutOntoBattlefieldEffect extends OneShotEffect {
return true; return true;
} }
Cards cardsToBringIntoPlay = new CardsImpl(); Cards cardsToBringIntoPlay = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { game.getState().getPlayersInRange(controller.getId(), game).forEach((playerId) -> {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null) { if (player != null) {
String exileKey = playerId.toString() + CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()).toString(); String exileKey = playerId.toString() + CardUtil.getExileZoneId(game,
source.getSourceId(),
pyxis.getZoneChangeCounter(game));
UUID exileId = exileIds.get(exileKey); UUID exileId = exileIds.get(exileKey);
if (exileId != null) { if (exileId != null) {
ExileZone exileZone = game.getState().getExile().getExileZone(exileId); ExileZone exileZone = game.getState().getExile().getExileZone(exileId);
if (exileZone != null) { if (exileZone != null) {
for (Card card : exileZone.getCards(game)) { exileZone.getCards(game).stream().map((card) -> {
card.setFaceDown(false, game); card.setFaceDown(false, game);
if (card.isPermanent()) { return card;
cardsToBringIntoPlay.add(card); }).filter((card) -> (card.isPermanent())).forEachOrdered((card) -> {
} cardsToBringIntoPlay.add(card);
} });
} }
} }
} }
} });
controller.moveCards(cardsToBringIntoPlay.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null); controller.moveCards(cardsToBringIntoPlay.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
return true; return true;
} }