Search in sources :

Example 1 with BecomesFaceDownCreatureEffect

use of mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect in project mage by magefree.

the class ManifestTargetPlayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (targetPlayer != null) {
        Ability newSource = source.copy();
        newSource.setWorksFaceDown(true);
        Set<Card> cards = targetPlayer.getLibrary().getTopCards(game, amount);
        for (Card card : cards) {
            ManaCosts manaCosts = null;
            if (card.isCreature(game)) {
                manaCosts = card.getSpellAbility().getManaCosts();
                if (manaCosts == null) {
                    manaCosts = new ManaCostsImpl("{0}");
                }
            }
            MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
            game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
        }
        targetPlayer.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);
        for (Card card : cards) {
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
                permanent.setManifested(true);
            }
        }
        return true;
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Example 2 with BecomesFaceDownCreatureEffect

use of mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect in project mage by magefree.

the class GhastlyConscriptionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && targetPlayer != null) {
        List<Card> cardsToManifest = new ArrayList<>();
        for (Card card : targetPlayer.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game)) {
            cardsToManifest.add(card);
            controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.GRAVEYARD, true);
        }
        if (cardsToManifest.isEmpty()) {
            return true;
        }
        Collections.shuffle(cardsToManifest);
        game.informPlayers(controller.getLogName() + " shuffles the face-down pile");
        Ability newSource = source.copy();
        newSource.setWorksFaceDown(true);
        for (Card card : cardsToManifest) {
            ManaCosts manaCosts = null;
            if (card.isCreature(game)) {
                manaCosts = card.getSpellAbility().getManaCosts();
                if (manaCosts == null) {
                    manaCosts = new ManaCostsImpl("{0}");
                }
            }
            MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
            game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
        }
        Set<Card> toBattlefield = new LinkedHashSet();
        toBattlefield.addAll(cardsToManifest);
        controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, true, false, null);
        return true;
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Example 3 with BecomesFaceDownCreatureEffect

use of mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect in project mage by magefree.

the class TurnOverEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature = game.getPermanent(source.getFirstTarget());
    if (creature != null) {
        if (creature.isFaceDown(game)) {
            creature.turnFaceUp(source, game, source.getControllerId());
        } else {
            creature.turnFaceDown(source, game, source.getControllerId());
            MageObjectReference objectReference = new MageObjectReference(creature.getId(), creature.getZoneChangeCounter(game), game);
            game.addEffect(new BecomesFaceDownCreatureEffect(null, objectReference, Duration.Custom, FaceDownType.MANUAL), source);
        }
        return true;
    }
    return false;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) MageObjectReference(mage.MageObjectReference) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Example 4 with BecomesFaceDownCreatureEffect

use of mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect in project mage by magefree.

the class JeskaiInfiltratorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Card> cardsToManifest = new HashSet<>();
        cardsToManifest.add(source.getSourcePermanentIfItStillExists(game));
        cardsToManifest.add(controller.getLibrary().getFromTop(game));
        UUID exileId = UUID.randomUUID();
        controller.moveCardsToExile(cardsToManifest, source, game, false, exileId, "");
        ExileZone exileZone = game.getExile().getExileZone(exileId);
        for (Card card : exileZone.getCards(game)) {
            card.setFaceDown(true, game);
        }
        // removes Jeskai Infiltrator from Battlefield, so Jeskai Infiltrator returns as a fresh permanent to the battlefield with new position
        game.fireUpdatePlayersEvent();
        Ability newSource = source.copy();
        newSource.setWorksFaceDown(true);
        // the Set will mimic the Shuffling
        exileZone.getCards(game).forEach(card -> {
            ManaCosts manaCosts = null;
            if (card.isCreature(game)) {
                manaCosts = card.getSpellAbility().getManaCosts();
                if (manaCosts == null) {
                    manaCosts = new ManaCostsImpl("{0}");
                }
            }
            MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
            game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
        });
        controller.moveCards(exileZone.getCards(game), Zone.BATTLEFIELD, source, game, false, true, false, null);
        return true;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) DealsCombatDamageToAPlayerTriggeredAbility(mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility) Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) Player(mage.players.Player) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) HashSet(java.util.HashSet) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Example 5 with BecomesFaceDownCreatureEffect

use of mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect in project mage by magefree.

the class ScrollOfFateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || controller.getHand().isEmpty()) {
        return false;
    }
    TargetCardInHand targetCard = new TargetCardInHand();
    if (!controller.chooseTarget(Outcome.PutCardInPlay, controller.getHand(), targetCard, source, game)) {
        return false;
    }
    Ability newSource = source.copy();
    newSource.setWorksFaceDown(true);
    Set<Card> cards = targetCard.getTargets().stream().map(game::getCard).filter(Objects::nonNull).collect(Collectors.toSet());
    cards.stream().forEach(card -> {
        ManaCosts manaCosts = null;
        if (card.isCreature(game)) {
            manaCosts = card.getSpellAbility() != null ? card.getSpellAbility().getManaCosts() : null;
            if (manaCosts == null) {
                manaCosts = new ManaCostsImpl("{0}");
            }
        }
        MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
        game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, BecomesFaceDownCreatureEffect.FaceDownType.MANIFESTED), newSource);
    });
    controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);
    cards.stream().map(Card::getId).map(game::getPermanent).filter(permanent -> permanent != null).forEach(permanent -> permanent.setManifested(true));
    return true;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) TargetCardInHand(mage.target.common.TargetCardInHand) ManaCosts(mage.abilities.costs.mana.ManaCosts) Zone(mage.constants.Zone) Outcome(mage.constants.Outcome) Set(java.util.Set) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Game(mage.game.Game) TapSourceCost(mage.abilities.costs.common.TapSourceCost) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect) Card(mage.cards.Card) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

Aggregations

MageObjectReference (mage.MageObjectReference)7 BecomesFaceDownCreatureEffect (mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)7 Ability (mage.abilities.Ability)6 ManaCosts (mage.abilities.costs.mana.ManaCosts)6 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)6 Card (mage.cards.Card)6 Player (mage.players.Player)6 UUID (java.util.UUID)3 Permanent (mage.game.permanent.Permanent)3 Set (java.util.Set)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 CardImpl (mage.cards.CardImpl)2 CardSetInfo (mage.cards.CardSetInfo)2 Game (mage.game.Game)2 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 MageInt (mage.MageInt)1 BeginningOfUpkeepTriggeredAbility (mage.abilities.common.BeginningOfUpkeepTriggeredAbility)1 DealsCombatDamageToAPlayerTriggeredAbility (mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility)1