mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
* Fixed a bug of TargetCardInHand class, that could lead to game locked down situations (e.g. Force of Will).
This commit is contained in:
parent
ba60a38472
commit
8a12fa9b01
2 changed files with 41 additions and 7 deletions
|
@ -30,20 +30,19 @@ package mage.abilities.effects.common.search;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCardInGraveyard;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
import mage.target.TargetCard;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
|
||||
/**
|
||||
|
@ -90,7 +89,7 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect
|
|||
int cardsCount = (cardName.isEmpty() ? 0 :targetPlayer.getGraveyard().count(filter, game));
|
||||
if (cardsCount > 0) {
|
||||
filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
|
||||
TargetCardInGraveyard target = new TargetCardInGraveyard((graveyardExileOptional ? 0 :cardsCount), cardsCount, filter);
|
||||
TargetCard target = new TargetCard((graveyardExileOptional ? 0 :cardsCount), cardsCount,Zone.GRAVEYARD, filter);
|
||||
if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
|
||||
List<UUID> targets = target.getTargets();
|
||||
for (UUID targetId : targets) {
|
||||
|
@ -107,7 +106,7 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect
|
|||
cardsCount = (cardName.isEmpty() ? 0 :targetPlayer.getHand().count(filter, game));
|
||||
if (cardsCount > 0) {
|
||||
filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
|
||||
TargetCardInHand target = new TargetCardInHand(0, cardsCount, filter);
|
||||
TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
|
||||
if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
|
||||
List<UUID> targets = target.getTargets();
|
||||
for (UUID targetId : targets) {
|
||||
|
|
|
@ -28,12 +28,16 @@
|
|||
|
||||
package mage.target.common;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.constants.Zone;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetCard;
|
||||
|
||||
/**
|
||||
|
@ -72,6 +76,37 @@ public class TargetCardInHand extends TargetCard {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceId, UUID playerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
for (Card card : player.getHand().getCards(filter, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, playerId))) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return possibleTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
int possibleTargets = 0;
|
||||
Player player = game.getPlayer(sourceControllerId);
|
||||
if (player != null) {
|
||||
for (Card card : player.getHand().getCards(filter, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
possibleTargets++;
|
||||
if (possibleTargets >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetCardInHand copy() {
|
||||
return new TargetCardInHand(this);
|
||||
|
|
Loading…
Reference in a new issue