Search in sources :

Example 81 with FilterCreaturePermanent

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

the class ReinsOfPowerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID opponentId = this.getTargetPointer().getFirst(game, source);
    if (opponentId != null) {
        // Untap all creatures you control and all creatures target opponent controls.
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        filter.add(Predicates.or(new ControllerIdPredicate(source.getControllerId()), new ControllerIdPredicate(opponentId)));
        new UntapAllEffect(filter).apply(game, source);
        // You and that opponent each gain control of all creatures the other controls until end of turn.
        Set<UUID> yourCreatures = new HashSet<>();
        Set<UUID> opponentCreatures = new HashSet<>();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), source.getSourceId(), game)) {
            yourCreatures.add(permanent.getId());
        }
        FilterCreaturePermanent filterOpponent = new FilterCreaturePermanent();
        filterOpponent.add(new ControllerIdPredicate(opponentId));
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filterOpponent, source.getControllerId(), source.getSourceId(), game)) {
            opponentCreatures.add(permanent.getId());
        }
        for (UUID creatureId : yourCreatures) {
            ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn, opponentId);
            effect.setTargetPointer(new FixedTarget(creatureId, game));
            game.addEffect(effect, source);
        }
        for (UUID creatureId : opponentCreatures) {
            ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creatureId, game));
            game.addEffect(effect, source);
        }
        // Those creatures gain haste until end of turn.
        game.addEffect(new GainAbilityAllEffect(HasteAbility.getInstance(), Duration.EndOfTurn, filter), source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) UntapAllEffect(mage.abilities.effects.common.UntapAllEffect) GainAbilityAllEffect(mage.abilities.effects.common.continuous.GainAbilityAllEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) HashSet(java.util.HashSet)

Example 82 with FilterCreaturePermanent

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

the class ReinsOfTheVinesteedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card aura = game.getCard(source.getSourceId());
    if (aura != null && game.getState().getZone(aura.getId()) == Zone.GRAVEYARD) {
        Player controller = game.getPlayer(source.getControllerId());
        Permanent lastStateAura = (Permanent) game.getLastKnownInformation(aura.getId(), Zone.BATTLEFIELD);
        Permanent lastStateCreature = game.getPermanentOrLKIBattlefield(lastStateAura.getAttachedTo());
        if (lastStateCreature == null) {
            return false;
        }
        FilterPermanent FILTER = new FilterCreaturePermanent("creature that shares a creature type with " + lastStateCreature.getName());
        FILTER.add(new SharesCreatureTypePredicate(lastStateCreature));
        TargetPermanent target = new TargetPermanent(FILTER);
        target.setNotTarget(true);
        if (controller != null && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
            if (!targetPermanent.cantBeAttachedBy(aura, source, game, false)) {
                game.getState().setValue("attachTo:" + aura.getId(), targetPermanent);
                controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
                return targetPermanent.addAttachment(aura.getId(), source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) 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) TargetPermanent(mage.target.TargetPermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) TargetPermanent(mage.target.TargetPermanent) Card(mage.cards.Card)

Example 83 with FilterCreaturePermanent

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

the class RumblingRuinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int counter = 1;
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
        if (permanent == null || !permanent.isCreature(game)) {
            continue;
        }
        counter += permanent.getCounters(game).getCount(CounterType.P1P1);
    }
    FilterCreaturePermanent filter = new FilterOpponentsCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, counter));
    game.addEffect(new CantBlockAllEffect(filter, Duration.EndOfTurn), source);
    return true;
}
Also used : FilterOpponentsCreaturePermanent(mage.filter.common.FilterOpponentsCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterOpponentsCreaturePermanent(mage.filter.common.FilterOpponentsCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CantBlockAllEffect(mage.abilities.effects.common.combat.CantBlockAllEffect) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

Example 84 with FilterCreaturePermanent

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

the class RowanKenrithDamageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(TappedPredicate.TAPPED);
    filter.add(new ControllerIdPredicate(source.getFirstTarget()));
    return new DamageAllEffect(3, filter).apply(game, source);
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DamageAllEffect(mage.abilities.effects.common.DamageAllEffect)

Example 85 with FilterCreaturePermanent

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

the class SearingRaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChoiceColor choice = new ChoiceColor();
    if (controller != null && controller.choose(outcome, choice, game) && choice.getColor() != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent(choice.getColor().getDescription() + " creatures");
        filter.add(new ColorPredicate(choice.getColor()));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            int amount = game.getBattlefield().countAll(filter, playerId, game);
            if (amount > 0) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    player.damage(amount, source.getSourceId(), source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ChoiceColor(mage.choices.ChoiceColor) UUID(java.util.UUID)

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