use of mage.abilities.costs.common.ExileFromHandCost in project mage by magefree.
the class HolisticWisdomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getFirstTarget());
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
for (Cost cost : source.getCosts()) {
if (cost instanceof ExileFromHandCost) {
List<CardType> cardtypes = new ArrayList<>();
ExileFromHandCost exileCost = (ExileFromHandCost) cost;
for (CardType cardtype : exileCost.getCards().get(0).getCardType(game)) {
cardtypes.add(cardtype);
}
for (CardType cardtype : card.getCardType(game)) {
if (cardtypes.contains(cardtype)) {
Effect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), game));
return effect.apply(game, source);
}
}
}
}
}
return false;
}
use of mage.abilities.costs.common.ExileFromHandCost in project mage by magefree.
the class JhoiraOfTheGhituSuspendEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<Card> cards = new ArrayList<>();
for (Cost cost : source.getCosts()) {
if (cost instanceof ExileFromHandCost) {
cards = ((ExileFromHandCost) cost).getCards();
}
}
if (cards != null && !cards.isEmpty()) {
// always one card to exile
Card card = game.getCard(cards.get(0).getId());
if (card == null) {
return false;
}
card = card.getMainCard();
boolean hasSuspend = card.getAbilities(game).containsClass(SuspendAbility.class);
UUID exileId = SuspendAbility.getSuspendExileId(controller.getId(), game);
if (controller.moveCardToExileWithInfo(card, exileId, "Suspended cards of " + controller.getName(), source, game, Zone.HAND, true)) {
card.addCounters(CounterType.TIME.createInstance(4), source.getControllerId(), source, game);
if (!hasSuspend) {
game.addEffect(new GainSuspendEffect(new MageObjectReference(card, game)), source);
}
game.informPlayers(controller.getLogName() + " suspends 4 - " + card.getName());
return true;
}
}
return false;
}
use of mage.abilities.costs.common.ExileFromHandCost in project mage by magefree.
the class ExileCardsFromHandAdjuster method adjustCosts.
@Override
public void adjustCosts(Ability ability, Game game) {
if (game.inCheckPlayableState()) {
return;
}
Player player = game.getPlayer(ability.getControllerId());
if (player == null) {
return;
}
int cardCount = player.getHand().count(filter, game);
int toExile = cardCount > 0 ? player.getAmount(0, cardCount, "Choose how many " + filter.getMessage() + " to exile", game) : 0;
if (toExile > 0) {
ability.addCost(new ExileFromHandCost(new TargetCardInHand(toExile, filter)));
CardUtil.reduceCost(ability, 2 * toExile);
}
}
use of mage.abilities.costs.common.ExileFromHandCost in project mage by magefree.
the class GemstoneCavernsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean result = false;
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card card = game.getCard(source.getSourceId());
if (card != null) {
ContinuousEffect effect = new EntersBattlefieldEffect(new AddCountersSourceEffect(CounterType.LUCK.createInstance()), "");
effect.setDuration(Duration.OneUse);
game.addEffect(effect, source);
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
Cost cost = new ExileFromHandCost(new TargetCardInHand());
if (cost.canPay(source, source, source.getControllerId(), game)) {
result = cost.pay(source, game, source, source.getControllerId(), true, null);
}
}
}
}
}
return result;
}
Aggregations