From 3ac82adb4de5d6426fde2e78eca02ed4667f87e3 Mon Sep 17 00:00:00 2001 From: "Alex W. Jackson" Date: Sat, 18 Dec 2021 19:53:27 -0500 Subject: [PATCH] Fix Nivix Cyclops and clean up some similar cards --- Mage.Sets/src/mage/cards/m/MobileFort.java | 10 +--- Mage.Sets/src/mage/cards/n/NivixCyclops.java | 41 +------------ Mage.Sets/src/mage/cards/n/NoviceKnight.java | 53 +++++++---------- .../src/mage/cards/o/OgreJailbreaker.java | 59 +++++-------------- Mage.Sets/src/mage/cards/r/RovingKeep.java | 3 +- Mage.Sets/src/mage/cards/w/WalkingWall.java | 3 +- Mage.Sets/src/mage/cards/w/WallOfWonder.java | 2 +- ...ThoughItDidntHaveDefenderSourceEffect.java | 6 +- 8 files changed, 48 insertions(+), 129 deletions(-) diff --git a/Mage.Sets/src/mage/cards/m/MobileFort.java b/Mage.Sets/src/mage/cards/m/MobileFort.java index deab260e39..52b731cd97 100644 --- a/Mage.Sets/src/mage/cards/m/MobileFort.java +++ b/Mage.Sets/src/mage/cards/m/MobileFort.java @@ -1,12 +1,10 @@ - package mage.cards.m; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; -import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.Effect; +import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.common.combat.CanAttackAsThoughItDidntHaveDefenderSourceEffect; import mage.abilities.effects.common.continuous.BoostSourceEffect; import mage.abilities.keyword.DefenderAbility; @@ -33,10 +31,8 @@ public final class MobileFort extends CardImpl { this.addAbility(DefenderAbility.getInstance()); // {3}: Mobile Fort gets +3/-1 until end of turn and can attack this turn as though it didn't have defender. Activate this ability only once each turn. - Effect effect = new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.EndOfTurn); - effect.setText("and can attack this turn as though it didn't have defender"); - Ability ability = new LimitedTimesPerTurnActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(3, -1, Duration.EndOfTurn), new ManaCostsImpl("{3}")); - ability.addEffect(effect); + Ability ability = new LimitedTimesPerTurnActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(3, -1, Duration.EndOfTurn), new GenericManaCost(3)); + ability.addEffect(new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.EndOfTurn, "and")); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/n/NivixCyclops.java b/Mage.Sets/src/mage/cards/n/NivixCyclops.java index 9b7a476c0b..9c9bd72bc2 100644 --- a/Mage.Sets/src/mage/cards/n/NivixCyclops.java +++ b/Mage.Sets/src/mage/cards/n/NivixCyclops.java @@ -4,19 +4,15 @@ import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SpellCastControllerTriggeredAbility; -import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.common.combat.CanAttackAsThoughItDidntHaveDefenderSourceEffect; import mage.abilities.effects.common.continuous.BoostSourceEffect; import mage.abilities.keyword.DefenderAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.AsThoughEffectType; import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -40,9 +36,8 @@ public final class NivixCyclops extends CardImpl { StaticFilters.FILTER_SPELL_AN_INSTANT_OR_SORCERY, false ); - ability.addEffect(new AsThoughNoDefenderEffect()); + ability.addEffect(new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.EndOfTurn, "and")); this.addAbility(ability); - } private NivixCyclops(final NivixCyclops card) { @@ -54,35 +49,3 @@ public final class NivixCyclops extends CardImpl { return new NivixCyclops(this); } } - -class AsThoughNoDefenderEffect extends AsThoughEffectImpl { - - public AsThoughNoDefenderEffect() { - super(AsThoughEffectType.ATTACK, Duration.EndOfTurn, Outcome.Benefit); - staticText = "and it can attack as though it didn't have defender"; - } - - public AsThoughNoDefenderEffect(final AsThoughNoDefenderEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public AsThoughNoDefenderEffect copy() { - return new AsThoughNoDefenderEffect(this); - } - - @Override - public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) { - Permanent nivixCyclops = game.getPermanent(source.getSourceId()); - if (nivixCyclops != null - && nivixCyclops.getAbilities().containsKey(DefenderAbility.getInstance().getId())) { - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/n/NoviceKnight.java b/Mage.Sets/src/mage/cards/n/NoviceKnight.java index 717ed56ba8..f11ae24013 100644 --- a/Mage.Sets/src/mage/cards/n/NoviceKnight.java +++ b/Mage.Sets/src/mage/cards/n/NoviceKnight.java @@ -4,15 +4,16 @@ import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.AsThoughEffectImpl; -import mage.constants.SubType; +import mage.abilities.condition.Condition; +import mage.abilities.decorator.ConditionalAsThoughEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.combat.CanAttackAsThoughItDidntHaveDefenderSourceEffect; import mage.abilities.keyword.DefenderAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.AsThoughEffectType; import mage.constants.CardType; +import mage.constants.SubType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; @@ -35,9 +36,11 @@ public final class NoviceKnight extends CardImpl { this.addAbility(DefenderAbility.getInstance()); // As long as Novice Knight is enchanted or equipped, it can attack as though it didn't have defender. - this.addAbility(new SimpleStaticAbility( - Zone.BATTLEFIELD, new NoviceKnightEffect() - )); + Effect effect = new ConditionalAsThoughEffect( + new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.WhileOnBattlefield), + EnchantedOrEquippedSourceCondition.instance); + effect.setText("As long as {this} is enchanted or equipped, it can attack as though it didn't have defender"); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); } private NoviceKnight(final NoviceKnight card) { @@ -50,44 +53,28 @@ public final class NoviceKnight extends CardImpl { } } -class NoviceKnightEffect extends AsThoughEffectImpl { +enum EnchantedOrEquippedSourceCondition implements Condition { - public NoviceKnightEffect() { - super(AsThoughEffectType.ATTACK, Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = "As long as {this} is enchanted or equipped, " - + "it can attack as though it didn't have defender."; - } - - public NoviceKnightEffect(final NoviceKnightEffect effect) { - super(effect); - } + instance; @Override public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public NoviceKnightEffect copy() { - return new NoviceKnightEffect(this); - } - - @Override - public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - if (!objectId.equals(source.getSourceId())) { - return false; - } Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId()); if (permanent != null) { for (UUID uuid : permanent.getAttachments()) { Permanent attached = game.getBattlefield().getPermanent(uuid); if (attached != null - && (attached.hasSubtype(SubType.EQUIPMENT, game) - || attached.hasSubtype(SubType.AURA, game))) { - return true; + && (attached.isEnchantment(game) + || attached.hasSubtype(SubType.EQUIPMENT, game))) { + return true; } } } return false; } + + @Override + public String toString() { + return "{this} is enchanted or equipped"; + } } diff --git a/Mage.Sets/src/mage/cards/o/OgreJailbreaker.java b/Mage.Sets/src/mage/cards/o/OgreJailbreaker.java index 7087ecef89..63d1d29377 100644 --- a/Mage.Sets/src/mage/cards/o/OgreJailbreaker.java +++ b/Mage.Sets/src/mage/cards/o/OgreJailbreaker.java @@ -1,18 +1,17 @@ - package mage.cards.o; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition; -import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.decorator.ConditionalAsThoughEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.combat.CanAttackAsThoughItDidntHaveDefenderSourceEffect; import mage.abilities.keyword.DefenderAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.filter.FilterPermanent; -import mage.game.Game; /** * @@ -20,6 +19,12 @@ import mage.game.Game; */ public final class OgreJailbreaker extends CardImpl { + private static final FilterPermanent filter = new FilterPermanent("Gate"); + + static { + filter.add(SubType.GATE.getPredicate()); + } + public OgreJailbreaker(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{B}"); this.subtype.add(SubType.OGRE); @@ -30,8 +35,13 @@ public final class OgreJailbreaker extends CardImpl { // Defender this.addAbility(DefenderAbility.getInstance()); + // Ogre Jailbreaker can attack as though it didn't have defender as long as you control a Gate. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new OgreJailbreakerEffect())); + Effect effect = new ConditionalAsThoughEffect( + new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.WhileOnBattlefield), + new PermanentsOnTheBattlefieldCondition(filter)); + effect.setText("{this} can attack as though it didn't have defender as long as you control a Gate"); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); } @@ -44,42 +54,3 @@ public final class OgreJailbreaker extends CardImpl { return new OgreJailbreaker(this); } } - -class OgreJailbreakerEffect extends AsThoughEffectImpl { - - private static final FilterPermanent filter = new FilterPermanent(); - private PermanentsOnTheBattlefieldCondition gateCondition; - static { - filter.add(SubType.GATE.getPredicate()); - } - - public OgreJailbreakerEffect() { - super(AsThoughEffectType.ATTACK, Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = "{this} can attack as though it didn't have defender as long as you control a Gate"; - gateCondition = new PermanentsOnTheBattlefieldCondition(filter); - } - - public OgreJailbreakerEffect(final OgreJailbreakerEffect effect) { - super(effect); - this.gateCondition = effect.gateCondition; - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public OgreJailbreakerEffect copy() { - return new OgreJailbreakerEffect(this); - } - - @Override - public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) { - if (sourceId.equals(source.getSourceId()) && gateCondition.apply(game, source)) { - return true; - } - return false; - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/r/RovingKeep.java b/Mage.Sets/src/mage/cards/r/RovingKeep.java index 8006368aa0..204524c59d 100644 --- a/Mage.Sets/src/mage/cards/r/RovingKeep.java +++ b/Mage.Sets/src/mage/cards/r/RovingKeep.java @@ -40,8 +40,7 @@ public final class RovingKeep extends CardImpl { ability.addEffect(new GainAbilitySourceEffect( TrampleAbility.getInstance(), Duration.EndOfTurn ).setText("and gains trample until end of turn")); - ability.addEffect(new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.EndOfTurn) - .setText("It can attack this turn as though it didn't have defender")); + ability.addEffect(new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.EndOfTurn, "it")); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/w/WalkingWall.java b/Mage.Sets/src/mage/cards/w/WalkingWall.java index 1c4c0bbe9b..0a76eee590 100644 --- a/Mage.Sets/src/mage/cards/w/WalkingWall.java +++ b/Mage.Sets/src/mage/cards/w/WalkingWall.java @@ -1,4 +1,3 @@ - package mage.cards.w; import java.util.UUID; @@ -33,7 +32,7 @@ public final class WalkingWall extends CardImpl { // {3}: Walking Wall gets +3/-1 until end of turn and can attack this turn as though it didn't have defender. Activate this ability only once each turn. Ability ability = new LimitedTimesPerTurnActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(3, -1, Duration.EndOfTurn), new GenericManaCost(3)); - ability.addEffect(new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.EndOfTurn)); + ability.addEffect(new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.EndOfTurn, "and")); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/w/WallOfWonder.java b/Mage.Sets/src/mage/cards/w/WallOfWonder.java index ccdc5b62ea..e4c67d6ca4 100644 --- a/Mage.Sets/src/mage/cards/w/WallOfWonder.java +++ b/Mage.Sets/src/mage/cards/w/WallOfWonder.java @@ -34,7 +34,7 @@ public final class WallOfWonder extends CardImpl { // {2}{U}{U}: Wall of Wonder gets +4/-4 until end of turn and can attack this turn as though it didn't have defender. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(4, -4, Duration.EndOfTurn), new ManaCostsImpl("{2}{U}{U}")); - ability.addEffect(new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.EndOfTurn)); + ability.addEffect(new CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration.EndOfTurn, "and")); this.addAbility(ability); } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CanAttackAsThoughItDidntHaveDefenderSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CanAttackAsThoughItDidntHaveDefenderSourceEffect.java index 40e19ce726..3ff4271d8e 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CanAttackAsThoughItDidntHaveDefenderSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CanAttackAsThoughItDidntHaveDefenderSourceEffect.java @@ -16,8 +16,12 @@ import mage.game.Game; public class CanAttackAsThoughItDidntHaveDefenderSourceEffect extends AsThoughEffectImpl { public CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration duration) { + this(duration, "{this}"); + } + + public CanAttackAsThoughItDidntHaveDefenderSourceEffect(Duration duration, String description) { super(AsThoughEffectType.ATTACK, duration, Outcome.Benefit); - staticText = "{this} can attack " + staticText = description + " can attack " + (duration == Duration.EndOfTurn ? "this turn " : "") + "as though it didn't have defender"; }