Search in sources :

Example 71 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class ArchfiendOfDepravityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (opponent != null) {
        List<Permanent> creaturesToSacrifice = new ArrayList<>();
        TargetControlledPermanent target = new TargetControlledPermanent(0, 2, new FilterControlledCreaturePermanent("creatures to keep"), true);
        if (opponent.chooseTarget(outcome, target, source, game)) {
            for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), opponent.getId(), source.getSourceId(), game)) {
                if (permanent != null && !target.getTargets().contains(permanent.getId())) {
                    creaturesToSacrifice.add(permanent);
                }
            }
        }
        for (Permanent creature : creaturesToSacrifice) {
            creature.sacrifice(source, game);
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 72 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class CopperhornScoutUntapEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    List<Permanent> creatures = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
    for (Permanent creature : creatures) {
        if (!creature.getId().equals(source.getSourceId())) {
            creature.untap(game);
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 73 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class AngelicSkirmisherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        Choice abilityChoice = new ChoiceImpl(true);
        Set<String> abilityChoices = new HashSet<>(3);
        abilityChoice.setMessage("Choose ability for your creatures");
        abilityChoices.add("First strike");
        abilityChoices.add("Vigilance");
        abilityChoices.add("Lifelink");
        abilityChoice.setChoices(abilityChoices);
        if (controller.choose(outcome, abilityChoice, game)) {
            Ability ability = null;
            switch(abilityChoice.getChoice()) {
                case "First strike":
                    ability = FirstStrikeAbility.getInstance();
                    break;
                case "Vigilance":
                    ability = VigilanceAbility.getInstance();
                    break;
                case "Lifelink":
                    ability = LifelinkAbility.getInstance();
                    break;
                default:
                    break;
            }
            if (ability != null) {
                GainAbilityControlledEffect effect = new GainAbilityControlledEffect(ability, Duration.EndOfTurn, new FilterControlledCreaturePermanent());
                game.addEffect(effect, source);
                game.informPlayers(sourcePermanent.getName() + ": " + controller.getLogName() + " has chosen " + abilityChoice.getChoice().toLowerCase(Locale.ENGLISH));
                return true;
            }
        }
    }
    return false;
}
Also used : BeginningOfCombatTriggeredAbility(mage.abilities.common.BeginningOfCombatTriggeredAbility) LifelinkAbility(mage.abilities.keyword.LifelinkAbility) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) FirstStrikeAbility(mage.abilities.keyword.FirstStrikeAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ChoiceImpl(mage.choices.ChoiceImpl) HashSet(java.util.HashSet)

Example 74 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent 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)

Example 75 with FilterControlledCreaturePermanent

use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.

the class BroodBirthingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("Eldrazi Spawn");
    filter.add(SubType.ELDRAZI.getPredicate());
    filter.add(SubType.SPAWN.getPredicate());
    EldraziSpawnToken token = new EldraziSpawnToken();
    int count = game.getBattlefield().countAll(filter, source.getControllerId(), game) > 0 ? 3 : 1;
    token.putOntoBattlefield(count, game, source, source.getControllerId());
    return true;
}
Also used : FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) EldraziSpawnToken(mage.game.permanent.token.EldraziSpawnToken)

Aggregations

FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)75 Permanent (mage.game.permanent.Permanent)62 Player (mage.players.Player)60 UUID (java.util.UUID)29 Target (mage.target.Target)27 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)21 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)16 ArrayList (java.util.ArrayList)13 Card (mage.cards.Card)11 TargetPermanent (mage.target.TargetPermanent)11 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)10 FixedTarget (mage.target.targetpointer.FixedTarget)9 MageObject (mage.MageObject)7 OneShotEffect (mage.abilities.effects.OneShotEffect)7 Effect (mage.abilities.effects.Effect)6 Ability (mage.abilities.Ability)5 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)5 FilterPermanent (mage.filter.FilterPermanent)5 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)5 Spell (mage.game.stack.Spell)5