MCPcopy Create free account
hub / github.com/Card-Forge/forge / scry

Method scry

forge-game/src/main/java/forge/game/GameAction.java:2581–2658  ·  view source on GitHub ↗
(final List<Player> players, int numScry, SpellAbility cause)

Source from the content-addressed store, hash-verified

2579 }
2580
2581 public void scry(final List<Player> players, int numScry, SpellAbility cause) {
2582 if (numScry <= 0) {
2583 // CR 701.22b If a player is instructed to scry 0, no scry event occurs.
2584 return;
2585 }
2586
2587 // in case something alters the scry amount
2588 Map<Player, Integer> actualPlayers = Maps.newLinkedHashMap();
2589
2590 for (final Player p : players) {
2591 int playerScry = numScry;
2592 final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(p);
2593 repParams.put(AbilityKey.Source, cause);
2594 repParams.put(AbilityKey.Num, playerScry);
2595
2596 switch (game.getReplacementHandler().run(ReplacementType.Scry, repParams)) {
2597 case NotReplaced:
2598 break;
2599 case Updated: {
2600 playerScry = (int) repParams.get(AbilityKey.Num);
2601 break;
2602 }
2603 default:
2604 continue;
2605 }
2606 if (playerScry > 0) {
2607 actualPlayers.put(p, playerScry);
2608
2609 // no real need to separate out the look if there is only one player scrying
2610 if (players.size() > 1) {
2611 revealTo(p.getCardsIn(ZoneType.Library, playerScry), p);
2612 }
2613 }
2614 }
2615
2616 // make the decisions
2617 Map<Player, ImmutablePair<CardCollection, CardCollection>> decisions = Maps.newLinkedHashMap();
2618 for (final Map.Entry<Player, Integer> e : actualPlayers.entrySet()) {
2619 final Player p = e.getKey();
2620 final CardCollection topN = new CardCollection(p.getCardsIn(ZoneType.Library, e.getValue()));
2621 ImmutablePair<CardCollection, CardCollection> decision = p.getController().arrangeForScry(topN);
2622 decisions.put(p, decision);
2623 int numToTop = decision.getLeft() == null ? 0 : decision.getLeft().size();
2624 int numToBottom = decision.getRight() == null ? 0 : decision.getRight().size();
2625
2626 // publicize the decision
2627 game.fireEvent(new GameEventScry(PlayerView.get(p), numToTop, numToBottom));
2628 }
2629 // do the moves after all the decisions (maybe not necessary, but let's
2630 // do it the official way)
2631 for (Map.Entry<Player, ImmutablePair<CardCollection, CardCollection>> e : decisions.entrySet()) {
2632 // no good iterate simultaneously in Java
2633 final Player p = e.getKey();
2634 final CardCollection toTop = e.getValue().getLeft();
2635 final CardCollection toBottom = e.getValue().getRight();
2636 int numLookedAt = 0;
2637 if (toTop != null) {
2638 numLookedAt += toTop.size();

Callers 2

afterMulliganMethod · 0.80
resolveMethod · 0.80

Calls 15

mapFromAffectedMethod · 0.95
revealToMethod · 0.95
getCardsInMethod · 0.95
getControllerMethod · 0.95
getMethod · 0.95
moveToLibraryMethod · 0.95
moveToBottomOfLibraryMethod · 0.95
mapFromPlayerMethod · 0.95
getReplacementHandlerMethod · 0.80
getLeftMethod · 0.80
getRightMethod · 0.80
reverseMethod · 0.80

Tested by

no test coverage detected