use of mage.filter.FilterPermanent in project mage by magefree.
the class PerniciousDeedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent filter = new FilterPermanent("artifacts, creatures, and enchantments");
filter.add(Predicates.or(CardType.ARTIFACT.getPredicate(), CardType.CREATURE.getPredicate(), CardType.ENCHANTMENT.getPredicate()));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
return new DestroyAllEffect(filter).apply(game, source);
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class PeerPressureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Choice choice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
if (controller != null && controller.choose(Outcome.GainControl, choice, game)) {
String chosenType = choice.getChoice();
game.informPlayers(controller.getLogName() + " has chosen " + chosenType);
UUID playerWithMost = null;
int maxControlled = 0;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
FilterPermanent filter = new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType);
filter.add(new ControllerIdPredicate(playerId));
int controlled = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
if (controlled > maxControlled) {
maxControlled = controlled;
playerWithMost = playerId;
} else if (controlled == maxControlled) {
// Do nothing in case of tie
playerWithMost = null;
}
}
if (playerWithMost != null && playerWithMost.equals(controller.getId())) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType), controller.getId(), source.getSourceId(), game)) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class SabaccGameEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent targetPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (targetPermanent != null) {
Player opponent = game.getPlayer(targetPermanent.getControllerId());
if (opponent != null) {
FilterPermanent filter = new FilterPermanent("permanent controlled by " + controller.getName());
filter.add(new ControllerIdPredicate(controller.getId()));
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
Permanent chosenPermanent = null;
if (target.chooseTarget(outcome, opponent.getId(), source, game)) {
chosenPermanent = game.getPermanent(target.getFirstTarget());
}
boolean flipWin = controller.flipCoin(source, game, true);
if (flipWin) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, controller.getId());
effect.setTargetPointer(new FixedTarget(targetPermanent, game));
game.addEffect(effect, source);
} else if (chosenPermanent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
effect.setTargetPointer(new FixedTarget(chosenPermanent, game));
game.addEffect(effect, source);
}
}
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class VaevictisAsmadiTheDireEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!game.getCombat().getAttackers().contains(this.getSourceId())) {
return false;
}
this.getTargets().clear();
for (UUID playerId : game.getState().getPlayerList(this.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
FilterPermanent filter = new FilterPermanent("permanent controlled by " + player.getName());
filter.add(new ControllerIdPredicate(playerId));
TargetPermanent target = new TargetPermanent(filter);
this.addTarget(target);
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class ZzzyxassAbyssEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<String> permanentNames = new ArrayList<>();
FilterPermanent filter = new FilterNonlandPermanent();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
permanentNames.add(permanent.getName());
}
if (permanentNames.isEmpty()) {
return true;
}
Collections.sort(permanentNames);
filter.add(new NamePredicate(permanentNames.get(0)));
return new DestroyAllEffect(filter).apply(game, source);
}
return false;
}
Aggregations