Search in sources :

Example 41 with Counter

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

the class EntersBattlefieldWithXCountersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        if (source.getAbilityType() == AbilityType.STATIC) {
            permanent = game.getPermanentEntering(source.getSourceId());
        }
    }
    if (permanent != null) {
        SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
        if (spellAbility != null && spellAbility.getSourceId().equals(source.getSourceId()) && permanent.getZoneChangeCounter(game) == spellAbility.getSourceObjectZoneChangeCounter()) {
            if (spellAbility.getSourceId().equals(source.getSourceId())) {
                // put into play by normal cast
                int amount = spellAbility.getManaCostsToPay().getX();
                if (amount > 0) {
                    Counter counterToAdd = counter.copy();
                    counterToAdd.add(amount - counter.getCount());
                    List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
                    permanent.addCounters(counterToAdd, source.getControllerId(), source, game, appliedEffects);
                }
            }
        }
    }
    return true;
}
Also used : Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) SpellAbility(mage.abilities.SpellAbility) UUID(java.util.UUID)

Example 42 with Counter

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

the class ProliferateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Counter newCounter = null;
    if (controller == null) {
        return false;
    }
    Target target = new TargetPermanentOrPlayer(0, Integer.MAX_VALUE, new FilterPermanentOrPlayerWithCounter(), true);
    Map<String, Serializable> options = new HashMap<>();
    options.put("UI.right.btn.text", "Done");
    controller.choose(Outcome.Benefit, target, source.getSourceId(), game, options);
    for (UUID chosen : target.getTargets()) {
        Permanent permanent = game.getPermanent(chosen);
        if (permanent != null) {
            if (!permanent.getCounters(game).isEmpty()) {
                for (Counter counter : permanent.getCounters(game).values()) {
                    newCounter = new Counter(counter.getName());
                    permanent.addCounters(newCounter, source.getControllerId(), source, game);
                }
                if (newCounter != null) {
                    game.informPlayers(permanent.getName() + " had 1 " + newCounter.getName() + " counter added to it.");
                }
            }
        } else {
            Player player = game.getPlayer(chosen);
            if (player != null) {
                if (!player.getCounters().isEmpty()) {
                    for (Counter counter : player.getCounters().values()) {
                        newCounter = new Counter(counter.getName());
                        player.addCounters(newCounter, source.getControllerId(), source, game);
                    }
                    if (newCounter != null) {
                        game.informPlayers(player.getLogName() + " had 1 " + newCounter.getName() + " counter added to them.");
                    }
                }
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) Target(mage.target.Target) Serializable(java.io.Serializable) FilterPermanentOrPlayerWithCounter(mage.filter.common.FilterPermanentOrPlayerWithCounter) Counter(mage.counters.Counter) TargetPermanentOrPlayer(mage.target.common.TargetPermanentOrPlayer) Permanent(mage.game.permanent.Permanent) HashMap(java.util.HashMap) FilterPermanentOrPlayerWithCounter(mage.filter.common.FilterPermanentOrPlayerWithCounter) UUID(java.util.UUID)

Example 43 with Counter

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

the class AddCountersAttachedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null && permanent.getAttachedTo() != null) {
        Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
        if (attachedTo != null && counter != null) {
            Counter newCounter = counter.copy();
            int countersToAdd = amount.calculate(game, source, this);
            if (countersToAdd > 0) {
                countersToAdd--;
                newCounter.add(countersToAdd);
                attachedTo.addCounters(newCounter, source.getControllerId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent)

Example 44 with Counter

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

the class ElspethConquersDeathReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(source.getFirstTarget());
    if (player == null || card == null) {
        return false;
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game);
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent == null) {
        return false;
    }
    Counter counter = player.chooseUse(outcome, "Choose a type of counter to add", null, "+1/+1", "Loyalty", source, game) ? CounterType.P1P1.createInstance() : CounterType.LOYALTY.createInstance();
    permanent.addCounters(counter, source.getControllerId(), source, game);
    return true;
}
Also used : Player(mage.players.Player) Counter(mage.counters.Counter) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 45 with Counter

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

the class GrimdancerEffect 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;
    }
    Choice choice = new ChoiceImpl(true);
    choice.setMessage("Choose two abilities");
    choice.setChoices(choices);
    if (!player.choose(outcome, choice, game)) {
        return false;
    }
    Counter counter1 = null;
    Counter counter2 = null;
    switch(choice.getChoice()) {
        case "Menace and deathtouch":
            counter1 = CounterType.MENACE.createInstance();
            counter2 = CounterType.DEATHTOUCH.createInstance();
            break;
        case "Menace and lifelink":
            counter1 = CounterType.MENACE.createInstance();
            counter2 = CounterType.LIFELINK.createInstance();
            break;
        case "Deathtouch and lifelink":
            counter1 = CounterType.DEATHTOUCH.createInstance();
            counter2 = CounterType.LIFELINK.createInstance();
            break;
    }
    permanent.addCounters(counter1, source.getControllerId(), source, game);
    permanent.addCounters(counter2, source.getControllerId(), source, game);
    return true;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) ChoiceImpl(mage.choices.ChoiceImpl)

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