[READY FOR REVIEW] Implement a "multi-amount" dialog (#7528)

* Implemented chooseTargetAmount and new GUI dialog (distribute damage, distribute mana)
* Added tests and AI support;
* Test framework: added aliases support in TargetAmount dialogs;

Co-authored-by: Oleg Agafonov <jaydi85@gmail.com>
This commit is contained in:
Daniel Bomar 2021-04-17 05:28:01 -05:00 committed by GitHub
parent 042aa61ad4
commit 600cac6fc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 1209 additions and 232 deletions

View file

@ -5,6 +5,7 @@ import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.constants.Outcome;
import mage.game.Game;
import mage.players.Player;
import java.util.*;
import java.util.stream.Collectors;
@ -59,7 +60,7 @@ public abstract class TargetAmount extends TargetImpl {
public void clearChosen() {
super.clearChosen();
amountWasSet = false;
// remainingAmount = amount;
// remainingAmount = amount; // auto-calced on target remove
}
public void setAmountDefinition(DynamicValue amount) {
@ -71,6 +72,9 @@ public abstract class TargetAmount extends TargetImpl {
amountWasSet = true;
}
public int getAmountTotal(Game game, Ability source) {
return amount.calculate(game, source, null);
}
@Override
public void addTarget(UUID id, int amount, Ability source, Game game, boolean skipEvent) {
@ -92,17 +96,25 @@ public abstract class TargetAmount extends TargetImpl {
@Override
public boolean chooseTarget(Outcome outcome, UUID playerId, Ability source, Game game) {
Player player = game.getPlayer(playerId);
if (player == null) {
return false;
}
if (!amountWasSet) {
setAmount(source, game);
}
chosen = isChosen();
while (remainingAmount > 0) {
if (!player.canRespond()) {
return chosen;
}
if (!getTargetController(game, playerId).chooseTargetAmount(outcome, this, source, game)) {
return chosen;
}
chosen = isChosen();
}
return chosen = true;
return chosen;
}
@Override
@ -163,4 +175,12 @@ public abstract class TargetAmount extends TargetImpl {
}
}
}
public void setTargetAmount(UUID targetId, int amount, Ability source, Game game) {
if (!amountWasSet) {
setAmount(source, game);
}
remainingAmount -= (amount - this.getTargetAmount(targetId));
this.setTargetAmount(targetId, amount, game);
}
}