diff --git a/Mage.Sets/src/mage/cards/e/EssenceCapture.java b/Mage.Sets/src/mage/cards/e/EssenceCapture.java index a95d30f554..7af749c449 100644 --- a/Mage.Sets/src/mage/cards/e/EssenceCapture.java +++ b/Mage.Sets/src/mage/cards/e/EssenceCapture.java @@ -28,7 +28,7 @@ public final class EssenceCapture extends CardImpl { // Put a +1/+1 counter on up to one target creature you control. this.getSpellAbility().addEffect(new AddCountersTargetEffect( CounterType.P1P1.createInstance() - ).setTargetPointer(new SecondTargetPointer()).setText("Put a +1/+1 counter on up to one target creature you control")); + ).setTargetPointer(new SecondTargetPointer())); this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent(0, 1)); } diff --git a/Mage/src/main/java/mage/abilities/effects/common/counter/AddCountersTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/counter/AddCountersTargetEffect.java index e50680a73c..4c717eb6e4 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/counter/AddCountersTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/counter/AddCountersTargetEffect.java @@ -1,8 +1,5 @@ - package mage.abilities.effects.common.counter; -import java.util.Locale; -import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.Mode; @@ -19,8 +16,10 @@ import mage.players.Player; import mage.target.Target; import mage.util.CardUtil; +import java.util.Locale; +import java.util.UUID; + /** - * * @author BetaSteward_at_googlemail.com */ public class AddCountersTargetEffect extends OneShotEffect { @@ -121,8 +120,8 @@ public class AddCountersTargetEffect extends OneShotEffect { } sb.append(" on "); - if (!mode.getTargets().isEmpty()) { - Target target = mode.getTargets().get(0); + Target target = mode.getTargets().getEffectTarget(this.targetPointer); + if (target != null) { if (target.getNumberOfTargets() == 0) { sb.append("up to "); } diff --git a/Mage/src/main/java/mage/target/Targets.java b/Mage/src/main/java/mage/target/Targets.java index a1645e12d4..112a409316 100644 --- a/Mage/src/main/java/mage/target/Targets.java +++ b/Mage/src/main/java/mage/target/Targets.java @@ -1,10 +1,14 @@ - package mage.target; import mage.abilities.Ability; import mage.constants.Outcome; import mage.game.Game; import mage.game.events.GameEvent; +import mage.target.targetpointer.FirstTargetPointer; +import mage.target.targetpointer.SecondTargetPointer; +import mage.target.targetpointer.TargetPointer; +import mage.target.targetpointer.ThirdTargetPointer; +import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; @@ -12,11 +16,12 @@ import java.util.UUID; import java.util.stream.Collectors; /** - * * @author BetaSteward_at_googlemail.com */ public class Targets extends ArrayList { + private static final Logger logger = Logger.getLogger(Targets.class); + public Targets() { } @@ -101,7 +106,7 @@ public class Targets extends ArrayList { * Checks if there are enough targets that can be chosen. Should only be * used for Ability targets since this checks for protection, shroud etc. * - * @param sourceId - the target event source + * @param sourceId - the target event source * @param sourceControllerId - controller of the target event source * @param game * @return - true if enough valid targets exist @@ -130,6 +135,38 @@ public class Targets extends ArrayList { return null; } + public Target getEffectTarget(TargetPointer targetPointer) { + boolean proccessed = false; + + if (targetPointer instanceof FirstTargetPointer) { + proccessed = true; + if (this.size() > 0) { + return this.get(0); + } + } + + if (targetPointer instanceof SecondTargetPointer) { + proccessed = true; + if (this.size() > 1) { + return this.get(1); + } + } + + if (targetPointer instanceof ThirdTargetPointer) { + proccessed = true; + if (this.size() > 2) { + return this.get(2); + } + } + + if (!proccessed) { + logger.error("Unknown target pointer " + (targetPointer != null ? targetPointer : "null"), new Throwable()); + // TODO: add other target types? + } + + return null; + } + public Targets copy() { return new Targets(this); }