use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class ChoiceOfDamnationsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (targetPlayer != null) {
int numberPermanents = game.getState().getBattlefield().countAll(new FilterPermanent(), targetPlayer.getId(), game);
// AI hint
int amount;
if (targetPlayer.isComputer()) {
// AI as defender
int safeLifeToLost = Math.max(0, targetPlayer.getLife() / 2);
amount = Math.min(numberPermanents, safeLifeToLost);
} else {
// Human must choose
amount = targetPlayer.getAmount(0, Integer.MAX_VALUE, "Chooses a number", game);
}
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// AI hint
boolean chooseLoseLife;
if (targetPlayer.isComputer()) {
// AI as attacker
chooseLoseLife = (numberPermanents == 0 || amount <= numberPermanents || targetPlayer.getLife() < amount);
} else {
// Human must choose
chooseLoseLife = controller.chooseUse(outcome, "Shall " + targetPlayer.getLogName() + " lose " + amount + " life?", source, game);
}
if (chooseLoseLife) {
targetPlayer.loseLife(amount, game, source, false);
} else {
// (2005-06-01)
if (numberPermanents > amount) {
int numberToSacrifice = numberPermanents - amount;
Target target = new TargetControlledPermanent(numberToSacrifice, numberToSacrifice, new FilterControlledPermanent("permanent you control to sacrifice"), false);
targetPlayer.chooseTarget(Outcome.Sacrifice, target, source, game);
for (UUID uuid : target.getTargets()) {
Permanent permanent = game.getPermanent(uuid);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
}
}
return true;
}
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class ConsumingVaporsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getTargets().getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
FilterControlledPermanent filter = new FilterControlledPermanent("creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(TargetController.YOU.getControllerPredicate());
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (player != null && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
controller.gainLife(permanent.getToughness().getValue(), game, source);
}
return true;
}
return false;
}
Aggregations