diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/CommandersCastTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/CommandersCastTest.java index ef7556ca1ee..0b0ea380119 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/CommandersCastTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/CommandersCastTest.java @@ -1,5 +1,6 @@ package org.mage.test.cards.continuous; +import mage.abilities.keyword.FirstStrikeAbility; import mage.constants.PhaseStep; import mage.constants.Zone; import org.junit.Test; @@ -224,4 +225,50 @@ public class CommandersCastTest extends CardTestCommander4Players { execute(); assertAllCommandsUsed(); } + + @Test + public void test_AlternativeSpellNormal() { + // Player order: A -> D -> C -> B + + // Weapon Surge + // Target creature you control gets +1/+0 and gains first strike until end of turn. + // Overload {1}{R} (You may cast this spell for its overload cost. If you do, change its text by replacing all instances of “target” with “each.”) + addCard(Zone.HAND, playerA, "Weapon Surge", 1); // {R} or {1}{R} + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + // + addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 2); + + // cast overload + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Weapon Surge with overload"); + checkAbility("after", 1, PhaseStep.BEGIN_COMBAT, playerA, "Balduvian Bears", FirstStrikeAbility.class, true); + + setStopAt(1, PhaseStep.END_TURN); + setStrictChooseMode(true); + execute(); + assertAllCommandsUsed(); + } + + @Test + public void test_AlternativeSpellCommander() { + // Player order: A -> D -> C -> B + + // Weapon Surge + // Target creature you control gets +1/+0 and gains first strike until end of turn. + // Overload {1}{R} (You may cast this spell for its overload cost. If you do, change its text by replacing all instances of “target” with “each.”) + addCard(Zone.COMMAND, playerA, "Weapon Surge", 1); // {R} or {1}{R} + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + // + addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 2); + + // cast overload + showAvaileableAbilities("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Weapon Surge with overload"); + setChoice(playerA, "Yes"); // move to command zone + checkAbility("after", 1, PhaseStep.BEGIN_COMBAT, playerA, "Balduvian Bears", FirstStrikeAbility.class, true); + + setStopAt(1, PhaseStep.END_TURN); + setStrictChooseMode(true); + execute(); + assertAllCommandsUsed(); + } } diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index bbd0f56b2e4..7b5cc3185e0 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -904,8 +904,8 @@ public class TestPlayer implements Player { .map(a -> ( a.getZone() + " -> " + a.getSourceObject(game).getIdName() + " -> " - + (a.getRule().length() > 0 - ? a.getRule().substring(0, Math.min(20, a.getRule().length()) - 1) + + (a.toString().length() > 0 + ? a.toString().substring(0, Math.min(20, a.toString().length()) - 1) : a.getClass().getSimpleName()) + "..." )) diff --git a/Mage/src/main/java/mage/abilities/common/CastCommanderAbility.java b/Mage/src/main/java/mage/abilities/common/CastCommanderAbility.java index b369830e706..e0921660147 100644 --- a/Mage/src/main/java/mage/abilities/common/CastCommanderAbility.java +++ b/Mage/src/main/java/mage/abilities/common/CastCommanderAbility.java @@ -2,7 +2,6 @@ package mage.abilities.common; import mage.abilities.SpellAbility; import mage.cards.Card; -import mage.constants.SpellAbilityType; import mage.constants.Zone; /** @@ -10,12 +9,12 @@ import mage.constants.Zone; */ public class CastCommanderAbility extends SpellAbility { - public CastCommanderAbility(Card card) { - super(card.getSpellAbility()); + public CastCommanderAbility(Card card, SpellAbility spellTemplate) { + super(spellTemplate); this.newId(); - this.setCardName(card.getName()); + this.setCardName(spellTemplate.getCardName()); zone = Zone.COMMAND; - spellAbilityType = SpellAbilityType.BASE; + spellAbilityType = spellTemplate.getSpellAbilityType(); } public CastCommanderAbility(final CastCommanderAbility ability) { diff --git a/Mage/src/main/java/mage/game/command/Commander.java b/Mage/src/main/java/mage/game/command/Commander.java index 96c25d0c4eb..e8a34c3a7d6 100644 --- a/Mage/src/main/java/mage/game/command/Commander.java +++ b/Mage/src/main/java/mage/game/command/Commander.java @@ -12,6 +12,7 @@ import mage.abilities.text.TextPart; import mage.cards.Card; import mage.cards.FrameStyle; import mage.constants.CardType; +import mage.constants.SpellAbilityType; import mage.constants.SubType; import mage.constants.SuperType; import mage.game.Game; @@ -19,7 +20,6 @@ import mage.game.events.ZoneChangeEvent; import mage.util.GameLog; import mage.util.SubTypeList; -import java.util.EnumSet; import java.util.List; import java.util.Set; import java.util.UUID; @@ -36,7 +36,17 @@ public class Commander implements CommandObject { // replace spell ability by commander cast spell (to cast from command zone) if (card.getSpellAbility() != null) { - abilities.add(new CastCommanderAbility(card)); + abilities.add(new CastCommanderAbility(card, card.getSpellAbility())); + } + + // replace alternative spell abilities by commander cast spell (to cast from command zone) + for (Ability ability : card.getAbilities()) { + if (ability instanceof SpellAbility) { + SpellAbility spellAbility = (SpellAbility) ability; + if (spellAbility.getSpellAbilityType() == SpellAbilityType.BASE_ALTERNATE) { + abilities.add(new CastCommanderAbility(card, spellAbility)); + } + } } // replace play land with commander play land (to play from command zone)