Search in sources :

Example 31 with FixedTargets

use of mage.target.targetpointer.FixedTargets in project mage by magefree.

the class MirrorMatchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID attackerId : game.getCombat().getAttackers()) {
            Permanent attacker = game.getPermanent(attackerId);
            if (attacker != null && source.isControlledBy(game.getCombat().getDefendingPlayerId(attackerId, game))) {
                CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, false);
                effect.setTargetPointer(new FixedTarget(attacker, game));
                effect.apply(game, source);
                CombatGroup group = game.getCombat().findGroup(attacker.getId());
                boolean isCreature = false;
                if (group != null) {
                    for (Permanent addedToken : effect.getAddedPermanents()) {
                        if (addedToken.isCreature(game)) {
                            group.addBlockerToGroup(addedToken.getId(), attackerId, game);
                            isCreature = true;
                        }
                    }
                    ExileTargetEffect exileEffect = new ExileTargetEffect("Exile those tokens at end of combat");
                    exileEffect.setTargetPointer(new FixedTargets(effect.getAddedPermanents(), game));
                    game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), source);
                    if (isCreature) {
                        group.pickBlockerOrder(attacker.getControllerId(), game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FixedTargets(mage.target.targetpointer.FixedTargets) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) UUID(java.util.UUID) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) CombatGroup(mage.game.combat.CombatGroup) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 32 with FixedTargets

use of mage.target.targetpointer.FixedTargets in project mage by magefree.

the class SeanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && card != null) {
        // Also if the move to exile is replaced, the copy takes place
        controller.moveCards(card, Zone.EXILED, source, game);
        CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, false);
        effect.setTargetPointer(new FixedTarget(card, game));
        effect.setAdditionalSubType(SubType.SPIRIT);
        effect.apply(game, source);
        ExileTargetEffect exileEffect = new ExileTargetEffect();
        exileEffect.setTargetPointer(new FixedTargets(effect.getAddedPermanents(), game));
        DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
        game.addDelayedTriggeredAbility(delayedAbility, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) FixedTargets(mage.target.targetpointer.FixedTargets) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Card(mage.cards.Card) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 33 with FixedTargets

use of mage.target.targetpointer.FixedTargets in project mage by magefree.

the class TilonallisSummonerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ManaCosts cost = new ManaCostsImpl("{X}{R}");
        if (controller.chooseUse(outcome, "Pay " + cost.getText() + "? If you do, you create X 1/1 red Elemental creature tokens that are tapped and attacking.", source, game)) {
            int costX = controller.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
            cost.add(new GenericManaCost(costX));
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                // otherwise you can undo the payment
                controller.resetStoredBookmark(game);
                CreateTokenEffect effect = new CreateTokenEffect(new TilonallisSummonerElementalToken(), costX, true, true);
                effect.apply(game, source);
                Effect exileEffect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD).setText("exile those tokens unless you have the city's blessing");
                exileEffect.setTargetPointer(new FixedTargets(new CardsImpl(effect.getLastAddedTokenIds()), game));
                game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect, TargetController.ANY, new InvertCondition(CitysBlessingCondition.instance)), source);
            }
        }
        return true;
    }
    return false;
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) TilonallisSummonerElementalToken(mage.game.permanent.token.TilonallisSummonerElementalToken) FixedTargets(mage.target.targetpointer.FixedTargets) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) CitysBlessingHint(mage.abilities.hint.common.CitysBlessingHint) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) InvertCondition(mage.abilities.condition.InvertCondition) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) CardsImpl(mage.cards.CardsImpl) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 34 with FixedTargets

use of mage.target.targetpointer.FixedTargets in project mage by magefree.

the class PlayFromNotOwnHandZoneTargetEffect method exileAndPlayFromExile.

/**
 * Exiles the cards and let the allowed player play them from exile for the given duration
 * Supports:
 *  - cards (use any side)
 *  - permanents (use permanent, not permanent's card)
 *
 * @param game
 * @param source
 * @param cards
 * @param allowedCaster
 * @param duration
 * @param withoutMana
 * @param anyColor
 * @param onlyCastAllowed true for rule "cast that card" and false for rule "play that card"
 * @return
 */
public static boolean exileAndPlayFromExile(Game game, Ability source, Set<Card> cards, TargetController allowedCaster, Duration duration, boolean withoutMana, boolean anyColor, boolean onlyCastAllowed) {
    if (cards == null || cards.isEmpty()) {
        return true;
    }
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    UUID exileId = CardUtil.getExileZoneId(controller.getId().toString() + "-" + game.getState().getTurnNum() + "-" + sourceObject.getIdName(), game);
    String exileName = sourceObject.getIdName() + " free play" + (Duration.EndOfTurn.equals(duration) ? " on turn " + game.getState().getTurnNum() : "") + " for " + controller.getName();
    if (Duration.EndOfTurn.equals(duration)) {
        game.getExile().createZone(exileId, exileName).setCleanupOnEndTurn(true);
    }
    if (!controller.moveCardsToExile(cards, source, game, true, exileId, exileName)) {
        return false;
    }
    // get real cards (if it was called on permanent instead card, example: Release to the Wind)
    Set<Card> cardsToPlay = cards.stream().map(Card::getMainCard).filter(card -> Zone.EXILED.equals(game.getState().getZone(card.getId()))).collect(Collectors.toSet());
    ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, allowedCaster, duration, withoutMana, onlyCastAllowed);
    effect.setTargetPointer(new FixedTargets(cardsToPlay, game));
    game.addEffect(effect, source);
    if (anyColor) {
        for (Card card : cardsToPlay) {
            game.addEffect(new YouMaySpendManaAsAnyColorToCastTargetEffect(duration).setTargetPointer(new FixedTarget(card, game)), source);
        }
    }
    return true;
}
Also used : Set(java.util.Set) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) HashSet(java.util.HashSet) PlayLandAbility(mage.abilities.PlayLandAbility) Game(mage.game.Game) List(java.util.List) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) FixedTargets(mage.target.targetpointer.FixedTargets) MageObject(mage.MageObject) Card(mage.cards.Card) mage.constants(mage.constants) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FixedTargets(mage.target.targetpointer.FixedTargets) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) Card(mage.cards.Card)

Example 35 with FixedTargets

use of mage.target.targetpointer.FixedTargets in project mage by magefree.

the class FlamesOfRemembranceMayPlayExiledEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, amount.calculate(game, source, this)));
        if (!cards.isEmpty()) {
            controller.moveCardsToExile(cards.getCards(game), source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, ""));
            ContinuousEffect effect = new FlamesOfRemembranceMayPlayExiledEffect();
            effect.setTargetPointer(new FixedTargets(cards, game));
            game.addEffect(effect, source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FixedTargets(mage.target.targetpointer.FixedTargets) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Aggregations

FixedTargets (mage.target.targetpointer.FixedTargets)58 Player (mage.players.Player)36 Permanent (mage.game.permanent.Permanent)28 ArrayList (java.util.ArrayList)19 UUID (java.util.UUID)19 OneShotEffect (mage.abilities.effects.OneShotEffect)15 CardsImpl (mage.cards.CardsImpl)15 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)14 ContinuousEffect (mage.abilities.effects.ContinuousEffect)14 Effect (mage.abilities.effects.Effect)14 Card (mage.cards.Card)14 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)13 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)10 Cards (mage.cards.Cards)10 Token (mage.game.permanent.token.Token)9 TargetPermanent (mage.target.TargetPermanent)8 HashSet (java.util.HashSet)7 MageObject (mage.MageObject)7 DontUntapInControllersNextUntapStepTargetEffect (mage.abilities.effects.common.DontUntapInControllersNextUntapStepTargetEffect)7 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)6