Search in sources :

Example 11 with MageObjectReferencePredicate

use of mage.filter.predicate.mageobject.MageObjectReferencePredicate in project mage by magefree.

the class RadiantPerformerEffect method prepareCopiesWithTargets.

@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
    List<MageObjectReferencePredicate> predicates = new ArrayList<>();
    Ability ability = stackObject instanceof Spell ? ((Spell) stackObject).getSpellAbility() : (StackAbility) stackObject;
    UUID targeted = ability == null ? null : ability.getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).findAny().orElse(null);
    game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, player.getId(), source.getSourceId(), game).stream().filter(Objects::nonNull).filter(p -> !p.equals(game.getPermanent(targeted))).filter(p -> stackObject.canTarget(game, p.getId())).map(p -> new MageObjectReference(p, game)).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    game.getState().getPlayersInRange(source.getControllerId(), game).stream().filter(uuid -> !uuid.equals(targeted)).filter(uuid -> stackObject.canTarget(game, uuid)).map(MageObjectReference::new).map(MageObjectReferencePredicate::new).forEach(predicates::add);
    return predicates;
}
Also used : EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) StackAbility(mage.game.stack.StackAbility) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) Ability(mage.abilities.Ability) Target(mage.target.Target) java.util(java.util) CopySpellForEachItCouldTargetEffect(mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect) TargetStackObject(mage.target.TargetStackObject) Predicate(mage.filter.predicate.Predicate) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) CastFromHandSourcePermanentCondition(mage.abilities.condition.common.CastFromHandSourcePermanentCondition) SubType(mage.constants.SubType) Mode(mage.abilities.Mode) Player(mage.players.Player) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) StaticFilters(mage.filter.StaticFilters) FilterStackObject(mage.filter.FilterStackObject) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) StackAbility(mage.game.stack.StackAbility) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) CastFromHandWatcher(mage.watchers.common.CastFromHandWatcher) Ability(mage.abilities.Ability) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 12 with MageObjectReferencePredicate

use of mage.filter.predicate.mageobject.MageObjectReferencePredicate in project mage by magefree.

the class MoorlandRescuerTarget method makeFilter.

private static FilterCard makeFilter(int xValue, Ability source, Game game) {
    FilterCard filter = new FilterCreatureCard("creature cards with total power " + xValue + " or less from your graveyard");
    filter.add(Predicates.not(new MageObjectReferencePredicate(source.getSourceObject(game), game)));
    return filter;
}
Also used : FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate)

Example 13 with MageObjectReferencePredicate

use of mage.filter.predicate.mageobject.MageObjectReferencePredicate in project mage by magefree.

the class CopySpellForEachItCouldTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player actingPlayer = getPlayer(game, source);
    StackObject stackObject = getStackObject(game, source);
    if (actingPlayer == null || stackObject == null) {
        return false;
    }
    List<MageObjectReferencePredicate> copies = prepareCopiesWithTargets(stackObject, actingPlayer, source, game);
    stackObject.createCopyOnStack(game, source, actingPlayer.getId(), false, copies.size(), new ForEachCopyApplier(copies));
    return true;
}
Also used : Player(mage.players.Player) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) StackObject(mage.game.stack.StackObject)

Example 14 with MageObjectReferencePredicate

use of mage.filter.predicate.mageobject.MageObjectReferencePredicate in project mage by magefree.

the class CrownOfFuryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // Enchanted creature ...
    ContinuousEffect effect = new BoostEnchantedEffect(1, 0, Duration.EndOfTurn);
    game.addEffect(effect, source);
    effect = new GainAbilityAttachedEffect(FirstStrikeAbility.getInstance(), AttachmentType.AURA, Duration.EndOfTurn);
    game.addEffect(effect, source);
    // ... and other creatures that share a creature type with it ...
    Permanent enchantedCreature = game.getPermanent(source.getSourcePermanentOrLKI(game).getAttachedTo());
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new CrownOfFuryPredicate(enchantedCreature));
    filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(enchantedCreature, game))));
    game.addEffect(new BoostAllEffect(1, 0, Duration.EndOfTurn, filter, false), source);
    game.addEffect(new GainAbilityAllEffect(FirstStrikeAbility.getInstance(), Duration.EndOfTurn, filter), source);
    // ... get +1/+0 and gain first strike until end of turn.
    return true;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) BoostEnchantedEffect(mage.abilities.effects.common.continuous.BoostEnchantedEffect) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) GainAbilityAttachedEffect(mage.abilities.effects.common.continuous.GainAbilityAttachedEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect) GainAbilityAllEffect(mage.abilities.effects.common.continuous.GainAbilityAllEffect) MageObjectReference(mage.MageObjectReference)

Example 15 with MageObjectReferencePredicate

use of mage.filter.predicate.mageobject.MageObjectReferencePredicate in project mage by magefree.

the class CrownOfAweEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // Enchanted creature
    ContinuousEffect effect = new GainAbilityAttachedEffect(ProtectionAbility.from(ObjectColor.BLACK, ObjectColor.RED), AttachmentType.AURA, Duration.EndOfTurn);
    game.addEffect(effect, source);
    // and other creatures that share a creature type with it
    Permanent enchantedCreature = game.getPermanent(source.getSourcePermanentOrLKI(game).getAttachedTo());
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new CrownOfAwePredicate(enchantedCreature));
    filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(enchantedCreature, game))));
    game.addEffect(effect, source);
    // have protection from black and from red until end of turn.
    return true;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) GainAbilityAttachedEffect(mage.abilities.effects.common.continuous.GainAbilityAttachedEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) MageObjectReference(mage.MageObjectReference)

Aggregations

MageObjectReferencePredicate (mage.filter.predicate.mageobject.MageObjectReferencePredicate)15 MageObjectReference (mage.MageObjectReference)11 Permanent (mage.game.permanent.Permanent)7 Player (mage.players.Player)6 TargetPermanent (mage.target.TargetPermanent)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 FilterPermanent (mage.filter.FilterPermanent)4 Spell (mage.game.stack.Spell)4 Ability (mage.abilities.Ability)3 CardImpl (mage.cards.CardImpl)3 CardSetInfo (mage.cards.CardSetInfo)3 Game (mage.game.Game)3 StackObject (mage.game.stack.StackObject)3 Target (mage.target.Target)3 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)3 java.util (java.util)2 Mode (mage.abilities.Mode)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 CopySpellForEachItCouldTargetEffect (mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect)2 GainAbilityAttachedEffect (mage.abilities.effects.common.continuous.GainAbilityAttachedEffect)2