mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
[KHM] fixed issues with booster collation, added test (fixes #7521)
This commit is contained in:
parent
e8d2648319
commit
a90e9923f5
2 changed files with 112 additions and 22 deletions
|
@ -7,6 +7,7 @@ import mage.cards.repository.CardRepository;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.SetType;
|
||||
import mage.constants.SuperType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -34,7 +35,6 @@ public final class Kaldheim extends ExpansionSet {
|
|||
this.numBoosterUncommon = 3;
|
||||
this.numBoosterRare = 1;
|
||||
this.ratioBoosterMythic = 8;
|
||||
this.numBoosterDoubleFaced = 1;
|
||||
this.maxCardNumberInBooster = 285;
|
||||
this.ratioBoosterSpecialLand = 12;
|
||||
this.ratioBoosterSpecialLandNumerator = 5;
|
||||
|
@ -448,24 +448,28 @@ public final class Kaldheim extends ExpansionSet {
|
|||
|
||||
@Override
|
||||
public List<CardInfo> getCardsByRarity(Rarity rarity) {
|
||||
if (rarity != Rarity.COMMON) {
|
||||
return super.getCardsByRarity(rarity);
|
||||
if (savedCards.containsKey(rarity)) {
|
||||
return new ArrayList<>(savedCards.get(rarity));
|
||||
}
|
||||
List<CardInfo> savedCardsInfos = savedCards.get(rarity);
|
||||
if (savedCardsInfos == null) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).notTypes(CardType.LAND);
|
||||
criteria.rarities(rarity).doubleFaced(false);
|
||||
savedCardsInfos = CardRepository.instance.findCards(criteria);
|
||||
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
|
||||
savedCardsInfos.removeIf(next -> next.getCardNumberAsInt() > maxCardNumberInBooster);
|
||||
}
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).nameExact("Shimmerdrift Vale");
|
||||
savedCardsInfos.addAll(CardRepository.instance.findCards(criteria));
|
||||
savedCards.put(rarity, savedCardsInfos);
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code);
|
||||
criteria.rarities(rarity);
|
||||
List<CardInfo> savedCardsInfos = CardRepository.instance.findCards(criteria);
|
||||
switch (rarity) {
|
||||
case LAND:
|
||||
savedCardsInfos.removeIf(cardInfo -> !cardInfo.getSupertypes().contains(SuperType.SNOW));
|
||||
savedCardsInfos.removeIf(cardInfo -> !cardInfo.getSupertypes().contains(SuperType.BASIC));
|
||||
break;
|
||||
case COMMON:
|
||||
savedCardsInfos.removeIf(cardInfo ->
|
||||
cardInfo.getCard().isSnow()
|
||||
&& cardInfo.getCard().isLand()
|
||||
&& !cardInfo.getCard().getName().equals("Shimmerdrift Vale")
|
||||
);
|
||||
break;
|
||||
}
|
||||
// Return a copy of the saved cards information, as not to modify the original.
|
||||
savedCardsInfos.removeIf(next -> next.getCardNumberAsInt() > maxCardNumberInBooster);
|
||||
savedCards.put(rarity, savedCardsInfos);
|
||||
return new ArrayList<>(savedCardsInfos);
|
||||
}
|
||||
|
||||
|
@ -474,11 +478,12 @@ public final class Kaldheim extends ExpansionSet {
|
|||
if (savedSpecialLand.isEmpty()) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code);
|
||||
criteria.rarities(Rarity.COMMON, Rarity.LAND);
|
||||
criteria.types(CardType.LAND);
|
||||
criteria.supertypes("Snow");
|
||||
savedSpecialLand.addAll(CardRepository.instance.findCards(criteria));
|
||||
savedSpecialLand.removeIf(cardInfo -> cardInfo.getName() == "Shimmerdrift Vale");
|
||||
savedSpecialLand.removeIf(cardInfo -> cardInfo.getSupertypes().contains(SuperType.BASIC));
|
||||
savedSpecialLand.removeIf(cardInfo -> !cardInfo.getSupertypes().contains(SuperType.SNOW));
|
||||
savedSpecialLand.removeIf(cardInfo -> cardInfo.getName().equals("Shimmerdrift Vale"));
|
||||
savedSpecialLand.removeIf(cardInfo -> cardInfo.getName().equals("Faceless Haven"));
|
||||
savedSpecialLand.removeIf(cardInfo -> cardInfo.getCardNumberAsInt() > maxCardNumberInBooster);
|
||||
}
|
||||
return new ArrayList<>(savedSpecialLand);
|
||||
|
|
|
@ -4,6 +4,7 @@ import mage.MageObject;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.keyword.PartnerWithAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ModalDoubleFacesCard;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardScanner;
|
||||
import mage.constants.CardType;
|
||||
|
@ -17,8 +18,7 @@ import org.mage.test.serverside.base.MageTestBase;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author nigelzor, JayDi85
|
||||
|
@ -296,4 +296,89 @@ public class BoosterGenerationTest extends MageTestBase {
|
|||
assertFalse("Amonkhet Remastered's booster must not contains Regal Caracal", contains(booster, "Regal Caracal", null));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKaldheim_SnowLandAndMDFC() {
|
||||
boolean foundVale = false;
|
||||
boolean foundMDFC = false;
|
||||
boolean foundNoMDFC = false;
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
List<Card> booster = Kaldheim.getInstance().createBooster();
|
||||
|
||||
assertEquals("Booster does not have 15 cards", 15, booster.size());
|
||||
assertTrue(
|
||||
"Booster contains cards from another set",
|
||||
booster.stream().map(Card::getExpansionSetCode).allMatch("KHM"::equals)
|
||||
);
|
||||
assertFalse(
|
||||
"Booster cannot contain non-snow basic lands",
|
||||
booster.stream().anyMatch(card -> card.isBasic() && !card.isSnow())
|
||||
);
|
||||
assertEquals(
|
||||
"Booster must contain exactly 1 rare or mythic", 1,
|
||||
booster.stream().map(Card::getRarity).filter(rarity -> rarity == Rarity.RARE || rarity == Rarity.MYTHIC).count()
|
||||
);
|
||||
assertEquals(
|
||||
"Booster must contain exactly 3 uncommons", 3,
|
||||
booster.stream().map(Card::getRarity).filter(Rarity.UNCOMMON::equals).count()
|
||||
);
|
||||
|
||||
List<Card> snowLands = booster.stream().filter(card -> card.isSnow() && card.isLand()).collect(Collectors.toList());
|
||||
switch (snowLands.size()) {
|
||||
case 0:
|
||||
fail("Booster must have snow lands");
|
||||
case 1:
|
||||
Card snowLand = snowLands.get(0);
|
||||
assertTrue(
|
||||
"Only one snow land, must be basic or common",
|
||||
snowLand.isBasic() || snowLand.getRarity() == Rarity.COMMON
|
||||
);
|
||||
assertNotEquals(
|
||||
"Only one snow land, can't be Shimmerdrift Vale",
|
||||
"Shimmerdrift Vale", snowLand.getName()
|
||||
);
|
||||
assertNotEquals(
|
||||
"Only one snow land, can't be Faceless Haven",
|
||||
"Faceless Haven", snowLand.getName()
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
assertEquals(
|
||||
"Booster can't have two snow lands unless one is Shimmerdrift Vale or Faceless Haven", 1,
|
||||
snowLands.stream().filter(card -> card.getName().equals("Shimmerdrift Vale") || card.getName().equals("Faceless Haven")).count()
|
||||
);
|
||||
assertEquals(
|
||||
"Booster can't have two snow lands unless one is not Shimmerdrift Vale or Faceless Haven", 1,
|
||||
snowLands.stream().filter(card -> !card.getName().equals("Shimmerdrift Vale") && !card.getName().equals("Faceless Haven")).count()
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
assertEquals("Booster can't have three snow lands unless one is Shimmerdrift Vale", 1,
|
||||
snowLands.stream().filter(card -> card.getName().equals("Shimmerdrift Vale")).count()
|
||||
);
|
||||
assertEquals("Booster can't have three snow lands unless one is Faceless Haven", 1,
|
||||
snowLands.stream().filter(card -> card.getName().equals("Faceless Haven")).count()
|
||||
);
|
||||
assertEquals("Booster can't have three snow lands unless one is not Shimmerdrift Vale or Faceless Haven", 1,
|
||||
snowLands.stream().filter(card -> !card.getName().equals("Shimmerdrift Vale") && !card.getName().equals("Faceless Haven")).count()
|
||||
);
|
||||
break;
|
||||
default:
|
||||
fail("Booster can't have more than three snow lands");
|
||||
}
|
||||
|
||||
long mdfcCount = booster.stream().filter(card -> card instanceof ModalDoubleFacesCard).count();
|
||||
assertTrue("Booster can't have more than one MDFC", mdfcCount < 2);
|
||||
|
||||
foundMDFC |= mdfcCount > 0;
|
||||
foundNoMDFC |= mdfcCount == 0;
|
||||
foundVale |= booster.stream().map(MageObject::getName).anyMatch("Shimmerdrift Vale"::equals);
|
||||
if (foundVale && foundMDFC && foundNoMDFC && i > 20) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue("No booster contained Shimmerdrift Vale", foundVale);
|
||||
assertTrue("No booster contained an MDFC", foundMDFC);
|
||||
assertTrue("Every booster contained an MDFC", foundNoMDFC);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue