Search in sources :

Example 81 with MageObject

use of mage.MageObject in project mage by magefree.

the class HedronAlignmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        Cards cardsToReveal = new CardsImpl();
        controller.revealCards(sourceObject.getIdName(), cardsToReveal, game);
        // Check battlefield
        if (!game.getBattlefield().contains(filterPermanent, source, game, 1)) {
            return true;
        }
        if (controller.getHand().getCards(filterCard, source.getSourceId(), controller.getId(), game).isEmpty()) {
            return true;
        }
        if (controller.getGraveyard().getCards(filterCard, source.getSourceId(), controller.getId(), game).isEmpty()) {
            return true;
        }
        Cards cardsToCheck = new CardsImpl();
        cardsToCheck.addAll(game.getExile().getAllCards(game));
        if (cardsToCheck.count(filterCard, source.getSourceId(), controller.getId(), game) == 0) {
            return true;
        }
        controller.won(game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 82 with MageObject

use of mage.MageObject in project mage by magefree.

the class JestersScepterCounterEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (affectedControllerId.equals(source.getControllerId())) {
        Card card = game.getCard(objectId);
        if (card != null) {
            MageObject sourceObject = game.getObject(source.getSourceId());
            if (sourceObject == null) {
                return false;
            }
            UUID exileId = CardUtil.getCardExileZoneId(game, source);
            ExileZone exile = game.getExile().getExileZone(exileId);
            return exile != null && exile.contains(objectId);
        }
    }
    return false;
}
Also used : MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard)

Example 83 with MageObject

use of mage.MageObject in project mage by magefree.

the class JestersScepterCounterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetedPlayer = game.getPlayer(source.getFirstTarget());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && targetedPlayer != null && sourceObject != null) {
        if (targetedPlayer.getLibrary().hasCards()) {
            Set<Card> cardsToExile = targetedPlayer.getLibrary().getTopCards(game, 5);
            for (Card card : cardsToExile) {
                if (card.moveToExile(CardUtil.getCardExileZoneId(game, source), sourceObject.getName(), source, game)) {
                    card.setFaceDown(true, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) MageObject(mage.MageObject) FilterCard(mage.filter.FilterCard)

Example 84 with MageObject

use of mage.MageObject in project mage by magefree.

the class JourneyForTheElixirGraveyardTarget method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
    Cards alreadyTargeted = new CardsImpl(this.getTargets());
    alreadyTargeted.addAll(cards);
    boolean hasBasic = alreadyTargeted.getCards(game).stream().filter(Objects::nonNull).filter(card1 -> card1.isLand(game)).anyMatch(MageObject::isBasic);
    possibleTargets.removeIf(uuid -> {
        Card card = game.getCard(uuid);
        return card != null && hasBasic && card.isLand(game) && card.isBasic();
    });
    boolean hasYanggu = alreadyTargeted.getCards(game).stream().filter(Objects::nonNull).map(MageObject::getName).anyMatch(name::equals);
    possibleTargets.removeIf(uuid -> {
        Card card = game.getCard(uuid);
        return card != null && hasYanggu && name.equals(card.getName());
    });
    return possibleTargets;
}
Also used : FilterCard(mage.filter.FilterCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Zone(mage.constants.Zone) mage.cards(mage.cards) Outcome(mage.constants.Outcome) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) Predicates(mage.filter.predicate.Predicates) UUID(java.util.UUID) Player(mage.players.Player) Objects(java.util.Objects) Game(mage.game.Game) TargetCard(mage.target.TargetCard) CardType(mage.constants.CardType) MageObject(mage.MageObject) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) SuperType(mage.constants.SuperType) Ability(mage.abilities.Ability) Objects(java.util.Objects) MageObject(mage.MageObject) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 85 with MageObject

use of mage.MageObject in project mage by magefree.

the class KyrenArchiveReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card != null) {
            UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
            card.setFaceDown(true, game);
            controller.moveCardsToExile(card, source, game, false, exileZoneId, sourceObject.getIdName());
            card.setFaceDown(true, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) Card(mage.cards.Card)

Aggregations

MageObject (mage.MageObject)738 Player (mage.players.Player)554 Permanent (mage.game.permanent.Permanent)239 UUID (java.util.UUID)224 Card (mage.cards.Card)210 FilterCard (mage.filter.FilterCard)113 CardsImpl (mage.cards.CardsImpl)106 TargetCard (mage.target.TargetCard)91 Cards (mage.cards.Cards)73 Spell (mage.game.stack.Spell)68 FixedTarget (mage.target.targetpointer.FixedTarget)66 HashSet (java.util.HashSet)56 Ability (mage.abilities.Ability)52 ContinuousEffect (mage.abilities.effects.ContinuousEffect)51 TargetPermanent (mage.target.TargetPermanent)48 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)48 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)46 Target (mage.target.Target)44 Effect (mage.abilities.effects.Effect)42 OneShotEffect (mage.abilities.effects.OneShotEffect)41