Search in sources :

Example 1 with DecayedAbility

use of mage.abilities.keyword.DecayedAbility in project mage by magefree.

the class GisaGloriousResurrectorReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Ability exiledWithSource = (Ability) game.getState().getValue("GisaGloriousResurrectorExile" + source.getSourceId().toString() + game.getState().getZoneChangeCounter(source.getSourceId()));
    if (exiledWithSource == null) {
        return false;
    }
    ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, exiledWithSource));
    if (player == null || exileZone == null || exileZone.isEmpty()) {
        return false;
    }
    Cards cards = new CardsImpl(exileZone.getCards(StaticFilters.FILTER_CARD_CREATURE, game));
    if (cards.isEmpty()) {
        return false;
    }
    player.moveCards(cards, Zone.BATTLEFIELD, source, game);
    cards.retainZone(Zone.BATTLEFIELD, game);
    if (cards.isEmpty()) {
        return false;
    }
    game.addEffect(new GainAbilityTargetEffect(new DecayedAbility(), Duration.Custom).setTargetPointer(new FixedTargets(cards, game)), source);
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) BeginningOfUpkeepTriggeredAbility(mage.abilities.common.BeginningOfUpkeepTriggeredAbility) DecayedAbility(mage.abilities.keyword.DecayedAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) FixedTargets(mage.target.targetpointer.FixedTargets) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ExileZone(mage.game.ExileZone) DecayedAbility(mage.abilities.keyword.DecayedAbility) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 2 with DecayedAbility

use of mage.abilities.keyword.DecayedAbility in project mage by magefree.

the class GhoulsNightOutTypeChangingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID controllerId = source.getControllerId();
    Player controller = game.getPlayer(controllerId);
    if (controller != null) {
        Set<Card> cardsToBattlefield = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controllerId, game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                boolean creatureInGraveyard = false;
                for (UUID cardId : player.getGraveyard()) {
                    Card card = game.getCard(cardId);
                    if (card != null && card.isCreature(game)) {
                        creatureInGraveyard = true;
                        break;
                    }
                }
                if (creatureInGraveyard) {
                    FilterCreatureCard filter = new FilterCreatureCard("creature card in " + player.getName() + "'s graveyard");
                    TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
                    target.setNotTarget(true);
                    controller.chooseTarget(controllerId.equals(playerId) ? Outcome.Benefit : Outcome.Detriment, player.getGraveyard(), target, source, game);
                    Card card = game.getCard(target.getFirstTarget());
                    if (card != null) {
                        cardsToBattlefield.add(card);
                    }
                }
            }
        }
        if (!cardsToBattlefield.isEmpty()) {
            controller.moveCards(cardsToBattlefield, Zone.BATTLEFIELD, source, game);
            cardsToBattlefield.removeIf(card -> game.getState().getZone(card.getId()) != Zone.BATTLEFIELD);
            if (!cardsToBattlefield.isEmpty()) {
                game.addEffect(new GhoulsNightOutTypeChangingEffect().setTargetPointer(new FixedTargets(cardsToBattlefield, game)), source);
                game.addEffect(new GainAbilityTargetEffect(new DecayedAbility(), Duration.Custom).setTargetPointer(new FixedTargets(cardsToBattlefield, game)), source);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) FixedTargets(mage.target.targetpointer.FixedTargets) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) TargetCard(mage.target.TargetCard) DecayedAbility(mage.abilities.keyword.DecayedAbility) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) HashSet(java.util.HashSet)

Aggregations

GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)2 DecayedAbility (mage.abilities.keyword.DecayedAbility)2 Player (mage.players.Player)2 FixedTargets (mage.target.targetpointer.FixedTargets)2 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 Ability (mage.abilities.Ability)1 BeginningOfUpkeepTriggeredAbility (mage.abilities.common.BeginningOfUpkeepTriggeredAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 Card (mage.cards.Card)1 Cards (mage.cards.Cards)1 CardsImpl (mage.cards.CardsImpl)1 FilterCreatureCard (mage.filter.common.FilterCreatureCard)1 ExileZone (mage.game.ExileZone)1 TargetCard (mage.target.TargetCard)1