* Fixed that spells with targets cast without paying mana could simply be canceled by canceling the target selection (e.g. player was able to cancel a spell cast by suspend what's not allowed by the rules).

This commit is contained in:
LevelX2 2015-09-11 23:03:03 +02:00
parent 963f371c12
commit 69dc4f10ac
6 changed files with 118 additions and 119 deletions

View file

@ -1,30 +1,30 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.sets.gatecrash; package mage.sets.gatecrash;
import java.util.UUID; import java.util.UUID;
@ -48,21 +48,21 @@ import mage.game.stack.StackAbility;
import mage.players.Player; import mage.players.Player;
/** /**
* *
* @author LevelX2 * @author LevelX2
*/ */
public class IllusionistsBracers extends CardImpl { public class IllusionistsBracers extends CardImpl {
public IllusionistsBracers(UUID ownerId) { public IllusionistsBracers(UUID ownerId) {
super(ownerId, 231, "Illusionist's Bracers", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{2}"); super(ownerId, 231, "Illusionist's Bracers", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{2}");
this.expansionSetCode = "GTC"; this.expansionSetCode = "GTC";
this.subtype.add("Equipment"); this.subtype.add("Equipment");
// Whenever an ability of equipped creature is activated, if it isn't a mana ability, copy that ability. You may choose new targets for the copy. // Whenever an ability of equipped creature is activated, if it isn't a mana ability, copy that ability. You may choose new targets for the copy.
this.addAbility(new AbilityActivatedTriggeredAbility()); this.addAbility(new AbilityActivatedTriggeredAbility());
// Equip 3 // Equip 3
this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(3))); this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(3)));
} }
public IllusionistsBracers(final IllusionistsBracers card) { public IllusionistsBracers(final IllusionistsBracers card) {
@ -76,6 +76,7 @@ public class IllusionistsBracers extends CardImpl {
} }
class AbilityActivatedTriggeredAbility extends TriggeredAbilityImpl { class AbilityActivatedTriggeredAbility extends TriggeredAbilityImpl {
AbilityActivatedTriggeredAbility() { AbilityActivatedTriggeredAbility() {
super(Zone.BATTLEFIELD, new CopyActivatedAbilityEffect()); super(Zone.BATTLEFIELD, new CopyActivatedAbilityEffect());
} }
@ -110,7 +111,7 @@ class AbilityActivatedTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public String getRule() { public String getRule() {
return "Whenever an ability of equipped creature is activated, if it isn't a mana ability, copy that ability. You may choose new targets for the copy."; return "Whenever an ability of equipped creature is activated, if it isn't a mana ability, copy that ability. You may choose new targets for the copy.";
} }
} }
@ -142,7 +143,7 @@ class CopyActivatedAbilityEffect extends OneShotEffect {
if (newAbility.getTargets().size() > 0) { if (newAbility.getTargets().size() > 0) {
if (controller.chooseUse(newAbility.getEffects().get(0).getOutcome(), "Choose new targets?", source, game)) { if (controller.chooseUse(newAbility.getEffects().get(0).getOutcome(), "Choose new targets?", source, game)) {
newAbility.getTargets().clearChosen(); newAbility.getTargets().clearChosen();
if (newAbility.getTargets().chooseTargets(newAbility.getEffects().get(0).getOutcome(), source.getControllerId(), newAbility, game) == false) { if (newAbility.getTargets().chooseTargets(newAbility.getEffects().get(0).getOutcome(), source.getControllerId(), newAbility, false, game) == false) {
return false; return false;
} }
} }

View file

@ -57,7 +57,7 @@ public class RingsOfBrighthearth extends CardImpl {
this.expansionSetCode = "LRW"; this.expansionSetCode = "LRW";
// Whenever you activate an ability, if it isn't a mana ability, you may pay {2}. If you do, copy that ability. You may choose new targets for the copy. // Whenever you activate an ability, if it isn't a mana ability, you may pay {2}. If you do, copy that ability. You may choose new targets for the copy.
this.addAbility(new RingsOfBrighthearthTriggeredAbility()); this.addAbility(new RingsOfBrighthearthTriggeredAbility());
} }
public RingsOfBrighthearth(final RingsOfBrighthearth card) { public RingsOfBrighthearth(final RingsOfBrighthearth card) {
@ -71,15 +71,15 @@ public class RingsOfBrighthearth extends CardImpl {
} }
class RingsOfBrighthearthTriggeredAbility extends TriggeredAbilityImpl { class RingsOfBrighthearthTriggeredAbility extends TriggeredAbilityImpl {
RingsOfBrighthearthTriggeredAbility() { RingsOfBrighthearthTriggeredAbility() {
super(Zone.BATTLEFIELD, new RingsOfBrighthearthEffect(), false); super(Zone.BATTLEFIELD, new RingsOfBrighthearthEffect(), false);
} }
RingsOfBrighthearthTriggeredAbility(final RingsOfBrighthearthTriggeredAbility ability) { RingsOfBrighthearthTriggeredAbility(final RingsOfBrighthearthTriggeredAbility ability) {
super(ability); super(ability);
} }
@Override @Override
public RingsOfBrighthearthTriggeredAbility copy() { public RingsOfBrighthearthTriggeredAbility copy() {
return new RingsOfBrighthearthTriggeredAbility(this); return new RingsOfBrighthearthTriggeredAbility(this);
@ -89,7 +89,7 @@ class RingsOfBrighthearthTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkEventType(GameEvent event, Game game) { public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.ACTIVATED_ABILITY; return event.getType() == EventType.ACTIVATED_ABILITY;
} }
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(getControllerId())) { if (event.getPlayerId().equals(getControllerId())) {
@ -102,7 +102,7 @@ class RingsOfBrighthearthTriggeredAbility extends TriggeredAbilityImpl {
} }
return false; return false;
} }
@Override @Override
public String getRule() { public String getRule() {
return "Whenever you activate an ability, if it isn't a mana ability, you may pay {2}. If you do, copy that ability. You may choose new targets for the copy."; return "Whenever you activate an ability, if it isn't a mana ability, you may pay {2}. If you do, copy that ability. You may choose new targets for the copy.";
@ -110,21 +110,21 @@ class RingsOfBrighthearthTriggeredAbility extends TriggeredAbilityImpl {
} }
class RingsOfBrighthearthEffect extends OneShotEffect { class RingsOfBrighthearthEffect extends OneShotEffect {
RingsOfBrighthearthEffect() { RingsOfBrighthearthEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);
this.staticText = ", you may pay {2}. If you do, copy that ability. You may choose new targets for the copy."; this.staticText = ", you may pay {2}. If you do, copy that ability. You may choose new targets for the copy.";
} }
RingsOfBrighthearthEffect(final RingsOfBrighthearthEffect effect) { RingsOfBrighthearthEffect(final RingsOfBrighthearthEffect effect) {
super(effect); super(effect);
} }
@Override @Override
public RingsOfBrighthearthEffect copy() { public RingsOfBrighthearthEffect copy() {
return new RingsOfBrighthearthEffect(this); return new RingsOfBrighthearthEffect(this);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
@ -142,7 +142,7 @@ class RingsOfBrighthearthEffect extends OneShotEffect {
if (newAbility.getTargets().size() > 0) { if (newAbility.getTargets().size() > 0) {
if (controller.chooseUse(newAbility.getEffects().get(0).getOutcome(), "Choose new targets?", source, game)) { if (controller.chooseUse(newAbility.getEffects().get(0).getOutcome(), "Choose new targets?", source, game)) {
newAbility.getTargets().clearChosen(); newAbility.getTargets().clearChosen();
if (newAbility.getTargets().chooseTargets(newAbility.getEffects().get(0).getOutcome(), source.getControllerId(), newAbility, game) == false) { if (newAbility.getTargets().chooseTargets(newAbility.getEffects().get(0).getOutcome(), source.getControllerId(), newAbility, false, game) == false) {
return false; return false;
} }
} }

View file

@ -57,8 +57,6 @@ import mage.target.TargetObject;
*/ */
public class StrionicResonator extends CardImpl { public class StrionicResonator extends CardImpl {
public StrionicResonator(UUID ownerId) { public StrionicResonator(UUID ownerId) {
super(ownerId, 224, "Strionic Resonator", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{2}"); super(ownerId, 224, "Strionic Resonator", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{2}");
this.expansionSetCode = "M14"; this.expansionSetCode = "M14";
@ -92,8 +90,8 @@ class StrionicResonatorEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
StackAbility stackAbility = (StackAbility)game.getStack().getStackObject(targetPointer.getFirst(game, source)); StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if(stackAbility != null){ if (stackAbility != null) {
Ability ability = (Ability) stackAbility.getStackAbility(); Ability ability = (Ability) stackAbility.getStackAbility();
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId());
@ -104,7 +102,7 @@ class StrionicResonatorEffect extends OneShotEffect {
if (newAbility.getTargets().size() > 0) { if (newAbility.getTargets().size() > 0) {
if (controller.chooseUse(newAbility.getEffects().get(0).getOutcome(), "Choose new targets?", source, game)) { if (controller.chooseUse(newAbility.getEffects().get(0).getOutcome(), "Choose new targets?", source, game)) {
newAbility.getTargets().clearChosen(); newAbility.getTargets().clearChosen();
if (newAbility.getTargets().chooseTargets(newAbility.getEffects().get(0).getOutcome(), source.getControllerId(), newAbility, game) == false) { if (newAbility.getTargets().chooseTargets(newAbility.getEffects().get(0).getOutcome(), source.getControllerId(), newAbility, false, game) == false) {
return false; return false;
} }
} }
@ -114,7 +112,7 @@ class StrionicResonatorEffect extends OneShotEffect {
} }
} }
return false; return false;
} }
@Override @Override
@ -122,7 +120,7 @@ class StrionicResonatorEffect extends OneShotEffect {
return new StrionicResonatorEffect(this); return new StrionicResonatorEffect(this);
} }
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Copy target ").append(mode.getTargets().get(0).getTargetName()).append(". You may choose new targets for the copy"); sb.append("Copy target ").append(mode.getTargets().get(0).getTargetName()).append(". You may choose new targets for the copy");
@ -143,7 +141,6 @@ class TargetTriggeredAbility extends TargetObject {
super(target); super(target);
} }
@Override @Override
public boolean canTarget(UUID id, Ability source, Game game) { public boolean canTarget(UUID id, Ability source, Game game) {
if (source != null && source.getSourceId().equals(id)) { if (source != null && source.getSourceId().equals(id)) {
@ -164,11 +161,11 @@ class TargetTriggeredAbility extends TargetObject {
@Override @Override
public boolean canChoose(UUID sourceControllerId, Game game) { public boolean canChoose(UUID sourceControllerId, Game game) {
for (StackObject stackObject : game.getStack()) { for (StackObject stackObject : game.getStack()) {
if (stackObject.getStackAbility() != null && stackObject.getStackAbility() instanceof TriggeredAbility && game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getStackAbility().getControllerId())) { if (stackObject.getStackAbility() != null && stackObject.getStackAbility() instanceof TriggeredAbility && game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getStackAbility().getControllerId())) {
return true; return true;
}
} }
}
return false; return false;
} }
@ -180,7 +177,7 @@ class TargetTriggeredAbility extends TargetObject {
@Override @Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) { public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<UUID>(); Set<UUID> possibleTargets = new HashSet<UUID>();
for (StackObject stackObject : game.getStack()) { for (StackObject stackObject : game.getStack()) {
if (stackObject.getStackAbility() != null && stackObject.getStackAbility() instanceof TriggeredAbility && game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getStackAbility().getControllerId())) { if (stackObject.getStackAbility() != null && stackObject.getStackAbility() instanceof TriggeredAbility && game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getStackAbility().getControllerId())) {
possibleTargets.add(stackObject.getStackAbility().getId()); possibleTargets.add(stackObject.getStackAbility().getId());
} }

View file

@ -152,7 +152,7 @@ class KurkeshOnakkeAncientEffect extends OneShotEffect {
if (newAbility.getTargets().size() > 0) { if (newAbility.getTargets().size() > 0) {
if (controller.chooseUse(newAbility.getEffects().get(0).getOutcome(), "Choose new targets?", source, game)) { if (controller.chooseUse(newAbility.getEffects().get(0).getOutcome(), "Choose new targets?", source, game)) {
newAbility.getTargets().clearChosen(); newAbility.getTargets().clearChosen();
if (newAbility.getTargets().chooseTargets(newAbility.getEffects().get(0).getOutcome(), source.getControllerId(), newAbility, game) == false) { if (newAbility.getTargets().chooseTargets(newAbility.getEffects().get(0).getOutcome(), source.getControllerId(), newAbility, false, game) == false) {
return false; return false;
} }
} }

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.effects.common.counter; package mage.abilities.effects.common.counter;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -40,8 +39,8 @@ import mage.game.permanent.Permanent;
* *
* @author Loki * @author Loki
*/ */
public class RemoveCounterSourceEffect extends OneShotEffect { public class RemoveCounterSourceEffect extends OneShotEffect {
private final Counter counter; private final Counter counter;
public RemoveCounterSourceEffect(Counter counter) { public RemoveCounterSourceEffect(Counter counter) {
@ -57,25 +56,24 @@ public class RemoveCounterSourceEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent p = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (p != null && p.getCounters().getCount(counter.getName()) >= counter.getCount()) { if (permanent != null && permanent.getCounters().getCount(counter.getName()) >= counter.getCount()) {
p.removeCounters(counter.getName(), counter.getCount(), game); permanent.removeCounters(counter.getName(), counter.getCount(), game);
if (!game.isSimulation()) { if (!game.isSimulation()) {
game.informPlayers(new StringBuilder("Removed ").append(counter.getCount()).append(" ").append(counter.getName()) game.informPlayers("Removed " + counter.getCount() + " " + counter.getName() + " counter from " + permanent.getLogName());
.append(" counter from ").append(p.getName()).toString());
} }
return true; return true;
} }
Card c = game.getCard(source.getSourceId()); Card card = game.getCard(source.getSourceId());
if (c != null && c.getCounters(game).getCount(counter.getName()) >= counter.getCount()) { if (card != null && card.getCounters(game).getCount(counter.getName()) >= counter.getCount()) {
c.removeCounters(counter.getName(), counter.getCount(), game); card.removeCounters(counter.getName(), counter.getCount(), game);
if (!game.isSimulation()) { if (!game.isSimulation()) {
game.informPlayers(new StringBuilder("Removed ").append(counter.getCount()).append(" ").append(counter.getName()) game.informPlayers("Removed " + counter.getCount() + " " + counter.getName()
.append(" counter from ").append(c.getName()) + " counter from " + card.getLogName()
.append(" (").append(c.getCounters(game).getCount(counter.getName())).append(" left)").toString()); + " (" + card.getCounters(game).getCount(counter.getName()) + " left)");
} }
return true; return true;
} }
return false; return false;
} }
@ -84,7 +82,7 @@ public class RemoveCounterSourceEffect extends OneShotEffect {
return new RemoveCounterSourceEffect(this); return new RemoveCounterSourceEffect(this);
} }
private void setText() { private void setText() {
if (counter.getCount() > 1) { if (counter.getCount() > 1) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("remove ").append(Integer.toString(counter.getCount())).append(" ").append(counter.getName()).append(" counters from {this}"); sb.append("remove ").append(Integer.toString(counter.getCount())).append(" ").append(counter.getName()).append(" counters from {this}");

View file

@ -1,58 +1,57 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.target; package mage.target;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.constants.Outcome;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class Targets extends ArrayList<Target> { public class Targets extends ArrayList<Target> {
public Targets() {} public Targets() {
}
public Targets(final Targets targets) { public Targets(final Targets targets) {
for (Target target: targets) { for (Target target : targets) {
this.add(target.copy()); this.add(target.copy());
} }
} }
public List<Target> getUnchosen() { public List<Target> getUnchosen() {
List<Target> unchosen = new ArrayList<>(); List<Target> unchosen = new ArrayList<>();
for (Target target: this) { for (Target target : this) {
if (!target.isChosen()) { if (!target.isChosen()) {
unchosen.add(target); unchosen.add(target);
} }
@ -61,13 +60,13 @@ public class Targets extends ArrayList<Target> {
} }
public void clearChosen() { public void clearChosen() {
for (Target target: this) { for (Target target : this) {
target.clearChosen(); target.clearChosen();
} }
} }
public boolean isChosen() { public boolean isChosen() {
for (Target target: this) { for (Target target : this) {
if (!target.isChosen()) { if (!target.isChosen()) {
return false; return false;
} }
@ -90,7 +89,7 @@ public class Targets extends ArrayList<Target> {
return true; return true;
} }
public boolean chooseTargets(Outcome outcome, UUID playerId, Ability source, Game game) { public boolean chooseTargets(Outcome outcome, UUID playerId, Ability source, boolean noMana, Game game) {
if (this.size() > 0) { if (this.size() > 0) {
if (!canChoose(source.getSourceId(), playerId, game)) { if (!canChoose(source.getSourceId(), playerId, game)) {
return false; return false;
@ -101,6 +100,9 @@ public class Targets extends ArrayList<Target> {
if (target.getTargetController() != null) { // some targets can have controller different than ability controller if (target.getTargetController() != null) { // some targets can have controller different than ability controller
targetController = target.getTargetController(); targetController = target.getTargetController();
} }
if (noMana) { // if cast without mana (e.g. by supend you may notr be able to cancel the casting if you are able to cast it
target.setRequired(true);
}
if (!target.chooseTarget(outcome, targetController, source, game)) { if (!target.chooseTarget(outcome, targetController, source, game)) {
return false; return false;
} }
@ -113,7 +115,7 @@ public class Targets extends ArrayList<Target> {
// 608.2 // 608.2
// The spell or ability is countered if all its targets, for every instance of the word "target," are now illegal // The spell or ability is countered if all its targets, for every instance of the word "target," are now illegal
int illegalCount = 0; int illegalCount = 0;
for (Target target: this) { for (Target target : this) {
if (!target.isLegal(source, game)) { if (!target.isLegal(source, game)) {
illegalCount++; illegalCount++;
} }
@ -123,8 +125,8 @@ public class Targets extends ArrayList<Target> {
} }
/** /**
* Checks if there are enough targets that can be chosen. Should only be used * Checks if there are enough targets that can be chosen. Should only be
* for Ability targets since this checks for protection, shroud etc. * 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 sourceControllerId - controller of the target event source
@ -132,7 +134,7 @@ public class Targets extends ArrayList<Target> {
* @return - true if enough valid targets exist * @return - true if enough valid targets exist
*/ */
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
for (Target target: this) { for (Target target : this) {
if (!target.canChoose(sourceId, sourceControllerId, game)) { if (!target.canChoose(sourceId, sourceControllerId, game)) {
return false; return false;
} }
@ -141,15 +143,16 @@ public class Targets extends ArrayList<Target> {
} }
/** /**
* Checks if there are enough objects that can be selected. Should not be used * Checks if there are enough objects that can be selected. Should not be
* for Ability targets since this does not check for protection, shroud etc. * used for Ability targets since this does not check for protection, shroud
* etc.
* *
* @param sourceControllerId - controller of the select event * @param sourceControllerId - controller of the select event
* @param game * @param game
* @return - true if enough valid objects exist * @return - true if enough valid objects exist
*/ */
public boolean canChoose(UUID sourceControllerId, Game game) { public boolean canChoose(UUID sourceControllerId, Game game) {
for (Target target: this) { for (Target target : this) {
if (!target.canChoose(sourceControllerId, game)) { if (!target.canChoose(sourceControllerId, game)) {
return false; return false;
} }