Search in sources :

Example 6 with PermanentIdPredicate

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

the class NecromancyChangeAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent enchantment = game.getPermanent(source.getSourceId());
    Card cardInGraveyard = game.getCard(getTargetPointer().getFirst(game, source));
    if (controller != null && enchantment != null && cardInGraveyard != null) {
        controller.moveCards(cardInGraveyard, Zone.BATTLEFIELD, source, game);
        Permanent enchantedCreature = game.getPermanent(cardInGraveyard.getId());
        if (enchantedCreature != null) {
            enchantedCreature.addAttachment(enchantment.getId(), source, game);
            FilterCreaturePermanent filter = new FilterCreaturePermanent("enchant creature put onto the battlefield with " + enchantment.getIdName());
            filter.add(new PermanentIdPredicate(cardInGraveyard.getId()));
            Target target = new TargetCreaturePermanent(filter);
            target.addTarget(enchantedCreature.getId(), source, game);
            game.addEffect(new NecromancyChangeAbilityEffect(target), source);
        }
        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)

Example 7 with PermanentIdPredicate

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

the class SasayasEssenceManaEffect method getNetMana.

@Override
public List<Mana> getNetMana(Game game, Ability source) {
    List<Mana> netMana = new ArrayList<>();
    Player controller = game.getPlayer(source.getControllerId());
    Mana producedMana = (Mana) this.getValue("mana");
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null && producedMana != 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) {
            if (producedMana.getBlack() > 0) {
                netMana.add(Mana.BlackMana(count));
            }
            if (producedMana.getRed() > 0) {
                netMana.add(Mana.RedMana(count));
            }
            if (producedMana.getBlue() > 0) {
                netMana.add(Mana.BlueMana(count));
            }
            if (producedMana.getGreen() > 0) {
                netMana.add(Mana.GreenMana(count));
            }
            if (producedMana.getWhite() > 0) {
                netMana.add(Mana.WhiteMana(count));
            }
            if (producedMana.getColorless() > 0) {
                netMana.add(Mana.ColorlessMana(count));
            }
        }
    }
    return netMana;
}
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) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) ArrayList(java.util.ArrayList)

Example 8 with PermanentIdPredicate

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

the class SeverTheBloodlineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (controller != null && targetPermanent != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        if (CardUtil.haveEmptyName(targetPermanent)) {
            // if no name (face down creature) only the creature itself is selected
            filter.add(new PermanentIdPredicate(targetPermanent.getId()));
        } else {
            filter.add(new NamePredicate(targetPermanent.getName()));
        }
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            controller.moveCardToExileWithInfo(permanent, null, "", source, game, Zone.BATTLEFIELD, true);
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Example 9 with PermanentIdPredicate

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

the class TormentOfVenomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (targetCreature != null) {
        new AddCountersTargetEffect(CounterType.M1M1.createInstance(3)).apply(game, source);
        Player controllingPlayer = game.getPlayer(targetCreature.getControllerId());
        if (controllingPlayer != null) {
            int permanents = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_NON_LAND, controllingPlayer.getId(), game);
            if (permanents > 0 && controllingPlayer.chooseUse(outcome, "Sacrifices a nonland permanent?", "Otherwise you have to discard a card or lose 3 life.", "Sacrifice", "Discard or life loss", source, game)) {
                FilterPermanent filter = new FilterControlledPermanent("another nonland permanent");
                filter.add(Predicates.not(CardType.LAND.getPredicate()));
                filter.add(Predicates.not(new PermanentIdPredicate(targetCreature.getId())));
                Target target = new TargetPermanent(filter);
                if (controllingPlayer.choose(outcome, target, source.getSourceId(), game)) {
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        permanent.sacrifice(source, game);
                        return true;
                    }
                }
            }
            if (!controllingPlayer.getHand().isEmpty() && controllingPlayer.chooseUse(outcome, "Discard a card?", "Otherwise you lose 3 life.", "Discard", "Lose 3 life", source, game)) {
                controllingPlayer.discardOne(false, false, source, game);
                return true;
            }
            controllingPlayer.loseLife(3, game, source, false);
            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) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 10 with PermanentIdPredicate

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

the class CyclopeanTombCounterWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObjectReference mor = new MageObjectReference(source.getSourceId(), source.getSourceObjectZoneChangeCounter(), game);
    CyclopeanTombCounterWatcher watcher = game.getState().getWatcher(CyclopeanTombCounterWatcher.class);
    if (controller != null && watcher != null) {
        Set<MageObjectReference> landRef = watcher.landMiredByCyclopeanTombInstance(mor, game);
        if (landRef == null || landRef.isEmpty()) {
            // no lands got mire counter from that instance
            return true;
        }
        FilterLandPermanent filter = new FilterLandPermanent("a land with a mire counter added from the Cyclopean Tomb instance (" + landRef.size() + " left)");
        Set<PermanentIdPredicate> idPref = new HashSet<>();
        for (MageObjectReference ref : landRef) {
            Permanent land = ref.getPermanent(game);
            if (land != null) {
                idPref.add(new PermanentIdPredicate(land.getId()));
            }
        }
        filter.add(Predicates.or(idPref));
        TargetLandPermanent target = new TargetLandPermanent(1, 1, filter, true);
        /*Player must choose a land each upkeep. Using the message are above the player hand where frequent interactions
             * take place is the most logical way to prompt for this scenario. A new constructor added to provide a not optional
             * option for any cards like this where the player must choose a target in such the way this card requires.
             */
        if (controller.chooseTarget(Outcome.Neutral, target, source, game)) {
            Permanent chosenLand = game.getPermanent(target.getFirstTarget());
            if (chosenLand != null) {
                Effect effect = new RemoveAllCountersTargetEffect(CounterType.MIRE);
                effect.setTargetPointer(new FixedTarget(chosenLand, game));
                effect.apply(game, source);
                landRef.remove(new MageObjectReference(chosenLand, game));
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) RemoveAllCountersTargetEffect(mage.abilities.effects.common.counter.RemoveAllCountersTargetEffect) BecomesBasicLandTargetEffect(mage.abilities.effects.common.continuous.BecomesBasicLandTargetEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetLandPermanent(mage.target.common.TargetLandPermanent) RemoveAllCountersTargetEffect(mage.abilities.effects.common.counter.RemoveAllCountersTargetEffect) MageObjectReference(mage.MageObjectReference)

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