Search in sources :

Example 51 with ContinuousEffect

use of mage.abilities.effects.ContinuousEffect in project mage by magefree.

the class WojekApothecaryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (target != null) {
            ObjectColor color = target.getColor(game);
            for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
                if (permanent.getColor(game).shares(color)) {
                    ContinuousEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, 1);
                    effect.setTargetPointer(new FixedTarget(permanent, game));
                    game.addEffect(effect, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ObjectColor(mage.ObjectColor) ContinuousEffect(mage.abilities.effects.ContinuousEffect) PreventDamageToTargetEffect(mage.abilities.effects.common.PreventDamageToTargetEffect)

Example 52 with ContinuousEffect

use of mage.abilities.effects.ContinuousEffect 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 53 with ContinuousEffect

use of mage.abilities.effects.ContinuousEffect in project mage by magefree.

the class DreadhordeArcanistReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
    if (card != null && controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getLogName() + '?', source, game)) {
        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
        controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
    }
    ContinuousEffect effect = new DreadhordeArcanistReplacementEffect(card.getId());
    effect.setTargetPointer(new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
    game.addEffect(effect, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) ApprovingObject(mage.ApprovingObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 54 with ContinuousEffect

use of mage.abilities.effects.ContinuousEffect in project mage by magefree.

the class DreamPillagerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        int amount = (Integer) getValue("damage");
        if (amount > 0) {
            Set<Card> cards = controller.getLibrary().getTopCards(game, amount);
            if (!cards.isEmpty()) {
                controller.moveCards(cards, Zone.EXILED, source, game);
                Cards canBeCast = new CardsImpl();
                for (Card card : cards) {
                    if (!card.isLand(game)) {
                        canBeCast.add(card);
                    }
                }
                ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
                effect.setTargetPointer(new FixedTargets(canBeCast, game));
                game.addEffect(effect, source);
            }
            return true;
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) PlayFromNotOwnHandZoneTargetEffect(mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect) FixedTargets(mage.target.targetpointer.FixedTargets) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 55 with ContinuousEffect

use of mage.abilities.effects.ContinuousEffect in project mage by magefree.

the class ExhaustionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getFirstTarget());
    if (player != null) {
        ContinuousEffect effect = new DontUntapInPlayersNextUntapStepAllEffect(filter);
        effect.setTargetPointer(new FixedTarget(player.getId()));
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) DontUntapInPlayersNextUntapStepAllEffect(mage.abilities.effects.common.DontUntapInPlayersNextUntapStepAllEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Aggregations

ContinuousEffect (mage.abilities.effects.ContinuousEffect)322 FixedTarget (mage.target.targetpointer.FixedTarget)245 Player (mage.players.Player)225 Permanent (mage.game.permanent.Permanent)202 Card (mage.cards.Card)97 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)76 UUID (java.util.UUID)65 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)55 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)50 MageObject (mage.MageObject)47 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)43 BoostTargetEffect (mage.abilities.effects.common.continuous.BoostTargetEffect)37 FilterCard (mage.filter.FilterCard)34 TargetPermanent (mage.target.TargetPermanent)33 Effect (mage.abilities.effects.Effect)32 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)31 OneShotEffect (mage.abilities.effects.OneShotEffect)30 Target (mage.target.Target)30 FilterPermanent (mage.filter.FilterPermanent)24 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)23