From f74e4118e0b995fd119a4c229f6f5dc936d80fb6 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 19 Mar 2019 16:39:10 -0500 Subject: [PATCH] - Fixed #5641 --- .../src/mage/cards/p/PyxisOfPandemonium.java | 65 +++++++++++-------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/Mage.Sets/src/mage/cards/p/PyxisOfPandemonium.java b/Mage.Sets/src/mage/cards/p/PyxisOfPandemonium.java index 9c7e5e2455..cb8f478b37 100644 --- a/Mage.Sets/src/mage/cards/p/PyxisOfPandemonium.java +++ b/Mage.Sets/src/mage/cards/p/PyxisOfPandemonium.java @@ -1,10 +1,8 @@ - package mage.cards.p; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.SacrificeSourceCost; @@ -17,6 +15,7 @@ import mage.constants.Outcome; import mage.constants.Zone; import mage.game.ExileZone; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.players.Player; import mage.util.CardUtil; @@ -27,12 +26,19 @@ import mage.util.CardUtil; public final class PyxisOfPandemonium extends CardImpl { 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. - 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. - 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 SacrificeSourceCost()); this.addAbility(ability); @@ -68,10 +74,11 @@ class PyxisOfPandemoniumExileEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - MageObject sourceObject = source.getSourceObject(game); - if (sourceObject != null && controller != null) { + Permanent pyxis = game.getPermanentOrLKIBattlefield(source.getSourceId()); + if (pyxis != null + && controller != null) { Map exileIds; - String valueKey = CardUtil.getObjectZoneString("exileIds", sourceObject, game); + String valueKey = CardUtil.getObjectZoneString("exileIds", pyxis, game); Object object = game.getState().getValue(valueKey); if (object instanceof Map) { exileIds = (Map) object; @@ -79,20 +86,22 @@ class PyxisOfPandemoniumExileEffect extends OneShotEffect { exileIds = new HashMap<>(); game.getState().setValue(valueKey, exileIds); } - - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - + game.getState().getPlayersInRange(controller.getId(), game).forEach((playerId) -> { Player player = game.getPlayer(playerId); if (player != null) { if (player.getLibrary().hasCards()) { 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()); - 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); } } - } + }); return true; } return false; @@ -103,7 +112,8 @@ class PyxisOfPandemoniumPutOntoBattlefieldEffect extends OneShotEffect { public PyxisOfPandemoniumPutOntoBattlefieldEffect() { 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) { @@ -118,10 +128,11 @@ class PyxisOfPandemoniumPutOntoBattlefieldEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - MageObject sourceObject = source.getSourceObject(game); - if (controller != null && sourceObject != null) { + Permanent pyxis = game.getPermanentOrLKIBattlefield(source.getSourceId()); + if (controller != null + && pyxis != null) { Map exileIds; - String valueKey = CardUtil.getObjectZoneString("exileIds", sourceObject, game); + String valueKey = CardUtil.getObjectZoneString("exileIds", pyxis, game); Object object = game.getState().getValue(valueKey); if (object instanceof Map) { exileIds = (Map) object; @@ -129,24 +140,26 @@ class PyxisOfPandemoniumPutOntoBattlefieldEffect extends OneShotEffect { return true; } 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); 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); if (exileId != null) { ExileZone exileZone = game.getState().getExile().getExileZone(exileId); if (exileZone != null) { - for (Card card : exileZone.getCards(game)) { + exileZone.getCards(game).stream().map((card) -> { card.setFaceDown(false, game); - if (card.isPermanent()) { - cardsToBringIntoPlay.add(card); - } - } + return card; + }).filter((card) -> (card.isPermanent())).forEachOrdered((card) -> { + cardsToBringIntoPlay.add(card); + }); } } } - } + }); controller.moveCards(cardsToBringIntoPlay.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null); return true; }