Search in sources :

Example 41 with ContinuousEffect

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

the class ParoxysmEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent aura = game.getPermanent(source.getSourceId());
    if (aura != null) {
        Permanent creatureAttachedTo = game.getPermanent(aura.getAttachedTo());
        if (creatureAttachedTo != null) {
            Player controllerOfCreature = game.getPlayer(creatureAttachedTo.getControllerId());
            if (controllerOfCreature != null) {
                Card revealCardFromTop = controllerOfCreature.getLibrary().getFromTop(game);
                if (revealCardFromTop != null) {
                    Cards cards = new CardsImpl(revealCardFromTop);
                    controllerOfCreature.revealCards(source, cards, game);
                    if (revealCardFromTop.isLand(game)) {
                        creatureAttachedTo.destroy(source, game, false);
                    } else {
                        ContinuousEffect effect = new BoostTargetEffect(3, 3, Duration.EndOfTurn);
                        effect.setTargetPointer(new FixedTarget(creatureAttachedTo.getId(), game));
                        game.addEffect(effect, source);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 42 with ContinuousEffect

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

the class PredatorsHourLookEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (opponent == null) {
        return false;
    }
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject == null) {
        return false;
    }
    Card topCard = opponent.getLibrary().getFromTop(game);
    if (topCard == null) {
        return false;
    }
    UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    topCard.setFaceDown(true, game);
    // Move card to exile
    if (controller.moveCardsToExile(topCard, source, game, false, exileZoneId, sourceObject.getIdName())) {
        topCard.setFaceDown(true, game);
        Set<UUID> exileZones = (Set<UUID>) game.getState().getValue(VALUE_PREFIX + source.getSourceId().toString());
        if (exileZones == null) {
            exileZones = new HashSet<>();
            game.getState().setValue(VALUE_PREFIX + source.getSourceId().toString(), exileZones);
        }
        exileZones.add(exileZoneId);
        // You may play the card
        ContinuousEffect effect = new PredatorsHourPlayFromExileEffect();
        effect.setTargetPointer(new FixedTarget(topCard.getId(), game));
        game.addEffect(effect, source);
        // And you may spend mana as though it were mana of any color to cast it
        effect = new PredatorsHourSpendAnyManaEffect();
        effect.setTargetPointer(new FixedTarget(topCard.getId(), game));
        game.addEffect(effect, source);
        // For as long as that card remains exiled, you may look at it
        effect = new PredatorsHourLookEffect(controller.getId());
        effect.setTargetPointer(new FixedTarget(topCard.getId(), game));
        game.addEffect(effect, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Set(java.util.Set) HashSet(java.util.HashSet) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

Example 43 with ContinuousEffect

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

the class RhythmOfTheWildEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player player = game.getPlayer(source.getControllerId());
    if (creature == null || player == null) {
        return false;
    }
    if (player.chooseUse(outcome, "Have " + creature.getLogName() + " enter the battlefield with a +1/+1 counter on it or with haste?", null, "+1/+1 counter", "Haste", source, game)) {
        game.informPlayers(player.getLogName() + " choose to put a +1/+1 counter on " + creature.getName());
        creature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game, event.getAppliedEffects());
    } else {
        ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
        effect.setTargetPointer(new FixedTarget(creature.getId(), creature.getZoneChangeCounter(game) + 1));
        game.addEffect(effect, source);
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 44 with ContinuousEffect

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

the class RideDownEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent blockingCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (blockingCreature != null) {
            for (CombatGroup combatGroup : game.getCombat().getGroups()) {
                if (combatGroup.getBlockers().contains(blockingCreature.getId())) {
                    for (UUID attackerId : combatGroup.getAttackers()) {
                        ContinuousEffect effect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
                        effect.setTargetPointer(new FixedTarget(attackerId, game));
                        game.addEffect(effect, source);
                    }
                    break;
                }
            }
            blockingCreature.destroy(source, game, false);
        }
        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) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup)

Example 45 with ContinuousEffect

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

the class DoUnlessAnyOpponentPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        String message;
        if (chooseUseText == null) {
            String effectText = executingEffects.getText(source.getModes().getMode());
            message = "Pay " + cost.getText() + " to prevent (" + effectText.substring(0, effectText.length() - 1) + ")?";
        } else {
            message = chooseUseText;
        }
        message = CardUtil.replaceSourceName(message, sourceObject.getName());
        boolean result = true;
        boolean doEffect = true;
        // check if any opponent is willing to pay
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.canRespond() && !player.equals(controller) && cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Benefit, message, source, game)) {
                cost.clearPaid();
                if (cost.pay(source, game, source, player.getId(), false, null)) {
                    if (!game.isSimulation()) {
                        game.informPlayers(player.getLogName() + " pays the cost to prevent the effect");
                    }
                    doEffect = false;
                    break;
                }
            }
        }
        // do the effects if nobody paid
        if (doEffect) {
            for (Effect effect : executingEffects) {
                effect.setTargetPointer(this.targetPointer);
                if (effect instanceof OneShotEffect) {
                    result &= effect.apply(game, source);
                } else {
                    game.addEffect((ContinuousEffect) effect, source);
                }
            }
        }
        return result;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ConditionalContinuousEffect(mage.abilities.decorator.ConditionalContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) OneShotEffect(mage.abilities.effects.OneShotEffect)

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