Search in sources :

Example 26 with Counter

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

the class SupremeLeaderSnokeCounterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        int amount = new OpponentNoncombatLostLifeCount().calculate(game, source, this);
        if (amount > 0) {
            Counter counterToAdd = counter.copy();
            counterToAdd.add(amount - counter.getCount());
            permanent.addCounters(counterToAdd, source.getControllerId(), source, game);
        }
    }
    return true;
}
Also used : Counter(mage.counters.Counter) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Example 27 with Counter

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

the class TheOzolithMoveCountersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    Permanent creature = game.getPermanent(source.getFirstTarget());
    if (permanent == null || creature == null) {
        return false;
    }
    permanent.getCounters(game).copy().values().stream().filter(counter -> creature.addCounters(counter, source.getControllerId(), source, game)).forEach(counter -> permanent.removeCounters(counter, source, game));
    return true;
}
Also used : BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) StaticFilters(mage.filter.StaticFilters) Condition(mage.abilities.condition.Condition) Counters(mage.counters.Counters) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) LeavesBattlefieldAllTriggeredAbility(mage.abilities.common.LeavesBattlefieldAllTriggeredAbility) UUID(java.util.UUID) TargetController(mage.constants.TargetController) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) CardType(mage.constants.CardType) Counter(mage.counters.Counter) SuperType(mage.constants.SuperType) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Example 28 with Counter

use of mage.counters.Counter 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 29 with Counter

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

the class AetherSnapEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards tokens = new CardsImpl();
    for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getSourceId(), game)) {
        if (permanent instanceof PermanentToken) {
            tokens.add(permanent);
        }
        if (permanent.getCounters(game).isEmpty()) {
            continue;
        }
        Counters counters = permanent.getCounters(game).copy();
        for (Counter counter : counters.values()) {
            permanent.removeCounters(counter, source, game);
        }
    }
    controller.moveCards(tokens, Zone.EXILED, source, game);
    return true;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) Counters(mage.counters.Counters) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 30 with Counter

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

the class DwarvenArmorerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose type of counter to add");
        choice.setChoices(choices);
        if (controller.choose(outcome, choice, game)) {
            Counter counter = choice.getChoice().equals("+0/+1") ? CounterType.P0P1.createInstance() : CounterType.P1P0.createInstance();
            Effect effect = new AddCountersTargetEffect(counter);
            effect.setTargetPointer(new FixedTarget(this.getTargetPointer().getFirst(game, source), game));
            return effect.apply(game, source);
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) ChoiceImpl(mage.choices.ChoiceImpl) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

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