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;
}
Aggregations