diff --git a/Mage.Sets/src/mage/cards/b/BoundByMoonsilver.java b/Mage.Sets/src/mage/cards/b/BoundByMoonsilver.java index 1ecccce788..d517e063c0 100644 --- a/Mage.Sets/src/mage/cards/b/BoundByMoonsilver.java +++ b/Mage.Sets/src/mage/cards/b/BoundByMoonsilver.java @@ -1,19 +1,19 @@ - package mage.cards.b; import mage.abilities.Ability; import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.SacrificeTargetCost; -import mage.abilities.effects.Effect; +import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.common.AttachEffect; -import mage.abilities.effects.common.CantAttackBlockTransformAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; import mage.filter.common.FilterControlledPermanent; import mage.filter.predicate.mageobject.AnotherPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetCreaturePermanent; @@ -43,10 +43,8 @@ public final class BoundByMoonsilver extends CardImpl { Ability ability = new EnchantAbility(auraTarget); this.addAbility(ability); - // Enchanted permanent can't attack, block, or transform. - Effect effect = new CantAttackBlockTransformAttachedEffect(); - effect.setText("Enchanted creature can't attack, block, or transform."); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); + // Enchanted creature can't attack, block, or transform. + this.addAbility(new SimpleStaticAbility(new BoundByMoonsilverEffect())); // Sacrifice another permanent: Attach Bound by Moonsilver to target creature. Activate this ability only any time you could cast a sorcery and only once each turn. LimitedTimesPerTurnActivatedAbility limitedAbility = new LimitedTimesPerTurnActivatedAbility(Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "Attach {this} to target creature"), @@ -65,3 +63,40 @@ public final class BoundByMoonsilver extends CardImpl { return new BoundByMoonsilver(this); } } + +class BoundByMoonsilverEffect extends RestrictionEffect { + + public BoundByMoonsilverEffect() { + super(Duration.WhileOnBattlefield); + staticText = "enchanted creature can't attack, block, or transform"; + } + + private BoundByMoonsilverEffect(final BoundByMoonsilverEffect effect) { + super(effect); + } + + @Override + public BoundByMoonsilverEffect copy() { + return new BoundByMoonsilverEffect(this); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + return permanent.getAttachments().contains(source.getSourceId()); + } + + @Override + public boolean canAttack(Game game, boolean canUseChooseDialogs) { + return false; + } + + @Override + public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game, boolean canUseChooseDialogs) { + return false; + } + + @Override + public boolean canTransform(Game game, boolean canUseChooseDialogs) { + return false; + } +} diff --git a/Mage.Sets/src/mage/cards/i/Immerwolf.java b/Mage.Sets/src/mage/cards/i/Immerwolf.java index 386bddbde8..823799f54c 100644 --- a/Mage.Sets/src/mage/cards/i/Immerwolf.java +++ b/Mage.Sets/src/mage/cards/i/Immerwolf.java @@ -1,21 +1,21 @@ - package mage.cards.i; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.common.continuous.BoostControlledEffect; import mage.abilities.keyword.IntimidateAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.SubType; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.Predicates; import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; /** @@ -40,10 +40,10 @@ public final class Immerwolf extends CardImpl { this.addAbility(IntimidateAbility.getInstance()); // Other Wolf and Werewolf creatures you control get +1/+1. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostControlledEffect(1, 1, Duration.WhileOnBattlefield, filter, true))); + this.addAbility(new SimpleStaticAbility(new BoostControlledEffect(1, 1, Duration.WhileOnBattlefield, filter, true))); // Non-Human Werewolves you control can't transform. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ImmerwolfEffect())); + this.addAbility(new SimpleStaticAbility(new ImmerwolfEffect())); } @@ -57,21 +57,20 @@ public final class Immerwolf extends CardImpl { } } -class ImmerwolfEffect extends ContinuousRuleModifyingEffectImpl { +class ImmerwolfEffect extends RestrictionEffect { - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); + private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(SubType.WEREWOLF); static { - filter.add(SubType.WEREWOLF.getPredicate()); filter.add(Predicates.not(SubType.HUMAN.getPredicate())); } public ImmerwolfEffect() { - super(Duration.WhileOnBattlefield, Outcome.Detriment); + super(Duration.WhileOnBattlefield); staticText = "Non-Human Werewolves you control can't transform"; } - public ImmerwolfEffect(final ImmerwolfEffect effect) { + private ImmerwolfEffect(final ImmerwolfEffect effect) { super(effect); } @@ -81,15 +80,12 @@ class ImmerwolfEffect extends ContinuousRuleModifyingEffectImpl { } @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.TRANSFORM; + public boolean applies(Permanent permanent, Ability source, Game game) { + return filter.match(permanent, source.getControllerId(), source, game); } - + @Override - public boolean applies(GameEvent event, Ability source, Game game) { - Permanent permanent = game.getPermanent(event.getTargetId()); - return permanent != null && - permanent.isControlledBy(source.getControllerId()) && - filter.match(permanent, game) ; + public boolean canTransform(Game game, boolean canUseChooseDialogs) { + return false; } } diff --git a/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java b/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java index 54a873fb9c..db448b7d38 100644 --- a/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java @@ -98,8 +98,7 @@ public abstract class RestrictionEffect extends ContinuousEffectImpl { return true; } - public boolean canTransform(Permanent permanent, Ability source, Game game, boolean canUseChooseDialogs) { + public boolean canTransform(Game game, boolean canUseChooseDialogs) { return true; } - } diff --git a/Mage/src/main/java/mage/abilities/effects/common/CantAttackBlockTransformAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/CantAttackBlockTransformAttachedEffect.java deleted file mode 100644 index 72e1747487..0000000000 --- a/Mage/src/main/java/mage/abilities/effects/common/CantAttackBlockTransformAttachedEffect.java +++ /dev/null @@ -1,52 +0,0 @@ -package mage.abilities.effects.common; - -import mage.abilities.Ability; -import mage.abilities.effects.RestrictionEffect; -import mage.constants.Duration; -import mage.game.Game; -import mage.game.permanent.Permanent; - -/** - * @author halljared - */ -public class CantAttackBlockTransformAttachedEffect extends RestrictionEffect { - - public CantAttackBlockTransformAttachedEffect() { - super(Duration.WhileOnBattlefield); - staticText = "Enchanted creature can't attack, block, or transform."; - } - - public CantAttackBlockTransformAttachedEffect(final CantAttackBlockTransformAttachedEffect effect) { - super(effect); - } - - @Override - public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - return permanent.getId().equals(enchantment.getAttachedTo()); - } - return false; - } - - @Override - public boolean canAttack(Game game, boolean canUseChooseDialogs) { - return false; - } - - @Override - public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game, boolean canUseChooseDialogs) { - return false; - } - - @Override - public boolean canTransform(Permanent permanent, Ability source, Game game, boolean canUseChooseDialogs) { - return false; - } - - @Override - public CantAttackBlockTransformAttachedEffect copy() { - return new CantAttackBlockTransformAttachedEffect(this); - } - -} diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/AttacksIfAbleAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/AttacksIfAbleAttachedEffect.java index 329f0f8353..f5eaf386ff 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/AttacksIfAbleAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/AttacksIfAbleAttachedEffect.java @@ -1,5 +1,3 @@ - - package mage.abilities.effects.common.combat; import mage.abilities.Ability; @@ -32,9 +30,7 @@ public class AttacksIfAbleAttachedEffect extends RequirementEffect { @Override public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent attachment = game.getPermanent(source.getSourceId()); - return attachment != null && attachment.getAttachedTo() != null - && permanent.getId().equals(attachment.getAttachedTo()); + return permanent.getAttachments().contains(source.getSourceId()); } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/BlocksIfAbleAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/BlocksIfAbleAttachedEffect.java index 635d8f865f..dc41a79222 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/BlocksIfAbleAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/BlocksIfAbleAttachedEffect.java @@ -29,9 +29,7 @@ public class BlocksIfAbleAttachedEffect extends RequirementEffect { @Override public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent attachment = game.getPermanent(source.getSourceId()); - return attachment != null && attachment.getAttachedTo() != null - && permanent.getId().equals(attachment.getAttachedTo()); + return permanent.getAttachments().contains(source.getSourceId()); } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackAloneAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackAloneAttachedEffect.java index 25c592c856..a7589bd722 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackAloneAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackAloneAttachedEffect.java @@ -33,8 +33,6 @@ public class CantAttackAloneAttachedEffect extends RestrictionEffect { @Override public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent attachment = game.getPermanent(source.getSourceId()); - return attachment != null && attachment.getAttachedTo() != null - && permanent.getId().equals(attachment.getAttachedTo()); + return permanent.getAttachments().contains(source.getSourceId()); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackBlockAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackBlockAttachedEffect.java index 883e89d76d..e52b3cd5b6 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackBlockAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackBlockAttachedEffect.java @@ -24,9 +24,7 @@ public class CantAttackBlockAttachedEffect extends RestrictionEffect { @Override public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent attachment = game.getPermanent(source.getSourceId()); - return attachment != null && attachment.getAttachedTo() != null - && permanent.getId().equals(attachment.getAttachedTo()); + return permanent.getAttachments().contains(source.getSourceId()); } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantBeBlockedAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantBeBlockedAttachedEffect.java index dfe28e5b50..4168f3614b 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantBeBlockedAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantBeBlockedAttachedEffect.java @@ -33,8 +33,6 @@ public class CantBeBlockedAttachedEffect extends RestrictionEffect { @Override public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent attachment = game.getPermanent(source.getSourceId()); - return attachment != null - && attachment.isAttachedTo(permanent.getId()); + return permanent.getAttachments().contains(source.getSourceId()); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantBlockActivateAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantBlockActivateAttachedEffect.java index 53e9a16e0d..fcbbc3a3e0 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantBlockActivateAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantBlockActivateAttachedEffect.java @@ -22,11 +22,7 @@ public class CantBlockActivateAttachedEffect extends RestrictionEffect { @Override public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - return permanent.getId().equals(enchantment.getAttachedTo()); - } - return false; + return permanent.getAttachments().contains(source.getSourceId()); } @Override @@ -43,5 +39,4 @@ public class CantBlockActivateAttachedEffect extends RestrictionEffect { public CantBlockActivateAttachedEffect copy() { return new CantBlockActivateAttachedEffect(this); } - } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantBlockAttackActivateAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantBlockAttackActivateAttachedEffect.java index e30263e223..b706bbcc9c 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantBlockAttackActivateAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantBlockAttackActivateAttachedEffect.java @@ -26,11 +26,7 @@ public class CantBlockAttackActivateAttachedEffect extends RestrictionEffect { @Override public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - return permanent.getId().equals(enchantment.getAttachedTo()); - } - return false; + return permanent.getAttachments().contains(source.getSourceId()); } @Override diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index 28229c7cf2..f41bceb0ec 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -303,7 +303,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { if (!entry.getKey().canUseActivatedAbilities(this, ability, game, false)) { restrictHints.add(HintUtils.prepareText("Can't use activated abilities" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT)); } - if (!entry.getKey().canTransform(this, ability, game, false)) { + if (!entry.getKey().canTransform(game, false)) { restrictHints.add(HintUtils.prepareText("Can't transform" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT)); } } @@ -599,6 +599,15 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { || this.getAbilities().containsClass(NightboundAbility.class); } + private boolean checkTransformRestrictionEffects(Game game) { + for (Map.Entry> entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) { + if (!entry.getKey().canTransform(game, true)) { + return false; + } + } + return true; + } + private Card getOtherFace() { return transformed ? this.getMainCard() : this.getMainCard().getSecondCardFace(); } @@ -608,6 +617,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { if (!this.isTransformable() || (!ignoreDayNight && this.checkDayNightBound()) || this.getOtherFace().isInstantOrSorcery() + || !this.checkTransformRestrictionEffects(game) || (source != null && !source.checkTransformCount(this, game)) || this.replaceEvent(EventType.TRANSFORM, game)) { return false;