use of mage.target.common.TargetCardInHand in project mage by magefree.
the class TheGreatAuroraEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<UUID, List<Permanent>> permanentsOwned = new HashMap<>();
Collection<Permanent> permanents = game.getBattlefield().getActivePermanents(source.getControllerId(), game);
for (Permanent permanent : permanents) {
List<Permanent> list = permanentsOwned.computeIfAbsent(permanent.getOwnerId(), k -> new ArrayList<>());
list.add(permanent);
}
// shuffle permanents and hand cards into owner's library
Map<UUID, Integer> permanentsCount = new HashMap<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int handCards = player.getHand().size();
player.moveCards(player.getHand(), Zone.LIBRARY, source, game);
List<Permanent> list = permanentsOwned.remove(player.getId());
permanentsCount.put(playerId, handCards + (list != null ? list.size() : 0));
if (list != null) {
for (Permanent permanent : list) {
player.moveCardToLibraryWithInfo(permanent, source, game, Zone.BATTLEFIELD, true, true);
}
player.shuffleLibrary(source, game);
}
}
}
// so effects from creatures that were on the battlefield won't trigger from draw or put into play
game.getState().processAction(game);
// Draw cards
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int count = permanentsCount.get(playerId);
if (count > 0) {
player.drawCards(count, source, game);
}
}
}
// put lands onto the battlefield
Cards toBattlefield = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetCard target = new TargetCardInHand(0, Integer.MAX_VALUE, new FilterLandCard("put any number of land cards from your hand onto the battlefield"));
player.chooseTarget(Outcome.PutLandInPlay, player.getHand(), target, source, game);
toBattlefield.addAll(target.getTargets());
}
}
return controller.moveCards(toBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class WidespreadPanicEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player shuffler = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (shuffler != null) {
if (!shuffler.getHand().isEmpty()) {
TargetCardInHand target = new TargetCardInHand();
target.setNotTarget(true);
target.setTargetName("a card from your hand to put on top of your library");
shuffler.choose(Outcome.Detriment, target, source.getSourceId(), game);
Card card = shuffler.getHand().get(target.getFirstTarget(), game);
if (card != null) {
shuffler.moveCardToLibraryWithInfo(card, source, game, Zone.HAND, true, false);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class BaneAlleyBrokerLookAtCardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
controller.drawCards(1, source, game);
if (controller.getHand().isEmpty()) {
return false;
}
TargetCard target = new TargetCardInHand().withChooseHint("to exile");
controller.chooseTarget(outcome, controller.getHand(), target, source, game);
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
if (!controller.moveCardsToExile(card, source, game, false, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source))) {
return false;
}
card.setFaceDown(true, game);
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class DeathrenderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (controller != null && sourcePermanent != null) {
TargetCardInHand target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_CREATURE);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card creatureInHand = game.getCard(target.getFirstTarget());
if (creatureInHand != null) {
if (controller.moveCards(creatureInHand, Zone.BATTLEFIELD, source, game)) {
game.getPermanent(creatureInHand.getId()).addAttachment(sourcePermanent.getId(), source, game);
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class HolyAvengerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = source.getSourcePermanentOrLKI(game);
if (player == null || sourcePermanent == null) {
return false;
}
Permanent permanent = game.getPermanent(sourcePermanent.getAttachedTo());
if (permanent == null) {
return false;
}
FilterCard filter = new FilterCard("an Aura than can enchant " + permanent.getName());
filter.add(SubType.AURA.getPredicate());
filter.add(new AuraCardCanAttachToPermanentId(permanent.getId()));
TargetCardInHand target = new TargetCardInHand(0, 1, filter);
player.choose(Outcome.PutCardInPlay, player.getHand(), target, game);
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
game.getState().setValue("attachTo:" + card.getId(), permanent);
player.moveCards(card, Zone.BATTLEFIELD, source, game);
if (!permanent.addAttachment(card.getId(), source, game)) {
return false;
}
game.informPlayers(player.getLogName() + " put " + card.getLogName() + " on the battlefield attached to " + permanent.getLogName() + '.');
return true;
}
Aggregations