Fix copying of emblems for simulated AI along with a test.

This commit is contained in:
Myrd
2016-12-22 19:45:16 +00:00
parent 85ad047e4b
commit 4b14c9d943
4 changed files with 49 additions and 4 deletions

View File

@@ -28,6 +28,7 @@ import forge.game.spellability.AbilityActivated;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.SpellAbilityRestriction;
import forge.game.spellability.SpellAbilityStackInstance;
import forge.game.staticability.StaticAbility;
import forge.game.trigger.TriggerType;
import forge.game.zone.PlayerZoneBattlefield;
import forge.game.zone.ZoneType;
@@ -188,14 +189,13 @@ public class GameCopier {
private static final boolean USE_FROM_PAPER_CARD = true;
private Card createCardCopy(Game newGame, Player newOwner, Card c) {
if (c.isToken()) {
if (c.isToken() && !c.isEmblem()) {
String tokenStr = new CardFactory.TokenInfo(c).toString();
// TODO: Use a version of the API that doesn't return a list (i.e. these shouldn't be affected
// by doubling season, etc).
return CardFactory.makeToken(CardFactory.TokenInfo.fromString(tokenStr), newOwner).get(0);
}
if (USE_FROM_PAPER_CARD) {
if (USE_FROM_PAPER_CARD && !c.isEmblem()) {
return Card.fromPaperCard(c.getPaperCard(), newOwner);
}
@@ -209,6 +209,9 @@ public class GameCopier {
for (String type : c.getType()) {
newCard.addType(type);
}
for (StaticAbility stAb : c.getStaticAbilities()) {
newCard.addStaticAbilityCopy(stAb);
}
for (SpellAbility sa : c.getSpellAbilities()) {
SpellAbility saCopy;

View File

@@ -3457,6 +3457,11 @@ public class Card extends GameEntity implements Comparable<Card> {
}
return null;
}
public final StaticAbility addStaticAbilityCopy(final StaticAbility stAb) {
final StaticAbility stAbCopy = new StaticAbility(stAb, this);
currentState.addStaticAbility(stAbCopy);
return stAbCopy;
}
public final void removeStaticAbility(StaticAbility stAb) {
currentState.removeStaticAbility(stAb);
}

View File

@@ -215,6 +215,13 @@ public class StaticAbility extends CardTraitBase implements Comparable<StaticAbi
this.hostCard = host;
}
public StaticAbility(StaticAbility stAb, Card host) {
this.originalMapParams.putAll(stAb.originalMapParams);
this.mapParams.putAll(stAb.mapParams);
this.layers = this.generateLayer();
this.hostCard = host;
}
public final CardCollectionView applyContinuousAbility(final StaticAbilityLayer layer) {
if (!shouldApplyContinuousAbility(layer, false)) {
return null;

View File

@@ -340,7 +340,37 @@ public class GameSimulatorTest extends TestCase {
assertFalse(minusTwoCopy.canPlay());
assertEquals(1, minusTwoCopy.getActivationsThisTurn());
}
public void testPlaneswalkerEmblems() {
Game game = initAndCreateGame();
Player p = game.getPlayers().get(1);
String bearCardName = "Runeclaw Bear";
addCard(bearCardName, p);
Card gideon = addCard("Gideon, Ally of Zendikar", p);
gideon.addCounter(CounterType.LOYALTY, 4, false);
game.getPhaseHandler().devModeSet(PhaseType.MAIN2, p);
game.getAction().checkStateEffects(true);
CardCollection cards = ComputerUtilAbility.getAvailableCards(game, p);
List<SpellAbility> abilities = ComputerUtilAbility.getSpellAbilities(cards, p);
SpellAbility minusFour = findSAWithPrefix(abilities, "-4: You get an emblem");
assertNotNull(minusFour);
minusFour.setActivatingPlayer(p);
assertTrue(minusFour.canPlay());
GameSimulator sim = createSimulator(game, p);
sim.simulateSpellAbility(minusFour);
Game simGame = sim.getSimulatedGameState();
Card simBear = findCardWithName(simGame, bearCardName);
assertEquals(3, simBear.getNetPower());
GameCopier copier = new GameCopier(simGame);
Game copy = copier.makeCopy();
Card copyBear = findCardWithName(copy, bearCardName);
assertEquals(3, copyBear.getNetPower());
}
public void testManifest() {
Game game = initAndCreateGame();
Player p = game.getPlayers().get(1);