use of mage.filter.FilterPermanent in project mage by magefree.
the class SameNameAsExiledCountValue method calculate.
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int value = 0;
Permanent permanent = game.getPermanent(sourceAbility.getSourceId());
if (permanent != null && !permanent.getImprinted().isEmpty()) {
FilterPermanent filterPermanent = new FilterPermanent();
filterPermanent.add(new NamePredicate(game.getCard(permanent.getImprinted().get(0)).getName()));
value = game.getBattlefield().count(filterPermanent, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
}
return value;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class TariffEffect method getPermanentsWithTheHighestCMC.
private List<Permanent> getPermanentsWithTheHighestCMC(Game game, UUID playerId, FilterPermanent filter) {
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(filter, playerId, game);
int highestCMC = -1;
for (Permanent permanent : permanents) {
if (highestCMC < permanent.getManaValue()) {
highestCMC = permanent.getManaValue();
}
}
List<Permanent> result = new ArrayList<>();
for (Permanent permanent : permanents) {
if (permanent.getManaValue() == highestCMC) {
result.add(permanent);
}
}
return result;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class TormentOfVenomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetCreature != null) {
new AddCountersTargetEffect(CounterType.M1M1.createInstance(3)).apply(game, source);
Player controllingPlayer = game.getPlayer(targetCreature.getControllerId());
if (controllingPlayer != null) {
int permanents = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_NON_LAND, controllingPlayer.getId(), game);
if (permanents > 0 && controllingPlayer.chooseUse(outcome, "Sacrifices a nonland permanent?", "Otherwise you have to discard a card or lose 3 life.", "Sacrifice", "Discard or life loss", source, game)) {
FilterPermanent filter = new FilterControlledPermanent("another nonland permanent");
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(Predicates.not(new PermanentIdPredicate(targetCreature.getId())));
Target target = new TargetPermanent(filter);
if (controllingPlayer.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
return true;
}
}
}
if (!controllingPlayer.getHand().isEmpty() && controllingPlayer.chooseUse(outcome, "Discard a card?", "Otherwise you lose 3 life.", "Discard", "Lose 3 life", source, game)) {
controllingPlayer.discardOne(false, false, source, game);
return true;
}
controllingPlayer.loseLife(3, game, source, false);
return true;
}
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class AshiokSculptorOfFearsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(source.getFirstTarget()));
new GainControlAllEffect(Duration.Custom, filter).apply(game, source);
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class CausticWaspsTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.sourceId) && ((DamagedPlayerEvent) event).isCombatDamage()) {
Player player = game.getPlayer(event.getTargetId());
if (player != null) {
FilterPermanent filter = new FilterPermanent("an artifact controlled by " + player.getLogName());
filter.add(CardType.ARTIFACT.getPredicate());
filter.add(new ControllerIdPredicate(event.getTargetId()));
this.getTargets().clear();
this.addTarget(new TargetPermanent(filter));
return true;
}
}
return false;
}
Aggregations