In TargetImpl, use accessor methods instead of minNumberOfTargets and maxNumberOfTargets so subclasses can easily reuse the functionality in TargetImpl.

This commit is contained in:
Duncan Townsend 2015-01-29 00:32:23 -05:00
parent 41d41444d1
commit 601e442208
No known key found for this signature in database
GPG key ID: C00ECDF315F7A593

View file

@ -28,7 +28,6 @@
package mage.target; package mage.target;
import java.io.Serializable;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -109,11 +108,11 @@ public abstract class TargetImpl implements Target {
@Override @Override
public String getMessage() { public String getMessage() {
if (maxNumberOfTargets != 1) { if (getMaxNumberOfTargets() != 1) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("Select ").append(targetName); sb.append("Select ").append(targetName);
if (maxNumberOfTargets > 0 && maxNumberOfTargets != Integer.MAX_VALUE) { if (getMaxNumberOfTargets() > 0 && getMaxNumberOfTargets() != Integer.MAX_VALUE) {
sb.append(" (").append(targets.size()).append("/").append(maxNumberOfTargets).append(")"); sb.append(" (").append(targets.size()).append("/").append(getMaxNumberOfTargets()).append(")");
} else { } else {
sb.append(" (").append(targets.size()).append(")"); sb.append(" (").append(targets.size()).append(")");
} }
@ -177,10 +176,10 @@ public abstract class TargetImpl implements Target {
@Override @Override
public boolean isChosen() { public boolean isChosen() {
if (maxNumberOfTargets == 0 && minNumberOfTargets == 0) { if (getMaxNumberOfTargets() == 0 && getNumberOfTargets() == 0) {
return true; return true;
} }
if (maxNumberOfTargets != 0 && targets.size() == maxNumberOfTargets) { if (getMaxNumberOfTargets() != 0 && targets.size() == getMaxNumberOfTargets()) {
return true; return true;
} }
return chosen; return chosen;
@ -188,10 +187,10 @@ public abstract class TargetImpl implements Target {
@Override @Override
public boolean doneChosing() { public boolean doneChosing() {
if (maxNumberOfTargets == 0) { if (getMaxNumberOfTargets() == 0) {
return false; return false;
} }
return targets.size() == maxNumberOfTargets; return targets.size() == getMaxNumberOfTargets();
} }
@Override @Override
@ -203,7 +202,7 @@ public abstract class TargetImpl implements Target {
@Override @Override
public void add(UUID id, Game game) { public void add(UUID id, Game game) {
if (maxNumberOfTargets == 0 || targets.size() < maxNumberOfTargets) { if (getMaxNumberOfTargets() == 0 || targets.size() < getMaxNumberOfTargets()) {
if (!targets.containsKey(id)) { if (!targets.containsKey(id)) {
targets.put(id, 0); targets.put(id, 0);
rememberZoneChangeCounter(id, game); rememberZoneChangeCounter(id, game);
@ -227,13 +226,13 @@ public abstract class TargetImpl implements Target {
@Override @Override
public void addTarget(UUID id, Ability source, Game game, boolean skipEvent) { public void addTarget(UUID id, Ability source, Game game, boolean skipEvent) {
//20100423 - 113.3 //20100423 - 113.3
if (maxNumberOfTargets == 0 || targets.size() < maxNumberOfTargets) { if (getMaxNumberOfTargets() == 0 || targets.size() < getMaxNumberOfTargets()) {
if (!targets.containsKey(id)) { if (!targets.containsKey(id)) {
if (source != null && !skipEvent) { if (source != null && !skipEvent) {
if (!game.replaceEvent(GameEvent.getEvent(EventType.TARGET, id, source.getSourceId(), source.getControllerId()))) { if (!game.replaceEvent(GameEvent.getEvent(EventType.TARGET, id, source.getSourceId(), source.getControllerId()))) {
targets.put(id, 0); targets.put(id, 0);
rememberZoneChangeCounter(id, game); rememberZoneChangeCounter(id, game);
chosen = targets.size() >= minNumberOfTargets; chosen = targets.size() >= getNumberOfTargets();
if (!skipEvent) { if (!skipEvent) {
game.fireEvent(GameEvent.getEvent(EventType.TARGETED, id, source.getSourceId(), source.getControllerId())); game.fireEvent(GameEvent.getEvent(EventType.TARGETED, id, source.getSourceId(), source.getControllerId()));
} }
@ -271,7 +270,7 @@ public abstract class TargetImpl implements Target {
if (!game.replaceEvent(GameEvent.getEvent(EventType.TARGET, id, source.getSourceId(), source.getControllerId()))) { if (!game.replaceEvent(GameEvent.getEvent(EventType.TARGET, id, source.getSourceId(), source.getControllerId()))) {
targets.put(id, amount); targets.put(id, amount);
rememberZoneChangeCounter(id, game); rememberZoneChangeCounter(id, game);
chosen = targets.size() >= minNumberOfTargets; chosen = targets.size() >= getNumberOfTargets();
if (!skipEvent) { if (!skipEvent) {
game.fireEvent(GameEvent.getEvent(EventType.TARGETED, id, source.getSourceId(), source.getControllerId())); game.fireEvent(GameEvent.getEvent(EventType.TARGETED, id, source.getSourceId(), source.getControllerId()));
} }
@ -286,11 +285,11 @@ public abstract class TargetImpl implements Target {
public boolean choose(Outcome outcome, UUID playerId, UUID sourceId, Game game) { public boolean choose(Outcome outcome, UUID playerId, UUID sourceId, Game game) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
while (!isChosen() && !doneChosing()) { while (!isChosen() && !doneChosing()) {
chosen = targets.size() >= minNumberOfTargets; chosen = targets.size() >= getNumberOfTargets();
if (!player.choose(outcome, this, sourceId, game)) { if (!player.choose(outcome, this, sourceId, game)) {
return chosen; return chosen;
} }
chosen = targets.size() >= minNumberOfTargets; chosen = targets.size() >= getNumberOfTargets();
} }
return chosen = true; return chosen = true;
} }
@ -299,7 +298,7 @@ public abstract class TargetImpl implements Target {
public boolean chooseTarget(Outcome outcome, UUID playerId, Ability source, Game game) { public boolean chooseTarget(Outcome outcome, UUID playerId, Ability source, Game game) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
while (!isChosen() && !doneChosing()) { while (!isChosen() && !doneChosing()) {
chosen = targets.size() >= minNumberOfTargets; chosen = targets.size() >= getNumberOfTargets();
if (isRandom()) { if (isRandom()) {
Set<UUID> possibleTargets = possibleTargets(source.getSourceId(), playerId, game); Set<UUID> possibleTargets = possibleTargets(source.getSourceId(), playerId, game);
if (possibleTargets.size() > 0) { if (possibleTargets.size() > 0) {
@ -319,7 +318,7 @@ public abstract class TargetImpl implements Target {
return chosen; return chosen;
} }
} }
chosen = targets.size() >= minNumberOfTargets; chosen = targets.size() >= getNumberOfTargets();
} }
return chosen = true; return chosen = true;
} }
@ -353,7 +352,7 @@ public abstract class TargetImpl implements Target {
// if (replacedTargets > 0 && replacedTargets == targets.size()) { // if (replacedTargets > 0 && replacedTargets == targets.size()) {
// return false; // return false;
// } // }
if (minNumberOfTargets == 0 && targets.isEmpty()) { if (getNumberOfTargets() == 0 && targets.isEmpty()) {
return true; return true;
} }
return targets.size() > 0; return targets.size() > 0;