Search in sources :

Example 36 with AddCountersSourceEffect

use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.

the class WoodlandChampionTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeGroupEvent zEvent = (ZoneChangeGroupEvent) event;
    if (zEvent != null && Zone.BATTLEFIELD == zEvent.getToZone() && zEvent.getTokens() != null) {
        int tokenCount = zEvent.getTokens().stream().mapToInt(card -> card.isControlledBy(this.getControllerId()) ? 1 : 0).sum();
        if (tokenCount > 0) {
            this.getEffects().clear();
            this.addEffect(new AddCountersSourceEffect(CounterType.P1P1.createInstance(tokenCount)));
            return true;
        }
    }
    return false;
}
Also used : Zone(mage.constants.Zone) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) ZoneChangeGroupEvent(mage.game.events.ZoneChangeGroupEvent) CounterType(mage.counters.CounterType) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) ZoneChangeGroupEvent(mage.game.events.ZoneChangeGroupEvent)

Example 37 with AddCountersSourceEffect

use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.

the class HeroOfBretagardTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeGroupEvent zEvent = (ZoneChangeGroupEvent) event;
    final int numberExiled = zEvent.getCards().size() + zEvent.getTokens().size();
    if (zEvent.getToZone() != Zone.EXILED || numberExiled == 0) {
        return false;
    }
    switch(zEvent.getFromZone()) {
        case BATTLEFIELD:
            if (controllerId.equals(zEvent.getSource().getControllerId()) && numberExiled > 0) {
                // must include both card permanents and tokens on the battlefield
                this.getEffects().clear();
                this.getEffects().add(new AddCountersSourceEffect(CounterType.P1P1.createInstance(numberExiled)));
                return true;
            }
        case HAND:
            if (zEvent.getCards().stream().filter(Objects::nonNull).map(Card::getOwnerId).anyMatch(this::isControlledBy) && numberExiled > 0) {
                this.getEffects().clear();
                this.getEffects().add(new AddCountersSourceEffect(CounterType.P1P1.createInstance(numberExiled)));
                return true;
            }
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) ZoneChangeGroupEvent(mage.game.events.ZoneChangeGroupEvent) Card(mage.cards.Card)

Example 38 with AddCountersSourceEffect

use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.

the class BecomesRenownedSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null && source instanceof RenownAbility) {
        game.informPlayers(permanent.getLogName() + " is now renowned");
        int renownValue = ((RenownAbility) source).getRenownValue();
        // handle renown = X
        if (renownValue == Integer.MAX_VALUE) {
            renownValue = source.getManaCostsToPay().getX();
        }
        new AddCountersSourceEffect(CounterType.P1P1.createInstance(renownValue), true).apply(game, source);
        permanent.setRenowned(true);
        game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BECOMES_RENOWNED, source.getSourceId(), source, source.getControllerId(), renownValue));
        return true;
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Permanent(mage.game.permanent.Permanent)

Example 39 with AddCountersSourceEffect

use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.

the class ChaoticGooEffect 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 (controller.flipCoin(source, game, true)) {
            game.informPlayers("Chaotic Goo: Won flip. Put a +1/+1 counter on Chaotic Goo.");
            new AddCountersSourceEffect(CounterType.P1P1.createInstance(1)).apply(game, source);
            return true;
        } else {
            game.informPlayers("Chaotic Goo: Lost flip. Remove a +1/+1 counter on Chaotic Goo.");
            new RemoveCounterSourceEffect(CounterType.P1P1.createInstance(1)).apply(game, source);
            return true;
        }
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) RemoveCounterSourceEffect(mage.abilities.effects.common.counter.RemoveCounterSourceEffect)

Example 40 with AddCountersSourceEffect

use of mage.abilities.effects.common.counter.AddCountersSourceEffect in project mage by magefree.

the class BountyOfTheLuxaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent bountyOfLuxa = game.getPermanent(source.getSourceId());
    if (bountyOfLuxa != null && bountyOfLuxa.getZoneChangeCounter(game) != source.getSourceObjectZoneChangeCounter()) {
        bountyOfLuxa = null;
    }
    if (controller != null) {
        if (bountyOfLuxa != null && bountyOfLuxa.getCounters(game).getCount(CounterType.FLOOD) > 0) {
            bountyOfLuxa.removeCounters(CounterType.FLOOD.createInstance(bountyOfLuxa.getCounters(game).getCount(CounterType.FLOOD)), source, game);
            if (bountyOfLuxa.getCounters(game).getCount(CounterType.FLOOD) == 0) {
                Mana manaToAdd = new Mana();
                manaToAdd.increaseColorless();
                manaToAdd.increaseGreen();
                manaToAdd.increaseBlue();
                controller.getManaPool().addMana(manaToAdd, game, source);
            }
        } else {
            if (bountyOfLuxa != null) {
                new AddCountersSourceEffect(CounterType.FLOOD.createInstance()).apply(game, source);
            }
            controller.drawCards(1, source, game);
        }
        return true;
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Mana(mage.Mana) Permanent(mage.game.permanent.Permanent)

Aggregations

AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)40 Player (mage.players.Player)21 Permanent (mage.game.permanent.Permanent)20 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)5 Cost (mage.abilities.costs.Cost)5 UUID (java.util.UUID)4 RemoveCounterSourceEffect (mage.abilities.effects.common.counter.RemoveCounterSourceEffect)4 Card (mage.cards.Card)4 ZoneChangeGroupEvent (mage.game.events.ZoneChangeGroupEvent)4 Target (mage.target.Target)4 TargetPermanent (mage.target.TargetPermanent)3 MageInt (mage.MageInt)2 Ability (mage.abilities.Ability)2 TapSourceCost (mage.abilities.costs.common.TapSourceCost)2 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)2 ManaCosts (mage.abilities.costs.mana.ManaCosts)2 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)2 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)2 FlyingAbility (mage.abilities.keyword.FlyingAbility)2 CardImpl (mage.cards.CardImpl)2