Fixed that TargetCard ignore filter in some calls

This commit is contained in:
Oleg Agafonov 2019-12-16 02:55:13 +04:00
parent 690f5f688d
commit 0885a01849
7 changed files with 93 additions and 58 deletions

View file

@ -1,11 +1,7 @@
package mage.target;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import mage.MageItem;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.cards.Cards;
import mage.constants.Zone;
@ -14,12 +10,17 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TargetCard extends TargetObject {
// all targets will be filtered by one zone, don't use "multi-zone" filter (if you want then override all canTarget and possible methods)
protected final FilterCard filter;
protected TargetCard(Zone zone) {
@ -53,7 +54,7 @@ public class TargetCard extends TargetObject {
/**
* Checks if there are enough {@link Card} that can be chosen.
*
* @param sourceId - the target event source
* @param sourceId - the target event source
* @param sourceControllerId - controller of the target event source
* @param game
* @return - true if enough valid {@link Card} exist
@ -179,7 +180,7 @@ public class TargetCard extends TargetObject {
}
public Set<UUID> possibleTargets(UUID sourceControllerId, Cards cards, Game game) {
return cards.getCards(filter,game).stream().map(MageItem::getId).collect(Collectors.toSet());
return cards.getCards(filter, game).stream().map(MageItem::getId).collect(Collectors.toSet());
}
@Override
@ -187,9 +188,28 @@ public class TargetCard extends TargetObject {
return possibleTargets(null, sourceControllerId, game);
}
// TODO: check all class targets, if it override canTarget then make sure it override ALL 3 METHODS with canTarget and possibleTargets (method with cards doesn't need)
@Override
public boolean canTarget(UUID id, Game game) {
return super.canTarget(id, game);
}
@Override
public boolean canTarget(UUID id, Ability source, Game game) {
return canTarget(id, game);
}
@Override
public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
Card card = game.getCard(id);
return card != null
&& zone != null && zone.match(game.getState().getZone(id))
&& getFilter() != null && getFilter().match(card, playerId, game);
}
public boolean canTarget(UUID id, Cards cards, Game game) {
Card card = cards.get(id, game);
return card != null && filter.match(card, game);
return cards.contains(id) && canTarget(id, game);
}
@Override