mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Fix GameCopier to preserve tracking of loyalty ability activations.
This commit is contained in:
@@ -22,6 +22,7 @@ import forge.game.card.CounterType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityRestriction;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.game.zone.PlayerZoneBattlefield;
|
||||
@@ -61,6 +62,10 @@ public class GameCopier {
|
||||
Player newPlayer = newGame.getPlayers().get(i);
|
||||
newPlayer.setLife(origPlayer.getLife(), null);
|
||||
newPlayer.setActivateLoyaltyAbilityThisTurn(origPlayer.getActivateLoyaltyAbilityThisTurn());
|
||||
for (int j = 0; j < origPlayer.getSpellsCastThisTurn(); j++)
|
||||
newPlayer.addSpellCastThisTurn();
|
||||
for (int j = 0; j < origPlayer.getLandsPlayedThisTurn(); j++)
|
||||
newPlayer.addLandPlayedThisTurn();
|
||||
newPlayer.setPoisonCounters(origPlayer.getPoisonCounters(), null);
|
||||
newPlayer.setLifeLostLastTurn(origPlayer.getLifeLostLastTurn());
|
||||
newPlayer.setLifeLostThisTurn(origPlayer.getLifeLostThisTurn());
|
||||
@@ -97,7 +102,7 @@ public class GameCopier {
|
||||
return newGame;
|
||||
}
|
||||
|
||||
private static void copyStack(Game origGame, Game newGame, GameObjectMap map) {
|
||||
private static void copyStack(Game origGame, Game newGame, GameObjectMap map) {
|
||||
for (SpellAbilityStackInstance origEntry : origGame.getStack()) {
|
||||
SpellAbility origSa = origEntry.getSpellAbility(false);
|
||||
Card origHostCard = origSa.getHostCard();
|
||||
@@ -112,13 +117,13 @@ public class GameCopier {
|
||||
}
|
||||
}
|
||||
if (newSa != null) {
|
||||
newSa.setActivatingPlayer(map.map(origSa.getActivatingPlayer()));
|
||||
if (origSa.usesTargeting()) {
|
||||
for (GameObject o : origSa.getTargets().getTargets()) {
|
||||
newSa.getTargets().add(map.map(o));
|
||||
}
|
||||
}
|
||||
newGame.getStack().add(newSa);
|
||||
newSa.setActivatingPlayer(map.map(origSa.getActivatingPlayer()));
|
||||
if (origSa.usesTargeting()) {
|
||||
for (GameObject o : origSa.getTargets().getTargets()) {
|
||||
newSa.getTargets().add(map.map(o));
|
||||
}
|
||||
}
|
||||
newGame.getStack().add(newSa);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,6 +223,20 @@ public class GameCopier {
|
||||
newCard.setMonstrosityNum(c.getMonstrosityNum());
|
||||
}
|
||||
|
||||
if (c.isPlaneswalker()) {
|
||||
for (SpellAbility sa : c.getAllSpellAbilities()) {
|
||||
SpellAbilityRestriction restrict = sa.getRestrictions();
|
||||
if (restrict.isPwAbility() && restrict.getNumberTurnActivations() > 0) {
|
||||
SpellAbility newSa = findSAInCard(sa, newCard);
|
||||
if (newSa != null) {
|
||||
for (int i = 0; i < restrict.getNumberTurnActivations(); i++) {
|
||||
newSa.getRestrictions().abilityActivated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<CounterType, Integer> counters = c.getCounters();
|
||||
if (!counters.isEmpty()) {
|
||||
for(Entry<CounterType, Integer> kv : counters.entrySet()) {
|
||||
@@ -246,6 +265,16 @@ public class GameCopier {
|
||||
}
|
||||
}
|
||||
|
||||
private static SpellAbility findSAInCard(SpellAbility sa, Card c) {
|
||||
String saDesc = sa.getDescription();
|
||||
for (SpellAbility cardSa : c.getAllSpellAbilities()) {
|
||||
if (saDesc.equals(cardSa.getDescription())) {
|
||||
return cardSa;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private class CopiedGameObjectMap extends GameObjectMap {
|
||||
private Game copiedGame;
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package forge.ai.simulation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.GuiDesktop;
|
||||
import forge.ai.ComputerUtilAbility;
|
||||
import forge.ai.LobbyPlayerAi;
|
||||
import forge.card.CardStateName;
|
||||
import forge.deck.Deck;
|
||||
@@ -15,6 +17,8 @@ import forge.game.GameStage;
|
||||
import forge.game.GameType;
|
||||
import forge.game.Match;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCollection;
|
||||
import forge.game.card.CounterType;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
@@ -55,7 +59,11 @@ public class GameSimulatorTest extends TestCase {
|
||||
}
|
||||
|
||||
private SpellAbility findSAWithPrefix(Card c, String prefix) {
|
||||
for (SpellAbility sa : c.getSpellAbilities()) {
|
||||
return findSAWithPrefix(c.getSpellAbilities(), prefix);
|
||||
}
|
||||
|
||||
private SpellAbility findSAWithPrefix(Iterable<SpellAbility> abilities, String prefix) {
|
||||
for (SpellAbility sa : abilities) {
|
||||
if (sa.toString().startsWith(prefix)) {
|
||||
return sa;
|
||||
}
|
||||
@@ -295,4 +303,46 @@ public class GameSimulatorTest extends TestCase {
|
||||
assertEquals(1, simGame.getPlayers().get(0).getCardsIn(ZoneType.Hand).size());
|
||||
assertEquals(0, simGame.getPlayers().get(1).getCardsIn(ZoneType.Hand).size());
|
||||
}
|
||||
|
||||
public void testPlaneswalkerAbilities() {
|
||||
Game game = initAndCreateGame();
|
||||
Player p = game.getPlayers().get(1);
|
||||
Card sorin = addCard("Sorin, Solemn Visitor", p);
|
||||
sorin.addCounter(CounterType.LOYALTY, 5, false);
|
||||
|
||||
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
|
||||
game.getAction().checkStateEffects(true);
|
||||
|
||||
CardCollection cards = ComputerUtilAbility.getAvailableCards(game, p);
|
||||
ArrayList<SpellAbility> abilities = ComputerUtilAbility.getSpellAbilities(cards, p);
|
||||
SpellAbility minusTwo = findSAWithPrefix(abilities, "-2: Put a 2/2 black Vampire");
|
||||
assertNotNull(minusTwo);
|
||||
minusTwo.setActivatingPlayer(p);
|
||||
assertTrue(minusTwo.canPlay());
|
||||
|
||||
GameSimulator sim = new GameSimulator(game, p);
|
||||
sim.simulateSpellAbility(minusTwo);
|
||||
Game simGame = sim.getSimulatedGameState();
|
||||
Card vampireToken = findCardWithName(simGame, "Vampire");
|
||||
assertNotNull(vampireToken);
|
||||
|
||||
Player simP = simGame.getPlayers().get(1);
|
||||
cards = ComputerUtilAbility.getAvailableCards(simGame, simP);
|
||||
abilities = ComputerUtilAbility.getSpellAbilities(cards, simP);
|
||||
SpellAbility minusTwoSim = findSAWithPrefix(abilities, "-2: Put a 2/2 black Vampire");
|
||||
assertNotNull(minusTwoSim);
|
||||
minusTwo.setActivatingPlayer(simP);
|
||||
assertFalse(minusTwoSim.canPlay());
|
||||
assertEquals(1, minusTwoSim.getActivationsThisTurn());
|
||||
|
||||
GameCopier copier = new GameCopier(simGame);
|
||||
Game copy = copier.makeCopy();
|
||||
Player copyP = copy.getPlayers().get(1);
|
||||
cards = ComputerUtilAbility.getAvailableCards(copy, copyP);
|
||||
abilities = ComputerUtilAbility.getSpellAbilities(cards, copyP);
|
||||
SpellAbility minusTwoCopy = findSAWithPrefix(abilities, "-2: Put a 2/2 black Vampire");
|
||||
minusTwoCopy.setActivatingPlayer(copyP);
|
||||
assertFalse(minusTwoCopy.canPlay());
|
||||
assertEquals(1, minusTwoCopy.getActivationsThisTurn());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user