Search in sources :

Example 96 with Card

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

the class ReturnCreatureFromGraveyardToBattlefieldAndGainHasteEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = game.getCard(source.getFirstTarget());
    if (card != null) {
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        Permanent permanent = game.getPermanent(card.getId());
        if (permanent != null) {
            ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Card(mage.cards.Card)

Example 97 with Card

use of mage.cards.Card 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 98 with Card

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

the class ReturnToHandSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    MageObject mageObject;
    if (returnFromNextZone && game.getState().getZoneChangeCounter(source.getSourceId()) == source.getSourceObjectZoneChangeCounter() + 1) {
        mageObject = game.getObject(source.getSourceId());
    } else {
        mageObject = source.getSourceObjectIfItStillExists(game);
    }
    if (mageObject == null) {
        return true;
    }
    switch(game.getState().getZone(mageObject.getId())) {
        case BATTLEFIELD:
            Permanent permanent = game.getPermanent(source.getSourceId());
            if (permanent != null && permanent.isPhasedIn()) {
                return controller.moveCards(permanent, Zone.HAND, source, game);
            }
            break;
        case GRAVEYARD:
            Card card = (Card) mageObject;
            return !fromBattlefieldOnly && controller.moveCards(card, Zone.HAND, source, game);
        case STACK:
            Spell spell = game.getSpell(source.getSourceId());
            return !fromBattlefieldOnly && spell != null && controller.moveCards(spell.getMainCard(), Zone.HAND, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 99 with Card

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

the class ReturnToHandTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<UUID> copyIds = new ArrayList<>();
    Set<Card> cards = new LinkedHashSet<>();
    if (multitargetHandling) {
        for (Target target : source.getTargets()) {
            for (UUID targetId : target.getTargets()) {
                MageObject mageObject = game.getObject(targetId);
                if (mageObject instanceof Spell && mageObject.isCopy()) {
                    copyIds.add(targetId);
                } else if (mageObject instanceof Card) {
                    cards.add((Card) mageObject);
                }
            }
        }
    } else {
        for (UUID targetId : targetPointer.getTargets(game, source)) {
            MageObject mageObject = game.getObject(targetId);
            if (mageObject != null) {
                if (mageObject instanceof Spell && mageObject.isCopy()) {
                    copyIds.add(targetId);
                } else if (mageObject instanceof Card) {
                    cards.add((Card) mageObject);
                }
            }
        }
    }
    for (UUID copyId : copyIds) {
        game.getStack().remove(game.getSpell(copyId), game);
    }
    return controller.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) Target(mage.target.Target) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 100 with Card

use of mage.cards.Card 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)

Aggregations

Card (mage.cards.Card)1448 Player (mage.players.Player)1096 Permanent (mage.game.permanent.Permanent)423 FilterCard (mage.filter.FilterCard)381 UUID (java.util.UUID)340 CardsImpl (mage.cards.CardsImpl)253 MageObject (mage.MageObject)212 FixedTarget (mage.target.targetpointer.FixedTarget)173 TargetCard (mage.target.TargetCard)165 Cards (mage.cards.Cards)159 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)111 ContinuousEffect (mage.abilities.effects.ContinuousEffect)99 TargetCardInHand (mage.target.common.TargetCardInHand)98 Target (mage.target.Target)86 HashSet (java.util.HashSet)85 FilterCreatureCard (mage.filter.common.FilterCreatureCard)84 ApprovingObject (mage.ApprovingObject)77 Ability (mage.abilities.Ability)71 TargetPlayer (mage.target.TargetPlayer)67 TargetPermanent (mage.target.TargetPermanent)64