Search in sources :

Example 71 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class DwarvenCatapultEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int howMany = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getFirstTarget(), game).size();
    int amount = source.getManaCostsToPay().getX() / howMany;
    DamageAllControlledTargetEffect dmgEffect = new DamageAllControlledTargetEffect(amount, new FilterCreaturePermanent());
    return dmgEffect.apply(game, source);
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DamageAllControlledTargetEffect(mage.abilities.effects.common.DamageAllControlledTargetEffect)

Example 72 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class DuneblastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetCreaturePermanent(0, 1, new FilterCreaturePermanent("creature to keep"), true);
        target.setRequired(true);
        Permanent creatureToKeep = null;
        if (controller.choose(outcome, target, source.getSourceId(), game)) {
            creatureToKeep = game.getPermanent(target.getFirstTarget());
        }
        for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), source.getSourceId(), game)) {
            if (!Objects.equals(creature, creatureToKeep)) {
                creature.destroy(source, game, false);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Example 73 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class InfernalDenizenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature = game.getPermanent(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        DynamicValue swamps = new PermanentsOnBattlefieldCount(filter);
        boolean canSac = swamps.calculate(game, source, this) > 1;
        Effect effect = new SacrificeControllerEffect(filter, 2, "Sacrifice two Swamps");
        effect.apply(game, source);
        if (!canSac) {
            if (creature != null) {
                creature.tap(source, game);
            }
            TargetOpponent targetOpp = new TargetOpponent(true);
            if (targetOpp.canChoose(source.getSourceId(), player.getId(), game) && targetOpp.choose(Outcome.Detriment, player.getId(), source.getSourceId(), game)) {
                Player opponent = game.getPlayer(targetOpp.getFirstTarget());
                if (opponent != null) {
                    FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creature controlled by " + player.getLogName());
                    filter2.add(new ControllerIdPredicate(player.getId()));
                    TargetCreaturePermanent targetCreature = new TargetCreaturePermanent(1, 1, filter2, true);
                    targetCreature.setTargetController(opponent.getId());
                    if (targetCreature.canChoose(source.getSourceId(), id, game) && opponent.chooseUse(Outcome.GainControl, "Gain control of a creature?", source, game) && opponent.chooseTarget(Outcome.GainControl, targetCreature, source, game)) {
                        ConditionalContinuousEffect giveEffect = new ConditionalContinuousEffect(new GainControlTargetEffect(Duration.Custom, true, opponent.getId()), SourceOnBattlefieldCondition.instance, "");
                        giveEffect.setTargetPointer(new FixedTarget(targetCreature.getFirstTarget(), game));
                        game.addEffect(giveEffect, source);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ConditionalContinuousEffect(mage.abilities.decorator.ConditionalContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) SacrificeControllerEffect(mage.abilities.effects.common.SacrificeControllerEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) SacrificeControllerEffect(mage.abilities.effects.common.SacrificeControllerEffect) ConditionalContinuousEffect(mage.abilities.decorator.ConditionalContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) DynamicValue(mage.abilities.dynamicvalue.DynamicValue)

Example 74 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class LastOneStandingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Permanent> creatureList = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game);
    if (creatureList.size() < 2) {
        return true;
    }
    int toSave = RandomUtil.nextInt(creatureList.size());
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(Predicates.not(new PermanentIdPredicate(creatureList.get(toSave).getId())));
    return new DestroyAllEffect(filter).apply(game, source);
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 75 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class MisfortuneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player chosenOpponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller != null && chosenOpponent != null) {
        if (chosenOpponent.chooseUse(Outcome.Neutral, "If you choose Yes, the controller puts a +1/+1 counter" + "on each creature they control and they gain 4 life. If no, the controller puts a -1/-1 counter" + "on each creature you control and {this} deals 4 damage to you.", source, game)) {
            Effect putP1P1CounterOnEachControlledCreature = new AddCountersAllEffect(CounterType.P1P1.createInstance(), new FilterControlledCreaturePermanent());
            putP1P1CounterOnEachControlledCreature.apply(game, source);
            controller.gainLife(4, game, source);
        } else {
            FilterCreaturePermanent filterOpponentCreatures = new FilterCreaturePermanent();
            filterOpponentCreatures.add(new ControllerIdPredicate(chosenOpponent.getId()));
            Effect putM1M1CounterOnEachOpponentCreature = new AddCountersAllEffect(CounterType.M1M1.createInstance(), filterOpponentCreatures);
            putM1M1CounterOnEachOpponentCreature.apply(game, source);
            chosenOpponent.damage(4, source.getSourceId(), source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) OneShotEffect(mage.abilities.effects.OneShotEffect) AddCountersAllEffect(mage.abilities.effects.common.counter.AddCountersAllEffect) Effect(mage.abilities.effects.Effect) AddCountersAllEffect(mage.abilities.effects.common.counter.AddCountersAllEffect)

Aggregations

FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)187 Player (mage.players.Player)125 Permanent (mage.game.permanent.Permanent)108 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)83 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)67 UUID (java.util.UUID)55 TargetPermanent (mage.target.TargetPermanent)32 Target (mage.target.Target)31 FilterPermanent (mage.filter.FilterPermanent)27 FixedTarget (mage.target.targetpointer.FixedTarget)25 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)23 ContinuousEffect (mage.abilities.effects.ContinuousEffect)22 MageObject (mage.MageObject)16 PowerPredicate (mage.filter.predicate.mageobject.PowerPredicate)16 OneShotEffect (mage.abilities.effects.OneShotEffect)14 Effect (mage.abilities.effects.Effect)13 Choice (mage.choices.Choice)13 TargetPlayer (mage.target.TargetPlayer)13 Card (mage.cards.Card)12 ChoiceCreatureType (mage.choices.ChoiceCreatureType)12