Search in sources :

Example 41 with Card

use of mage.cards.Card in project mage by magefree.

the class ImpromptuRaidEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Card card = controller.getLibrary().getFromTop(game);
        if (card != null) {
            Cards cards = new CardsImpl();
            cards.add(card);
            controller.revealCards(sourceObject.getName(), cards, game);
            if (filterPutInGraveyard.match(card, source.getSourceId(), source.getControllerId(), game)) {
                controller.moveCards(card, Zone.GRAVEYARD, source, game);
                return true;
            }
            if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                Permanent permanent = game.getPermanent(card.getId());
                if (permanent != null) {
                    ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
                    effect.setTargetPointer(new FixedTarget(permanent, game));
                    game.addEffect(effect, source);
                    SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("", source.getControllerId());
                    sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
                    DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect);
                    game.addDelayedTriggeredAbility(delayedAbility, source);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) MageObject(mage.MageObject) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 42 with Card

use of mage.cards.Card in project mage by magefree.

the class ImmortalServitudeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    if (you == null) {
        return false;
    }
    int count = source.getManaCostsToPay().getX();
    Set<Card> cards = you.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game);
    cards.removeIf(Objects::isNull);
    cards.removeIf(card -> !card.isCreature(game));
    cards.removeIf(card -> card.getManaValue() != count);
    return you.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
Also used : Player(mage.players.Player) Objects(java.util.Objects) Card(mage.cards.Card)

Example 43 with Card

use of mage.cards.Card in project mage by magefree.

the class KaaliaOfTheVastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, "Put an Angel, Demon, or Dragon creature card from your hand onto the battlefield tapped and attacking?", source, game)) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(filter);
    if (target.canChoose(source.getSourceId(), controller.getId(), game) && target.choose(outcome, controller.getId(), source.getSourceId(), game)) {
        if (!target.getTargets().isEmpty()) {
            UUID cardId = target.getFirstTarget();
            Card card = game.getCard(cardId);
            if (card != null && game.getCombat() != null) {
                UUID defenderId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
                if (defenderId != null) {
                    controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
                    Permanent creature = game.getPermanent(cardId);
                    if (creature != null) {
                        game.getCombat().addAttackerToCombat(card.getId(), defenderId, game);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 44 with Card

use of mage.cards.Card in project mage by magefree.

the class JungleWayfinderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
                if (player.chooseUse(Outcome.Benefit, "Search your library for a card to put into your hand?", source, game)) {
                    player.searchLibrary(target, source, game);
                    for (UUID cardId : target.getTargets()) {
                        Card card = player.getLibrary().getCard(cardId, game);
                        if (card != null) {
                            player.revealCards(source, new CardsImpl(card), game);
                            player.moveCards(card, Zone.HAND, source, game);
                        }
                    }
                    player.shuffleLibrary(source, game);
                }
            }
        }
        // prevent undo
        controller.resetStoredBookmark(game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 45 with Card

use of mage.cards.Card in project mage by magefree.

the class KozilekDiscardCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Spell targetSpell = game.getStack().getSpell(ability.getFirstTarget());
    if (targetSpell == null) {
        return false;
    }
    Player player = game.getPlayer(controllerId);
    if (player == null) {
        return false;
    }
    FilterCard filter = new FilterCard("card with mana value of " + targetSpell.getManaValue());
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, targetSpell.getManaValue()));
    TargetCardInHand target = new TargetCardInHand(filter);
    this.getTargets().clear();
    this.getTargets().add(target);
    if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
        for (UUID targetId : targets.get(0).getTargets()) {
            Card card = player.getHand().get(targetId, game);
            if (card == null) {
                return false;
            }
            player.discard(card, true, source, game);
            paid = true;
        }
    }
    return paid;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) FilterSpell(mage.filter.FilterSpell) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Aggregations

Card (mage.cards.Card)1448 Player (mage.players.Player)1096 Permanent (mage.game.permanent.Permanent)423 FilterCard (mage.filter.FilterCard)381 UUID (java.util.UUID)340 CardsImpl (mage.cards.CardsImpl)253 MageObject (mage.MageObject)212 FixedTarget (mage.target.targetpointer.FixedTarget)173 TargetCard (mage.target.TargetCard)165 Cards (mage.cards.Cards)159 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)111 ContinuousEffect (mage.abilities.effects.ContinuousEffect)99 TargetCardInHand (mage.target.common.TargetCardInHand)98 Target (mage.target.Target)86 HashSet (java.util.HashSet)85 FilterCreatureCard (mage.filter.common.FilterCreatureCard)84 ApprovingObject (mage.ApprovingObject)77 Ability (mage.abilities.Ability)71 TargetPlayer (mage.target.TargetPlayer)67 TargetPermanent (mage.target.TargetPermanent)64