Search in sources :

Example 1 with RemoveCountersSourceCost

use of mage.abilities.costs.common.RemoveCountersSourceCost in project mage by magefree.

the class TetravusPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (player == null || permanent == null) {
        return false;
    }
    int countersToRemove = permanent.getCounters(game).getCount(CounterType.P1P1);
    if (countersToRemove == 0) {
        return false;
    }
    countersToRemove = player.getAmount(0, countersToRemove, "Choose an amount of counters to remove", game);
    Cost cost = new RemoveCountersSourceCost(CounterType.P1P1.createInstance(countersToRemove));
    if (cost.pay(source, game, source, source.getControllerId(), true)) {
        CreateTokenEffect effect = new CreateTokenEffect(new TetraviteToken(), countersToRemove);
        effect.apply(game, source);
        Object object = game.getState().getValue(CardUtil.getObjectZoneString("_tokensCreated", permanent, game));
        Set<UUID> tokensCreated;
        if (object != null) {
            tokensCreated = (Set<UUID>) object;
        } else {
            tokensCreated = new HashSet<>();
        }
        for (UUID tokenId : effect.getLastAddedTokenIds()) {
            if (tokenId != null) {
                tokensCreated.add(tokenId);
            }
        }
        game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated);
    }
    return false;
}
Also used : Player(mage.players.Player) RemoveCountersSourceCost(mage.abilities.costs.common.RemoveCountersSourceCost) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) TetraviteToken(mage.game.permanent.token.TetraviteToken) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) ExileTargetCost(mage.abilities.costs.common.ExileTargetCost) RemoveCountersSourceCost(mage.abilities.costs.common.RemoveCountersSourceCost)

Example 2 with RemoveCountersSourceCost

use of mage.abilities.costs.common.RemoveCountersSourceCost in project mage by magefree.

the class KappaTechWreckerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent filter = new FilterArtifactOrEnchantmentPermanent("artifact or enchantment that player controls");
    filter.add(new ControllerIdPredicate(getTargetPointer().getFirst(game, source)));
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new ExileTargetEffect(), false);
    ability.addTarget(new TargetPermanent(filter));
    return new DoWhenCostPaid(ability, new RemoveCountersSourceCost(CounterType.DEATHTOUCH.createInstance()), "Remove a deathtouch counter?").apply(game, source);
}
Also used : FilterPermanent(mage.filter.FilterPermanent) RemoveCountersSourceCost(mage.abilities.costs.common.RemoveCountersSourceCost) DoWhenCostPaid(mage.abilities.effects.common.DoWhenCostPaid) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) FilterArtifactOrEnchantmentPermanent(mage.filter.common.FilterArtifactOrEnchantmentPermanent) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Aggregations

RemoveCountersSourceCost (mage.abilities.costs.common.RemoveCountersSourceCost)2 UUID (java.util.UUID)1 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)1 Cost (mage.abilities.costs.Cost)1 ExileTargetCost (mage.abilities.costs.common.ExileTargetCost)1 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)1 DoWhenCostPaid (mage.abilities.effects.common.DoWhenCostPaid)1 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)1 FilterPermanent (mage.filter.FilterPermanent)1 FilterArtifactOrEnchantmentPermanent (mage.filter.common.FilterArtifactOrEnchantmentPermanent)1 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)1 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)1 Permanent (mage.game.permanent.Permanent)1 TetraviteToken (mage.game.permanent.token.TetraviteToken)1 Player (mage.players.Player)1 TargetPermanent (mage.target.TargetPermanent)1 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)1