mirror of
https://github.com/correl/mage.git
synced 2025-01-13 19:11:33 +00:00
* Implemented handling of up to for TargetAmount.
This commit is contained in:
parent
ac2a59fdc2
commit
e91639a478
2 changed files with 16 additions and 25 deletions
|
@ -52,7 +52,10 @@ public abstract class TargetAmount extends TargetImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doneChosing() {
|
public boolean doneChosing() {
|
||||||
return amountWasSet && remainingAmount == 0;
|
return amountWasSet
|
||||||
|
&& (remainingAmount == 0
|
||||||
|
|| (getMinNumberOfTargets() < getMaxNumberOfTargets()
|
||||||
|
&& getTargets().size() >= getMinNumberOfTargets()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -85,9 +88,9 @@ public abstract class TargetAmount extends TargetImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(UUID id) {
|
public void remove(UUID id) {
|
||||||
int amount = getTargetAmount(id);
|
int usedAmount = getTargetAmount(id);
|
||||||
super.remove(id);
|
super.remove(id);
|
||||||
this.remainingAmount += amount;
|
this.remainingAmount += usedAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,16 +98,16 @@ public abstract class TargetAmount extends TargetImpl {
|
||||||
if (!amountWasSet) {
|
if (!amountWasSet) {
|
||||||
setAmount(source, game);
|
setAmount(source, game);
|
||||||
}
|
}
|
||||||
chosen = remainingAmount == 0;
|
chosen = isChosen();
|
||||||
while (remainingAmount > 0) {
|
while (remainingAmount > 0) {
|
||||||
if (!getTargetController(game, playerId).chooseTargetAmount(outcome, this, source, game)) {
|
if (!getTargetController(game, playerId).chooseTargetAmount(outcome, this, source, game)) {
|
||||||
return chosen;
|
return chosen;
|
||||||
}
|
}
|
||||||
chosen = remainingAmount == 0;
|
chosen = isChosen();
|
||||||
}
|
}
|
||||||
return chosen = true;
|
return chosen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<? extends TargetAmount> getTargetOptions(Ability source, Game game) {
|
public List<? extends TargetAmount> getTargetOptions(Ability source, Game game) {
|
||||||
List<TargetAmount> options = new ArrayList<>();
|
List<TargetAmount> options = new ArrayList<>();
|
||||||
|
|
|
@ -78,26 +78,14 @@ public abstract class TargetPermanentAmount extends TargetAmount {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||||
int count = 0;
|
return game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game).size()
|
||||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
>= this.minNumberOfTargets;
|
||||||
count++;
|
|
||||||
if (count >= this.minNumberOfTargets) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canChoose(UUID sourceControllerId, Game game) {
|
public boolean canChoose(UUID sourceControllerId, Game game) {
|
||||||
int count = 0;
|
return game.getBattlefield().getActivePermanents(filter, sourceControllerId, game).size()
|
||||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, game)) {
|
>= this.minNumberOfTargets;
|
||||||
count++;
|
|
||||||
if (count >= this.minNumberOfTargets) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -136,12 +124,12 @@ public abstract class TargetPermanentAmount extends TargetAmount {
|
||||||
@Override
|
@Override
|
||||||
public String getTargetedName(Game game) {
|
public String getTargetedName(Game game) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (UUID targetId : getTargets()) {
|
getTargets().forEach((targetId) -> {
|
||||||
Permanent permanent = game.getPermanent(targetId);
|
Permanent permanent = game.getPermanent(targetId);
|
||||||
if (permanent != null) {
|
if (permanent != null) {
|
||||||
sb.append(permanent.getLogName()).append('(').append(getTargetAmount(targetId)).append(") ");
|
sb.append(permanent.getLogName()).append('(').append(getTargetAmount(targetId)).append(") ");
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue