Search in sources :

Example 6 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class AsThoughEffectImpl method allowCardToPlayWithoutMana.

/**
 * Internal method to do the necessary to allow the card from objectId to be
 * cast or played (if it's a land) without paying any mana. Additional costs
 * (like sacrificing or discarding) have still to be payed. Checks if the
 * card is of the correct type or in the correct zone have to be done
 * before.
 *
 * @param objectId sourceId of the card to play
 * @param source source ability that allows this effect
 * @param affectedControllerId player allowed to play the card
 * @param game
 * @return
 */
protected boolean allowCardToPlayWithoutMana(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    Player player = game.getPlayer(affectedControllerId);
    Card card = game.getCard(objectId);
    if (card == null || player == null) {
        return false;
    }
    if (!card.isLand(game)) {
        if (card instanceof SplitCard) {
            Card leftCard = ((SplitCard) card).getLeftHalfCard();
            player.setCastSourceIdWithAlternateMana(leftCard.getId(), null, leftCard.getSpellAbility().getCosts());
            Card rightCard = ((SplitCard) card).getRightHalfCard();
            player.setCastSourceIdWithAlternateMana(rightCard.getId(), null, rightCard.getSpellAbility().getCosts());
        } else if (card instanceof ModalDoubleFacesCard) {
            Card leftCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
            Card rightCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
            // some MDFC's are land.  IE: sea gate restoration
            if (!leftCard.isLand(game)) {
                player.setCastSourceIdWithAlternateMana(leftCard.getId(), null, leftCard.getSpellAbility().getCosts());
            }
            if (!rightCard.isLand(game)) {
                player.setCastSourceIdWithAlternateMana(rightCard.getId(), null, rightCard.getSpellAbility().getCosts());
            }
        } else if (card instanceof AdventureCard) {
            Card creatureCard = card.getMainCard();
            Card spellCard = ((AdventureCard) card).getSpellCard();
            player.setCastSourceIdWithAlternateMana(creatureCard.getId(), null, creatureCard.getSpellAbility().getCosts());
            player.setCastSourceIdWithAlternateMana(spellCard.getId(), null, spellCard.getSpellAbility().getCosts());
        }
        player.setCastSourceIdWithAlternateMana(objectId, null, card.getSpellAbility().getCosts());
    }
    return true;
}
Also used : Player(mage.players.Player) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) Card(mage.cards.Card)

Example 7 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class CardTextPredicate method apply.

@Override
public boolean apply(Card input, Game game) {
    if (text.isEmpty() && !isUnique) {
        return true;
    }
    if (text.isEmpty() && isUnique) {
        boolean found = !seenCards.containsKey(input.getName());
        seenCards.put(input.getName(), true);
        return found;
    }
    // first check in card name
    if (inNames) {
        String fullName = input.getName();
        if (input instanceof MockCard) {
            fullName = ((MockCard) input).getFullName(true);
        } else if (input instanceof ModalDoubleFacesCard) {
            fullName = input.getName() + MockCard.MODAL_DOUBLE_FACES_NAME_SEPARATOR + ((ModalDoubleFacesCard) input).getRightHalfCard().getName();
        } else if (input instanceof AdventureCard) {
            fullName = input.getName() + MockCard.ADVENTURE_NAME_SEPARATOR + ((AdventureCard) input).getSpellCard().getName();
        }
        if (fullName.toLowerCase(Locale.ENGLISH).contains(text.toLowerCase(Locale.ENGLISH))) {
            if (isUnique && seenCards.containsKey(input.getName())) {
                return false;
            }
            if (isUnique) {
                seenCards.put(input.getName(), true);
            }
            return true;
        }
    }
    // separate by spaces
    String[] tokens = text.toLowerCase(Locale.ENGLISH).split(" ");
    for (String token : tokens) {
        boolean found = false;
        if (!token.isEmpty()) {
            // then try to find in rules
            if (inRules) {
                if (input instanceof SplitCard) {
                    for (String rule : ((SplitCard) input).getLeftHalfCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                    for (String rule : ((SplitCard) input).getRightHalfCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                }
                if (input instanceof ModalDoubleFacesCard) {
                    for (String rule : ((ModalDoubleFacesCard) input).getLeftHalfCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                    for (String rule : ((ModalDoubleFacesCard) input).getRightHalfCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                }
                if (input instanceof AdventureCard) {
                    for (String rule : ((AdventureCard) input).getSpellCard().getRules(game)) {
                        if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                            found = true;
                            break;
                        }
                    }
                }
                for (String rule : input.getRules(game)) {
                    if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
                        found = true;
                        break;
                    }
                }
            }
            if (inTypes) {
                for (SubType subType : input.getSubtype(game)) {
                    if (subType.toString().equalsIgnoreCase(token)) {
                        found = true;
                        break;
                    }
                }
                for (SuperType superType : input.getSuperType()) {
                    if (superType.toString().equalsIgnoreCase(token)) {
                        found = true;
                        break;
                    }
                }
            }
        }
        if (found && isUnique && seenCards.containsKey(input.getName())) {
            found = false;
        }
        if (!found) {
            return false;
        }
    }
    if (isUnique) {
        seenCards.put(input.getName(), true);
    }
    return true;
}
Also used : ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SubType(mage.constants.SubType) MockCard(mage.cards.mock.MockCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) SuperType(mage.constants.SuperType)

Example 8 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class DoubleHeaderPredicate method apply.

@Override
public boolean apply(MageObject input, Game game) {
    String name = input.getName();
    if (input instanceof SplitCard) {
        return hasTwoWords(((SplitCard) input).getLeftHalfCard().getName()) || hasTwoWords(((SplitCard) input).getRightHalfCard().getName());
    } else if (input instanceof ModalDoubleFacesCard) {
        return hasTwoWords(((ModalDoubleFacesCard) input).getLeftHalfCard().getName()) || hasTwoWords(((ModalDoubleFacesCard) input).getRightHalfCard().getName());
    } else if (input instanceof Spell && ((Spell) input).getSpellAbility().getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
        SplitCard card = (SplitCard) ((Spell) input).getCard();
        return hasTwoWords(card.getLeftHalfCard().getName()) || hasTwoWords(card.getRightHalfCard().getName());
    } else {
        if (name.contains(" // ")) {
            String leftName = name.substring(0, name.indexOf(" // "));
            String rightName = name.substring(name.indexOf(" // ") + 4);
            return hasTwoWords(leftName) || hasTwoWords(rightName);
        } else {
            return hasTwoWords(name);
        }
    }
}
Also used : ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) SplitCard(mage.cards.SplitCard) Spell(mage.game.stack.Spell)

Example 9 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class EtherealValkyrieEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        controller.drawCards(1, source, game);
        TargetCardInHand targetCard = new TargetCardInHand(new FilterCard("card to exile face down. It becomes foretold."));
        if (controller.chooseTarget(Outcome.Benefit, targetCard, source, game)) {
            Card exileCard = game.getCard(targetCard.getFirstTarget());
            if (exileCard == null) {
                return false;
            }
            // process Split, MDFC, and Adventure cards first
            // note that 'Foretell Cost' refers to the main card (left) and 'Foretell Split Cost' refers to the (right) card if it exists
            ForetellAbility foretellAbility = null;
            if (exileCard instanceof SplitCard) {
                String leftHalfCost = CardUtil.reduceCost(((SplitCard) exileCard).getLeftHalfCard().getManaCost(), 2).getText();
                String rightHalfCost = CardUtil.reduceCost(((SplitCard) exileCard).getRightHalfCard().getManaCost(), 2).getText();
                game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Cost", leftHalfCost);
                game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Split Cost", rightHalfCost);
                foretellAbility = new ForetellAbility(exileCard, leftHalfCost, rightHalfCost);
            } else if (exileCard instanceof ModalDoubleFacesCard) {
                ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) exileCard).getLeftHalfCard();
                if (!leftHalfCard.isLand(game)) {
                    String leftHalfCost = CardUtil.reduceCost(leftHalfCard.getManaCost(), 2).getText();
                    game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Cost", leftHalfCost);
                    ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) exileCard).getRightHalfCard();
                    if (rightHalfCard.isLand(game)) {
                        foretellAbility = new ForetellAbility(exileCard, leftHalfCost);
                    } else {
                        String rightHalfCost = CardUtil.reduceCost(rightHalfCard.getManaCost(), 2).getText();
                        game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Split Cost", rightHalfCost);
                        foretellAbility = new ForetellAbility(exileCard, leftHalfCost, rightHalfCost);
                    }
                }
            } else if (exileCard instanceof AdventureCard) {
                String creatureCost = CardUtil.reduceCost(exileCard.getMainCard().getManaCost(), 2).getText();
                String spellCost = CardUtil.reduceCost(((AdventureCard) exileCard).getSpellCard().getManaCost(), 2).getText();
                game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Cost", creatureCost);
                game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Split Cost", spellCost);
                foretellAbility = new ForetellAbility(exileCard, creatureCost, spellCost);
            } else {
                // normal card
                String costText = CardUtil.reduceCost(exileCard.getManaCost(), 2).getText();
                game.getState().setValue(exileCard.getId().toString() + "Foretell Cost", costText);
                foretellAbility = new ForetellAbility(exileCard, costText);
            }
            // note that the card is not foretell'd into exile, it is put into exile and made foretold
            if (foretellAbility != null) {
                // copy source and use it for the foretold effect on the exiled card
                // bug #8673
                Ability copiedSource = source.copy();
                copiedSource.newId();
                copiedSource.setSourceId(exileCard.getId());
                game.getState().setValue(exileCard.getMainCard().getId().toString() + "Foretell Turn Number", game.getTurnNum());
                UUID exileId = CardUtil.getExileZoneId(exileCard.getMainCard().getId().toString() + "foretellAbility", game);
                controller.moveCardsToExile(exileCard, source, game, true, exileId, " Foretell Turn Number: " + game.getTurnNum());
                exileCard.setFaceDown(true, game);
                foretellAbility.setSourceId(exileCard.getId());
                foretellAbility.setControllerId(exileCard.getOwnerId());
                game.getState().addOtherAbility(exileCard, foretellAbility);
                foretellAbility.activate(game, true);
                ContinuousEffect effect = foretellAbility.new ForetellAddCostEffect(new MageObjectReference(exileCard, game));
                game.addEffect(effect, copiedSource);
                game.fireEvent(GameEvent.getEvent(GameEvent.EventType.FORETOLD, exileCard.getId(), null, null));
                return true;
            }
        }
    }
    return false;
}
Also used : FlyingAbility(mage.abilities.keyword.FlyingAbility) ForetellAbility(mage.abilities.keyword.ForetellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) ForetellAbility(mage.abilities.keyword.ForetellAbility) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) FilterCard(mage.filter.FilterCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) ModalDoubleFacesCardHalf(mage.cards.ModalDoubleFacesCardHalf) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 10 with ModalDoubleFacesCard

use of mage.cards.ModalDoubleFacesCard in project mage by magefree.

the class WrennAndSixEmblemEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    for (UUID cardId : controller.getGraveyard()) {
        Card card = game.getCard(cardId);
        if (card == null) {
            continue;
        }
        if (card instanceof SplitCard) {
            SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
            SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
            if (leftHalfCard.isInstantOrSorcery(game)) {
                Ability ability = new RetraceAbility(leftHalfCard);
                ability.setSourceId(cardId);
                ability.setControllerId(leftHalfCard.getOwnerId());
                game.getState().addOtherAbility(leftHalfCard, ability);
            }
            if (rightHalfCard.isInstantOrSorcery(game)) {
                Ability ability = new RetraceAbility(rightHalfCard);
                ability.setSourceId(cardId);
                ability.setControllerId(rightHalfCard.getOwnerId());
                game.getState().addOtherAbility(rightHalfCard, ability);
            }
        }
        if (card instanceof ModalDoubleFacesCard) {
            ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
            ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
            if (leftHalfCard.isInstantOrSorcery(game)) {
                Ability ability = new RetraceAbility(leftHalfCard);
                ability.setSourceId(cardId);
                ability.setControllerId(leftHalfCard.getOwnerId());
                game.getState().addOtherAbility(leftHalfCard, ability);
            }
            if (rightHalfCard.isInstantOrSorcery(game)) {
                Ability ability = new RetraceAbility(rightHalfCard);
                ability.setSourceId(cardId);
                ability.setControllerId(rightHalfCard.getOwnerId());
                game.getState().addOtherAbility(rightHalfCard, ability);
            }
        }
        if (card instanceof AdventureCard) {
            // Adventure cards are castable per https://twitter.com/elishffrn/status/1179047911729946624
            card = ((AdventureCard) card).getSpellCard();
        }
        if (!card.isInstantOrSorcery(game)) {
            continue;
        }
        Ability ability = new RetraceAbility(card);
        ability.setSourceId(cardId);
        ability.setControllerId(card.getOwnerId());
        game.getState().addOtherAbility(card, ability);
    }
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) RetraceAbility(mage.abilities.keyword.RetraceAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) RetraceAbility(mage.abilities.keyword.RetraceAbility) ModalDoubleFacesCardHalf(mage.cards.ModalDoubleFacesCardHalf) SplitCardHalf(mage.cards.SplitCardHalf) UUID(java.util.UUID) SplitCard(mage.cards.SplitCard) AdventureCard(mage.cards.AdventureCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) AdventureCard(mage.cards.AdventureCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card)

Aggregations

ModalDoubleFacesCard (mage.cards.ModalDoubleFacesCard)10 Card (mage.cards.Card)7 SplitCard (mage.cards.SplitCard)7 AdventureCard (mage.cards.AdventureCard)5 Player (mage.players.Player)4 Ability (mage.abilities.Ability)3 ModalDoubleFacesCardHalf (mage.cards.ModalDoubleFacesCardHalf)3 Test (org.junit.Test)3 UUID (java.util.UUID)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 SplitCardHalf (mage.cards.SplitCardHalf)2 SubType (mage.constants.SubType)2 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 ApprovingObject (mage.ApprovingObject)1 MageObject (mage.MageObject)1 MageObjectReference (mage.MageObjectReference)1 SpellAbility (mage.abilities.SpellAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 Costs (mage.abilities.costs.Costs)1