diff --git a/Mage.Sets/src/mage/cards/a/AlibouAncientWitness.java b/Mage.Sets/src/mage/cards/a/AlibouAncientWitness.java index 1472c6cade6..3fc6f9f0f98 100644 --- a/Mage.Sets/src/mage/cards/a/AlibouAncientWitness.java +++ b/Mage.Sets/src/mage/cards/a/AlibouAncientWitness.java @@ -47,7 +47,7 @@ public final class AlibouAncientWitness extends CardImpl { Ability ability = new AttacksWithCreaturesTriggeredAbility( new AlibouAncientWitnessEffect(), 1, StaticFilters.FILTER_PERMANENTS_ARTIFACT_CREATURE - ); + ).setTriggerPhrase("Whenever one or more artifact creatures you control attack, "); ability.addTarget(new TargetAnyTarget()); this.addAbility(ability.addHint(AlibouAncientWitnessEffect.getHint())); } diff --git a/Mage.Sets/src/mage/cards/a/AncestorDragon.java b/Mage.Sets/src/mage/cards/a/AncestorDragon.java index 04857e8c10d..90820cb6a70 100644 --- a/Mage.Sets/src/mage/cards/a/AncestorDragon.java +++ b/Mage.Sets/src/mage/cards/a/AncestorDragon.java @@ -1,20 +1,20 @@ package mage.cards.a; -import java.util.UUID; - import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.AttacksWithCreaturesTriggeredAbility; import mage.abilities.effects.OneShotEffect; -import mage.constants.SubType; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; +import mage.constants.SubType; import mage.game.Game; import mage.players.Player; +import java.util.UUID; + /** * @author TheElk801 */ @@ -31,7 +31,9 @@ public final class AncestorDragon extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // Whenever one or more creatures you control attack, you gain 1 life for each attacking creature. - this.addAbility(new AttacksWithCreaturesTriggeredAbility(new AncestorDragonEffect(), 1)); + this.addAbility(new AttacksWithCreaturesTriggeredAbility( + new AncestorDragonEffect(), 1 + ).setTriggerPhrase("Whenever one or more creatures you control attack, ")); } private AncestorDragon(final AncestorDragon card) { diff --git a/Mage.Sets/src/mage/cards/a/AngelicGuardian.java b/Mage.Sets/src/mage/cards/a/AngelicGuardian.java index 19b7df8c97c..58cc6759579 100644 --- a/Mage.Sets/src/mage/cards/a/AngelicGuardian.java +++ b/Mage.Sets/src/mage/cards/a/AngelicGuardian.java @@ -37,7 +37,9 @@ public final class AngelicGuardian extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // Whenever one or more creatures you control attack, they gain indestructible until end of turn - this.addAbility(new AttacksWithCreaturesTriggeredAbility(new AngelicGuardianGainEffect(), 1)); + this.addAbility(new AttacksWithCreaturesTriggeredAbility( + new AngelicGuardianGainEffect(), 1 + ).setTriggerPhrase("Whenever one or more creatures you control attack, ")); } private AngelicGuardian(final AngelicGuardian card) { diff --git a/Mage.Sets/src/mage/cards/k/KrydleOfBaldursGate.java b/Mage.Sets/src/mage/cards/k/KrydleOfBaldursGate.java index 3c281503479..20b9bbf634a 100644 --- a/Mage.Sets/src/mage/cards/k/KrydleOfBaldursGate.java +++ b/Mage.Sets/src/mage/cards/k/KrydleOfBaldursGate.java @@ -47,7 +47,7 @@ public final class KrydleOfBaldursGate extends CardImpl { // Whenever you attack, you may pay {2}. If you do, target creature can't be blocked this turn. ability = new AttacksWithCreaturesTriggeredAbility(new DoIfCostPaid( new CantBeBlockedTargetEffect(), new GenericManaCost(2) - ), 0); + ), 1); ability.addTarget(new TargetCreaturePermanent()); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/p/PaladinClass.java b/Mage.Sets/src/mage/cards/p/PaladinClass.java index 0339e5a6ca5..15c0b70713b 100644 --- a/Mage.Sets/src/mage/cards/p/PaladinClass.java +++ b/Mage.Sets/src/mage/cards/p/PaladinClass.java @@ -68,7 +68,7 @@ public final class PaladinClass extends CardImpl { new BoostTargetEffect(xValue, xValue, Duration.EndOfTurn, true) .setText("until end of turn, target attacking creature " + "gets +1/+1 for each other attacking creature"), - 0 + 1 ); ability.addEffect(new GainAbilityTargetEffect( DoubleStrikeAbility.getInstance(), Duration.EndOfTurn diff --git a/Mage.Sets/src/mage/cards/p/PathOfBravery.java b/Mage.Sets/src/mage/cards/p/PathOfBravery.java index 5c11488da34..f1fbd0ba7bc 100644 --- a/Mage.Sets/src/mage/cards/p/PathOfBravery.java +++ b/Mage.Sets/src/mage/cards/p/PathOfBravery.java @@ -1,25 +1,25 @@ - package mage.cards.p; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.AttacksWithCreaturesTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.Condition; import mage.abilities.decorator.ConditionalContinuousEffect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.AttackingCreatureCount; +import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.effects.common.continuous.BoostAllEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.TargetController; -import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.players.Player; +import java.util.UUID; + /** * @author jeffwadsworth */ @@ -32,16 +32,20 @@ public final class PathOfBravery extends CardImpl { } static final String rule = "As long as your life total is greater than or equal to your starting life total, creatures you control get +1/+1"; + private static final DynamicValue xValue = new AttackingCreatureCount(); public PathOfBravery(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}"); // As long as your life total is greater than or equal to your starting life total, creatures you control get +1/+1. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filter, true), LifeCondition.instance, rule))); + this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect(new BoostAllEffect( + 1, 1, Duration.WhileOnBattlefield, filter, true + ), LifeCondition.instance, rule))); // Whenever one or more creatures you control attack, you gain life equal to the number of attacking creatures. - this.addAbility(new AttacksWithCreaturesTriggeredAbility(new PathOfBraveryEffect(), 1)); - + this.addAbility(new AttacksWithCreaturesTriggeredAbility(new GainLifeEffect( + xValue, "you gain life equal to the number of attacking creatures" + ), 1).setTriggerPhrase("Whenever one or more creatures you control attack, ")); } private PathOfBravery(final PathOfBravery card) { @@ -67,34 +71,3 @@ enum LifeCondition implements Condition { return false; } } - -class PathOfBraveryEffect extends OneShotEffect { - - private int attackers; - - public PathOfBraveryEffect() { - super(Outcome.GainLife); - staticText = "you gain life equal to the number of attacking creatures"; - } - - public PathOfBraveryEffect(final PathOfBraveryEffect effect) { - super(effect); - } - - @Override - public PathOfBraveryEffect copy() { - return new PathOfBraveryEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player you = game.getPlayer(source.getControllerId()); - attackers = game.getCombat().getAttackers().size(); - if (you != null) { - you.gainLife(attackers, game, source); - attackers = 0; - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/p/PlarggDeanOfChaos.java b/Mage.Sets/src/mage/cards/p/PlarggDeanOfChaos.java index e13e052308d..482dadd310a 100644 --- a/Mage.Sets/src/mage/cards/p/PlarggDeanOfChaos.java +++ b/Mage.Sets/src/mage/cards/p/PlarggDeanOfChaos.java @@ -82,7 +82,7 @@ public final class PlarggDeanOfChaos extends ModalDoubleFacesCard { // Whenever you attack, untap each creature you control, then tap any number of creatures you control. AttacksWithCreaturesTriggeredAbility augustaAbility = new AttacksWithCreaturesTriggeredAbility( - new UntapAllControllerEffect(StaticFilters.FILTER_PERMANENT_CREATURES, "untap each creature you control"), 0); + new UntapAllControllerEffect(StaticFilters.FILTER_PERMANENT_CREATURES, "untap each creature you control"), 1); augustaAbility.addEffect(new AugustaDeanOfOrderEffect().concatBy(", then")); this.getRightHalfCard().addAbility(augustaAbility); } diff --git a/Mage.Sets/src/mage/cards/r/RagingRiver.java b/Mage.Sets/src/mage/cards/r/RagingRiver.java index 0d342b57088..9fb3086d78b 100644 --- a/Mage.Sets/src/mage/cards/r/RagingRiver.java +++ b/Mage.Sets/src/mage/cards/r/RagingRiver.java @@ -1,4 +1,3 @@ - package mage.cards.r; import mage.MageObject; @@ -33,7 +32,6 @@ import java.util.UUID; import java.util.stream.Collectors; /** - * * @author L_J */ public final class RagingRiver extends CardImpl { @@ -42,7 +40,9 @@ public final class RagingRiver extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{R}{R}"); // Whenever one or more creatures you control attack, each defending player divides all creatures without flying they control into a "left" pile and a "right" pile. Then, for each attacking creature you control, choose "left" or "right." That creature can't be blocked this combat except by creatures with flying and creatures in a pile with the chosen label. - this.addAbility(new AttacksWithCreaturesTriggeredAbility(new RagingRiverEffect(), 1)); + this.addAbility(new AttacksWithCreaturesTriggeredAbility( + new RagingRiverEffect(), 1 + ).setTriggerPhrase("Whenever one or more creatures you control attack, ")); } private RagingRiver(final RagingRiver card) { @@ -92,20 +92,19 @@ class RagingRiverEffect extends OneShotEffect { if (target.getTargets().contains(permanent.getId())) { left.add(permanent); leftLog.add(permanent); - } - else if (filterBlockers.match(permanent, source.getSourceId(), defenderId, game)) { + } else if (filterBlockers.match(permanent, source.getSourceId(), defenderId, game)) { right.add(permanent); rightLog.add(permanent); } } } - + // it could be nice to invoke some graphic indicator of which creature is Left or Right in this spot StringBuilder sb = new StringBuilder("Left pile of ").append(defender.getLogName()).append(": "); sb.append(leftLog.stream().map(MageObject::getLogName).collect(Collectors.joining(", "))); game.informPlayers(sb.toString()); - + sb = new StringBuilder("Right pile of ").append(defender.getLogName()).append(": "); sb.append(rightLog.stream().map(MageObject::getLogName).collect(Collectors.joining(", "))); @@ -135,7 +134,7 @@ class RagingRiverEffect extends OneShotEffect { .filter(permanent -> permanent.isControlledBy(defender.getId())) .collect(Collectors.toList()); - + if (controller.choosePile(outcome, attacker.getName() + ": attacking " + defender.getName(), leftLog, rightLog, game)) { filter.add(Predicates.not(Predicates.or(new AbilityPredicate(FlyingAbility.class), new PermanentInListPredicate(left)))); game.informPlayers(attacker.getLogName() + ": attacks left (" + defender.getLogName() + ")"); diff --git a/Mage.Sets/src/mage/cards/r/RangerClass.java b/Mage.Sets/src/mage/cards/r/RangerClass.java index ee3fa766655..b570eb499b8 100644 --- a/Mage.Sets/src/mage/cards/r/RangerClass.java +++ b/Mage.Sets/src/mage/cards/r/RangerClass.java @@ -47,7 +47,7 @@ public final class RangerClass extends CardImpl { // Whenever you attack, put a +1/+1 counter on target attacking creature. Ability ability = new AttacksWithCreaturesTriggeredAbility( - new AddCountersTargetEffect(CounterType.P1P1.createInstance()), 0 + new AddCountersTargetEffect(CounterType.P1P1.createInstance()), 1 ); ability.addTarget(new TargetAttackingCreature()); this.addAbility(new SimpleStaticAbility(new GainClassAbilitySourceEffect(ability, 2))); diff --git a/Mage.Sets/src/mage/cards/s/SparringRegimen.java b/Mage.Sets/src/mage/cards/s/SparringRegimen.java index ef7ef8a13e5..1132d415d9d 100644 --- a/Mage.Sets/src/mage/cards/s/SparringRegimen.java +++ b/Mage.Sets/src/mage/cards/s/SparringRegimen.java @@ -29,7 +29,7 @@ public final class SparringRegimen extends CardImpl { // Whenever you attack, put a +1/+1 counter on target attacking creature and untap it. Ability ability = new AttacksWithCreaturesTriggeredAbility( - new AddCountersTargetEffect(CounterType.P1P1.createInstance()), 0 + new AddCountersTargetEffect(CounterType.P1P1.createInstance()), 1 ); ability.addEffect(new UntapTargetEffect().setText("and untap it")); ability.addTarget(new TargetAttackingCreature()); diff --git a/Mage.Sets/src/mage/cards/t/ThoroughInvestigation.java b/Mage.Sets/src/mage/cards/t/ThoroughInvestigation.java index c1cbdd18371..bed81742c95 100644 --- a/Mage.Sets/src/mage/cards/t/ThoroughInvestigation.java +++ b/Mage.Sets/src/mage/cards/t/ThoroughInvestigation.java @@ -23,7 +23,7 @@ public final class ThoroughInvestigation extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}"); // Whenever you attack, investigate. - this.addAbility(new AttacksWithCreaturesTriggeredAbility(new InvestigateEffect(), 0)); + this.addAbility(new AttacksWithCreaturesTriggeredAbility(new InvestigateEffect(), 1)); // Whenever you sacrifice a Clue, venture into the dungeon. this.addAbility(new SacrificePermanentTriggeredAbility(new VentureIntoTheDungeonEffect(), filter)); diff --git a/Mage/src/main/java/mage/abilities/common/AttacksWithCreaturesTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/AttacksWithCreaturesTriggeredAbility.java index c1e48bd0199..70c7b35367c 100644 --- a/Mage/src/main/java/mage/abilities/common/AttacksWithCreaturesTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/AttacksWithCreaturesTriggeredAbility.java @@ -7,18 +7,15 @@ import mage.filter.StaticFilters; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.permanent.Permanent; import mage.util.CardUtil; -import java.util.UUID; - /** * @author Styxo */ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl { - private FilterCreaturePermanent filter; - private int minAttackers; + private final FilterCreaturePermanent filter; + private final int minAttackers; public AttacksWithCreaturesTriggeredAbility(Effect effect, int minAttackers) { this(effect, minAttackers, StaticFilters.FILTER_PERMANENT_CREATURES); @@ -52,28 +49,26 @@ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { - if (game.getCombat().getAttackingPlayerId().equals(getControllerId())) { - int attackerCount = 0; - for (UUID attackerId : game.getCombat().getAttackers()) { - Permanent attacker = game.getPermanent(attackerId); - if (filter.match(attacker, game)) { - attackerCount++; - } - } - return attackerCount >= minAttackers; - } - return false; + return isControlledBy(game.getCombat().getAttackingPlayerId()) + && game + .getCombat() + .getAttackers() + .stream() + .map(game::getPermanent) + .filter(permanent -> filter.match(permanent, sourceId, controllerId, game)) + .mapToInt(x -> 1).sum() > minAttackers; } @Override public String getTriggerPhrase() { - if (minAttackers == 0) { + if (minAttackers == 1) { return "Whenever you attack, "; } - StringBuilder sb = new StringBuilder("Whenever you attack with " + CardUtil.numberToText(minAttackers) + " or more "); + StringBuilder sb = new StringBuilder("Whenever you attack with "); + sb.append(CardUtil.numberToText(minAttackers)); + sb.append(" or more "); sb.append(filter.getMessage()); sb.append(", "); return sb.toString(); } - }