Search in sources :

Example 6 with AddCountersTargetEffect

use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.

the class ShowOfDominanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int highestPower = Integer.MIN_VALUE;
        Permanent selectedCreature = null;
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
            if (highestPower < permanent.getPower().getValue()) {
                highestPower = permanent.getPower().getValue();
                selectedCreature = permanent;
            } else if (highestPower == permanent.getPower().getValue()) {
                highestPower = permanent.getPower().getValue();
                selectedCreature = null;
            }
        }
        if (highestPower != Integer.MIN_VALUE) {
            if (selectedCreature == null) {
                FilterPermanent filter = new FilterCreaturePermanent("creature with power " + highestPower);
                filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, highestPower));
                Target target = new TargetPermanent(1, 1, filter, true);
                if (controller.chooseTarget(outcome, target, source, game)) {
                    selectedCreature = game.getPermanent(target.getFirstTarget());
                }
            }
            if (selectedCreature != null) {
                FixedTarget target = new FixedTarget(selectedCreature.getId(), game);
                Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(4));
                effect.setTargetPointer(target);
                effect.apply(game, source);
                ContinuousEffect continuousEffect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
                continuousEffect.setTargetPointer(target);
                game.addEffect(continuousEffect, source);
                return true;
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 7 with AddCountersTargetEffect

use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.

the class SoulScarMageDamageReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent toGetCounters = game.getPermanent(event.getTargetId());
    if (toGetCounters != null) {
        AddCountersTargetEffect addCounters = new AddCountersTargetEffect(CounterType.M1M1.createInstance(), StaticValue.get(event.getAmount()));
        addCounters.setTargetPointer(new FixedTarget(toGetCounters.getId(), game));
        addCounters.apply(game, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 8 with AddCountersTargetEffect

use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.

the class LesserWerewolfEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    // must be valid target
    Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (controller != null && sourcePermanent != null && targetPermanent != null) {
        if (sourcePermanent.getPower().getValue() >= 1) {
            game.addEffect(new BoostSourceEffect(-1, 0, Duration.EndOfTurn), source);
            new AddCountersTargetEffect(new BoostCounter(0, -1), outcome).apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) BoostCounter(mage.counters.BoostCounter)

Example 9 with AddCountersTargetEffect

use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.

the class ServantOfTheScaleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    if (sourcePermanent != null && controller != null && (// Token
    sourcePermanent.getZoneChangeCounter(game) == source.getSourceObjectZoneChangeCounter() || sourcePermanent.getZoneChangeCounter(game) + 1 == source.getSourceObjectZoneChangeCounter())) {
        // PermanentCard
        int amount = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
        if (amount > 0) {
            Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(amount));
            effect.setTargetPointer(targetPointer);
            effect.apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Effect(mage.abilities.effects.Effect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 10 with AddCountersTargetEffect

use of mage.abilities.effects.common.counter.AddCountersTargetEffect in project mage by magefree.

the class TormentOfVenomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (targetCreature != null) {
        new AddCountersTargetEffect(CounterType.M1M1.createInstance(3)).apply(game, source);
        Player controllingPlayer = game.getPlayer(targetCreature.getControllerId());
        if (controllingPlayer != null) {
            int permanents = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_NON_LAND, controllingPlayer.getId(), game);
            if (permanents > 0 && controllingPlayer.chooseUse(outcome, "Sacrifices a nonland permanent?", "Otherwise you have to discard a card or lose 3 life.", "Sacrifice", "Discard or life loss", source, game)) {
                FilterPermanent filter = new FilterControlledPermanent("another nonland permanent");
                filter.add(Predicates.not(CardType.LAND.getPredicate()));
                filter.add(Predicates.not(new PermanentIdPredicate(targetCreature.getId())));
                Target target = new TargetPermanent(filter);
                if (controllingPlayer.choose(outcome, target, source.getSourceId(), game)) {
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        permanent.sacrifice(source, game);
                        return true;
                    }
                }
            }
            if (!controllingPlayer.getHand().isEmpty() && controllingPlayer.chooseUse(outcome, "Discard a card?", "Otherwise you lose 3 life.", "Discard", "Lose 3 life", source, game)) {
                controllingPlayer.discardOne(false, false, source, game);
                return true;
            }
            controllingPlayer.loseLife(3, game, source, false);
            return true;
        }
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Aggregations

AddCountersTargetEffect (mage.abilities.effects.common.counter.AddCountersTargetEffect)36 FixedTarget (mage.target.targetpointer.FixedTarget)27 Permanent (mage.game.permanent.Permanent)24 Effect (mage.abilities.effects.Effect)21 OneShotEffect (mage.abilities.effects.OneShotEffect)18 Player (mage.players.Player)18 Card (mage.cards.Card)7 UUID (java.util.UUID)6 ContinuousEffect (mage.abilities.effects.ContinuousEffect)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)6 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)6 Target (mage.target.Target)5 TargetPermanent (mage.target.TargetPermanent)5 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)4 Ability (mage.abilities.Ability)3 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)3 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)3