use of mage.target.common.TargetCardInHand in project mage by magefree.
the class AcademyResearchersEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterCard filterCardInHand = new FilterCard();
filterCardInHand.add(SubType.AURA.getPredicate());
Player controller = game.getPlayer(source.getControllerId());
Permanent academyResearchers = game.getPermanent(source.getSourceId());
if (controller != null && academyResearchers != null) {
filterCardInHand.add(new AuraCardCanAttachToPermanentId(academyResearchers.getId()));
TargetCardInHand target = new TargetCardInHand(0, 1, filterCardInHand);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card auraInHand = game.getCard(target.getFirstTarget());
if (auraInHand != null) {
game.getState().setValue("attachTo:" + auraInHand.getId(), academyResearchers);
controller.moveCards(auraInHand, Zone.BATTLEFIELD, source, game);
if (academyResearchers.addAttachment(auraInHand.getId(), source, game)) {
game.informPlayers(controller.getLogName() + " put " + auraInHand.getLogName() + " on the battlefield attached to " + academyResearchers.getLogName() + '.');
return true;
}
}
}
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class BalancingActEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int minPermanent = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE;
// count minimal permanents
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int count = game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game).size();
if (count < minPermanent) {
minPermanent = count;
}
}
}
// sacrifice permanents over the minimum
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetControlledPermanent target = new TargetControlledPermanent(minPermanent, minPermanent, new FilterControlledPermanent(), true);
if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source.getSourceId(), game)) {
if (permanent != null && !target.getTargets().contains(permanent.getId())) {
permanent.sacrifice(source, game);
}
}
}
}
}
// count minimal cards in hand
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int count = player.getHand().size();
if (count < minCard) {
minCard = count;
}
}
}
// discard cards over the minimum
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard());
if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), game)) {
Cards cards = player.getHand().copy();
cards.removeIf(target.getTargets()::contains);
player.discard(cards, false, source, game);
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class BrineSeerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
RevealTargetFromHandCost cost = new RevealTargetFromHandCost(new TargetCardInHand(0, Integer.MAX_VALUE, filter));
if (!cost.pay(source, game, source, source.getControllerId(), true)) {
return false;
}
int xValue = cost.getNumberRevealedCards();
return new CounterUnlessPaysEffect(new GenericManaCost(xValue)).apply(game, source);
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class DakkonShadowSlayerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
boolean inGrave = player.getGraveyard().count(StaticFilters.FILTER_CARD_ARTIFACT, game) > 0;
if (!inGrave && player.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game) < 1) {
return false;
}
TargetCard target;
if (!inGrave || player.chooseUse(outcome, "Choose a card in your hand or your graveyard?", null, "Hand", "Graveyard", source, game)) {
target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_ARTIFACT);
player.choose(outcome, player.getHand(), target, game);
} else {
target = new TargetCardInGraveyard(0, 1, StaticFilters.FILTER_CARD_ARTIFACT);
player.choose(outcome, player.getGraveyard(), target, game);
}
Card card = game.getCard(target.getFirstTarget());
return card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game);
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class IwamoriOfTheOpenFistEffect 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);
Target target = new TargetCardInHand(filter);
if (opponent != null && target.canChoose(source.getSourceId(), opponent.getId(), game)) {
if (opponent.chooseUse(Outcome.PutCreatureInPlay, "Put a legendary creature card from your hand onto the battlefield?", source, game)) {
if (target.chooseTarget(Outcome.PutCreatureInPlay, opponent.getId(), source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cards.add(card);
}
}
}
}
}
controller.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
return true;
}
return false;
}
Aggregations