* Implemented handling of up to for TargetAmount.

This commit is contained in:
LevelX2 2020-01-10 15:49:10 +01:00
parent ac2a59fdc2
commit e91639a478
2 changed files with 16 additions and 25 deletions

View file

@ -52,7 +52,10 @@ public abstract class TargetAmount extends TargetImpl {
@Override
public boolean doneChosing() {
return amountWasSet && remainingAmount == 0;
return amountWasSet
&& (remainingAmount == 0
|| (getMinNumberOfTargets() < getMaxNumberOfTargets()
&& getTargets().size() >= getMinNumberOfTargets()));
}
@Override
@ -85,9 +88,9 @@ public abstract class TargetAmount extends TargetImpl {
@Override
public void remove(UUID id) {
int amount = getTargetAmount(id);
int usedAmount = getTargetAmount(id);
super.remove(id);
this.remainingAmount += amount;
this.remainingAmount += usedAmount;
}
@Override
@ -95,12 +98,12 @@ public abstract class TargetAmount extends TargetImpl {
if (!amountWasSet) {
setAmount(source, game);
}
chosen = remainingAmount == 0;
chosen = isChosen();
while (remainingAmount > 0) {
if (!getTargetController(game, playerId).chooseTargetAmount(outcome, this, source, game)) {
return chosen;
}
chosen = remainingAmount == 0;
chosen = isChosen();
}
return chosen = true;
}

View file

@ -78,26 +78,14 @@ public abstract class TargetPermanentAmount extends TargetAmount {
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
int count = 0;
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
count++;
if (count >= this.minNumberOfTargets) {
return true;
}
}
return false;
return game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game).size()
>= this.minNumberOfTargets;
}
@Override
public boolean canChoose(UUID sourceControllerId, Game game) {
int count = 0;
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets) {
return true;
}
}
return false;
return game.getBattlefield().getActivePermanents(filter, sourceControllerId, game).size()
>= this.minNumberOfTargets;
}
@Override
@ -136,12 +124,12 @@ public abstract class TargetPermanentAmount extends TargetAmount {
@Override
public String getTargetedName(Game game) {
StringBuilder sb = new StringBuilder();
for (UUID targetId : getTargets()) {
getTargets().forEach((targetId) -> {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
sb.append(permanent.getLogName()).append('(').append(getTargetAmount(targetId)).append(") ");
}
}
});
return sb.toString();
}