Search in sources :

Example 1 with PermanentCard

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

the class DollhouseOfHorrorsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (card == null) {
        return false;
    }
    CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), CardType.ARTIFACT, false, 1, false, false, null, 0, 0, false);
    effect.setSavedPermanent(new PermanentCard(card, source.getControllerId(), game));
    effect.setAdditionalSubType(SubType.CONSTRUCT);
    effect.addAdditionalAbilities(new SimpleStaticAbility(new BoostSourceEffect(ArtifactYouControlCount.instance, ArtifactYouControlCount.instance, Duration.WhileOnBattlefield).setText("This creature gets +1/+1 for each artifact you control")));
    effect.apply(game, source);
    game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn).setTargetPointer(new FixedTargets(effect.getAddedPermanents(), game)), source);
    return true;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) FixedTargets(mage.target.targetpointer.FixedTargets) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 2 with PermanentCard

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

the class CopyEffect method copyToPermanent.

protected boolean copyToPermanent(Permanent permanent, Game game, Ability source) {
    if (copyFromObject.getCopyFrom() != null) {
        // copy from temp blueprints (they are already copies)
        permanent.setCopy(true, copyFromObject.getCopyFrom());
    } else {
        // copy object to object
        permanent.setCopy(true, copyFromObject);
    }
    permanent.setName(copyFromObject.getName());
    permanent.getColor(game).setColor(copyFromObject.getColor(game));
    permanent.getManaCost().clear();
    permanent.getManaCost().add(copyFromObject.getManaCost().copy());
    permanent.removeAllCardTypes(game);
    for (CardType type : copyFromObject.getCardType(game)) {
        permanent.addCardType(game, type);
    }
    permanent.removeAllSubTypes(game);
    permanent.copySubTypesFrom(game, copyFromObject);
    permanent.getSuperType().clear();
    for (SuperType type : copyFromObject.getSuperType()) {
        permanent.addSuperType(type);
    }
    permanent.removeAllAbilities(source.getSourceId(), game);
    if (copyFromObject instanceof Permanent) {
        for (Ability ability : ((Permanent) copyFromObject).getAbilities(game)) {
            permanent.addAbility(ability, getSourceId(), game);
        }
    } else {
        for (Ability ability : copyFromObject.getAbilities()) {
            permanent.addAbility(ability, getSourceId(), game);
        }
    }
    // Primal Clay example:
    // If a creature that’s already on the battlefield becomes a copy of this creature, it copies the power, toughness,
    // and abilities that were chosen for this creature as it entered the battlefield. (2018-03-16)
    permanent.getPower().setValue(copyFromObject.getPower().getBaseValueModified());
    permanent.getToughness().setValue(copyFromObject.getToughness().getBaseValueModified());
    permanent.setStartingLoyalty(copyFromObject.getStartingLoyalty());
    if (copyFromObject instanceof Permanent) {
        Permanent targetPermanent = (Permanent) copyFromObject;
        permanent.setTransformed(targetPermanent.isTransformed());
        permanent.setSecondCardFace(targetPermanent.getSecondCardFace());
        permanent.setFlipCard(targetPermanent.isFlipCard());
        permanent.setFlipCardName(targetPermanent.getFlipCardName());
    }
    // to get the image of the copied permanent copy number und expansionCode
    if (copyFromObject instanceof PermanentCard) {
        permanent.setCardNumber(((PermanentCard) copyFromObject).getCard().getCardNumber());
        permanent.setExpansionSetCode(((PermanentCard) copyFromObject).getCard().getExpansionSetCode());
    } else if (copyFromObject instanceof PermanentToken || copyFromObject instanceof Card) {
        permanent.setCardNumber(((Card) copyFromObject).getCardNumber());
        permanent.setExpansionSetCode(((Card) copyFromObject).getExpansionSetCode());
    }
    return true;
}
Also used : Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card)

Example 3 with PermanentCard

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

the class CopyEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    // must copy the default side of the card (example: clone with mdf card)
    if (!(copyFromObject instanceof Permanent) && (copyFromObject instanceof Card)) {
        Card newBluePrint = CardUtil.getDefaultCardSideForBattlefield(game, (Card) copyFromObject);
        this.copyFromObject = new PermanentCard(newBluePrint, source.getControllerId(), game);
    }
    Permanent permanent = game.getPermanent(copyToObjectId);
    if (permanent != null) {
        affectedObjectList.add(new MageObjectReference(permanent, game));
    } else if (source.getAbilityType() == AbilityType.STATIC) {
        // for replacement effects that let a permanent enter the battlefield as a copy of another permanent we need to apply that copy
        // before the permanent is added to the battlefield
        permanent = game.getPermanentEntering(copyToObjectId);
        if (permanent != null) {
            copyToPermanent(permanent, game, source);
            // set reference to the permanent later on the battlefield so we have to add already one (if no token) to the zone change counter
            int ZCCDiff = 1;
            if (permanent instanceof PermanentToken) {
                ZCCDiff = 0;
            }
            affectedObjectList.add(new MageObjectReference(permanent.getId(), game.getState().getZoneChangeCounter(copyToObjectId) + ZCCDiff, game));
        }
    }
}
Also used : Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken) MageObjectReference(mage.MageObjectReference) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard)

Example 4 with PermanentCard

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

the class CardTestPlayerAPIImpl 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) {
    // aliases for mage objects
    String aliasName = "";
    boolean useAliasMultiNames = (count != 1);
    if (cardName.contains(ALIAS_PREFIX)) {
        aliasName = cardName.substring(cardName.indexOf(ALIAS_PREFIX) + ALIAS_PREFIX.length());
        cardName = cardName.substring(0, cardName.indexOf(ALIAS_PREFIX));
    }
    // one card = one aliase, massive adds can use auto-name
    if (!useAliasMultiNames && !aliasName.isEmpty() && player.getAliasByName(aliasName) != null) {
        Assert.fail("Can't add card " + cardName + " - alias " + aliasName + " already exists for " + player.getName());
    }
    // game tests don't need cards from a specific set, so it can be from any set
    CardInfo cardInfo = CardRepository.instance.findCard(cardName, true);
    if (cardInfo == null) {
        throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
    }
    if (gameZone == Zone.BATTLEFIELD) {
        for (int i = 0; i < count; i++) {
            Card newCard = cardInfo.getCard();
            Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
            PermanentCard p = new PermanentCard(permCard, player.getId(), currentGame);
            p.setTapped(tapped);
            getBattlefieldCards(player).add(p);
            if (!aliasName.isEmpty()) {
                player.addAlias(player.generateAliasName(aliasName, useAliasMultiNames, i + 1), p.getId());
            }
        }
    } 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++) {
            Card newCard = cardInfo.getCard();
            cards.add(newCard);
            if (!aliasName.isEmpty()) {
                player.addAlias(player.generateAliasName(aliasName, useAliasMultiNames, i + 1), newCard.getId());
            }
        }
    }
}
Also used : CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 5 with PermanentCard

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

the class SerializationTest method test_PermanentImpl_Simple.

@Test
public void test_PermanentImpl_Simple() {
    CardInfo cardInfo = CardRepository.instance.findCard("Balduvian Bears");
    Card newCard = cardInfo.getCard();
    Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
    PermanentImpl permanent = new PermanentCard(permCard, playerA.getId(), currentGame);
    currentGame.addPermanent(permanent, 0);
    Object compressed = CompressUtil.compress(permanent);
    Assert.assertTrue("Must be zip", compressed instanceof ZippedObjectImpl);
    PermanentImpl uncompressed = (PermanentImpl) CompressUtil.decompress(compressed);
    Assert.assertEquals("Must be same", permanent.getName(), uncompressed.getName());
}
Also used : CardInfo(mage.cards.repository.CardInfo) PermanentImpl(mage.game.permanent.PermanentImpl) ZippedObjectImpl(mage.remote.traffic.ZippedObjectImpl) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard) Test(org.junit.Test)

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