use of mage.filter.FilterCard in project mage by magefree.
the class CardSelector method filterCards.
private void filterCards() {
FilterCard filter = buildFilter();
MageFrame.getDesktop().setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
// debug
// debugObjectMemorySize("Old cards size", this.currentView.getCardsStore());
this.currentView.clearCardsStoreBeforeUpdate();
java.util.List<Card> filteredCards = new ArrayList<>();
if (chkPennyDreadful.isSelected() && pdAllowed.isEmpty()) {
pdAllowed.putAll(PennyDreadfulLegalityUtil.getLegalCardList());
}
if (limited) {
for (Card card : cards) {
if (filter.match(card, null)) {
filteredCards.add(card);
}
}
} else {
java.util.List<CardInfo> foundCards = CardRepository.instance.findCards(buildCriteria());
for (CardInfo cardInfo : foundCards) {
// filter by penny
if (chkPennyDreadful.isSelected()) {
if (!pdAllowed.containsKey(cardInfo.getName())) {
continue;
}
}
// filter by settings
Card card = cardInfo.getMockCard();
if (!filter.match(card, null)) {
continue;
}
// found
filteredCards.add(card);
}
}
// force to list mode on too much cards
if (currentView instanceof CardGrid && filteredCards.size() > CardGrid.MAX_IMAGES) {
this.toggleViewMode();
}
// debug
// debugObjectMemorySize("New cards size", filteredCards);
this.currentView.loadCards(new CardsView(filteredCards), sortSetting, bigCard, null, false);
this.cardCount.setText(String.valueOf(filteredCards.size()));
} finally {
MageFrame.getDesktop().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
use of mage.filter.FilterCard in project mage by magefree.
the class AchHansRunEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
String cardName = ChooseACardNameEffect.TypeOfName.CREATURE_NAME.getChoice(controller, game, source, false);
game.informPlayers(controller.getLogName() + ": \"Ach! Hans, run! It's the " + cardName + "!\"");
FilterCard nameFilter = new FilterCard();
nameFilter.add(new NamePredicate(cardName));
TargetCardInLibrary target = new TargetCardInLibrary(1, 1, nameFilter);
if (!controller.searchLibrary(target, source, game)) {
return false;
}
Card card = controller.getLibrary().remove(target.getFirstTarget(), game);
if (card == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
return false;
}
Permanent creature = game.getPermanent(card.getId());
if (creature == null) {
return false;
}
// gains haste
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature, game));
game.addEffect(effect, source);
// Exile at begin of next end step
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(new FixedTarget(creature, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
controller.shuffleLibrary(source, game);
return true;
}
use of mage.filter.FilterCard in project mage by magefree.
the class AcademyResearchersEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterCard filterCardInHand = new FilterCard();
filterCardInHand.add(SubType.AURA.getPredicate());
Player controller = game.getPlayer(source.getControllerId());
Permanent academyResearchers = game.getPermanent(source.getSourceId());
if (controller != null && academyResearchers != null) {
filterCardInHand.add(new AuraCardCanAttachToPermanentId(academyResearchers.getId()));
TargetCardInHand target = new TargetCardInHand(0, 1, filterCardInHand);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card auraInHand = game.getCard(target.getFirstTarget());
if (auraInHand != null) {
game.getState().setValue("attachTo:" + auraInHand.getId(), academyResearchers);
controller.moveCards(auraInHand, Zone.BATTLEFIELD, source, game);
if (academyResearchers.addAttachment(auraInHand.getId(), source, game)) {
game.informPlayers(controller.getLogName() + " put " + auraInHand.getLogName() + " on the battlefield attached to " + academyResearchers.getLogName() + '.');
return true;
}
}
}
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class AmassTheComponentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
player.drawCards(3, source, game);
if (!player.getHand().isEmpty()) {
FilterCard filter = new FilterCard("card from your hand to put on the bottom of your library");
TargetCard target = new TargetCard(Zone.HAND, filter);
if (player.choose(Outcome.Detriment, player.getHand(), target, game)) {
Card card = player.getHand().get(target.getFirstTarget(), game);
if (card != null) {
return player.putCardsOnBottomOfLibrary(card, game, source, true);
}
}
}
return true;
}
use of mage.filter.FilterCard 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;
}
Aggregations