Fix some more places where gaame elements were reusing old game versions

This commit is contained in:
Chris H
2024-04-01 20:34:38 -04:00
parent 2c04b08ae8
commit 6d5579c4b8
5 changed files with 34 additions and 12 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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;

View File

@@ -82,14 +82,10 @@ public class AbilityManaPart implements java.io.Serializable {
// Spells paid with this mana spell can't be countered.
/**
* <p>
* Dev Mode Constructor for AbilityMana.
* </p>
*
* @param sourceCard
* a {@link forge.game.card.Card} object.
*/
public AbilityManaPart(final SpellAbility sourceSA, final Map<String, String> 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
}
/**
* <p>
* produceMana.

View File

@@ -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);