From 40dac70ebf62acf710747c583c18681cedf071c8 Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Thu, 28 Oct 2021 21:35:32 +0100 Subject: [PATCH] QuickFIX deckSection validation in Decks that inhibited the smart card art option to trigger This MR brings a quick FIX to `validateDeferredSections` method in Deck which erroneously considered entries in filtered Card Pool as for the valid deck entries, instead of the original one. Incidentally this affected only decks with no specified edition, imposing one given by card Db query using default Card Art Preference. In other word, no card with NO edition was found and smart card art was never triggered. This now won't be the case! Another quick fix in `getAllCardNamesWithNoSpecifiedEdition` to skip all sections that are not MAIN | SIDE | Commander for which card art harmonisation is necessary. --- forge-core/src/main/java/forge/deck/Deck.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/forge-core/src/main/java/forge/deck/Deck.java b/forge-core/src/main/java/forge/deck/Deck.java index 45037314276..a7818c1b3e2 100644 --- a/forge-core/src/main/java/forge/deck/Deck.java +++ b/forge-core/src/main/java/forge/deck/Deck.java @@ -25,6 +25,7 @@ import forge.card.CardDb; import forge.card.CardEdition; import forge.item.IPaperCard; import forge.item.PaperCard; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import java.util.*; @@ -283,6 +284,7 @@ public class Deck extends DeckBase implements Iterable cardsInSection = s.getValue(); + List> originalCardRequests = CardPool.processCardList(cardsInSection); CardPool pool = CardPool.fromCardList(cardsInSection); if (pool.countDistinct() == 0) continue; // pool empty, no card has been found! @@ -299,7 +301,7 @@ public class Deck extends DeckBase implements Iterable(); for (Entry entry : filteredPool) { - String poolRequest = getPoolRequest(entry); + String poolRequest = getPoolRequest(entry, originalCardRequests); whiteList.add(poolRequest); } validatedSections.put(s.getKey(), whiteList); @@ -314,7 +316,7 @@ public class Deck extends DeckBase implements Iterable entry : blackList) { DeckSection cardSection = DeckSection.matchingSection(entry.getKey()); - String poolRequest = getPoolRequest(entry); + String poolRequest = getPoolRequest(entry, originalCardRequests); List sectionCardList = validatedSections.getOrDefault(cardSection.name(), null); if (sectionCardList == null) sectionCardList = new ArrayList<>(); @@ -328,11 +330,26 @@ public class Deck extends DeckBase implements Iterable entry) { + private String getPoolRequest(Entry entry, List> originalCardRequests) { PaperCard card = entry.getKey(); int amount = entry.getValue(); - String cardRequest = CardDb.CardRequest.compose(card.isFoil() ? CardDb.CardRequest.compose(card.getName(), true) : card.getName(), card.getEdition(), card.getArtIndex()); - return String.format("%d %s", amount, cardRequest); + String poolCardRequest = CardDb.CardRequest.compose( + card.isFoil() ? CardDb.CardRequest.compose(card.getName(), true) : card.getName(), + card.getEdition(), card.getArtIndex()); + String originalRequestCandidate = null; + for (Pair originalRequest : originalCardRequests){ + String cardRequest = originalRequest.getLeft(); + if (!StringUtils.startsWithIgnoreCase(poolCardRequest, cardRequest)) + continue; + originalRequestCandidate = cardRequest; + int cardAmount = originalRequest.getRight(); + if (amount == cardAmount) + return String.format("%d %s", cardAmount, cardRequest); + } + // This is just in case, it should never happen as we're + if (originalRequestCandidate != null) + return String.format("%d %s", amount, originalRequestCandidate); + return String.format("%d %s", amount, poolCardRequest); } private ArrayList getAllCardNamesWithNoSpecifiedEdition(List cardsInSection) { @@ -355,7 +372,7 @@ public class Deck extends DeckBase implements Iterable part : parts.entrySet()) { DeckSection deckSection = part.getKey(); - if (deckSection == DeckSection.Planes || deckSection == DeckSection.Schemes || deckSection == DeckSection.Avatar) + if (deckSection != DeckSection.Main && deckSection != DeckSection.Sideboard && deckSection != DeckSection.Commander) continue; // == 0. First Off, check if there is anything at all to do for the current section