Search in sources :

Example 1 with FilterArtifactCreaturePermanent

use of mage.filter.common.FilterArtifactCreaturePermanent in project mage by magefree.

the class PerilousPredicamentSacrificeOpponentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> perms = new ArrayList<>();
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            FilterArtifactCreaturePermanent filterArtifact = new FilterArtifactCreaturePermanent("an artifact creature");
            filterArtifact.add(new ControllerIdPredicate(player.getId()));
            FilterCreaturePermanent filterNonArtifact = new FilterCreaturePermanent("a nonartifact creature");
            filterNonArtifact.add(Predicates.not(CardType.ARTIFACT.getPredicate()));
            filterNonArtifact.add(new ControllerIdPredicate(player.getId()));
            if (game.getBattlefield().countAll(filterArtifact, player.getId(), game) > 0) {
                TargetPermanent target = new TargetPermanent(1, 1, filterArtifact, true);
                if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                    player.chooseTarget(Outcome.Sacrifice, target, source, game);
                    perms.addAll(target.getTargets());
                }
            }
            if (game.getBattlefield().countAll(filterNonArtifact, player.getId(), game) > 0) {
                TargetPermanent target = new TargetPermanent(1, 1, filterNonArtifact, true);
                if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                    player.chooseTarget(Outcome.Sacrifice, target, source, game);
                    perms.addAll(target.getTargets());
                }
            }
        }
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterArtifactCreaturePermanent(mage.filter.common.FilterArtifactCreaturePermanent) FilterArtifactCreaturePermanent(mage.filter.common.FilterArtifactCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ArrayList(java.util.ArrayList) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Aggregations

ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 FilterArtifactCreaturePermanent (mage.filter.common.FilterArtifactCreaturePermanent)1 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 Permanent (mage.game.permanent.Permanent)1 Player (mage.players.Player)1 TargetPermanent (mage.target.TargetPermanent)1