use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DesolationWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
DesolationWatcher watcher = game.getState().getWatcher(DesolationWatcher.class);
if (watcher == null) {
return false;
}
List<Permanent> permanents = new ArrayList<>();
for (UUID playerId : watcher.getPlayersTappedForMana()) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
TargetPermanent target = new TargetControlledPermanent(StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND);
target.setNotTarget(true);
if (!target.canChoose(source.getSourceId(), player.getId(), game)) {
continue;
}
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanents.add(permanent);
}
}
for (Permanent permanent : permanents) {
Player player = game.getPlayer(permanent.getControllerId());
if (permanent != null && permanent.sacrifice(source, game) && permanent.hasSubtype(SubType.PLAINS, game) && player != null) {
player.damage(2, source.getSourceId(), source, game);
}
}
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DesecrationDemonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent descrationDemon = game.getPermanent(source.getSourceId());
if (controller != null && descrationDemon != null) {
for (UUID opponentId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null) {
FilterControlledPermanent filter = new FilterControlledPermanent("creature to sacrifice");
filter.add(CardType.CREATURE.getPredicate());
filter.add(TargetController.YOU.getControllerPredicate());
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, false);
if (target.canChoose(source.getSourceId(), opponent.getId(), game)) {
if (opponent.chooseUse(Outcome.AIDontUseIt, "Sacrifice a creature to tap " + descrationDemon.getLogName() + "and put a +1/+1 counter on it?", source, game)) {
opponent.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
game.informPlayers(opponent.getLogName() + " sacrifices " + permanent.getLogName() + " to tap " + descrationDemon.getLogName() + ". A +1/+1 counter was put on it");
descrationDemon.tap(source, game);
descrationDemon.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class LichsMasteryLoseLifeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterPermanent filter = new FilterPermanent();
filter.add(new ControllerIdPredicate(controller.getId()));
for (int i = 0; i < amount; i++) {
int handCount = controller.getHand().size();
int graveCount = controller.getGraveyard().size();
int permCount = game.getBattlefield().getActivePermanents(filter, controller.getId(), game).size();
if (graveCount + handCount == 0 || (permCount > 0 && controller.chooseUse(Outcome.Exile, "Exile permanent you control? (No = from hand or graveyard)", source, game))) {
Target target = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
controller.choose(outcome, target, source.getSourceId(), game);
Effect effect = new ExileTargetEffect();
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
effect.apply(game, source);
} else if (graveCount == 0 || (handCount > 0 && controller.chooseUse(Outcome.Exile, "Exile a card from your hand? (No = from graveyard)", source, game))) {
Target target = new TargetCardInHand(1, 1, new FilterCard());
controller.choose(outcome, target, source.getSourceId(), game);
Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
}
} else if (graveCount > 0) {
Target target = new TargetCardInYourGraveyard(1, 1, new FilterCard(), true);
target.choose(Outcome.Exile, source.getControllerId(), source.getSourceId(), game);
Card card = controller.getGraveyard().get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
}
}
}
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class TazeemRaptorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetPermanent target = new TargetControlledPermanent(0, 1, StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND, true);
player.choose(outcome, target, source.getSourceId(), game);
return player.moveCards(game.getCard(target.getFirstTarget()), Zone.HAND, source, game);
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DeterminedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent("a creature (to sacrifice)"), true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
if (controller.chooseTarget(outcome, target, source, game)) {
Permanent toSacrifice = game.getPermanent(target.getFirstTarget());
if (toSacrifice != null) {
toSacrifice.sacrifice(source, game);
game.getState().processAction(game);
int colors = toSacrifice.getColor(game).getColorCount();
if (colors > 0) {
TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(0, colors, new FilterCard("up to " + colors + " card" + (colors > 1 ? "s" : "") + " from your graveyard"));
controller.chooseTarget(outcome, targetCard, source, game);
controller.moveCards(new CardsImpl(targetCard.getTargets()), Zone.HAND, source, game);
}
}
}
}
return true;
}
return false;
}
Aggregations