Search in sources :

Example 21 with PermanentsOnBattlefieldCount

use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.

the class VastwoodAnimistElementalToken method apply.

@Override
public boolean apply(Game game, Ability source) {
    int amount = new PermanentsOnBattlefieldCount(filterAllies).calculate(game, source, this);
    ContinuousEffect effect = new BecomesCreatureTargetEffect(new VastwoodAnimistElementalToken(amount), false, true, Duration.EndOfTurn);
    effect.setTargetPointer(targetPointer);
    game.addEffect(effect, source);
    return false;
}
Also used : BecomesCreatureTargetEffect(mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 22 with PermanentsOnBattlefieldCount

use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.

the class BattletideAlchemistEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    boolean result = false;
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(event.getTargetId());
    if (controller != null && targetPlayer != null) {
        int numberOfClericsControlled = new PermanentsOnBattlefieldCount(new FilterControlledCreaturePermanent(SubType.CLERIC, "Clerics")).calculate(game, source, this);
        int toPrevent = Math.min(numberOfClericsControlled, event.getAmount());
        if (toPrevent > 0 && controller.chooseUse(Outcome.PreventDamage, "Prevent " + toPrevent + " damage to " + targetPlayer.getName() + '?', source, game)) {
            GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), toPrevent, ((DamageEvent) event).isCombatDamage());
            if (!game.replaceEvent(preventEvent)) {
                if (event.getAmount() >= toPrevent) {
                    event.setAmount(event.getAmount() - toPrevent);
                } else {
                    event.setAmount(0);
                    result = true;
                }
                game.informPlayers("Battletide Alchemist prevented " + toPrevent + " damage to " + targetPlayer.getName());
                game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), toPrevent));
            }
        }
    }
    return result;
}
Also used : Player(mage.players.Player) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) GameEvent(mage.game.events.GameEvent) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Aggregations

PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)22 Player (mage.players.Player)18 Permanent (mage.game.permanent.Permanent)6 Choice (mage.choices.Choice)5 ChoiceCreatureType (mage.choices.ChoiceCreatureType)5 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 ContinuousEffect (mage.abilities.effects.ContinuousEffect)4 Card (mage.cards.Card)4 FilterPermanent (mage.filter.FilterPermanent)4 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)4 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)4 UUID (java.util.UUID)3 CardsImpl (mage.cards.CardsImpl)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 Cost (mage.abilities.costs.Cost)2 DynamicValue (mage.abilities.dynamicvalue.DynamicValue)2 Effect (mage.abilities.effects.Effect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 BecomesCreatureTargetEffect (mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect)2