Search in sources :

Example 1 with MageItem

use of mage.MageItem in project mage by magefree.

the class WillScholarOfFrostEffect 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(targetPointer.getTargets(game, source));
    Map<UUID, Integer> playerMap = cards.getCards(game).stream().filter(Objects::nonNull).map(MageItem::getId).map(game::getControllerId).filter(Objects::nonNull).collect(Collectors.toMap(Function.identity(), x -> 1, Integer::sum));
    player.moveCards(cards, Zone.EXILED, source, game);
    for (Map.Entry<UUID, Integer> entry : playerMap.entrySet()) {
        new Elemental44Token().putOntoBattlefield(entry.getValue(), game, source, entry.getKey());
    }
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) SetPowerToughnessTargetEffect(mage.abilities.effects.common.continuous.SetPowerToughnessTargetEffect) Hint(mage.abilities.hint.Hint) Function(java.util.function.Function) MageItem(mage.MageItem) Player(mage.players.Player) RowanScholarOfSparksEmblem(mage.game.command.emblems.RowanScholarOfSparksEmblem) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Map(java.util.Map) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) mage.constants(mage.constants) CardsAmountDrawnThisTurnWatcher(mage.watchers.common.CardsAmountDrawnThisTurnWatcher) FilterCard(mage.filter.FilterCard) StaticFilters(mage.filter.StaticFilters) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard) Condition(mage.abilities.condition.Condition) Cards(mage.cards.Cards) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Elemental44Token(mage.game.permanent.token.Elemental44Token) Collectors(java.util.stream.Collectors) LoyaltyAbility(mage.abilities.LoyaltyAbility) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) DamagePlayersEffect(mage.abilities.effects.common.DamagePlayersEffect) SpellsCostReductionControllerEffect(mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect) GetEmblemEffect(mage.abilities.effects.common.GetEmblemEffect) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) Objects(java.util.Objects) UUID(java.util.UUID) Map(java.util.Map) Elemental44Token(mage.game.permanent.token.Elemental44Token) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 2 with MageItem

use of mage.MageItem in project mage by magefree.

the class OrvarTheAllFormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Spell spell = (Spell) this.getValue("spellCast");
    if (player == null || spell == null) {
        return false;
    }
    List<Predicate<Permanent>> predicates = spell.getSpellAbility().getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).map(MageItem::getId).map(PermanentIdPredicate::new).collect(Collectors.toList());
    if (predicates.isEmpty()) {
        return false;
    }
    FilterPermanent filter = new FilterControlledPermanent("a permanent you control targeted by that spell");
    filter.add(Predicates.or(predicates));
    filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(source))));
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    return new CreateTokenCopyTargetEffect().setTargetPointer(new FixedTarget(target.getFirstTarget(), game)).apply(game, source);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Mode(mage.abilities.Mode) MageItem(mage.MageItem) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Spell(mage.game.stack.Spell) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Predicate(mage.filter.predicate.Predicate) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetPermanent(mage.target.TargetPermanent) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) MageObjectReference(mage.MageObjectReference)

Example 3 with MageItem

use of mage.MageItem in project mage by magefree.

the class RitesOfSpringEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int numDiscarded = controller.discard(0, Integer.MAX_VALUE, false, source, game).size();
    if (numDiscarded == 0) {
        return true;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(numDiscarded, StaticFilters.FILTER_CARD_BASIC_LAND);
    controller.searchLibrary(target, source, game);
    Cards cards = new CardsImpl();
    controller.getLibrary().getCards(game).stream().filter(Objects::nonNull).map(MageItem::getId).filter(target.getTargets()::contains).forEach(cards::add);
    controller.revealCards(source, cards, game);
    controller.moveCards(cards, Zone.HAND, source, game);
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) MageItem(mage.MageItem) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 4 with MageItem

use of mage.MageItem in project mage by magefree.

the class RampantRejuvenatorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = source.getSourcePermanentOrLKI(game);
    if (player == null || permanent == null) {
        return false;
    }
    TargetCardInLibrary target = new TargetCardInLibrary(0, permanent.getPower().getValue(), StaticFilters.FILTER_CARD_BASIC_LANDS);
    player.searchLibrary(target, source, game);
    Cards cards = new CardsImpl();
    player.getLibrary().getCards(game).stream().map(MageItem::getId).filter(target.getTargets()::contains).forEach(cards::add);
    player.moveCards(cards, Zone.BATTLEFIELD, source, game);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageItem(mage.MageItem) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 5 with MageItem

use of mage.MageItem in project mage by magefree.

the class IlluminatedFolioTarget method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
    if (this.getTargets().size() == 1) {
        Card card = game.getCard(this.getTargets().get(0));
        possibleTargets.removeIf(uuid -> !game.getCard(uuid).getColor(game).shares(card.getColor(game)));
        return possibleTargets;
    }
    if (possibleTargets.size() < 2) {
        possibleTargets.clear();
        return possibleTargets;
    }
    Set<Card> allTargets = possibleTargets.stream().map(game::getCard).collect(Collectors.toSet());
    possibleTargets.clear();
    for (ObjectColor color : ObjectColor.getAllColors()) {
        Set<Card> inColor = allTargets.stream().filter(card -> card.getColor(game).shares(color)).collect(Collectors.toSet());
        if (inColor.size() > 1) {
            inColor.stream().map(MageItem::getId).forEach(possibleTargets::add);
        }
        if (possibleTargets.size() == allTargets.size()) {
            break;
        }
    }
    return possibleTargets;
}
Also used : FilterCard(mage.filter.FilterCard) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetCardInHand(mage.target.common.TargetCardInHand) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) Cards(mage.cards.Cards) Set(java.util.Set) Predicates(mage.filter.predicate.Predicates) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MageItem(mage.MageItem) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) List(java.util.List) TapSourceCost(mage.abilities.costs.common.TapSourceCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) CardImpl(mage.cards.CardImpl) RevealTargetFromHandCost(mage.abilities.costs.common.RevealTargetFromHandCost) CardType(mage.constants.CardType) ColorlessPredicate(mage.filter.predicate.mageobject.ColorlessPredicate) ObjectColor(mage.ObjectColor) Card(mage.cards.Card) Ability(mage.abilities.Ability) ObjectColor(mage.ObjectColor) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Aggregations

MageItem (mage.MageItem)6 Player (mage.players.Player)5 Cards (mage.cards.Cards)4 CardsImpl (mage.cards.CardsImpl)3 TargetPermanent (mage.target.TargetPermanent)3 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Ability (mage.abilities.Ability)2 DrawCardSourceControllerEffect (mage.abilities.effects.common.DrawCardSourceControllerEffect)2 CardSetInfo (mage.cards.CardSetInfo)2 FilterCard (mage.filter.FilterCard)2 FilterPermanent (mage.filter.FilterPermanent)2 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)2 Game (mage.game.Game)2 Permanent (mage.game.permanent.Permanent)2 Target (mage.target.Target)2 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)2 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1