use of mage.cards.Cards in project mage by magefree.
the class BalancingActEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int minPermanent = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE;
// count minimal permanents
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int count = game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game).size();
if (count < minPermanent) {
minPermanent = count;
}
}
}
// sacrifice permanents over the minimum
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetControlledPermanent target = new TargetControlledPermanent(minPermanent, minPermanent, new FilterControlledPermanent(), true);
if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game)) {
if (permanent != null && !target.getTargets().contains(permanent.getId())) {
permanent.sacrifice(source, game);
}
}
}
}
}
// count minimal cards in hand
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int count = player.getHand().size();
if (count < minCard) {
minCard = count;
}
}
}
// discard cards over the minimum
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard());
if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
Cards cards = player.getHand().copy();
cards.removeIf(target.getTargets()::contains);
player.discard(cards, false, source, game);
}
}
}
return true;
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class CelebrateTheHarvestEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int powerCount = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(MageObject::getPower).mapToInt(MageInt::getValue).distinct().map(x -> 1).sum();
TargetCardInLibrary target = new TargetCardInLibrary(0, powerCount, StaticFilters.FILTER_CARD_BASIC_LAND);
player.searchLibrary(target, source, game);
Cards cards = new CardsImpl();
target.getTargets().stream().map(cardId -> player.getLibrary().getCard(cardId, game)).forEach(cards::add);
player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, true, null);
player.shuffleLibrary(source, game);
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class ColfenorsPlansLookAtCardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards toExile = new CardsImpl(controller.getLibrary().getTopCards(game, 7));
UUID exileId = CardUtil.getCardExileZoneId(game, source);
controller.moveCardsToExile(toExile.getCards(game), source, game, false, exileId, CardUtil.createObjectRealtedWindowTitle(source, game, null));
ExileZone exileZone = game.getExile().getExileZone(exileId);
if (exileZone != null) {
for (Card card : exileZone.getCards(game)) {
if (card != null) {
card.setFaceDown(true, game);
}
}
}
return true;
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class DanceOfTheManseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).map(game::getCard).filter(Objects::nonNull).collect(Collectors.toSet()));
player.moveCards(cards, Zone.BATTLEFIELD, source, game);
if (source.getManaCostsToPay().getX() < 6) {
return true;
}
cards.stream().map(game::getPermanent).filter(Objects::nonNull).forEach(permanent -> {
ContinuousEffect effect = new AddCardTypeTargetEffect(Duration.EndOfGame, CardType.CREATURE);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
effect = new SetPowerToughnessTargetEffect(4, 4, Duration.EndOfGame);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
});
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class DanceOfManyExileTokenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Permanent> tokenPermanents = (List<Permanent>) game.getState().getValue(source.getSourceId() + "_token");
if (tokenPermanents != null) {
Cards cards = new CardsImpl();
for (Permanent permanent : tokenPermanents) {
cards.add(permanent);
}
controller.moveCards(cards, Zone.EXILED, source, game);
return true;
}
}
return false;
}
Aggregations