use of mage.target.common.TargetCardInHand in project mage by magefree.
the class StrefanMaurerProgenitorPlayVampireEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetCard target = new TargetCardInHand(0, 1, vampireCardFilter);
if (!player.choose(outcome, player.getHand(), target, game)) {
return false;
}
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, true, null);
Permanent permanent = game.getPermanent(card.getId());
if (permanent == null) {
return false;
}
game.getCombat().addAttackingCreature(permanent.getId(), game);
// Gains indestructable until end of turn
ContinuousEffect effect = new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent.getId(), game));
game.addEffect(effect, source);
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class TemptingWurmEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl();
for (UUID playerId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
Target target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
if (target.canChoose(source.getSourceId(), opponent.getId(), game)) {
if (opponent.chooseUse(Outcome.PutCardInPlay, "Put any artifact, creature, enchantment, and/or land cards cards from your hand onto the battlefield?", source, game)) {
if (target.chooseTarget(Outcome.PutCardInPlay, opponent.getId(), source, game)) {
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
cards.add(card);
}
}
}
}
}
}
}
controller.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class ExileFromZoneTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
Target target = null;
switch(zone) {
case HAND:
target = new TargetCardInHand(Math.min(player.getHand().count(filter, game), amount), filter);
break;
case GRAVEYARD:
target = new TargetCardInYourGraveyard(Math.min(player.getGraveyard().count(filter, game), amount), filter);
break;
default:
}
if (target == null || !target.canChoose(source.getSourceId(), player.getId(), game)) {
return true;
}
target.chooseTarget(Outcome.Exile, player.getId(), source, game);
Cards cards = new CardsImpl(target.getTargets());
if (withSource) {
return player.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
}
return player.moveCards(cards, Zone.EXILED, source, game);
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class AuraSwapEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterCard filterCardToCheck = new FilterCard();
filterCardToCheck.add(SubType.AURA.getPredicate());
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent auraSourcePermanent = game.getPermanent(source.getSourceId());
if (auraSourcePermanent != null && auraSourcePermanent.hasSubtype(SubType.AURA, game) && auraSourcePermanent.isOwnedBy(source.getControllerId())) {
Permanent enchantedPermanent = game.getPermanent(auraSourcePermanent.getAttachedTo());
filterCardToCheck.add(new AuraCardCanAttachToPermanentId(enchantedPermanent.getId()));
TargetCardInHand target = new TargetCardInHand(filterCardToCheck);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card auraInHand = game.getCard(target.getFirstTarget());
if (auraInHand != null) {
game.getState().setValue("attachTo:" + auraInHand.getId(), enchantedPermanent);
controller.moveCards(auraInHand, Zone.BATTLEFIELD, source, game);
enchantedPermanent.addAttachment(auraInHand.getId(), source, game);
game.informPlayers(controller.getLogName() + " put " + auraInHand.getLogName() + " on the battlefield attached to " + enchantedPermanent.getLogName() + '.');
enchantedPermanent.removeAttachment(auraSourcePermanent.getId(), source, game);
return controller.moveCards(auraSourcePermanent, Zone.HAND, source, game);
}
}
}
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class ArsenalThresherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Permanent arsenalThresher = game.getPermanentEntering(source.getSourceId());
FilterArtifactCard filter = new FilterArtifactCard();
filter.add(new AnotherCardPredicate());
if (controller.chooseUse(Outcome.Benefit, "Reveal other artifacts in your hand?", source, game)) {
Cards cards = new CardsImpl();
if (controller.getHand().count(filter, source.getSourceId(), source.getControllerId(), game) > 0) {
TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
if (controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
for (UUID uuid : target.getTargets()) {
cards.add(controller.getHand().get(uuid, game));
}
if (arsenalThresher != null) {
controller.revealCards(arsenalThresher.getIdName(), cards, game);
// the basic event is the EntersBattlefieldEvent, so use already applied replacement effects from that event
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
arsenalThresher.addCounters(CounterType.P1P1.createInstance(cards.size()), source.getControllerId(), source, game, appliedEffects);
}
}
}
return true;
}
return false;
}
Aggregations