Search in sources :

Example 11 with DestroyAllEffect

use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.

the class EndemicPlagueEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Permanent permanent = null;
    for (Cost cost : source.getCosts()) {
        if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
            permanent = ((SacrificeTargetCost) cost).getPermanents().get(0);
            break;
        }
    }
    if (permanent == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new SharesCreatureTypePredicate(permanent));
    return new DestroyAllEffect(filter, true).apply(game, source);
}
Also used : Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) SharesCreatureTypePredicate(mage.filter.predicate.mageobject.SharesCreatureTypePredicate) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 12 with DestroyAllEffect

use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.

the class HarshMercyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        Set<String> chosenTypes = new HashSet<>();
        PlayerIteration: for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            Choice typeChoice = new ChoiceCreatureType(sourceObject);
            if (player != null && !player.choose(Outcome.DestroyPermanent, typeChoice, game)) {
                continue PlayerIteration;
            }
            String chosenType = typeChoice.getChoice();
            if (chosenType != null) {
                game.informPlayers(sourceObject.getIdName() + ": " + player.getLogName() + " has chosen " + chosenType);
                chosenTypes.add(chosenType);
            }
        }
        FilterPermanent filter = new FilterCreaturePermanent("creatures");
        for (String type : chosenTypes) {
            filter.add(Predicates.not(SubType.byDescription(type).getPredicate()));
        }
        return new DestroyAllEffect(filter, true).apply(game, source);
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType) UUID(java.util.UUID) HashSet(java.util.HashSet) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 13 with DestroyAllEffect

use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.

the class MagisterOfWorthEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // Outcome.Benefit - AI will return from graveyard all the time (Grace choice)
    // TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
    TwoChoiceVote vote = new TwoChoiceVote("Grace (return from graveyard)", "Condemnation (destroy all)", Outcome.Benefit);
    vote.doVotes(source, game);
    int graceCount = vote.getVoteCount(true);
    int condemnationCount = vote.getVoteCount(false);
    if (condemnationCount >= graceCount) {
        return new DestroyAllEffect(filter).apply(game, source);
    }
    // grace win - each player returns each creature card from their graveyard to the battlefield
    Cards cards = new CardsImpl();
    game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getGraveyard).map(g -> g.getCards(game)).flatMap(Collection::stream).filter(Objects::nonNull).filter(card -> card.isCreature(game)).forEach(cards::add);
    return controller.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
}
Also used : Zone(mage.constants.Zone) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Collection(java.util.Collection) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) SubType(mage.constants.SubType) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) TwoChoiceVote(mage.choices.TwoChoiceVote) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FlyingAbility(mage.abilities.keyword.FlyingAbility) AnotherPredicate(mage.filter.predicate.mageobject.AnotherPredicate) Ability(mage.abilities.Ability) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect) Player(mage.players.Player) Objects(java.util.Objects) TwoChoiceVote(mage.choices.TwoChoiceVote) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 14 with DestroyAllEffect

use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.

the class SteelHellkiteWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    SteelHellkiteWatcher watcher = game.getState().getWatcher(SteelHellkiteWatcher.class);
    if (watcher == null || watcher.getDamagedPlayers(source.getSourceId()).isEmpty()) {
        return false;
    }
    Set<Predicate<Permanent>> predicateSet = new HashSet<>();
    for (UUID playerId : watcher.getDamagedPlayers(source.getSourceId())) {
        predicateSet.add(new ControllerIdPredicate(playerId));
    }
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
    filter.add(Predicates.or(predicateSet));
    return new DestroyAllEffect(filter).apply(game, source);
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Predicate(mage.filter.predicate.Predicate) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Example 15 with DestroyAllEffect

use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.

the class TimeWipeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Target target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    if (player.choose(outcome, target, source.getSourceId(), game)) {
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            player.moveCards(permanent, Zone.HAND, source, game);
        }
    }
    return new DestroyAllEffect(StaticFilters.FILTER_PERMANENT_A_CREATURE).apply(game, source);
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Aggregations

DestroyAllEffect (mage.abilities.effects.common.DestroyAllEffect)15 Player (mage.players.Player)9 FilterPermanent (mage.filter.FilterPermanent)8 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)7 Permanent (mage.game.permanent.Permanent)7 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)5 UUID (java.util.UUID)3 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)3 OneShotEffect (mage.abilities.effects.OneShotEffect)2 Choice (mage.choices.Choice)2 ChoiceCreatureType (mage.choices.ChoiceCreatureType)2 TwoChoiceVote (mage.choices.TwoChoiceVote)2 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)2 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1 MageInt (mage.MageInt)1 MageObject (mage.MageObject)1