Simplify implementation and fix bugs of Kaito, Dancing Shadow (#10639)

Implement PermanentReferenceInCollectionPredicate used by that
convert existing cards to use new Predicate as needed
Replaces PermanentInListPredicate for longer term effects
This commit is contained in:
ssk97 2023-07-17 20:47:37 -07:00 committed by GitHub
parent 8128e9935d
commit c3f7a9ab21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 166 deletions

View file

@ -20,6 +20,6 @@ public class PermanentInListPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
return permanents.contains(input);
return (permanents != null && permanents.contains(input));
}
}

View file

@ -0,0 +1,33 @@
package mage.filter.predicate.permanent;
import mage.MageObjectReference;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.Collection;
import java.util.stream.Collectors;
/**
*
* @author notgreat
*/
public class PermanentReferenceInCollectionPredicate implements Predicate<Permanent> {
private final Collection<MageObjectReference> references;
public PermanentReferenceInCollectionPredicate(Collection<MageObjectReference> references) {
//Note: it is assumed that the collection passed in isn't ever mutated afterwards
this.references = references;
}
public PermanentReferenceInCollectionPredicate(Collection<Permanent> permanents, Game game) {
this.references = permanents.stream().map((p) -> new MageObjectReference(p, game))
.collect(Collectors.toSet());
}
@Override
public boolean apply(Permanent input, Game game) {
return (references != null &&
references.contains(new MageObjectReference(input, game)));
}
}