Search in sources :

Example 1 with MeldCard

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

the class LongRoadHomeEntersBattlefieldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(objectToReturn.getSourceId());
    if (card != null && objectToReturn.refersTo(card, game)) {
        Player owner = game.getPlayer(card.getOwnerId());
        if (owner != null) {
            if (card instanceof MeldCard) {
                MeldCard meldCard = (MeldCard) card;
                game.addEffect(new LongRoadHomeEntersBattlefieldEffect(new MageObjectReference(meldCard.getTopHalfCard(), game)), source);
                game.addEffect(new LongRoadHomeEntersBattlefieldEffect(new MageObjectReference(meldCard.getBottomHalfCard(), game)), source);
            } else {
                game.addEffect(new LongRoadHomeEntersBattlefieldEffect(objectToReturn), source);
            }
            owner.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) MeldCard(mage.cards.MeldCard) MageObjectReference(mage.MageObjectReference) MeldCard(mage.cards.MeldCard) Card(mage.cards.Card)

Example 2 with MeldCard

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

the class ReturnToBattlefieldUnderYourControlTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cardsToBattlefield = new CardsImpl();
        if (returnFromExileZoneOnly) {
            for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
                UUID mainCardId = CardUtil.getMainCardId(game, targetId);
                if (game.getExile().containsId(mainCardId, game)) {
                    cardsToBattlefield.add(mainCardId);
                } else {
                    Card card = game.getCard(targetId);
                    if (card instanceof MeldCard) {
                        MeldCard meldCard = (MeldCard) card;
                        Card topCard = meldCard.getTopHalfCard();
                        Card bottomCard = meldCard.getBottomHalfCard();
                        if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter() && game.getExile().containsId(topCard.getId(), game)) {
                            cardsToBattlefield.add(topCard);
                        }
                        if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter() && game.getExile().containsId(bottomCard.getId(), game)) {
                            cardsToBattlefield.add(bottomCard);
                        }
                    }
                }
            }
        } else {
            cardsToBattlefield.addAll(getTargetPointer().getTargets(game, source));
        }
        for (Card card : cardsToBattlefield.getCards(game)) {
            if (controller.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, false, null)) {
                if (attacking) {
                    game.getCombat().addAttackingCreature(card.getId(), game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) MeldCard(mage.cards.MeldCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) MeldCard(mage.cards.MeldCard) Card(mage.cards.Card)

Example 3 with MeldCard

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

the class ReturnToBattlefieldUnderOwnerControlTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cardsToBattlefield = new CardsImpl();
        if (returnFromExileZoneOnly) {
            for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
                if (game.getExile().containsId(targetId, game)) {
                    cardsToBattlefield.add(targetId);
                } else {
                    Card card = game.getCard(targetId);
                    if (card instanceof MeldCard) {
                        MeldCard meldCard = (MeldCard) card;
                        Card topCard = meldCard.getTopHalfCard();
                        Card bottomCard = meldCard.getBottomHalfCard();
                        if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter() && game.getExile().containsId(topCard.getId(), game)) {
                            cardsToBattlefield.add(topCard);
                        }
                        if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter() && game.getExile().containsId(bottomCard.getId(), game)) {
                            cardsToBattlefield.add(bottomCard);
                        }
                    }
                }
            }
        } else {
            cardsToBattlefield.addAll(getTargetPointer().getTargets(game, source));
        }
        if (!cardsToBattlefield.isEmpty()) {
            controller.moveCards(cardsToBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, tapped, false, true, null);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) MeldCard(mage.cards.MeldCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) MeldCard(mage.cards.MeldCard) Card(mage.cards.Card)

Example 4 with MeldCard

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

the class MeldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        // Find the two permanents to meld.
        UUID sourceId = source.getSourceId();
        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature named " + meldWithName);
        filter.add(new NamePredicate(meldWithName));
        TargetPermanent target = new TargetControlledCreaturePermanent(filter);
        Set<UUID> meldWithList = target.possibleTargets(sourceId, source.getControllerId(), game);
        if (meldWithList.isEmpty()) {
            // possible permanent has left the battlefield meanwhile
            return false;
        }
        UUID meldWithId = null;
        if (meldWithList.size() == 1) {
            meldWithId = meldWithList.iterator().next();
        } else {
            if (controller.choose(Outcome.BoostCreature, target, sourceId, game)) {
                meldWithId = target.getFirstTarget();
            }
        }
        // Exile the two permanents to meld.
        Permanent sourcePermanent = game.getPermanent(sourceId);
        Permanent meldWithPermanent = game.getPermanent(meldWithId);
        if (sourcePermanent != null && meldWithPermanent != null) {
            Set<Card> toExile = new HashSet<>();
            toExile.add(sourcePermanent);
            toExile.add(meldWithPermanent);
            controller.moveCards(toExile, Zone.EXILED, source, game);
            // Create the meld card and move it to the battlefield.
            Card sourceCard = game.getExile().getCard(sourceId, game);
            Card meldWithCard = game.getExile().getCard(meldWithId, game);
            if (sourceCard != null && !sourceCard.isCopy() && meldWithCard != null && !meldWithCard.isCopy()) {
                meldCard.setOwnerId(controller.getId());
                meldCard.setTopHalfCard(meldWithCard, game);
                meldCard.setBottomHalfCard(sourceCard, game);
                meldCard.setMelded(true, game);
                game.addMeldCard(meldCard.getId(), meldCard);
                game.getState().addCard(meldCard);
                meldCard.setZone(Zone.EXILED, game);
                controller.moveCards(meldCard, Zone.BATTLEFIELD, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MeldCard(mage.cards.MeldCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Aggregations

Card (mage.cards.Card)4 MeldCard (mage.cards.MeldCard)4 Player (mage.players.Player)4 UUID (java.util.UUID)3 Cards (mage.cards.Cards)2 CardsImpl (mage.cards.CardsImpl)2 HashSet (java.util.HashSet)1 MageObjectReference (mage.MageObjectReference)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)1 Permanent (mage.game.permanent.Permanent)1 TargetPermanent (mage.target.TargetPermanent)1 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)1