Test framework: added support to put mdf cards on battlefield by cheats or unit tests;

This commit is contained in:
Oleg Agafonov 2021-02-03 14:23:50 +04:00
parent be77ecea84
commit 4b9de96a6b
7 changed files with 111 additions and 49 deletions

View file

@ -21,6 +21,7 @@ import mage.server.util.ConfigWrapper;
import mage.server.util.PluginClassLoader;
import mage.server.util.config.GamePlugin;
import mage.server.util.config.Plugin;
import mage.util.CardUtil;
import mage.util.Copier;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@ -247,14 +248,15 @@ public abstract class MageTestBase {
} else {
for (int i = 0; i < amount; i++) {
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
Card card = cardInfo != null ? cardInfo.getCard() : null;
if (card != null) {
Card newCard = cardInfo != null ? cardInfo.getCard() : null;
if (newCard != null) {
if (gameZone == Zone.BATTLEFIELD) {
PermanentCard p = new PermanentCard(card, null, currentGame);
Card permCard = CardUtil.getDefaultCardSideForBattlefield(newCard);
PermanentCard p = new PermanentCard(permCard, null, currentGame);
p.setTapped(tapped);
perms.add(p);
} else {
cards.add(card);
cards.add(newCard);
}
} else {
logger.fatal("Couldn't find a card: " + cardName);

View file

@ -33,6 +33,7 @@ import mage.server.util.PluginClassLoader;
import mage.server.util.config.GamePlugin;
import mage.server.util.config.Plugin;
import mage.target.common.TargetAnyTarget;
import mage.util.CardUtil;
import mage.util.Copier;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@ -250,14 +251,15 @@ public abstract class MageTestPlayerBase {
} else {
for (int i = 0; i < amount; i++) {
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
Card card = cardInfo != null ? cardInfo.getCard() : null;
if (card != null) {
Card newCard = cardInfo != null ? cardInfo.getCard() : null;
if (newCard != null) {
if (gameZone == Zone.BATTLEFIELD) {
PermanentCard p = new PermanentCard(card, null, currentGame);
Card permCard = CardUtil.getDefaultCardSideForBattlefield(newCard);
PermanentCard p = new PermanentCard(permCard, null, currentGame);
p.setTapped(tapped);
perms.add(p);
} else {
cards.add(card);
cards.add(newCard);
}
} else {
logger.fatal("Couldn't find a card: " + cardName);
@ -404,23 +406,25 @@ public abstract class MageTestPlayerBase {
CustomTestCard.addAdditionalSubtypes(customName, additionalSubTypes);
CardSetInfo testSet = new CardSetInfo(customName, "custom", "123", Rarity.COMMON);
PermanentCard card = new PermanentCard(new CustomTestCard(controllerPlayer.getId(), testSet, cardType, spellCost), controllerPlayer.getId(), currentGame);
Card newCard = new CustomTestCard(controllerPlayer.getId(), testSet, cardType, spellCost);
Card permCard = CardUtil.getDefaultCardSideForBattlefield(newCard);
PermanentCard permanent = new PermanentCard(permCard, controllerPlayer.getId(), currentGame);
switch (putAtZone) {
case BATTLEFIELD:
getBattlefieldCards(controllerPlayer).add(card);
getBattlefieldCards(controllerPlayer).add(permanent);
break;
case GRAVEYARD:
getGraveCards(controllerPlayer).add(card);
getGraveCards(controllerPlayer).add(newCard);
break;
case HAND:
getHandCards(controllerPlayer).add(card);
getHandCards(controllerPlayer).add(newCard);
break;
case LIBRARY:
getLibraryCards(controllerPlayer).add(card);
getLibraryCards(controllerPlayer).add(newCard);
break;
case COMMAND:
getCommandCards(controllerPlayer).add(card);
getCommandCards(controllerPlayer).add(newCard);
break;
default:
Assert.fail("Unsupported zone: " + putAtZone);

View file

@ -655,11 +655,14 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
if (gameZone == Zone.BATTLEFIELD) {
for (int i = 0; i < count; i++) {
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
Card card = cardInfo != null ? cardInfo.getCard() : null;
if (card == null) {
Card newCard = cardInfo != null ? cardInfo.getCard() : null;
if (newCard == null) {
throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
}
PermanentCard p = new PermanentCard(card.copy(), player.getId(), currentGame);
Card permCard = CardUtil.getDefaultCardSideForBattlefield(newCard);
PermanentCard p = new PermanentCard(permCard, player.getId(), currentGame);
p.setTapped(tapped);
getBattlefieldCards(player).add(p);

View file

@ -1,6 +1,7 @@
package org.mage.test.serverside.performance;
import mage.abilities.keyword.InfectAbility;
import mage.cards.Card;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.PhaseStep;
@ -11,6 +12,7 @@ import mage.game.mulligan.LondonMulligan;
import mage.game.permanent.PermanentCard;
import mage.game.permanent.PermanentImpl;
import mage.remote.traffic.ZippedObjectImpl;
import mage.util.CardUtil;
import mage.utils.CompressUtil;
import org.junit.Assert;
import org.junit.Test;
@ -24,7 +26,9 @@ public class SerializationTest extends CardTestPlayerBase {
@Test
public void test_PermanentImpl_Simple() {
CardInfo cardInfo = CardRepository.instance.findCard("Balduvian Bears");
PermanentImpl permanent = new PermanentCard(cardInfo.getCard(), playerA.getId(), currentGame);
Card newCard = cardInfo.getCard();
Card permCard = CardUtil.getDefaultCardSideForBattlefield(newCard);
PermanentImpl permanent = new PermanentCard(permCard, playerA.getId(), currentGame);
currentGame.addPermanent(permanent, 0);
Object compressed = CompressUtil.compress(permanent);
@ -36,7 +40,9 @@ public class SerializationTest extends CardTestPlayerBase {
@Test
public void test_PermanentImpl_MarkedDamageInfo() {
CardInfo cardInfo = CardRepository.instance.findCard("Balduvian Bears");
PermanentImpl permanent = new PermanentCard(cardInfo.getCard(), playerA.getId(), currentGame);
Card newCard = cardInfo.getCard();
Card permCard = CardUtil.getDefaultCardSideForBattlefield(newCard);
PermanentImpl permanent = new PermanentCard(permCard, playerA.getId(), currentGame);
currentGame.addPermanent(permanent, 0);
// mark damage from infected ability