Search in sources :

Example 51 with TargetPlayer

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

the class GrindstoneEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (targetPlayer != null) {
        int possibleIterations = targetPlayer.getLibrary().size() / 2;
        int iteration = 0;
        boolean colorShared;
        do {
            iteration++;
            if (iteration > possibleIterations + 20) {
                // 801.16. If the game somehow enters a "loop" of mandatory actions, repeating a sequence of events
                // with no way to stop, the game is a draw for each player who controls an object that's involved in
                // that loop, as well as for each player within the range of influence of any of those players. They
                // leave the game. All remaining players continue to play the game.
                game.setDraw(source.getControllerId());
                return true;
            }
            colorShared = false;
            List<Card> cards = targetPlayer.millCards(2, source, game).getCards(game).stream().collect(Collectors.toList());
            if (cards.size() < 2) {
                break;
            }
            for (int i = 0; i < cards.size(); i++) {
                if (colorShared) {
                    break;
                }
                ObjectColor color1 = cards.get(i).getColor(game);
                if (color1.isColorless()) {
                    continue;
                }
                for (int j = 0; j < cards.size(); j++) {
                    if (i >= j) {
                        continue;
                    }
                    ObjectColor color2 = cards.get(j).getColor(game);
                    if (color1.shares(color2)) {
                        colorShared = true;
                        break;
                    }
                }
            }
        } while (colorShared);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) ObjectColor(mage.ObjectColor) Card(mage.cards.Card)

Example 52 with TargetPlayer

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

the class KeeperOfTheDeadEffect method apply.

@Override
public boolean apply(ObjectSourcePlayer<Player> input, Game game) {
    Player targetPlayer = input.getObject();
    Permanent sourceObject = game.getPermanent(input.getSourceId());
    Player controller = null;
    if (sourceObject != null) {
        controller = game.getPlayer(sourceObject.getControllerId());
    }
    if (targetPlayer == null || controller == null || !controller.hasOpponent(targetPlayer.getId(), game)) {
        return false;
    }
    int countGraveyardTargetPlayer = targetPlayer.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURES, game).size();
    int countGraveyardController = controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURES, game).size();
    return countGraveyardController >= countGraveyardTargetPlayer + 2;
}
Also used : Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetPlayer(mage.target.TargetPlayer) FilterPlayer(mage.filter.FilterPlayer) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent)

Example 53 with TargetPlayer

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

the class KeeperOfTheMindPredicate method apply.

@Override
public boolean apply(ObjectSourcePlayer<Player> input, Game game) {
    Player targetPlayer = input.getObject();
    Player firstPlayer = game.getPlayer(game.getActivePlayerId());
    if (targetPlayer == null || firstPlayer == null || !firstPlayer.hasOpponent(targetPlayer.getId(), game)) {
        return false;
    }
    int countHandTargetPlayer = targetPlayer.getHand().size();
    int countHandFirstPlayer = firstPlayer.getHand().size();
    return countHandTargetPlayer - 2 >= countHandFirstPlayer;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer)

Example 54 with TargetPlayer

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

the class LilianaOfTheVeilEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (player != null && targetPlayer != null) {
        int count = game.getBattlefield().countAll(new FilterPermanent(), targetPlayer.getId(), game);
        TargetPermanent target = new TargetPermanent(0, count, new FilterPermanent("permanents to put in the first pile"), true);
        List<Permanent> pile1 = new ArrayList<>();
        target.setRequired(false);
        if (player.choose(Outcome.Neutral, target, source.getSourceId(), game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
                Permanent p = game.getPermanent(targetId);
                if (p != null) {
                    pile1.add(p);
                }
            }
        }
        List<Permanent> pile2 = new ArrayList<>();
        for (Permanent p : game.getBattlefield().getAllActivePermanents(targetPlayer.getId())) {
            if (!pile1.contains(p)) {
                pile2.add(p);
            }
        }
        boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to sacrifice.", pile1, pile2, game);
        if (choice) {
            sacrificePermanents(pile1, game, source);
        } else {
            sacrificePermanents(pile2, game, source);
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 55 with TargetPlayer

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

the class ScribNibblersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null && targetPlayer.getLibrary().hasCards()) {
        Card card = targetPlayer.getLibrary().getFromTop(game);
        card.moveToExile(id, "Scrib Nibblers Exile", source, game);
        if (card.isLand(game) && you != null) {
            you.gainLife(1, game, source);
            return true;
        }
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Card(mage.cards.Card)

Aggregations

TargetPlayer (mage.target.TargetPlayer)134 Player (mage.players.Player)129 Card (mage.cards.Card)38 Permanent (mage.game.permanent.Permanent)32 FilterCard (mage.filter.FilterCard)27 UUID (java.util.UUID)25 MageObject (mage.MageObject)16 CardsImpl (mage.cards.CardsImpl)16 FilterPlayer (mage.filter.FilterPlayer)16 TargetCard (mage.target.TargetCard)13 Cards (mage.cards.Cards)12 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)12 ObjectSourcePlayer (mage.filter.predicate.ObjectSourcePlayer)10 Target (mage.target.Target)10 FixedTarget (mage.target.targetpointer.FixedTarget)10 Spell (mage.game.stack.Spell)9 ContinuousEffect (mage.abilities.effects.ContinuousEffect)8 TargetPermanent (mage.target.TargetPermanent)7 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)5