use of mage.target.common.TargetOpponent in project mage by magefree.
the class DemonicHordesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent demonicHordes = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && demonicHordes != null) {
StringBuilder sb = new StringBuilder(cost.getText()).append('?');
if (!sb.toString().toLowerCase(Locale.ENGLISH).startsWith("exile ") && !sb.toString().toLowerCase(Locale.ENGLISH).startsWith("return ")) {
sb.insert(0, "Pay ");
}
if (controller.chooseUse(Outcome.Benefit, sb.toString(), source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
return true;
}
}
demonicHordes.tap(source, game);
Target choiceOpponent = new TargetOpponent();
choiceOpponent.setNotTarget(true);
FilterLandPermanent filterLand = new FilterLandPermanent();
filterLand.add(new ControllerIdPredicate(source.getControllerId()));
if (controller.choose(Outcome.Neutral, choiceOpponent, source.getSourceId(), game)) {
Player opponent = game.getPlayer(choiceOpponent.getFirstTarget());
if (opponent != null) {
Target chosenLand = new TargetLandPermanent(filterLand);
chosenLand.setNotTarget(true);
if (opponent.chooseTarget(Outcome.Sacrifice, chosenLand, source, game)) {
Permanent land = game.getPermanent(chosenLand.getFirstTarget());
if (land != null) {
land.sacrifice(source, game);
}
}
}
return true;
}
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class AllureOfTheUnknownEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
player.revealCards(source, cards, game);
if (cards.count(StaticFilters.FILTER_CARD_NON_LAND, game) == 0) {
return player.moveCards(cards, Zone.HAND, source, game);
}
TargetOpponent targetOpponent = new TargetOpponent(true);
if (!player.choose(outcome, targetOpponent, source.getSourceId(), game)) {
return false;
}
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent == null) {
return false;
}
TargetCard targetCard = new TargetCardInLibrary(StaticFilters.FILTER_CARD_A_NON_LAND);
opponent.choose(Outcome.Exile, cards, targetCard, game);
Card card = game.getCard(targetCard.getFirstTarget());
if (player.moveCards(card, Zone.EXILED, source, game) && card != null && game.getState().getZone(card.getId()) == Zone.EXILED) {
cards.remove(card);
}
player.moveCards(cards, Zone.HAND, source, game);
if (opponent.chooseUse(outcome, "Cast the exiled card without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
opponent.cast(opponent.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
return true;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class BenevolentOfferingEffect2 method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetOpponent(true);
target.choose(Outcome.Sacrifice, source.getControllerId(), source.getSourceId(), game);
Player opponent = game.getPlayer(target.getFirstTarget());
if (opponent != null) {
int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game) * 2;
controller.gainLife(count, game, source);
count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game) * 2;
opponent.gainLife(count, game, source);
return true;
}
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class AnimalMagnetismEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
if (!cards.isEmpty()) {
controller.revealCards(staticText, cards, game);
Card cardToBattlefield;
if (cards.size() == 1) {
cardToBattlefield = cards.getRandom(game);
} else {
Player opponent;
Set<UUID> opponents = game.getOpponents(controller.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target target = new TargetOpponent(true);
controller.chooseTarget(Outcome.Detriment, target, source, game);
opponent = game.getPlayer(target.getFirstTarget());
}
TargetCard target = new TargetCard(1, Zone.LIBRARY, StaticFilters.FILTER_CARD_CREATURE);
opponent.chooseTarget(outcome, cards, target, source, game);
cardToBattlefield = game.getCard(target.getFirstTarget());
}
if (cardToBattlefield != null) {
controller.moveCards(cardToBattlefield, Zone.BATTLEFIELD, source, game);
cards.remove(cardToBattlefield);
}
controller.moveCards(cards, Zone.GRAVEYARD, source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class BurningRuneDemonTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TargetCardInLibrary targetCardInLibrary = new BurningRuneDemonTarget();
if (controller.searchLibrary(targetCardInLibrary, source, game)) {
Cards cards = new CardsImpl(targetCardInLibrary.getTargets());
if (!cards.isEmpty()) {
Player opponent;
Set<UUID> opponents = game.getOpponents(controller.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
TargetOpponent targetOpponent = new TargetOpponent(true);
controller.chooseTarget(Outcome.Detriment, targetOpponent, source, game);
opponent = game.getPlayer(targetOpponent.getFirstTarget());
}
if (opponent != null) {
TargetCard targetCard = new TargetCard(Zone.LIBRARY, StaticFilters.FILTER_CARD);
targetCard.withChooseHint("Card to go to opponent's hand (other goes to graveyard)");
opponent.chooseTarget(outcome, cards, targetCard, source, game);
Card cardToHand = game.getCard(targetCard.getFirstTarget());
if (cardToHand != null) {
controller.moveCards(cardToHand, Zone.HAND, source, game);
cards.remove(cardToHand);
}
if (!cards.isEmpty()) {
controller.moveCards(cards, Zone.GRAVEYARD, source, game);
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
}
return false;
}
Aggregations