extracted duplicate AttachmentAttachedToCardTypePredicate

This commit is contained in:
ingmargoudt 2017-04-05 15:39:35 +02:00
parent 8b90f87af6
commit e44b2fd673
3 changed files with 33 additions and 52 deletions

View file

@ -0,0 +1,31 @@
package mage.filter.predicate.mageobject;
import mage.constants.CardType;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
public class AttachmentAttachedToCardTypePredicate implements Predicate<Permanent> {
private final CardType cardType;
public AttachmentAttachedToCardTypePredicate(CardType cardType) {
this.cardType = cardType;
}
@Override
public boolean apply(Permanent input, Game game) {
if (input.getAttachedTo() != null) {
Permanent attachedTo = game.getPermanent(input.getAttachedTo());
if (attachedTo != null && attachedTo.getCardType().contains(cardType)) {
return true;
}
}
return false;
}
@Override
public String toString() {
return "AttachmentAttachedToCardType(" + cardType + ')';
}
}