some more equipment-related filter changes

This commit is contained in:
theelk801 2025-05-27 07:32:49 -04:00
parent f5d48634a3
commit d223d9aad4
21 changed files with 105 additions and 280 deletions

View file

@ -1,17 +1,17 @@
package mage.filter.predicate.permanent;
import java.util.UUID;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.Optional;
/**
*
* @author LoneFox
*/
public class AttachedToPredicate implements Predicate<Permanent> {
public class AttachedToPredicate implements ObjectSourcePlayerPredicate<Permanent> {
private final FilterPermanent filter;
@ -20,10 +20,14 @@ public class AttachedToPredicate implements Predicate<Permanent> {
}
@Override
public boolean apply(Permanent input, Game game) {
UUID attachedTo = input.getAttachedTo();
Permanent permanent = game.getPermanent(attachedTo);
return filter.match(permanent, game);
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return Optional
.ofNullable(input)
.map(ObjectSourcePlayer::getObject)
.map(Permanent::getAttachedTo)
.map(game::getPermanent)
.map(permanent -> filter.match(permanent, input.getPlayerId(), input.getSource(), game))
.orElse(false);
}
@Override

View file

@ -5,8 +5,6 @@ import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.Optional;
/**
* @author Susucr
*/
@ -15,10 +13,7 @@ public enum AttachedToSourcePredicate implements ObjectSourcePlayerPredicate<Per
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return Optional.of(input.getObject())
.map(Permanent::getAttachedTo)
.filter(p -> p.equals(input.getSourceId()))
.isPresent();
return input.getObject().isAttachedTo(input.getSourceId());
}
@Override