added chandras embercat unit tests + fix for issue #5880

This commit is contained in:
John Gray 2019-07-06 11:27:23 -04:00
parent bce01ce053
commit f564c522a3
3 changed files with 148 additions and 4 deletions

View file

@ -9,10 +9,12 @@ import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.mana.ConditionalColoredManaAbility;
import mage.abilities.mana.builder.ConditionalManaBuilder;
import mage.abilities.mana.conditional.CreatureCastManaCondition;
import mage.abilities.mana.conditional.PlaneswalkerCastManaCondition;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.filter.Filter;
import mage.game.Game;
import java.util.UUID;
@ -60,7 +62,7 @@ class ChandrasEmbercatManaBuilder extends ConditionalManaBuilder {
}
}
class ChandrasEmbercatManaCondition extends CreatureCastManaCondition {
class ChandrasEmbercatElementalManaCondition extends CreatureCastManaCondition {
@Override
public boolean apply(Game game, Ability source) {
@ -71,8 +73,22 @@ class ChandrasEmbercatManaCondition extends CreatureCastManaCondition {
if (object == null) {
return false;
}
return object.hasSubtype(SubType.ELEMENTAL, game)
|| (object.hasSubtype(SubType.CHANDRA, game) && object.isPlaneswalker());
return object.hasSubtype(SubType.ELEMENTAL, game);
}
}
class ChandrasEmbercatPlaneswalkerManaCondition extends PlaneswalkerCastManaCondition {
@Override
public boolean apply(Game game, Ability source) {
if (!super.apply(game, source)) {
return false;
}
MageObject object = game.getObject(source.getSourceId());
if (object == null) {
return false;
}
return object.hasSubtype(SubType.CHANDRA, game);
}
}
@ -80,6 +96,8 @@ class ChandrasEmbercatConditionalMana extends ConditionalMana {
ChandrasEmbercatConditionalMana(Mana mana) {
super(mana);
addCondition(new ChandrasEmbercatManaCondition());
setComparisonScope(Filter.ComparisonScope.Any);
addCondition(new ChandrasEmbercatElementalManaCondition());
addCondition(new ChandrasEmbercatPlaneswalkerManaCondition());
}
}

View file

@ -0,0 +1,93 @@
package org.mage.test.cards.mana;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* Added this test class to test issue #5880.
* https://github.com/magefree/mage/issues/5880
*
* Chandra's Embercat's effect could not be used on Chandra planeswalkers.
*
* Card Type: Creature Elemental Cat
* P/T: 2 / 2
* Description: T: Add R. Spend this mana only to cast an Elemental spell or a Chandra planeswalker spell.
* @author jgray1206
*/
public class ChandrasEmbercatTest extends CardTestPlayerBase {
// Make sure we can use the mana to cast elementals
@Test
public void testCanCastElementalWithMana() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
addCard(Zone.BATTLEFIELD, playerA, "Chandra's Embercat", 1);
//An elemental creature that costs {1}{R}
addCard(Zone.HAND, playerA, "Chandra's Embercat", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chandra's Embercat");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Chandra's Embercat", 2);
}
// Make sure we can use the mana to cast Chandra Planeswalkers
@Test
public void testCanCastChandraPlaneswalkerWithMana() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 3);
addCard(Zone.BATTLEFIELD, playerA, "Chandra's Embercat", 1);
//A Chandra Planeswalker that costs {3}{R}
addCard(Zone.HAND, playerA, "Chandra, Novice Pyromancer", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chandra, Novice Pyromancer");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Chandra, Novice Pyromancer", 1);
}
// Make sure we cant use the mana to cast non-Chandra Planeswalkers
@Test
public void testCantCastNonChandraPlaneswalkerWithMana() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 3);
addCard(Zone.BATTLEFIELD, playerA, "Chandra's Embercat", 1);
//A non-Chandra planeswalker that costs {2}{U}{U}
addCard(Zone.HAND, playerA, "Jace, the Mind Sculptor", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Jace, the Mind Sculptor");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Jace, the Mind Sculptor", 0);
}
// Make sure we cant use the mana to cast non-Elemental creatures
@Test
public void testCantCastNonElementalCreatureWithMana() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 1);
addCard(Zone.BATTLEFIELD, playerA, "Chandra's Embercat", 1);
//A non-elemental creature that costs {1}{R}
addCard(Zone.HAND, playerA, "Raptor Hatchling", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Raptor Hatchling");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Raptor Hatchling", 0);
}
}

View file

@ -0,0 +1,33 @@
package mage.abilities.mana.conditional;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.condition.Condition;
import mage.abilities.costs.Cost;
import mage.game.Game;
import java.util.UUID;
/**
* @author jgray1206
*/
public class PlaneswalkerCastManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
MageObject object = game.getObject(source.getSourceId());
if (object != null && object.isPlaneswalker()) {
return true;
}
}
return false;
}
@Override
public boolean apply(Game game, Ability source, UUID originalId, Cost costToPay) {
return apply(game, source);
}
}