Search in sources :

Example 1 with PermanentToken

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

the class PurgatoryReturnEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(getSourceId());
    if (sourcePermanent != null) {
        Player controller = game.getPlayer(sourcePermanent.getControllerId());
        if (controller != null) {
            ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
            Permanent permanent = zEvent.getTarget();
            if (permanent != null && zEvent.isDiesEvent() && !(permanent instanceof PermanentToken) && permanent.isCreature(game) && permanent.isOwnedBy(controller.getId())) {
                this.getEffects().get(0).setTargetPointer(new FixedTarget(permanent, game));
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) PermanentToken(mage.game.permanent.PermanentToken)

Example 2 with PermanentToken

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

the class GisaGloriousResurrectorReturnEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.getTarget() instanceof PermanentToken) {
        return player.moveCards(zEvent.getTarget(), Zone.EXILED, source, game);
    }
    game.getState().setValue("GisaGloriousResurrectorExile" + source.getSourceId().toString() + game.getState().getZoneChangeCounter(source.getSourceId()), source);
    return player.moveCardsToExile(zEvent.getTarget(), source, game, false, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Player(mage.players.Player) PermanentToken(mage.game.permanent.PermanentToken)

Example 3 with PermanentToken

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

the class ParallaxWaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObject(game);
    Player controller = game.getPlayer(source.getControllerId());
    if (sourceObject != null && controller != null) {
        int zoneChangeCounter = (sourceObject instanceof PermanentToken) ? source.getSourceObjectZoneChangeCounter() : source.getSourceObjectZoneChangeCounter() - 1;
        UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), zoneChangeCounter);
        if (exileZoneId != null) {
            ExileZone exileZone = game.getExile().getExileZone(exileZoneId);
            if (exileZone != null) {
                return controller.moveCards(exileZone.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) PermanentToken(mage.game.permanent.PermanentToken) UUID(java.util.UUID)

Example 4 with PermanentToken

use of mage.game.permanent.PermanentToken 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 5 with PermanentToken

use of mage.game.permanent.PermanentToken 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)

Aggregations

PermanentToken (mage.game.permanent.PermanentToken)40 Permanent (mage.game.permanent.Permanent)30 Player (mage.players.Player)14 ZoneChangeEvent (mage.game.events.ZoneChangeEvent)8 Test (org.junit.Test)8 UUID (java.util.UUID)7 MageObject (mage.MageObject)7 Card (mage.cards.Card)7 PermanentCard (mage.game.permanent.PermanentCard)6 Ability (mage.abilities.Ability)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)4 FixedTarget (mage.target.targetpointer.FixedTarget)4 Cards (mage.cards.Cards)3 CardsImpl (mage.cards.CardsImpl)3 CardType (mage.constants.CardType)3 Outcome (mage.constants.Outcome)3 Zone (mage.constants.Zone)3 Counters (mage.counters.Counters)3 FilterCard (mage.filter.FilterCard)3 ExileZone (mage.game.ExileZone)3