GUI, game: fixed wrong number of targets in stack ability for some use cases (example: cumulative upkeep, close #12824)

This commit is contained in:
Oleg Agafonov 2024-09-07 20:49:25 +04:00
parent 8bd7e346fb
commit 2fc4e94b3a
2 changed files with 12 additions and 13 deletions

View file

@ -1134,13 +1134,13 @@ public class CardView extends SimpleCardView {
this.targets = new ArrayList<>();
}
// need only unique targets for arrow drawning
Set<UUID> newTargets = new HashSet<>();
// need only unique targets for arrow drawing
Set<UUID> uniqueTarget = new LinkedHashSet<>(); // use linked, so it will use stable sort order
// from normal targets
for (Target target : targets) {
if (target.isChosen(game)) {
newTargets.addAll(target.getTargets());
uniqueTarget.addAll(target.getTargets());
}
}
@ -1151,9 +1151,9 @@ public class CardView extends SimpleCardView {
.map(p -> p.getTargets(game, source))
.flatMap(Collection::stream)
.collect(Collectors.toList());
newTargets.addAll(fromPointers);
uniqueTarget.addAll(fromPointers);
this.targets.addAll(newTargets);
this.targets.addAll(uniqueTarget);
}
private void setOriginalValues(MageObject object) {

View file

@ -17,9 +17,7 @@ import mage.target.Target;
import mage.target.targetpointer.TargetPointer;
import mage.util.GameLog;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
@ -86,15 +84,16 @@ public class StackAbilityView extends CardView {
if (!mode.getTargets().isEmpty()) {
addTargets(mode.getTargets(), mode.getEffects(), ability, game);
} else {
List<UUID> targetList = new ArrayList<>();
// need only unique targets for arrow drawing
Set<UUID> uniqueTargets = new LinkedHashSet<>(); // use linked, so it will use stable sort order
for (Effect effect : mode.getEffects()) {
TargetPointer targetPointer = effect.getTargetPointer();
targetList.addAll(targetPointer.getTargets(game, ability));
uniqueTargets.addAll(targetPointer.getTargets(game, ability));
}
if (!targetList.isEmpty()) {
overrideTargets(targetList);
if (!uniqueTargets.isEmpty()) {
overrideTargets(new ArrayList<>(uniqueTargets));
for (UUID uuid : targetList) {
for (UUID uuid : uniqueTargets) {
MageObject mageObject = game.getObject(uuid);
if (mageObject != null) {
if ((mageObject instanceof Card) && ((Card) mageObject).isFaceDown(game)) {