diff --git a/Mage.Sets/src/mage/cards/s/ScourgeOfValkas.java b/Mage.Sets/src/mage/cards/s/ScourgeOfValkas.java index e108894cfc3..26ca584cc72 100644 --- a/Mage.Sets/src/mage/cards/s/ScourgeOfValkas.java +++ b/Mage.Sets/src/mage/cards/s/ScourgeOfValkas.java @@ -33,20 +33,22 @@ import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldControlledTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; -import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continuous.BoostSourceEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Outcome; import mage.constants.SubType; import mage.constants.Zone; -import mage.filter.common.FilterControlledCreaturePermanent; +import mage.filter.FilterPermanent; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.mageobject.SubtypePredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.common.TargetAnyTarget; /** @@ -56,17 +58,15 @@ import mage.target.common.TargetAnyTarget; public class ScourgeOfValkas extends CardImpl { private final static FilterCreaturePermanent filter = new FilterCreaturePermanent("{this} or another Dragon"); - private final static FilterControlledCreaturePermanent filter2 = new FilterControlledCreaturePermanent("Dragons you control"); static { filter.add(new SubtypePredicate(SubType.DRAGON)); - filter2.add(new SubtypePredicate(SubType.DRAGON)); } - + private static final String rule = "Whenever {this} or another Dragon enters the battlefield under your control, it deals X damage to any target, where X is the number of Dragons you control."; public ScourgeOfValkas(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{R}{R}{R}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{R}{R}{R}"); this.subtype.add(SubType.DRAGON); this.color.setRed(true); @@ -77,8 +77,7 @@ public class ScourgeOfValkas extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // Whenever Scourge of Valkas or another Dragon enters the battlefield under your control, it deals X damage to any target, where X is the number of Dragons you control. - DynamicValue dragons = new PermanentsOnBattlefieldCount(filter2); - Ability ability = new EntersBattlefieldControlledTriggeredAbility(Zone.BATTLEFIELD, new DamageTargetEffect(dragons), filter, false, rule); + Ability ability = new EntersBattlefieldControlledTriggeredAbility(Zone.BATTLEFIELD, new ScourgeOfValkasDamageEffect(), filter, false, rule); ability.addTarget(new TargetAnyTarget()); this.addAbility(ability); @@ -96,3 +95,45 @@ public class ScourgeOfValkas extends CardImpl { return new ScourgeOfValkas(this); } } + +class ScourgeOfValkasDamageEffect extends OneShotEffect { + + public ScourgeOfValkasDamageEffect() { + super(Outcome.Damage); + this.staticText = "it deals X damage to any target, where X is the number of Dragons you control"; + } + + public ScourgeOfValkasDamageEffect(final ScourgeOfValkasDamageEffect effect) { + super(effect); + } + + @Override + public ScourgeOfValkasDamageEffect copy() { + return new ScourgeOfValkasDamageEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + Permanent enteringDragon = (Permanent) getValue("permanentEnteringBattlefield"); + if (controller != null && enteringDragon != null) { + FilterPermanent filter = new FilterPermanent(); + filter.add(new SubtypePredicate(SubType.DRAGON)); + int dragons = game.getBattlefield().countAll(filter, source.getControllerId(), game); + if (dragons > 0) { + Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); + if (permanent != null) { + permanent.damage(dragons, enteringDragon.getId(), game, false, true); + } else { + Player player = game.getPlayer(getTargetPointer().getFirst(game, source)); + if (player != null + && player.isInGame()) { + player.damage(dragons, enteringDragon.getId(), game, false, true); + } + } + } + return true; + } + return false; + } +}