Search in sources :

Example 31 with AddCountersSourceEffect

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

the class RogueSkycaptainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && permanent != null) {
        new AddCountersSourceEffect(CounterType.WAGE.createInstance(), true).apply(game, source);
        Cost cost = ManaUtil.createManaCost(2 * permanent.getCounters(game).getCount(CounterType.WAGE), false);
        if (!cost.pay(source, game, source, controller.getId(), false)) {
            new RemoveAllCountersSourceEffect(CounterType.WAGE).apply(game, source);
            Player opponent;
            Set<UUID> opponents = game.getOpponents(controller.getId());
            if (opponents.size() == 1) {
                opponent = game.getPlayer(opponents.iterator().next());
            } else {
                Target target = new TargetOpponent(true);
                target.setNotTarget(true);
                target.choose(Outcome.GainControl, source.getControllerId(), source.getSourceId(), game);
                opponent = game.getPlayer(target.getFirstTarget());
            }
            if (opponent != null) {
                permanent.changeControllerId(opponent.getId(), game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) RemoveAllCountersSourceEffect(mage.abilities.effects.common.RemoveAllCountersSourceEffect) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost)

Example 32 with AddCountersSourceEffect

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

the class UlamogsDespoilerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetCardInExile(2, 2, filter, null);
        if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            if (controller.chooseTarget(outcome, target, source, game)) {
                Cards cardsToGraveyard = new CardsImpl(target.getTargets());
                controller.moveCards(cardsToGraveyard, Zone.GRAVEYARD, source, game);
                return new AddCountersSourceEffect(CounterType.P1P1.createInstance(4)).apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Target(mage.target.Target) TargetCardInExile(mage.target.common.TargetCardInExile) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 33 with AddCountersSourceEffect

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

the class GemstoneCavernsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result = false;
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Card card = game.getCard(source.getSourceId());
        if (card != null) {
            ContinuousEffect effect = new EntersBattlefieldEffect(new AddCountersSourceEffect(CounterType.LUCK.createInstance()), "");
            effect.setDuration(Duration.OneUse);
            game.addEffect(effect, source);
            if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                Permanent permanent = game.getPermanent(card.getId());
                if (permanent != null) {
                    Cost cost = new ExileFromHandCost(new TargetCardInHand());
                    if (cost.canPay(source, source, source.getControllerId(), game)) {
                        result = cost.pay(source, game, source, source.getControllerId(), true, null);
                    }
                }
            }
        }
    }
    return result;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) EntersBattlefieldEffect(mage.abilities.effects.EntersBattlefieldEffect) Card(mage.cards.Card)

Example 34 with AddCountersSourceEffect

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

the class MoritteOfTheFrostCopyApplier method apply.

@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
    blueprint.addSuperType(SuperType.LEGENDARY);
    blueprint.addSuperType(SuperType.SNOW);
    if (!isCopyOfCopy(source, blueprint, copyToObjectId) && blueprint.isCreature(game)) {
        blueprint.getAbilities().add(new ChangelingAbility());
        blueprint.getAbilities().add(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(2), false)));
    }
    return true;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) EntersBattlefieldAbility(mage.abilities.common.EntersBattlefieldAbility) ChangelingAbility(mage.abilities.keyword.ChangelingAbility)

Example 35 with AddCountersSourceEffect

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

the class PiousKitsuneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result;
    result = new AddCountersSourceEffect(CounterType.DEVOTION.createInstance()).apply(game, source);
    if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0) {
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
            int life = permanent.getCounters(game).getCount(CounterType.DEVOTION);
            if (life > 0) {
                Player controller = game.getPlayer(source.getControllerId());
                if (controller != null) {
                    controller.gainLife(life, game, source);
                }
            }
        }
    }
    return result;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Aggregations

AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)40 Player (mage.players.Player)21 Permanent (mage.game.permanent.Permanent)20 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)5 Cost (mage.abilities.costs.Cost)5 UUID (java.util.UUID)4 RemoveCounterSourceEffect (mage.abilities.effects.common.counter.RemoveCounterSourceEffect)4 Card (mage.cards.Card)4 ZoneChangeGroupEvent (mage.game.events.ZoneChangeGroupEvent)4 Target (mage.target.Target)4 TargetPermanent (mage.target.TargetPermanent)3 MageInt (mage.MageInt)2 Ability (mage.abilities.Ability)2 TapSourceCost (mage.abilities.costs.common.TapSourceCost)2 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)2 ManaCosts (mage.abilities.costs.mana.ManaCosts)2 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)2 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)2 FlyingAbility (mage.abilities.keyword.FlyingAbility)2 CardImpl (mage.cards.CardImpl)2