Search in sources :

Example 11 with PermanentCard

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

the class CardTestAPIImpl method addCard.

/**
 * Add any amount of cards to specified zone of specified player.
 *
 * @param gameZone {@link mage.constants.Zone} to add cards to.
 * @param player   {@link Player} to add cards for. Use either playerA or playerB.
 * @param cardName Card name in string format.
 * @param count    Amount of cards to be added.
 * @param tapped   In case gameZone is Battlefield, determines whether permanent should be tapped.
 *                 In case gameZone is other than Battlefield, {@link IllegalArgumentException} is thrown
 */
@Override
public void addCard(Zone gameZone, TestPlayer player, String cardName, int count, boolean tapped) {
    if (gameZone == Zone.BATTLEFIELD) {
        for (int i = 0; i < count; i++) {
            CardInfo cardInfo = CardRepository.instance.findCard(cardName);
            Card card = cardInfo != null ? cardInfo.getCard() : null;
            if (card == null) {
                throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
            }
            PermanentCard p = new PermanentCard(card, null, currentGame);
            p.setTapped(tapped);
            if (player.equals(playerA)) {
                battlefieldCardsA.add(p);
            } else if (player.equals(playerB)) {
                battlefieldCardsB.add(p);
            }
        }
    } else {
        if (tapped) {
            throw new IllegalArgumentException("Parameter tapped=true can be used only for Zone.BATTLEFIELD.");
        }
        List<Card> cards = getCardList(gameZone, player);
        for (int i = 0; i < count; i++) {
            CardInfo cardInfo = CardRepository.instance.findCard(cardName);
            Card card = cardInfo != null ? cardInfo.getCard() : null;
            cards.add(card);
        }
    }
}
Also used : CardInfo(mage.cards.repository.CardInfo) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard)

Example 12 with PermanentCard

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

the class AbilityPickerTest method getAbilitiesFromCard.

private Abilities<Ability> getAbilitiesFromCard(String cardName) {
    CardInfo info = CardRepository.instance.findCard(cardName);
    PermanentImpl permanent = new PermanentCard(info.getCard(), playerA.getId(), currentGame);
    return permanent.getAbilities(currentGame);
}
Also used : CardInfo(mage.cards.repository.CardInfo) PermanentImpl(mage.game.permanent.PermanentImpl) PermanentCard(mage.game.permanent.PermanentCard)

Example 13 with PermanentCard

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

the class LazavDimirMastermindCopyApplier method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent lazavDimirMastermind = game.getPermanent(source.getSourceId());
    Permanent newBluePrint = null;
    if (controller != null && lazavDimirMastermind != null) {
        Card copyFromCard = game.getCard(((FixedTarget) getTargetPointer()).getTarget());
        if (copyFromCard != null) {
            newBluePrint = new PermanentCard(copyFromCard, source.getControllerId(), game);
            newBluePrint.assignNewId();
            CopyApplier applier = new LazavDimirMastermindCopyApplier();
            applier.apply(game, newBluePrint, source, lazavDimirMastermind.getId());
            CopyEffect copyEffect = new CopyEffect(Duration.Custom, newBluePrint, lazavDimirMastermind.getId());
            copyEffect.newId();
            copyEffect.setApplier(applier);
            Ability newAbility = source.copy();
            copyEffect.init(newAbility, game);
            game.addEffect(copyEffect, newAbility);
        }
        return true;
    }
    return false;
}
Also used : CopyEffect(mage.abilities.effects.common.CopyEffect) PutCardIntoGraveFromAnywhereAllTriggeredAbility(mage.abilities.common.PutCardIntoGraveFromAnywhereAllTriggeredAbility) HexproofAbility(mage.abilities.keyword.HexproofAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) CopyApplier(mage.util.functions.CopyApplier) FilterCreatureCard(mage.filter.common.FilterCreatureCard) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard)

Example 14 with PermanentCard

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

the class ContinuousEffects method checkAbilityStillExists.

private boolean checkAbilityStillExists(Ability ability, ContinuousEffect effect, GameEvent event, Game game) {
    switch(// effects with fixed duration don't need an object with the source ability (e.g. a silence cast with isochronic Scepter has no more a card object
    effect.getDuration()) {
        case EndOfCombat:
        case EndOfGame:
        case EndOfStep:
        case EndOfTurn:
        case OneUse:
        case // custom duration means the effect ends itself if needed
        Custom:
            return true;
    }
    if (ability.getSourceId() == null) {
        // commander replacement effect
        return true;
    }
    MageObject object;
    if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD && event.getTargetId().equals(ability.getSourceId())) {
        object = ((ZoneChangeEvent) event).getTarget();
    } else {
        object = game.getObject(ability.getSourceId());
    }
    if (object == null) {
        return false;
    }
    boolean exists = true;
    if (!object.hasAbility(ability, game)) {
        exists = false;
        if (object instanceof PermanentCard) {
            PermanentCard permanent = (PermanentCard) object;
            if (permanent.isTransformable() && event.getType() == GameEvent.EventType.TRANSFORMED) {
                exists = permanent.getCard().hasAbility(ability, game);
            }
        }
    } else if (object instanceof PermanentCard) {
        PermanentCard permanent = (PermanentCard) object;
        if (permanent.isFaceDown(game) && !ability.getWorksFaceDown()) {
            return false;
        }
    } else if (object instanceof Spell) {
        Spell spell = (Spell) object;
        if (spell.isFaceDown(game) && !ability.getWorksFaceDown()) {
            return false;
        }
    }
    return exists;
}
Also used : MageObject(mage.MageObject) Spell(mage.game.stack.Spell) PermanentCard(mage.game.permanent.PermanentCard)

Example 15 with PermanentCard

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

the class GameImpl method cheat.

@Override
public void cheat(UUID ownerId, List<Card> library, List<Card> hand, List<PermanentCard> battlefield, List<Card> graveyard, List<Card> command) {
    // fake test ability for triggers and events
    Ability fakeSourceAbilityTemplate = new SimpleStaticAbility(Zone.OUTSIDE, new InfoEffect("adding testing cards"));
    fakeSourceAbilityTemplate.setControllerId(ownerId);
    Player player = getPlayer(ownerId);
    if (player != null) {
        loadCards(ownerId, library);
        loadCards(ownerId, hand);
        loadCards(ownerId, battlefield);
        loadCards(ownerId, graveyard);
        loadCards(ownerId, command);
        for (Card card : library) {
            player.getLibrary().putOnTop(card, this);
        }
        for (Card card : hand) {
            card.setZone(Zone.HAND, this);
            player.getHand().add(card);
        }
        for (Card card : graveyard) {
            card.setZone(Zone.GRAVEYARD, this);
            player.getGraveyard().add(card);
        }
        // as commander (only commander games, look at init code in GameCommanderImpl)
        if (this instanceof GameCommanderImpl) {
            for (Card card : command) {
                ((GameCommanderImpl) this).addCommander(card, player);
            // no needs in initCommander call -- it's uses on game startup (init)
            }
        } else if (!command.isEmpty()) {
            throw new IllegalArgumentException("Command zone supports in commander test games");
        }
        for (PermanentCard permanentCard : battlefield) {
            Ability fakeSourceAbility = fakeSourceAbilityTemplate.copy();
            fakeSourceAbility.setSourceId(permanentCard.getId());
            CardUtil.putCardOntoBattlefieldWithEffects(fakeSourceAbility, this, permanentCard, player);
        }
        applyEffects();
    }
}
Also used : SagaAbility(mage.abilities.common.SagaAbility) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) AttachableToRestrictedAbility(mage.abilities.common.AttachableToRestrictedAbility) TriggeredManaAbility(mage.abilities.mana.TriggeredManaAbility) DelayedTriggeredManaAbility(mage.abilities.mana.DelayedTriggeredManaAbility) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) CantHaveMoreThanAmountCountersSourceAbility(mage.abilities.common.CantHaveMoreThanAmountCountersSourceAbility) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) InfoEffect(mage.abilities.effects.common.InfoEffect) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) PermanentCard(mage.game.permanent.PermanentCard) 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