use of mage.filter.common.FilterControlledPermanent 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.filter.common.FilterControlledPermanent in project mage by magefree.
the class LichsMirrorEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Player player = game.getPlayer(event.getPlayerId());
if (player != null) {
Cards toLib = new CardsImpl();
FilterControlledPermanent filter = new FilterControlledPermanent();
filter.add(new OwnerIdPredicate(player.getId()));
toLib.addAll(player.getHand());
toLib.addAll(player.getGraveyard());
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
toLib.add(permanent);
}
player.shuffleCardsToLibrary(toLib, game, source);
game.getState().processAction(game);
// original event is not a draw event, so skip it in params
player.drawCards(7, source, game);
player.setLife(20, game, source);
}
// replace the loses event
return true;
}
use of mage.filter.common.FilterControlledPermanent 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.filter.common.FilterControlledPermanent in project mage by magefree.
the class TormentOfVenomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetCreature != null) {
new AddCountersTargetEffect(CounterType.M1M1.createInstance(3)).apply(game, source);
Player controllingPlayer = game.getPlayer(targetCreature.getControllerId());
if (controllingPlayer != null) {
int permanents = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_NON_LAND, controllingPlayer.getId(), game);
if (permanents > 0 && controllingPlayer.chooseUse(outcome, "Sacrifices a nonland permanent?", "Otherwise you have to discard a card or lose 3 life.", "Sacrifice", "Discard or life loss", source, game)) {
FilterPermanent filter = new FilterControlledPermanent("another nonland permanent");
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(Predicates.not(new PermanentIdPredicate(targetCreature.getId())));
Target target = new TargetPermanent(filter);
if (controllingPlayer.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
return true;
}
}
}
if (!controllingPlayer.getHand().isEmpty() && controllingPlayer.chooseUse(outcome, "Discard a card?", "Otherwise you lose 3 life.", "Discard", "Lose 3 life", source, game)) {
controllingPlayer.discardOne(false, false, source, game);
return true;
}
controllingPlayer.loseLife(3, game, source, false);
return true;
}
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class AffinityForLandTypeAbility method getFilter.
private static FilterControlledPermanent getFilter(SubType landType) {
FilterControlledPermanent affinityfilter = new FilterControlledPermanent();
affinityfilter.add(landType.getPredicate());
return affinityfilter;
}
Aggregations