Search in sources :

Example 46 with ContinuousEffect

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

the class ShowOfDominanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int highestPower = Integer.MIN_VALUE;
        Permanent selectedCreature = null;
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
            if (highestPower < permanent.getPower().getValue()) {
                highestPower = permanent.getPower().getValue();
                selectedCreature = permanent;
            } else if (highestPower == permanent.getPower().getValue()) {
                highestPower = permanent.getPower().getValue();
                selectedCreature = null;
            }
        }
        if (highestPower != Integer.MIN_VALUE) {
            if (selectedCreature == null) {
                FilterPermanent filter = new FilterCreaturePermanent("creature with power " + highestPower);
                filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, highestPower));
                Target target = new TargetPermanent(1, 1, filter, true);
                if (controller.chooseTarget(outcome, target, source, game)) {
                    selectedCreature = game.getPermanent(target.getFirstTarget());
                }
            }
            if (selectedCreature != null) {
                FixedTarget target = new FixedTarget(selectedCreature.getId(), game);
                Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(4));
                effect.setTargetPointer(target);
                effect.apply(game, source);
                ContinuousEffect continuousEffect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
                continuousEffect.setTargetPointer(target);
                game.addEffect(continuousEffect, source);
                return true;
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 47 with ContinuousEffect

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

the class ShowdownOfTheSkaldsDelayedTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Card> cards = controller.getLibrary().getTopCards(game, 4);
        Card sourceCard = game.getCard(source.getSourceId());
        controller.moveCardsToExile(cards, source, game, true, CardUtil.getCardExileZoneId(game, source), sourceCard != null ? sourceCard.getIdName() : "");
        for (Card card : cards) {
            ContinuousEffect effect = new ShowdownOfTheSkaldsMayPlayEffect();
            effect.setTargetPointer(new FixedTarget(card, game));
            game.addEffect(effect, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Card(mage.cards.Card)

Example 48 with ContinuousEffect

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

the class TangleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> doNotUntapNextUntapStep = new ArrayList<>();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            doNotUntapNextUntapStep.add(permanent);
        }
        if (!doNotUntapNextUntapStep.isEmpty()) {
            ContinuousEffect effect = new DontUntapInControllersNextUntapStepTargetEffect("This creature");
            effect.setTargetPointer(new FixedTargets(doNotUntapNextUntapStep, game));
            game.addEffect(effect, source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DontUntapInControllersNextUntapStepTargetEffect(mage.abilities.effects.common.DontUntapInControllersNextUntapStepTargetEffect) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 49 with ContinuousEffect

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

the class TreacherousUrgeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (opponent != null && sourceObject != null) {
        opponent.revealCards(sourceObject.getName(), opponent.getHand(), game);
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            int cardsHand = opponent.getHand().count(StaticFilters.FILTER_CARD_CREATURE, game);
            Card card = null;
            if (cardsHand > 0) {
                TargetCard target = new TargetCard(Zone.HAND, StaticFilters.FILTER_CARD_CREATURE);
                if (controller.choose(Outcome.Benefit, opponent.getHand(), target, game)) {
                    card = opponent.getHand().get(target.getFirstTarget(), game);
                    if (card != null) {
                        if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                            Permanent permanent = game.getPermanent(card.getId());
                            if (permanent != null) {
                                ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
                                effect.setTargetPointer(new FixedTarget(permanent, game));
                                game.addEffect(effect, source);
                                SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId());
                                sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
                                DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect);
                                game.addDelayedTriggeredAbility(delayedAbility, source);
                                return true;
                            }
                        }
                    }
                    return false;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) MageObject(mage.MageObject) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) TargetCard(mage.target.TargetCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 50 with ContinuousEffect

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

the class VhatiIlDalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        DynamicValue power = null;
        DynamicValue toughness = null;
        if (controller.chooseUse(outcome, "Set power? (otherwise toughness is set)", source, game)) {
            power = StaticValue.get(1);
        } else {
            toughness = StaticValue.get(1);
        }
        ContinuousEffect effect = new SetPowerToughnessTargetEffect(power, toughness, Duration.EndOfTurn);
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SetPowerToughnessTargetEffect(mage.abilities.effects.common.continuous.SetPowerToughnessTargetEffect) DynamicValue(mage.abilities.dynamicvalue.DynamicValue)

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