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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations