From 6d5579c4b8a5e03bc80aec759d4827902c8c6add Mon Sep 17 00:00:00 2001 From: Chris H Date: Mon, 1 Apr 2024 20:34:38 -0400 Subject: [PATCH] Fix some more places where gaame elements were reusing old game versions --- forge-game/src/main/java/forge/game/Game.java | 2 +- .../src/main/java/forge/game/GameSnapshot.java | 15 +++++++++++++-- .../src/main/java/forge/game/mana/Mana.java | 9 +++++---- .../game/spellability/AbilityManaPart.java | 18 ++++++++++++++---- .../SpellAbilityPickerSimulationTest.java | 2 +- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/forge-game/src/main/java/forge/game/Game.java b/forge-game/src/main/java/forge/game/Game.java index 6c940ec3fa8..ca91cd582ab 100644 --- a/forge-game/src/main/java/forge/game/Game.java +++ b/forge-game/src/main/java/forge/game/Game.java @@ -401,7 +401,7 @@ public class Game { } public final PlayerCollection getPlayersInTurnOrder(Player p) { - PlayerCollection players = getPlayersInTurnOrder(); + final PlayerCollection players = new PlayerCollection(getPlayersInTurnOrder()); int i = players.indexOf(p); Collections.rotate(players, -i); diff --git a/forge-game/src/main/java/forge/game/GameSnapshot.java b/forge-game/src/main/java/forge/game/GameSnapshot.java index 73f8c33677f..00187dd36bf 100644 --- a/forge-game/src/main/java/forge/game/GameSnapshot.java +++ b/forge-game/src/main/java/forge/game/GameSnapshot.java @@ -194,12 +194,23 @@ public class GameSnapshot { Game toGame = toPlayer.getGame(); toPlayer.getManaPool().resetPool(); for (Mana m : fromPlayer.getManaPool()) { - // TODO the mana object here needs to be copied to the new game - toPlayer.getManaPool().addMana(m, false); + toPlayer.getManaPool().addMana(copyMana(m, toGame), false); } toPlayer.updateManaForView(); } + private Mana copyMana(Mana m, Game toGame) { + Card fromCard = m.getSourceCard(); + Card toCard = findBy(toGame, fromCard); + // Are we copying over mana abilities properly? + if (toCard == null) { + return m; + } + Mana newMana = new Mana(m.getColor(), toCard, m.getManaAbility()); + newMana.getManaAbility().setSourceCard(toCard); + return newMana; + } + private void copyStack(Game fromGame, Game toGame, boolean restore) { // Try to match the StackInstance ID. If we don't find it, generate a new stack instance that matches // If we do find it, we may need to alter the existing stack instance diff --git a/forge-game/src/main/java/forge/game/mana/Mana.java b/forge-game/src/main/java/forge/game/mana/Mana.java index 4ffa75fb0be..dadf413ecbe 100644 --- a/forge-game/src/main/java/forge/game/mana/Mana.java +++ b/forge-game/src/main/java/forge/game/mana/Mana.java @@ -34,6 +34,11 @@ import forge.game.spellability.SpellAbility; * @version $Id$ */ public class Mana { + + private byte color; + private Card sourceCard = null; + private AbilityManaPart manaAbility = null; + @Override public int hashCode() { final int prime = 31; @@ -82,10 +87,6 @@ public class Mana { return mp == mp2 || (mp.getManaRestrictions().equals(mp2.getManaRestrictions()) && mp.getExtraManaRestriction().equals(mp2.getExtraManaRestriction())); } - private byte color; - private Card sourceCard = null; - private AbilityManaPart manaAbility = null; - public Mana(final byte color, final Card source, final AbilityManaPart manaAbility) { this.color = color; this.manaAbility = manaAbility; diff --git a/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java b/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java index dcbfe3e8c87..a187c9b2db9 100644 --- a/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java +++ b/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java @@ -82,14 +82,10 @@ public class AbilityManaPart implements java.io.Serializable { // Spells paid with this mana spell can't be countered. - /** *

* Dev Mode Constructor for AbilityMana. *

- * - * @param sourceCard - * a {@link forge.game.card.Card} object. */ public AbilityManaPart(final SpellAbility sourceSA, final Map params) { this(sourceSA.getHostCard(), params); @@ -110,6 +106,20 @@ public class AbilityManaPart implements java.io.Serializable { this.persistentMana = null != params.get("PersistentMana") && "True".equalsIgnoreCase(params.get("PersistentMana")); } + public AbilityManaPart(final Card newSource, AbilityManaPart oldMana) { + this.sourceCard = newSource; + this.origProduced = oldMana.origProduced; + this.manaRestrictions = oldMana.manaRestrictions; + this.cannotCounterSpell = oldMana.cannotCounterSpell; + this.addsKeywords = oldMana.addsKeywords; + this.addsKeywordsType = oldMana.addsKeywordsType; + this.addsKeywordsUntil = oldMana.addsKeywordsUntil; + this.addsCounters = oldMana.addsCounters; + this.triggersWhenSpent = oldMana.triggersWhenSpent; + this.persistentMana = oldMana.persistentMana; + // Do we need to copy over last mana produced somehow? Its kinda gross + } + /** *

* produceMana. diff --git a/forge-gui-desktop/src/test/java/forge/ai/simulation/SpellAbilityPickerSimulationTest.java b/forge-gui-desktop/src/test/java/forge/ai/simulation/SpellAbilityPickerSimulationTest.java index 1ab8735448e..367987c4f7d 100644 --- a/forge-gui-desktop/src/test/java/forge/ai/simulation/SpellAbilityPickerSimulationTest.java +++ b/forge-gui-desktop/src/test/java/forge/ai/simulation/SpellAbilityPickerSimulationTest.java @@ -536,7 +536,7 @@ public class SpellAbilityPickerSimulationTest extends SimulationTest { AssertJUnit.assertTrue(saDesc, saDesc.startsWith("Lightning Bolt deals 3 damage to any target.")); } - @Test(enabled = false) + @Test(enabled = true) public void testPlayingPumpSpellsAfterBlocks() { Game game = initAndCreateGame(); Player p = game.getPlayers().get(1);