Search in sources :

Example 36 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class GodsendRuleModifyingEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent equipment = game.getPermanentOrLKIBattlefield((this.getSourceId()));
    if (equipment != null && equipment.getAttachedTo() != null) {
        Permanent equippedPermanent = game.getPermanentOrLKIBattlefield((equipment.getAttachedTo()));
        if (equippedPermanent != null) {
            possibleTargets.clear();
            String targetName = "";
            if (equippedPermanent.isAttacking()) {
                for (CombatGroup group : game.getCombat().getGroups()) {
                    if (group.getAttackers().contains(equippedPermanent.getId())) {
                        possibleTargets.addAll(group.getBlockers());
                    }
                }
                targetName = "a creature blocking attacker ";
            } else if (equippedPermanent.getBlocking() > 0) {
                for (CombatGroup group : game.getCombat().getGroups()) {
                    if (group.getBlockers().contains(equippedPermanent.getId())) {
                        possibleTargets.addAll(group.getAttackers());
                    }
                }
                targetName = "a creature blocked by creature ";
            }
            if (!possibleTargets.isEmpty()) {
                this.getTargets().clear();
                if (possibleTargets.size() == 1) {
                    this.getEffects().get(0).setTargetPointer(new FixedTarget(possibleTargets.iterator().next(), game));
                } else {
                    this.getEffects().get(0).setTargetPointer(new FirstTargetPointer());
                    targetName = targetName + " equipped by " + equipment.getName();
                    FilterCreaturePermanent filter = new FilterCreaturePermanent(targetName);
                    List<PermanentIdPredicate> uuidPredicates = new ArrayList<>();
                    for (UUID creatureId : possibleTargets) {
                        uuidPredicates.add(new PermanentIdPredicate(creatureId));
                    }
                    filter.add(Predicates.or(uuidPredicates));
                    this.getTargets().add(new TargetCreaturePermanent(filter));
                }
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FirstTargetPointer(mage.target.targetpointer.FirstTargetPointer) CombatGroup(mage.game.combat.CombatGroup)

Example 37 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class SasayasEssenceManaEffect method produceMana.

/**
 * RULINGS 6/1/2005 If Sasaya’s Essence’s controller has four Forests and
 * taps one of them for Green, the Essence will add GreenGreenGreen to that
 * player’s mana pool for a total of GreenGreenGreenGreen.
 *
 * 6/1/2005 If Sasaya’s Essence’s controller has four Mossfire Valley and
 * taps one of them for RedGreen, the Essence will add three mana (one for
 * each other Mossfire Valley) of any combination of Red and/or Green to
 * that player’s mana pool.
 *
 * 6/1/2005 If Sasaya’s Essence’s controller has two Brushlands and taps one
 * of them for White, Sasaya’s Essence adds another White to that player’s
 * mana pool. It won’t produce Green or Colorless unless the land was tapped
 * for Green or Colorless instead.
 */
@Override
public Mana produceMana(Game game, Ability source) {
    Mana newMana = new Mana();
    if (game == null) {
        return newMana;
    }
    Player controller = game.getPlayer(source.getControllerId());
    Mana mana = (Mana) this.getValue("mana");
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null && mana != null && permanent != null) {
        FilterPermanent filter = new FilterLandPermanent();
        filter.add(Predicates.not(new PermanentIdPredicate(permanent.getId())));
        filter.add(new NamePredicate(permanent.getName()));
        int count = game.getBattlefield().countAll(filter, controller.getId(), game);
        if (count > 0) {
            Choice choice = new ChoiceColor(true);
            choice.getChoices().clear();
            choice.setMessage("Pick the type of mana to produce");
            if (mana.getBlack() > 0) {
                choice.getChoices().add("Black");
            }
            if (mana.getRed() > 0) {
                choice.getChoices().add("Red");
            }
            if (mana.getBlue() > 0) {
                choice.getChoices().add("Blue");
            }
            if (mana.getGreen() > 0) {
                choice.getChoices().add("Green");
            }
            if (mana.getWhite() > 0) {
                choice.getChoices().add("White");
            }
            if (mana.getColorless() > 0) {
                choice.getChoices().add("Colorless");
            }
            if (!choice.getChoices().isEmpty()) {
                for (int i = 0; i < count; i++) {
                    choice.clearChoice();
                    if (choice.getChoices().size() == 1) {
                        choice.setChoice(choice.getChoices().iterator().next());
                    } else {
                        if (!controller.choose(outcome, choice, game)) {
                            return newMana;
                        }
                    }
                    switch(choice.getChoice()) {
                        case "Black":
                            newMana.increaseBlack();
                            break;
                        case "Blue":
                            newMana.increaseBlue();
                            break;
                        case "Red":
                            newMana.increaseRed();
                            break;
                        case "Green":
                            newMana.increaseGreen();
                            break;
                        case "White":
                            newMana.increaseWhite();
                            break;
                        case "Colorless":
                            newMana.increaseColorless();
                            break;
                    }
                }
            }
        }
    }
    return newMana;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Mana(mage.Mana) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) ChoiceColor(mage.choices.ChoiceColor)

Example 38 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class GauntletsOfLightEffect method apply.

@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null || permanent.getAttachedTo() == null) {
        return false;
    }
    Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
    if (attachedTo == null || !attachedTo.getAbilities().containsKey(VigilanceAbility.getInstance().getId())) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new PermanentIdPredicate(permanent.getAttachedTo()));
    game.getCombat().setUseToughnessForDamage(true);
    game.getCombat().addUseToughnessForDamageFilter(filter);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 39 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate 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)

Example 40 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class DescentIntoMadnessEffect method selectCards.

private void selectCards(Player player, List<UUID> selectedObjects, int count, Ability source, Game game) {
    int amount = Math.min(count, player.getHand().size() + game.getBattlefield().getAllActivePermanents(player.getId()).size());
    int cardsFromHand = 0;
    while (player.canRespond() && amount > 0) {
        Target target;
        do {
            FilterControlledPermanent filter = new FilterControlledPermanent();
            filter.setMessage("permanent you control (" + amount + " left in total)");
            List<PermanentIdPredicate> uuidPredicates = new ArrayList<>();
            for (UUID uuid : selectedObjects) {
                uuidPredicates.add(new PermanentIdPredicate(uuid));
            }
            filter.add(Predicates.not(Predicates.or(uuidPredicates)));
            target = new TargetControlledPermanent(0, 1, filter, true);
            if (target.canChoose(source.getSourceId(), player.getId(), game) && player.choose(Outcome.Exile, target, source.getSourceId(), game)) {
                for (UUID targetId : target.getTargets()) {
                    if (!selectedObjects.contains(targetId)) {
                        Permanent chosen = game.getPermanent(targetId);
                        if (chosen != null) {
                            amount--;
                            game.informPlayers(player.getLogName() + " selects " + chosen.getLogName() + " from battlefield");
                            selectedObjects.add(targetId);
                        }
                    }
                }
            }
        } while (amount > 0 && !target.getTargets().isEmpty() && player.canRespond());
        if (amount > 0) {
            TargetCard targetInHand;
            do {
                FilterCard filterInHand = new FilterCard();
                filterInHand.setMessage("card from your hand (" + amount + " left in total)");
                targetInHand = new TargetCard(0, 1, Zone.HAND, filterInHand);
                List<CardIdPredicate> uuidPredicates = new ArrayList<>();
                for (UUID uuid : selectedObjects) {
                    uuidPredicates.add(new CardIdPredicate(uuid));
                }
                filterInHand.add(Predicates.not(Predicates.or(uuidPredicates)));
                if (targetInHand.canChoose(source.getSourceId(), player.getId(), game) && player.choose(Outcome.Exile, player.getHand(), targetInHand, game)) {
                    Card card = player.getHand().get(targetInHand.getFirstTarget(), game);
                    if (card != null) {
                        selectedObjects.add(targetInHand.getFirstTarget());
                        amount--;
                        cardsFromHand++;
                    }
                }
            } while (amount > 0 && !targetInHand.getTargets().isEmpty() && player.canRespond());
        }
    }
    if (cardsFromHand > 0) {
        game.informPlayers(player.getLogName() + " selects " + cardsFromHand + (cardsFromHand == 1 ? " card" : " cards") + " from their hand");
    }
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Target(mage.target.Target) UUID(java.util.UUID) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Aggregations

PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)45 Permanent (mage.game.permanent.Permanent)38 Player (mage.players.Player)26 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)24 FilterPermanent (mage.filter.FilterPermanent)19 TargetPermanent (mage.target.TargetPermanent)19 Target (mage.target.Target)17 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)17 UUID (java.util.UUID)14 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)9 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)7 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)5 MageObject (mage.MageObject)4 Predicate (mage.filter.predicate.Predicate)4 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 BecomesFaceDownCreatureAllEffect (mage.abilities.effects.common.continuous.BecomesFaceDownCreatureAllEffect)3 BoostAllEffect (mage.abilities.effects.common.continuous.BoostAllEffect)3 AbilityPredicate (mage.filter.predicate.mageobject.AbilityPredicate)3 ArrayList (java.util.ArrayList)2