From 874ff7179f9ec38dc7bfcf0aa05e4a4d86bc84db Mon Sep 17 00:00:00 2001 From: htrajan Date: Sat, 18 Apr 2020 13:13:02 -0700 Subject: [PATCH] -don't static import static filters -use existing choose color and gain protection from color attached effects -update naming and add null check for AttachedToCreatureSourceTriggeredAbility --- .../src/mage/cards/s/SanctuaryBlade.java | 18 +++-- Mage.Sets/src/mage/cards/v/VergeRangers.java | 10 ++- .../cards/single/c20/SanctuaryBladeTest.java | 2 +- ...chedToCreatureSourceTriggeredAbility.java} | 14 ++-- ...GainProtectionFromColorAttachedEffect.java | 67 ------------------- 5 files changed, 25 insertions(+), 86 deletions(-) rename Mage/src/main/java/mage/abilities/common/{AttachedToCreatureTriggeredAbility.java => AttachedToCreatureSourceTriggeredAbility.java} (60%) delete mode 100644 Mage/src/main/java/mage/abilities/effects/common/continuous/GainProtectionFromColorAttachedEffect.java diff --git a/Mage.Sets/src/mage/cards/s/SanctuaryBlade.java b/Mage.Sets/src/mage/cards/s/SanctuaryBlade.java index dc7ad03b19e..ffb42ebb7e0 100644 --- a/Mage.Sets/src/mage/cards/s/SanctuaryBlade.java +++ b/Mage.Sets/src/mage/cards/s/SanctuaryBlade.java @@ -1,15 +1,19 @@ package mage.cards.s; -import mage.abilities.common.AttachedToCreatureTriggeredAbility; +import mage.abilities.common.AttachedToCreatureSourceTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.Effect; +import mage.abilities.effects.common.ChooseColorEffect; import mage.abilities.effects.common.continuous.BoostEquippedEffect; -import mage.abilities.effects.common.continuous.GainProtectionFromColorAttachedEffect; +import mage.abilities.effects.keyword.ProtectionChosenColorAttachedEffect; import mage.abilities.keyword.EquipAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.Zone; import java.util.UUID; @@ -25,13 +29,15 @@ public final class SanctuaryBlade extends CardImpl { this.subtype.add(SubType.EQUIPMENT); // As Sanctuary Blade becomes attached to a creature, choose a color. - GainProtectionFromColorAttachedEffect protectionEffect = new GainProtectionFromColorAttachedEffect(Duration.WhileOnBattlefield); - this.addAbility(new AttachedToCreatureTriggeredAbility(protectionEffect, false)); + this.addAbility(new AttachedToCreatureSourceTriggeredAbility(new ChooseColorEffect(Outcome.Benefit), false)); - // Equipped creature gets +2/+0 and has protection from the last chosen color. + // Equipped creature gets +2/+0 Effect boostEffect = new BoostEquippedEffect(2, 0); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, boostEffect)); + // and has protection from the last chosen color + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ProtectionChosenColorAttachedEffect(false))); + // Equip {3} this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(3))); } diff --git a/Mage.Sets/src/mage/cards/v/VergeRangers.java b/Mage.Sets/src/mage/cards/v/VergeRangers.java index 78f0e166b51..f4b9228294b 100644 --- a/Mage.Sets/src/mage/cards/v/VergeRangers.java +++ b/Mage.Sets/src/mage/cards/v/VergeRangers.java @@ -11,14 +11,12 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Zone; +import mage.filter.StaticFilters; import mage.game.Game; import java.util.Comparator; import java.util.UUID; -import static mage.filter.StaticFilters.FILTER_CARD_LAND; -import static mage.filter.StaticFilters.FILTER_LAND; - /** * * @author htrajan @@ -56,7 +54,7 @@ public final class VergeRangers extends CardImpl { class VergeRangersEffect extends PlayTheTopCardEffect { public VergeRangersEffect() { - super(FILTER_CARD_LAND); + super(StaticFilters.FILTER_CARD_LAND); staticText = "As long as an opponent controls more lands than you, you may play lands from the top of your library."; } @@ -72,9 +70,9 @@ class VergeRangersEffect extends PlayTheTopCardEffect { @Override public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) { if (super.applies(objectId, affectedAbility, source, game, playerId)) { - int myLandCount = game.getBattlefield().countAll(FILTER_LAND, playerId, game); + int myLandCount = game.getBattlefield().countAll(StaticFilters.FILTER_LAND, playerId, game); int maxOpponentLandCount = game.getOpponents(playerId).stream() - .map(opponentId -> game.getBattlefield().countAll(FILTER_LAND, opponentId, game)) + .map(opponentId -> game.getBattlefield().countAll(StaticFilters.FILTER_LAND, opponentId, game)) .max(Comparator.naturalOrder()) .orElse(0); return maxOpponentLandCount > myLandCount; diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/c20/SanctuaryBladeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/c20/SanctuaryBladeTest.java index f13b7907a63..c5aee920341 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/c20/SanctuaryBladeTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/c20/SanctuaryBladeTest.java @@ -24,7 +24,7 @@ public class SanctuaryBladeTest extends CardTestPlayerBase { assertAllCommandsUsed(); assertPowerToughness(playerA, "Savai Sabertooth", 5, 1); - assertAbility(playerA, "Savai Sabertooth", new ProtectionAbility(new FilterCard("Black")), true); + assertAbility(playerA, "Savai Sabertooth", new ProtectionAbility(new FilterCard("black")), true); } } diff --git a/Mage/src/main/java/mage/abilities/common/AttachedToCreatureTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/AttachedToCreatureSourceTriggeredAbility.java similarity index 60% rename from Mage/src/main/java/mage/abilities/common/AttachedToCreatureTriggeredAbility.java rename to Mage/src/main/java/mage/abilities/common/AttachedToCreatureSourceTriggeredAbility.java index 8eff81ff624..1387a45d9cc 100644 --- a/Mage/src/main/java/mage/abilities/common/AttachedToCreatureTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/AttachedToCreatureSourceTriggeredAbility.java @@ -13,19 +13,21 @@ import static mage.constants.CardType.CREATURE; * * @author htrajan */ -public class AttachedToCreatureTriggeredAbility extends TriggeredAbilityImpl { +public class AttachedToCreatureSourceTriggeredAbility extends TriggeredAbilityImpl { - public AttachedToCreatureTriggeredAbility(Effect effect, boolean optional) { + public AttachedToCreatureSourceTriggeredAbility(Effect effect, boolean optional) { super(Zone.BATTLEFIELD, effect, optional); } - public AttachedToCreatureTriggeredAbility(final AttachedToCreatureTriggeredAbility ability) { + public AttachedToCreatureSourceTriggeredAbility(final AttachedToCreatureSourceTriggeredAbility ability) { super(ability); } @Override public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.ATTACHED && event.getSourceId().equals(this.getSourceId()); + return event.getType() == GameEvent.EventType.ATTACHED + && event.getSourceId() != null + && event.getSourceId().equals(this.getSourceId()); } @Override @@ -40,7 +42,7 @@ public class AttachedToCreatureTriggeredAbility extends TriggeredAbilityImpl { } @Override - public AttachedToCreatureTriggeredAbility copy() { - return new AttachedToCreatureTriggeredAbility(this); + public AttachedToCreatureSourceTriggeredAbility copy() { + return new AttachedToCreatureSourceTriggeredAbility(this); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainProtectionFromColorAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainProtectionFromColorAttachedEffect.java deleted file mode 100644 index c54d9bbf844..00000000000 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainProtectionFromColorAttachedEffect.java +++ /dev/null @@ -1,67 +0,0 @@ - -package mage.abilities.effects.common.continuous; - -import mage.abilities.Ability; -import mage.abilities.keyword.ProtectionAbility; -import mage.choices.ChoiceColor; -import mage.constants.Duration; -import mage.filter.FilterCard; -import mage.filter.predicate.mageobject.ColorPredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; - -/** - * - * @author htrajan - */ -public class GainProtectionFromColorAttachedEffect extends GainAbilitySourceEffect { - - FilterCard protectionFilter; - - public GainProtectionFromColorAttachedEffect(Duration duration) { - super(new ProtectionAbility(new FilterCard()), duration); - protectionFilter = (FilterCard) ((ProtectionAbility) ability).getFilter(); - } - - public GainProtectionFromColorAttachedEffect(final GainProtectionFromColorAttachedEffect effect) { - super(effect); - this.protectionFilter = effect.protectionFilter.copy(); - } - - @Override - public GainProtectionFromColorAttachedEffect copy() { - return new GainProtectionFromColorAttachedEffect(this); - } - - @Override - public void init(Ability source, Game game) { - super.init(source, game); - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - ChoiceColor colorChoice = new ChoiceColor(true); - colorChoice.setMessage("Choose color for protection ability"); - if (controller.choose(outcome, colorChoice, game)) { - game.informPlayers("Choosen color: " + colorChoice.getColor()); - protectionFilter.add(new ColorPredicate(colorChoice.getColor())); - protectionFilter.setMessage(colorChoice.getChoice()); - ((ProtectionAbility) ability).setFilter(protectionFilter); - return; - } - } - discard(); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null && permanent.getAttachedTo() != null) { - Permanent attachedPermanent = game.getPermanent(permanent.getAttachedTo()); - attachedPermanent.addAbility(ability, source.getSourceId(), game); - } else { - // the source permanent is no longer on the battlefield, or it is not attached -- effect can be discarded - discard(); - } - return true; - } -}