Search in sources :

Example 31 with CreateTokenCopyTargetEffect

use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.

the class CreateTokenCopySourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (permanent == null) {
        return false;
    }
    CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, false, number, tapped, false);
    effect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
    return effect.apply(game, source);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect)

Example 32 with CreateTokenCopyTargetEffect

use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.

the class FaerieArtisansEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanentToCopy = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && permanentToCopy != null) {
        CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(null, CardType.ARTIFACT, false);
        effect.setTargetPointer(new FixedTarget(permanentToCopy, game));
        if (effect.apply(game, source)) {
            String oldTokens = (String) game.getState().getValue(source.getSourceId().toString() + source.getSourceObjectZoneChangeCounter());
            StringBuilder sb = new StringBuilder();
            for (Permanent permanent : effect.getAddedPermanents()) {
                if (sb.length() > 0) {
                    sb.append(';');
                }
                sb.append(permanent.getId());
            }
            game.getState().setValue(source.getSourceId().toString() + source.getSourceObjectZoneChangeCounter(), sb.toString());
            if (oldTokens != null) {
                Cards cards = new CardsImpl();
                StringTokenizer tokenizer = new StringTokenizer(oldTokens, ";");
                while (tokenizer.hasMoreTokens()) {
                    String tokenId = tokenizer.nextToken();
                    cards.add(UUID.fromString(tokenId));
                }
                controller.moveCards(cards, Zone.EXILED, source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) StringTokenizer(java.util.StringTokenizer) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 33 with CreateTokenCopyTargetEffect

use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.

the class FlamerushRiderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (controller != null && permanent != null) {
        CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true, 1, true, true);
        effect.setTargetPointer(new FixedTarget(permanent, game));
        effect.apply(game, source);
        for (Permanent addedToken : effect.getAddedPermanents()) {
            Effect exileEffect = new ExileTargetEffect();
            exileEffect.setTargetPointer(new FixedTarget(addedToken, game));
            new CreateDelayedTriggeredAbilityEffect(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), false).apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Effect(mage.abilities.effects.Effect) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 34 with CreateTokenCopyTargetEffect

use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.

the class FlameshadowConjuringEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (permanent != null) {
        CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(null, null, true);
        effect.setTargetPointer(getTargetPointer());
        if (effect.apply(game, source)) {
            for (Permanent tokenPermanent : effect.getAddedPermanents()) {
                ExileTargetEffect exileEffect = new ExileTargetEffect();
                exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
                DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
                game.addDelayedTriggeredAbility(delayedAbility, source);
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 35 with CreateTokenCopyTargetEffect

use of mage.abilities.effects.common.CreateTokenCopyTargetEffect in project mage by magefree.

the class HauntingImitationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Cards cards = new CardsImpl();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Card card = player.getLibrary().getFromTop(game);
        if (card == null) {
            continue;
        }
        player.revealCards(source, new CardsImpl(cards), game);
        if (card.isCreature(game)) {
            cards.add(card);
        }
    }
    if (cards.isEmpty()) {
        Player player = game.getPlayer(source.getControllerId());
        MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
        if (player != null && sourceObject instanceof Card) {
            player.moveCards((Card) sourceObject, Zone.HAND, source, game);
        }
        return true;
    }
    CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, false, 1, false, false, null, 1, 1, true);
    effect.setAdditionalSubType(SubType.SPIRIT);
    for (Card card : cards.getCards(game)) {
        effect.setSavedPermanent(new PermanentCard(card, source.getControllerId(), game));
        effect.apply(game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Aggregations

CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)64 FixedTarget (mage.target.targetpointer.FixedTarget)50 Permanent (mage.game.permanent.Permanent)46 Player (mage.players.Player)31 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)20 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)17 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)14 Card (mage.cards.Card)12 TargetPermanent (mage.target.TargetPermanent)10 UUID (java.util.UUID)9 Effect (mage.abilities.effects.Effect)8 OneShotEffect (mage.abilities.effects.OneShotEffect)8 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)7 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)7 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)7 FixedTargets (mage.target.targetpointer.FixedTargets)6 AtTheEndOfCombatDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility)5 FilterPermanent (mage.filter.FilterPermanent)5 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)5 FilterCard (mage.filter.FilterCard)4