Search in sources :

Example 21 with AddCountersTargetEffect

use of mage.abilities.effects.common.counter.AddCountersTargetEffect 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 22 with AddCountersTargetEffect

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

the class EssenceFluxEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cardsToBattlefield = new CardsImpl();
        for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
            UUID mainCardId = CardUtil.getMainCardId(game, targetId);
            if (game.getExile().containsId(mainCardId, game)) {
                cardsToBattlefield.add(mainCardId);
            } else {
                Card card = game.getCard(targetId);
                if (card instanceof MeldCard) {
                    MeldCard meldCard = (MeldCard) card;
                    Card topCard = meldCard.getTopHalfCard();
                    Card bottomCard = meldCard.getBottomHalfCard();
                    if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter() && game.getExile().containsId(topCard.getId(), game)) {
                        cardsToBattlefield.add(topCard);
                    }
                    if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter() && game.getExile().containsId(bottomCard.getId(), game)) {
                        cardsToBattlefield.add(bottomCard);
                    }
                }
            }
        }
        if (!cardsToBattlefield.isEmpty()) {
            controller.moveCards(cardsToBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
            for (UUID cardId : cardsToBattlefield) {
                Permanent permanent = game.getPermanent(cardId);
                if (permanent != null && permanent.hasSubtype(SubType.SPIRIT, game)) {
                    Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance());
                    effect.setTargetPointer(new FixedTarget(permanent, game));
                    return effect.apply(game, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) 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) Effect(mage.abilities.effects.Effect) ExileTargetForSourceEffect(mage.abilities.effects.common.ExileTargetForSourceEffect) UUID(java.util.UUID) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 23 with AddCountersTargetEffect

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

the class FierceInvocationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card != null) {
            new ManifestEffect(1).apply(game, source);
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
                Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(2));
                effect.setTargetPointer(new FixedTarget(permanent, game));
                return effect.apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ManifestEffect(mage.abilities.effects.keyword.ManifestEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ManifestEffect(mage.abilities.effects.keyword.ManifestEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) Card(mage.cards.Card)

Example 24 with AddCountersTargetEffect

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

the class RakdosRiteknifeEffect method makeAbility.

private static Ability makeAbility(Permanent permanent, Game game) {
    Ability ability = new SimpleActivatedAbility(new AddCountersTargetEffect(CounterType.BLOOD.createInstance()).setText("put a blood counter on " + permanent.getName()).setTargetPointer(new FixedTarget(permanent, game)), new TapSourceCost());
    ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT)));
    return ability;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) EquipAbility(mage.abilities.keyword.EquipAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) TapSourceCost(mage.abilities.costs.common.TapSourceCost) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 25 with AddCountersTargetEffect

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

the class BolsterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (amount.calculate(game, source, this) <= 0) {
            return true;
        }
        int leastToughness = Integer.MAX_VALUE;
        Permanent selectedCreature = null;
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
            if (leastToughness > permanent.getToughness().getValue()) {
                leastToughness = permanent.getToughness().getValue();
                selectedCreature = permanent;
            } else if (leastToughness == permanent.getToughness().getValue()) {
                leastToughness = permanent.getToughness().getValue();
                selectedCreature = null;
            }
        }
        if (leastToughness != Integer.MAX_VALUE) {
            if (selectedCreature == null) {
                FilterPermanent filter = new FilterControlledCreaturePermanent("creature you control with toughness " + leastToughness);
                filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
                Target target = new TargetPermanent(1, 1, filter, true);
                if (controller.chooseTarget(outcome, target, source, game)) {
                    selectedCreature = game.getPermanent(target.getFirstTarget());
                }
            }
            if (selectedCreature != null) {
                Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(amount.calculate(game, source, this)));
                effect.setTargetPointer(new FixedTarget(selectedCreature, game));
                return effect.apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetPermanent(mage.target.TargetPermanent) 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