use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class SameNameAsExiledCountValue method calculate.
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int value = 0;
Permanent permanent = game.getPermanent(sourceAbility.getSourceId());
if (permanent != null && !permanent.getImprinted().isEmpty()) {
FilterPermanent filterPermanent = new FilterPermanent();
filterPermanent.add(new NamePredicate(game.getCard(permanent.getImprinted().get(0)).getName()));
value = game.getBattlefield().count(filterPermanent, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
}
return value;
}
use of mage.filter.predicate.mageobject.NamePredicate 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.predicate.mageobject.NamePredicate 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.predicate.mageobject.NamePredicate in project mage by magefree.
the class CurseOfMisfortunesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent enchantment = game.getPermanent(source.getSourceId());
if (controller != null && enchantment != null && enchantment.getAttachedTo() != null) {
Player targetPlayer = game.getPlayer(enchantment.getAttachedTo());
Player player = game.getPlayer(source.getControllerId());
if (player != null && targetPlayer != null) {
FilterCard filter = new FilterCard("Curse card that doesn't have the same name as a Curse attached to enchanted player");
filter.add(SubType.CURSE.getPredicate());
// get the names of attached Curses
for (UUID attachmentId : targetPlayer.getAttachments()) {
Permanent attachment = game.getPermanent(attachmentId);
if (attachment != null && attachment.hasSubtype(SubType.CURSE, game)) {
filter.add(Predicates.not(new NamePredicate(attachment.getName())));
}
}
TargetCardInLibrary targetCard = new TargetCardInLibrary(filter);
if (player.searchLibrary(targetCard, source, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
this.setTargetPointer(new FixedTarget(targetPlayer.getId()));
game.getState().setValue("attachTo:" + card.getId(), targetPlayer.getId());
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
targetPlayer.addAttachment(card.getId(), source, game);
}
}
}
player.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.NamePredicate in project mage by magefree.
the class EchoingDecayEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
if (targetPermanent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
if (CardUtil.haveEmptyName(targetPermanent)) {
// if no name (face down creature) only the creature itself is selected
filter.add(new PermanentIdPredicate(targetPermanent.getId()));
} else {
filter.add(new NamePredicate(targetPermanent.getName()));
}
ContinuousEffect effect = new BoostAllEffect(-2, -2, Duration.EndOfTurn, filter, false);
game.addEffect(effect, source);
return true;
}
return false;
}
Aggregations