mirror of
https://github.com/correl/mage.git
synced 2025-03-18 01:03:59 -09:00
* Fixed possible game exception with empty library and commander movement (fixes #6952).
This commit is contained in:
parent
b16d30b79b
commit
12c50420bf
2 changed files with 84 additions and 43 deletions
|
@ -1,6 +1,8 @@
|
|||
|
||||
package org.mage.test.commander.duel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
@ -93,4 +95,41 @@ public class CastCommanderTest extends CardTestCommanderDuelBase {
|
|||
assertGraveyardCount(playerA, "Coiled Tinviper", 1);
|
||||
assertTappedCount("Forest", false, 3);
|
||||
}
|
||||
|
||||
// https://github.com/magefree/mage/issues/6952
|
||||
|
||||
@Test
|
||||
public void testCastCommanderAndUnexpectedlyAbsent() {
|
||||
setStrictChooseMode(true);
|
||||
|
||||
playerA.getLibrary().clear();
|
||||
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
|
||||
|
||||
// Put target nonland permanent into its owner's library just beneath the top X cards of that library.
|
||||
addCard(Zone.HAND, playerA, "Unexpectedly Absent"); // Instant {X}{W}{W}
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ob Nixilis of the Black Oath"); // {3}{B}{B}
|
||||
|
||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Unexpectedly Absent", "Ob Nixilis of the Black Oath");
|
||||
setChoice(playerA, "X=0");
|
||||
setChoice(playerA, "Yes"); // Move Commander to command zone instead library?
|
||||
|
||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertPermanentCount(playerA, "Ob Nixilis of the Black Oath", 0);
|
||||
assertLibraryCount(playerA, "Ob Nixilis of the Black Oath", 0);
|
||||
assertCommandZoneCount(playerA, "Ob Nixilis of the Black Oath", 1);
|
||||
|
||||
assertLibraryCount(playerA, 0);
|
||||
|
||||
assertGraveyardCount(playerA, "Unexpectedly Absent", 1);
|
||||
|
||||
assertLife(playerA, 40);
|
||||
assertLife(playerB, 40);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -996,14 +996,16 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
} else {
|
||||
if (card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true)
|
||||
&& !(card instanceof PermanentToken) && !card.isCopy()) {
|
||||
card = getLibrary().removeFromTop(game);
|
||||
getLibrary().putCardToTopXPos(card, xFromTheTop, game);
|
||||
game.informPlayers(card.getLogName()
|
||||
Card cardInLib = getLibrary().getFromTop(game);
|
||||
if (cardInLib != null && cardInLib.getId().equals(card.getId())) { // check needed because e.g. commander can go to command zone
|
||||
getLibrary().putCardToTopXPos(cardInLib, xFromTheTop, game);
|
||||
game.informPlayers(cardInLib.getLogName()
|
||||
+ " is put into "
|
||||
+ getLogName()
|
||||
+ "'s library "
|
||||
+ CardUtil.numberToOrdinalText(xFromTheTop)
|
||||
+ " from the top");
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -2894,7 +2896,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
boolean withCost = false;
|
||||
Abilities<ActivatedManaAbilityImpl> manaAbilities
|
||||
= permanent.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, game);
|
||||
for (Iterator<ActivatedManaAbilityImpl> it = manaAbilities.iterator(); it.hasNext(); ) {
|
||||
for (Iterator<ActivatedManaAbilityImpl> it = manaAbilities.iterator(); it.hasNext();) {
|
||||
ActivatedManaAbilityImpl ability = it.next();
|
||||
if (canUse == null) {
|
||||
canUse = permanent.canUseActivatedAbilities(game);
|
||||
|
@ -2935,7 +2937,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
boolean anAbilityWasUsed = true;
|
||||
while (anAbilityWasUsed && !sourceWithCosts.isEmpty()) {
|
||||
anAbilityWasUsed = false;
|
||||
for (Iterator<Abilities<ActivatedManaAbilityImpl>> iterator = sourceWithCosts.iterator(); iterator.hasNext(); ) {
|
||||
for (Iterator<Abilities<ActivatedManaAbilityImpl>> iterator = sourceWithCosts.iterator(); iterator.hasNext();) {
|
||||
Abilities<ActivatedManaAbilityImpl> manaAbilities = iterator.next();
|
||||
boolean used = availableMana.addManaWithCost(manaAbilities, game);
|
||||
if (used) {
|
||||
|
@ -4176,7 +4178,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
// identify cards from one owner
|
||||
Cards cards = new CardsImpl();
|
||||
UUID ownerId = null;
|
||||
for (Iterator<Card> it = allCards.iterator(); it.hasNext(); ) {
|
||||
for (Iterator<Card> it = allCards.iterator(); it.hasNext();) {
|
||||
Card card = it.next();
|
||||
if (cards.isEmpty()) {
|
||||
ownerId = card.getOwnerId();
|
||||
|
|
Loading…
Add table
Reference in a new issue