use of mage.target.common.TargetCardInHand in project mage by magefree.
the class OracleOfBonesCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetCardInHand(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Cast an instant or sorcery " + "card from your hand without paying its mana cost?", source, game)) {
Card cardToCast = null;
boolean cancel = false;
while (controller.canRespond() && !cancel) {
if (controller.chooseTarget(outcome, target, source, game)) {
cardToCast = game.getCard(target.getFirstTarget());
if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
cancel = true;
}
} else {
cancel = true;
}
}
if (cardToCast != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class AssemblyHallEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || controller.getHand().isEmpty() || sourceObject == null) {
return false;
}
Card cardToReveal = null;
Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
target.setNotTarget(true);
if (controller.chooseTarget(outcome, target, source, game)) {
cardToReveal = game.getCard(target.getFirstTarget());
}
if (cardToReveal == null) {
return false;
}
controller.revealCards("from hand :" + sourceObject.getName(), new CardsImpl(cardToReveal), game);
String nameToSearch = CardUtil.getCardNameForSameNameSearch(cardToReveal);
FilterCard filterCard = new FilterCard("card named " + nameToSearch);
filterCard.add(new NamePredicate(nameToSearch));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filterCard), true, true).apply(game, source);
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class ExtortionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player you = game.getPlayer(source.getControllerId());
if (targetPlayer == null || you == null) {
return false;
}
you.lookAtCards("Discard", targetPlayer.getHand(), game);
TargetCard target = new TargetCardInHand(0, 2, StaticFilters.FILTER_CARD_CARDS);
target.setNotTarget(true);
you.choose(Outcome.Discard, targetPlayer.getHand(), target, game);
targetPlayer.discard(new CardsImpl(target.getTargets()), false, source, game);
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class HypergenesisEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
PlayerList playerList = game.getState().getPlayerList().copy();
while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
playerList.getNext();
}
Player currentPlayer = game.getPlayer(playerList.get());
UUID firstInactivePlayer = null;
Target target = new TargetCardInHand(filter);
while (controller.canRespond()) {
if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
if (firstInactivePlayer == null) {
firstInactivePlayer = currentPlayer.getId();
}
target.clearChosen();
if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game) && currentPlayer.chooseUse(outcome, "Put card from your hand to play?", source, game)) {
if (target.chooseTarget(outcome, currentPlayer.getId(), source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
currentPlayer.moveCards(card, Zone.BATTLEFIELD, source, game);
firstInactivePlayer = null;
}
}
}
}
// get next player
playerList.getNext();
currentPlayer = game.getPlayer(playerList.get());
// if all player since this player didn't put permanent in play finish the process
if (currentPlayer.getId().equals(firstInactivePlayer)) {
break;
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class MindSwordsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// Store for each player the cards to exile, that's important because all exile shall happen at the same time
Map<UUID, Cards> cardsToExile = new HashMap<>();
// Each player chooses 2 cards to discard
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
int numberOfCardsToExile = Math.min(2, player.getHand().size());
Cards cards = new CardsImpl();
Target target = new TargetCardInHand(numberOfCardsToExile, new FilterCard());
player.chooseTarget(Outcome.Exile, target, source, game);
cards.addAll(target.getTargets());
cardsToExile.put(playerId, cards);
}
// Exile all choosen cards
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
Cards cardsPlayerChoseToExile = cardsToExile.get(playerId);
if (cardsPlayerChoseToExile == null) {
continue;
}
player.moveCards(cardsPlayerChoseToExile.getCards(game), Zone.EXILED, source, game);
}
return true;
}
Aggregations