use of mage.cards.Card in project mage by magefree.
the class SuddenReclamationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cardsToHand = new CardsImpl();
Target target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cardsToHand.add(card);
}
}
target = new TargetCardInYourGraveyard(new FilterLandCard("land card from your graveyard"));
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cardsToHand.add(card);
}
}
controller.moveCards(cardsToHand, Zone.HAND, source, game);
return true;
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class SufferThePastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterCard filter = new FilterCard("card in target player's graveyard");
int numberExiled = 0;
Player you = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (targetPlayer != null) {
int numberToTarget = Math.min(targetPlayer.getGraveyard().size(), source.getManaCostsToPay().getX());
TargetCardInOpponentsGraveyard target = new TargetCardInOpponentsGraveyard(numberToTarget, numberToTarget, filter);
if (you != null) {
if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
if (!target.getTargets().isEmpty()) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = game.getCard(targetId);
if (card != null) {
card.moveToExile(id, "Suffer the Past", source, game);
numberExiled++;
}
}
you.gainLife(numberExiled, game, source);
targetPlayer.loseLife(numberExiled, game, source, false);
}
}
return true;
}
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class CardCanBeCastPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.getLibrary().hasCards()) {
/**
* 10/1/2005 Any card you find must be legally cast-able (for
* example, you have to be able to choose a legal target for
* it). If you can't find a cast-able card (or choose not to),
* nothing happens and you shuffle your library.
*/
FilterCard filter = new FilterCard("red or white instant card with mana value 4 or less");
TargetCardInLibrary target = new TargetCardInLibrary(filter);
filter.add(Predicates.or(new ColorPredicate(ObjectColor.RED), new ColorPredicate(ObjectColor.WHITE)));
filter.add(CardType.INSTANT.getPredicate());
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 5));
filter.add(new CardCanBeCastPredicate(source.getControllerId()));
if (controller.searchLibrary(target, source, game, controller.getId())) {
UUID targetId = target.getFirstTarget();
Card card = game.getCard(targetId);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class TezzeretTheSeekerEffect3 method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int cmc = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof PayVariableLoyaltyCost) {
cmc = ((PayVariableLoyaltyCost) cost).getAmount();
}
}
FilterArtifactCard filter = new FilterArtifactCard("artifact card with mana value " + cmc + " or less");
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, cmc + 1));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
return false;
}
use of mage.cards.Card in project mage by magefree.
the class TestOfTalentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
if (stackObject == null) {
return false;
}
MageObject targetObject = game.getObject(stackObject.getSourceId());
String cardName;
if (targetObject instanceof Card) {
cardName = targetObject.getName();
} else {
cardName = "";
}
UUID searchPlayerId = stackObject.getControllerId();
Player player = game.getPlayer(searchPlayerId);
if (player == null) {
return false;
}
int previousCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
game.getStack().counter(source.getFirstTarget(), source, game);
this.applySearchAndExile(game, source, cardName, searchPlayerId);
int newCount = player.getHand().getCards(game).stream().map(MageObject::getName).filter(Objects::nonNull).mapToInt(s -> CardUtil.haveSameNames(s, cardName) ? 1 : 0).sum();
if (previousCount > newCount) {
player.drawCards(previousCount - newCount, source, game);
}
return true;
}
Aggregations