Merge branch 'improve_xitax_method' into 'master'

Improve convertByXitaxMethod

Closes #1754

See merge request core-developers/forge!4200
This commit is contained in:
Michael Kamensky
2021-03-15 05:17:55 +00:00
3 changed files with 50 additions and 4 deletions

View File

@@ -247,6 +247,36 @@ public class StaticData {
return card; return card;
} }
public PaperCard getCardFromLatestorEarliest(PaperCard card) {
PaperCard c = this.getCommonCards().getCardFromEdition(card.getName(), null, CardDb.SetPreference.Latest, card.getArtIndex());
if (null != c && c.hasImage()) {
return c;
}
c = this.getCommonCards().getCardFromEdition(card.getName(), null, CardDb.SetPreference.Latest, -1);
if (null != c && c.hasImage()) {
return c;
}
c = this.getCommonCards().getCardFromEdition(card.getName(), null, CardDb.SetPreference.LatestCoreExp, -1);
if (null != c) {
return c;
}
c = this.getCommonCards().getCardFromEdition(card.getName(), null, CardDb.SetPreference.EarliestCoreExp, -1);
if (null != c) {
return c;
}
// I give up!
return card;
}
public boolean getFilteredHandsEnabled(){ public boolean getFilteredHandsEnabled(){
return filteredHandsEnabled; return filteredHandsEnabled;
} }

View File

@@ -396,6 +396,16 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
public PaperCard getCardFromEdition(final String cardName, final Date printedBefore, final SetPreference fromSet, int artIndex) { public PaperCard getCardFromEdition(final String cardName, final Date printedBefore, final SetPreference fromSet, int artIndex) {
final CardRequest cr = CardRequest.fromString(cardName); final CardRequest cr = CardRequest.fromString(cardName);
List<PaperCard> cards = getAllCards(cr.cardName); List<PaperCard> cards = getAllCards(cr.cardName);
if (printedBefore != null){
cards = Lists.newArrayList(Iterables.filter(cards, new Predicate<PaperCard>() {
@Override public boolean apply(PaperCard c) {
CardEdition ed = editions.get(c.getEdition());
return ed.getDate().before(printedBefore); }
}));
}
if (cards.size() == 0) // Don't bother continuing! No cards has been found!
return null;
boolean cardsListReadOnly = true; boolean cardsListReadOnly = true;
if (StringUtils.isNotBlank(cr.edition)) { if (StringUtils.isNotBlank(cr.edition)) {

View File

@@ -252,7 +252,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
} }
private void convertByXitaxMethod() { private void convertByXitaxMethod() {
Date dateWithAllCards = StaticData.instance().getEditions().getEarliestDateWithAllCards(getAllCardsInASinglePool()); //Date dateWithAllCards = StaticData.instance().getEditions().getEarliestDateWithAllCards(getAllCardsInASinglePool());
for(Entry<DeckSection, CardPool> p : parts.entrySet()) { for(Entry<DeckSection, CardPool> p : parts.entrySet()) {
if( p.getKey() == DeckSection.Planes || p.getKey() == DeckSection.Schemes || p.getKey() == DeckSection.Avatar) if( p.getKey() == DeckSection.Planes || p.getKey() == DeckSection.Schemes || p.getKey() == DeckSection.Avatar)
@@ -264,12 +264,18 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
PaperCard card = cp.getKey(); PaperCard card = cp.getKey();
int count = cp.getValue(); int count = cp.getValue();
PaperCard replacementCard = StaticData.instance().getCardByEditionDate(card, dateWithAllCards); PaperCard replacementCard = StaticData.instance().getCardFromLatestorEarliest(card);
if (replacementCard.getArtIndex() == card.getArtIndex()) { if (replacementCard.getArtIndex() == card.getArtIndex()) {
if (card.hasImage())
newPool.add(card, count); newPool.add(card, count);
else
newPool.add(replacementCard, count);
} else { } else {
if (card.hasImage())
newPool.add(card.getName(), card.getEdition(), count); // this is to randomize art newPool.add(card.getName(), card.getEdition(), count); // this is to randomize art
else
newPool.add(replacementCard, count);
} }
} }