Search in sources :

Example 6 with Counter

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

the class FateTransferEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creatureToMoveCountersFrom = game.getPermanent(source.getTargets().get(0).getFirstTarget());
    Permanent creatureToMoveCountersTo = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (creatureToMoveCountersFrom != null && creatureToMoveCountersTo != null) {
        Permanent copyCreature = creatureToMoveCountersFrom.copy();
        for (Counter counter : copyCreature.getCounters(game).values()) {
            creatureToMoveCountersFrom.removeCounters(counter, source, game);
            creatureToMoveCountersTo.addCounters(counter, source.getControllerId(), source, game);
        }
        return true;
    }
    return false;
}
Also used : Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Example 7 with Counter

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

the class GilderBairnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent target = game.getPermanent(source.getFirstTarget());
    if (target != null) {
        for (Counter counter : target.getCounters(game).values()) {
            Counter newCounter = new Counter(counter.getName(), counter.getCount());
            target.addCounters(newCounter, source.getControllerId(), source, game);
        }
    }
    return false;
}
Also used : Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent)

Example 8 with Counter

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

the class PartingThoughtsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (permanent != null) {
            permanent.destroy(source, game, false);
            int numberOfCounters = 0;
            for (Counter counter : permanent.getCounters(game).values()) {
                numberOfCounters += counter.getCount();
            }
            if (numberOfCounters > 0) {
                controller.drawCards(numberOfCounters, source, game);
                controller.loseLife(numberOfCounters, game, source, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Example 9 with Counter

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

the class AddCounterChoiceSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (player == null || permanent == null) {
        return false;
    }
    Counter counter;
    if (player.chooseUse(Outcome.Neutral, "Choose " + counterType1 + " or " + counterType2, null, cap(counterType1.getName()), cap(counterType2.getName()), source, game)) {
        counter = counterType1.createInstance();
    } else {
        counter = counterType2.createInstance();
    }
    return permanent.addCounters(counter, source.getControllerId(), source, game);
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent)

Example 10 with Counter

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

the class AddCountersSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (putOnCard) {
            Card card = game.getCard(source.getSourceId());
            if (card != null) {
                if (counter != null) {
                    Counter newCounter = counter.copy();
                    int countersToAdd = amount.calculate(game, source, this);
                    if (countersToAdd > 0 && newCounter.getCount() == 1) {
                        countersToAdd--;
                    }
                    newCounter.add(countersToAdd);
                    List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
                    card.addCounters(newCounter, source.getControllerId(), source, game, appliedEffects);
                    if (informPlayers && !game.isSimulation()) {
                        Player player = game.getPlayer(source.getControllerId());
                        if (player != null) {
                            game.informPlayers(player.getLogName() + " puts " + newCounter.getCount() + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + card.getLogName());
                        }
                    }
                }
                return true;
            }
        } else {
            Permanent permanent = game.getPermanent(source.getSourceId());
            if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
                permanent = game.getPermanentEntering(source.getSourceId());
            }
            if (permanent != null && (// from static ability
            source.getSourceObjectZoneChangeCounter() == 0 || source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game))) {
                // prevent to add counters to later source objects
                if (counter != null) {
                    Counter newCounter = counter.copy();
                    int countersToAdd = amount.calculate(game, source, this);
                    if (amount instanceof StaticValue || countersToAdd > 0) {
                        if (countersToAdd > 0 && newCounter.getCount() == 1) {
                            countersToAdd--;
                        }
                        newCounter.add(countersToAdd);
                        int before = permanent.getCounters(game).getCount(newCounter.getName());
                        List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
                        // if used from a replacement effect, the basic event determines if an effect was already applied to an event
                        permanent.addCounters(newCounter, source.getControllerId(), source, game, appliedEffects);
                        if (informPlayers && !game.isSimulation()) {
                            int amountAdded = permanent.getCounters(game).getCount(newCounter.getName()) - before;
                            Player player = game.getPlayer(source.getControllerId());
                            if (player != null) {
                                game.informPlayers(player.getLogName() + " puts " + amountAdded + ' ' + newCounter.getName().toLowerCase(Locale.ENGLISH) + " counter on " + permanent.getLogName());
                            }
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) StaticValue(mage.abilities.dynamicvalue.common.StaticValue) UUID(java.util.UUID) Card(mage.cards.Card)

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