mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
Fixed that TargetCard ignore filter in some calls
This commit is contained in:
parent
690f5f688d
commit
0885a01849
7 changed files with 93 additions and 58 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public abstract class TargetImpl implements Target {
|
|||
protected final Map<UUID, Integer> zoneChangeCounters = new HashMap<>();
|
||||
|
||||
protected String targetName;
|
||||
protected Zone zone;
|
||||
protected Zone zone; // all targets will be filtered by that zone, don't use "multi-zone" filter
|
||||
protected int maxNumberOfTargets;
|
||||
protected int minNumberOfTargets;
|
||||
protected boolean required = true;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
|
||||
package mage.target.common;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.FilterPermanent;
|
||||
|
|
@ -19,58 +17,76 @@ import java.util.UUID;
|
|||
*/
|
||||
public class TargetCardInGraveyardOrBattlefield extends TargetCard {
|
||||
|
||||
public TargetCardInGraveyardOrBattlefield() {
|
||||
this(1, 1, new FilterCard("target card in a graveyard or permanent on the battlefield"));
|
||||
}
|
||||
protected final FilterPermanent filterBattlefield;
|
||||
|
||||
public TargetCardInGraveyardOrBattlefield(FilterCard filter) {
|
||||
this(1, 1, filter);
|
||||
}
|
||||
|
||||
public TargetCardInGraveyardOrBattlefield(int numTargets, FilterCard filter) {
|
||||
this(numTargets, numTargets, filter);
|
||||
}
|
||||
|
||||
public TargetCardInGraveyardOrBattlefield(int minNumTargets, int maxNumTargets, FilterCard filter) {
|
||||
super(minNumTargets, maxNumTargets, Zone.GRAVEYARD, filter); // Zone for card
|
||||
this.targetName = filter.getMessage();
|
||||
public TargetCardInGraveyardOrBattlefield(int minNumTargets, int maxNumTargets, FilterCard filterGraveyard, FilterPermanent filterBattlefield) {
|
||||
super(minNumTargets, maxNumTargets, Zone.GRAVEYARD, filterGraveyard); // zone for card in graveyard, don't change
|
||||
this.filterBattlefield = filterBattlefield;
|
||||
this.targetName = filter.getMessage()
|
||||
+ " in a graveyard "
|
||||
+ (maxNumTargets > 1 ? " and/or " : " or ")
|
||||
+ this.filterBattlefield.getMessage()
|
||||
+ " on the battlefield";
|
||||
}
|
||||
|
||||
public TargetCardInGraveyardOrBattlefield(final TargetCardInGraveyardOrBattlefield target) {
|
||||
super(target);
|
||||
this.filterBattlefield = target.filterBattlefield;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
if (!super.canChoose(sourceId, sourceControllerId, game)) {
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(), sourceControllerId, game)) {
|
||||
if ((notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) && filter.match(permanent, sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterBattlefield, sourceControllerId, game)) {
|
||||
if ((notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game))
|
||||
&& filterBattlefield.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTarget(UUID id, Ability source, Game game) {
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
return filter.match(permanent, game);
|
||||
if (!super.canTarget(id, source, game)) { // in graveyard first
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
return filterBattlefield.match(permanent, game);
|
||||
}
|
||||
}
|
||||
Card card = game.getCard(id);
|
||||
return card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD && filter.match(card, game);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
|
||||
if (!super.canTarget(playerId, id, source, game)) { // in graveyard first
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
return filterBattlefield.match(permanent, source != null ? source.getSourceId() : null, playerId, game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTarget(UUID id, Game game) {
|
||||
if (!super.canTarget(id, game)) { // in graveyard first
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
return filterBattlefield.match(permanent, game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
|
||||
//return super.possibleTargets(sourceControllerId, game); //To change body of generated methods, choose Tools | Templates.
|
||||
Set<UUID> possibleTargets = super.possibleTargets(sourceControllerId, game);
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(), sourceControllerId, game)) {
|
||||
if (filter.match(permanent, sourceControllerId, game)) {
|
||||
Set<UUID> possibleTargets = super.possibleTargets(sourceControllerId, game); // in graveyard first
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterBattlefield, sourceControllerId, game)) {
|
||||
if (filterBattlefield.match(permanent, null, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -79,15 +95,14 @@ public class TargetCardInGraveyardOrBattlefield extends TargetCard {
|
|||
|
||||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
|
||||
Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game); // in graveyard first
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(), sourceControllerId, game)) {
|
||||
if ((notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterBattlefield, sourceControllerId, sourceId, game)) {
|
||||
if ((notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) && filterBattlefield.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
return possibleTargets;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue