* Changed handling of search library limiting effect.

This commit is contained in:
LevelX2 2014-02-09 11:20:20 +01:00
parent e1ac1a7c8d
commit 9fcfb8527a
4 changed files with 40 additions and 33 deletions

View file

@ -28,11 +28,6 @@
package mage.sets.futuresight;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -40,8 +35,14 @@ import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.keyword.FlashAbility;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
/**
*
@ -90,14 +91,17 @@ class AvenMindcensorEffect extends ReplacementEffectImpl<AvenMindcensorEffect> {
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
game.getState().setValue("LibrarySearchLimit", new Integer(4));
event.setAmount(4);
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.SEARCH_LIBRARY && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
if (event.getType() == GameEvent.EventType.SEARCH_LIBRARY) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && game.isOpponent(controller, event.getPlayerId())) {
return true;
}
}
return false;
}

View file

@ -30,10 +30,6 @@ package mage.sets.magic2010;
import java.util.Collection;
import java.util.TreeSet;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
@ -43,7 +39,12 @@ import mage.cards.Card;
import mage.cards.CardImpl;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
@ -97,8 +98,8 @@ class SphinxAmbassadorEffect extends OneShotEffect<SphinxAmbassadorEffect> {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null && targetPlayer != null) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (player != null && targetPlayer != null && sourcePermanent != null) {
TargetCardInLibrary target = new TargetCardInLibrary();
player.searchLibrary(target, game, targetPlayer.getId());
@ -122,9 +123,11 @@ class SphinxAmbassadorEffect extends OneShotEffect<SphinxAmbassadorEffect> {
}
String cardName = cardChoice.getChoice();
game.informPlayers("Sphinx Ambassador, named card: [" + cardName + "]");
game.informPlayers(new StringBuilder(sourcePermanent.getName()).append(", named card: [").append(cardName).append("]").toString());
if (!card.getName().equals(cardName) && card.getCardType().contains(CardType.CREATURE)) {
card.putOntoBattlefield(game, Zone.LIBRARY, source.getId(), player.getId());
if (player.chooseUse(outcome, new StringBuilder("Put ").append(card.getName()).append(" onto the battlefield?").toString(), game)) {
player.putOntoBattlefieldWithInfo(card, game, Zone.LIBRARY, source.getSourceId());
}
}
}

View file

@ -173,7 +173,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
protected List<UUID> attachments = new ArrayList<UUID>();
protected boolean topCardRevealed = false;
// 800.4i When a player leaves the game, any continuous effects with durations that last until that player's next turn
// or until a specific point in that turn will last until that turn would have begun.
// They neither expire immediately nor last indefinitely.
@ -342,7 +342,6 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
this.setLife(game.getLife(), game);
this.setReachedNextTurnAfterLeaving(false);
game.getState().getWatchers().add(new BloodthirstWatcher(playerId));
}
@Override
@ -1607,16 +1606,16 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
if (searchedLibrary == null) {
return false;
}
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.SEARCH_LIBRARY, targetPlayerId, playerId))) {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.SEARCH_LIBRARY, targetPlayerId, playerId, playerId, Integer.MAX_VALUE);
if (!game.replaceEvent(event)) {
TargetCardInLibrary newTarget = target.copy();
int count;
Integer cardLimit = (Integer) game.getState().getValue("LibrarySearchLimit");
if (cardLimit != null) {
newTarget.setCardLimit(cardLimit);
game.getState().setValue("LibrarySearchLimit", null);
count = Math.min(searchedLibrary.count(target.getFilter(), game),cardLimit.intValue());
} else {
int librarySearchLimit = event.getAmount();
if (librarySearchLimit == Integer.MAX_VALUE) {
count = searchedLibrary.count(target.getFilter(), game);
} else {
newTarget.setCardLimit(librarySearchLimit);
count = Math.min(searchedLibrary.count(target.getFilter(), game), librarySearchLimit);
}
if (count < target.getNumberOfTargets()) {

View file

@ -31,17 +31,17 @@ package mage.target.common;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import mage.constants.Outcome;
import mage.constants.Zone;
import java.util.UUID;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetCard;
import java.util.UUID;
/**
*
@ -49,7 +49,7 @@ import java.util.UUID;
*/
public class TargetCardInLibrary extends TargetCard<TargetCardInLibrary> {
private Integer cardLimit;
private int librarySearchLimit;
public TargetCardInLibrary() {
this(1, 1, new FilterCard());
@ -65,11 +65,12 @@ public class TargetCardInLibrary extends TargetCard<TargetCardInLibrary> {
public TargetCardInLibrary(int minNumTargets, int maxNumTargets, FilterCard filter) {
super(minNumTargets, maxNumTargets, Zone.LIBRARY, filter);
this.librarySearchLimit = Integer.MAX_VALUE;
}
public TargetCardInLibrary(final TargetCardInLibrary target) {
super(target);
this.cardLimit = target.cardLimit;
this.librarySearchLimit = target.librarySearchLimit;
}
@Override
@ -81,10 +82,10 @@ public class TargetCardInLibrary extends TargetCard<TargetCardInLibrary> {
}
List<Card> cards;
if (cardLimit == null) {
if (librarySearchLimit == Integer.MAX_VALUE) {
cards = targetPlayer.getLibrary().getCards(game);
} else {
int maxCards = Math.min(cardLimit.intValue(), targetPlayer.getLibrary().size());
int maxCards = Math.min(librarySearchLimit, targetPlayer.getLibrary().size());
cards = targetPlayer.getLibrary().getTopCards(game, maxCards);
}
Collections.sort(cards, new CardNameComparator());
@ -118,8 +119,8 @@ public class TargetCardInLibrary extends TargetCard<TargetCardInLibrary> {
this.minNumberOfTargets = minNumberOfTargets;
}
public void setCardLimit(Integer cardLimit) {
this.cardLimit = new Integer(cardLimit.intValue());
public void setCardLimit(int librarySearchLimit) {
this.librarySearchLimit = librarySearchLimit;
}