Search in sources :

Example 31 with Counter

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

the class FlayEssenceEffect 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) {
        int life = 0;
        for (Counter counter : permanent.getCounters(game).values()) {
            life += counter.getCount();
        }
        controller.moveCards(permanent, Zone.EXILED, source, game);
        controller.gainLife(life, game, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent)

Example 32 with Counter

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

the class LeechBonderEffect 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) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 33 with Counter

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

the class SunburstEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    if (permanent != null) {
        int countersAmount = amount.calculate(game, source, this);
        if (countersAmount > 0) {
            Counter counter;
            if (permanent.isCreature(game)) {
                counter = CounterType.P1P1.createInstance(countersAmount);
            } else {
                counter = CounterType.CHARGE.createInstance(countersAmount);
            }
            // the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
            List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
            permanent.addCounters(counter, source.getControllerId(), source, game, appliedEffects);
            if (!game.isSimulation()) {
                Player player = game.getPlayer(source.getControllerId());
                if (player != null) {
                    game.informPlayers(player.getLogName() + " puts " + counter.getCount() + ' ' + counter.getName() + " counter on " + permanent.getName());
                }
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 34 with Counter

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

the class CardImpl method addCounters.

public boolean addCounters(Counter counter, UUID playerAddingCounters, Ability source, Game game, List<UUID> appliedEffects, boolean isEffect, int maxCounters) {
    boolean returnCode = true;
    GameEvent addingAllEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTERS, objectId, source, playerAddingCounters, counter.getName(), counter.getCount());
    addingAllEvent.setAppliedEffects(appliedEffects);
    addingAllEvent.setFlag(isEffect);
    if (!game.replaceEvent(addingAllEvent)) {
        int amount;
        if (maxCounters < Integer.MAX_VALUE) {
            amount = Integer.min(addingAllEvent.getAmount(), maxCounters - this.getCounters(game).getCount(counter.getName()));
        } else {
            amount = addingAllEvent.getAmount();
        }
        boolean isEffectFlag = addingAllEvent.getFlag();
        int finalAmount = amount;
        for (int i = 0; i < amount; i++) {
            Counter eventCounter = counter.copy();
            eventCounter.remove(eventCounter.getCount() - 1);
            GameEvent addingOneEvent = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, source, playerAddingCounters, counter.getName(), 1);
            addingOneEvent.setAppliedEffects(appliedEffects);
            addingOneEvent.setFlag(isEffectFlag);
            if (!game.replaceEvent(addingOneEvent)) {
                getCounters(game).addCounter(eventCounter);
                GameEvent addedOneEvent = GameEvent.getEvent(GameEvent.EventType.COUNTER_ADDED, objectId, source, playerAddingCounters, counter.getName(), 1);
                addedOneEvent.setFlag(addingOneEvent.getFlag());
                game.fireEvent(addedOneEvent);
            } else {
                finalAmount--;
                returnCode = false;
            }
        }
        if (finalAmount > 0) {
            GameEvent addedAllEvent = GameEvent.getEvent(GameEvent.EventType.COUNTERS_ADDED, objectId, source, playerAddingCounters, counter.getName(), amount);
            addedAllEvent.setFlag(isEffectFlag);
            game.fireEvent(addedAllEvent);
        }
    } else {
        returnCode = false;
    }
    return returnCode;
}
Also used : Counter(mage.counters.Counter)

Example 35 with Counter

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

the class PermanentImpl method getValue.

@Override
public String getValue(GameState state) {
    StringBuilder sb = threadLocalBuilder.get();
    sb.append(controllerId).append(getName()).append(tapped).append(damage);
    sb.append(subtype).append(supertype).append(power.getValue()).append(toughness.getValue());
    sb.append(abilities.getValue());
    for (Counter counter : getCounters(state).values()) {
        sb.append(counter.getName()).append(counter.getCount());
    }
    return sb.toString();
}
Also used : Counter(mage.counters.Counter) ThreadLocalStringBuilder(mage.util.ThreadLocalStringBuilder)

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