Search in sources :

Example 1 with ReturnToHandFromBattlefieldAllEffect

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

the class DispersalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Set<PermanentIdPredicate> permsToReturn = new HashSet<>();
    for (UUID opponentId : game.getOpponents(player.getId())) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null) {
            continue;
        }
        int highestCMC = 0;
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
            if (permanent != null) {
                highestCMC = Math.max(highestCMC, permanent.getManaValue());
            }
        }
        FilterPermanent filter = new FilterNonlandPermanent("permanent you control with mana value " + highestCMC);
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, highestCMC));
        filter.add(new ControllerIdPredicate(opponentId));
        Target target = new TargetPermanent(1, 1, filter, true);
        if (opponent.choose(outcome, target, source.getSourceId(), game)) {
            if (target.getFirstTarget() == null) {
                continue;
            }
            permsToReturn.add(new PermanentIdPredicate(target.getFirstTarget()));
        }
    }
    FilterPermanent filter = new FilterPermanent();
    filter.add(Predicates.or(permsToReturn));
    new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
    new DiscardEachPlayerEffect(StaticValue.get(1), false, TargetController.OPPONENT).apply(game, source);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ReturnToHandFromBattlefieldAllEffect(mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect) DiscardEachPlayerEffect(mage.abilities.effects.common.discard.DiscardEachPlayerEffect) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Target(mage.target.Target) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) HashSet(java.util.HashSet)

Example 2 with ReturnToHandFromBattlefieldAllEffect

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

the class DromarTheBanisherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        ChoiceColor choice = new ChoiceColor();
        if (player.choose(outcome, choice, game)) {
            game.informPlayers(player.getLogName() + " chooses " + choice.getChoice());
            FilterCreaturePermanent filter = new FilterCreaturePermanent();
            filter.add(new ColorPredicate(choice.getColor()));
            new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
            return true;
        }
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ReturnToHandFromBattlefieldAllEffect(mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect) ChoiceColor(mage.choices.ChoiceColor)

Example 3 with ReturnToHandFromBattlefieldAllEffect

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

the class HurkylsRecallReturnToHandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (targetPointer.getFirst(game, source) != null) {
        FilterPermanent filter = new FilterArtifactPermanent();
        filter.add(new OwnerIdPredicate(targetPointer.getFirst(game, source)));
        return new ReturnToHandFromBattlefieldAllEffect(filter).apply(game, source);
    }
    return false;
}
Also used : FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterPermanent(mage.filter.FilterPermanent) ReturnToHandFromBattlefieldAllEffect(mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect)

Aggregations

ReturnToHandFromBattlefieldAllEffect (mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect)3 FilterPermanent (mage.filter.FilterPermanent)2 Player (mage.players.Player)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 DiscardEachPlayerEffect (mage.abilities.effects.common.discard.DiscardEachPlayerEffect)1 ChoiceColor (mage.choices.ChoiceColor)1 FilterArtifactPermanent (mage.filter.common.FilterArtifactPermanent)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)1 OwnerIdPredicate (mage.filter.predicate.card.OwnerIdPredicate)1 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)1 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)1 Permanent (mage.game.permanent.Permanent)1 Target (mage.target.Target)1 TargetPermanent (mage.target.TargetPermanent)1