diff --git a/forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java index 047e6b3e5e0..954248b3562 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java @@ -8,7 +8,6 @@ import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import forge.ai.ComputerUtilCard; import forge.ai.ability.ChangeZoneAi; import forge.card.CardCharacteristicName; import forge.game.Game; @@ -711,29 +710,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect { source.clearImprinted(); } - List movedCards; - if (decider.getLobbyPlayer().isHuman()) { - movedCards = changeHiddenOriginResolveHuman(decider, sa, player, changeNum, origin, destination, fetchList, libraryPos); - } else { - movedCards = hiddenOriginResolveAI(decider, sa, player, changeNum, origin, destination, fetchList, libraryPos); - } - if (((!ZoneType.Battlefield.equals(destination) && changeType != null && !defined) - || (sa.hasParam("Reveal") && !movedCards.isEmpty())) && !sa.hasParam("NoReveal")) { - game.getAction().reveal(movedCards, player); - } - - if ((origin.contains(ZoneType.Library) && !destination.equals(ZoneType.Library) && !defined && shuffleMandatory) - || (sa.hasParam("Shuffle") && "True".equals(sa.getParam("Shuffle")))) { - player.shuffle(sa); - } - } - - private List changeHiddenOriginResolveHuman(final Player decider, final SpellAbility sa, Player player, int changeNum, List origin, ZoneType destination, List fetchList, int libraryPos) { - final List movedCards = new ArrayList(); - - final Card source = sa.getSourceCard(); - final Game game = player.getGame(); final boolean remember = sa.hasParam("RememberChanged"); final boolean champion = sa.hasParam("Champion"); @@ -742,12 +719,12 @@ public class ChangeZoneEffect extends SpellAbilityEffect { final String selectPrompt = sa.hasParam("SelectPrompt") ? sa.getParam("SelectPrompt") : "Select a card from " + origin; final String totalcmc = sa.getParam("WithTotalCMC"); int totcmc = AbilityUtils.calculateAmount(source, totalcmc, sa); - - - + + + List chosenCards = new ArrayList(); for (int i = 0; i < changeNum && destination != null; i++) { if (sa.hasParam("DifferentNames")) { - for (Card c : movedCards) { + for (Card c : chosenCards) { fetchList = CardLists.filter(fetchList, Predicates.not(CardPredicates.nameEquals(c.getName()))); } } @@ -763,7 +740,10 @@ public class ChangeZoneEffect extends SpellAbilityEffect { } else if (sa.hasParam("Defined")) { c = Iterables.getFirst(fetchList, null); } else { - c = decider.getController().chooseSingleEntityForEffect(fetchList, sa, selectPrompt, !sa.hasParam("Mandatory")); + if (decider.getController().getLobbyPlayer().isHuman()) + c = decider.getController().chooseSingleEntityForEffect(fetchList, sa, selectPrompt, !sa.hasParam("Mandatory"), decider); + else + c = ChangeZoneAi.chooseCardToHiddenOriginChangeZone(destination, origin, sa, fetchList, player, decider); } if (c == null) { @@ -776,14 +756,22 @@ public class ChangeZoneEffect extends SpellAbilityEffect { i--; continue; } - - fetchList.remove(c); - Card movedCard = null; + fetchList.remove(c); + chosenCards.add(c); + + if (totalcmc != null) { + totcmc -= c.getCMC(); + } + } + + List movedCards = new ArrayList(); + for(Card c : chosenCards) { + Card movedCard = null; if (destination.equals(ZoneType.Library)) { // do not shuffle the library once we have placed a fetched // card on top. - if (origin.contains(ZoneType.Library) && (i < 1) && !"False".equals(sa.getParam("Shuffle"))) { + if (origin.contains(ZoneType.Library) && !"False".equals(sa.getParam("Shuffle"))) { player.shuffle(sa); } movedCard = game.getAction().moveToLibrary(c, libraryPos); @@ -891,6 +879,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect { } else { movedCard = game.getAction().moveTo(destination, c); } + movedCards.add(movedCard); if (champion) { @@ -910,164 +899,19 @@ public class ChangeZoneEffect extends SpellAbilityEffect { if (imprint) { source.addImprinted(movedCard); } - if (totalcmc != null) { - totcmc -= movedCard.getCMC(); - } + } + + if (((!ZoneType.Battlefield.equals(destination) && changeType != null && !defined) + || (sa.hasParam("Reveal") && !movedCards.isEmpty())) && !sa.hasParam("NoReveal")) { + game.getAction().reveal(movedCards, player); } - return movedCards; + if ((origin.contains(ZoneType.Library) && !destination.equals(ZoneType.Library) && !defined && shuffleMandatory) + || (sa.hasParam("Shuffle") && "True".equals(sa.getParam("Shuffle")))) { + player.shuffle(sa); + } } - - private List hiddenOriginResolveAI(final Player decider, final SpellAbility sa, Player player, int changeNum, List origin, ZoneType destination, List fetchList, int libraryPos) { - final List movedCards = new ArrayList(); - - final Card source = sa.getSourceCard(); - final Game game = decider.getGame(); - - - final boolean remember = sa.hasParam("RememberChanged"); - final boolean forget = sa.hasParam("ForgetChanged"); - final boolean champion = sa.hasParam("Champion"); - final boolean imprint = sa.hasParam("Imprint"); - final String totalcmc = sa.getParam("WithTotalCMC"); - int totcmc = AbilityUtils.calculateAmount(source, totalcmc, sa); - - for (int i = 0; i < changeNum; i++) { - if (sa.hasParam("DifferentNames")) { - for (Card c : movedCards) { - fetchList = CardLists.filter(fetchList, Predicates.not(CardPredicates.nameEquals(c.getName()))); - } - } - if (totalcmc != null) { - if (totcmc >= 0) { - fetchList = CardLists.getValidCards(fetchList, "Card.cmcLE" + Integer.toString(totcmc), decider, source); - } - } - if (fetchList.isEmpty()) { - break; - } - - // Improve the AI for fetching. - Card c = null; - if (sa.hasParam("AtRandom")) { - c = Aggregates.random(fetchList); - } else if (sa.hasParam("Defined")) { - c = fetchList.get(0); - } else { - c = ChangeZoneAi.chooseCardToHiddenOriginChangeZone(destination, origin, sa, fetchList, player, decider); - } - - movedCards.add(c); - fetchList.remove(c); - if (totalcmc != null) { - totcmc -= c.getCMC(); - } - } - - for (final Card c : movedCards) { - Card movedCard = null; - if (ZoneType.Library.equals(destination)) { - movedCard = game.getAction().moveToLibrary(c, libraryPos); - } else if (ZoneType.Battlefield.equals(destination)) { - if (sa.hasParam("Tapped")) { - c.setTapped(true); - } - if (sa.hasParam("GainControl")) { - Player newController = sa.getActivatingPlayer(); - if (sa.hasParam("NewController")) { - newController = AbilityUtils.getDefinedPlayers(sa.getSourceCard(), sa.getParam("NewController"), sa).get(0); - } - c.setController(newController, game.getNextTimestamp()); - } - - if (sa.hasParam("AttachedTo")) { - List list = AbilityUtils.getDefinedCards(sa.getSourceCard(), - sa.getParam("AttachedTo"), sa); - if (list.isEmpty()) { - list = game.getCardsIn(ZoneType.Battlefield); - list = CardLists.getValidCards(list, sa.getParam("AttachedTo"), c.getController(), c); - } - if (!list.isEmpty()) { - final Card attachedTo = ComputerUtilCard.getBestAI(list); - if (c.isEnchanting()) { - // If this Card is already Enchanting something, need - // to unenchant it, then clear out the commands - final GameEntity oldEnchanted = c.getEnchanting(); - c.removeEnchanting(oldEnchanted); - } - c.enchantEntity(attachedTo); - } else { // When it should enter the battlefield attached to an illegal permanent it fails - continue; - } - } - - if (sa.hasParam("Attacking")) { - final Combat combat = game.getCombat(); - if ( null != combat ) { - final List e = combat.getDefenders(); - final GameEntity defender = player.getController().chooseSingleEntityForEffect(e, sa, "Declare " + c); - combat.addAttacker(c, defender); - } - } - if (sa.hasParam("Blocking")) { - final Combat combat = game.getCombat(); - if ( null != combat ) { - List attackers = AbilityUtils.getDefinedCards(source, sa.getParam("Blocking"), sa); - if (!attackers.isEmpty()) { - Card attacker = attackers.get(0); - if (combat.isAttacking(attacker)) { - combat.addBlocker(attacker, c); - combat.orderAttackersForDamageAssignment(c); - } - } - } - } - // Auras without Candidates stay in their current location - if (c.isAura()) { - final SpellAbility saAura = AttachEffect.getAttachSpellAbility(c); - if (!saAura.getTargetRestrictions().hasCandidates(saAura, false)) { - continue; - } - } - - movedCard = game.getAction().moveTo(c.getController().getZone(destination), c); - if (sa.hasParam("Tapped")) { - movedCard.setTapped(true); - } - } else if (destination.equals(ZoneType.Exile)) { - movedCard = game.getAction().exile(c); - if (sa.hasParam("ExileFaceDown")) { - movedCard.setState(CardCharacteristicName.FaceDown); - } - } else { - movedCard = game.getAction().moveTo(destination, c); - } - - if (champion) { - final HashMap runParams = new HashMap(); - runParams.put("Card", source); - runParams.put("Championed", c); - game.getTriggerHandler().runTrigger(TriggerType.Championed, runParams, false); - } - - if (remember) { - source.addRemembered(movedCard); - } - if (forget) { - source.removeRemembered(movedCard); - } - // for imprinted since this doesn't use Target - if (imprint) { - source.addImprinted(movedCard); - } - } - - return movedCards; - } // end changeHiddenOriginResolveAI - - - /** *

* removeFromStack.