use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class EquipoiseEffect method phaseOutCardType.
private void phaseOutCardType(Player controller, Player targetPlayer, CardType cardType, Ability source, Game game) {
FilterPermanent filter = new FilterControlledPermanent();
filter.add(cardType.getPredicate());
int numberController = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
int numberTargetPlayer = game.getBattlefield().count(filter, source.getSourceId(), targetPlayer.getId(), game);
int excess = numberTargetPlayer - numberController;
if (excess > 0) {
FilterPermanent filterChoose = new FilterPermanent(cardType.toString().toLowerCase(Locale.ENGLISH) + (excess > 1 ? "s" : "") + " of target player");
filterChoose.add(new ControllerIdPredicate(targetPlayer.getId()));
filterChoose.add(cardType.getPredicate());
Target target = new TargetPermanent(excess, excess, filterChoose, true);
controller.chooseTarget(outcome, target, source, game);
new PhaseOutAllEffect(target.getTargets()).apply(game, source);
}
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class FeastOfWormsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentOrLKIBattlefield(id);
Player targetPlayer = null;
if (permanent != null) {
targetPlayer = game.getPlayer(permanent.getControllerId());
}
if (targetPlayer != null && permanent != null && (permanent.isLegendary())) {
FilterControlledPermanent filter = new FilterControlledLandPermanent("land to sacrifice");
filter.add(new ControllerIdPredicate(targetPlayer.getId()));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, false);
if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
targetPlayer.chooseTarget(Outcome.Sacrifice, target, source, game);
Permanent land = game.getPermanent(target.getFirstTarget());
if (land != null) {
land.sacrifice(source, game);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class RunEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getTargets().getFirstTarget());
if (targetPlayer != null) {
FilterControlledPermanent filter = new FilterControlledPermanent("artifact or creature");
filter.add(Predicates.or(CardType.ARTIFACT.getPredicate(), CardType.CREATURE.getPredicate()));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
targetPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
int damage = permanent.getManaValue();
if (damage > 0) {
targetPlayer.damage(damage, source.getSourceId(), source, game);
}
}
}
}
return true;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class LilianaDreadhordeGeneralEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent keepFilter = new FilterPermanent();
keepFilter.add(TargetController.OPPONENT.getControllerPredicate());
for (UUID opponentId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player opponent = game.getPlayer(opponentId);
if (opponent == null || !opponent.hasOpponent(source.getControllerId(), game)) {
continue;
}
for (CardType cardType : CardType.values()) {
if (!cardType.isPermanentType()) {
continue;
}
FilterControlledPermanent filter = new FilterControlledPermanent("a " + cardType.toString() + " you control " + "(everything you don't choose will be sacrificed)");
filter.add(cardType.getPredicate());
Target target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (opponent.choose(outcome, target, source.getSourceId(), game)) {
keepFilter.add(Predicates.not(new CardIdPredicate(target.getFirstTarget())));
}
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
if (keepFilter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
permanent.sacrifice(source, game);
}
}
return true;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class MinionLeshracEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent minionLeshrac = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller != null && minionLeshrac != null) {
FilterControlledPermanent filterCreature = new FilterControlledPermanent();
filterCreature.add(CardType.CREATURE.getPredicate());
filterCreature.add(AnotherPredicate.instance);
TargetControlledPermanent target = new TargetControlledPermanent(filterCreature);
SacrificeTargetCost cost = new SacrificeTargetCost(target);
if (controller.chooseUse(Outcome.AIDontUseIt, "Sacrifice another creature to prevent the damage?", source, game) && cost.canPay(source, source, source.getControllerId(), game) && cost.pay(source, game, source, source.getControllerId(), true)) {
return true;
}
if (controller.damage(5, minionLeshrac.getId(), source, game) > 0) {
minionLeshrac.tap(source, game);
return true;
}
}
return false;
}
Aggregations