Search in sources :

Example 21 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class BreechesBrazenPlundererEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    opponentIds.stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getLibrary).map(library -> library.getFromTop(game)).forEach(cards::add);
    player.moveCards(cards, Zone.EXILED, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
    if (cards.isEmpty()) {
        return false;
    }
    for (Card card : cards.getCards(game)) {
        CardUtil.makeCardPlayable(game, source, card, Duration.EndOfTurn, true);
    }
    return true;
}
Also used : PartnerAbility(mage.abilities.keyword.PartnerAbility) mage.cards(mage.cards) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) MageInt(mage.MageInt) Player(mage.players.Player) DamagedPlayerBatchEvent(mage.game.events.DamagedPlayerBatchEvent) HashSet(java.util.HashSet) Objects(java.util.Objects) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) Permanent(mage.game.permanent.Permanent) DamagedEvent(mage.game.events.DamagedEvent) MenaceAbility(mage.abilities.keyword.MenaceAbility) mage.constants(mage.constants) Ability(mage.abilities.Ability) Player(mage.players.Player) mage.cards(mage.cards)

Example 22 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class CelestialJudgmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
    Map<Integer, List<Permanent>> powerMap = permanents.stream().collect(Collectors.toMap(permanent -> permanent.getPower().getValue(), permanent -> Arrays.asList(permanent), (a1, a2) -> {
        a1.addAll(a2);
        return a1;
    }));
    Set<UUID> toKeep = new HashSet<>();
    for (Map.Entry<Integer, List<Permanent>> entry : powerMap.entrySet()) {
        if (entry.getValue().size() == 1) {
            toKeep.add(entry.getValue().get(0).getId());
            continue;
        }
        FilterPermanent filter = new FilterCreaturePermanent("creature with power " + entry.getKey() + " to save");
        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, entry.getKey()));
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        toKeep.add(target.getFirstTarget());
    }
    for (Permanent permanent : permanents) {
        if (!toKeep.contains(permanent.getId())) {
            permanent.destroy(source, game);
        }
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) java.util(java.util) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) Player(mage.players.Player) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) ComparisonType(mage.constants.ComparisonType) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 23 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class CavalierOfThornsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
    if (cards.isEmpty()) {
        return true;
    }
    controller.revealCards(source, cards, game);
    TargetCard target = new TargetCard(1, 1, Zone.LIBRARY, filter);
    if (cards.getCards(game).stream().anyMatch(card1 -> card1.isLand(game)) && controller.choose(Outcome.PutCardInPlay, cards, target, game)) {
        Card card = cards.get(target.getFirstTarget(), game);
        if (card != null) {
            cards.remove(card);
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        }
    }
    controller.moveCards(cards, Zone.GRAVEYARD, source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Zone(mage.constants.Zone) PutOnLibraryTargetEffect(mage.abilities.effects.common.PutOnLibraryTargetEffect) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) ExileSourceFromGraveCost(mage.abilities.costs.common.ExileSourceFromGraveCost) UUID(java.util.UUID) MageInt(mage.MageInt) ReachAbility(mage.abilities.keyword.ReachAbility) SubType(mage.constants.SubType) Player(mage.players.Player) FilterLandCard(mage.filter.common.FilterLandCard) Game(mage.game.Game) TargetCard(mage.target.TargetCard) CardType(mage.constants.CardType) AnotherPredicate(mage.filter.predicate.mageobject.AnotherPredicate) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterLandCard(mage.filter.common.FilterLandCard) TargetCard(mage.target.TargetCard)

Example 24 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class CelebrateTheHarvestEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int powerCount = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageObject::getPower).mapToInt(MageInt::getValue).distinct().map(x -> 1).sum();
    TargetCardInLibrary target = new TargetCardInLibrary(0, powerCount, StaticFilters.FILTER_CARD_BASIC_LAND);
    player.searchLibrary(target, source, game);
    Cards cards = new CardsImpl();
    target.getTargets().stream().map(cardId -> player.getLibrary().getCard(cardId, game)).forEach(cards::add);
    player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) MageObject(mage.MageObject) CovenHint(mage.abilities.hint.common.CovenHint) Ability(mage.abilities.Ability) Player(mage.players.Player) MageObject(mage.MageObject) CovenHint(mage.abilities.hint.common.CovenHint) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 25 with Ability

use of mage.abilities.Ability in project mage by magefree.

the class CoercedConfessionMillEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    int creaturesMilled = player.millCards(4, source, game).getCards(game).stream().filter(Objects::nonNull).filter(card -> game.getState().getZone(card.getId()) == Zone.GRAVEYARD).filter(card1 -> card1.isCreature(game)).mapToInt(x -> 1).sum();
    if (creaturesMilled < 1) {
        return true;
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return true;
    }
    controller.drawCards(creaturesMilled, source, game);
    return true;
}
Also used : CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) Zone(mage.constants.Zone) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) Player(mage.players.Player) Ability(mage.abilities.Ability) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Objects(java.util.Objects)

Aggregations

Ability (mage.abilities.Ability)359 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)134 UUID (java.util.UUID)126 Game (mage.game.Game)123 OneShotEffect (mage.abilities.effects.OneShotEffect)98 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)87 CardSetInfo (mage.cards.CardSetInfo)87 CardImpl (mage.cards.CardImpl)85 CardType (mage.constants.CardType)78 Outcome (mage.constants.Outcome)76 Card (mage.cards.Card)72 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)64 MageObject (mage.MageObject)57 MageInt (mage.MageInt)47 SpellAbility (mage.abilities.SpellAbility)43 Objects (java.util.Objects)38 Zone (mage.constants.Zone)38 mage.constants (mage.constants)37 FilterCard (mage.filter.FilterCard)35