From 4b1e9b6c0c19a28a40bd7027cd5b57ad2c5ead9c Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Thu, 12 Aug 2021 16:35:08 +0100 Subject: [PATCH] Improved Implementation for Card Art Optimisation The new implementation now contains a completely refactored version of the algorithm, also including the invocation of the latest method for getAlternativeCardPrint in StaticData (with extra statistics paramenters gathered from current pool). This include optimisation for card frame, and cards from Expansion sets. Moreover, the new implementation now automatically distribute card arts for **all** the cards in the pool - regardless they need to be "replaced" with alternative print or not. THE ONLY case when this is not happening is when there is NO card to update in the current pool. This makes sense as this means editions has been specified, so the Deck won't receive any UNDESIRED alteration. --- forge-core/src/main/java/forge/deck/Deck.java | 68 ++++++++++++++++--- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/forge-core/src/main/java/forge/deck/Deck.java b/forge-core/src/main/java/forge/deck/Deck.java index c8ea690eed2..a1f55007199 100644 --- a/forge-core/src/main/java/forge/deck/Deck.java +++ b/forge-core/src/main/java/forge/deck/Deck.java @@ -290,6 +290,10 @@ public class Deck extends DeckBase implements Iterable> cardsWithNoEdition) { StaticData data = StaticData.instance(); + // Get current Card Art Preference Settings + boolean isCardArtPreferenceLatestArt = data.cardArtPreferenceIsLatest(); + boolean cardArtPreferenceHasFilter = data.isCoreExpansionOnlyFilterSet(); + for(Entry part : parts.entrySet()) { DeckSection deckSection = part.getKey(); if(deckSection == DeckSection.Planes || deckSection == DeckSection.Schemes || deckSection == DeckSection.Avatar) @@ -301,37 +305,82 @@ public class Deck extends DeckBase implements Iterable cp : pool) { PaperCard card = cp.getKey(); - int count = cp.getValue(); + int totalToAddToPool = cp.getValue(); // A. Skip cards not requiring any update, because they add the edition specified! if (!cardNamesWithNoEditionInSection.contains(card.getName())) { - newPool.add(card, count); + addCardToPool(newPool, card, totalToAddToPool, card.isFoil()); continue; } // B. Determine if current card requires update boolean cardArtNeedsOptimisation = this.isCardArtUpdateRequired(card, releaseDatePivotEdition); if (!cardArtNeedsOptimisation) { - newPool.add(card, count); + addCardToPool(newPool, card, totalToAddToPool, card.isFoil()); continue; } - PaperCard alternativeArtCard = data.getAlternativeCardPrint(card, releaseDatePivotEdition); - if (alternativeArtCard == null) // no alternative found, add original card in Pool - newPool.add(card, count); + PaperCard alternativeCardPrint = data.getAlternativeCardPrint(card, releaseDatePivotEdition, + isCardArtPreferenceLatestArt, + cardArtPreferenceHasFilter, + isExpansionTheMajorityInThePool, + isPoolModernFramed); + if (alternativeCardPrint == null) // no alternative found, add original card in Pool + addCardToPool(newPool, card, totalToAddToPool, card.isFoil()); else - newPool.add(alternativeArtCard, count); + addCardToPool(newPool, alternativeCardPrint, totalToAddToPool, card.isFoil()); } parts.put(deckSection, newPool); } } + private void addCardToPool(CardPool pool, PaperCard card, int totalToAdd, boolean isFoil) { + StaticData data = StaticData.instance(); + if (card.getArtIndex() != IPaperCard.NO_ART_INDEX && card.getArtIndex() != IPaperCard.DEFAULT_ART_INDEX) + pool.add(isFoil ? card.getFoiled() : card, totalToAdd); // art index requested, keep that way! + else { + int artCount = data.getCardArtCount(card); + if (artCount > 1) + addAlternativeCardPrintInPoolWithMultipleArt(card, pool, totalToAdd, artCount); + else + pool.add(isFoil ? card.getFoiled() : card, totalToAdd); + } + } + + private void addAlternativeCardPrintInPoolWithMultipleArt(PaperCard alternativeCardPrint, CardPool pool, + int totalNrToAdd, int nrOfAvailableArts) { + StaticData data = StaticData.instance(); + + // distribute available card art + String cardName = alternativeCardPrint.getName(); + String setCode = alternativeCardPrint.getEdition(); + boolean isFoil = alternativeCardPrint.isFoil(); + int cardsPerArtIndex = totalNrToAdd / nrOfAvailableArts; + cardsPerArtIndex = Math.max(1, cardsPerArtIndex); // make sure is never zero + int restOfCardsToAdd = totalNrToAdd % nrOfAvailableArts; + int cardsAdded = 0; + PaperCard alternativeCardArt = null; + for (int artIndex = 1; artIndex <= nrOfAvailableArts; artIndex++){ + alternativeCardArt = data.getOrLoadCommonCard(cardName, setCode, artIndex, isFoil); + cardsAdded += cardsPerArtIndex; + pool.add(alternativeCardArt, cardsPerArtIndex); + if (cardsAdded == totalNrToAdd) + break; + } + if (restOfCardsToAdd > 0) + pool.add(alternativeCardArt, restOfCardsToAdd); + } + private boolean isCardArtUpdateRequired(PaperCard card, Date referenceReleaseDate) { /* A Card Art update is required ONLY IF the current edition of the card is either newer (older) than pivot edition when LATEST ART (ORIGINAL ART) Card Art Preference @@ -347,6 +396,9 @@ public class Deck extends DeckBase implements Iterable