Search in sources :

Example 16 with Counters

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

the class CrystallineGiantEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        return false;
    }
    Counters counters = permanent.getCounters(game);
    List<CounterType> counterTypes = new ArrayList();
    counterTypes.addAll(counterTypeSet);
    counterTypes.removeIf(counters::containsKey);
    if (counterTypes.isEmpty()) {
        return true;
    }
    return permanent.addCounters(counterTypes.get(RandomUtil.nextInt(counterTypes.size())).createInstance(), source.getControllerId(), source, game);
}
Also used : CounterType(mage.counters.CounterType) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) Counters(mage.counters.Counters)

Example 17 with Counters

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

the class BogardanPhoenixEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (permanent == null || controller == null || permanent.getZoneChangeCounter(game) + 1 != source.getSourceObjectZoneChangeCounter()) {
        return false;
    }
    Card card = game.getCard(permanent.getId());
    if (card == null || card.getZoneChangeCounter(game) != source.getSourceObjectZoneChangeCounter()) {
        return false;
    }
    if (permanent.getCounters(game).containsKey(CounterType.DEATH)) {
        return controller.moveCards(card, Zone.EXILED, source, game);
    } else {
        Counters countersToAdd = new Counters();
        countersToAdd.addCounter(CounterType.DEATH.createInstance());
        game.setEnterWithCounters(source.getSourceId(), countersToAdd);
        return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    }
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) 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