some reworking of sagas, added tests

This commit is contained in:
Evan Kranzler 2021-06-18 18:27:37 -04:00
parent 949b2671e0
commit 6ca7b06ab9
2 changed files with 83 additions and 33 deletions

View file

@ -13,6 +13,8 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
public class SagaTest extends CardTestPlayerBase {
private static final String rite = "Rite of Belzenlok";
private static final String vorinclex = "Vorinclex, Monstrous Raider";
private static final String flicker = "Flicker";
private static final String boomerang = "Boomerang";
private static final String saga = "Urza's Saga";
private static final String moon = "Blood Moon";
@ -45,6 +47,38 @@ public class SagaTest extends CardTestPlayerBase {
assertPermanentCount(playerA, "Demon", 1);
}
@Test
public void testRiteOfBelzenlokFlicker() {
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 4);
addCard(Zone.HAND, playerA, rite);
addCard(Zone.HAND, playerA, flicker);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, rite);
setStopAt(1, PhaseStep.PRECOMBAT_MAIN);
execute();
assertCounterCount(rite, CounterType.LORE, 1);
assertPermanentCount(playerA, "Cleric", 2);
setStopAt(3, PhaseStep.PRECOMBAT_MAIN);
execute();
assertCounterCount(rite, CounterType.LORE, 2);
assertPermanentCount(playerA, "Cleric", 4);
castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerA, flicker, rite);
setStopAt(3, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertGraveyardCount(playerA, rite, 0);
assertPermanentCount(playerA, rite, 1);
assertCounterCount(playerA, rite, CounterType.LORE, 1);
assertPermanentCount(playerA, "Cleric", 6);
assertPermanentCount(playerA, "Demon", 0);
}
@Test
public void testRiteOfBelzenlokBounced() {
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
@ -77,6 +111,29 @@ public class SagaTest extends CardTestPlayerBase {
assertPermanentCount(playerA, "Demon", 1);
}
@Test
public void testRiteOfBelzenlokVorinclex() {
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 4);
addCard(Zone.BATTLEFIELD, playerA, vorinclex);
addCard(Zone.HAND, playerA, rite);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, rite);
setStopAt(1, PhaseStep.PRECOMBAT_MAIN);
execute();
assertCounterCount(rite, CounterType.LORE, 2);
assertPermanentCount(playerA, "Cleric", 4);
setStopAt(3, PhaseStep.PRECOMBAT_MAIN);
execute();
assertAllCommandsUsed();
assertGraveyardCount(playerA, rite, 1);
assertPermanentCount(playerA, rite, 0);
assertPermanentCount(playerA, "Cleric", 4);
assertPermanentCount(playerA, "Demon", 1);
}
@Test
public void testUrzasSagaThenBloodMoon() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3);
@ -125,7 +182,7 @@ public class SagaTest extends CardTestPlayerBase {
assertPermanentCount(playerA, moon, 1);
}
@Ignore // TODO: fix this
@Ignore // TODO: fix this, related to blood moon etb issues
@Test
public void testBloodMoonThenUrzasSagaThenBounce() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);

View file

@ -17,18 +17,22 @@ import mage.game.stack.StackAbility;
import mage.game.stack.StackObject;
import mage.target.Target;
import mage.target.Targets;
import mage.util.CardUtil;
import java.util.Arrays;
/**
* @author LevelX2
*/
public class SagaAbility extends SimpleStaticAbility {
private SagaChapter maxChapter;
private final SagaChapter maxChapter;
public SagaAbility(Card card, SagaChapter maxChapter) {
super(Zone.ALL, new AddCountersSourceEffect(CounterType.LORE.createInstance()));
this.maxChapter = maxChapter;
this.setRuleVisible(false);
this.setRuleVisible(true);
this.setRuleAtTheTop(true);
Ability ability = new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LORE.createInstance()));
ability.setRuleVisible(false);
card.addAbility(ability);
@ -86,9 +90,6 @@ public class SagaAbility extends SimpleStaticAbility {
}
card.addAbility(ability);
}
if (maxChapter == null || toChapter.getNumber() > maxChapter.getNumber()) {
maxChapter = toChapter;
}
}
public SagaChapter getMaxChapter() {
@ -119,7 +120,7 @@ public class SagaAbility extends SimpleStaticAbility {
class ChapterTriggeredAbility extends TriggeredAbilityImpl {
private SagaChapter chapterFrom, chapterTo;
private final SagaChapter chapterFrom, chapterTo;
public ChapterTriggeredAbility(Effect effect, SagaChapter chapterFrom, SagaChapter chapterTo, boolean optional) {
super(Zone.ALL, effect, optional);
@ -140,22 +141,18 @@ class ChapterTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(getSourceId()) && event.getData().equals(CounterType.LORE.getName())) {
int amountAdded = event.getAmount();
int loreCounters = amountAdded;
//Permanent sourceSaga = game.getPermanentOrLKIBattlefield(getSourceId()); BUG #5393
Permanent sourceSaga = game.getPermanent(getSourceId());
if (sourceSaga == null) {
sourceSaga = game.getPermanentEntering(getSourceId());
}
if (sourceSaga != null) {
loreCounters = sourceSaga.getCounters(game).getCount(CounterType.LORE);
}
return loreCounters - amountAdded < chapterFrom.getNumber()
&& chapterFrom.getNumber() <= loreCounters;
}
if (!event.getTargetId().equals(getSourceId())
|| !event.getData().equals(CounterType.LORE.getName())) {
return false;
}
Permanent permanent = getSourcePermanentIfItStillExists(game);
if (permanent == null) {
return false;
}
int loreCounters = permanent.getCounters(game).getCount(CounterType.LORE);
return loreCounters - event.getAmount() < chapterFrom.getNumber()
&& chapterFrom.getNumber() <= loreCounters;
}
@Override
public ChapterTriggeredAbility copy() {
@ -177,17 +174,13 @@ class ChapterTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
StringBuilder sb = new StringBuilder();
for (SagaChapter chapter : SagaChapter.values()) {
if (chapter.getNumber() >= getChapterFrom().getNumber()
&& chapter.getNumber() < getChapterTo().getNumber()) {
sb.append(chapter.toString()).append(", ");
} else if (chapter.equals(getChapterTo())) {
sb.append(chapter.toString());
}
}
String text = super.getRule();
sb.append(" - ").append(Character.toUpperCase(text.charAt(0))).append(text.substring(1));
return sb.toString();
return Arrays
.stream(SagaChapter.values())
.filter(chapter -> chapterFrom.getNumber() <= chapter.getNumber())
.filter(chapter -> chapter.getNumber() <= chapterTo.getNumber())
.map(SagaChapter::toString)
.reduce((a, b) -> a + ", " + b)
.orElse("")
+ " - " + CardUtil.getTextWithFirstCharUpperCase(super.getRule());
}
}