Search in sources :

Example 46 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class WakeToSlaughterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Cards pickedCards = new CardsImpl(getTargetPointer().getTargets(game, source));
    if (player != null && !pickedCards.isEmpty()) {
        Card cardToHand;
        if (pickedCards.size() == 1) {
            cardToHand = pickedCards.getRandom(game);
        } else {
            Player opponent;
            Set<UUID> opponents = game.getOpponents(player.getId());
            if (opponents.size() == 1) {
                opponent = game.getPlayer(opponents.iterator().next());
            } else {
                Target targetOpponent = new TargetOpponent(true);
                player.chooseTarget(Outcome.Detriment, targetOpponent, source, game);
                opponent = game.getPlayer(targetOpponent.getFirstTarget());
            }
            TargetCard target = new TargetCard(1, Zone.GRAVEYARD, new FilterCard());
            target.withChooseHint("Card to go to opponent's hand (other goes to battlefield)");
            opponent.chooseTarget(outcome, pickedCards, target, source, game);
            cardToHand = game.getCard(target.getFirstTarget());
        }
        for (Card card : pickedCards.getCards(game)) {
            if (card == cardToHand) {
                player.moveCards(cardToHand, Zone.HAND, source, game);
            } else {
                player.moveCards(card, Zone.BATTLEFIELD, source, game);
                FixedTarget fixedTarget = new FixedTarget(card, game);
                ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfGame);
                effect.setTargetPointer(fixedTarget);
                game.addEffect(effect, source);
                ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
                exileEffect.setTargetPointer(fixedTarget);
                DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
                game.addDelayedTriggeredAbility(delayedAbility, source);
            }
        }
        pickedCards.clear();
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 47 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class WakeThePastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(player.getGraveyard().getCards(StaticFilters.FILTER_CARD_ARTIFACT, game));
    if (cards.isEmpty()) {
        return false;
    }
    player.moveCards(cards, Zone.BATTLEFIELD, source, game);
    cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.BATTLEFIELD);
    if (cards.isEmpty()) {
        return true;
    }
    game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn).setTargetPointer(new FixedTargets(cards, game)), source);
    return true;
}
Also used : Player(mage.players.Player) FixedTargets(mage.target.targetpointer.FixedTargets) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 48 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class InfoEffect method addCardHintToPermanent.

/**
 * Add temporary card hint to permanent (visible in rules list)
 *
 * @param game
 * @param source
 * @param permanent
 * @param cardHint
 * @param duration
 */
public static void addCardHintToPermanent(Game game, Ability source, Permanent permanent, Hint cardHint, Duration duration) {
    SimpleStaticAbility ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new InfoEffect("hint"));
    ability.setRuleVisible(false);
    ability.addHint(cardHint);
    GainAbilityTargetEffect gainEffect = new GainAbilityTargetEffect(ability, duration);
    gainEffect.setTargetPointer(new FixedTarget(permanent, game));
    game.addEffect(gainEffect, source);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect)

Example 49 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class EncoreSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getSourceId());
    if (card == null) {
        return false;
    }
    EmptyToken token = new EmptyToken();
    CardUtil.copyTo(token).from(card, game);
    Set<MageObjectReference> addedTokens = new HashSet<>();
    int opponentCount = OpponentsCount.instance.calculate(game, source, this);
    if (opponentCount < 1) {
        return false;
    }
    token.putOntoBattlefield(opponentCount, game, source, source.getControllerId());
    Iterator<UUID> it = token.getLastAddedTokenIds().iterator();
    while (it.hasNext()) {
        for (UUID playerId : game.getOpponents(source.getControllerId())) {
            if (game.getPlayer(playerId) == null) {
                continue;
            }
            UUID tokenId = it.next();
            MageObjectReference mageObjectReference = new MageObjectReference(tokenId, game);
            game.addEffect(new EncoreRequirementEffect(mageObjectReference, playerId), source);
            game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom).setTargetPointer(new FixedTarget(mageObjectReference)), source);
            addedTokens.add(mageObjectReference);
        }
    }
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new EncoreSacrificeEffect(addedTokens)), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Card(mage.cards.Card) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference) EmptyToken(mage.game.permanent.token.EmptyToken) HashSet(java.util.HashSet)

Example 50 with GainAbilityTargetEffect

use of mage.abilities.effects.common.continuous.GainAbilityTargetEffect in project mage by magefree.

the class CantStayAwayReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Card targetCard = game.getCard(source.getFirstTarget());
    if (controller == null || targetCard == null || game.getState().getZone(targetCard.getId()) != Zone.GRAVEYARD) {
        return false;
    }
    controller.moveCards(targetCard, Zone.BATTLEFIELD, source, game);
    Permanent permanent = game.getPermanent(targetCard.getId());
    if (permanent != null) {
        ContinuousEffect effect = new GainAbilityTargetEffect(new SimpleStaticAbility(new CantStayAwayReplacementEffect()), Duration.Custom);
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Aggregations

GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)125 FixedTarget (mage.target.targetpointer.FixedTarget)96 Permanent (mage.game.permanent.Permanent)93 ContinuousEffect (mage.abilities.effects.ContinuousEffect)76 Player (mage.players.Player)76 Card (mage.cards.Card)42 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)28 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)22 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)21 UUID (java.util.UUID)18 BoostTargetEffect (mage.abilities.effects.common.continuous.BoostTargetEffect)17 Effect (mage.abilities.effects.Effect)16 OneShotEffect (mage.abilities.effects.OneShotEffect)15 FilterCard (mage.filter.FilterCard)15 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)15 TargetPermanent (mage.target.TargetPermanent)15 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)14 SacrificeTargetEffect (mage.abilities.effects.common.SacrificeTargetEffect)13 FilterCreatureCard (mage.filter.common.FilterCreatureCard)12 FixedTargets (mage.target.targetpointer.FixedTargets)12