From 3b9867c5377d8833ca43ee1f689277bb6cae01bb Mon Sep 17 00:00:00 2001 From: tool4ever Date: Sat, 5 Jul 2025 06:58:26 +0000 Subject: [PATCH] Fix updateTarget (#7927) * Fix meld exiling missing half --- .../src/main/java/forge/game/GameAction.java | 3 ++- .../ability/effects/ChangeTargetsEffect.java | 22 ++++++++++--------- .../SpellAbilityStackInstance.java | 10 ++++----- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/forge-game/src/main/java/forge/game/GameAction.java b/forge-game/src/main/java/forge/game/GameAction.java index 4eaa8510fe9..3456fb3102a 100644 --- a/forge-game/src/main/java/forge/game/GameAction.java +++ b/forge-game/src/main/java/forge/game/GameAction.java @@ -645,7 +645,8 @@ public class GameAction { // Ask controller if it wants to be on top or bottom of other meld. unmeldPosition++; } - changeZone(null, zoneTo, unmeld, position, cause, params); + unmeld = changeZone(null, zoneTo, unmeld, position, cause, params); + storeChangesZoneAll(unmeld, zoneFrom, zoneTo, params); } } else if (toBattlefield) { for (Player p : game.getPlayers()) { diff --git a/forge-game/src/main/java/forge/game/ability/effects/ChangeTargetsEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ChangeTargetsEffect.java index 76b0f8de722..ef463bd6baa 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ChangeTargetsEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ChangeTargetsEffect.java @@ -37,7 +37,7 @@ public class ChangeTargetsEffect extends SpellAbilityEffect { final Player chooser = sa.hasParam("Chooser") ? getDefinedPlayersOrTargeted(sa, "Chooser").get(0) : activator; final MagicStack stack = activator.getGame().getStack(); - + for (final SpellAbility tgtSA : sas) { SpellAbilityStackInstance si = stack.getInstanceMatchingSpellAbilityID(tgtSA); if (si == null) { @@ -72,8 +72,8 @@ public class ChangeTargetsEffect extends SpellAbilityEffect { // 2. prepare new target choices SpellAbilityStackInstance replaceIn = chosenTarget.getKey(); GameObject oldTarget = chosenTarget.getValue(); - TargetChoices oldTargetBlock = replaceIn.getTargetChoices(); - TargetChoices newTargetBlock = oldTargetBlock.clone(); + TargetChoices newTargetBlock = replaceIn.getTargetChoices(); + TargetChoices oldTargetBlock = newTargetBlock.clone(); // gets the divided value from old target Integer div = oldTargetBlock.getDividedValue(oldTarget); // 3. test if updated choices would be correct. @@ -87,7 +87,7 @@ public class ChangeTargetsEffect extends SpellAbilityEffect { if (div != null) { newTargetBlock.addDividedAllocation(newTarget, div); } - replaceIn.updateTarget(newTargetBlock, sa.getHostCard()); + replaceIn.updateTarget(oldTargetBlock, sa.getHostCard()); } } else { while (changingTgtSI != null) { @@ -104,25 +104,26 @@ public class ChangeTargetsEffect extends SpellAbilityEffect { if (candidates.isEmpty()) { return; } - changingTgtSA.resetTargets(); GameEntity choice = Aggregates.random(candidates); + TargetChoices oldTarget = changingTgtSA.getTargets(); + changingTgtSA.resetTargets(); changingTgtSA.getTargets().add(choice); if (changingTgtSA.isDividedAsYouChoose()) { changingTgtSA.addDividedAllocation(choice, div); } - - changingTgtSI.updateTarget(changingTgtSA.getTargets(), sa.getHostCard()); + changingTgtSI.updateTarget(oldTarget, sa.getHostCard()); } else if (sa.hasParam("DefinedMagnet")) { GameObject newTarget = Iterables.getFirst(getDefinedCardsOrTargeted(sa, "DefinedMagnet"), null); if (newTarget != null && changingTgtSA.canTarget(newTarget)) { int div = changingTgtSA.getTotalDividedValue(); + TargetChoices oldTarget = changingTgtSA.getTargets(); changingTgtSA.resetTargets(); changingTgtSA.getTargets().add(newTarget); - changingTgtSI.updateTarget(changingTgtSA.getTargets(), sa.getHostCard()); if (changingTgtSA.isDividedAsYouChoose()) { changingTgtSA.addDividedAllocation(newTarget, div); } + changingTgtSI.updateTarget(oldTarget, sa.getHostCard()); } } else { // Update targets, with a potential new target @@ -132,8 +133,9 @@ public class ChangeTargetsEffect extends SpellAbilityEffect { source = changingTgtSA.getTargetCard(); } Predicate filter = sa.hasParam("TargetRestriction") ? GameObjectPredicates.restriction(sa.getParam("TargetRestriction").split(","), activator, source, sa) : null; - TargetChoices newTarget = chooser.getController().chooseNewTargetsFor(changingTgtSA, filter, false); - changingTgtSI.updateTarget(newTarget, sa.getHostCard()); + TargetChoices oldTarget = changingTgtSA.getTargets(); + chooser.getController().chooseNewTargetsFor(changingTgtSA, filter, false); + changingTgtSI.updateTarget(oldTarget, sa.getHostCard()); } } changingTgtSI = changingTgtSI.getSubInstance(); diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbilityStackInstance.java b/forge-game/src/main/java/forge/game/spellability/SpellAbilityStackInstance.java index c324fe367e9..e4ddb14f36c 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbilityStackInstance.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbilityStackInstance.java @@ -133,18 +133,16 @@ public class SpellAbilityStackInstance implements IIdentifiable, IHasCardView { return ability.getTargets(); } - public void updateTarget(TargetChoices target, Card cause) { - if (target != null) { - TargetChoices oldTarget = ability.getTargets(); - ability.setTargets(target); + public void updateTarget(TargetChoices oldTC, Card cause) { + if (oldTC != null) { stackDescription = ability.getStackDescription(); view.updateTargetCards(this); view.updateTargetPlayers(this); view.updateText(this); Set distinctObjects = Sets.newHashSet(); - for (final GameObject tgt : target) { - if (oldTarget != null && oldTarget.contains(tgt)) { + for (final GameObject tgt : ability.getTargets()) { + if (oldTC.contains(tgt)) { // it was an old target, so don't trigger becomes target continue; }