diff --git a/Mage.Sets/src/mage/cards/b/BrothersOfFire.java b/Mage.Sets/src/mage/cards/b/BrothersOfFire.java index ba5e830dd35..98098bfe433 100644 --- a/Mage.Sets/src/mage/cards/b/BrothersOfFire.java +++ b/Mage.Sets/src/mage/cards/b/BrothersOfFire.java @@ -1,21 +1,18 @@ - package mage.cards.b; -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.Effect; -import mage.abilities.effects.common.DamageControllerEffect; -import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.DamageTargetAndYouEffect; 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 LoneFox @@ -29,10 +26,7 @@ public final class BrothersOfFire extends CardImpl { this.toughness = new MageInt(2); // {1}{R}{R}: Brothers of Fire deals 1 damage to any target and 1 damage to you. - Ability ability = new SimpleActivatedAbility(new DamageTargetEffect(1), new ManaCostsImpl<>("{1}{R}{R}")); - Effect effect = new DamageControllerEffect(1); - effect.setText("and 1 damage to you"); - ability.addEffect(effect); + Ability ability = new SimpleActivatedAbility(new DamageTargetAndYouEffect(1), new ManaCostsImpl<>("{1}{R}{R}")); ability.addTarget(new TargetAnyTarget()); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/c/Char.java b/Mage.Sets/src/mage/cards/c/Char.java index d3fb54b2f59..96fbde8965a 100644 --- a/Mage.Sets/src/mage/cards/c/Char.java +++ b/Mage.Sets/src/mage/cards/c/Char.java @@ -1,15 +1,13 @@ - package mage.cards.c; -import java.util.UUID; -import mage.abilities.effects.Effect; -import mage.abilities.effects.common.DamageControllerEffect; -import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.DamageTargetAndYouEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.target.common.TargetAnyTarget; +import java.util.UUID; + /** * * @author LevelX2 @@ -19,13 +17,9 @@ public final class Char extends CardImpl { public Char(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{2}{R}"); - // Char deals 4 damage to any target and 2 damage to you. - this.getSpellAbility().addEffect(new DamageTargetEffect(4)); + this.getSpellAbility().addEffect(new DamageTargetAndYouEffect(4, 2)); this.getSpellAbility().addTarget(new TargetAnyTarget()); - Effect effect = new DamageControllerEffect(2); - effect.setText("and 2 damage to you"); - this.getSpellAbility().addEffect(effect); } private Char(final Char card) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/DamageTargetAndYouEffect.java b/Mage/src/main/java/mage/abilities/effects/common/DamageTargetAndYouEffect.java new file mode 100644 index 00000000000..b1e874e845e --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/DamageTargetAndYouEffect.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 DamageTargetAndYouEffect extends OneShotEffect { + + private final int firstAmount; + private final int secondAmount; + + /** + * Deals simultaneous damage to the target and the controller of the source + */ + public DamageTargetAndYouEffect(int amount) { + this(amount, amount); + } + + /** + * Deals simultaneous damage to the target and the controller of the source + */ + public DamageTargetAndYouEffect(int firstAmount, int secondAmount) { + super(Outcome.Damage); + this.firstAmount = firstAmount; + this.secondAmount = secondAmount; + } + + protected DamageTargetAndYouEffect(final DamageTargetAndYouEffect effect) { + super(effect); + this.firstAmount = effect.firstAmount; + this.secondAmount = effect.secondAmount; + } + + @Override + public DamageTargetAndYouEffect copy() { + return new DamageTargetAndYouEffect(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); + } + } + } + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + controller.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 you"; + } +}