Skip to content

Commit

Permalink
removed method for preventing library search triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
theelk801 committed Nov 13, 2020
1 parent c693b0d commit 01a0d23
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/j/JaceArchitectOfThought.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public boolean apply(Game game, Ability source) {
playerName = "your";
}
TargetCardInLibrary target = new TargetCardInLibrary(new FilterNonlandCard("nonland card from " + playerName + " library"));
if (controller.searchLibrary(target, source, game, playerId, !checkList.contains(playerId))) {
if (controller.searchLibrary(target, source, game, playerId)) {
checkList.add(playerId);
UUID targetId = target.getFirstTarget();
Card card = player.getLibrary().remove(targetId, game);
Expand Down
13 changes: 2 additions & 11 deletions Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3273,21 +3273,12 @@ public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game ga
return computerPlayer.searchLibrary(target, source, game);
}

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, boolean triggerEvents) {
return computerPlayer.searchLibrary(target, source, game, triggerEvents);
}

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, UUID targetPlayerId) {
return computerPlayer.searchLibrary(target, source, game, targetPlayerId);
}

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, UUID targetPlayerId, boolean triggerEvents) {
return computerPlayer.searchLibrary(target, source, game, targetPlayerId, triggerEvents);
}

@Override
public void lookAtAllLibraries(Ability source, Game game) {
computerPlayer.lookAtAllLibraries(source, game);
Expand Down Expand Up @@ -3402,12 +3393,12 @@ public void setAllowBadMoves(boolean allowBadMoves) {
public boolean canPayLifeCost(Ability ability) {
return computerPlayer.canPayLifeCost(ability);
}

@Override
public boolean getCanPayLifeCost() {
return computerPlayer.getCanPayLifeCost();
}

@Override
public void setCanPayLifeCost(boolean canPayLifeCost) {
computerPlayer.setCanPayLifeCost(canPayLifeCost);
Expand Down
28 changes: 9 additions & 19 deletions Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.mage.test.stub;

import mage.ApprovingObject;
import mage.MageObject;
import mage.Mana;
import mage.abilities.*;
import mage.abilities.costs.AlternativeSourceCosts;
import mage.abilities.costs.Cost;
Expand Down Expand Up @@ -40,8 +42,6 @@

import java.io.Serializable;
import java.util.*;
import mage.ApprovingObject;
import mage.Mana;

/**
* @author Quercitron
Expand Down Expand Up @@ -179,12 +179,12 @@ public boolean isCanGainLife() {
public void setCanPayLifeCost(boolean canPayLifeCost) {

}

@Override
public boolean getCanPayLifeCost() {
return false;
}

@Override
public boolean canPayLifeCost(Ability ability) {
return false;
Expand Down Expand Up @@ -579,21 +579,11 @@ public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game ga
return false;
}

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, boolean triggerEvents) {
return false;
}

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, UUID targetPlayerId) {
return false;
}

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, UUID targetPlayerId, boolean triggerEvents) {
return false;
}

@Override
public void lookAtAllLibraries(Ability source, Game game) {
}
Expand Down Expand Up @@ -1045,19 +1035,19 @@ public ManaOptions getManaAvailable(Game game) {

@Override
public void addAvailableTriggeredMana(List<Mana> availableTriggeredMan) {
}

}

@Override
public List<List<Mana>> getAvailableTriggeredMana() {
return null;
}

@Override
public int announceXMana(int min, int max, String message, Game game, Ability ability) {
return 0;
}

@Override
public List<ActivatedAbility> getPlayable(Game game, boolean hidden) {
return null;
Expand Down
21 changes: 9 additions & 12 deletions Mage/src/main/java/mage/players/Player.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mage.players;

import java.io.Serializable;
import java.util.*;
import mage.ApprovingObject;
import mage.MageItem;
import mage.MageObject;
Expand Down Expand Up @@ -41,6 +39,9 @@
import mage.target.common.TargetCardInLibrary;
import mage.util.Copyable;

import java.io.Serializable;
import java.util.*;

/**
* @author BetaSteward_at_googlemail.com
*/
Expand Down Expand Up @@ -103,12 +104,12 @@ public interface Player extends MageItem, Copyable<Player> {

/**
* Is the player allowed to pay life for casting spells or activate activated abilities
*
* @param canPayLifeCost
*
* @param canPayLifeCost
*/

void setCanPayLifeCost(boolean canPayLifeCost);

boolean getCanPayLifeCost();

/**
Expand Down Expand Up @@ -345,19 +346,15 @@ public interface Player extends MageItem, Copyable<Player> {

boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game);

boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, boolean triggerEvents);

boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, UUID targetPlayerId);

/**
* @param target
* @param source
* @param game
* @param targetPlayerId player whose library will be searched
* @param triggerEvents whether searching will trigger any game events
* @return true if search was successful
*/
boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, UUID targetPlayerId, boolean triggerEvents);

boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, UUID targetPlayerId);

/**
* Reveals all players' libraries. Useful for abilities like Jace, Architect
Expand Down
100 changes: 44 additions & 56 deletions Mage/src/main/java/mage/players/PlayerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2603,21 +2603,11 @@ public void declareBlocker(UUID defenderId, UUID blockerId, UUID attackerId, Gam

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game) {
return searchLibrary(target, source, game, playerId, true);
}

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, boolean triggerEvents) {
return searchLibrary(target, source, game, playerId, triggerEvents);
return searchLibrary(target, source, game, playerId);
}

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, UUID targetPlayerId) {
return searchLibrary(target, source, game, targetPlayerId, true);
}

@Override
public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game game, UUID targetPlayerId, boolean triggerEvents) {
//20091005 - 701.14c
Library searchedLibrary = null;
String searchInfo = null;
Expand All @@ -2636,59 +2626,57 @@ public boolean searchLibrary(TargetCardInLibrary target, Ability source, Game ga
}
GameEvent event = GameEvent.getEvent(GameEvent.EventType.SEARCH_LIBRARY,
targetPlayerId, source.getSourceId(), playerId, Integer.MAX_VALUE);
if (!game.replaceEvent(event)) {
if (!game.isSimulation()) {
game.informPlayers(searchInfo);
}
TargetCardInLibrary newTarget = target.copy();
int count;
int librarySearchLimit = event.getAmount();
List<Card> cardsFromTop = null;
do {
// TODO: prevent shuffling from moving the visualized cards
if (librarySearchLimit == Integer.MAX_VALUE) {
count = searchedLibrary.count(target.getFilter(), game);
} else {
Player targetPlayer = game.getPlayer(targetPlayerId);
if (targetPlayer == null) {
return false;
}
if (cardsFromTop == null) {
cardsFromTop = new ArrayList<>(targetPlayer.getLibrary().getTopCards(game, librarySearchLimit));
} else {
cardsFromTop.retainAll(targetPlayer.getLibrary().getCards(game));
}
newTarget.setCardLimit(Math.min(librarySearchLimit, cardsFromTop.size()));
count = Math.min(searchedLibrary.count(target.getFilter(), game), librarySearchLimit);
if (game.replaceEvent(event)) {
return false;
}
if (!game.isSimulation()) {
game.informPlayers(searchInfo);
}
TargetCardInLibrary newTarget = target.copy();
int count;
int librarySearchLimit = event.getAmount();
List<Card> cardsFromTop = null;
do {
// TODO: prevent shuffling from moving the visualized cards
if (librarySearchLimit == Integer.MAX_VALUE) {
count = searchedLibrary.count(target.getFilter(), game);
} else {
Player targetPlayer = game.getPlayer(targetPlayerId);
if (targetPlayer == null) {
return false;
}

if (count < target.getNumberOfTargets()) {
newTarget.setMinNumberOfTargets(count);
if (cardsFromTop == null) {
cardsFromTop = new ArrayList<>(targetPlayer.getLibrary().getTopCards(game, librarySearchLimit));
} else {
cardsFromTop.retainAll(targetPlayer.getLibrary().getCards(game));
}
if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) {
if (targetPlayerId.equals(playerId) && handleLibraryCastableCards(library,
game, targetPlayerId)) { // for handling Panglacial Wurm
newTarget.clearChosen();
continue;
}
target.getTargets().clear();
for (UUID targetId : newTarget.getTargets()) {
target.add(targetId, game);
}
newTarget.setCardLimit(Math.min(librarySearchLimit, cardsFromTop.size()));
count = Math.min(searchedLibrary.count(target.getFilter(), game), librarySearchLimit);
}

} else if (targetPlayerId.equals(playerId) && handleLibraryCastableCards(library,
if (count < target.getNumberOfTargets()) {
newTarget.setMinNumberOfTargets(count);
}
if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) {
if (targetPlayerId.equals(playerId) && handleLibraryCastableCards(library,
game, targetPlayerId)) { // for handling Panglacial Wurm
newTarget.clearChosen();
continue;
}
if (triggerEvents) {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId));
target.getTargets().clear();
for (UUID targetId : newTarget.getTargets()) {
target.add(targetId, game);
}
break;
} while (true);
return true;
}
return false;

} else if (targetPlayerId.equals(playerId) && handleLibraryCastableCards(library,
game, targetPlayerId)) { // for handling Panglacial Wurm
newTarget.clearChosen();
continue;
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId));
break;
} while (true);
return true;
}

@Override
Expand Down

0 comments on commit 01a0d23

Please sign in to comment.