Search in sources :

Example 26 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class SpellAbility method canActivate.

@Override
public ActivationStatus canActivate(UUID playerId, Game game) {
    if (this.spellCanBeActivatedRegularlyNow(playerId, game)) {
        if (spellAbilityType == SpellAbilityType.SPLIT || spellAbilityType == SpellAbilityType.SPLIT_AFTERMATH) {
            return ActivationStatus.getFalse();
        }
        // play from not own hand
        ApprovingObject approvingObject = game.getContinuousEffects().asThough(getSourceId(), AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, this, playerId, game);
        if (approvingObject == null) {
            Card card = game.getCard(sourceId);
            if (!(card != null && card.isOwnedBy(playerId))) {
                return ActivationStatus.getFalse();
            }
        }
        // Check if rule modifying events prevent to cast the spell in check playable mode
        if (game.inCheckPlayableState()) {
            Card card = game.getCard(sourceId);
            GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, this.getId(), this, playerId);
            castEvent.setZone(card == null ? null : game.getState().getZone(card.getMainCard().getId()));
            if (game.getContinuousEffects().preventedByRuleModification(castEvent, this, game, true)) {
                return ActivationStatus.getFalse();
            }
        }
        // Alternate spell abilities (Flashback, Overload) can't be cast with no mana to pay option
        if (getSpellAbilityType() == SpellAbilityType.BASE_ALTERNATE) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.getCastSourceIdWithAlternateMana().contains(getSourceId())) {
                return ActivationStatus.getFalse();
            }
        }
        // can pay all costs and choose targets
        if (costs.canPay(this, this, playerId, game)) {
            if (getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
                SplitCard splitCard = (SplitCard) game.getCard(getSourceId());
                if (splitCard != null) {
                    // see https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/magic-rulings-archives/251926-snapcaster-mage-and-fuse
                    if (game.getState().getZone(splitCard.getId()) == Zone.HAND) {
                        return new ActivationStatus(splitCard.getLeftHalfCard().getSpellAbility().canChooseTarget(game, playerId) && splitCard.getRightHalfCard().getSpellAbility().canChooseTarget(game, playerId), null);
                    }
                }
                return ActivationStatus.getFalse();
            } else {
                return new ActivationStatus(canChooseTarget(game, playerId), approvingObject);
            }
        }
    }
    return ActivationStatus.getFalse();
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) GameEvent(mage.game.events.GameEvent) SplitCard(mage.cards.SplitCard) SplitCard(mage.cards.SplitCard) Card(mage.cards.Card)

Example 27 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class HideawayPlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    ExileZone zone = null;
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (permanent != null) {
        zone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), permanent.getZoneChangeCounter(game)));
    }
    if (zone == null) {
        return true;
    }
    Set<Card> cards = zone.getCards(game);
    if (cards.isEmpty()) {
        return true;
    }
    Card card = cards.iterator().next();
    Player controller = game.getPlayer(source.getControllerId());
    if (card != null && controller != null) {
        if (controller.chooseUse(Outcome.PlayForFree, "Play " + card.getIdName() + " for free?", source, game)) {
            card.setFaceDown(false, game);
            int zcc = card.getZoneChangeCounter(game);
            /* 702.74. Hideaway, rulings:
                 * If the removed card is a land, you may play it as a result of the last ability only if it's your turn
                 * and you haven't already played a land that turn. This counts as your land play for the turn.
                 */
            if (card.isLand(game)) {
                UUID playerId = controller.getId();
                if (!game.isActivePlayer(playerId) || !game.getPlayer(playerId).canPlayLand()) {
                    return false;
                }
            }
            if (!controller.playCard(card, game, true, new ApprovingObject(source, game))) {
                if (card.getZoneChangeCounter(game) == zcc) {
                    card.setFaceDown(true, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) Card(mage.cards.Card)

Example 28 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class BloodthirstyAdversaryCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<Card> cardsToExile = new LinkedHashSet<>();
    for (UUID cardId : targetPointer.getTargets(game, source)) {
        Card card = game.getCard(cardId);
        if (card != null) {
            cardsToExile.add(card);
        }
    }
    if (cardsToExile.isEmpty()) {
        return false;
    }
    controller.moveCards(cardsToExile, Zone.EXILED, source, game);
    ApprovingObject approvingObject = new ApprovingObject(source, game);
    for (Card card : cardsToExile) {
        Card copiedCard = game.copyCard(card, source, controller.getId());
        if (copiedCard != null && controller.chooseUse(outcome, "Cast " + copiedCard.getName() + " for free?", source, game)) {
            game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
            controller.cast(controller.chooseAbilityForCast(copiedCard, game, true), game, true, approvingObject);
            game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
        }
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) UUID(java.util.UUID) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 29 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class ChunLiCountlessKicksCastEffect 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.getExile().getAllCards(game, source.getControllerId()));
    cards.removeIf(uuid -> !game.getCard(uuid).getCounters(game).containsKey(CounterType.KICK));
    if (cards.isEmpty()) {
        return false;
    }
    Cards copies = new CardsImpl();
    for (Card card : cards.getCards(game)) {
        Card copiedCard = game.copyCard(card, source, source.getControllerId());
        game.getExile().add(source.getSourceId(), "", copiedCard);
        game.getState().setZone(copiedCard.getId(), Zone.EXILED);
        copies.add(copiedCard);
    }
    for (Card copiedCard : copies.getCards(game)) {
        if (!player.chooseUse(outcome, "Cast the copied card?", source, game)) {
            continue;
        }
        if (copiedCard.getSpellAbility() != null) {
            game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
            player.cast(player.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
            game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
        } else {
            Logger.getLogger(ChunLiCountlessKicksCastEffect.class).error("Chun Li, Countless Kicks: " + "spell ability == null " + copiedCard.getName());
        }
    }
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) FilterCard(mage.filter.FilterCard)

Example 30 with ApprovingObject

use of mage.ApprovingObject in project mage by magefree.

the class DazzlingSphinxEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller == null || opponent == null) {
        return false;
    }
    Cards cards = new CardsImpl();
    Card toCast = null;
    for (Card card : opponent.getLibrary().getCards(game)) {
        cards.add(card);
        if (card.isInstantOrSorcery(game)) {
            toCast = card;
        }
    }
    opponent.moveCards(cards, Zone.EXILED, source, game);
    if (toCast != null && controller.chooseUse(outcome, "Cast " + toCast.getName() + " without paying its mana cost?", source, game)) {
        game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), Boolean.TRUE);
        controller.cast(controller.chooseAbilityForCast(toCast, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), null);
    }
    cards.retainZone(Zone.EXILED, game);
    opponent.putCardsOnBottomOfLibrary(cards, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject)

Aggregations

ApprovingObject (mage.ApprovingObject)111 Player (mage.players.Player)109 Card (mage.cards.Card)77 FilterCard (mage.filter.FilterCard)53 TargetCard (mage.target.TargetCard)30 MageObject (mage.MageObject)20 FilterInstantOrSorceryCard (mage.filter.common.FilterInstantOrSorceryCard)17 CardsImpl (mage.cards.CardsImpl)16 Permanent (mage.game.permanent.Permanent)16 UUID (java.util.UUID)15 TargetCardInHand (mage.target.common.TargetCardInHand)13 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 FilterNonlandCard (mage.filter.common.FilterNonlandCard)10 TargetCardInExile (mage.target.common.TargetCardInExile)10 ExileZone (mage.game.ExileZone)9 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)9 Cards (mage.cards.Cards)8 Spell (mage.game.stack.Spell)8 Target (mage.target.Target)7 FixedTarget (mage.target.targetpointer.FixedTarget)7