use of mage.filter.predicate.mageobject.MageObjectReferencePredicate in project mage by magefree.
the class FarrelsMantleDamageEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent aura = getSourcePermanentOrLKI(game);
if (aura == null || !event.getTargetId().equals(aura.getAttachedTo()) || game.getPermanent(aura.getAttachedTo()) == null) {
return false;
}
MageObjectReference mor = new MageObjectReference(event.getTargetId(), game);
FilterPermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.not(new MageObjectReferencePredicate(mor)));
TargetPermanent target = new TargetPermanent(filter);
target.setTargetController(game.getControllerId(event.getTargetId()));
this.getTargets().clear();
this.addTarget(target);
this.getEffects().clear();
this.addEffect(new FarrelsMantleEffect(mor));
return true;
}
use of mage.filter.predicate.mageobject.MageObjectReferencePredicate 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.predicate.mageobject.MageObjectReferencePredicate in project mage by magefree.
the class StackObjectImpl method createCopyOnStack.
@Override
public void createCopyOnStack(Game game, Ability source, UUID newControllerId, boolean chooseNewTargets, int amount, StackObjectCopyApplier applier) {
GameEvent gameEvent = new CopyStackObjectEvent(source, this, newControllerId, amount);
if (game.replaceEvent(gameEvent)) {
return;
}
Iterator<MageObjectReferencePredicate> newTargetTypeIterator = new NewTargetTypeIterator(game, newControllerId, gameEvent.getAmount(), applier);
for (int i = 0; i < gameEvent.getAmount(); i++) {
createSingleCopy(newControllerId, applier, newTargetTypeIterator.next(), game, source, chooseNewTargets);
}
Player player = game.getPlayer(newControllerId);
if (player == null) {
return;
}
game.informPlayers(player.getName() + " created " + CardUtil.numberToText(gameEvent.getAmount(), "a") + " cop" + (gameEvent.getAmount() == 1 ? "y" : "ies") + " of " + getIdName());
}
use of mage.filter.predicate.mageobject.MageObjectReferencePredicate in project mage by magefree.
the class MindlinkMechApplier method makeFilter.
public static FilterPermanent makeFilter(Ability source, Game game) {
Set<MageObjectReferencePredicate> predicates = game.getState().getWatcher(MindlinkMechWatcher.class).crewMap.computeIfAbsent(new MageObjectReference(source), x -> new HashSet<>()).stream().filter(mor -> {
Permanent permanent = mor.getPermanent(game);
return permanent != null && !permanent.isLegendary() && permanent.isCreature(game);
}).map(MageObjectReferencePredicate::new).collect(Collectors.toSet());
if (predicates.isEmpty()) {
return invalidFilter;
}
FilterPermanent filterPermanent = new FilterPermanent("nonlegendary creature that crewed " + CardUtil.getSourceName(game, source) + " this turn");
filterPermanent.add(Predicates.or(predicates));
return filterPermanent;
}
use of mage.filter.predicate.mageobject.MageObjectReferencePredicate in project mage by magefree.
the class RadiateEffect method prepareCopiesWithTargets.
@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
List<MageObjectReferencePredicate> predicates = new ArrayList<>();
UUID targeted = ((Spell) stackObject).getSpellAbilities().stream().map(AbilityImpl::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).findAny().orElse(null);
game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, player.getId(), source.getSourceId(), game).stream().filter(Objects::nonNull).filter(p -> !p.equals(game.getPermanent(targeted))).filter(p -> stackObject.canTarget(game, p.getId())).map(p -> new MageObjectReference(p, game)).map(MageObjectReferencePredicate::new).forEach(predicates::add);
game.getState().getPlayersInRange(source.getControllerId(), game).stream().filter(uuid -> !uuid.equals(targeted)).filter(uuid -> stackObject.canTarget(game, uuid)).map(MageObjectReference::new).map(MageObjectReferencePredicate::new).forEach(predicates::add);
return predicates;
}
Aggregations