Ensures first group of commons gets removed first

Tested with 20 card packs containing 13 commons followed by 5 uncommons, a rare, then a card of any rarity.
Also tested with 20 card packs containing 3 commons followed by 15 uncommons, a rare, then a card of any rarity.

-------

In the first scenario, only commons from the group of 13 were removed.
In the second scenario, the first three commons got removed, then the first two uncommons in the pack.

That was expected behaviour. Note - second scenario not expected to occur.
This commit is contained in:
tiera3 2025-01-07 20:05:00 +10:00 committed by GitHub
parent e120932bb4
commit 85948bf028
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -226,8 +226,20 @@ public abstract class ExpansionSet implements Serializable {
if (theBooster.size() > 15 && theBooster.get(0).getRarity() == Rarity.LAND) {
theBooster.remove(0);
}
int keepCards = 4;
ArrayList<rarity> dontRemove = new ArrayList<>(Arrays.asList(Rarity.UNCOMMON, Rarity.RARE, Rarity.MYTHIC));
int toRemove;
while (theBooster.size() > 15) {
theBooster.remove(RandomUtil.nextInt(theBooster.size() - 4));
if (theBooster.size() > keepCards) {
toRemove = RandomUtil.nextInt(theBooster.size() - keepCards);
if( dontRemove.contains( theBooster.get(toRemove).getRarity() )) {
keepCards = theBooster.size() - toRemove ;
} else {
theBooster.remove(toRemove);
}
} else {
theBooster.remove(0);
}
}
return theBooster;