-
Notifications
You must be signed in to change notification settings - Fork 917
Player Hidden Keywords related to SearchLibrary #10219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kojotak
wants to merge
17
commits into
Card-Forge:master
Choose a base branch
from
kojotak:issue/4760/searchLibrary
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
98f3002
StaticAbilityCantSearchLibrary
kojotak 6200bd6
refactoring renamed StaticAbilityCantSearchLibrary
kojotak d318e09
Leonin Arbiter: added Continuos mode for IgnoreEffectCost$
kojotak 4de14fc
StaticAbilitySearchLibrary#cantSearchLibrary considers getIgnoreEffec…
kojotak f7b33c7
refactoring removed CantCauseToSearchLibrary
kojotak 021f048
Merge branch 'master' into issue/4760/searchLibrary
kojotak 1778105
Ashiok, Dream Render: replaced targetPlayer.eq(activatingPlayer) chec…
kojotak d13facf
Revert "Ashiok, Dream Render: replaced targetPlayer.eq(activatingPlay…
kojotak bdddb69
Ashiok, Dream Render: added ValidCause
kojotak b1f8f9b
added StaticAbilitySearchLibraryTest
kojotak 6c853de
added failing testAshiok_opponentCanCauseOtherOpponentToSearchTheirLi…
kojotak d2abfc7
Claude AI fix to the testAshiok_opponentCanCauseOtherOpponentToSearch…
kojotak f4079a2
Claude AI fix to the testAshiok_opponentCanCauseOtherOpponentToSearch…
kojotak 27b0eac
removed TODO
kojotak 331b9e6
Merge branch 'master' into issue/4760/searchLibrary
kojotak b45ebb1
no need for ValidCause$ when ValidPlayerCauseRelative$ is used
kojotak da9d34a
Merge branch 'master' into issue/4760/searchLibrary
kojotak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
forge-game/src/main/java/forge/game/staticability/StaticAbilitySearchLibrary.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package forge.game.staticability; | ||
|
|
||
| import forge.game.player.Player; | ||
| import forge.game.spellability.SpellAbility; | ||
| import forge.game.zone.ZoneType; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import static forge.game.staticability.StaticAbilityMode.CantSearchLibrary; | ||
| import static forge.game.staticability.StaticAbilityMode.LimitSearchLibrary; | ||
|
|
||
|
|
||
| public class StaticAbilitySearchLibrary { | ||
|
|
||
| /** | ||
| * @return maximum number of cards which can be fetched from a library considering its size and search limit or null if there is no limit | ||
| */ | ||
| public static Integer limitSearchLibraryConsideringSize(Player player) { | ||
|
kojotak marked this conversation as resolved.
|
||
| Integer limit = limitSearchLibrary(player); | ||
| if (limit != null) { | ||
| return Math.min(player.getCardsIn(ZoneType.Library).size(), limit); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @return maximum number of cards which can be revealed from a library or null if there is no limit | ||
| */ | ||
| public static Integer limitSearchLibrary(Player player) { | ||
| return findStaticAbilityForValidPlayer(player, LimitSearchLibrary) | ||
| .map(stAb -> Integer.valueOf(stAb.getParam("LimitNum"))) | ||
| .orElse(null); | ||
| } | ||
|
|
||
| public static boolean cantSearchLibrary(Player player, SpellAbility sa) { | ||
| return findStaticAbilityForValidPlayer(player, CantSearchLibrary) | ||
| .filter(stAb -> !stAb.getIgnoreEffectPlayers().contains(player)) | ||
| .filter(stAb -> stAb.matchesValidParam("ValidPlayerCauseRelative", player, sa.getHostCard())) | ||
| .isPresent(); | ||
| } | ||
|
|
||
| private static Optional<StaticAbility> findStaticAbilityForValidPlayer(final Player player, final StaticAbilityMode mode) { | ||
| return player.getGame() | ||
| .getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES) | ||
| .stream() | ||
| .flatMap(card -> card.getStaticAbilities().stream()) | ||
| .filter(stAb -> stAb.checkConditions(mode) && stAb.matchesValidParam("ValidPlayer", player)) | ||
| .findAny(); | ||
| } | ||
| } | ||
168 changes: 168 additions & 0 deletions
168
forge-gui-desktop/src/test/java/forge/ai/ability/StaticAbilitySearchLibraryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| package forge.ai.ability; | ||
|
|
||
| import static org.testng.Assert.assertFalse; | ||
| import static org.testng.Assert.assertTrue; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import forge.game.*; | ||
| import forge.game.card.CounterEnumType; | ||
| import forge.game.spellability.AbilitySub; | ||
| import forge.game.zone.ZoneType; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import com.google.common.collect.Lists; | ||
|
|
||
| import forge.ai.AITest; | ||
| import forge.ai.LobbyPlayerAi; | ||
| import forge.deck.Deck; | ||
| import forge.game.card.Card; | ||
| import forge.game.phase.PhaseType; | ||
| import forge.game.player.Player; | ||
| import forge.game.player.RegisteredPlayer; | ||
| import forge.game.spellability.SpellAbility; | ||
|
|
||
| public class StaticAbilitySearchLibraryTest extends AITest { | ||
|
|
||
| //Overrides 2 player game with 3 player game | ||
| @Override | ||
| public Game resetGame() { | ||
| List<RegisteredPlayer> players = Lists.newArrayList(); | ||
| Deck d1 = new Deck(); | ||
| players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p1", null))); | ||
| players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p2", null))); | ||
| players.add(new RegisteredPlayer(d1).setPlayer(new LobbyPlayerAi("p3", null))); | ||
| GameRules rules = new GameRules(GameType.Constructed); | ||
| Match match = new Match(rules, players, "Test 3 player game"); | ||
| Game game = new Game(players, rules, match); | ||
| game.setAge(GameStage.Play); | ||
| game.getPhaseHandler().devModeSet(PhaseType.MAIN1, game.getPlayers().get(0)); | ||
| game.getPhaseHandler().onStackResolved(); | ||
| return game; | ||
| } | ||
|
|
||
| @Test | ||
| public void testMindlockOrb_canSearchWhenNotInPlay() { | ||
| Game game = initAndCreateGame(); | ||
| Player p1 = game.getPlayers().get(1); | ||
|
|
||
| Card aridMesa = addCard("Arid Mesa", p1); | ||
|
|
||
| game.getAction().checkStateEffects(true); | ||
|
|
||
| assertTrue(p1.canSearchLibraryWith(findSearchLibraryAbility(aridMesa), p1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMindlockOrb_canNotSearchIfPlayerOwnsIt() { | ||
| Game game = initAndCreateGame(); | ||
| Player p1 = game.getPlayers().get(1); | ||
|
|
||
| addCard("Mindlock Orb", p1); | ||
| Card aridMesa = addCard("Arid Mesa", p1); | ||
|
|
||
| game.getAction().checkStateEffects(true); | ||
|
|
||
| assertFalse(p1.canSearchLibraryWith(findSearchLibraryAbility(aridMesa), p1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMindlockOrb_canNotSearchIfOpponentOwnsIt() { | ||
| Game game = initAndCreateGame(); | ||
|
|
||
| Player p1 = game.getPlayers().get(1); | ||
| Card aridMesa = addCard("Arid Mesa", p1); | ||
|
|
||
| Player p2 = game.getPlayers().get(0); | ||
| addCard("Mindlock Orb", p2); | ||
|
|
||
| game.getAction().checkStateEffects(true); | ||
|
|
||
| assertFalse(p1.canSearchLibraryWith(findSearchLibraryAbility(aridMesa), p1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAshiok_ownerCanSearchOwnLibrary() { | ||
| Game game = initAndCreateGame(); | ||
| Player p1 = game.getPlayers().get(0); | ||
|
|
||
| addCard("Ashiok, Dream Render", p1); | ||
| Card aridMesa = addCard("Arid Mesa", p1); | ||
|
|
||
| game.getAction().checkStateEffects(true); | ||
|
|
||
| assertTrue(p1.canSearchLibraryWith(findSearchLibraryAbility(aridMesa), p1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAshiok_opponentCannotSearchOwnLibrary() { | ||
| Game game = initAndCreateGame(); | ||
| Player p1 = game.getPlayers().get(0); | ||
| Player p2 = game.getPlayers().get(1); | ||
|
|
||
| Card ashiok = addCard("Ashiok, Dream Render", p2); | ||
| ashiok.setCounters(CounterEnumType.LOYALTY, 5); | ||
| Card aridMesa = addCard("Arid Mesa", p1); | ||
|
|
||
| game.getAction().checkStateEffects(true); | ||
|
|
||
| assertFalse(p1.canSearchLibraryWith(findSearchLibraryAbility(aridMesa), p1)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAshiok_opponentCanCauseOtherOpponentToSearchTheirLibrary() { | ||
|
kojotak marked this conversation as resolved.
|
||
| Game game = initAndCreateGame(); | ||
| Player p1 = game.getPlayers().get(0); | ||
| Player p2 = game.getPlayers().get(1); | ||
| Player p3 = game.getPlayers().get(2); | ||
|
|
||
| Card ashiok = addCard("Ashiok, Dream Render", p1); | ||
| ashiok.setCounters(CounterEnumType.LOYALTY, 5); | ||
|
|
||
| Card grizzlyBears = addCard("Grizzly Bears", p2); | ||
|
|
||
| Card pathToExile = addCardToZone("Path to Exile", p3, ZoneType.Hand); | ||
|
|
||
| SpellAbility pathToExileSA = pathToExile.getSpellAbilities().get(0); | ||
| pathToExileSA.getTargets().add(grizzlyBears); | ||
| pathToExileSA.setActivatingPlayer(p3); | ||
|
|
||
| game.getAction().checkStateEffects(true); | ||
|
|
||
| AbilitySub sub = pathToExileSA.getSubAbility(); | ||
|
|
||
| assertTrue(p2.canSearchLibraryWith(sub, p2)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAshiok_opponentCanNotCauseToSearchTheirOwnLibrary() { | ||
| Game game = initAndCreateGame(); | ||
| Player p1 = game.getPlayers().get(0); | ||
| Player p3 = game.getPlayers().get(2); | ||
|
|
||
| Card ashiok = addCard("Ashiok, Dream Render", p1); | ||
| ashiok.setCounters(CounterEnumType.LOYALTY, 5); | ||
|
|
||
| Card grizzlyBears = addCard("Grizzly Bears", p3); | ||
|
|
||
| Card pathToExile = addCardToZone("Path to Exile", p3, ZoneType.Hand); | ||
|
|
||
| SpellAbility pathToExileSA = pathToExile.getSpellAbilities().get(0); | ||
| pathToExileSA.getTargets().add(grizzlyBears); | ||
| pathToExileSA.setActivatingPlayer(p3); | ||
|
|
||
| game.getAction().checkStateEffects(true); | ||
|
|
||
| AbilitySub sub = pathToExileSA.getSubAbility(); | ||
| assertFalse(p3.canSearchLibraryWith(sub, p3), "P3 can not search their own library by sending his own creature to exile"); | ||
| } | ||
|
|
||
| private SpellAbility findSearchLibraryAbility(Card card){ | ||
| return card.getSpellAbilities() | ||
| .stream() | ||
| .filter( sa -> sa.getDescription().toLowerCase().contains("search your library")) | ||
| .peek( sa -> sa.setActivatingPlayer(card.getOwner())) | ||
| .findFirst() | ||
| .orElse(null); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| Name:Mindlock Orb | ||
| ManaCost:3 U | ||
| Types:Artifact | ||
| S:Mode$ Continuous | Affected$ Player | AddKeyword$ CantSearchLibrary | Description$ Players can't search libraries. | ||
| S:Mode$ CantSearchLibrary | ValidPlayer$ Player | Description$ Players can't search libraries. | ||
| Oracle:Players can't search libraries. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit skeptical about the usefulness of these tests in general
(you're not even using
targetPlayerany longer)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. These tests help me to understand and experiment with Forge engine and give me some (false?) confidence. I can easily remove them if the rest is OK.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to break it down:
Ashiok needs the following information
a) SA controller
b) Searcher
c) Searched
then the condition has to check
a = b = c = Opponent(all the same player)I have a hard time seeing that this refactor has this equivalently covered yet