mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
* Fixed a bug if casting split cards from other players e.g with Mindclaw Shaman (fixes #3867).
This commit is contained in:
parent
ff22a75f34
commit
cba7a510ea
5 changed files with 177 additions and 19 deletions
|
@ -1514,7 +1514,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
if (object != null) {
|
||||
LinkedHashMap<UUID, ActivatedAbility> 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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,24 +1242,37 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
|
||||
for (Ability ability : object.getAbilities()) {
|
||||
if (ability instanceof SpellAbility) {
|
||||
if (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
|
||||
switch (((SpellAbility) ability).getSpellAbilityType()) {
|
||||
case SPLIT_FUSED:
|
||||
if (zone == Zone.HAND) {
|
||||
// Fix so you don't need to choose Fuse twice
|
||||
useable.clear();
|
||||
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;
|
||||
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 {
|
||||
// Fuse only allowed from hand
|
||||
continue;
|
||||
if (((SplitCard) object).getLeftHalfCard().getSpellAbility().canChooseTarget(game)) {
|
||||
useable.put(((SplitCard) object).getLeftHalfCard().getSpellAbility().getId(), ((SplitCard) object).getLeftHalfCard().getSpellAbility());
|
||||
}
|
||||
}
|
||||
if (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT
|
||||
|| ((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_AFTERMATH) {
|
||||
continue;
|
||||
}
|
||||
return useable;
|
||||
default:
|
||||
useable.put(ability.getId(), (SpellAbility) ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
return useable;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue