diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index 27129fed99..005158b651 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -1514,7 +1514,7 @@ public class ComputerPlayer extends PlayerImpl implements Player { if (object != null) { LinkedHashMap useableAbilities = getSpellAbilities(object, game.getState().getZone(object.getId()), game); if (useableAbilities != null && !useableAbilities.isEmpty()) { - game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(useableAbilities.values())); + // game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(useableAbilities.values())); // TODO: Improve this return (SpellAbility) useableAbilities.values().iterator().next(); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/cost/splitcards/CastSplitCardsFromOtherZonesTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/cost/splitcards/CastSplitCardsFromOtherZonesTest.java new file mode 100644 index 0000000000..fcec6f5e2c --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/cost/splitcards/CastSplitCardsFromOtherZonesTest.java @@ -0,0 +1,127 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package org.mage.test.cards.cost.splitcards; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class CastSplitCardsFromOtherZonesTest extends CardTestPlayerBase { + + /** + * I attempted to cast Wear // Tear from my opponent's hand with Mindclaw + * Shaman - the card is selectable, but doesn't do anything at all after it + * gets selected to cast. To my best knowledge, Mindclaw Shaman should be + * able to cast one side, the other or both (only in the case of Fuse + * cards). + */ + @Test + public void testCastTearFromOpponentsHand() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5); + // When Mindclaw Shaman enters the battlefield, target opponent reveals his or her hand. + // You may cast an instant or sorcery card from it without paying its mana cost. + addCard(Zone.HAND, playerA, "Mindclaw Shaman"); // Creature {4}{R} + + addCard(Zone.BATTLEFIELD, playerB, "Sanguine Bond", 1); // Enchantment to destroy + // Wear + // Destroy target artifact. + // Tear + // Destroy target enchantment. + addCard(Zone.HAND, playerB, "Wear // Tear"); // Instant {1}{R} // {W} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Mindclaw Shaman"); + addTarget(playerA, "Sanguine Bond"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Mindclaw Shaman", 1); + assertGraveyardCount(playerB, "Wear // Tear", 1); + assertGraveyardCount(playerB, "Sanguine Bond", 1); + + } + + @Test + public void testCastFearFromOpponentsHand() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5); + // When Mindclaw Shaman enters the battlefield, target opponent reveals his or her hand. + // You may cast an instant or sorcery card from it without paying its mana cost. + addCard(Zone.HAND, playerA, "Mindclaw Shaman"); // Creature {4}{R} + + addCard(Zone.BATTLEFIELD, playerB, "Icy Manipulator", 1); // Artifact to destroy + // Wear + // Destroy target artifact. + // Tear + // Destroy target enchantment. + addCard(Zone.HAND, playerB, "Wear // Tear"); // Instant {1}{R} // {W} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Mindclaw Shaman"); + addTarget(playerA, "Icy Manipulator"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Mindclaw Shaman", 1); + assertGraveyardCount(playerB, "Wear // Tear", 1); + assertGraveyardCount(playerB, "Icy Manipulator", 1); + + } + + @Test + public void testCastFusedFromOpponentsHand() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 5); + // When Mindclaw Shaman enters the battlefield, target opponent reveals his or her hand. + // You may cast an instant or sorcery card from it without paying its mana cost. + addCard(Zone.HAND, playerA, "Mindclaw Shaman"); // Creature {4}{R} + + addCard(Zone.BATTLEFIELD, playerB, "Sanguine Bond", 1); // Enchantment to destroy + addCard(Zone.BATTLEFIELD, playerB, "Icy Manipulator", 1); // Artifact to destroy + // Wear + // Destroy target artifact. + // Tear + // Destroy target enchantment. + addCard(Zone.HAND, playerB, "Wear // Tear"); // Instant {1}{R} // {W} + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Mindclaw Shaman"); + addTarget(playerA, "Sanguine Bond"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Mindclaw Shaman", 1); + assertGraveyardCount(playerB, "Wear // Tear", 1); + assertGraveyardCount(playerB, "Sanguine Bond", 1); + assertGraveyardCount(playerB, "Icy Manipulator", 1); + + } +} diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index 33f84c4e63..e814b181f0 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -47,6 +47,7 @@ import mage.abilities.effects.common.ManaEffect; import mage.abilities.keyword.FlashbackAbility; import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.cards.Card; +import mage.cards.SplitCard; import mage.constants.*; import mage.game.Game; import mage.game.command.Emblem; @@ -886,14 +887,28 @@ public abstract class AbilityImpl implements Ability { @Override public boolean canChooseTarget(Game game) { + if (this instanceof SpellAbility) { + if (SpellAbilityType.SPLIT_FUSED.equals(((SpellAbility) this).getSpellAbilityType())) { + Card card = game.getCard(getSourceId()); + if (card != null) { + return canChooseTargetAbility(((SplitCard) card).getLeftHalfCard().getSpellAbility(), game, getControllerId()) + && canChooseTargetAbility(((SplitCard) card).getRightHalfCard().getSpellAbility(), game, getControllerId()); + } + return false; + } + } + return canChooseTargetAbility(this, game, getControllerId()); + } + + private static boolean canChooseTargetAbility(Ability ability, Game game, UUID controllerId) { int found = 0; - for (Mode mode : getModes().values()) { - if (mode.getTargets().canChoose(sourceId, controllerId, game)) { + for (Mode mode : ability.getModes().values()) { + if (mode.getTargets().canChoose(ability.getSourceId(), ability.getControllerId(), game)) { found++; - if (getModes().isEachModeMoreThanOnce()) { + if (ability.getModes().isEachModeMoreThanOnce()) { return true; } - if (found >= getModes().getMinModes()) { + if (found >= ability.getModes().getMinModes()) { return true; } } diff --git a/Mage/src/main/java/mage/cards/SplitCard.java b/Mage/src/main/java/mage/cards/SplitCard.java index 9e57f04b9f..58fd8e0a08 100644 --- a/Mage/src/main/java/mage/cards/SplitCard.java +++ b/Mage/src/main/java/mage/cards/SplitCard.java @@ -119,6 +119,8 @@ public abstract class SplitCard extends CardImpl { case SPLIT_RIGHT: return this.getRightHalfCard().cast(game, fromZone, ability, controllerId); default: + this.getLeftHalfCard().getSpellAbility().setControllerId(controllerId); + this.getRightHalfCard().getSpellAbility().setControllerId(controllerId); return super.cast(game, fromZone, ability, controllerId); } } diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 4aeb681206..efbbb38964 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -966,6 +966,7 @@ public abstract class PlayerImpl implements Player, Serializable { if (game == null || ability == null) { return false; } + ability.setControllerId(getId()); if (ability.getSpellAbilityType() != SpellAbilityType.BASE) { ability = chooseSpellAbilityForCast(ability, game, noMana); } @@ -1241,22 +1242,35 @@ public abstract class PlayerImpl implements Player, Serializable { LinkedHashMap useable = new LinkedHashMap<>(); for (Ability ability : object.getAbilities()) { if (ability instanceof SpellAbility) { - if (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) { - if (zone == Zone.HAND) { - // Fix so you don't need to choose Fuse twice - useable.clear(); - useable.put(ability.getId(), (SpellAbility) ability); + switch (((SpellAbility) ability).getSpellAbilityType()) { + case SPLIT_FUSED: + if (zone == Zone.HAND) { + if (((SpellAbility) ability).canChooseTarget(game)) { + useable.put(ability.getId(), (SpellAbility) ability); + } + } + case SPLIT: + if (((SplitCard) object).getLeftHalfCard().getSpellAbility().canChooseTarget(game)) { + useable.put(((SplitCard) object).getLeftHalfCard().getSpellAbility().getId(), ((SplitCard) object).getLeftHalfCard().getSpellAbility()); + } + if (((SplitCard) object).getRightHalfCard().getSpellAbility().canChooseTarget(game)) { + useable.put(((SplitCard) object).getRightHalfCard().getSpellAbility().getId(), ((SplitCard) object).getRightHalfCard().getSpellAbility()); + } return useable; - } else { - // Fuse only allowed from hand - continue; - } + case SPLIT_AFTERMATH: + if (zone == Zone.GRAVEYARD) { + if (((SplitCard) object).getRightHalfCard().getSpellAbility().canChooseTarget(game)) { + useable.put(((SplitCard) object).getRightHalfCard().getSpellAbility().getId(), ((SplitCard) object).getRightHalfCard().getSpellAbility()); + } + } else { + if (((SplitCard) object).getLeftHalfCard().getSpellAbility().canChooseTarget(game)) { + useable.put(((SplitCard) object).getLeftHalfCard().getSpellAbility().getId(), ((SplitCard) object).getLeftHalfCard().getSpellAbility()); + } + } + return useable; + default: + useable.put(ability.getId(), (SpellAbility) ability); } - if (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT - || ((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_AFTERMATH) { - continue; - } - useable.put(ability.getId(), (SpellAbility) ability); } } return useable;