use of mage.MageItem in project mage by magefree.
the class CallOfTheDeathDwellerTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Cards cards = new CardsImpl(source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).collect(Collectors.toSet()));
if (player == null || cards.isEmpty() || !player.moveCards(cards, Zone.BATTLEFIELD, source, game)) {
return false;
}
List<PermanentIdPredicate> predicates = cards.stream().map(game::getPermanent).filter(Objects::nonNull).map(MageItem::getId).map(PermanentIdPredicate::new).collect(Collectors.toList());
if (predicates.isEmpty()) {
return false;
}
FilterPermanent filter = new FilterPermanent("creature to put a deathtouch counter on");
filter.add(Predicates.or(predicates));
Target target = new TargetPermanent(0, 1, filter, true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.addCounters(CounterType.DEATHTOUCH.createInstance(), source.getControllerId(), source, game);
}
}
filter.setMessage("creature to put a menace counter on");
target = new TargetPermanent(0, 1, filter, true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.addCounters(CounterType.MENACE.createInstance(), source.getControllerId(), source, game);
}
}
return true;
}
Aggregations