Search in sources :

Example 16 with Counter

use of mage.counters.Counter in project mage by magefree.

the class EvolutionaryEscalationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Counter counter = CounterType.P1P1.createInstance(3);
    boolean addedCounters = false;
    for (Target target : source.getTargets()) {
        Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
        if (targetPermanent != null) {
            targetPermanent.addCounters(counter.copy(), source.getControllerId(), source, game);
            addedCounters = true;
        }
    }
    return addedCounters;
}
Also used : Target(mage.target.Target) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 17 with Counter

use of mage.counters.Counter in project mage by magefree.

the class TayamLuminousEnigmaReplacementEffect method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    paid = false;
    int countersRemoved = 0;
    Player controller = game.getPlayer(controllerId);
    for (int i = 0; i < countersToRemove; i++) {
        if (target.choose(Outcome.UnboostCreature, controllerId, source.getSourceId(), game)) {
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                if (!permanent.getCounters(game).isEmpty()) {
                    String counterName = null;
                    if (permanent.getCounters(game).size() > 1) {
                        Choice choice = new ChoiceImpl(true);
                        Set<String> choices = new HashSet<>();
                        for (Counter counter : permanent.getCounters(game).values()) {
                            if (permanent.getCounters(game).getCount(counter.getName()) > 0) {
                                choices.add(counter.getName());
                            }
                        }
                        choice.setChoices(choices);
                        choice.setMessage("Choose a counter to remove from " + permanent.getLogName());
                        if (!controller.choose(Outcome.UnboostCreature, choice, game)) {
                            return false;
                        }
                        counterName = choice.getChoice();
                    } else {
                        for (Counter counter : permanent.getCounters(game).values()) {
                            if (counter.getCount() > 0) {
                                counterName = counter.getName();
                            }
                        }
                    }
                    if (counterName != null) {
                        permanent.removeCounters(counterName, 1, source, game);
                        target.clearChosen();
                        if (!game.isSimulation()) {
                            game.informPlayers(new StringBuilder(controller.getLogName()).append(" removes a ").append(counterName).append(" counter from ").append(permanent.getName()).toString());
                        }
                        countersRemoved++;
                        if (countersRemoved == countersToRemove) {
                            paid = true;
                            break;
                        }
                    }
                }
            }
        } else {
            break;
        }
    }
    return paid;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 18 with Counter

use of mage.counters.Counter in project mage by magefree.

the class ChronozoaTest method testDuplicationEffect.

/**
 * Test that the tokens are put to battlefield if the last time counter is removed
 */
@Test
public void testDuplicationEffect() {
    addCard(Zone.BATTLEFIELD, playerA, "Island", 4);
    addCard(Zone.HAND, playerA, "Chronozoa");
    castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chronozoa");
    setStopAt(9, PhaseStep.PRECOMBAT_MAIN);
    execute();
    // The original Chronozoa card should be in graveyard
    assertGraveyardCount(playerA, 1);
    final List<Permanent> creatures = currentGame.getBattlefield().getAllActivePermanents(CardType.CREATURE, currentGame);
    Assert.assertEquals(2, creatures.size());
    for (final Permanent creature : creatures) {
        // Make sure the creatures are Chronozoa tokens
        Assert.assertEquals("Chronozoa", creature.getName());
        Assert.assertEquals("Chronozoa has to be a token", true, creature instanceof PermanentToken);
        // Make sure each token has 2 time counters
        final Counters counters = creature.getCounters(currentGame);
        Assert.assertEquals(1, counters.size());
        for (final Counter counter : counters.values()) {
            Assert.assertEquals(CounterType.TIME.getName(), counter.getName());
            Assert.assertEquals(2, counter.getCount());
        }
    }
}
Also used : Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) Counters(mage.counters.Counters) Test(org.junit.Test)

Example 19 with Counter

use of mage.counters.Counter in project mage by magefree.

the class RemoveCountersAttachedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null && permanent.getAttachedTo() != null) {
        Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
        if (attachedTo != null && counter != null) {
            Counter newCounter = counter.copy();
            newCounter.add(amount.calculate(game, source, this));
            attachedTo.removeCounters(newCounter, source, game);
        }
        return true;
    }
    return false;
}
Also used : Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent)

Example 20 with Counter

use of mage.counters.Counter in project mage by magefree.

the class ClockspinningAddOrRemoveCounterEffect method selectCounterType.

private Counter selectCounterType(Game game, Ability source, Card card) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && !card.getCounters(game).isEmpty()) {
        String counterName = null;
        if (card.getCounters(game).size() > 1) {
            Choice choice = new ChoiceImpl(true);
            Set<String> choices = new HashSet<>();
            for (Counter counter : card.getCounters(game).values()) {
                if (card.getCounters(game).getCount(counter.getName()) > 0) {
                    choices.add(counter.getName());
                }
            }
            choice.setChoices(choices);
            choice.setMessage("Choose a counter type to add to " + card.getName());
            if (controller.choose(Outcome.Neutral, choice, game)) {
                counterName = choice.getChoice();
            } else {
                return null;
            }
        } else {
            for (Counter counter : card.getCounters(game).values()) {
                if (counter.getCount() > 0) {
                    counterName = counter.getName();
                }
            }
        }
        return new Counter(counterName);
    }
    return null;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Aggregations

Counter (mage.counters.Counter)49 Permanent (mage.game.permanent.Permanent)38 Player (mage.players.Player)28 Choice (mage.choices.Choice)10 ChoiceImpl (mage.choices.ChoiceImpl)10 TargetPermanent (mage.target.TargetPermanent)10 UUID (java.util.UUID)9 HashSet (java.util.HashSet)8 Counters (mage.counters.Counters)8 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)8 Card (mage.cards.Card)6 CounterType (mage.counters.CounterType)5 FilterPermanent (mage.filter.FilterPermanent)5 Target (mage.target.Target)4 TargetPermanentOrPlayer (mage.target.common.TargetPermanentOrPlayer)4 ArrayList (java.util.ArrayList)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)2 Effect (mage.abilities.effects.Effect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2