diff --git a/Mage.Sets/src/mage/cards/p/PaintersServant.java b/Mage.Sets/src/mage/cards/p/PaintersServant.java index 28fc6117af..d88ffcb23d 100644 --- a/Mage.Sets/src/mage/cards/p/PaintersServant.java +++ b/Mage.Sets/src/mage/cards/p/PaintersServant.java @@ -1,6 +1,5 @@ package mage.cards.p; -import java.util.UUID; import mage.MageInt; import mage.MageObject; import mage.ObjectColor; @@ -9,29 +8,18 @@ import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.common.ChooseColorEffect; -import mage.cards.Card; -import mage.cards.CardImpl; -import mage.cards.CardSetInfo; -import mage.cards.ModalDoubleFacesCard; -import mage.cards.ModalDoubleFacesCardHalf; -import mage.cards.SplitCard; -import mage.cards.SplitCardHalf; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Layer; -import mage.constants.Outcome; -import mage.constants.SubLayer; -import mage.constants.SubType; -import mage.constants.Zone; +import mage.cards.*; +import mage.constants.*; import mage.game.Game; -import mage.game.command.CommandObject; -import mage.game.command.Commander; import mage.game.permanent.Permanent; import mage.game.stack.Spell; import mage.players.Player; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class PaintersServant extends CardImpl { @@ -75,121 +63,71 @@ class PaintersServantEffect extends ContinuousEffectImpl { if (color == null) { return false; } + + // permanents for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { perm.getColor(game).addColor(color); } - // Stack + + List affectedCards = new ArrayList<>(); + + // stack for (MageObject object : game.getStack()) { if (object instanceof Spell) { game.getState().getCreateMageObjectAttribute(object, game).getColor().addColor(color); + Card card = ((Spell) object).getCard(); - game.getState().getCreateMageObjectAttribute(card, game).getColor().addColor(color); + affectedCards.add(card); } } - // Exile - for (Card card : game.getExile().getAllCards(game)) { - // handle MDFC + + // exile + affectedCards.addAll(game.getExile().getAllCardsByRange(game, controller.getId())); + + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player == null) { + continue; + } + + // command + affectedCards.addAll(game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY)); + + // hand + affectedCards.addAll(player.getHand().getCards(game)); + + // library + affectedCards.addAll(player.getLibrary().getCards(game)); + + // graveyard + affectedCards.addAll(player.getGraveyard().getCards(game)); + } + + // apply colors to all cards + affectedCards.forEach(card -> { + game.getState().getCreateMageObjectAttribute(card, game).getColor().addColor(color); + + // mdf cards if (card instanceof ModalDoubleFacesCard) { ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard(); ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard(); game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); } - // handle Split-Cards + + // split cards if (card instanceof SplitCard) { SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard(); SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard(); game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); } - game.getState().getCreateMageObjectAttribute(card, game).getColor().addColor(color); - } - // Command - for (CommandObject commandObject : game.getState().getCommand()) { - if (commandObject instanceof Commander) { - Card card = game.getCard(((Commander) commandObject).getId()); - if (card != null) { - // handle MDFC - if (card instanceof ModalDoubleFacesCard) { - ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard(); - ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard(); - game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); - game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); - } - // handle Split-Cards - if (card instanceof SplitCard) { - SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard(); - SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard(); - game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); - game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); - } - game.getState().getCreateMageObjectAttribute(card, game).getColor().addColor(color); - } - } - } - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null) { - // Hand - for (Card card : player.getHand().getCards(game)) { - // handle MDFC - if (card instanceof ModalDoubleFacesCard) { - ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard(); - ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard(); - game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); - game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); - } - // handle Split-Cards - if (card instanceof SplitCard) { - SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard(); - SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard(); - game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); - game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); - } - game.getState().getCreateMageObjectAttribute(card.getMainCard(), game).getColor().addColor(color); - if (card.getSecondCardFace() != null) { - game.getState().getCreateMageObjectAttribute(card.getSecondCardFace(), game).getColor().addColor(color); - } - } - // Library - for (Card card : player.getLibrary().getCards(game)) { - // handle MDFC - if (card instanceof ModalDoubleFacesCard) { - ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard(); - ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard(); - game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); - game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); - } - // handle Split-Cards - if (card instanceof SplitCard) { - SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard(); - SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard(); - game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); - game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); - } - game.getState().getCreateMageObjectAttribute(card, game).getColor().addColor(color); - } - // Graveyard - for (Card card : player.getGraveyard().getCards(game)) { - // handle MDFC - if (card instanceof ModalDoubleFacesCard) { - ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard(); - ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard(); - game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); - game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); - } - // handle Split-Cards - if (card instanceof SplitCard) { - SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard(); - SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard(); - game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color); - game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color); - } - game.getState().getCreateMageObjectAttribute(card, game).getColor().addColor(color); - } + // double faces cards + if (card.getSecondCardFace() != null) { + game.getState().getCreateMageObjectAttribute(card.getSecondCardFace(), game).getColor().addColor(color); } - } + }); return true; } return false; diff --git a/Mage/src/main/java/mage/game/Exile.java b/Mage/src/main/java/mage/game/Exile.java index 4f842fd5de..2c9a73fd7d 100644 --- a/Mage/src/main/java/mage/game/Exile.java +++ b/Mage/src/main/java/mage/game/Exile.java @@ -71,12 +71,36 @@ public class Exile implements Serializable, Copyable { return allCards.stream().filter(card -> filter.match(card, game)).collect(Collectors.toList()); } + @Deprecated // TODO: must use related request due game range public List getAllCards(Game game) { - List cards = new ArrayList<>(); + return getAllCards(game, null); + } + + /** + * Return exiled cards from specific player. Use it in effects to find all cards in range. + * + * @param game + * @param fromPlayerId + * @return + */ + public List getAllCards(Game game, UUID fromPlayerId) { + List res = new ArrayList<>(); for (ExileZone exile : exileZones.values()) { - cards.addAll(exile.getCards(game)); + for (Card card : exile.getCards(game)) { + if (fromPlayerId == null || card.getOwnerId().equals(fromPlayerId)) { + res.add(card); + } + } } - return cards; + return res; + } + + public List getAllCardsByRange(Game game, UUID controllerId) { + List res = new ArrayList<>(); + for (UUID playerId : game.getState().getPlayersInRange(controllerId, game)) { + res.addAll(getAllCards(game, playerId)); + } + return res; } public boolean removeCard(Card card, Game game) {