Search in sources :

Example 1 with MageObjectReferencePredicate

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

the class ChefsKissApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getSpell(source.getFirstTarget());
    if (spell == null) {
        return false;
    }
    spell.setControllerId(source.getControllerId());
    List<UUID> possibleTargets = new ArrayList<>(game.getState().getPlayersInRange(source.getControllerId(), game));
    possibleTargets.remove(source.getControllerId());
    game.getBattlefield().getActivePermanents(source.getControllerId(), game).stream().filter(p -> !p.isControlledBy(source.getControllerId())).map(MageItem::getId).forEach(possibleTargets::add);
    possibleTargets.removeIf(uuid -> !spell.canTarget(game, uuid));
    StackObjectCopyApplier applier;
    MageObjectReferencePredicate predicate;
    if (possibleTargets.isEmpty()) {
        applier = null;
        predicate = null;
    } else {
        applier = new ChefsKissApplier(possibleTargets.get(RandomUtil.nextInt(possibleTargets.size())), game);
        predicate = new MageObjectReferencePredicate(new MageObjectReference(possibleTargets.get(RandomUtil.nextInt(possibleTargets.size())), game));
    }
    spell.createCopyOnStack(game, source, source.getControllerId(), false, 1, applier);
    if (predicate != null) {
        spell.chooseNewTargets(game, source.getControllerId(), true, true, predicate);
    }
    return true;
}
Also used : MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) StackObjectCopyApplier(mage.util.functions.StackObjectCopyApplier) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) MageObjectReference(mage.MageObjectReference)

Example 2 with MageObjectReferencePredicate

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

the class ColfenorTheLastYewTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!super.checkTrigger(event, game)) {
        return false;
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    Permanent permanent = zEvent.getTarget();
    if (permanent == null) {
        return false;
    }
    FilterCard filterCard = new FilterCreatureCard("creature card with toughness less than " + permanent.getToughness().getValue());
    filterCard.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, permanent.getToughness().getValue()));
    filterCard.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(permanent, game))));
    this.getTargets().clear();
    this.addTarget(new TargetCardInYourGraveyard(0, 1, filterCard));
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) MageObjectReference(mage.MageObjectReference)

Example 3 with MageObjectReferencePredicate

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

the class ToralfsHammerEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedEvent dEvent = (DamagedEvent) event;
    if (dEvent.getExcess() < 1 || dEvent.isCombatDamage() || !game.getOpponents(getControllerId()).contains(game.getControllerId(event.getTargetId()))) {
        return false;
    }
    this.getEffects().clear();
    this.getTargets().clear();
    this.addEffect(new DamageTargetEffect(dEvent.getExcess()));
    FilterCreaturePlayerOrPlaneswalker filter = new FilterCreaturePlayerOrPlaneswalker();
    filter.getPermanentFilter().add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(event.getTargetId(), game))));
    this.addTarget(new TargetAnyTarget(filter));
    return true;
}
Also used : DamagedEvent(mage.game.events.DamagedEvent) FilterCreaturePlayerOrPlaneswalker(mage.filter.common.FilterCreaturePlayerOrPlaneswalker) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) MageObjectReference(mage.MageObjectReference) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Example 4 with MageObjectReferencePredicate

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

the class ExhilaratingElocutionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    permanent.addCounters(CounterType.P1P1.createInstance(2), source.getControllerId(), source, game);
    FilterCreaturePermanent filterPermanent = new FilterCreaturePermanent();
    filterPermanent.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(permanent, game))));
    game.addEffect(new BoostControlledEffect(1, 1, Duration.EndOfTurn, filterPermanent), source);
    return true;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) BoostControlledEffect(mage.abilities.effects.common.continuous.BoostControlledEffect) MageObjectReference(mage.MageObjectReference)

Example 5 with MageObjectReferencePredicate

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

the class HandOfVecnaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getHand().size() < 1) {
        return false;
    }
    Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
    Permanent equipped = game.getPermanent(sourcePermanent != null ? sourcePermanent.getAttachedTo() : null);
    List<Permanent> chooseable = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
    if (equipped != null) {
        chooseable.add(equipped);
    }
    Permanent toBoost;
    switch(chooseable.size()) {
        case 0:
            return false;
        case 1:
            toBoost = chooseable.get(0);
            break;
        default:
            FilterPermanent filter = new FilterPermanent("a creature to give +X/+X to");
            filter.add(Predicates.or(chooseable.stream().map(permanent -> new MageObjectReferencePredicate(permanent, game)).collect(Collectors.toList())));
            TargetPermanent target = new TargetPermanent(filter);
            target.setNotTarget(true);
            player.choose(outcome, target, source.getSourceId(), game);
            toBoost = game.getPermanent(target.getFirstTarget());
    }
    int xValue = player.getHand().size();
    game.addEffect(new BoostTargetEffect(xValue, xValue, Duration.EndOfTurn).setTargetPointer(new FixedTarget(toBoost, game)), source);
    return true;
}
Also used : BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) CardsInControllerHandCount(mage.abilities.dynamicvalue.common.CardsInControllerHandCount) PayLifeCost(mage.abilities.costs.common.PayLifeCost) EquipAbility(mage.abilities.keyword.EquipAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) TargetPermanent(mage.target.TargetPermanent)

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