mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Merge pull request #7584 from weirddan455/cascade
Implemented updated Cascade ruling 702.84a
This commit is contained in:
commit
39f6b69391
12 changed files with 201 additions and 45 deletions
|
@ -2781,6 +2781,12 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
return randomOpponentId;
|
return randomOpponentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SpellAbility chooseAbilityForCast(Card card, Game game, boolean noMana) {
|
||||||
|
Map<UUID, ActivatedAbility> useable = PlayerImpl.getSpellAbilities(this.getId(), card, game.getState().getZone(card.getId()), game);
|
||||||
|
return (SpellAbility) useable.values().stream().findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
|
|
|
@ -90,7 +90,6 @@ class GodEternalKefnetDrawCardReplacementEffect extends ReplacementEffectImpl {
|
||||||
you.setTopCardRevealed(true);
|
you.setTopCardRevealed(true);
|
||||||
|
|
||||||
// cast copy
|
// cast copy
|
||||||
|
|
||||||
if (topCard.isInstantOrSorcery()
|
if (topCard.isInstantOrSorcery()
|
||||||
&& you.chooseUse(outcome, "Would you like to copy " + topCard.getName() + " and cast it for {2} less?", source, game)) {
|
&& you.chooseUse(outcome, "Would you like to copy " + topCard.getName() + " and cast it for {2} less?", source, game)) {
|
||||||
Card blueprint = topCard.copy();
|
Card blueprint = topCard.copy();
|
||||||
|
@ -105,7 +104,9 @@ class GodEternalKefnetDrawCardReplacementEffect extends ReplacementEffectImpl {
|
||||||
}
|
}
|
||||||
Card copiedCard = game.copyCard(blueprint, source, source.getControllerId());
|
Card copiedCard = game.copyCard(blueprint, source, source.getControllerId());
|
||||||
you.moveCardToHandWithInfo(copiedCard, source, game, true); // The copy is created in and cast from your hand. (2019-05-03)
|
you.moveCardToHandWithInfo(copiedCard, source, game, true); // The copy is created in and cast from your hand. (2019-05-03)
|
||||||
|
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
|
||||||
you.cast(you.chooseAbilityForCast(copiedCard, game, false), game, false, new ApprovingObject(source, game));
|
you.cast(you.chooseAbilityForCast(copiedCard, game, false), game, false, new ApprovingObject(source, game));
|
||||||
|
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw (return false for default draw)
|
// draw (return false for default draw)
|
||||||
|
|
|
@ -156,7 +156,8 @@ class JestersScepterCost extends CostImpl {
|
||||||
TargetCardInExile target = new TargetCardInExile(new FilterCard(), CardUtil.getCardExileZoneId(game, ability));
|
TargetCardInExile target = new TargetCardInExile(new FilterCard(), CardUtil.getCardExileZoneId(game, ability));
|
||||||
target.setNotTarget(true);
|
target.setNotTarget(true);
|
||||||
Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, ability));
|
Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, ability));
|
||||||
if (!cards.isEmpty()
|
if (cards != null
|
||||||
|
&& !cards.isEmpty()
|
||||||
&& controller.choose(Outcome.Benefit, cards, target, game)) {
|
&& controller.choose(Outcome.Benefit, cards, target, game)) {
|
||||||
Card card = game.getCard(target.getFirstTarget());
|
Card card = game.getCard(target.getFirstTarget());
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
|
|
|
@ -130,7 +130,8 @@ class KahoMinamoHistorianCastEffect extends OneShotEffect {
|
||||||
filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
|
filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
|
||||||
TargetCardInExile target = new TargetCardInExile(filter, CardUtil.getCardExileZoneId(game, source));
|
TargetCardInExile target = new TargetCardInExile(filter, CardUtil.getCardExileZoneId(game, source));
|
||||||
Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
|
Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
|
||||||
if (!cards.isEmpty()
|
if (cards != null
|
||||||
|
&& !cards.isEmpty()
|
||||||
&& controller.choose(Outcome.PlayForFree, cards, target, game)) {
|
&& controller.choose(Outcome.PlayForFree, cards, target, game)) {
|
||||||
Card card = game.getCard(target.getFirstTarget());
|
Card card = game.getCard(target.getFirstTarget());
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
|
|
|
@ -122,7 +122,7 @@ class MesmericFiendLeaveEffect extends OneShotEffect {
|
||||||
UUID exileId = (UUID) game.getState().getValue(source.getSourceId().toString() + zoneChangeMinusOne);
|
UUID exileId = (UUID) game.getState().getValue(source.getSourceId().toString() + zoneChangeMinusOne);
|
||||||
if (exileId != null) {
|
if (exileId != null) {
|
||||||
Cards cards = game.getExile().getExileZone(exileId);
|
Cards cards = game.getExile().getExileZone(exileId);
|
||||||
if (!cards.isEmpty()) {
|
if (cards != null && !cards.isEmpty()) {
|
||||||
return controller.moveCards(cards, Zone.HAND, source, game);
|
return controller.moveCards(cards, Zone.HAND, source, game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,7 @@ class ValkiGodOfLiesRevealExileEffect extends OneShotEffect {
|
||||||
if (opponent != null) {
|
if (opponent != null) {
|
||||||
opponent.revealCards(source, opponent.getHand(), game);
|
opponent.revealCards(source, opponent.getHand(), game);
|
||||||
TargetCard targetToExile = new TargetCard(Zone.HAND, StaticFilters.FILTER_CARD_CREATURE);
|
TargetCard targetToExile = new TargetCard(Zone.HAND, StaticFilters.FILTER_CARD_CREATURE);
|
||||||
|
targetToExile.withChooseHint("card to exile");
|
||||||
targetToExile.setNotTarget(true);
|
targetToExile.setNotTarget(true);
|
||||||
if (controller.choose(Outcome.Exile, opponent.getHand(), targetToExile, game)) {
|
if (controller.choose(Outcome.Exile, opponent.getHand(), targetToExile, game)) {
|
||||||
Card targetedCardToExile = game.getCard(targetToExile.getFirstTarget());
|
Card targetedCardToExile = game.getCard(targetToExile.getFirstTarget());
|
||||||
|
@ -240,7 +241,8 @@ class ValkiGodOfLiesCopyExiledEffect extends OneShotEffect {
|
||||||
filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
|
filter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
|
||||||
TargetCardInExile target = new TargetCardInExile(filter, exileId);
|
TargetCardInExile target = new TargetCardInExile(filter, exileId);
|
||||||
Cards cards = game.getExile().getExileZone(exileId);
|
Cards cards = game.getExile().getExileZone(exileId);
|
||||||
if (!cards.isEmpty()
|
if (cards != null
|
||||||
|
&& !cards.isEmpty()
|
||||||
&& controller.choose(Outcome.Benefit, cards, target, game)) {
|
&& controller.choose(Outcome.Benefit, cards, target, game)) {
|
||||||
Card chosenExiledCard = game.getCard(target.getFirstTarget());
|
Card chosenExiledCard = game.getCard(target.getFirstTarget());
|
||||||
if (chosenExiledCard != null) {
|
if (chosenExiledCard != null) {
|
||||||
|
|
|
@ -138,7 +138,8 @@ class VoidMawCost extends CostImpl {
|
||||||
TargetCardInExile target = new TargetCardInExile(new FilterCard(), CardUtil.getCardExileZoneId(game, ability));
|
TargetCardInExile target = new TargetCardInExile(new FilterCard(), CardUtil.getCardExileZoneId(game, ability));
|
||||||
target.setNotTarget(true);
|
target.setNotTarget(true);
|
||||||
Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, ability));
|
Cards cards = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, ability));
|
||||||
if (!cards.isEmpty()
|
if (cards != null
|
||||||
|
&& !cards.isEmpty()
|
||||||
&& controller.choose(Outcome.Benefit, cards, target, game)) {
|
&& controller.choose(Outcome.Benefit, cards, target, game)) {
|
||||||
Card card = game.getCard(target.getFirstTarget());
|
Card card = game.getCard(target.getFirstTarget());
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import mage.util.CardUtil;
|
||||||
import mage.util.ManaUtil;
|
import mage.util.ManaUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mage.test.player.TestPlayer;
|
||||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -797,4 +798,69 @@ public class ModalDoubleFacesCardsTest extends CardTestPlayerBase {
|
||||||
execute();
|
execute();
|
||||||
assertAllCommandsUsed();
|
assertAllCommandsUsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Cascade_ValkiGodOfLies() {
|
||||||
|
// https://magic.wizards.com/en/articles/archive/news/february-15-2021-banned-and-restricted-announcement
|
||||||
|
// For example, if you cast Bloodbraid Elf and exile Valki, God of Lies from your library,
|
||||||
|
// you'll be able to cast Valki but not Tibalt, Cosmic Impostor. On the other hand, if you
|
||||||
|
// exile Cosima, God of the Voyage, you may cast either Cosima or The Omenkeel, as each face
|
||||||
|
// has a lesser converted mana cost than Bloodbraid Elf.
|
||||||
|
removeAllCardsFromLibrary(playerA);
|
||||||
|
skipInitShuffling();
|
||||||
|
|
||||||
|
// Cascade
|
||||||
|
addCard(Zone.HAND, playerA, "Bloodbraid Elf"); // {2}{R}{G}
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
|
||||||
|
//
|
||||||
|
addCard(Zone.LIBRARY, playerA, "Swamp", 2);
|
||||||
|
addCard(Zone.LIBRARY, playerA, "Valki, God of Lies", 1);
|
||||||
|
addCard(Zone.LIBRARY, playerA, "Island", 2);
|
||||||
|
|
||||||
|
// play elf with cascade
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Bloodbraid Elf");
|
||||||
|
setChoice(playerA, "Yes"); // use free cast
|
||||||
|
//setChoice(playerA, "Cast Valki, God of Lies"); possible bug: you can see two spell abilities to choose, but only one allows here
|
||||||
|
setChoice(playerA, TestPlayer.CHOICE_SKIP); // no choices for valki's etb exile
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
execute();
|
||||||
|
assertAllCommandsUsed();
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Valki, God of Lies", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_Cascade_CosimaGodOfTheVoyage() {
|
||||||
|
// https://magic.wizards.com/en/articles/archive/news/february-15-2021-banned-and-restricted-announcement
|
||||||
|
// For example, if you cast Bloodbraid Elf and exile Valki, God of Lies from your library,
|
||||||
|
// you'll be able to cast Valki but not Tibalt, Cosmic Impostor. On the other hand, if you
|
||||||
|
// exile Cosima, God of the Voyage, you may cast either Cosima or The Omenkeel, as each face
|
||||||
|
// has a lesser converted mana cost than Bloodbraid Elf.
|
||||||
|
removeAllCardsFromLibrary(playerA);
|
||||||
|
skipInitShuffling();
|
||||||
|
|
||||||
|
// Cascade
|
||||||
|
addCard(Zone.HAND, playerA, "Bloodbraid Elf"); // {2}{R}{G}
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
|
||||||
|
//
|
||||||
|
addCard(Zone.LIBRARY, playerA, "Swamp", 2);
|
||||||
|
addCard(Zone.LIBRARY, playerA, "Cosima, God of the Voyage", 1);
|
||||||
|
addCard(Zone.LIBRARY, playerA, "Island", 2);
|
||||||
|
|
||||||
|
// play elf with cascade
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Bloodbraid Elf");
|
||||||
|
setChoice(playerA, "Yes"); // use free cast
|
||||||
|
setChoice(playerA, "Cast The Omenkeel"); // can cast any side here
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
execute();
|
||||||
|
assertAllCommandsUsed();
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "The Omenkeel", 1);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3777,6 +3777,21 @@ public class TestPlayer implements Player {
|
||||||
) {
|
) {
|
||||||
assertAliasSupportInChoices(false);
|
assertAliasSupportInChoices(false);
|
||||||
if (!choices.isEmpty()) {
|
if (!choices.isEmpty()) {
|
||||||
|
|
||||||
|
// skip choices
|
||||||
|
if (choices.get(0).equals(CHOICE_SKIP)) {
|
||||||
|
choices.remove(0);
|
||||||
|
if (cards.isEmpty()) {
|
||||||
|
// cancel button forced in GUI on no possible choices
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
Assert.assertTrue("found skip choice, but it require more choices, needs "
|
||||||
|
+ (target.getMinNumberOfTargets() - target.getTargets().size()) + " more",
|
||||||
|
target.getTargets().size() >= target.getMinNumberOfTargets());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (String choose2 : choices) {
|
for (String choose2 : choices) {
|
||||||
// TODO: More targetting to fix
|
// TODO: More targetting to fix
|
||||||
String[] targetList = choose2.split("\\^");
|
String[] targetList = choose2.split("\\^");
|
||||||
|
|
|
@ -1,36 +1,38 @@
|
||||||
package mage.abilities.keyword;
|
package mage.abilities.keyword;
|
||||||
|
|
||||||
import mage.ApprovingObject;
|
import mage.ApprovingObject;
|
||||||
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.TriggeredAbilityImpl;
|
import mage.abilities.TriggeredAbilityImpl;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.cards.Card;
|
import mage.cards.*;
|
||||||
import mage.cards.Cards;
|
|
||||||
import mage.cards.CardsImpl;
|
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.filter.FilterCard;
|
|
||||||
import mage.filter.StaticFilters;
|
import mage.filter.StaticFilters;
|
||||||
import mage.filter.common.FilterLandCard;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.common.TargetCardInExile;
|
import mage.target.common.TargetCardInExile;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class CascadeAbility extends TriggeredAbilityImpl {
|
public class CascadeAbility extends TriggeredAbilityImpl {
|
||||||
//20091005 - 702.82
|
//20091005 - 702.82
|
||||||
|
//20210215 - 702.84a - Updated Cascade rule
|
||||||
|
|
||||||
private static final String REMINDERTEXT = " <i>(When you cast this spell, "
|
private static final String REMINDERTEXT = " <i>(When you cast this spell, "
|
||||||
+ "exile cards from the top of your library until you exile a "
|
+ "exile cards from the top of your library until you exile a "
|
||||||
+ "nonland card that costs less."
|
+ "nonland card whose converted mana cost is less than this spell's converted mana cost. "
|
||||||
+ " You may cast it without paying its mana cost. "
|
+ "You may cast that spell without paying its mana cost "
|
||||||
+ "Put the exiled cards on the bottom in a random order.)</i>";
|
+ "if its converted mana cost is less than this spell's converted mana cost. "
|
||||||
|
+ "Then put all cards exiled this way that weren't cast on the bottom of your library in a random order.)</i>";
|
||||||
private final boolean withReminder;
|
private final boolean withReminder;
|
||||||
private static final FilterCard filter = new FilterLandCard("land card (to put onto the battlefield)");
|
|
||||||
|
|
||||||
public CascadeAbility() {
|
public CascadeAbility() {
|
||||||
this(true);
|
this(true);
|
||||||
|
@ -86,52 +88,83 @@ class CascadeEffect extends OneShotEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Card card;
|
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
if (controller == null) {
|
if (controller == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Cards cards = new CardsImpl();
|
Card sourceCard = game.getCard(source.getSourceId());
|
||||||
card = game.getCard(source.getSourceId());
|
if (sourceCard == null) {
|
||||||
if (card == null) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int sourceCost = card.getConvertedManaCost();
|
|
||||||
do {
|
// exile cards from the top of your library until you exile a nonland card whose converted mana cost is less than this spell's converted mana cost
|
||||||
card = controller.getLibrary().getFromTop(game);
|
Cards cardsToExile = new CardsImpl();
|
||||||
if (card == null) {
|
int sourceCost = sourceCard.getConvertedManaCost();
|
||||||
|
Card cardToCast = null;
|
||||||
|
for (Card card : controller.getLibrary().getCards(game)) {
|
||||||
|
cardsToExile.add(card);
|
||||||
|
if (!card.isLand() && card.getConvertedManaCost() < sourceCost) {
|
||||||
|
cardToCast = card;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cards.add(card);
|
}
|
||||||
controller.moveCards(card, Zone.EXILED, source, game);
|
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
|
||||||
} while (controller.canRespond()
|
|
||||||
&& (card.isLand() || card.getConvertedManaCost() >= sourceCost));
|
|
||||||
|
|
||||||
controller.getLibrary().reset(); // set back empty draw state if that caused an empty draw
|
controller.getLibrary().reset(); // set back empty draw state if that caused an empty draw
|
||||||
|
|
||||||
|
// additional replacement effect: As you cascade, you may put a land card from among the exiled cards onto the battlefield tapped
|
||||||
GameEvent event = GameEvent.getEvent(GameEvent.EventType.CASCADE_LAND, source.getSourceId(), source, source.getControllerId(), 0);
|
GameEvent event = GameEvent.getEvent(GameEvent.EventType.CASCADE_LAND, source.getSourceId(), source, source.getControllerId(), 0);
|
||||||
game.replaceEvent(event);
|
game.replaceEvent(event);
|
||||||
if (event.getAmount() > 0) {
|
if (event.getAmount() > 0) {
|
||||||
TargetCardInExile target = new TargetCardInExile(
|
TargetCardInExile target = new TargetCardInExile(0, event.getAmount(), StaticFilters.FILTER_CARD_LAND, null, true);
|
||||||
0, event.getAmount(), StaticFilters.FILTER_CARD_LAND, null, true
|
target.withChooseHint("land to put onto battlefield tapped");
|
||||||
);
|
controller.choose(Outcome.PutCardInPlay, cardsToExile, target, game);
|
||||||
controller.choose(Outcome.PutCardInPlay, cards, target, game);
|
|
||||||
controller.moveCards(
|
controller.moveCards(
|
||||||
new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD,
|
new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD,
|
||||||
source, game, true, false, false, null
|
source, game, true, false, false, null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (card != null && controller.chooseUse(
|
|
||||||
outcome, "Use cascade effect on " + card.getLogName() + '?', source, game
|
// You may cast that spell without paying its mana cost if its converted mana cost is less than this spell's converted mana cost.
|
||||||
)) {
|
List<Card> partsToCast = new ArrayList<>();
|
||||||
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
|
if (cardToCast != null) {
|
||||||
controller.cast(controller.chooseAbilityForCast(card, game, true),
|
if (cardToCast instanceof SplitCard) {
|
||||||
game, true, new ApprovingObject(source, game));
|
partsToCast.add(((SplitCard) cardToCast).getLeftHalfCard());
|
||||||
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
|
partsToCast.add(((SplitCard) cardToCast).getRightHalfCard());
|
||||||
|
partsToCast.add(cardToCast);
|
||||||
|
} else if (cardToCast instanceof AdventureCard) {
|
||||||
|
partsToCast.add(((AdventureCard) cardToCast).getSpellCard());
|
||||||
|
partsToCast.add(cardToCast);
|
||||||
|
} else if (cardToCast instanceof ModalDoubleFacesCard) {
|
||||||
|
partsToCast.add(((ModalDoubleFacesCard) cardToCast).getLeftHalfCard());
|
||||||
|
partsToCast.add(((ModalDoubleFacesCard) cardToCast).getRightHalfCard());
|
||||||
|
} else {
|
||||||
|
partsToCast.add(cardToCast);
|
||||||
}
|
}
|
||||||
// Move the remaining cards to the buttom of the library in a random order
|
// remove too big cmc
|
||||||
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
|
partsToCast.removeIf(card -> card.getConvertedManaCost() >= sourceCost);
|
||||||
return controller.putCardsOnBottomOfLibrary(cards, game, source, false);
|
// remove non spells
|
||||||
|
partsToCast.removeIf(card -> card.getSpellAbility() == null);
|
||||||
|
}
|
||||||
|
|
||||||
|
String partsInfo = partsToCast.stream()
|
||||||
|
.map(MageObject::getIdName)
|
||||||
|
.collect(Collectors.joining(" or "));
|
||||||
|
if (cardToCast != null
|
||||||
|
&& partsToCast.size() > 0
|
||||||
|
&& controller.chooseUse(outcome, "Cast spell without paying its mana cost (" + partsInfo + ")?", source, game)) {
|
||||||
|
try {
|
||||||
|
// enable free cast for all compatible parts
|
||||||
|
partsToCast.forEach(card -> game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE));
|
||||||
|
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true),
|
||||||
|
game, true, new ApprovingObject(source, game));
|
||||||
|
} finally {
|
||||||
|
partsToCast.forEach(card -> game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then put all cards exiled this way that weren't cast on the bottom of your library in a random order.
|
||||||
|
cardsToExile.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
|
||||||
|
return controller.putCardsOnBottomOfLibrary(cardsToExile, game, source, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -365,6 +365,20 @@ public interface Player extends MageItem, Copyable<Player> {
|
||||||
|
|
||||||
boolean cast(SpellAbility ability, Game game, boolean noMana, ApprovingObject approvingObject);
|
boolean cast(SpellAbility ability, Game game, boolean noMana, ApprovingObject approvingObject);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force player to choose spell ability to cast. Use it in effects while casting cards.
|
||||||
|
*
|
||||||
|
* Commands order in all use cases:
|
||||||
|
* - PlayFromNotOwnHandZone - true
|
||||||
|
* - chooseAbilityForCast
|
||||||
|
* - cast
|
||||||
|
* - PlayFromNotOwnHandZone - false
|
||||||
|
*
|
||||||
|
* @param card
|
||||||
|
* @param game
|
||||||
|
* @param noMana
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
SpellAbility chooseAbilityForCast(Card card, Game game, boolean noMana);
|
SpellAbility chooseAbilityForCast(Card card, Game game, boolean noMana);
|
||||||
|
|
||||||
boolean putInHand(Card card, Game game);
|
boolean putInHand(Card card, Game game);
|
||||||
|
|
|
@ -1519,7 +1519,20 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return spells for possible cast
|
||||||
|
* Uses in GUI to show only playable spells for choosing from the card
|
||||||
|
* (example: effect allow to cast card and player must choose the spell ability)
|
||||||
|
*
|
||||||
|
* @param playerId
|
||||||
|
* @param object
|
||||||
|
* @param zone
|
||||||
|
* @param game
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static LinkedHashMap<UUID, ActivatedAbility> getSpellAbilities(UUID playerId, MageObject object, Zone zone, Game game) {
|
public static LinkedHashMap<UUID, ActivatedAbility> getSpellAbilities(UUID playerId, MageObject object, Zone zone, Game game) {
|
||||||
|
// it uses simple check from spellCanBeActivatedRegularlyNow
|
||||||
|
// reason: no approved info here (e.g. forced to choose spell ability from cast card)
|
||||||
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
|
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
|
||||||
Abilities<Ability> allAbilities;
|
Abilities<Ability> allAbilities;
|
||||||
if (object instanceof Card) {
|
if (object instanceof Card) {
|
||||||
|
@ -1532,8 +1545,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
if (ability instanceof SpellAbility) {
|
if (ability instanceof SpellAbility) {
|
||||||
switch (((SpellAbility) ability).getSpellAbilityType()) {
|
switch (((SpellAbility) ability).getSpellAbilityType()) {
|
||||||
case BASE_ALTERNATE:
|
case BASE_ALTERNATE:
|
||||||
ActivationStatus as = ((SpellAbility) ability).canActivate(playerId, game);
|
if (((SpellAbility) ability).spellCanBeActivatedRegularlyNow(playerId, game)) {
|
||||||
if (as.canActivate()) {
|
|
||||||
useable.put(ability.getId(), (SpellAbility) ability); // example: Chandra, Torch of Defiance +1 loyal ability
|
useable.put(ability.getId(), (SpellAbility) ability); // example: Chandra, Torch of Defiance +1 loyal ability
|
||||||
}
|
}
|
||||||
return useable;
|
return useable;
|
||||||
|
@ -1567,10 +1579,12 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
return useable;
|
return useable;
|
||||||
default:
|
default:
|
||||||
|
if (((SpellAbility) ability).spellCanBeActivatedRegularlyNow(playerId, game)) {
|
||||||
useable.put(ability.getId(), (SpellAbility) ability);
|
useable.put(ability.getId(), (SpellAbility) ability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return useable;
|
return useable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2720,7 +2734,9 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
|
|
||||||
// casting selected card
|
// casting selected card
|
||||||
// TODO: fix costs (why is Panglacial Wurm automatically accepting payment?)
|
// TODO: fix costs (why is Panglacial Wurm automatically accepting payment?)
|
||||||
|
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
|
||||||
targetPlayer.cast(targetPlayer.chooseAbilityForCast(card, game, false), game, false, null);
|
targetPlayer.cast(targetPlayer.chooseAbilityForCast(card, game, false), game, false, null);
|
||||||
|
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
|
||||||
castableCards.remove(card.getId());
|
castableCards.remove(card.getId());
|
||||||
casted = true;
|
casted = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue