Search in sources :

Example 41 with PermanentIdPredicate

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

the class CloudstoneCurioEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent triggeringCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
        if (triggeringCreature != null) {
            FilterPermanent filter = new FilterPermanent("another permanent you control that shares a permanent type with " + triggeringCreature.getName());
            filter.add(Predicates.not(new PermanentIdPredicate(triggeringCreature.getId())));
            filter.add(TargetController.YOU.getControllerPredicate());
            filter.add(Predicates.or(triggeringCreature.getCardType(game).stream().filter(CardType::isPermanentType).map(CardType::getPredicate).collect(Collectors.toSet())));
            TargetPermanent target = new TargetPermanent(1, 1, filter, true);
            if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
                Permanent returningCreature = game.getPermanent(target.getFirstTarget());
                if (returningCreature != null) {
                    controller.moveCards(returningCreature, Zone.HAND, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 42 with PermanentIdPredicate

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

the class CrownOfTheAgesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent aura = game.getPermanent(source.getFirstTarget());
    if (aura == null) {
        return false;
    }
    Permanent fromPermanent = game.getPermanent(aura.getAttachedTo());
    Player controller = game.getPlayer(source.getControllerId());
    if (fromPermanent == null || controller == null) {
        return false;
    }
    boolean passed = true;
    FilterCreaturePermanent filterChoice = new FilterCreaturePermanent("another creature");
    filterChoice.add(Predicates.not(new PermanentIdPredicate(fromPermanent.getId())));
    Target chosenCreatureToAttachAura = new TargetPermanent(filterChoice);
    chosenCreatureToAttachAura.setNotTarget(true);
    if (chosenCreatureToAttachAura.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.Neutral, chosenCreatureToAttachAura, source.getSourceId(), game)) {
        Permanent creatureToAttachAura = game.getPermanent(chosenCreatureToAttachAura.getFirstTarget());
        if (creatureToAttachAura != null) {
            if (passed) {
                // Check the target filter
                Target target = aura.getSpellAbility().getTargets().get(0);
                if (target instanceof TargetPermanent) {
                    if (!target.getFilter().match(creatureToAttachAura, game)) {
                        passed = false;
                    }
                }
                // Check for protection
                MageObject auraObject = game.getObject(aura.getId());
                if (auraObject != null && creatureToAttachAura.cantBeAttachedBy(auraObject, source, game, true)) {
                    passed = false;
                }
            }
            if (passed) {
                fromPermanent.removeAttachment(aura.getId(), source, game);
                creatureToAttachAura.addAttachment(aura.getId(), source, game);
                return true;
            }
        }
    }
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterEnchantmentPermanent(mage.filter.common.FilterEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) MageObject(mage.MageObject) TargetPermanent(mage.target.TargetPermanent)

Example 43 with PermanentIdPredicate

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

the class ArmoryAutomatonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (player != null && sourcePermanent != null) {
        // dynamic filter (can't selects own attaches and can't selects twice)
        FilterPermanent currentFilter = new FilterEquipmentPermanent();
        FilterPermanent filterSourceId = new FilterPermanent();
        filterSourceId.add(new CardIdPredicate(source.getSourceId()));
        currentFilter.add(Predicates.not(new AttachedToPredicate(filterSourceId)));
        int countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
        while (player.canRespond() && countBattlefield > 0 && player.chooseUse(Outcome.Benefit, "Select and attach a target Equipment?", source, game)) {
            Target targetEquipment = new TargetPermanent(currentFilter);
            targetEquipment.setRequired(false);
            if (player.choose(Outcome.Benefit, targetEquipment, source.getSourceId(), game) && targetEquipment.getFirstTarget() != null) {
                // exclude selected for next time
                currentFilter.add(Predicates.not(new PermanentIdPredicate(targetEquipment.getFirstTarget())));
                Permanent aura = game.getPermanent(targetEquipment.getFirstTarget());
                if (aura != null) {
                    Permanent attachedTo = game.getPermanent(aura.getAttachedTo());
                    if (attachedTo != null) {
                        attachedTo.removeAttachment(aura.getId(), source, game);
                    }
                    sourcePermanent.addAttachment(aura.getId(), source, game);
                }
            } else {
                break;
            }
            countBattlefield = game.getBattlefield().getAllActivePermanents(currentFilter, game).size();
        }
        return true;
    }
    return false;
}
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) FilterEquipmentPermanent(mage.filter.common.FilterEquipmentPermanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetPermanent(mage.target.TargetPermanent) FilterEquipmentPermanent(mage.filter.common.FilterEquipmentPermanent) AttachedToPredicate(mage.filter.predicate.permanent.AttachedToPredicate) TargetPermanent(mage.target.TargetPermanent) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 44 with PermanentIdPredicate

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

the class BackslideEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Predicate pred = new PermanentIdPredicate(UUID.randomUUID());
    for (Target target : source.getTargets()) {
        for (UUID targetId : target.getTargets()) {
            pred = Predicates.or(pred, new PermanentIdPredicate(targetId));
        }
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(pred);
    game.addEffect(new BecomesFaceDownCreatureAllEffect(filter), source);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BecomesFaceDownCreatureAllEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureAllEffect) UUID(java.util.UUID) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Predicate(mage.filter.predicate.Predicate) AbilityPredicate(mage.filter.predicate.mageobject.AbilityPredicate)

Example 45 with PermanentIdPredicate

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

the class DanceOfTheDeadDoIfCostPaidEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent enchantment = game.getPermanent(source.getSourceId());
    if (controller != null && enchantment != null) {
        Card cardInGraveyard = game.getCard(enchantment.getAttachedTo());
        if (cardInGraveyard == null) {
            return true;
        }
        // put card into play
        controller.moveCards(cardInGraveyard, Zone.BATTLEFIELD, source, game, true, false, false, null);
        Permanent enchantedCreature = game.getPermanent(cardInGraveyard.getId());
        FilterCreaturePermanent filter = new FilterCreaturePermanent("enchant creature put onto the battlefield with Dance of the Dead");
        filter.add(new PermanentIdPredicate(cardInGraveyard.getId()));
        Target target = new TargetCreaturePermanent(filter);
        // enchantAbility.setTargetName(target.getTargetName());
        if (enchantedCreature != null) {
            target.addTarget(enchantedCreature.getId(), source, game);
            enchantment.getSpellAbility().getTargets().clear();
            enchantment.getSpellAbility().getTargets().add(target);
            enchantedCreature.addAttachment(enchantment.getId(), source, game);
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

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