use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class MalakirBloodwitchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("Vampire");
filter.add(SubType.VAMPIRE.getPredicate());
int amount = game.getBattlefield().countAll(filter, source.getControllerId(), game);
Set<UUID> opponents = game.getOpponents(source.getControllerId());
int total = 0;
for (UUID opponentUuid : opponents) {
Player opponent = game.getPlayer(opponentUuid);
if (opponent != null) {
total += opponent.loseLife(amount, game, source, false);
}
}
if (total > 0) {
player.gainLife(total, game, source);
}
return true;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class OrvarTheAllFormEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Spell spell = (Spell) this.getValue("spellCast");
if (player == null || spell == null) {
return false;
}
List<Predicate<Permanent>> predicates = spell.getSpellAbility().getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).map(MageItem::getId).map(PermanentIdPredicate::new).collect(Collectors.toList());
if (predicates.isEmpty()) {
return false;
}
FilterPermanent filter = new FilterControlledPermanent("a permanent you control targeted by that spell");
filter.add(Predicates.or(predicates));
filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(source))));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
return new CreateTokenCopyTargetEffect().setTargetPointer(new FixedTarget(target.getFirstTarget(), game)).apply(game, source);
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class RaziasPurificationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Card> chosen = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
Target target1 = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
if (player != null && target1.canChoose(source.getSourceId(), player.getId(), game)) {
int chosenPermanents = 0;
while (player.canRespond() && !target1.isChosen() && target1.canChoose(source.getSourceId(), player.getId(), game) && chosenPermanents < 3) {
player.chooseTarget(Outcome.Benefit, target1, source, game);
for (UUID targetId : target1.getTargets()) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
chosen.add(p);
chosenPermanents++;
}
}
target1.clearChosen();
}
}
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
if (!chosen.contains(permanent)) {
permanent.sacrifice(source, game);
}
}
return true;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class ReadTheRunesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int drawnCards = controller.drawCards(source.getManaCostsToPay().getX(), source, game);
Target target = new TargetControlledPermanent(0, drawnCards, new FilterControlledPermanent(), true);
controller.chooseTarget(Outcome.Sacrifice, target, source, game);
int sacrificedPermanents = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
if (permanent.sacrifice(source, game)) {
sacrificedPermanents++;
}
}
}
controller.discard(drawnCards - sacrificedPermanents, false, false, source, game);
return true;
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class TouchOfTheEternalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterControlledPermanent filter = new FilterControlledPermanent();
Player player = game.getPlayer(source.getControllerId());
int permanentsInPlay = game.getBattlefield().countAll(filter, source.getControllerId(), game);
if (player != null) {
player.setLife(permanentsInPlay, game, source);
return true;
}
return false;
}
Aggregations