Search in sources :

Example 1 with EmptyToken

use of mage.game.permanent.token.EmptyToken in project mage by magefree.

the class MechanizedProductionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourceObject != null && sourceObject.getAttachedTo() != null) {
        Permanent enchantedArtifact = game.getPermanentOrLKIBattlefield(sourceObject.getAttachedTo());
        if (enchantedArtifact != null) {
            EmptyToken token = new EmptyToken();
            CardUtil.copyTo(token).from(enchantedArtifact, game);
            token.putOntoBattlefield(1, game, source, source.getControllerId());
        }
        Map<String, Integer> countNames = new HashMap<>();
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterArtifactPermanent(), source.getControllerId(), game)) {
            int counter = countNames.getOrDefault(permanent.getName(), 0);
            countNames.put(permanent.getName(), counter + 1);
        }
        for (Entry<String, Integer> entry : countNames.entrySet()) {
            if (entry.getValue() > 7) {
                Player controller = game.getPlayer(source.getControllerId());
                if (controller != null) {
                    game.informPlayers(controller.getLogName() + " controls eight or more artifacts with the same name as one another (" + entry.getKey() + ").");
                    controller.won(game);
                    return true;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetPermanent(mage.target.TargetPermanent) HashMap(java.util.HashMap) EmptyToken(mage.game.permanent.token.EmptyToken)

Example 2 with EmptyToken

use of mage.game.permanent.token.EmptyToken in project mage by magefree.

the class CreateTokenCopyTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID targetId;
    if (getTargetPointer() instanceof FixedTarget) {
        targetId = ((FixedTarget) getTargetPointer()).getTarget();
    } else {
        targetId = getTargetPointer().getFirst(game, source);
    }
    Permanent permanent;
    if (savedPermanent != null) {
        permanent = savedPermanent;
    } else if (useLKI) {
        permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    } else {
        permanent = game.getPermanentOrLKIBattlefield(targetId);
    }
    // can target card or permanent
    Card copyFrom;
    CopyApplier applier = new EmptyCopyApplier();
    if (permanent != null) {
        // handle copies of copies
        Permanent copyFromPermanent = permanent;
        for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
            if (effect instanceof CopyEffect) {
                CopyEffect copyEffect = (CopyEffect) effect;
                // there is another copy effect that our targetPermanent copies stats from
                if (copyEffect.getSourceId().equals(permanent.getId())) {
                    MageObject object = ((CopyEffect) effect).getTarget();
                    if (object instanceof Permanent) {
                        copyFromPermanent = (Permanent) object;
                        if (copyEffect.getApplier() != null) {
                            applier = copyEffect.getApplier();
                        }
                    }
                }
            }
        }
        copyFrom = copyFromPermanent;
    } else {
        copyFrom = game.getCard(getTargetPointer().getFirst(game, source));
    }
    if (copyFrom == null) {
        return false;
    }
    // create token and modify all attributes permanently (without game usage)
    EmptyToken token = new EmptyToken();
    // needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
    CardUtil.copyTo(token).from(copyFrom, game);
    applier.apply(game, token, source, targetId);
    if (becomesArtifact) {
        token.addCardType(CardType.ARTIFACT);
    }
    if (isntLegendary) {
        token.getSuperType().remove(SuperType.LEGENDARY);
    }
    if (startingLoyalty != -1) {
        token.setStartingLoyalty(startingLoyalty);
    }
    if (additionalCardType != null) {
        token.addCardType(additionalCardType);
    }
    if (hasHaste) {
        token.addAbility(HasteAbility.getInstance());
    }
    if (gainsFlying) {
        token.addAbility(FlyingAbility.getInstance());
    }
    if (tokenPower != Integer.MIN_VALUE) {
        token.removePTCDA();
        token.getPower().modifyBaseValue(tokenPower);
    }
    if (tokenToughness != Integer.MIN_VALUE) {
        token.removePTCDA();
        token.getToughness().modifyBaseValue(tokenToughness);
    }
    if (onlySubType != null) {
        token.removeAllCreatureTypes();
        token.addSubType(onlySubType);
    }
    if (additionalSubType != null) {
        token.addSubType(additionalSubType);
    }
    if (color != null) {
        token.getColor().setColor(color);
    }
    additionalAbilities.stream().forEach(token::addAbility);
    if (!this.abilityClazzesToRemove.isEmpty()) {
        List<Ability> abilitiesToRemoveTmp = new ArrayList<>();
        // Find the ones to remove
        for (Ability ability : token.getAbilities()) {
            if (this.abilityClazzesToRemove.contains(ability.getClass())) {
                abilitiesToRemoveTmp.add(ability);
            }
        }
        // Remove them
        for (Ability ability : abilitiesToRemoveTmp) {
            // Remove subabilities
            token.removeAbilities(ability.getSubAbilities());
            // Remove the ability
            token.removeAbility(ability);
        }
    }
    token.putOntoBattlefield(number, game, source, playerId == null ? source.getControllerId() : playerId, tapped, attacking, attackedPlayer);
    for (UUID tokenId : token.getLastAddedTokenIds()) {
        // by cards like Doubling Season multiple tokens can be added to the battlefield
        Permanent tokenPermanent = game.getPermanent(tokenId);
        if (tokenPermanent != null) {
            addedTokenPermanents.add(tokenPermanent);
            // add counters if necessary ie Ochre Jelly
            if (counter != null && numberOfCounters > 0) {
                tokenPermanent.addCounters(counter.createInstance(numberOfCounters), source.getControllerId(), source, game);
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) HasteAbility(mage.abilities.keyword.HasteAbility) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) FlyingAbility(mage.abilities.keyword.FlyingAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) Ability(mage.abilities.Ability) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) Card(mage.cards.Card) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) CopyApplier(mage.util.functions.CopyApplier) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) ContinuousEffect(mage.abilities.effects.ContinuousEffect) EmptyToken(mage.game.permanent.token.EmptyToken)

Example 3 with EmptyToken

use of mage.game.permanent.token.EmptyToken in project mage by magefree.

the class HourOfEternityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Card> cardsToExile = new HashSet<>(this.getTargetPointer().getTargets(game, source).size());
        for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
            Card card = controller.getGraveyard().get(targetId, game);
            if (card != null) {
                cardsToExile.add(card);
            }
        }
        controller.moveCardsToExile(cardsToExile, source, game, true, null, "");
        for (Card card : cardsToExile) {
            if (game.getState().getZone(card.getId()) == Zone.EXILED) {
                // create token and modify all attributes permanently (without game usage)
                EmptyToken token = new EmptyToken();
                CardUtil.copyTo(token).from(card, game);
                token.removePTCDA();
                token.getPower().modifyBaseValue(4);
                token.getToughness().modifyBaseValue(4);
                token.getColor().setColor(ObjectColor.BLACK);
                token.removeAllCreatureTypes();
                token.addSubType(SubType.ZOMBIE);
                token.putOntoBattlefield(1, game, source, source.getControllerId());
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) HashSet(java.util.HashSet) EmptyToken(mage.game.permanent.token.EmptyToken)

Example 4 with EmptyToken

use of mage.game.permanent.token.EmptyToken in project mage by magefree.

the class PrototypePortalCreateTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent == null) {
        return false;
    }
    if (!permanent.getImprinted().isEmpty()) {
        Card card = game.getCard(permanent.getImprinted().get(0));
        if (card != null) {
            EmptyToken token = new EmptyToken();
            CardUtil.copyTo(token).from(card, game);
            token.putOntoBattlefield(1, game, source, source.getControllerId());
            return true;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) EmptyToken(mage.game.permanent.token.EmptyToken)

Example 5 with EmptyToken

use of mage.game.permanent.token.EmptyToken in project mage by magefree.

the class EmbalmEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getSourceId());
    if (card == null) {
        return false;
    }
    Player controller = game.getPlayer(card.getOwnerId());
    if (controller == null) {
        return false;
    }
    // create token and modify all attributes permanently (without game usage)
    EmptyToken token = new EmptyToken();
    // needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
    CardUtil.copyTo(token).from(card, game);
    token.getColor().setColor(ObjectColor.WHITE);
    token.addSubType(SubType.ZOMBIE);
    token.getManaCost().clear();
    game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EMBALMED_CREATURE, token.getId(), source, controller.getId()));
    token.putOntoBattlefield(1, game, source, controller.getId(), false, false, null);
    // Also it can never get active or? But it's not mentioned in the reminder text.
    return true;
}
Also used : Player(mage.players.Player) Card(mage.cards.Card) EmptyToken(mage.game.permanent.token.EmptyToken)

Aggregations

EmptyToken (mage.game.permanent.token.EmptyToken)13 Card (mage.cards.Card)9 Permanent (mage.game.permanent.Permanent)8 Player (mage.players.Player)6 MageObject (mage.MageObject)3 TargetPermanent (mage.target.TargetPermanent)3 HashSet (java.util.HashSet)2 UUID (java.util.UUID)2 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)2 AtTheEndOfCombatDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 FixedTargets (mage.target.targetpointer.FixedTargets)2 CopyApplier (mage.util.functions.CopyApplier)2 EmptyCopyApplier (mage.util.functions.EmptyCopyApplier)2 HashMap (java.util.HashMap)1 MageObjectReference (mage.MageObjectReference)1 Ability (mage.abilities.Ability)1 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)1