Search in sources :

Example 1 with OnLeaveReturnExiledToBattlefieldAbility

use of mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility in project mage by magefree.

the class YannikScavengingSentinelEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (player == null || sourcePermanent == null || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) < 1) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    int power = permanent.getPower().getValue();
    new ExileTargetEffect(CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()), permanent.getIdName()).setTargetPointer(new FixedTarget(permanent, game)).apply(game, source);
    game.addDelayedTriggeredAbility(new OnLeaveReturnExiledToBattlefieldAbility(), source);
    if (game.getState().getZone(permanent.getId()) != Zone.BATTLEFIELD) {
        ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DistributeCountersEffect(CounterType.P1P1, power, false, ""), false, "distribute X +1/+1 counters among any number of target creatures, " + "where X is the exiled creature's power");
        ability.addTarget(new TargetCreaturePermanentAmount(power));
        game.fireReflexiveTriggeredAbility(ability, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetCreaturePermanentAmount(mage.target.common.TargetCreaturePermanentAmount) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) DistributeCountersEffect(mage.abilities.effects.common.counter.DistributeCountersEffect) OnLeaveReturnExiledToBattlefieldAbility(mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 2 with OnLeaveReturnExiledToBattlefieldAbility

use of mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility in project mage by magefree.

the class DeputyOfDetentionExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    Permanent targeted = game.getPermanent(source.getFirstTarget());
    if (permanent == null || controller == null || targeted == null) {
        return false;
    }
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ControllerIdPredicate(targeted.getControllerId()));
    filter.add(new NamePredicate(targeted.getName()));
    Set<Card> toExile = new LinkedHashSet<>();
    for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
        toExile.add(creature);
    }
    if (!toExile.isEmpty()) {
        controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
        new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) OnLeaveReturnExiledToBattlefieldAbility(mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility) Card(mage.cards.Card)

Example 3 with OnLeaveReturnExiledToBattlefieldAbility

use of mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility in project mage by magefree.

the class AlignedHedronNetworkExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    // the target creature won't be exiled.
    if (controller != null && permanent != null) {
        Set<Card> toExile = new LinkedHashSet<>();
        for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), source.getSourceId(), game)) {
            toExile.add(creature);
        }
        if (!toExile.isEmpty()) {
            controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
            new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) OnLeaveReturnExiledToBattlefieldAbility(mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility) Card(mage.cards.Card)

Example 4 with OnLeaveReturnExiledToBattlefieldAbility

use of mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility in project mage by magefree.

the class ConsulateCracksownExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    // If the permanent leaves the battlefield before the ability resolves, artifacts won't be exiled.
    if (permanent == null || controller == null)
        return false;
    Set<Card> toExile = new LinkedHashSet<>();
    for (Permanent artifact : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
        toExile.add(artifact);
    }
    if (!toExile.isEmpty()) {
        controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
        new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) OnLeaveReturnExiledToBattlefieldAbility(mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility) Card(mage.cards.Card)

Aggregations

OnLeaveReturnExiledToBattlefieldAbility (mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility)4 Permanent (mage.game.permanent.Permanent)4 Player (mage.players.Player)4 LinkedHashSet (java.util.LinkedHashSet)3 CreateDelayedTriggeredAbilityEffect (mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect)3 Card (mage.cards.Card)3 FilterPermanent (mage.filter.FilterPermanent)2 TargetPermanent (mage.target.TargetPermanent)2 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)1 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)1 DistributeCountersEffect (mage.abilities.effects.common.counter.DistributeCountersEffect)1 FilterArtifactPermanent (mage.filter.common.FilterArtifactPermanent)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)1 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 TargetCreaturePermanentAmount (mage.target.common.TargetCreaturePermanentAmount)1 FixedTarget (mage.target.targetpointer.FixedTarget)1