* Fixed some library search effects that didn't sort the library and didn't take search limitations into account (Aven Mindcensor)

This commit is contained in:
LevelX2 2014-02-09 00:21:43 +01:00
parent dc6a4b07cd
commit 3b03a0500a
16 changed files with 104 additions and 89 deletions

View file

@ -30,6 +30,8 @@ package mage.cards;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
@ -133,8 +135,9 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
public int count(FilterCard filter, UUID playerId, Game game) {
int result = 0;
for (UUID card: this) {
if (filter.match(game.getCard(card), playerId, game))
if (filter.match(game.getCard(card), playerId, game)) {
result++;
}
}
return result;
}
@ -158,8 +161,9 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
Set<Card> cards = new LinkedHashSet<Card>();
for (UUID card: this) {
boolean match = filter.match(game.getCard(card), game);
if (match)
if (match) {
cards.add(game.getCard(card));
}
}
return cards;
}

View file

@ -28,14 +28,24 @@
package mage.players;
import mage.constants.Zone;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import mage.cards.Card;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game;
import java.io.Serializable;
import java.util.*;
/**
*
* @author BetaSteward_at_googlemail.com
@ -45,8 +55,8 @@ public class Library implements Serializable {
private static Random rnd = new Random();
private boolean emptyDraw;
private Deque<UUID> library = new ArrayDeque<UUID>();
private UUID playerId;
private final Deque<UUID> library = new ArrayDeque<UUID>();
private final UUID playerId;
public Library(UUID playerId) {
this.playerId = playerId;
@ -202,8 +212,9 @@ public class Library implements Serializable {
public int count(FilterCard filter, Game game) {
int result = 0;
for (UUID card: library) {
if (filter.match(game.getCard(card), game))
if (filter.match(game.getCard(card), game)) {
result++;
}
}
return result;
}
@ -222,8 +233,9 @@ public class Library implements Serializable {
public Card getCard(UUID cardId, Game game) {
for (UUID card: library) {
if (card.equals(cardId))
if (card.equals(cardId)) {
return game.getCard(card);
}
}
return null;
}

View file

@ -122,6 +122,7 @@ public interface Player extends MageItem, Copyable<Player> {
boolean isInGame();
/**
* Called if other player left the game
* @param game
*/
void otherPlayerLeftGame(Game game);

View file

@ -1595,6 +1595,18 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
@Override
public boolean searchLibrary(TargetCardInLibrary target, Game game, UUID targetPlayerId) {
//20091005 - 701.14c
Library searchedLibrary = null;
if (targetPlayerId.equals(playerId)) {
searchedLibrary = library;
} else {
Player targetPlayer = game.getPlayer(targetPlayerId);
if (targetPlayer != null) {
searchedLibrary = targetPlayer.getLibrary();
}
}
if (searchedLibrary == null) {
return false;
}
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.SEARCH_LIBRARY, targetPlayerId, playerId))) {
TargetCardInLibrary newTarget = target.copy();
int count;
@ -1602,9 +1614,9 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
if (cardLimit != null) {
newTarget.setCardLimit(cardLimit);
game.getState().setValue("LibrarySearchLimit", null);
count = Math.min(library.count(target.getFilter(), game),cardLimit.intValue());
count = Math.min(searchedLibrary.count(target.getFilter(), game),cardLimit.intValue());
} else {
count = library.count(target.getFilter(), game);
count = searchedLibrary.count(target.getFilter(), game);
}
if (count < target.getNumberOfTargets()) {

View file

@ -31,8 +31,6 @@ package mage.target.common;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.abilities.Ability;
@ -115,6 +113,7 @@ public class TargetCardInLibrary extends TargetCard<TargetCardInLibrary> {
return new TargetCardInLibrary(this);
}
@Override
public void setMinNumberOfTargets(int minNumberOfTargets) {
this.minNumberOfTargets = minNumberOfTargets;
}