use of mage.filter.FilterPermanent in project mage by magefree.
the class PowderKegEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourcePermanent == null) {
return false;
}
int count = sourcePermanent.getCounters(game).getCount(CounterType.FUSE);
FilterPermanent filter = new FilterPermanent();
filter.add(Predicates.or(CardType.ARTIFACT.getPredicate(), CardType.CREATURE.getPredicate()));
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, count));
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
perm.destroy(source, game, false);
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class ReinsOfTheVinesteedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card aura = game.getCard(source.getSourceId());
if (aura != null && game.getState().getZone(aura.getId()) == Zone.GRAVEYARD) {
Player controller = game.getPlayer(source.getControllerId());
Permanent lastStateAura = (Permanent) game.getLastKnownInformation(aura.getId(), Zone.BATTLEFIELD);
Permanent lastStateCreature = game.getPermanentOrLKIBattlefield(lastStateAura.getAttachedTo());
if (lastStateCreature == null) {
return false;
}
FilterPermanent FILTER = new FilterCreaturePermanent("creature that shares a creature type with " + lastStateCreature.getName());
FILTER.add(new SharesCreatureTypePredicate(lastStateCreature));
TargetPermanent target = new TargetPermanent(FILTER);
target.setNotTarget(true);
if (controller != null && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
if (!targetPermanent.cantBeAttachedBy(aura, source, game, false)) {
game.getState().setValue("attachTo:" + aura.getId(), targetPermanent);
controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
return targetPermanent.addAttachment(aura.getId(), source, game);
}
}
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class SphereOfAnnihilationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = source.getSourcePermanentOrLKI(game);
if (player == null || permanent == null) {
return false;
}
Cards cards = new CardsImpl(permanent);
int counters = permanent.getCounters(game).getCount(CounterType.VOID);
FilterPermanent filter = StaticFilters.FILTER_PERMANENT_CREATURE_OR_PLANESWALKER.copy();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, counters + 1));
cards.addAll(game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game));
game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getGraveyard).map(g -> g.getCards(game)).flatMap(Collection::stream).filter(card -> card.isCreature(game) || card.isPlaneswalker(game)).filter(card -> card.getManaValue() <= counters).forEach(cards::add);
return player.moveCards(cards, Zone.EXILED, source, game);
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class TrygonPredatorTriggeredAbility 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 or enchantment controlled by " + player.getLogName());
filter.add(Predicates.or(CardType.ARTIFACT.getPredicate(), CardType.ENCHANTMENT.getPredicate()));
filter.add(new ControllerIdPredicate(event.getTargetId()));
this.getTargets().clear();
this.addTarget(new TargetPermanent(filter));
return true;
}
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class WeightOfConscienceTarget method canTarget.
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
if (!super.canTarget(id, game)) {
return false;
}
Permanent targetPermanent = game.getPermanent(id);
if (targetPermanent == null) {
return false;
}
if (this.getTargets().isEmpty()) {
List<Permanent> permanentList = game.getBattlefield().getActivePermanents(filterUntapped, source.getControllerId(), source.getSourceId(), game);
if (permanentList.size() < 2) {
return false;
}
for (Permanent permanent : permanentList) {
if (permanent.isAllCreatureTypes(game)) {
return true;
}
FilterPermanent filter = filterUntapped.copy();
filter.add(new SharesCreatureTypePredicate(permanent));
if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 1) {
return true;
}
}
} else {
Permanent firstTarget = game.getPermanent(this.getTargets().get(0));
return firstTarget != null && firstTarget.shareCreatureTypes(game, targetPermanent);
}
return false;
}
Aggregations