diff --git a/Mage.Sets/src/mage/cards/r/RecklessEmbermage.java b/Mage.Sets/src/mage/cards/r/RecklessEmbermage.java index 9446db91015..4605538e0c5 100644 --- a/Mage.Sets/src/mage/cards/r/RecklessEmbermage.java +++ b/Mage.Sets/src/mage/cards/r/RecklessEmbermage.java @@ -1,20 +1,18 @@ - package mage.cards.r; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.common.DamageSelfEffect; -import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.DamageTargetAndSelfEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; import mage.target.common.TargetAnyTarget; +import java.util.UUID; + /** * * @author Quercitron @@ -30,8 +28,7 @@ public final class RecklessEmbermage extends CardImpl { this.toughness = new MageInt(2); // {1}{R}: Reckless Embermage deals 1 damage to any target and 1 damage to itself. - Ability ability = new SimpleActivatedAbility(new DamageTargetEffect(1), new ManaCostsImpl<>("{1}{R}")); - ability.addEffect(new DamageSelfEffect(1).setText("and 1 damage to itself")); + Ability ability = new SimpleActivatedAbility(new DamageTargetAndSelfEffect(1), new ManaCostsImpl<>("{1}{R}")); ability.addTarget(new TargetAnyTarget()); this.addAbility(ability); } diff --git a/Mage/src/main/java/mage/abilities/effects/common/DamageTargetAndSelfEffect.java b/Mage/src/main/java/mage/abilities/effects/common/DamageTargetAndSelfEffect.java new file mode 100644 index 00000000000..ea7bc7c38ea --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/DamageTargetAndSelfEffect.java @@ -0,0 +1,77 @@ +package mage.abilities.effects.common; + +import mage.abilities.Ability; +import mage.abilities.Mode; +import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +import java.util.UUID; + +/** + * @author xenohedron + */ +public class DamageTargetAndSelfEffect extends OneShotEffect { + + private final int firstAmount; + private final int secondAmount; + + /** + * Deals simultaneous damage to the target and to itself + */ + public DamageTargetAndSelfEffect(int amount) { + this(amount, amount); + } + + /** + * Deals simultaneous damage to the target and to itself + */ + public DamageTargetAndSelfEffect(int firstAmount, int secondAmount) { + super(Outcome.Damage); + this.firstAmount = firstAmount; + this.secondAmount = secondAmount; + } + + protected DamageTargetAndSelfEffect(final DamageTargetAndSelfEffect effect) { + super(effect); + this.firstAmount = effect.firstAmount; + this.secondAmount = effect.secondAmount; + } + + @Override + public DamageTargetAndSelfEffect copy() { + return new DamageTargetAndSelfEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + for (UUID targetId : this.getTargetPointer().getTargets(game, source)) { + Permanent permanent = game.getPermanent(targetId); + if (permanent != null) { + permanent.damage(firstAmount, source.getSourceId(), source, game); + } else { + Player player = game.getPlayer(targetId); + if (player != null) { + player.damage(firstAmount, source.getSourceId(), source, game); + } + } + } + Permanent itself = source.getSourcePermanentIfItStillExists(game); + if (itself != null) { + itself.damage(secondAmount, source.getSourceId(), source, game); + } + return true; + } + + @Override + public String getText(Mode mode) { + if (staticText != null && !staticText.isEmpty()) { + return staticText; + } + return "{this} deals " + firstAmount + "damage to " + + getTargetPointer().describeTargets(mode.getTargets(), "that creature") + + " and " + secondAmount + "damage to itself"; + } +}