From 8e3ca7e5ca73acf921cb79421173f935dba0e271 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 11 Feb 2014 17:28:59 +0100 Subject: [PATCH] Added CantAttackControllerAttachedEffect. Minor formatting. --- .../mage/sets/theros/MedomaiTheAgeless.java | 4 +- .../effects/ReplacementEffectImpl.java | 1 + ...ct.java => CantAttackAllSourceEffect.java} | 13 ++- .../CantAttackControllerAttachedEffect.java | 109 ++++++++++++++++++ 4 files changed, 119 insertions(+), 8 deletions(-) rename Mage/src/mage/abilities/effects/common/combat/{CantAttackSourceEffect.java => CantAttackAllSourceEffect.java} (85%) create mode 100644 Mage/src/mage/abilities/effects/common/combat/CantAttackControllerAttachedEffect.java diff --git a/Mage.Sets/src/mage/sets/theros/MedomaiTheAgeless.java b/Mage.Sets/src/mage/sets/theros/MedomaiTheAgeless.java index 41c1a88ab31..df7cb8bbdb4 100644 --- a/Mage.Sets/src/mage/sets/theros/MedomaiTheAgeless.java +++ b/Mage.Sets/src/mage/sets/theros/MedomaiTheAgeless.java @@ -35,7 +35,7 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.Condition; import mage.abilities.decorator.ConditionalRestrictionEffect; import mage.abilities.effects.Effect; -import mage.abilities.effects.common.combat.CantAttackSourceEffect; +import mage.abilities.effects.common.combat.CantAttackAllSourceEffect; import mage.abilities.effects.common.turn.AddExtraTurnControllerEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; @@ -67,7 +67,7 @@ public class MedomaiTheAgeless extends CardImpl { // Whenever Medomai the Ageless deals combat damage to a player, take an extra turn after this one. this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new AddExtraTurnControllerEffect(), false)); // Medomai the Ageless can't attack during extra turns. - Effect effect = new ConditionalRestrictionEffect(new CantAttackSourceEffect(Duration.WhileOnBattlefield), ExtraTurnCondition.getInstance()); + Effect effect = new ConditionalRestrictionEffect(new CantAttackAllSourceEffect(Duration.WhileOnBattlefield), ExtraTurnCondition.getInstance()); effect.setText("{this} can't attack during extra turns"); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); } diff --git a/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java b/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java index ecdd0529ae3..c029d3c1e78 100644 --- a/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java +++ b/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java @@ -35,6 +35,7 @@ import mage.constants.Outcome; /** * * @author BetaSteward_at_googlemail.com + * @param */ public abstract class ReplacementEffectImpl> extends ContinuousEffectImpl implements ReplacementEffect { diff --git a/Mage/src/mage/abilities/effects/common/combat/CantAttackSourceEffect.java b/Mage/src/mage/abilities/effects/common/combat/CantAttackAllSourceEffect.java similarity index 85% rename from Mage/src/mage/abilities/effects/common/combat/CantAttackSourceEffect.java rename to Mage/src/mage/abilities/effects/common/combat/CantAttackAllSourceEffect.java index 7af3e74a6e6..bc35ae12b96 100644 --- a/Mage/src/mage/abilities/effects/common/combat/CantAttackSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/combat/CantAttackAllSourceEffect.java @@ -35,16 +35,17 @@ import mage.game.Game; import mage.game.permanent.Permanent; /** - * + * The source of this effect can't attack any opponent + * * @author BetaSteward_at_googlemail.com */ -public class CantAttackSourceEffect extends RestrictionEffect { +public class CantAttackAllSourceEffect extends RestrictionEffect { - public CantAttackSourceEffect(Duration duration) { + public CantAttackAllSourceEffect(Duration duration) { super(duration); } - public CantAttackSourceEffect(final CantAttackSourceEffect effect) { + public CantAttackAllSourceEffect(final CantAttackAllSourceEffect effect) { super(effect); } @@ -62,8 +63,8 @@ public class CantAttackSourceEffect extends RestrictionEffect implements MageSingleton { + + /** + * The creature this permanent is attached to can't attack the controller + * of the attachment nor it's plainswalkers + * + * @param attachmentType + */ + public CantAttackControllerAttachedEffect(AttachmentType attachmentType) { + super(Duration.WhileOnBattlefield, Outcome.Detriment); + if (attachmentType.equals(AttachmentType.AURA)) { + this.staticText = "Enchanted creature can't attack you or a planeswalker you control"; + } else { + this.staticText = "Equiped creature can't attack you or a planeswalker you control"; + } + } + + public CantAttackControllerAttachedEffect(final CantAttackControllerAttachedEffect effect) { + super(effect); + } + + @Override + public CantAttackControllerAttachedEffect copy() { + return new CantAttackControllerAttachedEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + Permanent sourcePermanent = game.getPermanent(source.getSourceId()); + Player attackingPlayer = game.getPlayer(event.getPlayerId()); + if (attackingPlayer != null && sourcePermanent != null) { + game.informPlayer(attackingPlayer, + new StringBuilder("You can't attack this player or his or her planeswalker, because the attacking creature is enchanted by ") + .append(sourcePermanent.getName()).append(".").toString()); + } + return true; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (event.getType() == EventType.DECLARE_ATTACKER) { + Permanent attachment = game.getPermanent(source.getSourceId()); + if (attachment != null && attachment.getAttachedTo() != null + && event.getSourceId().equals(attachment.getAttachedTo())) { + if (event.getTargetId().equals(source.getControllerId())) { + return true; + } + Permanent plainswalker = game.getPermanent(event.getTargetId()); + if (plainswalker != null && plainswalker.getControllerId().equals(source.getSourceId())) { + return true; + } + } + } + return false; + } + +}