diff --git a/Mage.Sets/src/mage/sets/returntoravnica/RighteousAuthority.java b/Mage.Sets/src/mage/sets/returntoravnica/RighteousAuthority.java index ae2acafb4b..ad0b02b68c 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/RighteousAuthority.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/RighteousAuthority.java @@ -39,13 +39,19 @@ import mage.Constants.Zone; import mage.abilities.Ability; import mage.abilities.common.BeginningOfDrawTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.CardsInControllerHandCount; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.DrawCardControllerEffect; +import mage.abilities.effects.common.DrawCardTargetEffect; +import mage.abilities.effects.common.continious.BoostEnchantedEffect; import mage.abilities.effects.common.continious.BoostSourceEffect; import mage.abilities.effects.common.continious.GainAbilityAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -55,9 +61,6 @@ import mage.target.common.TargetCreaturePermanent; */ public class RighteousAuthority extends CardImpl { - static final String rule = "Enchanted creature gets +1/+1 for each card in its controller's hand"; - static final String rule2 = "At the beginning of the draw step of enchanted creature's controller, that player draws an additional card"; - public RighteousAuthority (UUID ownerId) { super(ownerId, 189, "Righteous Authority", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}{U}"); this.expansionSetCode = "RTR"; @@ -73,13 +76,11 @@ public class RighteousAuthority extends CardImpl { this.addAbility(ability); // Enchanted creature gets +1/+1 for each card in its controller's hand. - CardsInControllerHandCount boost = new CardsInControllerHandCount(); - Ability gainedAbility = new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostSourceEffect(boost, boost, Duration.WhileOnBattlefield)); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(gainedAbility, AttachmentType.AURA, Duration.WhileOnBattlefield, rule))); + CardsInEnchantedControllerHandCount boost = new CardsInEnchantedControllerHandCount(); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(boost, boost, Duration.WhileOnBattlefield))); // At the beginning of the draw step of enchanted creature's controller, that player draws an additional card. - Ability gainedAbility2 = new BeginningOfDrawTriggeredAbility(new DrawCardControllerEffect(1), TargetController.YOU, false); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(gainedAbility2, AttachmentType.AURA, Duration.WhileOnBattlefield, rule2))); + this.addAbility(new BeginningOfDrawTriggeredAbility(new DrawCardTargetEffect(1), TargetController.CONTROLLER_ATTACHED_TO, false)); } public RighteousAuthority (final RighteousAuthority card) { @@ -91,3 +92,38 @@ public class RighteousAuthority extends CardImpl { return new RighteousAuthority(this); } } + + +class CardsInEnchantedControllerHandCount implements DynamicValue { + @Override + public int calculate(Game game, Ability sourceAbility) { + if (sourceAbility != null) { + Permanent attachment = game.getPermanent(sourceAbility.getSourceId()); + if (attachment != null && attachment.getAttachedTo() != null) { + Permanent attachedTo = game.getPermanent(attachment.getAttachedTo()); + if (attachedTo != null) { + Player controller = game.getPlayer(attachedTo.getControllerId()); + if (controller != null) { + return controller.getHand().size(); + } + } + } + } + return 0; + } + + @Override + public DynamicValue clone() { + return new mage.abilities.dynamicvalue.common.CardsInControllerHandCount(); + } + + @Override + public String getMessage() { + return "card in its controller's hand"; + } + + @Override + public String toString() { + return "1"; + } +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/common/BeginningOfDrawTriggeredAbility.java b/Mage/src/mage/abilities/common/BeginningOfDrawTriggeredAbility.java index 8b9a5b489e..12f795cef1 100644 --- a/Mage/src/mage/abilities/common/BeginningOfDrawTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/BeginningOfDrawTriggeredAbility.java @@ -1,20 +1,22 @@ package mage.abilities.common; -import mage.Constants; +import mage.Constants.TargetController; +import mage.Constants.Zone; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; import mage.target.targetpointer.FixedTarget; public class BeginningOfDrawTriggeredAbility extends TriggeredAbilityImpl { - private Constants.TargetController targetController; + private TargetController targetController; - public BeginningOfDrawTriggeredAbility(Effect effect, Constants.TargetController targetController, boolean isOptional) { - this(Constants.Zone.BATTLEFIELD, effect, targetController, isOptional); + public BeginningOfDrawTriggeredAbility(Effect effect, TargetController targetController, boolean isOptional) { + this(Zone.BATTLEFIELD, effect, targetController, isOptional); } - public BeginningOfDrawTriggeredAbility(Constants.Zone zone, Effect effect, Constants.TargetController targetController, boolean isOptional) { + public BeginningOfDrawTriggeredAbility(Zone zone, Effect effect, TargetController targetController, boolean isOptional) { super(zone, effect, isOptional); this.targetController = targetController; } @@ -52,6 +54,19 @@ public class BeginningOfDrawTriggeredAbility extends TriggeredAbilityImpl