Simulation: fix wrong ActivatingPlayer

This commit is contained in:
tool4EvEr
2022-03-20 20:25:58 +01:00
parent 40bbdab3fe
commit b544ae0c9f
4 changed files with 21 additions and 8 deletions

View File

@@ -27,6 +27,7 @@ import forge.game.card.CardFactory;
import forge.game.card.CounterType;
import forge.game.card.token.TokenInfo;
import forge.game.combat.Combat;
import forge.game.mana.Mana;
import forge.game.phase.PhaseHandler;
import forge.game.phase.PhaseType;
import forge.game.player.Player;
@@ -90,7 +91,9 @@ public class GameCopier {
newPlayer.setLifeLostLastTurn(origPlayer.getLifeLostLastTurn());
newPlayer.setLifeLostThisTurn(origPlayer.getLifeLostThisTurn());
newPlayer.setLifeGainedThisTurn(origPlayer.getLifeGainedThisTurn());
newPlayer.getManaPool().add(origPlayer.getManaPool());
for (Mana m : origPlayer.getManaPool()) {
newPlayer.getManaPool().addMana(m, false);
}
newPlayer.setCommanders(origPlayer.getCommanders()); // will be fixed up below
playerMap.put(origPlayer, newPlayer);
}
@@ -131,7 +134,7 @@ public class GameCopier {
for (SpellAbility sa : c.getSpellAbilities()) {
Player activatingPlayer = sa.getActivatingPlayer();
if (activatingPlayer != null && activatingPlayer.getGame() != newGame) {
sa.setActivatingPlayer(gameObjectMap.map(activatingPlayer));
sa.setActivatingPlayer(gameObjectMap.map(activatingPlayer), true);
}
}
}
@@ -180,7 +183,7 @@ public class GameCopier {
}
}
if (newSa != null) {
newSa.setActivatingPlayer(map.map(origSa.getActivatingPlayer()));
newSa.setActivatingPlayer(map.map(origSa.getActivatingPlayer()), true);
if (origSa.usesTargeting()) {
for (GameObject o : origSa.getTargets()) {
newSa.getTargets().add(map.map(o));

View File

@@ -16,6 +16,7 @@ import forge.game.phase.PhaseType;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.TargetChoices;
import forge.util.collect.FCollectionView;
public class GameSimulator {
public static boolean COPY_STACK = false;
@@ -124,7 +125,7 @@ public class GameSimulator {
}
}
private SpellAbility findSaInSimGame(SpellAbility sa) {
private SpellAbility findSaInSimGame(final SpellAbility sa) {
// is already an ability from sim game
if (sa.getHostCard().getGame().equals(this.simGame)) {
return sa;
@@ -132,7 +133,15 @@ public class GameSimulator {
Card origHostCard = sa.getHostCard();
Card hostCard = (Card) copier.find(origHostCard);
String desc = sa.getDescription();
for (SpellAbility cSa : hostCard.getSpellAbilities()) {
FCollectionView<SpellAbility> candidates = hostCard.getSpellAbilities();
// first pass for accuracy (spells with alternative costs)
for (SpellAbility cSa : candidates) {
if (desc.equals(cSa.getDescription())) {
return cSa;
}
}
// fall back for safety
for (SpellAbility cSa : candidates) {
if (desc.startsWith(cSa.getDescription())) {
return cSa;
}
@@ -160,7 +169,7 @@ public class GameSimulator {
}
debugPrint("Found SA " + sa + " on host card " + sa.getHostCard() + " with owner:"+ sa.getHostCard().getOwner());
sa.setActivatingPlayer(aiPlayer);
sa.setActivatingPlayer(aiPlayer, true);
SpellAbility origSaOrSubSa = origSa;
SpellAbility saOrSubSa = sa;
do {