Merge branch 'scryReplace' into 'master'

ReplaceScry: RE for Eligeth

See merge request core-developers/forge!3384
This commit is contained in:
Tim Mocny
2020-11-11 13:54:31 +00:00
4 changed files with 105 additions and 17 deletions

View File

@@ -1796,25 +1796,50 @@ public class GameAction {
// 701.17c If multiple players scry at once, each of those players looks at the top cards of their library // 701.17c If multiple players scry at once, each of those players looks at the top cards of their library
// at the same time. Those players decide in APNAP order (see rule 101.4) where to put those // at the same time. Those players decide in APNAP order (see rule 101.4) where to put those
// cards, then those cards move at the same time. // cards, then those cards move at the same time.
public void scry(List<Player> players, int numScry, SpellAbility cause) { public void scry(final List<Player> players, int numScry, SpellAbility cause) {
if (numScry == 0) { if (numScry <= 0) {
return; return;
} }
// reveal the top N library cards to the player (only)
// no real need to separate out the look if // in case something alters the scry amount
// there is only one player scrying Map<Player, Integer> actualPlayers = Maps.newLinkedHashMap();
if (players.size() > 1) {
for (final Player p : players) { for (final Player p : players) {
final CardCollection topN = new CardCollection(p.getCardsIn(ZoneType.Library, numScry)); int playerScry = numScry;
revealTo(topN, p); final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(p);
repParams.put(AbilityKey.Source, cause);
repParams.put(AbilityKey.Num, playerScry);
switch (game.getReplacementHandler().run(ReplacementType.Scry, repParams)) {
case NotReplaced:
break;
case Updated: {
playerScry = (int) repParams.get(AbilityKey.Num);
break;
}
default:
continue;
}
if (playerScry > 0) {
actualPlayers.put(p, playerScry);
// reveal the top N library cards to the player (only)
// no real need to separate out the look if
// there is only one player scrying
if (players.size() > 1) {
final CardCollection topN = new CardCollection(p.getCardsIn(ZoneType.Library, playerScry));
revealTo(topN, p);
}
} }
} }
// make the decisions // make the decisions
List<ImmutablePair<CardCollection, CardCollection>> decisions = Lists.newArrayList(); Map<Player, ImmutablePair<CardCollection, CardCollection>> decisions = Maps.newLinkedHashMap();
for (final Player p : players) { for (final Map.Entry<Player, Integer> e : actualPlayers.entrySet()) {
final CardCollection topN = new CardCollection(p.getCardsIn(ZoneType.Library, numScry)); final Player p = e.getKey();
final CardCollection topN = new CardCollection(p.getCardsIn(ZoneType.Library, e.getValue()));
ImmutablePair<CardCollection, CardCollection> decision = p.getController().arrangeForScry(topN); ImmutablePair<CardCollection, CardCollection> decision = p.getController().arrangeForScry(topN);
decisions.add(decision); decisions.put(p, decision);
int numToTop = decision.getLeft() == null ? 0 : decision.getLeft().size(); int numToTop = decision.getLeft() == null ? 0 : decision.getLeft().size();
int numToBottom = decision.getRight() == null ? 0 : decision.getRight().size(); int numToBottom = decision.getRight() == null ? 0 : decision.getRight().size();
@@ -1823,11 +1848,11 @@ public class GameAction {
} }
// do the moves after all the decisions (maybe not necesssary, but let's // do the moves after all the decisions (maybe not necesssary, but let's
// do it the official way) // do it the official way)
for (int i = 0; i < players.size(); i++) { for (Map.Entry<Player, ImmutablePair<CardCollection, CardCollection>> e : decisions.entrySet()) {
// no good iterate simultaneously in Java // no good iterate simultaneously in Java
final Player p = players.get(i); final Player p = e.getKey();
final CardCollection toTop = decisions.get(i).getLeft(); final CardCollection toTop = e.getValue().getLeft();
final CardCollection toBottom = decisions.get(i).getRight(); final CardCollection toBottom = e.getValue().getRight();
if (toTop != null) { if (toTop != null) {
Collections.reverse(toTop); // reverse to get the correct order Collections.reverse(toTop); // reverse to get the correct order
for (Card c : toTop) { for (Card c : toTop) {

View File

@@ -0,0 +1,51 @@
package forge.game.replacement;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
import java.util.Map;
/**
* TODO: Write javadoc for this type.
*
*/
public class ReplaceScry extends ReplacementEffect {
/**
*
* @param mapParams &emsp; HashMap<String, String>
* @param host &emsp; Card
*/
public ReplaceScry(final Map<String, String> mapParams, final Card host, final boolean intrinsic) {
super(mapParams, host, intrinsic);
}
/* (non-Javadoc)
* @see forge.card.replacement.ReplacementEffect#canReplace(java.util.Map)
*/
@Override
public boolean canReplace(Map<AbilityKey, Object> runParams) {
if (((int) runParams.get(AbilityKey.Num)) <= 0) {
return false;
}
if (hasParam("ValidPlayer")) {
if (!matchesValid(runParams.get(AbilityKey.Affected), getParam("ValidPlayer").split(","), getHostCard())) {
return false;
}
}
return true;
}
/* (non-Javadoc)
* @see forge.card.replacement.ReplacementEffect#setReplacingObjects(java.util.Map, forge.card.spellability.SpellAbility)
*/
@Override
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
sa.setReplacingObject(AbilityKey.Num, runParams.get(AbilityKey.Num));
}
}

View File

@@ -26,6 +26,7 @@ public enum ReplacementType {
Mill(ReplaceMill.class), Mill(ReplaceMill.class),
Moved(ReplaceMoved.class), Moved(ReplaceMoved.class),
ProduceMana(ReplaceProduceMana.class), ProduceMana(ReplaceProduceMana.class),
Scry(ReplaceScry.class),
SetInMotion(ReplaceSetInMotion.class), SetInMotion(ReplaceSetInMotion.class),
Surveil(ReplaceSurveil.class), Surveil(ReplaceSurveil.class),
TurnFaceUp(ReplaceTurnFaceUp.class), TurnFaceUp(ReplaceTurnFaceUp.class),

View File

@@ -0,0 +1,11 @@
Name:Eligeth, Crossroads Augur
ManaCost:4 U U
Types:Legendary Creature Sphinx
PT:5/6
K:Flying
K:Partner
R:Event$ Scry | ActiveZones$ Battlefield | ValidPlayer$ You | ReplaceWith$ Draw | Description$ If you would scry a number of cards, draw that many cards instead.
SVar:Draw:DB$ Draw | Defined$ You | NumCards$ X | References$ X
SVar:X:ReplaceCount$Num
Oracle:Flying\nIf you would scry a number of cards, draw that many cards instead.\nPartner (You can have two commanders if both have partner.)