From dfc2624d32f456f679406ea7d9fbaaec5accd459 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sun, 13 Jun 2021 21:22:28 -0400 Subject: [PATCH] [MH2] fixed Urza's Saga not being sacrificed immediately when Blood Moon is on battlefield (ability still triggers on etb, related to Blood Moon issue) --- Mage/src/main/java/mage/game/GameImpl.java | 54 +++++++++++----------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index 8e22f67d90..53eda2a74a 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -2186,34 +2186,34 @@ public abstract class GameImpl implements Game, Serializable { // 704.5s If the number of lore counters on a Saga permanent is greater than or equal to its final chapter number // and it isn't the source of a chapter ability that has triggered but not yet left the stack, that Saga's controller sacrifices it. if (perm.hasSubtype(SubType.SAGA, this)) { - for (Ability sagaAbility : perm.getAbilities()) { - if (sagaAbility instanceof SagaAbility) { - int maxChapter = ((SagaAbility) sagaAbility).getMaxChapter().getNumber(); - if (maxChapter <= perm.getCounters(this).getCount(CounterType.LORE)) { - boolean noChapterAbilityTriggeredOrOnStack = true; - // Check chapter abilities on stack - for (StackObject stackObject : getStack()) { - if (stackObject.getSourceId().equals(perm.getId()) && SagaAbility.isChapterAbility(stackObject)) { - noChapterAbilityTriggeredOrOnStack = false; - break; - } - } - if (noChapterAbilityTriggeredOrOnStack) { - for (TriggeredAbility trigger : state.getTriggered(perm.getControllerId())) { - if (SagaAbility.isChapterAbility(trigger) && trigger.getSourceId().equals(perm.getId())) { - noChapterAbilityTriggeredOrOnStack = false; - break; - } - } - } - if (noChapterAbilityTriggeredOrOnStack) { - // After the last chapter ability has left the stack, you'll sacrifice the Saga - perm.sacrifice(null, this); - somethingHappened = true; - } - } + int maxChapter = perm + .getAbilities(this) + .stream() + .filter(SagaAbility.class::isInstance) + .map(SagaAbility.class::cast) + .map(SagaAbility::getMaxChapter) + .mapToInt(SagaChapter::getNumber) + .max() + .orElse(0); - } + boolean sacSaga = maxChapter <= perm + .getCounters(this) + .getCount(CounterType.LORE) + && this.getStack() + .stream() + .filter(SagaAbility::isChapterAbility) + .map(StackObject::getSourceId) + .noneMatch(perm.getId()::equals) + && this.state + .getTriggered(perm.getControllerId()) + .stream() + .filter(SagaAbility::isChapterAbility) + .map(Ability::getSourceId) + .noneMatch(perm.getId()::equals); + if (sacSaga) { + // After the last chapter ability has left the stack, you'll sacrifice the Saga + perm.sacrifice(null, this); + somethingHappened = true; } } if (this.getState().isLegendaryRuleActive() && StaticFilters.FILTER_PERMANENT_LEGENDARY.match(perm, this)) {