Search in sources :

Example 36 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class GameImpl method loadCards.

@Override
public void loadCards(Set<Card> cards, UUID ownerId) {
    for (Card card : cards) {
        if (card instanceof PermanentCard) {
            card = ((PermanentCard) card).getCard();
        }
        // init each card by parts... if you add new type here then getInitAbilities must be
        // implemented too (it allows to split abilities between card and parts)
        // main card
        card.setOwnerId(ownerId);
        addCardToState(card);
        // parts
        if (card instanceof SplitCard) {
            // left
            Card leftCard = ((SplitCard) card).getLeftHalfCard();
            leftCard.setOwnerId(ownerId);
            addCardToState(leftCard);
            // right
            Card rightCard = ((SplitCard) card).getRightHalfCard();
            rightCard.setOwnerId(ownerId);
            addCardToState(rightCard);
        } else if (card instanceof ModalDoubleFacesCard) {
            // left
            Card leftCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
            leftCard.setOwnerId(ownerId);
            addCardToState(leftCard);
            // right
            Card rightCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
            rightCard.setOwnerId(ownerId);
            addCardToState(rightCard);
        } else if (card instanceof AdventureCard) {
            Card spellCard = ((AdventureCard) card).getSpellCard();
            spellCard.setOwnerId(ownerId);
            addCardToState(spellCard);
        }
    }
}
Also used : FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 37 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class CardUtil method putCardOntoBattlefieldWithEffects.

/**
 * Put card to battlefield without resolve (for cheats and tests only)
 *
 * @param source  must be non null (if you need it empty then use fakeSourceAbility)
 * @param game
 * @param newCard
 * @param player
 */
public static void putCardOntoBattlefieldWithEffects(Ability source, Game game, Card newCard, Player player) {
    // same logic as ZonesHandler->maybeRemoveFromSourceZone
    // workaround to put real permanent from one side (example: you call mdf card by cheats)
    Card permCard = getDefaultCardSideForBattlefield(game, newCard);
    // prepare card and permanent
    permCard.setZone(Zone.BATTLEFIELD, game);
    permCard.setOwnerId(player.getId());
    PermanentCard permanent;
    if (permCard instanceof MeldCard) {
        permanent = new PermanentMeld(permCard, player.getId(), game);
    } else {
        permanent = new PermanentCard(permCard, player.getId(), game);
    }
    // put onto battlefield with possible counters
    game.getPermanentsEntering().put(permanent.getId(), permanent);
    permCard.checkForCountersToAdd(permanent, source, game);
    permanent.entersBattlefield(source, game, Zone.OUTSIDE, false);
    game.addPermanent(permanent, game.getState().getNextPermanentOrderNumber());
    game.getPermanentsEntering().remove(permanent.getId());
    // workaround for special tapped status from test framework's command (addCard)
    if (permCard instanceof PermanentCard && ((PermanentCard) permCard).isTapped()) {
        permanent.setTapped(true);
    }
    // remove sickness
    permanent.removeSummoningSickness();
    // init effects on static abilities (init continuous effects; warning, game state contains copy)
    for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
        Optional<Ability> ability = game.getState().getContinuousEffects().getLayeredEffectAbilities(effect).stream().findFirst();
        if (ability.isPresent() && permanent.getId().equals(ability.get().getSourceId())) {
            effect.init(ability.get(), game, player.getId());
        }
    }
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) PermanentMeld(mage.game.permanent.PermanentMeld) ContinuousEffect(mage.abilities.effects.ContinuousEffect) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 38 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class EerieInterludeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null && controller != null) {
        Set<Card> toExile = new HashSet<>();
        for (UUID targetId : getTargetPointer().getTargets(game, source)) {
            Permanent targetCreature = game.getPermanent(targetId);
            if (targetCreature != null) {
                toExile.add(targetCreature);
            }
        }
        UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
        controller.moveCardsToExile(toExile, source, game, true, exileId, sourceObject.getIdName());
        Cards cardsToReturn = new CardsImpl();
        for (Card exiled : toExile) {
            if (exiled instanceof PermanentMeld) {
                MeldCard meldCard = (MeldCard) ((PermanentCard) exiled).getCard();
                Card topCard = meldCard.getTopHalfCard();
                Card bottomCard = meldCard.getBottomHalfCard();
                if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter()) {
                    cardsToReturn.add(topCard);
                }
                if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter()) {
                    cardsToReturn.add(bottomCard);
                }
            } else if (exiled.getZoneChangeCounter(game) == game.getState().getZoneChangeCounter(exiled.getId()) - 1) {
                cardsToReturn.add(exiled);
            }
        }
        Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
        effect.setTargetPointer(new FixedTargets(cardsToReturn, game));
        AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
        game.addDelayedTriggeredAbility(delayedAbility, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) FixedTargets(mage.target.targetpointer.FixedTargets) MageObject(mage.MageObject) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) PermanentCard(mage.game.permanent.PermanentCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) PermanentMeld(mage.game.permanent.PermanentMeld) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 39 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class NephaliaAcademyEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (event.getType() == GameEvent.EventType.DISCARD_CARD) {
        // only save card info if it's an opponent effect
        Card card = game.getCard(event.getTargetId());
        if (card != null) {
            boolean isAnOpponentEffect = false;
            MageObject object = game.getObject(event.getSourceId());
            if (object instanceof PermanentCard) {
                isAnOpponentEffect = game.getOpponents(source.getControllerId()).contains(((PermanentCard) object).getControllerId());
            } else if (object instanceof Spell) {
                isAnOpponentEffect = game.getOpponents(source.getControllerId()).contains(((Spell) object).getControllerId());
            } else if (object instanceof Card) {
                isAnOpponentEffect = game.getOpponents(source.getControllerId()).contains(((Card) object).getOwnerId());
            }
            if (isAnOpponentEffect) {
                cardId = card.getId();
                zoneChangeCounter = game.getState().getZoneChangeCounter(cardId);
            }
        }
        return false;
    }
    if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
        Player controller = game.getPlayer(source.getControllerId());
        Card card = game.getCard(event.getTargetId());
        if (controller != null && card != null) {
            cardId = null;
            zoneChangeCounter = 0;
            if (controller.chooseUse(outcome, "Put " + card.getIdName() + " on top of your library instead?", source, game)) {
                Cards cardsToLibrary = new CardsImpl(card);
                // reveal the card then put it on top of your library
                controller.revealCards(card.getName(), cardsToLibrary, game);
                controller.putCardsOnTopOfLibrary(cardsToLibrary, game, source, false);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard)

Example 40 with PermanentCard

use of mage.game.permanent.PermanentCard in project mage by magefree.

the class DermotaxiCopyApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
    if (sourcePermanent == null) {
        return false;
    }
    Card card = game.getCard(sourcePermanent.getImprinted().get(0));
    if (card == null) {
        return false;
    }
    Permanent newBluePrint = new PermanentCard(card, source.getControllerId(), game);
    newBluePrint.assignNewId();
    DermotaxiCopyApplier applier = new DermotaxiCopyApplier();
    applier.apply(game, newBluePrint, source, sourcePermanent.getId());
    CopyEffect copyEffect = new CopyEffect(Duration.EndOfTurn, newBluePrint, sourcePermanent.getId());
    copyEffect.newId();
    copyEffect.setApplier(applier);
    game.addEffect(copyEffect, source);
    return true;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard)

Aggregations

PermanentCard (mage.game.permanent.PermanentCard)42 Card (mage.cards.Card)22 Permanent (mage.game.permanent.Permanent)16 Player (mage.players.Player)16 Ability (mage.abilities.Ability)11 MageObject (mage.MageObject)9 CardInfo (mage.cards.repository.CardInfo)9 CopyEffect (mage.abilities.effects.common.CopyEffect)8 FilterCard (mage.filter.FilterCard)6 CopyApplier (mage.util.functions.CopyApplier)6 UUID (java.util.UUID)5 PermanentMeld (mage.game.permanent.PermanentMeld)4 Test (org.junit.Test)4 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)3 FilterCreatureCard (mage.filter.common.FilterCreatureCard)3 PermanentToken (mage.game.permanent.PermanentToken)3 TargetCard (mage.target.TargetCard)3 Matcher (java.util.regex.Matcher)2