From 8c8a73c791f5bd7f7a0b8b8787a94ad7ea7798de Mon Sep 17 00:00:00 2001 From: jesusjbr Date: Thu, 2 Aug 2018 23:14:23 +0200 Subject: [PATCH] Added effect to Xantcha, Sleeper Agent. Now this creature can't attack its owner or planeswalkers its owner controls. --- .../src/mage/cards/x/XantchaSleeperAgent.java | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/Mage.Sets/src/mage/cards/x/XantchaSleeperAgent.java b/Mage.Sets/src/mage/cards/x/XantchaSleeperAgent.java index 095cf0ec00d..a3aed39c2b4 100644 --- a/Mage.Sets/src/mage/cards/x/XantchaSleeperAgent.java +++ b/Mage.Sets/src/mage/cards/x/XantchaSleeperAgent.java @@ -7,6 +7,7 @@ import mage.abilities.common.*; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.Effect; +import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.InfoEffect; import mage.abilities.effects.common.LoseLifePermanentControllerEffect; @@ -42,10 +43,13 @@ public final class XantchaSleeperAgent extends CardImpl { this.addAbility(ability); // Xantcha attacks each combat if able and can’t attack its owner or planeswalkers its owner controls. - this.addAbility(new AttacksEachCombatStaticAbility()); + ability = new AttacksEachCombatStaticAbility(); + Effect effect = new XantchaSleeperAgentAttackRestrictionEffect(); + ability.addEffect(effect); + this.addAbility(ability); // {3}: Xantcha’s controller loses 2 life and you draw a card. Any player may activate this ability. - Effect effect = new LoseLifePermanentControllerEffect(2); + effect = new LoseLifePermanentControllerEffect(2); effect.setText("Xantcha’s controller loses 2 life"); SimpleActivatedAbility simpleAbility = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{3}")); @@ -95,4 +99,44 @@ class XantchaSleeperAgentChangeControlEffect extends ContinuousEffectImpl { } return false; } -} \ No newline at end of file +} + +class XantchaSleeperAgentAttackRestrictionEffect extends RestrictionEffect { + + XantchaSleeperAgentAttackRestrictionEffect() { + super(Duration.WhileOnBattlefield); + staticText = "and can't attack its owner or planeswalkers its owner controls."; + } + + XantchaSleeperAgentAttackRestrictionEffect(final XantchaSleeperAgentAttackRestrictionEffect effect) { + super(effect); + } + + @Override + public XantchaSleeperAgentAttackRestrictionEffect copy() { + return new XantchaSleeperAgentAttackRestrictionEffect(this); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + return true; + } + + @Override + public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + + boolean allowAttack = true; + UUID ownerPlayerId = source.getSourcePermanentIfItStillExists(game).getOwnerId(); + + if (defenderId.equals(ownerPlayerId)) { + allowAttack = false; + } + else { + Permanent planeswalker = game.getPermanent(defenderId); + if (planeswalker != null && planeswalker.isControlledBy(ownerPlayerId)) { + allowAttack = false; + } + } + return allowAttack; + } +}