1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-14 09:09:38 -09:00

* Buyback abilities - fixed that AI can't cast cards with buyback for normal cost (AI don't use buyback now);

This commit is contained in:
Oleg Agafonov 2020-01-04 20:26:59 +04:00
parent 1ae9fc883e
commit bcb37992cc
2 changed files with 30 additions and 5 deletions
Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords
Mage/src/main/java/mage/abilities/keyword

View file

@ -1,13 +1,12 @@
package org.mage.test.cards.abilities.keywords;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Ignore;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class BuybackTest extends CardTestPlayerBase {
@ -16,7 +15,7 @@ public class BuybackTest extends CardTestPlayerBase {
* Tests boosting on being blocked
*/
@Test
public void testNormal() {
public void testNormal_User() {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 5);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1);
// Buyback {4} (You may pay an additional as you cast this spell. If you do, put this card into your hand as it resolves.)
@ -24,9 +23,33 @@ public class BuybackTest extends CardTestPlayerBase {
addCard(Zone.HAND, playerA, "Elvish Fury", 1); // Instant {G}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elvish Fury", "Silvercoat Lion");
setChoice(playerA, "Yes"); // use buyback
setStrictChooseMode(true);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPowerToughness(playerA, "Silvercoat Lion", 4, 4);
assertHandCount(playerA, "Elvish Fury", 1);
}
@Test
@Ignore // TODO: enable test after buyback ability will be supported by AI
public void testNormal_AI() {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 5);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1);
// Buyback {4} (You may pay an additional as you cast this spell. If you do, put this card into your hand as it resolves.)
// Target creature gets +2/+2 until end of turn.
addCard(Zone.HAND, playerA, "Elvish Fury", 1); // Instant {G}
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Elvish Fury", "Silvercoat Lion");
//setChoice(playerA, "Yes"); // use buyback - AI must choose
//setStrictChooseMode(true); - AI must choose
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPowerToughness(playerA, "Silvercoat Lion", 4, 4);
assertHandCount(playerA, "Elvish Fury", 1);
@ -35,7 +58,7 @@ public class BuybackTest extends CardTestPlayerBase {
/**
* It seems that a spell with it's buyback cost paid returned to hand after
* it fizzled (by failing to target) when it should go to graveyard.
*
* <p>
* "Q: If I pay a spell's buyback cost, but it fizzles, do I get the card
* back anyway? A: If you pay a buyback cost, you would get the card back
* during the spell's resolution. So if it never resolves (i.e., something

View file

@ -131,7 +131,9 @@ public class BuybackAbility extends StaticAbility implements OptionalAdditionalS
Player player = game.getPlayer(ability.getControllerId());
if (player != null) {
this.resetBuyback(game);
if (player.chooseUse(Outcome.Benefit, "Pay " + buybackCost.getText(false) + " ?", ability, game)) {
// TODO: add AI support to find mana available to pay buyback
// canPay checks only single mana available, not total mana usage
if (player.chooseUse(/*Outcome.Benefit*/ Outcome.AIDontUseIt, "Pay " + buybackCost.getText(false) + " ?", ability, game)) {
activateBuyback(game, true);
for (Iterator it = ((Costs) buybackCost).iterator(); it.hasNext(); ) {
Cost cost = (Cost) it.next();