Search in sources :

Example 61 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class VisionCharmEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceLandType();
        if (!controller.choose(outcome, choice, game)) {
            discard();
            return;
        }
        targetLandType = choice.getChoice();
        choice = new ChoiceBasicLandType();
        if (!controller.choose(outcome, choice, game)) {
            discard();
            return;
        }
        targetBasicLandType = SubType.byDescription(choice.getChoice());
        if (targetLandType == null || targetBasicLandType == null) {
            this.discard();
            return;
        }
    } else {
        this.discard();
        return;
    }
    FilterPermanent filter = new FilterLandPermanent();
    filter.add(SubType.byDescription(targetLandType).getPredicate());
    if (this.affectedObjectsSet) {
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
            affectedObjectList.add(new MageObjectReference(permanent, game));
        }
    }
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceLandType(mage.choices.ChoiceLandType) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) ChoiceBasicLandType(mage.choices.ChoiceBasicLandType) MageObjectReference(mage.MageObjectReference)

Example 62 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class SimpleGameTest method testSimple.

@Test
public void testSimple() {
    addCard(Zone.BATTLEFIELD, playerA, "Forest");
    addCard(Zone.BATTLEFIELD, playerB, "Forest");
    addCard(Zone.BATTLEFIELD, playerC, "Forest");
    addCard(Zone.BATTLEFIELD, playerD, "Forest");
    setStopAt(1, PhaseStep.BEGIN_COMBAT);
    execute();
    assertLife(playerA, 20);
    assertLife(playerB, 20);
    assertLife(playerC, 20);
    assertLife(playerD, 20);
    FilterPermanent filterPermanent = new FilterLandPermanent();
    filterPermanent.add(SubType.FOREST.getPredicate());
    List<Permanent> forestCards = currentGame.getBattlefield().getAllActivePermanents(filterPermanent, currentGame);
    Assert.assertEquals(4, forestCards.size());
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) FilterPermanent(mage.filter.FilterPermanent) Test(org.junit.Test)

Example 63 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class ExchangeControlTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Set<UUID> toDelete = new HashSet<>();
    for (Map.Entry<UUID, Integer> entry : zoneChangeCounter.entrySet()) {
        Permanent permanent = game.getPermanent(entry.getKey());
        if (permanent == null || permanent.getZoneChangeCounter(game) != entry.getValue()) {
            // controll effect cease if the same permanent is no longer on the battlefield
            toDelete.add(entry.getKey());
            continue;
        }
        permanent.changeControllerId(lockedControllers.get(permanent.getId()), game, source);
        permanent.getAbilities().setControllerId(lockedControllers.get(permanent.getId()));
        if (destroyAttachedAuras) {
            FilterPermanent filter = new FilterPermanent();
            filter.add(SubType.AURA.getPredicate());
            for (UUID attachmentId : new HashSet<>(permanent.getAttachments())) {
                Permanent attachment = game.getPermanent(attachmentId);
                if (filter.match(attachment, game)) {
                    attachment.destroy(source, game, false);
                }
            }
        }
    }
    if (!toDelete.isEmpty()) {
        for (UUID uuid : toDelete) {
            zoneChangeCounter.remove(uuid);
        }
        if (zoneChangeCounter.isEmpty()) {
            discard();
            return false;
        }
    }
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 64 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class ArcbondEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int damage = (Integer) this.getValue("damage");
    UUID sourceId = (UUID) this.getValue("sourceId");
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && damage > 0 && sourceId != null) {
        Permanent targetObject = game.getPermanentOrLKIBattlefield(sourceId);
        if (targetObject != null) {
            game.informPlayers(sourceObject.getLogName() + ": " + targetObject.getLogName() + " deals " + damage + " damage to each other creature and each player");
        }
        FilterPermanent filter = new FilterCreaturePermanent("each other creature");
        filter.add(Predicates.not(new PermanentIdPredicate(sourceId)));
        return new DamageEverythingEffect(StaticValue.get(damage), filter, sourceId).apply(game, source);
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DamageEverythingEffect(mage.abilities.effects.common.DamageEverythingEffect) MageObject(mage.MageObject) UUID(java.util.UUID)

Example 65 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class BlastZoneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    int xValue = permanent.getCounters(game).getCount(CounterType.CHARGE);
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, xValue));
    return new DestroyAllEffect(filter).apply(game, source);
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Aggregations

FilterPermanent (mage.filter.FilterPermanent)155 Permanent (mage.game.permanent.Permanent)99 Player (mage.players.Player)99 TargetPermanent (mage.target.TargetPermanent)62 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)49 UUID (java.util.UUID)41 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)30 Target (mage.target.Target)24 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)18 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)17 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)13 FilterCard (mage.filter.FilterCard)11 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)11 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)11 CardsImpl (mage.cards.CardsImpl)10