* Fixed that selecting no target players let fizzle the spell (e.g. Wheel and Deal).

This commit is contained in:
LevelX2 2016-12-22 23:50:02 +01:00
parent c2ef2b1f47
commit 8ba22ad7e2

View file

@ -24,20 +24,18 @@
* 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
* or implied, of BetaSteward_at_googlemail.com.
*/
*/
package mage.target;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.filter.FilterPlayer;
import mage.game.Game;
import mage.players.Player;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -77,8 +75,8 @@ public class TargetPlayer extends TargetImpl {
}
/**
* Checks if there are enough {@link Player} that can be chosen. Should only be used
* for Ability targets since this checks for protection, shroud etc.
* Checks if there are enough {@link Player} 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 sourceControllerId - controller of the target event source
@ -89,7 +87,7 @@ public class TargetPlayer extends TargetImpl {
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
int count = 0;
MageObject targetSource = game.getObject(sourceId);
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null && !player.hasLeft() && filter.match(player, sourceId, sourceControllerId, game)) {
if (player.canBeTargetedBy(targetSource, sourceControllerId, game)) {
@ -104,8 +102,9 @@ public class TargetPlayer extends TargetImpl {
}
/**
* Checks if there are enough {@link Player} that can be selected. Should not be used
* for Ability targets since this does not check for protection, shroud etc.
* Checks if there are enough {@link Player} that can be selected. Should
* not be used for Ability targets since this does not check for protection,
* shroud etc.
*
* @param sourceControllerId - controller of the select event
* @param game
@ -114,7 +113,7 @@ public class TargetPlayer extends TargetImpl {
@Override
public boolean canChoose(UUID sourceControllerId, Game game) {
int count = 0;
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null && !player.hasLeft() && filter.match(player, game)) {
count++;
@ -130,7 +129,7 @@ public class TargetPlayer extends TargetImpl {
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null && !player.hasLeft() && filter.match(player, sourceId, sourceControllerId, game)) {
if (isNotTarget() || player.canBeTargetedBy(targetSource, sourceControllerId, game)) {
@ -144,7 +143,7 @@ public class TargetPlayer extends TargetImpl {
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<>();
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
Player player = game.getPlayer(playerId);
if (player != null && !player.hasLeft() && filter.match(player, game)) {
possibleTargets.add(playerId);
@ -156,7 +155,10 @@ public class TargetPlayer extends TargetImpl {
@Override
public boolean isLegal(Ability source, Game game) {
//20101001 - 608.2b
for (UUID playerId: targets.keySet()) {
if (getNumberOfTargets() == 0 && targets.isEmpty()) {
return true; // 0 targets selected is valid
}
for (UUID playerId : targets.keySet()) {
if (canTarget(playerId, source, game)) {
return true;
}
@ -195,7 +197,7 @@ public class TargetPlayer extends TargetImpl {
@Override
public String getTargetedName(Game game) {
StringBuilder sb = new StringBuilder();
for (UUID targetId: getTargets()) {
for (UUID targetId : getTargets()) {
Player player = game.getPlayer(targetId);
if (player != null) {
sb.append(player.getLogName()).append(" ");