Search in sources :

Example 6 with MageObjectReferencePredicate

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

the class FarrelsMantleDamageEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent aura = getSourcePermanentOrLKI(game);
    if (aura == null || !event.getTargetId().equals(aura.getAttachedTo()) || game.getPermanent(aura.getAttachedTo()) == null) {
        return false;
    }
    MageObjectReference mor = new MageObjectReference(event.getTargetId(), game);
    FilterPermanent filter = new FilterCreaturePermanent();
    filter.add(Predicates.not(new MageObjectReferencePredicate(mor)));
    TargetPermanent target = new TargetPermanent(filter);
    target.setTargetController(game.getControllerId(event.getTargetId()));
    this.getTargets().clear();
    this.addTarget(target);
    this.getEffects().clear();
    this.addEffect(new FarrelsMantleEffect(mor));
    return true;
}
Also used : 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) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetPermanent(mage.target.TargetPermanent) MageObjectReference(mage.MageObjectReference)

Example 7 with MageObjectReferencePredicate

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

the class OrvarTheAllFormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Spell spell = (Spell) this.getValue("spellCast");
    if (player == null || spell == null) {
        return false;
    }
    List<Predicate<Permanent>> predicates = spell.getSpellAbility().getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).map(MageItem::getId).map(PermanentIdPredicate::new).collect(Collectors.toList());
    if (predicates.isEmpty()) {
        return false;
    }
    FilterPermanent filter = new FilterControlledPermanent("a permanent you control targeted by that spell");
    filter.add(Predicates.or(predicates));
    filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(source))));
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    return new CreateTokenCopyTargetEffect().setTargetPointer(new FixedTarget(target.getFirstTarget(), game)).apply(game, source);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Mode(mage.abilities.Mode) MageItem(mage.MageItem) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Spell(mage.game.stack.Spell) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Predicate(mage.filter.predicate.Predicate) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetPermanent(mage.target.TargetPermanent) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) MageObjectReference(mage.MageObjectReference)

Example 8 with MageObjectReferencePredicate

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

the class StackObjectImpl method createCopyOnStack.

@Override
public void createCopyOnStack(Game game, Ability source, UUID newControllerId, boolean chooseNewTargets, int amount, StackObjectCopyApplier applier) {
    GameEvent gameEvent = new CopyStackObjectEvent(source, this, newControllerId, amount);
    if (game.replaceEvent(gameEvent)) {
        return;
    }
    Iterator<MageObjectReferencePredicate> newTargetTypeIterator = new NewTargetTypeIterator(game, newControllerId, gameEvent.getAmount(), applier);
    for (int i = 0; i < gameEvent.getAmount(); i++) {
        createSingleCopy(newControllerId, applier, newTargetTypeIterator.next(), game, source, chooseNewTargets);
    }
    Player player = game.getPlayer(newControllerId);
    if (player == null) {
        return;
    }
    game.informPlayers(player.getName() + " created " + CardUtil.numberToText(gameEvent.getAmount(), "a") + " cop" + (gameEvent.getAmount() == 1 ? "y" : "ies") + " of " + getIdName());
}
Also used : Player(mage.players.Player) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) GameEvent(mage.game.events.GameEvent) CopyStackObjectEvent(mage.game.events.CopyStackObjectEvent)

Example 9 with MageObjectReferencePredicate

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

the class MindlinkMechApplier method makeFilter.

public static FilterPermanent makeFilter(Ability source, Game game) {
    Set<MageObjectReferencePredicate> predicates = game.getState().getWatcher(MindlinkMechWatcher.class).crewMap.computeIfAbsent(new MageObjectReference(source), x -> new HashSet<>()).stream().filter(mor -> {
        Permanent permanent = mor.getPermanent(game);
        return permanent != null && !permanent.isLegendary() && permanent.isCreature(game);
    }).map(MageObjectReferencePredicate::new).collect(Collectors.toSet());
    if (predicates.isEmpty()) {
        return invalidFilter;
    }
    FilterPermanent filterPermanent = new FilterPermanent("nonlegendary creature that crewed " + CardUtil.getSourceName(game, source) + " this turn");
    filterPermanent.add(Predicates.or(predicates));
    return filterPermanent;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) MageObjectReference(mage.MageObjectReference)

Example 10 with MageObjectReferencePredicate

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

the class RadiateEffect method prepareCopiesWithTargets.

@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
    List<MageObjectReferencePredicate> predicates = new ArrayList<>();
    UUID targeted = ((Spell) stackObject).getSpellAbilities().stream().map(AbilityImpl::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 : Target(mage.target.Target) StaticFilters(mage.filter.StaticFilters) java.util(java.util) CopySpellForEachItCouldTargetEffect(mage.abilities.effects.common.CopySpellForEachItCouldTargetEffect) TargetAddress(mage.util.TargetAddress) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) FilterInstantOrSorcerySpell(mage.filter.common.FilterInstantOrSorcerySpell) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) FilterSpell(mage.filter.FilterSpell) Game(mage.game.Game) AbilityImpl(mage.abilities.AbilityImpl) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) ObjectSourcePlayerPredicate(mage.filter.predicate.ObjectSourcePlayerPredicate) Ability(mage.abilities.Ability) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetSpell(mage.target.TargetSpell) AbilityImpl(mage.abilities.AbilityImpl) Target(mage.target.Target) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) FilterInstantOrSorcerySpell(mage.filter.common.FilterInstantOrSorcerySpell) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) 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