mirror of
https://github.com/correl/mage.git
synced 2025-03-16 01:06:34 -09:00
fixed TargetCardInOpponentsGraveyard not working properly
fixed ignoring allFromOneOpponent in canChoose fixed including own graveyard in canChoose fixed including own graveyard for possibleTargets fixed not overriding one canTarget at all which allowed targeting cards in different graveyards should also fix #6472
This commit is contained in:
parent
a91b210456
commit
9597e95b8d
1 changed files with 54 additions and 0 deletions
|
@ -1,8 +1,11 @@
|
||||||
package mage.target.common;
|
package mage.target.common;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
import mage.cards.Cards;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.filter.FilterCard;
|
import mage.filter.FilterCard;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
@ -33,6 +36,23 @@ public class TargetCardInOpponentsGraveyard extends TargetCard {
|
||||||
this.allFromOneOpponent = target.allFromOneOpponent;
|
this.allFromOneOpponent = target.allFromOneOpponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
|
||||||
|
Card card = game.getCard(id);
|
||||||
|
if (card != null && zone.match(game.getState().getZone(id))) {
|
||||||
|
if (game.getPlayer(source.getControllerId()).hasOpponent(card.getOwnerId(), game)) {
|
||||||
|
if (allFromOneOpponent && !targets.isEmpty()) {
|
||||||
|
Card firstCard = game.getCard(targets.keySet().iterator().next());
|
||||||
|
if (firstCard != null && !card.isOwnedBy(firstCard.getOwnerId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filter.match(card, source.getId(), playerId, game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canTarget(UUID id, Ability source, Game game) {
|
public boolean canTarget(UUID id, Ability source, Game game) {
|
||||||
Card card = game.getCard(id);
|
Card card = game.getCard(id);
|
||||||
|
@ -69,7 +89,14 @@ public class TargetCardInOpponentsGraveyard extends TargetCard {
|
||||||
if (getNumberOfTargets() == 0) { // if 0 target is valid, the canChoose is always true
|
if (getNumberOfTargets() == 0) { // if 0 target is valid, the canChoose is always true
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Player sourceController = game.getPlayer(sourceControllerId);
|
||||||
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
|
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||||
|
if (!sourceController.hasOpponent(playerId, game)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (this.allFromOneOpponent) {
|
||||||
|
possibleTargets = 0;
|
||||||
|
}
|
||||||
if (!playerId.equals(sourceControllerId)) {
|
if (!playerId.equals(sourceControllerId)) {
|
||||||
Player player = game.getPlayer(playerId);
|
Player player = game.getPlayer(playerId);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
|
@ -86,6 +113,33 @@ public class TargetCardInOpponentsGraveyard extends TargetCard {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||||
|
Set<UUID> possibleTargets = new HashSet<>();
|
||||||
|
Player sourceController = game.getPlayer(sourceControllerId);
|
||||||
|
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||||
|
if (!sourceController.hasOpponent(playerId, game)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Player player = game.getPlayer(playerId);
|
||||||
|
if (player != null) {
|
||||||
|
Set<UUID> targetsInThisGraveyeard = new HashSet<>();
|
||||||
|
for (Card card : player.getGraveyard().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||||
|
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||||
|
targetsInThisGraveyeard.add(card.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if there is not enough possible targets, the can't be any
|
||||||
|
if (this.allFromOneOpponent && targetsInThisGraveyeard.size() < this.minNumberOfTargets) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
possibleTargets.addAll(targetsInThisGraveyeard);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return possibleTargets;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TargetCardInOpponentsGraveyard copy() {
|
public TargetCardInOpponentsGraveyard copy() {
|
||||||
return new TargetCardInOpponentsGraveyard(this);
|
return new TargetCardInOpponentsGraveyard(this);
|
||||||
|
|
Loading…
Add table
Reference in a new issue