From 44559371587d8c15e696e23c8f6fa519e8dcf3e2 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sun, 24 Jun 2018 18:21:16 -0400 Subject: [PATCH] fixed Novice Knight not working correctly --- Mage.Sets/src/mage/cards/n/NoviceKnight.java | 66 +++++++++++++++----- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/Mage.Sets/src/mage/cards/n/NoviceKnight.java b/Mage.Sets/src/mage/cards/n/NoviceKnight.java index c7fb1e9885..1a40f02fc3 100644 --- a/Mage.Sets/src/mage/cards/n/NoviceKnight.java +++ b/Mage.Sets/src/mage/cards/n/NoviceKnight.java @@ -2,19 +2,20 @@ package mage.cards.n; import java.util.UUID; import mage.MageInt; +import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.OrCondition; -import mage.abilities.condition.common.EnchantedSourceCondition; -import mage.abilities.condition.common.EquippedSourceCondition; -import mage.abilities.decorator.ConditionalContinuousEffect; -import mage.abilities.effects.common.combat.CanAttackAsThoughItDidntHaveDefenderSourceEffect; +import mage.abilities.effects.AsThoughEffectImpl; import mage.constants.SubType; import mage.abilities.keyword.DefenderAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.constants.AsThoughEffectType; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Outcome; import mage.constants.Zone; +import mage.game.Game; +import mage.game.permanent.Permanent; /** * @@ -35,18 +36,7 @@ public final class NoviceKnight extends CardImpl { // 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 ConditionalContinuousEffect( - new CanAttackAsThoughItDidntHaveDefenderSourceEffect( - Duration.WhileOnBattlefield - ), - new OrCondition( - EquippedSourceCondition.instance, - new EnchantedSourceCondition() - ), - "As long as {this} is enchanted or equipped, " - + "it can attack as though it didn't have defender." - ) + Zone.BATTLEFIELD, new NoviceKnightEffect() )); } @@ -59,3 +49,45 @@ public final class NoviceKnight extends CardImpl { return new NoviceKnight(this); } } + +class NoviceKnightEffect extends AsThoughEffectImpl { + + 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); + } + + @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; + } + } + } + return false; + } +}