use of mage.target.common.TargetOpponent in project mage by magefree.
the class SixyBeastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentEntering(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (permanent != null && controller != null) {
int counterAmount = controller.getAmount(0, 6, "Secretly put up to six counters on " + permanent.getName(), game);
permanent.addCounters(CounterType.P1P1.createInstance(counterAmount), source.getControllerId(), source, game);
Player opponent = null;
Set<UUID> opponents = game.getOpponents(source.getControllerId());
if (!opponents.isEmpty()) {
if (opponents.size() > 1) {
Target targetOpponent = new TargetOpponent(true);
if (controller.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
opponent = game.getPlayer(targetOpponent.getFirstTarget());
}
} else {
opponent = game.getPlayer(opponents.iterator().next());
}
}
if (opponent != null) {
int guessedAmount = opponent.getAmount(0, 6, "Guess the number of counters on " + permanent.getName(), game);
game.informPlayers(opponent.getLogName() + " guessed " + guessedAmount + " as the number of counters on " + permanent.getLogName());
if (counterAmount == guessedAmount) {
permanent.sacrifice(source, game);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class FatesealEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetOpponent(true);
if (controller.choose(outcome, target, source.getSourceId(), game)) {
Player opponent = game.getPlayer(target.getFirstTarget());
if (opponent == null) {
return false;
}
// by looking at the cards with fateseal you have not to reveal the next card
boolean revealed = opponent.isTopCardRevealed();
opponent.setTopCardRevealed(false);
Cards cards = new CardsImpl();
int count = Math.min(fatesealNumber, opponent.getLibrary().size());
if (count == 0) {
return true;
}
for (int i = 0; i < count; i++) {
Card card = opponent.getLibrary().removeFromTop(game);
cards.add(card);
}
TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
target1.setRequired(false);
// move cards to the bottom of the library
while (!cards.isEmpty() && controller.choose(Outcome.Detriment, cards, target1, game)) {
if (!controller.canRespond() || !opponent.canRespond()) {
return false;
}
Card card = cards.get(target1.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, false, false);
}
target1.clearChosen();
}
// move cards to the top of the library
controller.putCardsOnTopOfLibrary(cards, game, source, true);
game.fireEvent(new GameEvent(GameEvent.EventType.FATESEALED, opponent.getId(), source, source.getControllerId()));
controller.setTopCardRevealed(revealed);
return true;
}
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class AkroanHorseCreateTokenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Target target = new TargetOpponent();
target.setNotTarget(true);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.chooseTarget(outcome, target, source, game)) {
ContinuousEffect effect = new AkroanHorseGainControlEffect(Duration.Custom, target.getFirstTarget());
effect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
game.addEffect(effect, source);
return true;
}
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class EcologicalAppreciationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int xValue = source.getManaCostsToPay().getX();
FilterCard filter = new FilterCreatureCard();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard targetCardsInLibrary = new TargetCardInLibrary(0, 4, filter) {
@Override
public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
if (!super.canTarget(playerId, id, source, game)) {
return false;
}
Card card = game.getCard(id);
Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
return isValidTarget(card, disallowedCards);
}
};
targetCardsInLibrary.setNotTarget(true);
targetCardsInLibrary.withChooseHint("Step 1 of 2: Search library");
player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getLibrary().getCards(game)), targetCardsInLibrary, game);
Cards cards = new CardsImpl(targetCardsInLibrary.getTargets());
boolean status = !cards.isEmpty();
if (status) {
int remainingCards = 4 - cards.size();
if (remainingCards > 0) {
TargetCard targetCardsInGY = new TargetCardInYourGraveyard(0, remainingCards, filter) {
@Override
public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
if (!super.canTarget(playerId, id, source, game)) {
return false;
}
Card card = game.getCard(id);
Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
Set<Card> checkList = new HashSet<>();
checkList.addAll(disallowedCards);
checkList.addAll(cards.getCards(game));
return isValidTarget(card, checkList);
}
};
targetCardsInGY.setNotTarget(true);
targetCardsInGY.withChooseHint("Step 2 of 2: Search graveyard");
player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getGraveyard().getCards(game)), targetCardsInGY, game);
cards.addAll(targetCardsInGY.getTargets());
}
TargetOpponent targetOpponent = new TargetOpponent();
targetOpponent.setNotTarget(true);
player.choose(outcome, targetOpponent, source.getSourceId(), game);
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent == null) {
status = false;
}
if (status) {
TargetCard chosenCards = new TargetCard(2, Zone.ALL, StaticFilters.FILTER_CARD);
chosenCards.setNotTarget(true);
opponent.choose(outcome, cards, chosenCards, game);
Cards toShuffle = new CardsImpl(chosenCards.getTargets().stream().map(game::getCard).collect(Collectors.toList()));
player.putCardsOnTopOfLibrary(toShuffle, game, source, false);
cards.removeAll(toShuffle);
player.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
}
player.shuffleLibrary(source, game);
return status;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class WakeToSlaughterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Cards pickedCards = new CardsImpl(getTargetPointer().getTargets(game, source));
if (player != null && !pickedCards.isEmpty()) {
Card cardToHand;
if (pickedCards.size() == 1) {
cardToHand = pickedCards.getRandom(game);
} else {
Player opponent;
Set<UUID> opponents = game.getOpponents(player.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target targetOpponent = new TargetOpponent(true);
player.chooseTarget(Outcome.Detriment, targetOpponent, source, game);
opponent = game.getPlayer(targetOpponent.getFirstTarget());
}
TargetCard target = new TargetCard(1, Zone.GRAVEYARD, new FilterCard());
target.withChooseHint("Card to go to opponent's hand (other goes to battlefield)");
opponent.chooseTarget(outcome, pickedCards, target, source, game);
cardToHand = game.getCard(target.getFirstTarget());
}
for (Card card : pickedCards.getCards(game)) {
if (card == cardToHand) {
player.moveCards(cardToHand, Zone.HAND, source, game);
} else {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
FixedTarget fixedTarget = new FixedTarget(card, game);
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfGame);
effect.setTargetPointer(fixedTarget);
game.addEffect(effect, source);
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(fixedTarget);
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
pickedCards.clear();
return true;
}
return false;
}
Aggregations