use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class InvokeDespairEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (opponent == null || controller == null) {
return false;
}
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
opponent.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
boolean sacrificed = false;
if (permanent != null) {
sacrificed = permanent.sacrifice(source, game);
}
if (!sacrificed) {
opponent.loseLife(2, game, source, false);
controller.drawCards(1, source, game);
}
target = new TargetControlledPermanent(enchantmentFilter);
target.setNotTarget(true);
opponent.choose(outcome, target, source.getSourceId(), game);
permanent = game.getPermanent(target.getFirstTarget());
sacrificed = false;
if (permanent != null) {
sacrificed = permanent.sacrifice(source, game);
}
if (!sacrificed) {
opponent.loseLife(2, game, source, false);
controller.drawCards(1, source, game);
}
target = new TargetControlledPermanent(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER);
target.setNotTarget(true);
opponent.choose(outcome, target, source.getSourceId(), game);
permanent = game.getPermanent(target.getFirstTarget());
sacrificed = false;
if (permanent != null) {
sacrificed = permanent.sacrifice(source, game);
}
if (!sacrificed) {
opponent.loseLife(2, game, source, false);
controller.drawCards(1, source, game);
}
return true;
}
use of mage.target.common.TargetControlledPermanent 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.target.common.TargetControlledPermanent 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;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ReprocessEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int amount = 0;
TargetControlledPermanent toSacrifice = new TargetControlledPermanent(0, Integer.MAX_VALUE, filter, true);
if (player.chooseTarget(Outcome.Sacrifice, toSacrifice, source, game)) {
for (UUID uuid : toSacrifice.getTargets()) {
Permanent permanent = game.getPermanent(uuid);
if (permanent != null) {
permanent.sacrifice(source, game);
amount++;
}
}
player.drawCards(amount, source, game);
}
return true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ShivanWumpusEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
boolean costPaid = false;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent()));
Player player = game.getPlayer(playerId);
if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice a land?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
costPaid = true;
}
}
if (costPaid) {
super.apply(game, source);
}
return true;
}
return false;
}
Aggregations