From 44d4eae8a145ae47339710eedd05e485f9bd56b8 Mon Sep 17 00:00:00 2001 From: Lyu Zong-Hong Date: Thu, 15 Apr 2021 16:15:59 +0900 Subject: [PATCH] Filter more cards in getTargetableCards --- .../main/java/forge/game/card/CardLists.java | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/forge-game/src/main/java/forge/game/card/CardLists.java b/forge-game/src/main/java/forge/game/card/CardLists.java index c08fd8c6046..4d1dc53fbe6 100644 --- a/forge-game/src/main/java/forge/game/card/CardLists.java +++ b/forge-game/src/main/java/forge/game/card/CardLists.java @@ -30,6 +30,7 @@ import forge.game.CardTraitBase; import forge.game.keyword.Keyword; import forge.game.player.Player; import forge.game.spellability.SpellAbility; +import forge.game.spellability.TargetRestrictions; import forge.util.MyRandom; import forge.util.collect.FCollectionView; @@ -230,7 +231,67 @@ public class CardLists { } public static CardCollection getTargetableCards(Iterable cardList, SpellAbility source) { - return CardLists.filter(cardList, CardPredicates.isTargetableBy(source)); + CardCollection result = CardLists.filter(cardList, CardPredicates.isTargetableBy(source)); + // Filter more cards that can only be detected along with other candiates + if (source.getTargets().isEmpty() && source.getMinTargets() >= 2) { + CardCollection removeList = new CardCollection(); + TargetRestrictions tr = source.getTargetRestrictions(); + for (final Card card : cardList) { + if (tr.isSameController()) { + boolean found = false; + for (final Card card2 : cardList) { + if (card != card2 && card.getController() == card2.getController()) { + found = true; + break; + } + } + if (!found) { + removeList.add(card); + } + } + + if (tr.isWithoutSameCreatureType()) { + boolean found = false; + for (final Card card2 : cardList) { + if (card != card2 && !card.sharesCreatureTypeWith(card2)) { + found = true; + break; + } + } + if (!found) { + removeList.add(card); + } + } + + if (tr.isWithSameCreatureType()) { + boolean found = false; + for (final Card card2 : cardList) { + if (card != card2 && card.sharesCreatureTypeWith(card2)) { + found = true; + break; + } + } + if (!found) { + removeList.add(card); + } + } + + if (tr.isWithSameCardType()) { + boolean found = false; + for (final Card card2 : cardList) { + if (card != card2 && card.sharesCardTypeWith(card2)) { + found = true; + break; + } + } + if (!found) { + removeList.add(card); + } + } + } + result.removeAll(removeList); + } + return result; } public static CardCollection getKeyword(Iterable cardList, final String keyword) {