Search in sources :

Example 91 with MageObject

use of mage.MageObject in project mage by magefree.

the class OathOfGhoulsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    Player firstPlayer = game.getPlayer(game.getActivePlayerId());
    if (sourceObject == null || firstPlayer == null) {
        return false;
    }
    FilterCard filter = new FilterCreatureCard("creature card");
    filter.add(new OwnerIdPredicate(firstPlayer.getId()));
    Target target = new TargetCardInGraveyard(filter);
    target.setNotTarget(true);
    if (target.canChoose(source.getSourceId(), firstPlayer.getId(), game) && firstPlayer.chooseUse(outcome, "Return a creature card from your graveyard to your hand?", source, game) && firstPlayer.chooseTarget(Outcome.ReturnToHand, target, source, game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            firstPlayer.moveCards(card, Zone.HAND, source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetPlayer(mage.target.TargetPlayer) FilterPlayer(mage.filter.FilterPlayer) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) Target(mage.target.Target) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) MageObject(mage.MageObject) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 92 with MageObject

use of mage.MageObject in project mage by magefree.

the class NullChamberReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    TargetOpponent chosenOpponent = new TargetOpponent(true);
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getPermanentEntering(source.getSourceId());
    if (sourceObject == null) {
        sourceObject = source.getSourceObject(game);
    }
    if (controller == null || sourceObject == null) {
        return false;
    }
    controller.choose(Outcome.Neutral, chosenOpponent, source.getSourceId(), game);
    Player opponent = game.getPlayer(chosenOpponent.getFirstTarget());
    String cardName = ChooseACardNameEffect.TypeOfName.NOT_BASIC_LAND_NAME.getChoice(controller, game, source, false);
    if (cardName != null) {
        game.getState().setValue(source.getSourceId().toString() + INFO_KEY_CONTROLLER, cardName);
        if (sourceObject instanceof Permanent) {
            ((Permanent) sourceObject).addInfo(INFO_KEY_CONTROLLER, CardUtil.addToolTipMarkTags("Named card (Controller): " + cardName), game);
        }
    }
    if (opponent == null) {
        return true;
    }
    cardName = ChooseACardNameEffect.TypeOfName.NOT_BASIC_LAND_NAME.getChoice(opponent, game, source, false);
    if (cardName == null) {
        return true;
    }
    game.getState().setValue(source.getSourceId().toString() + INFO_KEY_OPPONENT, cardName);
    if (sourceObject instanceof Permanent) {
        ((Permanent) sourceObject).addInfo(INFO_KEY_OPPONENT, CardUtil.addToolTipMarkTags("Named card (Opponent): " + cardName), game);
    }
    return true;
}
Also used : TargetOpponent(mage.target.common.TargetOpponent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject)

Example 93 with MageObject

use of mage.MageObject in project mage by magefree.

the class PatriarchsBiddingEffect 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) {
        Set<String> chosenTypes = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            Choice typeChoice = new ChoiceCreatureType(sourceObject);
            if (!player.choose(Outcome.PutCreatureInPlay, typeChoice, game)) {
                continue;
            }
            String chosenType = typeChoice.getChoice();
            game.informPlayers(sourceObject.getLogName() + ": " + player.getLogName() + " has chosen " + chosenType);
            chosenTypes.add(chosenType);
        }
        List<SubType.SubTypePredicate> predicates = new ArrayList<>();
        for (String type : chosenTypes) {
            predicates.add(SubType.byDescription(type).getPredicate());
        }
        FilterCard filter = new FilterCreatureCard();
        filter.add(Predicates.or(predicates));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                player.moveCards(player.getGraveyard().getCards(filter, game), Zone.BATTLEFIELD, source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) MageObject(mage.MageObject) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ChoiceCreatureType(mage.choices.ChoiceCreatureType)

Example 94 with MageObject

use of mage.MageObject in project mage by magefree.

the class ParallaxWaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObject(game);
    Player controller = game.getPlayer(source.getControllerId());
    if (sourceObject != null && controller != null) {
        int zoneChangeCounter = (sourceObject instanceof PermanentToken) ? source.getSourceObjectZoneChangeCounter() : source.getSourceObjectZoneChangeCounter() - 1;
        UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), zoneChangeCounter);
        if (exileZoneId != null) {
            ExileZone exileZone = game.getExile().getExileZone(exileZoneId);
            if (exileZone != null) {
                return controller.moveCards(exileZone.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) PermanentToken(mage.game.permanent.PermanentToken) UUID(java.util.UUID)

Example 95 with MageObject

use of mage.MageObject 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)

Aggregations

MageObject (mage.MageObject)738 Player (mage.players.Player)554 Permanent (mage.game.permanent.Permanent)239 UUID (java.util.UUID)224 Card (mage.cards.Card)210 FilterCard (mage.filter.FilterCard)113 CardsImpl (mage.cards.CardsImpl)106 TargetCard (mage.target.TargetCard)91 Cards (mage.cards.Cards)73 Spell (mage.game.stack.Spell)68 FixedTarget (mage.target.targetpointer.FixedTarget)66 HashSet (java.util.HashSet)56 Ability (mage.abilities.Ability)52 ContinuousEffect (mage.abilities.effects.ContinuousEffect)51 TargetPermanent (mage.target.TargetPermanent)48 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)48 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)46 Target (mage.target.Target)44 Effect (mage.abilities.effects.Effect)42 OneShotEffect (mage.abilities.effects.OneShotEffect)41