Search in sources :

Example 86 with Ability

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

the class EcologicalAppreciationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    FilterCard filter = new FilterCreatureCard();
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard targetCardsInLibrary = new TargetCardInLibrary(0, 4, filter) {

        @Override
        public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
            if (!super.canTarget(playerId, id, source, game)) {
                return false;
            }
            Card card = game.getCard(id);
            Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
            return isValidTarget(card, disallowedCards);
        }
    };
    targetCardsInLibrary.setNotTarget(true);
    targetCardsInLibrary.withChooseHint("Step 1 of 2: Search library");
    player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getLibrary().getCards(game)), targetCardsInLibrary, game);
    Cards cards = new CardsImpl(targetCardsInLibrary.getTargets());
    boolean status = !cards.isEmpty();
    if (status) {
        int remainingCards = 4 - cards.size();
        if (remainingCards > 0) {
            TargetCard targetCardsInGY = new TargetCardInYourGraveyard(0, remainingCards, filter) {

                @Override
                public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
                    if (!super.canTarget(playerId, id, source, game)) {
                        return false;
                    }
                    Card card = game.getCard(id);
                    Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
                    Set<Card> checkList = new HashSet<>();
                    checkList.addAll(disallowedCards);
                    checkList.addAll(cards.getCards(game));
                    return isValidTarget(card, checkList);
                }
            };
            targetCardsInGY.setNotTarget(true);
            targetCardsInGY.withChooseHint("Step 2 of 2: Search graveyard");
            player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getGraveyard().getCards(game)), targetCardsInGY, game);
            cards.addAll(targetCardsInGY.getTargets());
        }
        TargetOpponent targetOpponent = new TargetOpponent();
        targetOpponent.setNotTarget(true);
        player.choose(outcome, targetOpponent, source.getSourceId(), game);
        Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
        if (opponent == null) {
            status = false;
        }
        if (status) {
            TargetCard chosenCards = new TargetCard(2, Zone.ALL, StaticFilters.FILTER_CARD);
            chosenCards.setNotTarget(true);
            opponent.choose(outcome, cards, chosenCards, game);
            Cards toShuffle = new CardsImpl(chosenCards.getTargets().stream().map(game::getCard).collect(Collectors.toList()));
            player.putCardsOnTopOfLibrary(toShuffle, game, source, false);
            cards.removeAll(toShuffle);
            player.moveCards(cards, Zone.BATTLEFIELD, source, game);
        }
    }
    player.shuffleLibrary(source, game);
    return status;
}
Also used : Ability(mage.abilities.Ability) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Game(mage.game.Game) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 87 with Ability

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

the class EchoingReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(source.getFirstTarget());
    if (player == null || card == null) {
        return false;
    }
    Cards cards = new CardsImpl(card);
    player.getGraveyard().getCards(game).stream().filter(c -> CardUtil.haveSameNames(c.getName(), card.getName())).forEach(cards::add);
    return player.moveCards(cards, Zone.HAND, source, game);
}
Also used : StaticFilters(mage.filter.StaticFilters) Game(mage.game.Game) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Zone(mage.constants.Zone) mage.cards(mage.cards) CardType(mage.constants.CardType) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) Player(mage.players.Player) Ability(mage.abilities.Ability) Player(mage.players.Player) mage.cards(mage.cards)

Example 88 with Ability

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

the class ExpropriateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    // Outcome.Detriment - AI will gain control all the time (Money choice)
    // TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
    TwoChoiceVote vote = new TwoChoiceVote("Time (extra turn)", "Money (gain control)", Outcome.Detriment);
    vote.doVotes(source, game);
    // extra turn
    int timeCount = vote.getVoteCount(true);
    for (int i = 0; i < timeCount; i++) {
        game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false));
    }
    // gain control
    if (vote.getVoteCount(false) < 1) {
        return true;
    }
    List<Permanent> toSteal = new ArrayList<>();
    for (UUID playerId : vote.getVotedFor(false)) {
        int moneyCount = vote.getVotes(playerId).stream().mapToInt(x -> x ? 0 : 1).sum();
        FilterPermanent filter = new FilterPermanent();
        filter.add(new ControllerIdPredicate(playerId));
        moneyCount = Math.min(game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game), moneyCount);
        if (moneyCount == 0) {
            continue;
        }
        TargetPermanent target = new TargetPermanent(moneyCount, filter);
        target.setNotTarget(true);
        player.choose(Outcome.GainControl, target, source.getSourceId(), game);
        target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(toSteal::add);
    }
    game.addEffect(new GainControlTargetEffect(Duration.Custom, true, source.getControllerId()).setTargetPointer(new FixedTargets(toSteal, game)), source);
    return true;
}
Also used : GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) ArrayList(java.util.ArrayList) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) ExileSpellEffect(mage.abilities.effects.common.ExileSpellEffect) TwoChoiceVote(mage.choices.TwoChoiceVote) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FixedTargets(mage.target.targetpointer.FixedTargets) TurnMod(mage.game.turn.TurnMod) 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) TargetPermanent(mage.target.TargetPermanent) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) TurnMod(mage.game.turn.TurnMod) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TwoChoiceVote(mage.choices.TwoChoiceVote) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 89 with Ability

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

the class FacelessAgentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || player.getLibrary().count(filterAnyType, game) < 1) {
        return false;
    }
    Map<SubType, Integer> typeMap = player.getLibrary().getCards(game).stream().filter(card -> !card.isAllCreatureTypes(game)).map(card -> card.getSubtype(game)).flatMap(Collection::stream).filter(subType -> subType.getSubTypeSet() == SubTypeSet.CreatureType).collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum));
    if (typeMap.isEmpty()) {
        return player.seekCard(filterAnyType, source, game);
    }
    int max = typeMap.values().stream().mapToInt(x -> x).max().orElse(0);
    FilterCard filter = new FilterCreatureCard();
    filter.add(Predicates.or(typeMap.entrySet().stream().filter(entry -> entry.getValue() == max).map(Map.Entry::getKey).map(SubType::getPredicate).collect(Collectors.toSet())));
    return player.seekCard(filter, source, game);
}
Also used : FilterCard(mage.filter.FilterCard) Predicate(mage.filter.predicate.Predicate) SubTypeSet(mage.constants.SubTypeSet) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Collection(java.util.Collection) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Map(java.util.Map) ChangelingAbility(mage.abilities.keyword.ChangelingAbility) CardType(mage.constants.CardType) Card(mage.cards.Card) Ability(mage.abilities.Ability) FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) SubType(mage.constants.SubType) Collection(java.util.Collection)

Example 90 with Ability

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

the class GorgingVultureEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int lifeToGain = player.millCards(4, source, game).getCards(game).stream().filter(card1 -> card1.isCreature(game)).mapToInt(card -> game.getState().getZone(card.getId()) == Zone.GRAVEYARD ? 1 : 0).sum();
    return player.gainLife(lifeToGain, game, source) > 0;
}
Also used : Zone(mage.constants.Zone) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) FlyingAbility(mage.abilities.keyword.FlyingAbility) Ability(mage.abilities.Ability) Player(mage.players.Player)

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