Search in sources :

Example 41 with MageObject

use of mage.MageObject in project mage by magefree.

the class SpoilsOfTheVaultEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (sourceObject == null || controller == null || cardName == null || cardName.isEmpty()) {
        return false;
    }
    Cards cardsToReveal = new CardsImpl();
    Cards cardsToExile = new CardsImpl();
    for (Card card : controller.getLibrary().getCards(game)) {
        if (card != null) {
            cardsToReveal.add(card);
            if (CardUtil.haveSameNames(card, cardName, game)) {
                controller.moveCards(card, Zone.HAND, source, game);
                break;
            } else {
                cardsToExile.add(card);
            }
        }
    }
    controller.revealCards(sourceObject.getIdName(), cardsToReveal, game);
    controller.moveCards(cardsToExile, Zone.EXILED, source, game);
    controller.loseLife(cardsToExile.size(), game, source, false);
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject)

Example 42 with MageObject

use of mage.MageObject in project mage by magefree.

the class SunscourgeChampionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && permanent != null && sourceObject != null) {
        controller.gainLife(permanent.getPower().getValue(), game, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject)

Example 43 with MageObject

use of mage.MageObject in project mage by magefree.

the class TestOfTalentsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    if (stackObject == null) {
        return false;
    }
    MageObject targetObject = game.getObject(stackObject.getSourceId());
    String cardName;
    if (targetObject instanceof Card) {
        cardName = targetObject.getName();
    } else {
        cardName = "";
    }
    UUID searchPlayerId = stackObject.getControllerId();
    Player player = game.getPlayer(searchPlayerId);
    if (player == null) {
        return false;
    }
    int previousCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    game.getStack().counter(source.getFirstTarget(), source, game);
    this.applySearchAndExile(game, source, cardName, searchPlayerId);
    int newCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
    if (previousCount > newCount) {
        player.drawCards(previousCount - newCount, source, game);
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) SearchTargetGraveyardHandLibraryForCardNameAndExileEffect(mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) Card(mage.cards.Card) Ability(mage.abilities.Ability) TargetSpell(mage.target.TargetSpell) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) Objects(java.util.Objects) UUID(java.util.UUID) Card(mage.cards.Card)

Example 44 with MageObject

use of mage.MageObject in project mage by magefree.

the class TrackDownEffect 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) {
        return false;
    }
    if (!controller.getLibrary().hasCards()) {
        return false;
    }
    Card card = controller.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    CardsImpl cards = new CardsImpl();
    cards.add(card);
    controller.revealCards(sourceObject.getName(), cards, game);
    if (card.isLand(game) || card.isCreature(game)) {
        controller.drawCards(1, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 45 with MageObject

use of mage.MageObject in project mage by magefree.

the class ExileAllCardsFromAllGraveyards method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject Valki = game.getObject(source.getSourceId());
    Set<Card> cardsToExile = new LinkedHashSet<>();
    if (controller != null && Valki != null) {
        UUID exileId = CardUtil.getExileZoneId(source.getSourceId().toString() + Valki.getZoneChangeCounter(game), game);
        for (UUID opponentId : game.getOpponents(controller.getId())) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                opponent.revealCards(source, opponent.getHand(), game);
                TargetCard targetToExile = new TargetCard(Zone.HAND, StaticFilters.FILTER_CARD_CREATURE);
                targetToExile.withChooseHint("card to exile");
                targetToExile.setNotTarget(true);
                if (controller.choose(Outcome.Exile, opponent.getHand(), targetToExile, game)) {
                    Card targetedCardToExile = game.getCard(targetToExile.getFirstTarget());
                    if (targetedCardToExile != null && game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
                        cardsToExile.add(targetedCardToExile);
                    }
                }
            }
        }
        // exile all cards at one time
        controller.moveCardsToExile(cardsToExile, source, game, true, exileId, Valki.getName());
        game.addDelayedTriggeredAbility(new ValkiGodOfLiesReturnExiledCardAbility(), source);
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) ModalDoubleFacesCard(mage.cards.ModalDoubleFacesCard)

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