From 79b8093047390e4f87481de1224a73c9d22334c2 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sat, 15 Apr 2023 15:38:44 +0400 Subject: [PATCH] * Jaheira's Respite - fixed that it allows to choose any cards amount (#10206), added card hint; * Arachnogenesis, Blessed Reversal - added card hint; --- .../src/mage/cards/a/Arachnogenesis.java | 47 ++++--------------- .../src/mage/cards/b/BlessedReversal.java | 46 +++--------------- .../src/mage/cards/j/JaheirasRespite.java | 16 +++---- .../common/CreaturesAttackingYouCount.java | 44 +++++++++++++++++ 4 files changed, 67 insertions(+), 86 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/dynamicvalue/common/CreaturesAttackingYouCount.java diff --git a/Mage.Sets/src/mage/cards/a/Arachnogenesis.java b/Mage.Sets/src/mage/cards/a/Arachnogenesis.java index de84153f50b..3ca9441ec26 100644 --- a/Mage.Sets/src/mage/cards/a/Arachnogenesis.java +++ b/Mage.Sets/src/mage/cards/a/Arachnogenesis.java @@ -1,9 +1,6 @@ - package mage.cards.a; -import java.util.UUID; -import mage.abilities.Ability; -import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.CreaturesAttackingYouCount; import mage.abilities.effects.Effect; import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.PreventAllDamageByAllPermanentsEffect; @@ -14,16 +11,15 @@ import mage.constants.Duration; import mage.constants.SubType; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.Predicates; -import mage.game.Game; -import mage.game.combat.CombatGroup; import mage.game.permanent.token.SpiderToken; +import java.util.UUID; + /** - * * @author fireshoes */ public final class Arachnogenesis extends CardImpl { - + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("non-Spider creatures"); static { @@ -31,15 +27,16 @@ public final class Arachnogenesis extends CardImpl { } public Arachnogenesis(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{2}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{G}"); - // create X 1/2 green Spider creature tokens with reach, where X is the number of creatures attacking you. - Effect effect = new CreateTokenEffect(new SpiderToken(), new ArachnogenesisCount()); + // Create X 1/2 green Spider creature tokens with reach, where X is the number of creatures attacking you. + Effect effect = new CreateTokenEffect(new SpiderToken(), CreaturesAttackingYouCount.instance); effect.setText("create X 1/2 green Spider creature tokens with reach, where X is the number of creatures attacking you"); this.getSpellAbility().addEffect(effect); - + this.getSpellAbility().addHint(CreaturesAttackingYouCount.getHint()); + // Prevent all combat damage that would be dealt this turn by non-Spider creatures. - this.getSpellAbility().addEffect(new PreventAllDamageByAllPermanentsEffect(filter, Duration.EndOfTurn, true)); + this.getSpellAbility().addEffect(new PreventAllDamageByAllPermanentsEffect(filter, Duration.EndOfTurn, true)); } private Arachnogenesis(final Arachnogenesis card) { @@ -50,28 +47,4 @@ public final class Arachnogenesis extends CardImpl { public Arachnogenesis copy() { return new Arachnogenesis(this); } -} - -class ArachnogenesisCount implements DynamicValue { - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - int count = 0; - for (CombatGroup combatGroup : game.getCombat().getGroups()) { - if (combatGroup.getDefenderId().equals(sourceAbility.getControllerId())) { - count += combatGroup.getAttackers().size(); - } - } - return count; - } - - @Override - public DynamicValue copy() { - return this; - } - - @Override - public String getMessage() { - return "creatures attacking you"; - } } \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/b/BlessedReversal.java b/Mage.Sets/src/mage/cards/b/BlessedReversal.java index 1062d4621d3..1e10778066f 100644 --- a/Mage.Sets/src/mage/cards/b/BlessedReversal.java +++ b/Mage.Sets/src/mage/cards/b/BlessedReversal.java @@ -1,29 +1,26 @@ - package mage.cards.b; -import java.util.UUID; -import mage.abilities.Ability; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.effects.Effect; +import mage.abilities.dynamicvalue.MultipliedValue; +import mage.abilities.dynamicvalue.common.CreaturesAttackingYouCount; import mage.abilities.effects.common.GainLifeEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.game.Game; -import mage.game.combat.CombatGroup; + +import java.util.UUID; /** - * * @author North */ public final class BlessedReversal extends CardImpl { public BlessedReversal(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{1}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{W}"); // You gain 3 life for each creature attacking you. - this.getSpellAbility().addEffect(new GainLifeEffect(new BlessedReversalCount())); + this.getSpellAbility().addEffect(new GainLifeEffect(new MultipliedValue(CreaturesAttackingYouCount.instance, 3))); + this.getSpellAbility().addHint(CreaturesAttackingYouCount.getHint()); } private BlessedReversal(final BlessedReversal card) { @@ -35,32 +32,3 @@ public final class BlessedReversal extends CardImpl { return new BlessedReversal(this); } } - -class BlessedReversalCount implements DynamicValue { - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - int count = 0; - for (CombatGroup combatGroup : game.getCombat().getGroups()) { - if (combatGroup.getDefenderId().equals(sourceAbility.getControllerId())) { - count += combatGroup.getAttackers().size(); - } - } - return count * 3; - } - - @Override - public DynamicValue copy() { - return this; - } - - @Override - public String getMessage() { - return "creature attacking you"; - } - - @Override - public String toString() { - return "3"; - } -} diff --git a/Mage.Sets/src/mage/cards/j/JaheirasRespite.java b/Mage.Sets/src/mage/cards/j/JaheirasRespite.java index 6ddf73a4fe8..3e59623a94c 100644 --- a/Mage.Sets/src/mage/cards/j/JaheirasRespite.java +++ b/Mage.Sets/src/mage/cards/j/JaheirasRespite.java @@ -1,6 +1,7 @@ package mage.cards.j; import mage.abilities.Ability; +import mage.abilities.dynamicvalue.common.CreaturesAttackingYouCount; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.PreventAllDamageByAllPermanentsEffect; import mage.cards.CardImpl; @@ -13,11 +14,9 @@ import mage.constants.Outcome; import mage.constants.Zone; import mage.filter.StaticFilters; import mage.game.Game; -import mage.game.combat.CombatGroup; import mage.players.Player; import mage.target.common.TargetCardInLibrary; -import java.util.List; import java.util.UUID; /** @@ -30,6 +29,7 @@ public final class JaheirasRespite extends CardImpl { // Search your library for up to X basic land cards, where X is the number of creatures attacking you, put those cards onto the battlefield tapped, then shuffle. this.getSpellAbility().addEffect(new JaheirasRespiteEffect()); + this.getSpellAbility().addHint(CreaturesAttackingYouCount.getHint()); // Prevent all combat damage that would be dealt this turn. this.getSpellAbility().addEffect(new PreventAllDamageByAllPermanentsEffect(Duration.EndOfTurn, true).concatBy("
")); @@ -68,14 +68,10 @@ class JaheirasRespiteEffect extends OneShotEffect { if (player == null) { return false; } - int count = game - .getCombat() - .getGroups() - .stream() - .filter(combatGroup -> source.isControlledBy(combatGroup.getDefenderId())) - .map(CombatGroup::getAttackers) - .mapToInt(List::size) - .sum(); + int count = CreaturesAttackingYouCount.instance.calculate(game, source, this); + if (count == 0) { + return false; + } TargetCardInLibrary target = new TargetCardInLibrary(0, count, StaticFilters.FILTER_CARD_BASIC_LANDS); player.searchLibrary(target, source, game); Cards cards = new CardsImpl(); diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/CreaturesAttackingYouCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CreaturesAttackingYouCount.java new file mode 100644 index 00000000000..b9c4352f8d6 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/CreaturesAttackingYouCount.java @@ -0,0 +1,44 @@ +package mage.abilities.dynamicvalue.common; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.Effect; +import mage.abilities.hint.Hint; +import mage.abilities.hint.ValueHint; +import mage.game.Game; +import mage.game.combat.CombatGroup; + +/** + * @author JayDi85 + */ +public enum CreaturesAttackingYouCount implements DynamicValue { + + instance; + + private static final Hint hint = new ValueHint("Creatures attacking you", instance); + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + int count = 0; + for (CombatGroup combatGroup : game.getCombat().getGroups()) { + if (combatGroup.getDefenderId().equals(sourceAbility.getControllerId())) { + count += combatGroup.getAttackers().size(); + } + } + return count; + } + + @Override + public DynamicValue copy() { + return instance; + } + + @Override + public String getMessage() { + return "creatures attacking you"; + } + + public static Hint getHint() { + return hint; + } +}