Painters Servant - removed duplicated code;

This commit is contained in:
Oleg Agafonov 2021-09-04 17:48:46 +04:00
parent 0d7b75cae0
commit 21a9735aaf
2 changed files with 75 additions and 113 deletions

View file

@ -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<Card> 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;

View file

@ -71,12 +71,36 @@ public class Exile implements Serializable, Copyable<Exile> {
return allCards.stream().filter(card -> filter.match(card, game)).collect(Collectors.toList());
}
@Deprecated // TODO: must use related request due game range
public List<Card> getAllCards(Game game) {
List<Card> 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<Card> getAllCards(Game game, UUID fromPlayerId) {
List<Card> 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<Card> getAllCardsByRange(Game game, UUID controllerId) {
List<Card> 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) {