Search in sources :

Example 6 with Ability

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

the class HauntingEchoesPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(source.getFirstTarget());
    if (controller == null || player == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    player.getGraveyard().getCards(game).stream().filter(Objects::nonNull).filter(card -> !card.isBasic() || !card.isLand(game)).forEach(cards::add);
    controller.moveCards(cards, Zone.EXILED, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
    FilterCard filter = new FilterCard("cards with the same name as a card exiled this way");
    filter.add(new HauntingEchoesPredicate(cards));
    TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
    controller.searchLibrary(target, source, game, player.getId());
    cards.clear();
    cards.addAll(target.getTargets());
    controller.moveCards(cards, Zone.EXILED, source, game);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) Predicate(mage.filter.predicate.Predicate) mage.cards(mage.cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) Player(mage.players.Player) Objects(java.util.Objects) Game(mage.game.Game) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) mage.cards(mage.cards) Objects(java.util.Objects) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 7 with Ability

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

the class KotoseTheSilentSpiderWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (controller == null || card == null) {
        return false;
    }
    Player opponent = game.getPlayer(card.getOwnerId());
    if (opponent == null) {
        return false;
    }
    UUID exileId = CardUtil.getExileZoneId(game, source);
    String exileName = CardUtil.getSourceName(game, source);
    controller.moveCardsToExile(card, source, game, true, exileId, exileName);
    Cards cards = new CardsImpl();
    FilterCard filter = new FilterCard("cards named " + card.getName() + " from " + opponent.getName() + "'s graveyard");
    filter.add(new NamePredicate(card.getName()));
    TargetCardInGraveyard targetCardInGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filter);
    controller.choose(outcome, opponent.getGraveyard(), targetCardInGraveyard, game);
    cards.addAll(targetCardInGraveyard.getTargets());
    filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s hand");
    TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
    controller.choose(outcome, opponent.getHand(), targetCardInHand, game);
    cards.addAll(targetCardInHand.getTargets());
    filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s library");
    TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
    controller.searchLibrary(target, source, game, opponent.getId());
    target.getTargets().stream().map(cardId -> opponent.getLibrary().getCard(cardId, game)).forEach(cards::add);
    Set<Card> cardSet = cards.getCards(game);
    controller.moveCardsToExile(cardSet, source, game, true, exileId, exileName);
    opponent.shuffleLibrary(source, game);
    cardSet.add(card);
    if (cardSet.isEmpty() || source.getSourcePermanentIfItStillExists(game) == null) {
        return true;
    }
    KotoseTheSilentSpiderWatcher.addCards(source, cardSet, game);
    for (Card exiledCard : cardSet) {
        CardUtil.makeCardPlayable(game, source, exiledCard, Duration.WhileControlled, true, null, new KotoseTheSilentSpiderCondition(exiledCard, game));
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) java.util(java.util) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) mage.cards(mage.cards) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) CardUtil(mage.util.CardUtil) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) Player(mage.players.Player) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) Spell(mage.game.stack.Spell) mage.constants(mage.constants) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) TargetCardInOpponentsGraveyard(mage.target.common.TargetCardInOpponentsGraveyard) Ability(mage.abilities.Ability) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) mage.cards(mage.cards) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard)

Example 8 with Ability

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

the class SehtsTigerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    ChoiceColor choice = new ChoiceColor();
    if (controller != null && mageObject != null && controller.choose(Outcome.Protect, choice, game)) {
        game.informPlayers(mageObject.getLogName() + ": " + controller.getLogName() + " has chosen " + choice.getChoice());
        FilterCard filter = new FilterCard();
        filter.add(new ColorPredicate(choice.getColor()));
        filter.setMessage(choice.getChoice());
        Ability ability = new ProtectionAbility(filter);
        game.addEffect(new GainAbilityControllerEffect(ability, Duration.EndOfTurn), source);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FlashAbility(mage.abilities.keyword.FlashAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) MageObject(mage.MageObject) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ChoiceColor(mage.choices.ChoiceColor) GainAbilityControllerEffect(mage.abilities.effects.common.continuous.GainAbilityControllerEffect)

Example 9 with Ability

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

the class TestOfTalentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    if (stackObject == null) {
        return false;
    }
    MageObject targetObject = game.getObject(stackObject.getSourceId());
    String cardName;
    if (targetObject instanceof Card) {
        cardName = targetObject.getName();
    } else {
        cardName = "";
    }
    UUID searchPlayerId = stackObject.getControllerId();
    Player player = game.getPlayer(searchPlayerId);
    if (player == null) {
        return false;
    }
    int previousCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    game.getStack().counter(source.getFirstTarget(), source, game);
    this.applySearchAndExile(game, source, cardName, searchPlayerId);
    int newCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    if (previousCount > newCount) {
        player.drawCards(previousCount - newCount, source, game);
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) SearchTargetGraveyardHandLibraryForCardNameAndExileEffect(mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) 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) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card) Ability(mage.abilities.Ability) TargetSpell(mage.target.TargetSpell) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Objects(java.util.Objects) UUID(java.util.UUID) Card(mage.cards.Card)

Example 10 with Ability

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

the class NassariDeanOfExpressionTriggeredAbility 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();
    game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getLibrary).map(p -> p.getFromTop(game)).forEach(cards::add);
    player.moveCards(cards, Zone.EXILED, source, game);
    cards.retainZone(Zone.EXILED, game);
    if (cards.isEmpty()) {
        return false;
    }
    for (Card card : cards.getCards(game)) {
        CardUtil.makeCardPlayable(game, source, card, Duration.EndOfTurn, true);
    }
    return true;
}
Also used : TargetCardInHand(mage.target.common.TargetCardInHand) SpellCastControllerTriggeredAbility(mage.abilities.common.SpellCastControllerTriggeredAbility) MageObjectReference(mage.MageObjectReference) Player(mage.players.Player) AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) TapSourceCost(mage.abilities.costs.common.TapSourceCost) TargetCard(mage.target.TargetCard) MageObject(mage.MageObject) mage.constants(mage.constants) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) StaticFilters(mage.filter.StaticFilters) ApprovingObject(mage.ApprovingObject) mage.cards(mage.cards) Condition(mage.abilities.condition.Condition) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) Objects(java.util.Objects) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) SpellAbility(mage.abilities.SpellAbility) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) ConditionalInterveningIfTriggeredAbility(mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) RemoveCounterSourceEffect(mage.abilities.effects.common.counter.RemoveCounterSourceEffect) Player(mage.players.Player) mage.cards(mage.cards) TargetCard(mage.target.TargetCard)

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