Search in sources :

Example 1 with Counters

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

the class MaulfistRevolutionaryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (player != null) {
            Counters counters = player.getCounters().copy();
            for (Counter counter : counters.values()) {
                CounterType counterType = CounterType.findByName(counter.getName());
                Counter counterToAdd;
                if (counterType != null) {
                    counterToAdd = counterType.createInstance();
                } else {
                    counterToAdd = new Counter(counter.getName());
                }
                player.addCounters(counterToAdd, source.getControllerId(), source, game);
            }
            return true;
        }
        Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (permanent != null) {
            Counters counters = permanent.getCounters(game).copy();
            for (Counter counter : counters.values()) {
                CounterType counterType = CounterType.findByName(counter.getName());
                Counter counterToAdd;
                if (counterType != null) {
                    counterToAdd = counterType.createInstance();
                } else {
                    counterToAdd = new Counter(counter.getName());
                }
                permanent.addCounters(counterToAdd, source.getControllerId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) Counter(mage.counters.Counter) CounterType(mage.counters.CounterType) Permanent(mage.game.permanent.Permanent) Counters(mage.counters.Counters)

Example 2 with Counters

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

the class SkyshipPlundererEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (player != null) {
            Counters counters = player.getCounters().copy();
            for (Counter counter : counters.values()) {
                CounterType counterType = CounterType.findByName(counter.getName());
                Counter counterToAdd;
                if (counterType != null) {
                    counterToAdd = counterType.createInstance();
                } else {
                    counterToAdd = new Counter(counter.getName());
                }
                player.addCounters(counterToAdd, source.getControllerId(), source, game);
            }
            return true;
        }
        Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (permanent != null) {
            Counters counters = permanent.getCounters(game).copy();
            for (Counter counter : counters.values()) {
                CounterType counterType = CounterType.findByName(counter.getName());
                Counter counterToAdd;
                if (counterType != null) {
                    counterToAdd = counterType.createInstance();
                } else {
                    counterToAdd = new Counter(counter.getName());
                }
                permanent.addCounters(counterToAdd, source.getControllerId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) Counter(mage.counters.Counter) CounterType(mage.counters.CounterType) Permanent(mage.game.permanent.Permanent) Counters(mage.counters.Counters)

Example 3 with Counters

use of mage.counters.Counters 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 4 with Counters

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

the class ThiefOfBloodEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int countersRemoved = 0;
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
        Counters counters = permanent.getCounters(game).copy();
        for (Counter counter : counters.values()) {
            permanent.removeCounters(counter.getName(), counter.getCount(), source, game);
            countersRemoved += counter.getCount();
        }
    }
    if (countersRemoved > 0) {
        Permanent sourcePermanent = game.getPermanentEntering(source.getSourceId());
        if (sourcePermanent != null) {
            sourcePermanent.addCounters(CounterType.P1P1.createInstance(countersRemoved), source.getControllerId(), source, game);
        }
    }
    return true;
}
Also used : Counter(mage.counters.Counter) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) Counters(mage.counters.Counters)

Example 5 with Counters

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

the class UnholyIndentureReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // copy from ReturnToBattlefieldUnderYourControlAttachedEffect
    Object object = getValue("attachedTo");
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && object instanceof Permanent && !(object instanceof PermanentToken)) {
        // not token
        Card card = game.getCard(((Permanent) object).getId());
        // Move the card only, if it is still in the next zone after the battlefield
        if (card != null && card.getZoneChangeCounter(game) == ((Permanent) object).getZoneChangeCounter(game) + 1) {
            Counters countersToAdd = new Counters();
            countersToAdd.addCounter(CounterType.P1P1.createInstance());
            game.setEnterWithCounters(card.getId(), countersToAdd);
            controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, false, null);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PermanentToken(mage.game.permanent.PermanentToken) Counters(mage.counters.Counters) Card(mage.cards.Card)

Aggregations

Counters (mage.counters.Counters)17 Permanent (mage.game.permanent.Permanent)13 Player (mage.players.Player)10 Counter (mage.counters.Counter)7 Card (mage.cards.Card)5 CounterType (mage.counters.CounterType)4 TargetPermanent (mage.target.TargetPermanent)4 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 PermanentToken (mage.game.permanent.PermanentToken)3 UUID (java.util.UUID)2 Effect (mage.abilities.effects.Effect)2 FilterPermanent (mage.filter.FilterPermanent)2 TargetPermanentOrPlayer (mage.target.common.TargetPermanentOrPlayer)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1