Search in sources :

Example 1 with EntersBattlefieldEffect

use of mage.abilities.effects.EntersBattlefieldEffect in project mage by magefree.

the class PyrrhicRevivalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<Card> toBattlefield = new HashSet<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            for (Card card : player.getGraveyard().getCards(game)) {
                if (card != null && card.isCreature(game)) {
                    toBattlefield.add(card);
                    ContinuousEffect effect = new EntersBattlefieldEffect(new AddCountersTargetEffect(CounterType.M1M1.createInstance()));
                    effect.setDuration(Duration.OneUse);
                    effect.setTargetPointer(new FixedTarget(card.getId()));
                    game.addEffect(effect, source);
                }
            }
        }
    }
    controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) EntersBattlefieldEffect(mage.abilities.effects.EntersBattlefieldEffect) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 2 with EntersBattlefieldEffect

use of mage.abilities.effects.EntersBattlefieldEffect in project mage by magefree.

the class GemstoneCavernsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result = false;
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = game.getCard(source.getSourceId());
        if (card != null) {
            ContinuousEffect effect = new EntersBattlefieldEffect(new AddCountersSourceEffect(CounterType.LUCK.createInstance()), "");
            effect.setDuration(Duration.OneUse);
            game.addEffect(effect, source);
            if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                Permanent permanent = game.getPermanent(card.getId());
                if (permanent != null) {
                    Cost cost = new ExileFromHandCost(new TargetCardInHand());
                    if (cost.canPay(source, source, source.getControllerId(), game)) {
                        result = cost.pay(source, game, source, source.getControllerId(), true, null);
                    }
                }
            }
        }
    }
    return result;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) EntersBattlefieldEffect(mage.abilities.effects.EntersBattlefieldEffect) Card(mage.cards.Card)

Aggregations

ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 EntersBattlefieldEffect (mage.abilities.effects.EntersBattlefieldEffect)2 Card (mage.cards.Card)2 Player (mage.players.Player)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 Cost (mage.abilities.costs.Cost)1 ExileFromHandCost (mage.abilities.costs.common.ExileFromHandCost)1 TapSourceCost (mage.abilities.costs.common.TapSourceCost)1 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)1 AddCountersTargetEffect (mage.abilities.effects.common.counter.AddCountersTargetEffect)1 Permanent (mage.game.permanent.Permanent)1 TargetCardInHand (mage.target.common.TargetCardInHand)1 FixedTarget (mage.target.targetpointer.FixedTarget)1