Search in sources :

Example 76 with ContinuousEffect

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

the class AngelicGuardianGainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    if (you != null) {
        game.getCombat().getAttackers().stream().map(game::getPermanent).filter(Objects::nonNull).filter(permanent -> permanent.isControlledBy(you.getId())).filter(permanent1 -> permanent1.isCreature(game)).forEach(permanent -> {
            ContinuousEffect effect = new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        });
        return true;
    }
    return false;
}
Also used : IndestructibleAbility(mage.abilities.keyword.IndestructibleAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) AttacksWithCreaturesTriggeredAbility(mage.abilities.common.AttacksWithCreaturesTriggeredAbility) Duration(mage.constants.Duration) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) FlyingAbility(mage.abilities.keyword.FlyingAbility) Ability(mage.abilities.Ability) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 77 with ContinuousEffect

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

the class AssaultSuitGainControlEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player activePlayer = game.getPlayer(game.getActivePlayerId());
    Permanent equipment = game.getPermanent(source.getSourceId());
    if (controller != null && activePlayer != null && equipment != null) {
        if (equipment.getAttachedTo() != null) {
            Permanent equippedCreature = game.getPermanent(equipment.getAttachedTo());
            if (equippedCreature != null && controller.chooseUse(outcome, "Let have " + activePlayer.getLogName() + " gain control of " + equippedCreature.getLogName() + '?', source, game)) {
                equippedCreature.untap(game);
                ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn, activePlayer.getId());
                effect.setTargetPointer(new FixedTarget(equipment.getAttachedTo(), 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) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 78 with ContinuousEffect

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

the class CustodyBattleUnlessPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        String message = "sacrifice a land?";
        message = CardUtil.replaceSourceName(message, sourcePermanent.getLogName());
        message = Character.toUpperCase(message.charAt(0)) + message.substring(1);
        if (cost.canPay(source, source, source.getControllerId(), game) && controller.chooseUse(Outcome.Benefit, message, source, game)) {
            cost.clearPaid();
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                return true;
            }
        }
        if (source.getSourceObjectZoneChangeCounter() == game.getState().getZoneChangeCounter(source.getSourceId()) && game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
            ContinuousEffect effect = new GiveControlEffect();
            effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
            game.addEffect(effect, source);
            game.informPlayers(game.getPlayer(source.getFirstTarget()).getLogName() + " gains control of " + sourcePermanent.getIdName());
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 79 with ContinuousEffect

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

the class EchoingDecayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
    if (targetPermanent != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        if (CardUtil.haveEmptyName(targetPermanent)) {
            // if no name (face down creature) only the creature itself is selected
            filter.add(new PermanentIdPredicate(targetPermanent.getId()));
        } else {
            filter.add(new NamePredicate(targetPermanent.getName()));
        }
        ContinuousEffect effect = new BoostAllEffect(-2, -2, Duration.EndOfTurn, filter, false);
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect)

Example 80 with ContinuousEffect

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

the class GontiLordOfLuxuryLookEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || opponent == null || sourceObject == null) {
        return false;
    }
    Cards topCards = new CardsImpl();
    topCards.addAll(opponent.getLibrary().getTopCards(game, 4));
    TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to exile"));
    controller.choose(outcome, topCards, target, game);
    Card card = game.getCard(target.getFirstTarget());
    if (card == null) {
        controller.putCardsOnBottomOfLibrary(topCards, game, source, false);
        return true;
    }
    topCards.remove(card);
    // move card to exile
    UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    card.setFaceDown(true, game);
    if (controller.moveCardsToExile(card, source, game, false, exileZoneId, sourceObject.getIdName())) {
        card.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);
        // allow to cast the card
        ContinuousEffect effect = new GontiLordOfLuxuryCastFromExileEffect();
        effect.setTargetPointer(new FixedTarget(card.getId(), game));
        game.addEffect(effect, source);
        // and you may spend mana as though it were mana of any color to cast it
        effect = new GontiLordOfLuxurySpendAnyManaEffect();
        effect.setTargetPointer(new FixedTarget(card.getId(), game));
        game.addEffect(effect, source);
        // For as long as that card remains exiled, you may look at it
        effect = new GontiLordOfLuxuryLookEffect(controller.getId());
        effect.setTargetPointer(new FixedTarget(card.getId(), game));
        game.addEffect(effect, source);
    }
    // then put the rest on the bottom of that library in a random order
    controller.putCardsOnBottomOfLibrary(topCards, game, source, false);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Set(java.util.Set) HashSet(java.util.HashSet) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID)

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