Search in sources :

Example 21 with AddCountersSourceEffect

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

the class OutOfTimeReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Permanent> creatures = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
    int numCreatures = creatures.size();
    if (numCreatures > 0) {
        Set<UUID> creatureIds = new HashSet<>(numCreatures);
        for (Permanent creature : creatures) {
            creature.untap(game);
            creatureIds.add(creature.getId());
        }
        // https://magic.wizards.com/en/articles/archive/feature/modern-horizons-2-release-notes-2021-06-04
        // If Out of Time leaves the battlefield before its enter the battlefield trigger resolves, creatures will untap, but they won't phase out.
        Permanent outOfTime = game.getPermanent(source.getSourceId());
        if (outOfTime != null) {
            new PhaseOutAllEffect(new ArrayList<>(creatureIds)).apply(game, source);
            new AddCountersSourceEffect(CounterType.TIME.createInstance(numCreatures)).apply(game, source);
            game.getState().setValue("phasedOutCreatures" + source.getId().toString(), creatureIds);
            game.getState().setValue("phasedOutBySourceId" + source.getSourceId(), source.getId());
            game.addDelayedTriggeredAbility(new OutOfTimeDelayedTriggeredAbility(), source);
            game.addEffect(new OutOfTimeReplacementEffect(), source);
        }
    }
    return true;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Permanent(mage.game.permanent.Permanent) PhaseOutAllEffect(mage.abilities.effects.common.PhaseOutAllEffect)

Example 22 with AddCountersSourceEffect

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

the class PoultrygeistEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int result = controller.rollDice(outcome, source, game, 6);
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
            if (result == 1) {
                return permanent.sacrifice(source, game);
            } else {
                return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
            }
        }
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Example 23 with AddCountersSourceEffect

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

the class SpectralAdversaryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Integer timesPaid = (Integer) getValue("timesPaid");
    if (timesPaid == null || timesPaid <= 0) {
        return false;
    }
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(timesPaid)), false, staticText);
    ability.addEffect(new PhaseOutTargetEffect());
    ability.addTarget(new TargetPermanent(0, timesPaid, filter));
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) PhaseOutTargetEffect(mage.abilities.effects.common.PhaseOutTargetEffect) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent)

Example 24 with AddCountersSourceEffect

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

the class FlowstoneSculptureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceImpl(true);
        choice.setMessage("Choose ability to add");
        choice.setChoices(choices);
        if (!controller.choose(outcome, choice, game)) {
            return false;
        }
        String chosen = choice.getChoice();
        if (chosen.equals("+1/+1 counter")) {
            return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
        } else {
            Ability gainedAbility;
            switch(chosen) {
                case "Flying":
                    gainedAbility = FlyingAbility.getInstance();
                    break;
                case "First strike":
                    gainedAbility = FirstStrikeAbility.getInstance();
                    break;
                default:
                    gainedAbility = TrampleAbility.getInstance();
                    break;
            }
            game.addEffect(new GainAbilitySourceEffect(gainedAbility, Duration.WhileOnBattlefield), source);
            return true;
        }
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) FirstStrikeAbility(mage.abilities.keyword.FirstStrikeAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TrampleAbility(mage.abilities.keyword.TrampleAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Choice(mage.choices.Choice) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect) ChoiceImpl(mage.choices.ChoiceImpl)

Example 25 with AddCountersSourceEffect

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

the class GallopingLizrogEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    RemoveVariableCountersTargetCost variableCost = new RemoveVariableCountersTargetCost(StaticFilters.FILTER_CONTROLLED_CREATURE, CounterType.P1P1);
    int toPay = variableCost.announceXValue(source, game);
    Cost cost = variableCost.getFixedCostsFromAnnouncedValue(toPay);
    if (!cost.pay(source, game, source, source.getControllerId(), true)) {
        return false;
    }
    return new AddCountersSourceEffect(CounterType.P1P1.createInstance(2 * toPay)).apply(game, source);
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) RemoveVariableCountersTargetCost(mage.abilities.costs.common.RemoveVariableCountersTargetCost) Cost(mage.abilities.costs.Cost) RemoveVariableCountersTargetCost(mage.abilities.costs.common.RemoveVariableCountersTargetCost)

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