Change handling of minNumberOfTargets and required status

This commit is contained in:
Quercitron 2014-06-29 02:45:18 +04:00
parent 1129858a6c
commit 13b8cad131
3 changed files with 18 additions and 8 deletions

View file

@ -239,7 +239,11 @@ public class HumanPlayer extends PlayerImpl {
updateGameStatePriority("choose(5)", game); updateGameStatePriority("choose(5)", game);
while (!abort) { while (!abort) {
Set<UUID> cards = target.possibleTargets(null, playerId, game); Set<UUID> cards = target.possibleTargets(null, playerId, game);
game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(sourceId, game), options); boolean required = target.isRequired(sourceId, game);
if (target.getTargets().size() >= target.getNumberOfTargets()) {
required = false;
}
game.fireSelectTargetEvent(playerId, target.getMessage(), cards, required, options);
waitForResponse(game); waitForResponse(game);
if (response.getUUID() != null) { if (response.getUUID() != null) {
if (target instanceof TargetPermanent) { if (target instanceof TargetPermanent) {
@ -287,7 +291,10 @@ public class HumanPlayer extends PlayerImpl {
updateGameStatePriority("chooseTarget", game); updateGameStatePriority("chooseTarget", game);
while (!abort) { while (!abort) {
Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game); Set<UUID> possibleTargets = target.possibleTargets(source==null?null:source.getSourceId(), playerId, game);
boolean required = possibleTargets.isEmpty() ? false : target.isRequired(source); boolean required = target.isRequired(source);
if (possibleTargets.isEmpty() || target.getTargets().size() >= target.getNumberOfTargets()) {
required = false;
}
game.fireSelectTargetEvent(playerId, target.getMessage(), possibleTargets, required, getOptions(target)); game.fireSelectTargetEvent(playerId, target.getMessage(), possibleTargets, required, getOptions(target));
waitForResponse(game); waitForResponse(game);
if (response.getUUID() != null) { if (response.getUUID() != null) {
@ -319,7 +326,7 @@ public class HumanPlayer extends PlayerImpl {
} }
private Map<String, Serializable> getOptions(Target target) { private Map<String, Serializable> getOptions(Target target) {
return target.getNumberOfTargets() != target.getMaxNumberOfTargets() ? staticOptions : null; return target.getTargets().size() >= target.getNumberOfTargets() ? staticOptions : null;
} }
@Override @Override
@ -336,6 +343,9 @@ public class HumanPlayer extends PlayerImpl {
required = false; required = false;
} }
} }
if (target.getTargets().size() >= target.getNumberOfTargets()) {
required = false;
}
Map<String, Serializable> options = getOptions(target); Map<String, Serializable> options = getOptions(target);
if (target.getTargets().size() > 0) { if (target.getTargets().size() > 0) {
if (options == null) { if (options == null) {
@ -379,7 +389,10 @@ public class HumanPlayer extends PlayerImpl {
required = false; required = false;
} }
} }
game.fireSelectTargetEvent(playerId, target.getMessage(), cards, target.isRequired(source), null); if (target.getTargets().size() >= target.getNumberOfTargets()) {
required = false;
}
game.fireSelectTargetEvent(playerId, target.getMessage(), cards, required, null);
waitForResponse(game); waitForResponse(game);
if (response.getUUID() != null) { if (response.getUUID() != null) {
if (target.canTarget(response.getUUID(), cards, game)) { if (target.canTarget(response.getUUID(), cards, game)) {

View file

@ -58,9 +58,6 @@ public abstract class TargetObject extends TargetImpl {
public TargetObject(int minNumTargets, int maxNumTargets, Zone zone, boolean notTarget) { public TargetObject(int minNumTargets, int maxNumTargets, Zone zone, boolean notTarget) {
this.minNumberOfTargets = minNumTargets; this.minNumberOfTargets = minNumTargets;
this.maxNumberOfTargets = maxNumTargets; this.maxNumberOfTargets = maxNumTargets;
if (minNumTargets == 0) {
setRequired(false);
}
this.zone = zone; this.zone = zone;
this.targetName = "card"; this.targetName = "card";
this.notTarget = notTarget; this.notTarget = notTarget;

View file

@ -65,7 +65,7 @@ public class TargetCardInLibrary extends TargetCard {
public TargetCardInLibrary(int minNumTargets, int maxNumTargets, FilterCard filter) { public TargetCardInLibrary(int minNumTargets, int maxNumTargets, FilterCard filter) {
super(minNumTargets, maxNumTargets, Zone.LIBRARY, filter); super(minNumTargets, maxNumTargets, Zone.LIBRARY, filter);
this.setRequired(minNumTargets > 0 && !filter.hasPredicates()); this.setRequired(!filter.hasPredicates());
this.librarySearchLimit = Integer.MAX_VALUE; this.librarySearchLimit = Integer.MAX_VALUE;
} }