use of mage.target.common.TargetCardInHand in project mage by magefree.
the class SpectersShriekEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(source.getFirstTarget());
if (controller == null || player == null) {
return false;
}
player.revealCards(source, player.getHand(), game);
if (player.getHand().count(StaticFilters.FILTER_CARD_NON_LAND, game) == 0 || !controller.chooseUse(Outcome.Benefit, "Exile a card from " + player.getName() + "'s hand?", source, game)) {
return false;
}
TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard());
target.setNotTarget(true);
target.setRequired(false);
if (!controller.chooseTarget(Outcome.Benefit, player.getHand(), target, source, game)) {
return false;
}
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
boolean isBlack = card.getColor(game).isBlack();
player.moveCards(card, Zone.EXILED, source, game);
if (isBlack || controller.getHand().isEmpty()) {
return true;
}
target = new TargetCardInHand(filter);
target.setNotTarget(true);
return controller.choose(Outcome.Detriment, controller.getHand(), target, game) && controller.moveCards(game.getCard(target.getFirstTarget()), Zone.EXILED, source, game);
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class CardIdPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.drawCards(2, source, game);
SylvanLibraryCardsDrawnThisTurnWatcher watcher = game.getState().getWatcher(SylvanLibraryCardsDrawnThisTurnWatcher.class);
if (watcher != null) {
Cards cards = new CardsImpl();
Set<UUID> cardsDrawnThisTurn = watcher.getCardsDrawnThisTurn(controller.getId());
for (UUID cardId : controller.getHand()) {
if (cardsDrawnThisTurn != null && cardsDrawnThisTurn.contains(cardId)) {
Card card = game.getCard(cardId);
if (card != null) {
cards.add(card);
}
}
}
int numberOfTargets = Math.min(2, cards.size());
if (numberOfTargets > 0) {
FilterCard filter = new FilterCard(numberOfTargets + " cards of cards drawn this turn");
filter.add(new CardIdPredicate(cards));
TargetCardInHand target = new TargetCardInHand(numberOfTargets, filter);
controller.choose(outcome, target, source.getSourceId(), game);
Cards cardsPutBack = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = cards.get(cardId, game);
if (card != null) {
if (controller.canPayLifeCost(source) && controller.getLife() >= 4 && controller.chooseUse(outcome, "Pay 4 life for " + card.getLogName() + "? (Otherwise it's put on top of your library)", source, game)) {
controller.loseLife(4, game, source, false);
game.informPlayers(controller.getLogName() + " pays 4 life to keep a card on hand");
} else {
cardsPutBack.add(card);
}
}
}
controller.putCardsOnTopOfLibrary(cardsPutBack, game, source, true);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class SyphonMindEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int amount = 0;
boolean result = false;
Player you = game.getPlayer(source.getControllerId());
if (you != null) {
for (UUID playerId : game.getState().getPlayersInRange(you.getId(), game)) {
if (!playerId.equals(you.getId())) {
Player otherPlayer = game.getPlayer(playerId);
if (otherPlayer != null && !otherPlayer.getHand().isEmpty()) {
TargetCardInHand target = new TargetCardInHand();
if (otherPlayer.choose(Outcome.Discard, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
if (otherPlayer.discard(card, false, source, game)) {
amount += 1;
result = true;
target.clearChosen();
}
}
}
}
}
}
you.drawCards(amount, source, game);
}
return result;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class ContinuousEffects method applySpliceEffects.
/**
* Checks all available splice effects to be applied.
*
* @param abilityToModify
* @param game
*/
public void applySpliceEffects(Ability abilityToModify, Game game) {
// splice spell - spell can't be spliced again
if (CardUtil.isSpliceAbility(abilityToModify, game)) {
return;
}
// fused spell - can be spliced only to main fused ability, not to parts
if (CardUtil.isFusedPartAbility(abilityToModify, game)) {
return;
}
List<SpliceCardEffect> spliceEffects = getApplicableSpliceCardEffects(game, abilityToModify.getControllerId());
// get the applyable splice abilities
List<Ability> spliceAbilities = new ArrayList<>();
for (SpliceCardEffect effect : spliceEffects) {
Set<Ability> abilities = spliceCardEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
if (effect.applies(abilityToModify, ability, game)) {
spliceAbilities.add(ability);
}
}
}
if (!spliceAbilities.isEmpty()) {
Player controller = game.getPlayer(abilityToModify.getControllerId());
if (controller.chooseUse(Outcome.Benefit, "Splice a card?", abilityToModify, game)) {
Cards cardsToReveal = new CardsImpl();
do {
FilterCard filter = new FilterCard("a card to splice");
List<Predicate<MageObject>> idPredicates = new ArrayList<>();
for (Ability ability : spliceAbilities) {
idPredicates.add(new CardIdPredicate((ability.getSourceId())));
}
filter.add(Predicates.or(idPredicates));
TargetCardInHand target = new TargetCardInHand(filter);
controller.chooseTarget(Outcome.Benefit, target, abilityToModify, game);
UUID cardId = target.getFirstTarget();
if (cardId != null) {
Ability selectedAbility = null;
for (Ability ability : spliceAbilities) {
if (ability.getSourceId().equals(cardId)) {
selectedAbility = ability;
break;
}
}
if (selectedAbility != null) {
SpliceCardEffect spliceEffect = (SpliceCardEffect) selectedAbility.getEffects().get(0);
spliceEffect.apply(game, selectedAbility, abilityToModify);
cardsToReveal.add(game.getCard(cardId));
spliceAbilities.remove(selectedAbility);
}
}
} while (!spliceAbilities.isEmpty() && controller.chooseUse(Outcome.Benefit, "Splice another card?", abilityToModify, game));
controller.revealCards("Spliced cards", cardsToReveal, game);
}
}
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class LondonMulligan method mulligan.
@Override
public void mulligan(Game game, UUID playerId) {
Player player = game.getPlayer(playerId);
int numCards = startingHandSizes.get(player.getId());
player.getLibrary().addAll(player.getHand().getCards(game), game);
player.getHand().clear();
player.shuffleLibrary(null, game);
int deduction = 1;
if (freeMulligans > 0) {
if (usedFreeMulligans.containsKey(player.getId())) {
int used = usedFreeMulligans.get(player.getId());
if (used < freeMulligans) {
deduction = 0;
usedFreeMulligans.put(player.getId(), used + 1);
}
} else {
deduction = 0;
usedFreeMulligans.put(player.getId(), 1);
}
}
openingHandSizes.put(playerId, openingHandSizes.get(playerId) - deduction);
int newHandSize = openingHandSizes.get(player.getId());
if (deduction == 0) {
game.fireInformEvent(player.getLogName() + " mulligans for free.");
} else {
game.fireInformEvent(player.getLogName() + " mulligans down to " + newHandSize + (newHandSize == 1 ? " card" : " cards"));
}
player.drawCards(numCards, null, game);
while (player.canRespond() && player.getHand().size() > newHandSize) {
Target target = new TargetCardInHand(new FilterCard("card (" + (player.getHand().size() - newHandSize) + " more) to put on the bottom of your library"));
player.chooseTarget(Outcome.Discard, target, null, game);
player.putCardsOnBottomOfLibrary(new CardsImpl(target.getTargets()), game, null, true);
}
}
Aggregations