Search in sources :

Example 21 with Counter

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

the class ClockspinningAddOrRemoveCounterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (player != null && permanent != null) {
        if (player.chooseUse(Outcome.Neutral, "Remove a counter?", source, game)) {
            RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect();
            effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
            effect.apply(game, source);
        } else {
            Counter counter = selectCounterType(game, source, permanent);
            if (counter != null) {
                AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
                effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
                effect.apply(game, source);
            }
        }
        return true;
    }
    Card card = game.getCard(source.getFirstTarget());
    if (player != null && card != null) {
        if (player.chooseUse(Outcome.Neutral, "Remove a counter?", source, game)) {
            Counter counter = selectCounterType(game, source, card);
            RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect(counter);
            effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
            effect.apply(game, source);
        } else {
            Counter counter = selectCounterType(game, source, card);
            if (counter != null) {
                AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
                effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
                effect.apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) RemoveCounterTargetEffect(mage.abilities.effects.common.counter.RemoveCounterTargetEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) TargetPermanentOrSuspendedCard(mage.target.common.TargetPermanentOrSuspendedCard) Card(mage.cards.Card)

Example 22 with Counter

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

the class NestingGroundsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent fromPermanent = game.getPermanent(source.getFirstTarget());
    Permanent toPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (fromPermanent == null || toPermanent == null || controller == null) {
        return false;
    }
    Set<String> possibleChoices = new HashSet<>(fromPermanent.getCounters(game).keySet());
    if (possibleChoices.size() == 0) {
        return false;
    }
    Choice choice = new ChoiceImpl();
    choice.setChoices(possibleChoices);
    if (controller.choose(outcome, choice, game)) {
        String chosen = choice.getChoice();
        if (fromPermanent.getCounters(game).containsKey(chosen)) {
            CounterType counterType = CounterType.findByName(chosen);
            if (counterType != null) {
                Counter counter = counterType.createInstance();
                fromPermanent.removeCounters(counterType.getName(), 1, source, game);
                toPermanent.addCounters(counter, source.getControllerId(), source, game);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) CounterType(mage.counters.CounterType) Counter(mage.counters.Counter) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 23 with Counter

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

the class QuarryHaulerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller == null || permanent == null) {
        return false;
    }
    List<String> counterNames = permanent.getCounters(game).values().stream().map(Counter::getName).collect(Collectors.toList());
    for (String counterName : counterNames) {
        Counter newCounter = CounterType.findByName(counterName).createInstance();
        if (controller.chooseUse(Outcome.BoostCreature, "Add or remove a " + counterName + " counter?", null, "Add", "Remove", source, game)) {
            permanent.addCounters(newCounter, source.getControllerId(), source, game);
        } else {
            permanent.removeCounters(newCounter, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent)

Example 24 with Counter

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

the class StrengthOfTheTajuruAddCountersTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int affectedTargets = 0;
    int amount = source.getManaCostsToPay().getX();
    Counter counter = CounterType.P1P1.createInstance(amount);
    for (UUID uuid : targetPointer.getTargets(game, source)) {
        Permanent permanent = game.getPermanent(uuid);
        if (permanent != null) {
            permanent.addCounters(counter.copy(), source.getControllerId(), source, game);
            affectedTargets++;
        }
    }
    return affectedTargets > 0;
}
Also used : Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) UUID(java.util.UUID)

Example 25 with Counter

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

the class AsLuckWouldHaveItEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (controller != null && permanent != null) {
        if (getValue("rolled") != null) {
            int amount = (Integer) getValue("rolled");
            permanent.addCounters(new Counter("luck", amount), source.getControllerId(), source, game);
            if (permanent.getCounters(game).getCount("luck") >= 100) {
                Player player = game.getPlayer(permanent.getControllerId());
                if (player != null) {
                    player.won(game);
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent)

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