use of mage.cards.Card in project mage by magefree.
the class DiscipleOfDeceitEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (player != null && mageObject != null) {
Cost cost = new DiscardTargetCost(new TargetCardInHand(new FilterNonlandCard()));
String message = "Discard a nonland card to search your library?";
if (cost.canPay(source, source, source.getControllerId(), game) && player.chooseUse(Outcome.Detriment, message, source, game)) {
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
Card card = game.getCard(cost.getTargets().getFirstTarget());
if (card == null) {
return false;
}
String targetName = "card with mana value of " + card.getManaValue();
FilterCard filter = new FilterCard(targetName);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, card.getManaValue()));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);
}
}
return true;
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class ElevenTheMageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
player.drawCards(1, source, game);
player.loseLife(1, game, source, false);
if (player.getHand().size() < 11) {
return true;
}
// TODO: change this to fit with changes made in https://github.com/magefree/mage/pull/8136 when merged
Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
if (!target.canChoose(source.getSourceId(), player.getId(), game) || !player.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery spell " + "from your hand without paying its mana cost?", source, game)) {
return true;
}
Card cardToCast = null;
boolean cancel = false;
while (player.canRespond() && !cancel) {
if (player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
cardToCast = game.getCard(target.getFirstTarget());
if (cardToCast != null) {
if (cardToCast.getSpellAbility() == null) {
Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
cancel = true;
}
if (cardToCast.getSpellAbility().canChooseTarget(game, player.getId())) {
cancel = true;
}
}
} else {
cancel = true;
}
}
if (cardToCast != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class ElkinLairPutIntoGraveyardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && sourcePermanent != null) {
Card[] cards = player.getHand().getCards(new FilterCard(), game).toArray(new Card[0]);
if (cards.length > 0) {
Card card = cards[RandomUtil.nextInt(cards.length)];
if (card != null) {
String exileName = sourcePermanent.getIdName() + " <this card may be played the turn it was exiled";
player.moveCardsToExile(card, source, game, true, source.getSourceId(), exileName);
if (game.getState().getZone(card.getId()) == Zone.EXILED) {
ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
DelayedTriggeredAbility delayed = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ElkinLairPutIntoGraveyardEffect());
game.addDelayedTriggeredAbility(delayed, source);
return true;
}
}
}
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class ElkinBottleCastFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
controller.moveCardsToExile(card, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
ContinuousEffect effect = new ElkinBottleCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), game));
game.addEffect(effect, source);
}
return true;
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class FiendslayerPaladinEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Card targetCard = game.getCard(event.getTargetId());
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (targetCard != null && stackObject != null && targetCard.getId().equals(source.getSourceId())) {
if (stackObject.getColor(game).isBlack() || stackObject.getColor(game).isRed()) {
if (!stackObject.isControlledBy(source.getControllerId()) && stackObject.isInstant(game) || stackObject.isSorcery(game)) {
return true;
}
}
}
return false;
}
Aggregations