From e91639a4789966323b20966e18310d5e63ae58c4 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 10 Jan 2020 15:49:10 +0100 Subject: [PATCH] * Implemented handling of up to for TargetAmount. --- .../main/java/mage/target/TargetAmount.java | 17 +++++++------ .../target/common/TargetPermanentAmount.java | 24 +++++-------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/Mage/src/main/java/mage/target/TargetAmount.java b/Mage/src/main/java/mage/target/TargetAmount.java index b493de4880..41da56d5ea 100644 --- a/Mage/src/main/java/mage/target/TargetAmount.java +++ b/Mage/src/main/java/mage/target/TargetAmount.java @@ -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,16 +98,16 @@ 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)) { + if (!getTargetController(game, playerId).chooseTargetAmount(outcome, this, source, game)) { return chosen; } - chosen = remainingAmount == 0; + chosen = isChosen(); } return chosen = true; } - + @Override public List getTargetOptions(Ability source, Game game) { List options = new ArrayList<>(); diff --git a/Mage/src/main/java/mage/target/common/TargetPermanentAmount.java b/Mage/src/main/java/mage/target/common/TargetPermanentAmount.java index 77187b2931..ecfd696f5c 100644 --- a/Mage/src/main/java/mage/target/common/TargetPermanentAmount.java +++ b/Mage/src/main/java/mage/target/common/TargetPermanentAmount.java @@ -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(); }