Search in sources :

Example 6 with MageItem

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;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Collection(java.util.Collection) MageItem(mage.MageItem) TargetPermanent(mage.target.TargetPermanent)

Aggregations

MageItem (mage.MageItem)6 Player (mage.players.Player)5 Cards (mage.cards.Cards)4 CardsImpl (mage.cards.CardsImpl)3 TargetPermanent (mage.target.TargetPermanent)3 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Ability (mage.abilities.Ability)2 DrawCardSourceControllerEffect (mage.abilities.effects.common.DrawCardSourceControllerEffect)2 CardSetInfo (mage.cards.CardSetInfo)2 FilterCard (mage.filter.FilterCard)2 FilterPermanent (mage.filter.FilterPermanent)2 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)2 Game (mage.game.Game)2 Permanent (mage.game.permanent.Permanent)2 Target (mage.target.Target)2 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)2 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1