use of mage.filter.FilterCard in project mage by magefree.
the class CardTestPlayerAPIImpl method assertHandCount.
/**
* Assert card count in player's hand.
*
* @param player {@link Player} who's hand should be counted.
* @param cardName Name of the cards that should be counted.
* @param count Expected count.
*/
public void assertHandCount(Player player, String cardName, int count) throws AssertionError {
// Assert.assertNotEquals("", cardName);
int actual;
if (cardName.contains("//")) {
// special logic for cheched split cards, because in game logic of card name filtering is different than for test
actual = 0;
for (Card card : currentGame.getPlayer(player.getId()).getHand().getCards(currentGame)) {
if (CardUtil.haveSameNames(card.getName(), cardName, true)) {
actual++;
}
}
} else {
FilterCard filter = new FilterCard();
// must find any cards even without names
filter.add(new NamePredicate(cardName, true));
actual = currentGame.getPlayer(player.getId()).getHand().count(filter, player.getId(), currentGame);
}
Assert.assertEquals("(Hand) Card counts for card " + cardName + " for " + player.getName() + " are not equal ", count, actual);
}
use of mage.filter.FilterCard in project mage by magefree.
the class SearchLibraryWithLessCMCPutInPlayEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// never change static objects so copy the object here before
FilterCard advancedFilter = filter.copy();
advancedFilter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
TargetCardInLibrary target = new TargetCardInLibrary(advancedFilter);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
controller.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class AladdinsLampEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
controller.lookAtCards(source, null, cards, game);
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to stay at the top of library"));
if (controller.choose(outcome, cards, target, game)) {
cards.remove(target.getFirstTarget());
}
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
game.getState().processAction(game);
controller.drawCards(1, source, game, event);
discard();
return true;
}
use of mage.filter.FilterCard in project mage by magefree.
the class AssemblyHallEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || controller.getHand().isEmpty() || sourceObject == null) {
return false;
}
Card cardToReveal = null;
Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
target.setNotTarget(true);
if (controller.chooseTarget(outcome, target, source, game)) {
cardToReveal = game.getCard(target.getFirstTarget());
}
if (cardToReveal == null) {
return false;
}
controller.revealCards("from hand :" + sourceObject.getName(), new CardsImpl(cardToReveal), game);
String nameToSearch = CardUtil.getCardNameForSameNameSearch(cardToReveal);
FilterCard filterCard = new FilterCard("card named " + nameToSearch);
filterCard.add(new NamePredicate(nameToSearch));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source);
}
use of mage.filter.FilterCard in project mage by magefree.
the class AshnodsCylixEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 3));
player.lookAtCards(source, null, cards, game);
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put on top of your library"));
if (player.choose(Outcome.Benefit, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
game.informPlayers(source.getSourceObject(game).getIdName() + ": " + player.getLogName() + " puts a card back on top of their library");
}
}
player.moveCards(cards, Zone.EXILED, source, game);
return true;
}
Aggregations