use of mage.filter.FilterPermanent in project mage by magefree.
the class LavalancheEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayerOrPlaneswalkerController(source.getFirstTarget());
if (targetPlayer == null) {
return false;
}
targetPlayer.damage(amount.calculate(game, source, this), source.getSourceId(), source, game);
FilterPermanent filter = new FilterPermanent("and each creature that player or that planeswalker's controller controls");
filter.add(CardType.CREATURE.getPredicate());
filter.add(new ControllerIdPredicate(targetPlayer.getId()));
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
for (Permanent permanent : permanents) {
permanent.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, true);
}
return true;
}
use of mage.filter.FilterPermanent 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.FilterPermanent in project mage by magefree.
the class PsychicAllergyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) {
FilterPermanent filter = new FilterPermanent();
filter.add(new ColorPredicate((ObjectColor) game.getState().getValue(source.getSourceId() + "_color")));
filter.add(TokenPredicate.FALSE);
int damage = game.getBattlefield().countAll(filter, player.getId(), game);
player.damage(damage, source.getSourceId(), source, game);
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class SingleCombatRestrictionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent filterSac = new FilterCreatureOrPlaneswalkerPermanent();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
filterSac.add(Predicates.not(new PermanentIdPredicate(target.getFirstTarget())));
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterSac, source.getControllerId(), game)) {
permanent.sacrifice(source, game);
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class SteelHellkiteWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
SteelHellkiteWatcher watcher = game.getState().getWatcher(SteelHellkiteWatcher.class);
if (watcher == null || watcher.getDamagedPlayers(source.getSourceId()).isEmpty()) {
return false;
}
Set<Predicate<Permanent>> predicateSet = new HashSet<>();
for (UUID playerId : watcher.getDamagedPlayers(source.getSourceId())) {
predicateSet.add(new ControllerIdPredicate(playerId));
}
FilterPermanent filter = new FilterNonlandPermanent();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
filter.add(Predicates.or(predicateSet));
return new DestroyAllEffect(filter).apply(game, source);
}
Aggregations