Search in sources :

Example 1 with BlockedByIdPredicate

use of mage.filter.predicate.permanent.BlockedByIdPredicate in project mage by magefree.

the class WallOfVaporEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (super.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0) {
        DamageEvent damageEvent = (DamageEvent) event;
        if (event.getTargetId().equals(source.getSourceId())) {
            Permanent permanent = game.getPermanentOrLKIBattlefield(damageEvent.getSourceId());
            FilterCreaturePermanent filter = new FilterCreaturePermanent();
            filter.add(new BlockedByIdPredicate(source.getSourceId()));
            if (permanent != null && filter.match(permanent, game)) {
                return true;
            }
        }
    }
    return false;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DamageEvent(mage.game.events.DamageEvent) BlockedByIdPredicate(mage.filter.predicate.permanent.BlockedByIdPredicate)

Example 2 with BlockedByIdPredicate

use of mage.filter.predicate.permanent.BlockedByIdPredicate in project mage by magefree.

the class WallOfShadowsEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!super.applies(event, source, game) || !(event instanceof DamageEvent) || event.getAmount() <= 0) {
        return false;
    }
    DamageEvent damageEvent = (DamageEvent) event;
    if (!event.getTargetId().equals(source.getSourceId())) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(damageEvent.getSourceId());
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new BlockedByIdPredicate(source.getSourceId()));
    return permanent != null && filter.match(permanent, game);
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) DamageEvent(mage.game.events.DamageEvent) BlockedByIdPredicate(mage.filter.predicate.permanent.BlockedByIdPredicate)

Example 3 with BlockedByIdPredicate

use of mage.filter.predicate.permanent.BlockedByIdPredicate in project mage by magefree.

the class GreaterWerewolfEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourcePermanent != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        filter.add(Predicates.or(new BlockedByIdPredicate(sourcePermanent.getId()), new BlockingAttackerIdPredicate(sourcePermanent.getId())));
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
            Effect effect = new AddCountersTargetEffect(CounterType.M0M2.createInstance(), Outcome.UnboostCreature);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            effect.apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BlockingAttackerIdPredicate(mage.filter.predicate.permanent.BlockingAttackerIdPredicate) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) BlockedByIdPredicate(mage.filter.predicate.permanent.BlockedByIdPredicate)

Example 4 with BlockedByIdPredicate

use of mage.filter.predicate.permanent.BlockedByIdPredicate in project mage by magefree.

the class SpittingSlugEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourcePermanent != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        filter.add(Predicates.or(new BlockedByIdPredicate(sourcePermanent.getId()), new BlockingAttackerIdPredicate(sourcePermanent.getId())));
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) {
            ContinuousEffect effect = new GainAbilityTargetEffect(FirstStrikeAbility.getInstance(), Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BlockingAttackerIdPredicate(mage.filter.predicate.permanent.BlockingAttackerIdPredicate) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) BlockedByIdPredicate(mage.filter.predicate.permanent.BlockedByIdPredicate)

Example 5 with BlockedByIdPredicate

use of mage.filter.predicate.permanent.BlockedByIdPredicate in project mage by magefree.

the class SereneMasterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourceCreature = game.getPermanent(source.getSourceId());
    if (controller != null && sourceCreature != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature it's blocking");
        filter.add(new BlockedByIdPredicate((source.getSourceId())));
        Target target = new TargetCreaturePermanent(filter);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            if (controller.chooseTarget(outcome, target, source, game)) {
                Permanent attackingCreature = game.getPermanent(target.getFirstTarget());
                if (attackingCreature != null) {
                    int newSourcePower = attackingCreature.getPower().getValue();
                    int newAttackerPower = sourceCreature.getPower().getValue();
                    ContinuousEffect effect = new SetPowerToughnessTargetEffect(newSourcePower, sourceCreature.getToughness().getValue(), Duration.EndOfCombat);
                    effect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
                    game.addEffect(effect, source);
                    effect = new SetPowerToughnessTargetEffect(newAttackerPower, attackingCreature.getToughness().getValue(), Duration.EndOfCombat);
                    effect.setTargetPointer(new FixedTarget(attackingCreature.getId(), game));
                    game.addEffect(effect, source);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SetPowerToughnessTargetEffect(mage.abilities.effects.common.continuous.SetPowerToughnessTargetEffect) BlockedByIdPredicate(mage.filter.predicate.permanent.BlockedByIdPredicate)

Aggregations

FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 BlockedByIdPredicate (mage.filter.predicate.permanent.BlockedByIdPredicate)5 Permanent (mage.game.permanent.Permanent)5 FixedTarget (mage.target.targetpointer.FixedTarget)3 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 BlockingAttackerIdPredicate (mage.filter.predicate.permanent.BlockingAttackerIdPredicate)2 DamageEvent (mage.game.events.DamageEvent)2 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)1 SetPowerToughnessTargetEffect (mage.abilities.effects.common.continuous.SetPowerToughnessTargetEffect)1 AddCountersTargetEffect (mage.abilities.effects.common.counter.AddCountersTargetEffect)1 FilterPermanent (mage.filter.FilterPermanent)1 Player (mage.players.Player)1 Target (mage.target.Target)1 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)1