diff --git a/Mage/src/main/java/mage/filter/predicate/mageobject/NumberOfTargetsPredicate.java b/Mage/src/main/java/mage/filter/predicate/mageobject/NumberOfTargetsPredicate.java index fb917ef5f4..47bfd2ed07 100644 --- a/Mage/src/main/java/mage/filter/predicate/mageobject/NumberOfTargetsPredicate.java +++ b/Mage/src/main/java/mage/filter/predicate/mageobject/NumberOfTargetsPredicate.java @@ -31,7 +31,7 @@ import mage.MageObject; import mage.abilities.Mode; import mage.filter.predicate.Predicate; import mage.game.Game; -import mage.game.stack.Spell; +import mage.game.stack.StackObject; import mage.target.Target; /** @@ -48,10 +48,10 @@ public class NumberOfTargetsPredicate implements Predicate { @Override public boolean apply(MageObject input, Game game) { - Spell spell = game.getStack().getSpell(input.getId()); - if (spell != null) { + StackObject stackObject = game.getState().getStack().getStackObject(input.getId()); + if (stackObject != null) { int numberOfTargets = 0; - for (Mode mode : spell.getSpellAbility().getModes().getSelectedModes()) { + for (Mode mode : stackObject.getStackAbility().getModes().getSelectedModes()) { for (Target target : mode.getTargets()) { numberOfTargets += target.getTargets().size(); } @@ -60,6 +60,18 @@ public class NumberOfTargetsPredicate implements Predicate { return true; } } +// Spell spell = game.getStack().getSpell(input.getId()); +// if (spell != null) { +// int numberOfTargets = 0; +// for (Mode mode : spell.getSpellAbility().getModes().getSelectedModes()) { +// for (Target target : mode.getTargets()) { +// numberOfTargets += target.getTargets().size(); +// } +// } +// if (numberOfTargets == targets) { +// return true; +// } +// } return false; } diff --git a/Mage/src/main/java/mage/game/stack/StackAbility.java b/Mage/src/main/java/mage/game/stack/StackAbility.java index 15cb0d4a0f..46e0a94458 100644 --- a/Mage/src/main/java/mage/game/stack/StackAbility.java +++ b/Mage/src/main/java/mage/game/stack/StackAbility.java @@ -178,7 +178,9 @@ public class StackAbility extends StackObjImpl implements Ability { @Override public Abilities getAbilities() { - return emptyAbilites; + Abilities abilities = new AbilitiesImpl<>(); + abilities.add(ability); + return abilities; } @Override diff --git a/Mage/src/main/java/mage/game/stack/StackObjImpl.java b/Mage/src/main/java/mage/game/stack/StackObjImpl.java index e04169cd92..2286fd06ae 100644 --- a/Mage/src/main/java/mage/game/stack/StackObjImpl.java +++ b/Mage/src/main/java/mage/game/stack/StackObjImpl.java @@ -113,7 +113,7 @@ public abstract class StackObjImpl implements StackObject { if (this instanceof Spell) { objectAbilities.addAll(((Spell) this).getSpellAbilities()); } else { - objectAbilities.addAll(getAbilities()); + objectAbilities.add(getStackAbility()); } for (Ability ability : objectAbilities) { // Some spells can have more than one mode @@ -210,34 +210,36 @@ public abstract class StackObjImpl implements StackObject { again = true; } } else // if possible add the alternate Target - it may not be included in the old definition nor in the already selected targets of the new definition - if (newTarget.getTargets().contains(tempTarget.getFirstTarget()) || target.getTargets().contains(tempTarget.getFirstTarget())) { - if (targetController.isHuman()) { - if (targetController.chooseUse(Outcome.Benefit, "This target was already selected from origin spell. Reset to original target?", ability, game)) { - // use previous target no target was selected - newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); + { + if (newTarget.getTargets().contains(tempTarget.getFirstTarget()) || target.getTargets().contains(tempTarget.getFirstTarget())) { + if (targetController.isHuman()) { + if (targetController.chooseUse(Outcome.Benefit, "This target was already selected from origin spell. Reset to original target?", ability, game)) { + // use previous target no target was selected + newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); + } else { + again = true; + } } else { + newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); + } + } else if (!target.canTarget(getControllerId(), tempTarget.getFirstTarget(), ability, game)) { + if (targetController.isHuman()) { + game.informPlayer(targetController, "This target is not valid!"); + again = true; + } else { + // keep the old + newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); + } + } else if (newTarget.getFirstTarget() != null && filterNewTarget != null) { + Permanent newTargetPermanent = game.getPermanent(newTarget.getFirstTarget()); + if (newTargetPermanent == null || !filterNewTarget.match(newTargetPermanent, game)) { + game.informPlayer(targetController, "This target does not fullfil the target requirements (" + filterNewTarget.getMessage() + ")"); again = true; } } else { - newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); + // valid target was selected, add it to the new target definition + newTarget.addTarget(tempTarget.getFirstTarget(), target.getTargetAmount(targetId), ability, game, false); } - } else if (!target.canTarget(getControllerId(), tempTarget.getFirstTarget(), ability, game)) { - if (targetController.isHuman()) { - game.informPlayer(targetController, "This target is not valid!"); - again = true; - } else { - // keep the old - newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false); - } - } else if (newTarget.getFirstTarget() != null && filterNewTarget != null) { - Permanent newTargetPermanent = game.getPermanent(newTarget.getFirstTarget()); - if (newTargetPermanent == null || !filterNewTarget.match(newTargetPermanent, game)) { - game.informPlayer(targetController, "This target does not fullfil the target requirements (" + filterNewTarget.getMessage() + ")"); - again = true; - } - } else { - // valid target was selected, add it to the new target definition - newTarget.addTarget(tempTarget.getFirstTarget(), target.getTargetAmount(targetId), ability, game, false); } } while (again && targetController.canRespond()); }