Search in sources :

Example 6 with Target

use of mage.target.Target in project mage by magefree.

the class BarrinsSpiteEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Permanent> permanents = source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
    if (permanents.isEmpty()) {
        return false;
    }
    if (permanents.size() == 1) {
        permanents.get(0).sacrifice(source, game);
        return true;
    }
    if (permanents.size() > 2) {
        throw new IllegalStateException("Too many permanents in list, shouldn't be possible");
    }
    Player player = game.getPlayer(permanents.get(0).getControllerId());
    Player controller = game.getPlayer(source.getControllerId());
    if (player == null || controller == null) {
        return false;
    }
    Permanent perm1 = permanents.get(0);
    Permanent perm2 = permanents.get(1);
    if (player.chooseUse(outcome, "Choose which permanent to sacrifice", "The other will be returned to your hand", perm1.getIdName(), perm2.getIdName(), source, game)) {
        perm1.sacrifice(source, game);
        controller.moveCards(perm2, Zone.HAND, source, game);
        return true;
    }
    perm2.sacrifice(source, game);
    controller.moveCards(perm1, Zone.HAND, source, game);
    return true;
}
Also used : Target(mage.target.Target) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Example 7 with Target

use of mage.target.Target in project mage by magefree.

the class BeamsplitterMageApplier method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!isControlledBy(event.getPlayerId())) {
        return false;
    }
    Spell spell = game.getSpellOrLKIStack(event.getTargetId());
    if (spell == null || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    if (spell.getSpellAbilities().stream().map(AbilityImpl::getModes).flatMap(m -> m.getSelectedModes().stream().map(m::get)).filter(Objects::nonNull).map(Mode::getTargets).flatMap(Collection::stream).filter(t -> !t.isNotTarget()).map(Target::getTargets).flatMap(Collection::stream).anyMatch(uuid -> !getSourceId().equals(uuid) && uuid != null)) {
        return false;
    }
    this.getEffects().setValue("spellCast", spell);
    return true;
}
Also used : Target(mage.target.Target) java.util(java.util) Zone(mage.constants.Zone) Predicate(mage.filter.predicate.Predicate) MageObjectReference(mage.MageObjectReference) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) SubType(mage.constants.SubType) FilterPermanent(mage.filter.FilterPermanent) Mode(mage.abilities.Mode) Player(mage.players.Player) StackObjectCopyApplier(mage.util.functions.StackObjectCopyApplier) CardType(mage.constants.CardType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell) StaticFilters(mage.filter.StaticFilters) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) AbilityImpl(mage.abilities.AbilityImpl) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) AnotherPredicate(mage.filter.predicate.mageobject.AnotherPredicate) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) AbilityImpl(mage.abilities.AbilityImpl) Target(mage.target.Target) Spell(mage.game.stack.Spell)

Example 8 with Target

use of mage.target.Target in project mage by magefree.

the class BorderlandExplorerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        // Store for each player the cards to discard, that's important because all discard shall happen at the same time
        Map<UUID, Cards> cardsToDiscard = new HashMap<>();
        // Store for each player the lands to reveal, that's important because all reveals shall happen at the same time
        Map<UUID, Cards> cardsToReveal = new HashMap<>();
        // choose cards to discard
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Target target = new TargetDiscard(0, 1, new FilterCard(), playerId);
                player.chooseTarget(outcome, target, source, game);
                Cards cards = new CardsImpl(target.getTargets());
                cardsToDiscard.put(playerId, cards);
            }
        }
        // discard all chosen cards
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToDiscard.get(playerId);
                if (cardsPlayer != null) {
                    for (UUID cardId : cardsPlayer) {
                        Card card = game.getCard(cardId);
                        player.discard(card, false, source, game);
                    }
                }
            }
        }
        // search for a land for each player that discarded
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToDiscard.get(playerId);
                if (cardsPlayer != null && !cardsPlayer.isEmpty()) {
                    TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
                    if (player.searchLibrary(target, source, game)) {
                        if (!target.getTargets().isEmpty()) {
                            Cards cards = new CardsImpl(target.getTargets());
                            cards.addAll(target.getTargets());
                            cardsToReveal.put(playerId, cards);
                        }
                    }
                }
            }
        }
        // reveal the searched lands, put in hands, and shuffle
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Cards cardsPlayer = cardsToReveal.get(playerId);
                if (cardsPlayer != null) {
                    for (UUID cardId : cardsPlayer) {
                        Card card = game.getCard(cardId);
                        Cards cards = new CardsImpl(game.getCard(cardId));
                        if (card != null && !cards.isEmpty()) {
                            player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cards, game);
                            player.moveCards(card, Zone.HAND, source, game);
                            player.shuffleLibrary(source, game);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) MageObject(mage.MageObject) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 9 with Target

use of mage.target.Target in project mage by magefree.

the class BoneyardParleyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Cards cards = new CardsImpl();
        for (Target target : source.getTargets()) {
            for (UUID cardId : target.getTargets()) {
                cards.add(cardId);
            }
        }
        if (!cards.isEmpty() && player.moveCards(cards, Zone.EXILED, source, game)) {
            TargetOpponent targetOpponent = new TargetOpponent(true);
            if (player.choose(Outcome.Neutral, targetOpponent, source.getSourceId(), game)) {
                Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
                if (opponent != null) {
                    TargetCard targetCards = new TargetCard(0, cards.size(), Zone.EXILED, new FilterCard("cards to put in the first pile"));
                    List<Card> pile1 = new ArrayList<>();
                    if (opponent.choose(Outcome.Neutral, cards, targetCards, game)) {
                        List<UUID> targets = targetCards.getTargets();
                        for (UUID targetId : targets) {
                            Card card = cards.get(targetId, game);
                            if (card != null) {
                                pile1.add(card);
                                cards.remove(card);
                            }
                        }
                    }
                    List<Card> pile2 = new ArrayList<>();
                    pile2.addAll(cards.getCards(game));
                    boolean choice = player.choosePile(outcome, "Choose a pile to put onto the battlefield.", pile1, pile2, game);
                    Zone pile1Zone = Zone.GRAVEYARD;
                    Zone pile2Zone = Zone.BATTLEFIELD;
                    if (choice) {
                        pile1Zone = Zone.BATTLEFIELD;
                        pile2Zone = Zone.GRAVEYARD;
                    }
                    Set<Card> pile1Set = new HashSet<>();
                    Set<Card> pile2Set = new HashSet<>();
                    pile1Set.addAll(pile1);
                    pile2Set.addAll(pile2);
                    // Cards toBattlefield = new CardsImpl();
                    // Cards toGraveyard = new CardsImpl();
                    // 
                    // if (pile1Zone == Zone.BATTLEFIELD) {
                    // toBattlefield.addAll(pile1);
                    // toGraveyard.addAll(pile2);
                    // } else {
                    // toBattlefield.addAll(pile2);
                    // toGraveyard.addAll(pile1);
                    // }
                    player.moveCards(pile1Set, pile1Zone, source, game, false, false, false, null);
                    player.moveCards(pile2Set, pile2Zone, source, game, false, false, false, null);
                // StringBuilder sb = new StringBuilder("Pile 1, going to ").append(pile1Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(": ");
                // game.informPlayers(sb.toString());
                // sb = new StringBuilder("Pile 2, going to ").append(pile2Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(':');
                // game.informPlayers(sb.toString());
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Zone(mage.constants.Zone) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) HashSet(java.util.HashSet)

Example 10 with Target

use of mage.target.Target in project mage by magefree.

the class CracklingDoomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> toSacrifice = new ArrayList<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (controller.hasOpponent(playerId, game)) {
                Player opponent = game.getPlayer(playerId);
                if (opponent != null) {
                    int greatestPower = Integer.MIN_VALUE;
                    int numberOfCreatures = 0;
                    Permanent permanentToSacrifice = null;
                    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
                        if (permanent.getPower().getValue() > greatestPower) {
                            greatestPower = permanent.getPower().getValue();
                            numberOfCreatures = 1;
                            permanentToSacrifice = permanent;
                        } else if (permanent.getPower().getValue() == greatestPower) {
                            numberOfCreatures++;
                        }
                    }
                    if (numberOfCreatures == 1) {
                        if (permanentToSacrifice != null) {
                            toSacrifice.add(permanentToSacrifice);
                        }
                    } else if (greatestPower != Integer.MIN_VALUE) {
                        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature to sacrifice with power equal to " + greatestPower);
                        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
                        Target target = new TargetControlledCreaturePermanent(filter);
                        if (opponent.choose(outcome, target, playerId, game)) {
                            Permanent permanent = game.getPermanent(target.getFirstTarget());
                            if (permanent != null) {
                                toSacrifice.add(permanent);
                            }
                        }
                    }
                }
            }
        }
        for (Permanent permanent : toSacrifice) {
            permanent.sacrifice(source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Aggregations

Target (mage.target.Target)385 Player (mage.players.Player)291 Permanent (mage.game.permanent.Permanent)223 UUID (java.util.UUID)155 Card (mage.cards.Card)86 TargetPermanent (mage.target.TargetPermanent)80 FilterCard (mage.filter.FilterCard)62 FilterPermanent (mage.filter.FilterPermanent)56 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)54 FixedTarget (mage.target.targetpointer.FixedTarget)49 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)45 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)45 MageObject (mage.MageObject)43 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)42 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 TargetOpponent (mage.target.common.TargetOpponent)35 CardsImpl (mage.cards.CardsImpl)32 ArrayList (java.util.ArrayList)31 ContinuousEffect (mage.abilities.effects.ContinuousEffect)31 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)30